Skip to content

Commit

Permalink
Merge pull request aboutcode-org#3555 from schischi/yarn-v1-alias
Browse files Browse the repository at this point in the history
npm: support aliases in yarn lock v1

Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne authored Oct 20, 2023
2 parents d6a9e41 + 0d20d10 commit b1a3620
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/packagedcode/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# <alias-package>@npm:<package>
if "@npm:" in ns:
ns = ns.split(':')[1]
top_requirements.append((ns, name, constraint,))

else:
Expand Down
17 changes: 17 additions & 0 deletions tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,20 @@
integrity sha512-3UYcJUj9kvSLbLbUIfQTqzcy5VX7GRZ/CCDrnOaZorFFM01aXp1+GJwuFGV4NDDoAS+mOUyHcO6UD/RfqOks3Q==
dependencies:
"@babel/types" "^7.0.0"

"@react-spring/[email protected]", "react-spring@npm:@react-spring/[email protected]":
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"
157 changes: 156 additions & 1 deletion tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock-expected
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,161 @@
"purl": "pkg:npm/%40babel/[email protected]"
},
"extra_data": {}
},
{
"purl": "pkg:npm/%40react-spring/[email protected]",
"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/[email protected]"
},
"extra_data": {}
},
{
"purl": "pkg:npm/%40testing-library/[email protected]",
"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/[email protected]"
},
"extra_data": {}
}
],
"repository_homepage_url": null,
Expand All @@ -258,4 +413,4 @@
"datasource_id": "yarn_lock_v1",
"purl": null
}
]
]

0 comments on commit b1a3620

Please sign in to comment.