diff --git a/packages/nx/src/plugins/js/lock-file/__fixtures__/mixed-keys/package-lock.json b/packages/nx/src/plugins/js/lock-file/__fixtures__/mixed-keys/package-lock.json new file mode 100644 index 0000000000000..8deeff428723e --- /dev/null +++ b/packages/nx/src/plugins/js/lock-file/__fixtures__/mixed-keys/package-lock.json @@ -0,0 +1,340 @@ +{ + "name": "something", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "something", + "version": "0.0.0", + "dependencies": { + "@isaacs/cliui": "^8.0.2", + "cliui": "^8.0.1" + } + }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/cliui/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/cliui/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/cliui/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==" + }, + "node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==" + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width-cjs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/string-width-cjs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/wrap-ansi-cjs/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + } + } +} diff --git a/packages/nx/src/plugins/js/lock-file/__fixtures__/mixed-keys/package.json b/packages/nx/src/plugins/js/lock-file/__fixtures__/mixed-keys/package.json index 3243f162b6e8a..508085075d84d 100644 --- a/packages/nx/src/plugins/js/lock-file/__fixtures__/mixed-keys/package.json +++ b/packages/nx/src/plugins/js/lock-file/__fixtures__/mixed-keys/package.json @@ -1,5 +1,6 @@ { "name": "something", + "version": "0.0.0", "dependencies": { "@isaacs/cliui": "^8.0.2", "cliui": "^8.0.1" diff --git a/packages/nx/src/plugins/js/lock-file/npm-parser.spec.ts b/packages/nx/src/plugins/js/lock-file/npm-parser.spec.ts index 817e100c023d7..6806afdbdda07 100644 --- a/packages/nx/src/plugins/js/lock-file/npm-parser.spec.ts +++ b/packages/nx/src/plugins/js/lock-file/npm-parser.spec.ts @@ -853,6 +853,467 @@ describe('NPM lock file utility', () => { expect(Object.keys(externalNodes).length).toEqual(5); }); }); + + describe('mixed keys', () => { + let lockFile, lockFileHash; + + beforeEach(() => { + lockFile = require(joinPathFragments( + __dirname, + '__fixtures__/mixed-keys/package-lock.json' + )); + lockFileHash = '__fixtures__/mixed-keys/package-lock.json'; + }); + + it('should parse and prune packages with mixed keys', () => { + const packageJson = require(joinPathFragments( + __dirname, + '__fixtures__/mixed-keys/package.json' + )); + + const externalNodes = getNpmLockfileNodes( + JSON.stringify(lockFile), + lockFileHash + ); + let graph: ProjectGraph = { + nodes: {}, + dependencies: {}, + externalNodes, + }; + const ctx: CreateDependenciesContext = { + projects: {}, + externalNodes, + fileMap: { + nonProjectFiles: [], + projectFileMap: {}, + }, + filesToProcess: { + nonProjectFiles: [], + projectFileMap: {}, + }, + nxJsonConfiguration: null, + workspaceRoot: '/virtual', + }; + const dependencies = getNpmLockfileDependencies( + JSON.stringify(lockFile), + lockFileHash, + ctx + ); + + const builder = new ProjectGraphBuilder(graph); + for (const dep of dependencies) { + builder.addDependency( + dep.source, + dep.target, + dep.type, + 'sourceFile' in dep ? dep.sourceFile : null + ); + } + graph = builder.getUpdatedProjectGraph(); + + expect(graph.externalNodes).toMatchInlineSnapshot(` + { + "npm:@isaacs/cliui": { + "data": { + "hash": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "packageName": "@isaacs/cliui", + "version": "8.0.2", + }, + "name": "npm:@isaacs/cliui", + "type": "npm", + }, + "npm:ansi-regex": { + "data": { + "hash": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "packageName": "ansi-regex", + "version": "6.0.1", + }, + "name": "npm:ansi-regex", + "type": "npm", + }, + "npm:ansi-regex@5.0.1": { + "data": { + "hash": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "packageName": "ansi-regex", + "version": "5.0.1", + }, + "name": "npm:ansi-regex@5.0.1", + "type": "npm", + }, + "npm:ansi-styles": { + "data": { + "hash": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "packageName": "ansi-styles", + "version": "6.2.1", + }, + "name": "npm:ansi-styles", + "type": "npm", + }, + "npm:ansi-styles@4.3.0": { + "data": { + "hash": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "packageName": "ansi-styles", + "version": "4.3.0", + }, + "name": "npm:ansi-styles@4.3.0", + "type": "npm", + }, + "npm:cliui": { + "data": { + "hash": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "packageName": "cliui", + "version": "8.0.1", + }, + "name": "npm:cliui", + "type": "npm", + }, + "npm:color-convert": { + "data": { + "hash": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "packageName": "color-convert", + "version": "2.0.1", + }, + "name": "npm:color-convert", + "type": "npm", + }, + "npm:color-name": { + "data": { + "hash": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "packageName": "color-name", + "version": "1.1.4", + }, + "name": "npm:color-name", + "type": "npm", + }, + "npm:eastasianwidth": { + "data": { + "hash": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "packageName": "eastasianwidth", + "version": "0.2.0", + }, + "name": "npm:eastasianwidth", + "type": "npm", + }, + "npm:emoji-regex": { + "data": { + "hash": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "packageName": "emoji-regex", + "version": "9.2.2", + }, + "name": "npm:emoji-regex", + "type": "npm", + }, + "npm:emoji-regex@8.0.0": { + "data": { + "hash": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "packageName": "emoji-regex", + "version": "8.0.0", + }, + "name": "npm:emoji-regex@8.0.0", + "type": "npm", + }, + "npm:is-fullwidth-code-point": { + "data": { + "hash": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "packageName": "is-fullwidth-code-point", + "version": "3.0.0", + }, + "name": "npm:is-fullwidth-code-point", + "type": "npm", + }, + "npm:string-width": { + "data": { + "hash": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "packageName": "string-width", + "version": "5.1.2", + }, + "name": "npm:string-width", + "type": "npm", + }, + "npm:string-width-cjs": { + "data": { + "hash": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "packageName": "string-width-cjs", + "version": "npm:string-width@4.2.3", + }, + "name": "npm:string-width-cjs", + "type": "npm", + }, + "npm:string-width@4.2.3": { + "data": { + "hash": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "packageName": "string-width", + "version": "4.2.3", + }, + "name": "npm:string-width@4.2.3", + "type": "npm", + }, + "npm:strip-ansi": { + "data": { + "hash": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "packageName": "strip-ansi", + "version": "7.1.0", + }, + "name": "npm:strip-ansi", + "type": "npm", + }, + "npm:strip-ansi-cjs": { + "data": { + "hash": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "packageName": "strip-ansi-cjs", + "version": "npm:strip-ansi@6.0.1", + }, + "name": "npm:strip-ansi-cjs", + "type": "npm", + }, + "npm:strip-ansi@6.0.1": { + "data": { + "hash": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "packageName": "strip-ansi", + "version": "6.0.1", + }, + "name": "npm:strip-ansi@6.0.1", + "type": "npm", + }, + "npm:wrap-ansi": { + "data": { + "hash": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "packageName": "wrap-ansi", + "version": "8.1.0", + }, + "name": "npm:wrap-ansi", + "type": "npm", + }, + "npm:wrap-ansi-cjs": { + "data": { + "hash": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "packageName": "wrap-ansi-cjs", + "version": "npm:wrap-ansi@7.0.0", + }, + "name": "npm:wrap-ansi-cjs", + "type": "npm", + }, + "npm:wrap-ansi@7.0.0": { + "data": { + "hash": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "packageName": "wrap-ansi", + "version": "7.0.0", + }, + "name": "npm:wrap-ansi@7.0.0", + "type": "npm", + }, + } + `); + + expect(graph.dependencies).toMatchInlineSnapshot(` + { + "npm:@isaacs/cliui": [ + { + "source": "npm:@isaacs/cliui", + "target": "npm:string-width", + "type": "static", + }, + { + "source": "npm:@isaacs/cliui", + "target": "npm:string-width-cjs", + "type": "static", + }, + { + "source": "npm:@isaacs/cliui", + "target": "npm:strip-ansi", + "type": "static", + }, + { + "source": "npm:@isaacs/cliui", + "target": "npm:strip-ansi-cjs", + "type": "static", + }, + { + "source": "npm:@isaacs/cliui", + "target": "npm:wrap-ansi", + "type": "static", + }, + { + "source": "npm:@isaacs/cliui", + "target": "npm:wrap-ansi-cjs", + "type": "static", + }, + ], + "npm:ansi-styles@4.3.0": [ + { + "source": "npm:ansi-styles@4.3.0", + "target": "npm:color-convert", + "type": "static", + }, + ], + "npm:cliui": [ + { + "source": "npm:cliui", + "target": "npm:string-width@4.2.3", + "type": "static", + }, + { + "source": "npm:cliui", + "target": "npm:strip-ansi@6.0.1", + "type": "static", + }, + { + "source": "npm:cliui", + "target": "npm:wrap-ansi@7.0.0", + "type": "static", + }, + ], + "npm:color-convert": [ + { + "source": "npm:color-convert", + "target": "npm:color-name", + "type": "static", + }, + ], + "npm:string-width": [ + { + "source": "npm:string-width", + "target": "npm:eastasianwidth", + "type": "static", + }, + { + "source": "npm:string-width", + "target": "npm:emoji-regex", + "type": "static", + }, + { + "source": "npm:string-width", + "target": "npm:strip-ansi", + "type": "static", + }, + ], + "npm:string-width-cjs": [ + { + "source": "npm:string-width-cjs", + "target": "npm:emoji-regex@8.0.0", + "type": "static", + }, + { + "source": "npm:string-width-cjs", + "target": "npm:is-fullwidth-code-point", + "type": "static", + }, + { + "source": "npm:string-width-cjs", + "target": "npm:strip-ansi@6.0.1", + "type": "static", + }, + ], + "npm:string-width@4.2.3": [ + { + "source": "npm:string-width@4.2.3", + "target": "npm:emoji-regex@8.0.0", + "type": "static", + }, + { + "source": "npm:string-width@4.2.3", + "target": "npm:is-fullwidth-code-point", + "type": "static", + }, + { + "source": "npm:string-width@4.2.3", + "target": "npm:strip-ansi@6.0.1", + "type": "static", + }, + ], + "npm:strip-ansi": [ + { + "source": "npm:strip-ansi", + "target": "npm:ansi-regex", + "type": "static", + }, + ], + "npm:strip-ansi-cjs": [ + { + "source": "npm:strip-ansi-cjs", + "target": "npm:ansi-regex@5.0.1", + "type": "static", + }, + ], + "npm:strip-ansi@6.0.1": [ + { + "source": "npm:strip-ansi@6.0.1", + "target": "npm:ansi-regex@5.0.1", + "type": "static", + }, + ], + "npm:wrap-ansi": [ + { + "source": "npm:wrap-ansi", + "target": "npm:ansi-styles", + "type": "static", + }, + { + "source": "npm:wrap-ansi", + "target": "npm:string-width", + "type": "static", + }, + { + "source": "npm:wrap-ansi", + "target": "npm:strip-ansi", + "type": "static", + }, + ], + "npm:wrap-ansi-cjs": [ + { + "source": "npm:wrap-ansi-cjs", + "target": "npm:ansi-styles@4.3.0", + "type": "static", + }, + { + "source": "npm:wrap-ansi-cjs", + "target": "npm:string-width@4.2.3", + "type": "static", + }, + { + "source": "npm:wrap-ansi-cjs", + "target": "npm:strip-ansi@6.0.1", + "type": "static", + }, + ], + "npm:wrap-ansi@7.0.0": [ + { + "source": "npm:wrap-ansi@7.0.0", + "target": "npm:ansi-styles@4.3.0", + "type": "static", + }, + { + "source": "npm:wrap-ansi@7.0.0", + "target": "npm:string-width@4.2.3", + "type": "static", + }, + { + "source": "npm:wrap-ansi@7.0.0", + "target": "npm:strip-ansi@6.0.1", + "type": "static", + }, + ], + } + `); + + const prunedGraph = pruneProjectGraph(graph, packageJson); + const result = stringifyNpmLockfile( + prunedGraph, + JSON.stringify(lockFile), + packageJson + ); + expect(result).toEqual( + JSON.stringify( + require(joinPathFragments( + __dirname, + '__fixtures__/mixed-keys/package-lock.json' + )), + null, + 2 + ) + ); + }); + }); }); function uniq(str: string) { diff --git a/packages/nx/src/plugins/js/lock-file/npm-parser.ts b/packages/nx/src/plugins/js/lock-file/npm-parser.ts index 00ce0290631a9..11cbeef62a7b1 100644 --- a/packages/nx/src/plugins/js/lock-file/npm-parser.ts +++ b/packages/nx/src/plugins/js/lock-file/npm-parser.ts @@ -305,7 +305,19 @@ function findTarget( if (keyMap.has(searchPath)) { const child = keyMap.get(searchPath); + // if the version is alias to another package we need to parse the versions to compare if ( + child.data.version.startsWith('npm:') && + versionRange.startsWith('npm:') + ) { + const nodeVersion = child.data.version.slice( + child.data.version.indexOf('@', 5) + 1 + ); + const depVersion = versionRange.slice(versionRange.indexOf('@', 5) + 1); + if (nodeVersion === depVersion || satisfies(nodeVersion, depVersion)) { + return child; + } + } else if ( child.data.version === versionRange || satisfies(child.data.version, versionRange) ) {