Skip to content

Commit

Permalink
fix(core): fix wrong yarn patch key mapping (#18759)
Browse files Browse the repository at this point in the history
(cherry picked from commit 42d93b0)
  • Loading branch information
meeroslav authored and FrozenPandaz committed Aug 23, 2023
1 parent e4d46b2 commit 944eeac
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
102 changes: 102 additions & 0 deletions packages/nx/src/plugins/js/lock-file/yarn-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2144,4 +2144,106 @@ __metadata:
`);
});
});

describe('patches', () => {
beforeEach(() => {
const fileSys = {
'node_modules/resolve/package.json': '{"version": "1.22.3"}',
};
vol.fromJSON(fileSys, '/root');
});

it('should keep the builtin patch', () => {
const lockFile = `# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!
__metadata:
version: 6
cacheKey: 8
"resolve@npm:^1.12.0, resolve@npm:^1.14.2, resolve@npm:^1.20.0, resolve@npm:^1.22.1":
version: 1.22.3
resolution: "resolve@npm:1.22.3"
dependencies:
is-core-module: ^2.12.0
path-parse: ^1.0.7
supports-preserve-symlinks-flag: ^1.0.0
bin:
resolve: bin/resolve
checksum: fb834b81348428cb545ff1b828a72ea28feb5a97c026a1cf40aa1008352c72811ff4d4e71f2035273dc536dcfcae20c13604ba6283c612d70fa0b6e44519c374
languageName: node
linkType: hard
"resolve@patch:resolve@^1.12.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.14.2#~builtin<compat/resolve>, resolve@patch:resolve@^1.20.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.22.1#~builtin<compat/resolve>":
version: 1.22.3
resolution: "resolve@patch:resolve@npm%3A1.22.3#~builtin<compat/resolve>::version=1.22.3&hash=c3c19d"
dependencies:
is-core-module: ^2.12.0
path-parse: ^1.0.7
supports-preserve-symlinks-flag: ^1.0.0
bin:
resolve: bin/resolve
checksum: ad59734723b596d0891321c951592ed9015a77ce84907f89c9d9307dd0c06e11a67906a3e628c4cae143d3e44898603478af0ddeb2bba3f229a9373efe342665
languageName: node
linkType: hard
`;

const packageJson: PackageJson = {
name: '@my-ns/example',
version: '0.0.1',
type: 'commonjs',
dependencies: {
resolve: '^1.12.0',
},
};
const builder = new ProjectGraphBuilder();
parseYarnLockfile(lockFile, packageJson, builder);
const graph = builder.getUpdatedProjectGraph();
const prunedGraph = pruneProjectGraph(graph, packageJson);
const result = stringifyYarnLockfile(prunedGraph, lockFile, packageJson);
expect(result).toMatchInlineSnapshot(`
"# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!
__metadata:
version: 6
cacheKey: 8
"@my-ns/example@workspace:.":
version: 0.0.0-use.local
resolution: "@my-ns/example@workspace:."
dependencies:
resolve: ^1.12.0
languageName: unknown
linkType: soft
"resolve@npm:^1.12.0":
version: 1.22.3
resolution: "resolve@npm:1.22.3"
dependencies:
is-core-module: ^2.12.0
path-parse: ^1.0.7
supports-preserve-symlinks-flag: ^1.0.0
bin:
resolve: bin/resolve
checksum: fb834b81348428cb545ff1b828a72ea28feb5a97c026a1cf40aa1008352c72811ff4d4e71f2035273dc536dcfcae20c13604ba6283c612d70fa0b6e44519c374
languageName: node
linkType: hard
"resolve@patch:resolve@^1.12.0#~builtin<compat/resolve>":
version: 1.22.3
resolution: "resolve@patch:resolve@npm%3A1.22.3#~builtin<compat/resolve>::version=1.22.3&hash=c3c19d"
dependencies:
is-core-module: ^2.12.0
path-parse: ^1.0.7
supports-preserve-symlinks-flag: ^1.0.0
bin:
resolve: bin/resolve
checksum: ad59734723b596d0891321c951592ed9015a77ce84907f89c9d9307dd0c06e11a67906a3e628c4cae143d3e44898603478af0ddeb2bba3f229a9373efe342665
languageName: node
linkType: hard
"
`);
});
});
});
3 changes: 1 addition & 2 deletions packages/nx/src/plugins/js/lock-file/yarn-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ function mapSnapshots(
if (isBerry && key.includes('@patch:') && key.includes('#')) {
normalizedKey = key
.slice(0, key.indexOf('#'))
.replace(`@patch:${packageName}@`, '@npm:')
.replace(/:.*$/u, ':' + snapshotKey.version);
.replace(`@patch:${packageName}@`, '@npm:');
}
if (
!existingKeys.get(packageName) ||
Expand Down

0 comments on commit 944eeac

Please # to comment.