Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix wrong yarn patch key mapping #18759

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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