-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure that npm dependencies retain their "production" grouping (#…
…939) This resolves an inconsistency in the scanner output for npm packages that appear in the same tree multiple times but in different groups; this happens because the table outputter deduplicates on groups on the assumption that a package can only appear in a single group which is incorrect for the NPM ecosystem. To address this, I've introduced an internal map type that ensures groups are merged when a package is added, with the twist that if either instance of a package being merged is in no groups then that is the result of the merge because implicitly that means an instance of the package is in the "production" group which takes priority over the other groups. This is something that should most likely be improved on the future, but right now this fix should be good enough to ship since afaik it doesn't impact any other ecosystem and groups are something of a PoC given we can't resolve that information richly enough across all ecosystems yet. I think this technically could impact `pnpm` as well, but none of our fixtures gave a good indicator and the latest lockfile version doesn't have that information anymore so frankly I'm not worrying about it at this point. Resolves #924
- Loading branch information
Showing
6 changed files
with
266 additions
and
7 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
pkg/lockfile/fixtures/npm/same-package-different-groups.v1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"requires": true, | ||
"lockfileVersion": 1, | ||
"dependencies": { | ||
"ajv": { | ||
"version": "5.5.2", | ||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", | ||
"integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", | ||
"dev": true, | ||
"requires": { | ||
"co": "^4.6.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
} | ||
}, | ||
"eslint": { | ||
"version": "1.2.3", | ||
"dev": true, | ||
"dependencies": { | ||
"ajv": { | ||
"version": "5.5.2", | ||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", | ||
"integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", | ||
"dev": true, | ||
"requires": { | ||
"co": "^4.6.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
}, | ||
"dependencies": { | ||
"ajv": { | ||
"version": "5.5.2", | ||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", | ||
"integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", | ||
"optional": true, | ||
"requires": { | ||
"co": "^4.6.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"table": { | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"ajv": { | ||
"version": "5.5.2", | ||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", | ||
"integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", | ||
"requires": { | ||
"co": "^4.6.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
}, | ||
"dependencies": { | ||
"ajv": { | ||
"version": "5.5.2", | ||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", | ||
"integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", | ||
"dev": true, | ||
"optional": true, | ||
"requires": { | ||
"co": "^4.6.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
pkg/lockfile/fixtures/npm/same-package-different-groups.v2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"name": "my-library", | ||
"lockfileVersion": 2, | ||
"requires": true, | ||
"packages": { | ||
"": { | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
}, | ||
"node_modules/ajv": { | ||
"version": "5.5.2", | ||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", | ||
"integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", | ||
"dev": true, | ||
"dependencies": { | ||
"co": "^4.6.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
} | ||
}, | ||
"node_modules/eslint": { | ||
"version": "1.2.3", | ||
"dev": true | ||
}, | ||
"node_modules/eslint/node_modules/ajv": { | ||
"version": "5.5.2", | ||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", | ||
"integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", | ||
"dev": true, | ||
"dependencies": { | ||
"co": "^4.6.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
} | ||
}, | ||
"node_modules/eslint/node_modules/ajv/node_modules/ajv": { | ||
"version": "5.5.2", | ||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", | ||
"integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", | ||
"optional": true, | ||
"dependencies": { | ||
"co": "^4.6.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
} | ||
}, | ||
"node_modules/table": { | ||
"version": "1.0.0" | ||
}, | ||
"node_modules/table/node_modules/ajv": { | ||
"version": "5.5.2", | ||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", | ||
"integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", | ||
"dependencies": { | ||
"co": "^4.6.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
} | ||
}, | ||
"node_modules/table/node_modules/ajv/node_modules/ajv": { | ||
"version": "5.5.2", | ||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", | ||
"integrity": "sha512-Ajr4IcMXq/2QmMkEmSvxqfLN5zGmJ92gHXAeOXq1OekoH2rfDNsgdDoL2f7QaRCy7G/E6TpxBVdRuNraMztGHw==", | ||
"devOptional": true, | ||
"dependencies": { | ||
"co": "^4.6.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"json-schema-traverse": "^0.3.0" | ||
} | ||
} | ||
}, | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters