diff --git a/src/packagedcode/npm.py b/src/packagedcode/npm.py index 6059850448..c831aa8e85 100644 --- a/src/packagedcode/npm.py +++ b/src/packagedcode/npm.py @@ -623,15 +623,21 @@ def parse(cls, location): elif not line.startswith(' ') and stripped.endswith(':'): # the first line of a dependency has the name and requirements # "@babel/core@^7.1.0", "@babel/core@^7.3.4": + # For aliases: "@alias@npm:@package@^12": requirements = stripped.strip(':').split(', ') requirements = [r.strip().strip("\"'") for r in requirements] for req in requirements: if req.startswith('@'): - assert req.count('@') == 2 + # 2 = package, 4 = alias + assert req.count('@') in [2, 4] ns_name, _, constraint = req.rpartition('@') ns, _ , name = ns_name.rpartition('/') constraint = constraint.strip("\"'") + # If we have an alias, just keep the package part: + # @npm: + if "@npm:" in ns: + ns = ns.split(':')[1] top_requirements.append((ns, name, constraint,)) else: diff --git a/tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock b/tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock index ba267ae31a..a3202ffc0d 100644 --- a/tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock +++ b/tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock @@ -25,3 +25,20 @@ integrity sha512-3UYcJUj9kvSLbLbUIfQTqzcy5VX7GRZ/CCDrnOaZorFFM01aXp1+GJwuFGV4NDDoAS+mOUyHcO6UD/RfqOks3Q== dependencies: "@babel/types" "^7.0.0" + +"@react-spring/web@9.7.3", "react-spring@npm:@react-spring/web@9.7.3": + version "9.7.3" + resolved "https://registry.yarnpkg.com/@react-spring/web/-/web-9.7.3.tgz#da977382f91d9af4c400e4aa7dc37d3db07b87e0" + integrity sha512-rEvipblmihiz8+Eo01zDp5dqWn6XfYk8q2rlN9c18YIOL4o6nuY/VplDoocUMHYfH4liurpO4o1QudKOO1nAiQ== + dependencies: + "@react-spring/animated" "9.7.3" + "@react-spring/core" "9.7.3" + "@react-spring/shared" "9.7.3" + +"@testing-library/react-12@npm:@testing-library/react@^12": + version "12.1.2" + resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-12.1.2.tgz#f1bc9a45943461fa2a598bb4597df1ae044cfc76" + integrity sha512-ihQiEOklNyHIpo2Y8FREkyD1QAea054U0MVbwH1m8N9TxeFz+KoJ9LkqoKqJlzx2JDm56DVwaJ1r36JYxZM05g== + dependencies: + "@babel/runtime" "^7.12.5" + "@testing-library/dom" "^8.0.0" diff --git a/tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock-expected b/tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock-expected index 240319304a..02b97085a2 100644 --- a/tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock-expected +++ b/tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock-expected @@ -250,6 +250,161 @@ "purl": "pkg:npm/%40babel/helper-annotate-as-pure@7.0.0" }, "extra_data": {} + }, + { + "purl": "pkg:npm/%40react-spring/web@9.7.3", + "extracted_requirement": "9.7.3 9.7.3", + "scope": "dependencies", + "is_runtime": true, + "is_optional": false, + "is_resolved": true, + "resolved_package": { + "type": "npm", + "namespace": "@react-spring", + "name": "web", + "version": "9.7.3", + "qualifiers": {}, + "subpath": null, + "primary_language": "JavaScript", + "description": null, + "release_date": null, + "parties": [], + "keywords": [], + "homepage_url": null, + "download_url": "https://registry.yarnpkg.com/@react-spring/web/-/web-9.7.3.tgz", + "size": null, + "sha1": "da977382f91d9af4c400e4aa7dc37d3db07b87e0", + "md5": null, + "sha256": null, + "sha512": + "ac4be2a5b9668a18b3f3e128d35cc3a7976a5a7e977d893cab6ae537d735f1820e2f8a3a9ee63f569943a2871430761f1f8962baba4ee28d50b9d28e3b59c089", + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "holder": null, + "declared_license_expression": null, + "declared_license_expression_spdx": null, + "license_detections": [], + "other_license_expression": null, + "other_license_expression_spdx": null, + "other_license_detections": [], + "extracted_license_statement": null, + "notice_text": null, + "source_packages": [], + "file_references": [], + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:npm/%22%40react-spring/animated%22", + "extracted_requirement": "9.7.3", + "scope": "dependencies", + "is_runtime": true, + "is_optional": false, + "is_resolved": false, + "resolved_package": {}, + "extra_data": {} + }, + { + "purl": "pkg:npm/%22%40react-spring/core%22", + "extracted_requirement": "9.7.3", + "scope": "dependencies", + "is_runtime": true, + "is_optional": false, + "is_resolved": false, + "resolved_package": {}, + "extra_data": {} + }, + { + "purl": "pkg:npm/%22%40react-spring/shared%22", + "extracted_requirement": "9.7.3", + "scope": "dependencies", + "is_runtime": true, + "is_optional": false, + "is_resolved": false, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": "https://www.npmjs.com/package/@react-spring/web", + "repository_download_url": "https://registry.npmjs.org/@react-spring/web/-/web-9.7.3.tgz", + "api_data_url": "https://registry.npmjs.org/@react-spring%2fweb/9.7.3", + "datasource_id": "yarn_lock_v1", + "purl": "pkg:npm/%40react-spring/web@9.7.3" + }, + "extra_data": {} + }, + { + "purl": "pkg:npm/%40testing-library/react@12.1.2", + "extracted_requirement": "^12", + "scope": "dependencies", + "is_runtime": true, + "is_optional": false, + "is_resolved": true, + "resolved_package": { + "type": "npm", + "namespace": "@testing-library", + "name": "react", + "version": "12.1.2", + "qualifiers": {}, + "subpath": null, + "primary_language": "JavaScript", + "description": null, + "release_date": null, + "parties": [], + "keywords": [], + "homepage_url": null, + "download_url": "https://registry.yarnpkg.com/@testing-library/react/-/react-12.1.2.tgz", + "size": null, + "sha1": "f1bc9a45943461fa2a598bb4597df1ae044cfc76", + "md5": null, + "sha256": null, + "sha512": "8a142210e9253721c8a68d98f054449320f540079ad39e14d0c55bc07d66f0df53c5e173f8aa09f4b92aa0aa89973c762439b9e83570689d6bdfa258c59334e6", + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "holder": null, + "declared_license_expression": null, + "declared_license_expression_spdx": null, + "license_detections": [], + "other_license_expression": null, + "other_license_expression_spdx": null, + "other_license_detections": [], + "extracted_license_statement": null, + "notice_text": null, + "source_packages": [], + "file_references": [], + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:npm/%22%40babel/runtime%22", + "extracted_requirement": "^7.12.5", + "scope": "dependencies", + "is_runtime": true, + "is_optional": false, + "is_resolved": false, + "resolved_package": {}, + "extra_data": {} + }, + { + "purl": "pkg:npm/%22%40testing-library/dom%22", + "extracted_requirement": "^8.0.0", + "scope": "dependencies", + "is_runtime": true, + "is_optional": false, + "is_resolved": false, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": "https://www.npmjs.com/package/@testing-library/react", + "repository_download_url": "https://registry.npmjs.org/@testing-library/react/-/react-12.1.2.tgz", + "api_data_url": "https://registry.npmjs.org/@testing-library%2freact/12.1.2", + "datasource_id": "yarn_lock_v1", + "purl": "pkg:npm/%40testing-library/react@12.1.2" + }, + "extra_data": {} } ], "repository_homepage_url": null, @@ -258,4 +413,4 @@ "datasource_id": "yarn_lock_v1", "purl": null } -] \ No newline at end of file +]