Skip to content

Commit 2bc9e84

Browse files
authored
feat(core): support npm v1 lock file pruning with disclaimer (#13218)
1 parent c0deca8 commit 2bc9e84

File tree

4 files changed

+160
-94
lines changed

4 files changed

+160
-94
lines changed

e2e/vite/src/vite.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,13 @@ describe('Vite Plugin', () => {
135135
afterEach(() => killPorts());
136136

137137
it('should serve applications in dev mode', async () => {
138-
const p = await runCommandUntil(`run ${myApp}:serve`, (output) => {
139-
return output.includes('Local:');
140-
});
138+
const port = 4212;
139+
const p = await runCommandUntil(
140+
`run ${myApp}:serve --port=${port}`,
141+
(output) => {
142+
return output.includes('Local:');
143+
}
144+
);
141145
p.kill();
142146
}, 200000);
143147
});

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

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21565,34 +21565,13 @@ export const lockFileV1YargsAndDevkitOnly = `{
2156521565
"peer": true
2156621566
},
2156721567
"@yarnpkg/parsers": {
21568-
"version": "3.0.0-rc.28",
21569-
"resolved": "https://registry.npmjs.org/@yarnpkg/parsers/-/parsers-3.0.0-rc.28.tgz",
21570-
"integrity": "sha512-OdBYBaACPjFnqek4jtyR5VH7wX5i7BwfS0AP8m6hTqgULRVOLEc6TKxUBxMCTISzZPGdo5wWAB7OcMmU6G2UnA==",
21568+
"version": "3.0.0-rc.27",
21569+
"resolved": "https://registry.npmjs.org/@yarnpkg/parsers/-/parsers-3.0.0-rc.27.tgz",
21570+
"integrity": "sha512-qs2wZulOYVjaOS6tYOs3SsR7m/qeHwjPrB5i4JtBJELsgWrEkyL+rJH21RA+fVwttJobAYQqw5Xj5SYLaDK/bQ==",
2157121571
"peer": true,
2157221572
"requires": {
2157321573
"js-yaml": "^3.10.0",
2157421574
"tslib": "^2.4.0"
21575-
},
21576-
"dependencies": {
21577-
"argparse": {
21578-
"version": "1.0.10",
21579-
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
21580-
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
21581-
"peer": true,
21582-
"requires": {
21583-
"sprintf-js": "~1.0.2"
21584-
}
21585-
},
21586-
"js-yaml": {
21587-
"version": "3.14.1",
21588-
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz",
21589-
"integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==",
21590-
"peer": true,
21591-
"requires": {
21592-
"argparse": "^1.0.7",
21593-
"esprima": "^4.0.0"
21594-
}
21595-
}
2159621575
}
2159721576
},
2159821577
"@zkochan/js-yaml": {
@@ -21602,6 +21581,14 @@ export const lockFileV1YargsAndDevkitOnly = `{
2160221581
"peer": true,
2160321582
"requires": {
2160421583
"argparse": "^2.0.1"
21584+
},
21585+
"dependencies": {
21586+
"argparse": {
21587+
"version": "2.0.1",
21588+
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
21589+
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
21590+
"peer": true
21591+
}
2160521592
}
2160621593
},
2160721594
"ansi-colors": {
@@ -21634,10 +21621,13 @@ export const lockFileV1YargsAndDevkitOnly = `{
2163421621
}
2163521622
},
2163621623
"argparse": {
21637-
"version": "2.0.1",
21638-
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
21639-
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
21640-
"peer": true
21624+
"version": "1.0.10",
21625+
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
21626+
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
21627+
"peer": true,
21628+
"requires": {
21629+
"sprintf-js": "~1.0.2"
21630+
}
2164121631
},
2164221632
"async": {
2164321633
"version": "3.2.4",
@@ -21718,9 +21708,9 @@ export const lockFileV1YargsAndDevkitOnly = `{
2171821708
}
2171921709
},
2172021710
"chalk": {
21721-
"version": "4.1.2",
21722-
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
21723-
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
21711+
"version": "4.1.0",
21712+
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
21713+
"integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
2172421714
"requires": {
2172521715
"ansi-styles": "^4.1.0",
2172621716
"supports-color": "^7.1.0"
@@ -22127,21 +22117,13 @@ export const lockFileV1YargsAndDevkitOnly = `{
2212722117
}
2212822118
},
2212922119
"js-yaml": {
22130-
"version": "4.1.0",
22131-
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
22132-
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
22133-
"peer": true,
22134-
"requires": {
22135-
"argparse": "^2.0.1"
22136-
}
22137-
},
22138-
"json5": {
22139-
"version": "1.0.1",
22140-
"resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz",
22141-
"integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
22120+
"version": "3.14.1",
22121+
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz",
22122+
"integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==",
2214222123
"peer": true,
2214322124
"requires": {
22144-
"minimist": "^1.2.0"
22125+
"argparse": "^1.0.7",
22126+
"esprima": "^4.0.0"
2214522127
}
2214622128
},
2214722129
"jsonc-parser": {
@@ -22289,14 +22271,19 @@ export const lockFileV1YargsAndDevkitOnly = `{
2228922271
"yargs-parser": "21.1.1"
2229022272
},
2229122273
"dependencies": {
22292-
"chalk": {
22274+
"argparse": {
22275+
"version": "2.0.1",
22276+
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
22277+
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
22278+
"peer": true
22279+
},
22280+
"js-yaml": {
2229322281
"version": "4.1.0",
22294-
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
22295-
"integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
22282+
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
22283+
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
2229622284
"peer": true,
2229722285
"requires": {
22298-
"ansi-styles": "^4.1.0",
22299-
"supports-color": "^7.1.0"
22286+
"argparse": "^2.0.1"
2230022287
}
2230122288
},
2230222289
"minimatch": {
@@ -22481,12 +22468,6 @@ export const lockFileV1YargsAndDevkitOnly = `{
2248122468
"ansi-regex": "^5.0.1"
2248222469
}
2248322470
},
22484-
"strip-bom": {
22485-
"version": "3.0.0",
22486-
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
22487-
"integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==",
22488-
"peer": true
22489-
},
2249022471
"strong-log-transformer": {
2249122472
"version": "2.1.0",
2249222473
"resolved": "https://registry.npmjs.org/strong-log-transformer/-/strong-log-transformer-2.1.0.tgz",
@@ -22553,6 +22534,23 @@ export const lockFileV1YargsAndDevkitOnly = `{
2255322534
"json5": "^1.0.1",
2255422535
"minimist": "^1.2.6",
2255522536
"strip-bom": "^3.0.0"
22537+
},
22538+
"dependencies": {
22539+
"json5": {
22540+
"version": "1.0.1",
22541+
"resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz",
22542+
"integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
22543+
"peer": true,
22544+
"requires": {
22545+
"minimist": "^1.2.0"
22546+
}
22547+
},
22548+
"strip-bom": {
22549+
"version": "3.0.0",
22550+
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
22551+
"integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==",
22552+
"peer": true
22553+
}
2255622554
}
2255722555
},
2255822556
"tslib": {

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

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ import {
1414
lockFileV1YargsAndDevkitOnly,
1515
lockFileV2YargsAndDevkitOnly,
1616
} from './__fixtures__/npm.lock';
17+
import { vol } from 'memfs';
18+
import { readJsonFile } from '../fileutils';
19+
20+
jest.mock('fs', () => require('memfs').fs);
21+
22+
jest.mock('@nrwl/devkit', () => ({
23+
...jest.requireActual<any>('@nrwl/devkit'),
24+
workspaceRoot: '/root',
25+
}));
26+
27+
jest.mock('nx/src/utils/workspace-root', () => ({
28+
workspaceRoot: '/root',
29+
}));
1730

1831
describe('npm LockFile utility', () => {
1932
describe('v3', () => {
@@ -316,32 +329,48 @@ describe('npm LockFile utility', () => {
316329
expect(stringifyNpmLockFile(parsedLockFile)).toEqual(lockFileV1);
317330
});
318331

319-
xit('should prune the lock file', () => {
320-
expect(
321-
Object.keys(
322-
pruneNpmLockFile(parsedLockFile, ['typescript']).dependencies
323-
).length
324-
).toEqual(1);
325-
expect(
326-
Object.keys(
327-
pruneNpmLockFile(parsedLockFile, ['yargs', '@nrwl/devkit'])
328-
.dependencies
329-
).length
330-
).toEqual(136);
331-
});
332+
describe('pruning', () => {
333+
beforeAll(() => {
334+
const v2packages = JSON.parse(lockFileV2).packages;
335+
const fileSys = {};
336+
// map all v2 packages to the file system
337+
Object.keys(v2packages).forEach((key) => {
338+
if (key) {
339+
fileSys[`/root/${key}/package.json`] = JSON.stringify(
340+
v2packages[key]
341+
);
342+
}
343+
});
344+
vol.fromJSON(fileSys, '/root');
345+
});
332346

333-
xit('should correctly prune lockfile with single package', () => {
334-
expect(
335-
stringifyNpmLockFile(pruneNpmLockFile(parsedLockFile, ['typescript']))
336-
).toEqual(lockFileV1JustTypescript);
337-
});
347+
it('should prune the lock file', () => {
348+
expect(
349+
Object.keys(
350+
pruneNpmLockFile(parsedLockFile, ['typescript']).dependencies
351+
).length
352+
).toEqual(1);
353+
expect(
354+
Object.keys(
355+
pruneNpmLockFile(parsedLockFile, ['yargs', '@nrwl/devkit'])
356+
.dependencies
357+
).length
358+
).toEqual(136);
359+
});
338360

339-
xit('should correctly prune lockfile with multiple packages', () => {
340-
expect(
341-
stringifyNpmLockFile(
342-
pruneNpmLockFile(parsedLockFile, ['yargs', '@nrwl/devkit'])
343-
)
344-
).toEqual(lockFileV1YargsAndDevkitOnly);
361+
it('should correctly prune lockfile with single package', () => {
362+
expect(
363+
stringifyNpmLockFile(pruneNpmLockFile(parsedLockFile, ['typescript']))
364+
).toEqual(lockFileV1JustTypescript);
365+
});
366+
367+
it('should correctly prune lockfile with multiple packages', () => {
368+
expect(
369+
stringifyNpmLockFile(
370+
pruneNpmLockFile(parsedLockFile, ['yargs', '@nrwl/devkit'])
371+
)
372+
).toEqual(lockFileV1YargsAndDevkitOnly);
373+
});
345374
});
346375
});
347376
});

0 commit comments

Comments
 (0)