Skip to content

Commit

Permalink
npm: more tests for alias in yarn.lock v1
Browse files Browse the repository at this point in the history
An assert in the code was making aliases using `@` fail.

Signed-off-by: Adrien Schildknecht <[email protected]>
  • Loading branch information
schischi committed Oct 20, 2023
1 parent 2638a71 commit 0d20d10
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/packagedcode/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,13 @@ 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('/')
Expand Down
8 changes: 8 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 @@ -34,3 +34,11 @@
"@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"
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,78 @@
"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 Down

0 comments on commit 0d20d10

Please sign in to comment.