fix(core): support yarn berry patches in pruned lock file (#15993)
This commit is contained in:
parent
d9c55aa17c
commit
30f993e57e
@ -1037,6 +1037,7 @@ __metadata:
|
|||||||
"@nrwl/devkit": 15.0.13
|
"@nrwl/devkit": 15.0.13
|
||||||
eslint-plugin-disable-autofix: "npm:@mattlewis92/eslint-plugin-disable-autofix@3.0.0"
|
eslint-plugin-disable-autofix: "npm:@mattlewis92/eslint-plugin-disable-autofix@3.0.0"
|
||||||
postgres: "https://github.com/charsleysa/postgres.git#commit=3b1a01b2da3e2fafb1a79006f838eff11a8de3cb"
|
postgres: "https://github.com/charsleysa/postgres.git#commit=3b1a01b2da3e2fafb1a79006f838eff11a8de3cb"
|
||||||
|
typescript: 4.8.4
|
||||||
yargs: 17.6.2
|
yargs: 17.6.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
react: 18.2.0
|
react: 18.2.0
|
||||||
@ -1073,6 +1074,26 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"typescript@npm:4.8.4":
|
||||||
|
version: 4.8.4
|
||||||
|
resolution: "typescript@npm:4.8.4"
|
||||||
|
bin:
|
||||||
|
tsc: bin/tsc
|
||||||
|
tsserver: bin/tsserver
|
||||||
|
checksum: ee000bc26848147ad423b581bd250075662a354d84f0e06eb76d3b892328d8d4440b7487b5a83e851b12b255f55d71835b008a66cbf8f255a11e4400159237db
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
|
"typescript@patch:typescript@4.8.4#~builtin<compat/typescript>":
|
||||||
|
version: 4.8.4
|
||||||
|
resolution: "typescript@patch:typescript@npm%3A4.8.4#~builtin<compat/typescript>::version=4.8.4&hash=23ec76"
|
||||||
|
bin:
|
||||||
|
tsc: bin/tsc
|
||||||
|
tsserver: bin/tsserver
|
||||||
|
checksum: ab417a2f398380c90a6cf5a5f74badd17866adf57f1165617d6a551f059c3ba0a3e4da0d147b3ac5681db9ac76a303c5876394b13b3de75fdd5b1eaa06181c9d
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"uri-js@npm:^4.2.2":
|
"uri-js@npm:^4.2.2":
|
||||||
version: 4.4.1
|
version: 4.4.1
|
||||||
resolution: "uri-js@npm:4.4.1"
|
resolution: "uri-js@npm:4.4.1"
|
||||||
|
|||||||
@ -1074,6 +1074,26 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"typescript@npm:4.8.4":
|
||||||
|
version: 4.8.4
|
||||||
|
resolution: "typescript@npm:4.8.4"
|
||||||
|
bin:
|
||||||
|
tsc: bin/tsc
|
||||||
|
tsserver: bin/tsserver
|
||||||
|
checksum: ee000bc26848147ad423b581bd250075662a354d84f0e06eb76d3b892328d8d4440b7487b5a83e851b12b255f55d71835b008a66cbf8f255a11e4400159237db
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
|
"typescript@patch:typescript@4.8.4#~builtin<compat/typescript>":
|
||||||
|
version: 4.8.4
|
||||||
|
resolution: "typescript@patch:typescript@npm%3A4.8.4#~builtin<compat/typescript>::version=4.8.4&hash=23ec76"
|
||||||
|
bin:
|
||||||
|
tsc: bin/tsc
|
||||||
|
tsserver: bin/tsserver
|
||||||
|
checksum: ab417a2f398380c90a6cf5a5f74badd17866adf57f1165617d6a551f059c3ba0a3e4da0d147b3ac5681db9ac76a303c5876394b13b3de75fdd5b1eaa06181c9d
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"uri-js@npm:^4.2.2":
|
"uri-js@npm:^4.2.2":
|
||||||
version: 4.4.1
|
version: 4.4.1
|
||||||
resolution: "uri-js@npm:4.4.1"
|
resolution: "uri-js@npm:4.4.1"
|
||||||
|
|||||||
@ -369,7 +369,7 @@ describe('yarn LockFile utility', () => {
|
|||||||
const builder = new ProjectGraphBuilder();
|
const builder = new ProjectGraphBuilder();
|
||||||
parseYarnLockfile(berryLockFile, builder);
|
parseYarnLockfile(berryLockFile, builder);
|
||||||
const graph = builder.getUpdatedProjectGraph();
|
const graph = builder.getUpdatedProjectGraph();
|
||||||
expect(Object.keys(graph.externalNodes).length).toEqual(128); //124 hoisted
|
expect(Object.keys(graph.externalNodes).length).toEqual(129); //124 hoisted
|
||||||
|
|
||||||
expect(graph.externalNodes['npm:minimatch']).toMatchInlineSnapshot(`
|
expect(graph.externalNodes['npm:minimatch']).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
@ -433,6 +433,7 @@ describe('yarn LockFile utility', () => {
|
|||||||
'npm:@mattlewis92/eslint-plugin-disable-autofix@3.0.0',
|
'npm:@mattlewis92/eslint-plugin-disable-autofix@3.0.0',
|
||||||
postgres:
|
postgres:
|
||||||
'https://github.com/charsleysa/postgres.git#commit=3b1a01b2da3e2fafb1a79006f838eff11a8de3cb',
|
'https://github.com/charsleysa/postgres.git#commit=3b1a01b2da3e2fafb1a79006f838eff11a8de3cb',
|
||||||
|
typescript: '4.8.4',
|
||||||
yargs: '17.6.2',
|
yargs: '17.6.2',
|
||||||
},
|
},
|
||||||
devDependencies: {
|
devDependencies: {
|
||||||
@ -930,7 +931,7 @@ __metadata:
|
|||||||
const prunedGraph = pruneProjectGraph(graph, prunedPackageJson);
|
const prunedGraph = pruneProjectGraph(graph, prunedPackageJson);
|
||||||
expect(stringifyYarnLockfile(prunedGraph, lockFile, prunedPackageJson))
|
expect(stringifyYarnLockfile(prunedGraph, lockFile, prunedPackageJson))
|
||||||
.toMatchInlineSnapshot(`
|
.toMatchInlineSnapshot(`
|
||||||
"# This file was generated by Nx. Do not edit this file directly
|
"# This file is generated by running \\"yarn install\\" inside your project.
|
||||||
# Manual changes might be lost - proceed with caution!
|
# Manual changes might be lost - proceed with caution!
|
||||||
|
|
||||||
__metadata:
|
__metadata:
|
||||||
|
|||||||
@ -58,8 +58,8 @@ function addNodes(
|
|||||||
const nodes: Map<string, Map<string, ProjectGraphExternalNode>> = new Map();
|
const nodes: Map<string, Map<string, ProjectGraphExternalNode>> = new Map();
|
||||||
|
|
||||||
Object.entries(dependencies).forEach(([keys, snapshot]) => {
|
Object.entries(dependencies).forEach(([keys, snapshot]) => {
|
||||||
// ignore workspace projects
|
// ignore workspace projects & patches
|
||||||
if (snapshot.linkType === 'soft') {
|
if (snapshot.linkType === 'soft' || keys.includes('@patch:')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const packageName = keys.slice(0, keys.indexOf('@', 1));
|
const packageName = keys.slice(0, keys.indexOf('@', 1));
|
||||||
@ -313,13 +313,28 @@ function mapSnapshots(
|
|||||||
snapshotMap.get(snapshot).add(requestedKey);
|
snapshotMap.get(snapshot).add(requestedKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isBerry) {
|
||||||
|
// look for patched versions
|
||||||
|
const patch = findPatchedKeys(groupedDependencies, node);
|
||||||
|
if (patch) {
|
||||||
|
const [matchedKeys, snapshot] = patch;
|
||||||
|
snapshotMap.set(snapshot, new Set(matchedKeys));
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove keys that match version ranges that have been pruned away
|
// remove keys that match version ranges that have been pruned away
|
||||||
snapshotMap.forEach((keysSet) => {
|
snapshotMap.forEach((keysSet) => {
|
||||||
for (const key of keysSet.values()) {
|
for (const key of keysSet.values()) {
|
||||||
const packageName = key.slice(0, key.indexOf('@', 1));
|
const packageName = key.slice(0, key.indexOf('@', 1));
|
||||||
if (!existingKeys.get(packageName).has(key)) {
|
let normalizedKey = key;
|
||||||
|
if (isBerry && key.includes('@patch:') && key.includes('#')) {
|
||||||
|
normalizedKey = key
|
||||||
|
.slice(0, key.indexOf('#'))
|
||||||
|
.replace(`@patch:${packageName}@`, '@npm:');
|
||||||
|
}
|
||||||
|
if (!existingKeys.get(packageName).has(normalizedKey)) {
|
||||||
keysSet.delete(key);
|
keysSet.delete(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -414,7 +429,23 @@ function findOriginalKeys(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const BERRY_LOCK_FILE_DISCLAIMER = `# This file was generated by Nx. Do not edit this file directly\n# Manual changes might be lost - proceed with caution!\n\n`;
|
function findPatchedKeys(
|
||||||
|
dependencies: Record<string, YarnDependency>,
|
||||||
|
node: ProjectGraphExternalNode
|
||||||
|
): [string[], YarnDependency] | void {
|
||||||
|
for (const keyExpr of Object.keys(dependencies)) {
|
||||||
|
const snapshot = dependencies[keyExpr];
|
||||||
|
const keys = keyExpr.split(', ');
|
||||||
|
if (!keys[0].startsWith(`${node.data.packageName}@patch:`)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (snapshot.version === node.data.version) {
|
||||||
|
return [keys, snapshot];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const BERRY_LOCK_FILE_DISCLAIMER = `# This file is generated by running "yarn install" inside your project.\n# Manual changes might be lost - proceed with caution!\n\n`;
|
||||||
|
|
||||||
function generateRootWorkspacePackage(
|
function generateRootWorkspacePackage(
|
||||||
packageJson: NormalizedPackageJson
|
packageJson: NormalizedPackageJson
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user