Skip to content

Commit 0d20d10

Browse files
committed
npm: more tests for alias in yarn.lock v1
An assert in the code was making aliases using `@` fail. Signed-off-by: Adrien Schildknecht <[email protected]>
1 parent 2638a71 commit 0d20d10

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

src/packagedcode/npm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,13 @@ def parse(cls, location):
623623
elif not line.startswith(' ') and stripped.endswith(':'):
624624
# the first line of a dependency has the name and requirements
625625
# "@babel/core@^7.1.0", "@babel/core@^7.3.4":
626+
# For aliases: "@alias@npm:@package@^12":
626627
requirements = stripped.strip(':').split(', ')
627628
requirements = [r.strip().strip("\"'") for r in requirements]
628629
for req in requirements:
629630
if req.startswith('@'):
630-
assert req.count('@') == 2
631+
# 2 = package, 4 = alias
632+
assert req.count('@') in [2, 4]
631633

632634
ns_name, _, constraint = req.rpartition('@')
633635
ns, _ , name = ns_name.rpartition('/')

tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@
3434
"@react-spring/animated" "9.7.3"
3535
"@react-spring/core" "9.7.3"
3636
"@react-spring/shared" "9.7.3"
37+
38+
"@testing-library/react-12@npm:@testing-library/react@^12":
39+
version "12.1.2"
40+
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-12.1.2.tgz#f1bc9a45943461fa2a598bb4597df1ae044cfc76"
41+
integrity sha512-ihQiEOklNyHIpo2Y8FREkyD1QAea054U0MVbwH1m8N9TxeFz+KoJ9LkqoKqJlzx2JDm56DVwaJ1r36JYxZM05g==
42+
dependencies:
43+
"@babel/runtime" "^7.12.5"
44+
"@testing-library/dom" "^8.0.0"

tests/packagedcode/data/npm/yarn-lock/v1-complex/yarn.lock-expected

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,78 @@
333333
"purl": "pkg:npm/%40react-spring/[email protected]"
334334
},
335335
"extra_data": {}
336+
},
337+
{
338+
"purl": "pkg:npm/%40testing-library/[email protected]",
339+
"extracted_requirement": "^12",
340+
"scope": "dependencies",
341+
"is_runtime": true,
342+
"is_optional": false,
343+
"is_resolved": true,
344+
"resolved_package": {
345+
"type": "npm",
346+
"namespace": "@testing-library",
347+
"name": "react",
348+
"version": "12.1.2",
349+
"qualifiers": {},
350+
"subpath": null,
351+
"primary_language": "JavaScript",
352+
"description": null,
353+
"release_date": null,
354+
"parties": [],
355+
"keywords": [],
356+
"homepage_url": null,
357+
"download_url": "https://registry.yarnpkg.com/@testing-library/react/-/react-12.1.2.tgz",
358+
"size": null,
359+
"sha1": "f1bc9a45943461fa2a598bb4597df1ae044cfc76",
360+
"md5": null,
361+
"sha256": null,
362+
"sha512": "8a142210e9253721c8a68d98f054449320f540079ad39e14d0c55bc07d66f0df53c5e173f8aa09f4b92aa0aa89973c762439b9e83570689d6bdfa258c59334e6",
363+
"bug_tracking_url": null,
364+
"code_view_url": null,
365+
"vcs_url": null,
366+
"copyright": null,
367+
"holder": null,
368+
"declared_license_expression": null,
369+
"declared_license_expression_spdx": null,
370+
"license_detections": [],
371+
"other_license_expression": null,
372+
"other_license_expression_spdx": null,
373+
"other_license_detections": [],
374+
"extracted_license_statement": null,
375+
"notice_text": null,
376+
"source_packages": [],
377+
"file_references": [],
378+
"extra_data": {},
379+
"dependencies": [
380+
{
381+
"purl": "pkg:npm/%22%40babel/runtime%22",
382+
"extracted_requirement": "^7.12.5",
383+
"scope": "dependencies",
384+
"is_runtime": true,
385+
"is_optional": false,
386+
"is_resolved": false,
387+
"resolved_package": {},
388+
"extra_data": {}
389+
},
390+
{
391+
"purl": "pkg:npm/%22%40testing-library/dom%22",
392+
"extracted_requirement": "^8.0.0",
393+
"scope": "dependencies",
394+
"is_runtime": true,
395+
"is_optional": false,
396+
"is_resolved": false,
397+
"resolved_package": {},
398+
"extra_data": {}
399+
}
400+
],
401+
"repository_homepage_url": "https://www.npmjs.com/package/@testing-library/react",
402+
"repository_download_url": "https://registry.npmjs.org/@testing-library/react/-/react-12.1.2.tgz",
403+
"api_data_url": "https://registry.npmjs.org/@testing-library%2freact/12.1.2",
404+
"datasource_id": "yarn_lock_v1",
405+
"purl": "pkg:npm/%40testing-library/[email protected]"
406+
},
407+
"extra_data": {}
336408
}
337409
],
338410
"repository_homepage_url": null,

0 commit comments

Comments
 (0)