Skip to content

Commit 0d5e4f9

Browse files
meeroslavFrozenPandaz
authored andcommitted
fix(core): improve external node dependency mapping (#12996)
(cherry picked from commit 2f20807)
1 parent f1db9ce commit 0d5e4f9

File tree

10 files changed

+7085
-1165
lines changed

10 files changed

+7085
-1165
lines changed

packages/nx/src/utils/lock-file/__fixtures__/npm.lock.ts

Lines changed: 6824 additions & 1031 deletions
Large diffs are not rendered by default.

packages/nx/src/utils/lock-file/__snapshots__/lock-file.spec.ts.snap

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Array [
5555
exports[`lock-file mapLockFileDataToExternalNodes npm should map lock file v2 data to external nodes 1`] = `
5656
Object {
5757
"data": Object {
58-
"hash": "54342be9f4609650eba8e995881c5eb98c29b9d7bb95b9a699d9e9df68d6428e",
58+
"hash": "c22918aa52c9fdce78bf82451d8114e00b6d4375a8e5b1d1d96c6cf4755dbe1a",
5959
"packageName": "yargs",
6060
"version": "17.5.1",
6161
},
@@ -159,7 +159,7 @@ Array [
159159
exports[`lock-file mapLockFileDataToExternalNodes npm should map successfully complex lock file v2 1`] = `
160160
Object {
161161
"data": Object {
162-
"hash": "1e61b9db38c17534ce427d40ce84f9c03b4c439253f659e9a48513a10a52b465",
162+
"hash": "8da365ef8d327d868461fda5c863f779c2f75acfe6a591e733b31a2882763af3",
163163
"packageName": "nx",
164164
"version": "14.7.5",
165165
},
@@ -187,7 +187,7 @@ Array [
187187
},
188188
Object {
189189
"source": "npm:nx",
190-
"target": "npm:chalk",
190+
"target": "npm:chalk@4.1.0",
191191
"type": "static",
192192
},
193193
Object {
@@ -252,7 +252,7 @@ Array [
252252
},
253253
Object {
254254
"source": "npm:nx",
255-
"target": "npm:js-yaml@4.1.0",
255+
"target": "npm:js-yaml",
256256
"type": "static",
257257
},
258258
Object {
@@ -262,7 +262,7 @@ Array [
262262
},
263263
Object {
264264
"source": "npm:nx",
265-
"target": "npm:minimatch",
265+
"target": "npm:minimatch@3.0.5",
266266
"type": "static",
267267
},
268268
Object {
@@ -317,7 +317,7 @@ Array [
317317
},
318318
Object {
319319
"source": "npm:nx",
320-
"target": "npm:yargs-parser",
320+
"target": "npm:yargs-parser@21.0.1",
321321
"type": "static",
322322
},
323323
]
@@ -326,7 +326,7 @@ Array [
326326
exports[`lock-file mapLockFileDataToExternalNodes npm should map successfully complex lock file v3 1`] = `
327327
Object {
328328
"data": Object {
329-
"hash": "48388b2bf77ed12f2830273632c13c745854d63133c5c0466e229ef29ea074c0",
329+
"hash": "8da365ef8d327d868461fda5c863f779c2f75acfe6a591e733b31a2882763af3",
330330
"packageName": "nx",
331331
"version": "14.7.5",
332332
},
@@ -354,7 +354,7 @@ Array [
354354
},
355355
Object {
356356
"source": "npm:nx",
357-
"target": "npm:chalk",
357+
"target": "npm:chalk@4.1.0",
358358
"type": "static",
359359
},
360360
Object {
@@ -419,7 +419,7 @@ Array [
419419
},
420420
Object {
421421
"source": "npm:nx",
422-
"target": "npm:js-yaml@4.1.0",
422+
"target": "npm:js-yaml",
423423
"type": "static",
424424
},
425425
Object {
@@ -429,7 +429,7 @@ Array [
429429
},
430430
Object {
431431
"source": "npm:nx",
432-
"target": "npm:minimatch",
432+
"target": "npm:minimatch@3.0.5",
433433
"type": "static",
434434
},
435435
Object {
@@ -484,7 +484,7 @@ Array [
484484
},
485485
Object {
486486
"source": "npm:nx",
487-
"target": "npm:yargs-parser",
487+
"target": "npm:yargs-parser@21.0.1",
488488
"type": "static",
489489
},
490490
]
@@ -493,7 +493,7 @@ Array [
493493
exports[`lock-file mapLockFileDataToExternalNodes npm should map successfully complex npm lock file v1 1`] = `
494494
Object {
495495
"data": Object {
496-
"hash": "3e63cd88ec8f5eb00f37559c24caf47da1f45f6a3f607d013f148da8593e3a26",
496+
"hash": "62016caa192e50e3af6e4730fa1427455ad431a0e11ad807215c56bee04a8c8e",
497497
"packageName": "nx",
498498
"version": "14.7.5",
499499
},
@@ -521,7 +521,7 @@ Array [
521521
},
522522
Object {
523523
"source": "npm:nx",
524-
"target": "npm:chalk",
524+
"target": "npm:chalk@4.1.0",
525525
"type": "static",
526526
},
527527
Object {
@@ -596,7 +596,7 @@ Array [
596596
},
597597
Object {
598598
"source": "npm:nx",
599-
"target": "npm:minimatch",
599+
"target": "npm:minimatch@3.0.5",
600600
"type": "static",
601601
},
602602
Object {
@@ -651,7 +651,7 @@ Array [
651651
},
652652
Object {
653653
"source": "npm:nx",
654-
"target": "npm:yargs-parser",
654+
"target": "npm:yargs-parser@21.0.1",
655655
"type": "static",
656656
},
657657
]
@@ -958,7 +958,7 @@ Array [
958958
exports[`lock-file mapLockFileDataToExternalNodes yarn should map successfully complex lock file 1`] = `
959959
Object {
960960
"data": Object {
961-
"hash": "1e61b9db38c17534ce427d40ce84f9c03b4c439253f659e9a48513a10a52b465",
961+
"hash": "6562d56c136e9e359c74fb6843da8deb66890de8e61e49ee766ad9cee2be6878",
962962
"packageName": "nx",
963963
"version": "14.7.5",
964964
},

packages/nx/src/utils/lock-file/__snapshots__/npm.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Object {
7070

7171
exports[`npm LockFile utility v2 should parse lockfile correctly 2`] = `
7272
Object {
73-
"typescript@4.8.3": Object {
73+
"typescript@4.8.4": Object {
7474
"bin": Object {
7575
"tsc": "bin/tsc",
7676
"tsserver": "bin/tsserver",
@@ -79,17 +79,17 @@ Object {
7979
"engines": Object {
8080
"node": ">=4.2.0",
8181
},
82-
"integrity": "sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig==",
82+
"integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==",
8383
"packageMeta": Array [
8484
Object {
8585
"dev": true,
8686
"optional": undefined,
8787
"path": "node_modules/typescript",
8888
},
8989
],
90-
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.3.tgz",
90+
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz",
9191
"rootVersion": true,
92-
"version": "4.8.3",
92+
"version": "4.8.4",
9393
},
9494
}
9595
`;

packages/nx/src/utils/lock-file/lock-file.spec.ts

Lines changed: 67 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { parseNpmLockFile } from './npm';
33
import { parsePnpmLockFile } from './pnpm';
44
import { parseYarnLockFile } from './yarn';
55
import {
6-
lockFileV3YargsOnly as npmLockFileV3YargsOnly,
7-
lockFileV2YargsOnly as npmLockFileV2YargsOnly,
8-
lockFileV1YargsOnly as npmLockFileV1YargsOnly,
6+
lockFileV3YargsAndDevkitOnly as npmLockFileV3YargsAndDevkit,
7+
lockFileV2YargsAndDevkitOnly as npmLockFileV2YargsAndDevkit,
8+
lockFileV1YargsAndDevkitOnly as npmLockFileV1YargsAndDevkit,
99
lockFileV3 as npmLockFileV3,
1010
lockFileV2 as npmLockFileV2,
1111
lockFileV1 as npmLockFileV1,
@@ -32,25 +32,28 @@ jest.mock('nx/src/utils/workspace-root', () => ({
3232
}));
3333

3434
describe('lock-file', () => {
35-
const fileSys = {
36-
'node_modules/chalk/package.json': '{"version": "4.1.0"}',
37-
'node_modules/glob/package.json': '{"version": "7.1.4"}',
38-
'node_modules/js-yaml/package.json': '{"version": "4.1.0"}',
39-
'node_modules/minimatch/package.json': '{"version": "3.0.5"}',
40-
'node_modules/semver/package.json': '{"version": "7.3.4"}',
41-
'node_modules/tslib/package.json': '{"version": "2.4.0"}',
42-
'node_modules/yargs-parser/package.json': '{"version": "21.0.1"}',
43-
};
44-
beforeEach(() => {
45-
vol.fromJSON(fileSys, '/root');
46-
});
47-
4835
describe('mapLockFileDataToExternalNodes', () => {
4936
describe('yarn', () => {
37+
const fileSys = {
38+
'node_modules/chalk/package.json': '{"version": "4.1.0"}',
39+
'node_modules/glob/package.json': '{"version": "7.1.4"}',
40+
'node_modules/js-yaml/package.json': '{"version": "4.1.0"}',
41+
'node_modules/minimatch/package.json': '{"version": "3.0.5"}',
42+
'node_modules/semver/package.json': '{"version": "7.3.4"}',
43+
'node_modules/tslib/package.json': '{"version": "2.4.0"}',
44+
'node_modules/yargs-parser/package.json': '{"version": "21.0.1"}',
45+
};
46+
beforeEach(() => {
47+
vol.fromJSON(fileSys, '/root');
48+
});
49+
5050
it('should map lock file data to external nodes', () => {
5151
const lockFileData = parseYarnLockFile(yarnLockFileDevkitAndYargs);
5252

53-
const partialGraph = mapLockFileDataToPartialGraph(lockFileData);
53+
const partialGraph = mapLockFileDataToPartialGraph(
54+
lockFileData,
55+
'yarn'
56+
);
5457

5558
expect(partialGraph.externalNodes['npm:yargs']).toMatchSnapshot();
5659
expect(partialGraph.dependencies['npm:yargs']).toMatchSnapshot();
@@ -59,36 +62,52 @@ describe('lock-file', () => {
5962
it('should map successfully complex lock file', () => {
6063
const lockFileData = parseYarnLockFile(yarnLockFile);
6164

62-
const partialGraph = mapLockFileDataToPartialGraph(lockFileData);
65+
const partialGraph = mapLockFileDataToPartialGraph(
66+
lockFileData,
67+
'yarn'
68+
);
6369

6470
expect(partialGraph.externalNodes['npm:nx']).toMatchSnapshot();
6571
expect(partialGraph.dependencies['npm:nx']).toMatchSnapshot();
6672
});
6773
});
6874

6975
describe('npm', () => {
76+
const fileSys = {
77+
'node_modules/chalk/package.json': '{"version": "4.1.2"}',
78+
'node_modules/glob/package.json': '{"version": "7.1.4"}',
79+
'node_modules/js-yaml/package.json': '{"version": "4.1.0"}',
80+
'node_modules/minimatch/package.json': '{"version": "4.0.5"}',
81+
'node_modules/semver/package.json': '{"version": "7.3.4"}',
82+
'node_modules/tslib/package.json': '{"version": "2.4.1"}',
83+
'node_modules/yargs-parser/package.json': '{"version": "21.1.1"}',
84+
};
85+
beforeEach(() => {
86+
vol.fromJSON(fileSys, '/root');
87+
});
88+
7089
it('should map lock file v3 data to external nodes', () => {
71-
const lockFileData = parseNpmLockFile(npmLockFileV3YargsOnly);
90+
const lockFileData = parseNpmLockFile(npmLockFileV3YargsAndDevkit);
7291

73-
const partialGraph = mapLockFileDataToPartialGraph(lockFileData);
92+
const partialGraph = mapLockFileDataToPartialGraph(lockFileData, 'npm');
7493

7594
expect(partialGraph.externalNodes['npm:yargs']).toMatchSnapshot();
7695
expect(partialGraph.dependencies['npm:yargs']).toMatchSnapshot();
7796
});
7897

7998
it('should map lock file v2 data to external nodes', () => {
80-
const lockFileData = parseNpmLockFile(npmLockFileV2YargsOnly);
99+
const lockFileData = parseNpmLockFile(npmLockFileV2YargsAndDevkit);
81100

82-
const partialGraph = mapLockFileDataToPartialGraph(lockFileData);
101+
const partialGraph = mapLockFileDataToPartialGraph(lockFileData, 'npm');
83102

84103
expect(partialGraph.externalNodes['npm:yargs']).toMatchSnapshot();
85104
expect(partialGraph.dependencies['npm:yargs']).toMatchSnapshot();
86105
});
87106

88107
it('should map lock file v1 data to external nodes', () => {
89-
const lockFileData = parseNpmLockFile(npmLockFileV1YargsOnly);
108+
const lockFileData = parseNpmLockFile(npmLockFileV1YargsAndDevkit);
90109

91-
const partialGraph = mapLockFileDataToPartialGraph(lockFileData);
110+
const partialGraph = mapLockFileDataToPartialGraph(lockFileData, 'npm');
92111

93112
expect(partialGraph.externalNodes['npm:yargs']).toMatchSnapshot();
94113
expect(partialGraph.dependencies['npm:yargs']).toMatchSnapshot();
@@ -97,7 +116,7 @@ describe('lock-file', () => {
97116
it('should map successfully complex lock file v3', () => {
98117
const lockFileData = parseNpmLockFile(npmLockFileV3);
99118

100-
const partialGraph = mapLockFileDataToPartialGraph(lockFileData);
119+
const partialGraph = mapLockFileDataToPartialGraph(lockFileData, 'npm');
101120

102121
expect(partialGraph.externalNodes['npm:nx']).toMatchSnapshot();
103122
expect(partialGraph.dependencies['npm:nx']).toMatchSnapshot();
@@ -106,7 +125,7 @@ describe('lock-file', () => {
106125
it('should map successfully complex lock file v2', () => {
107126
const lockFileData = parseNpmLockFile(npmLockFileV2);
108127

109-
const partialGraph = mapLockFileDataToPartialGraph(lockFileData);
128+
const partialGraph = mapLockFileDataToPartialGraph(lockFileData, 'npm');
110129

111130
expect(partialGraph.externalNodes['npm:nx']).toMatchSnapshot();
112131
expect(partialGraph.dependencies['npm:nx']).toMatchSnapshot();
@@ -115,18 +134,34 @@ describe('lock-file', () => {
115134
it('should map successfully complex npm lock file v1', () => {
116135
const lockFileData = parseNpmLockFile(npmLockFileV1);
117136

118-
const partialGraph = mapLockFileDataToPartialGraph(lockFileData);
137+
const partialGraph = mapLockFileDataToPartialGraph(lockFileData, 'npm');
119138

120139
expect(partialGraph.externalNodes['npm:nx']).toMatchSnapshot();
121140
expect(partialGraph.dependencies['npm:nx']).toMatchSnapshot();
122141
});
123142
});
124143

125144
describe('pnpm', () => {
145+
const fileSys = {
146+
'node_modules/chalk/package.json': '{"version": "4.1.0"}',
147+
'node_modules/glob/package.json': '{"version": "7.1.4"}',
148+
'node_modules/js-yaml/package.json': '{"version": "4.1.0"}',
149+
'node_modules/minimatch/package.json': '{"version": "3.0.5"}',
150+
'node_modules/semver/package.json': '{"version": "7.3.4"}',
151+
'node_modules/tslib/package.json': '{"version": "2.4.0"}',
152+
'node_modules/yargs-parser/package.json': '{"version": "21.0.1"}',
153+
};
154+
beforeEach(() => {
155+
vol.fromJSON(fileSys, '/root');
156+
});
157+
126158
it('should map lock file data to external nodes', () => {
127159
const lockFileData = parsePnpmLockFile(pnpmLockFileYargsOnly);
128160

129-
const partialGraph = mapLockFileDataToPartialGraph(lockFileData);
161+
const partialGraph = mapLockFileDataToPartialGraph(
162+
lockFileData,
163+
'pnpm'
164+
);
130165

131166
expect(partialGraph.externalNodes['npm:yargs']).toMatchSnapshot();
132167
expect(partialGraph.dependencies['npm:yargs']).toMatchSnapshot();
@@ -135,7 +170,10 @@ describe('lock-file', () => {
135170
it('should map successfully complex lock file', () => {
136171
const lockFileData = parsePnpmLockFile(pnpmLockFile);
137172

138-
const partialGraph = mapLockFileDataToPartialGraph(lockFileData);
173+
const partialGraph = mapLockFileDataToPartialGraph(
174+
lockFileData,
175+
'pnpm'
176+
);
139177

140178
expect(partialGraph.externalNodes['npm:nx']).toMatchSnapshot();
141179
expect(partialGraph.dependencies['npm:nx']).toMatchSnapshot();

0 commit comments

Comments
 (0)