From 0d20d10c16a9fce1420719a4134d241d062e03f1 Mon Sep 17 00:00:00 2001 From: Adrien Schildknecht Date: Fri, 20 Oct 2023 02:23:46 +0200 Subject: [PATCH] npm: more tests for alias in yarn.lock v1 An assert in the code was making aliases using `@` fail. Signed-off-by: Adrien Schildknecht --- src/packagedcode/npm.py | 4 +- .../data/npm/yarn-lock/v1-complex/yarn.lock | 8 +++ .../yarn-lock/v1-complex/yarn.lock-expected | 72 +++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/packagedcode/npm.py b/src/packagedcode/npm.py index 99b34c4bf25..c831aa8e855 100644 --- a/src/packagedcode/npm.py +++ b/src/packagedcode/npm.py @@ -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('/') 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 b14f652add9..a3202ffc0d4 100644 --- a/tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock +++ b/tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock @@ -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" 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 e327ab91aa3..02b97085a21 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 @@ -333,6 +333,78 @@ "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,