fix(core): ensure correct hoisted packages detection with pnpm parser (#26153)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Miroslav Jonaš 2024-05-28 19:49:34 +02:00 committed by GitHub
parent 2b820a274e
commit c7bea55d59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 56 additions and 15 deletions

View File

@ -249,7 +249,7 @@ hoistedDependencies:
to-regex-range: private
/tsconfig-paths/4.1.2:
tsconfig-paths: private
/tslib/2.4.1:
/tslib/2.5.0:
tslib: private
/universalify/2.0.0:
universalify: private

View File

@ -55,7 +55,7 @@ packages:
ignore: 5.2.4
nx: 15.4.5
semver: 7.3.4
tslib: 2.4.1
tslib: 2.5.0
transitivePeerDependencies:
- typescript
dev: false
@ -98,7 +98,7 @@ packages:
engines: {node: '>=14.15.0'}
dependencies:
js-yaml: 3.14.1
tslib: 2.4.1
tslib: 2.5.0
dev: false
/@zkochan/js-yaml/0.0.6:
@ -698,7 +698,7 @@ packages:
tar-stream: 2.2.0
tmp: 0.2.1
tsconfig-paths: 4.1.2
tslib: 2.4.1
tslib: 2.5.0
v8-compile-cache: 2.3.0
yargs: 17.6.2
yargs-parser: 21.1.1
@ -900,8 +900,8 @@ packages:
strip-bom: 3.0.0
dev: false
/tslib/2.4.1:
resolution: {integrity: sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==}
/tslib/2.5.0:
resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==}
dev: false
/typescript/4.8.4:

View File

@ -57,7 +57,7 @@ packages:
ignore: 5.2.4
nx: 15.4.5
semver: 7.3.4
tslib: 2.4.1
tslib: 2.5.0
transitivePeerDependencies:
- typescript
dev: true
@ -73,7 +73,7 @@ packages:
'@nrwl/devkit': 15.4.5_nx@15.4.5+typescript@4.8.4
'@phenomnomnominal/tsquery': 4.1.1_typescript@4.8.4
tmp: 0.2.1
tslib: 2.4.1
tslib: 2.5.0
transitivePeerDependencies:
- nx
- typescript
@ -121,7 +121,7 @@ packages:
rxjs: 6.6.7
semver: 7.3.4
tmp: 0.2.1
tslib: 2.4.1
tslib: 2.5.0
yargs: 17.6.2
yargs-parser: 21.1.1
transitivePeerDependencies:
@ -159,7 +159,7 @@ packages:
engines: {node: '>=14.15.0'}
dependencies:
js-yaml: 3.14.1
tslib: 2.4.1
tslib: 2.5.0
dev: true
/@zkochan/js-yaml/0.0.6:
@ -759,7 +759,7 @@ packages:
tar-stream: 2.2.0
tmp: 0.2.1
tsconfig-paths: 4.1.2
tslib: 2.4.1
tslib: 2.5.0
v8-compile-cache: 2.3.0
yargs: 17.6.2
yargs-parser: 21.1.1
@ -978,8 +978,8 @@ packages:
resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==}
dev: true
/tslib/2.4.1:
resolution: {integrity: sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==}
/tslib/2.5.0:
resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==}
dev: true
/typescript/4.8.4:

View File

@ -654,7 +654,6 @@ describe('pnpm LockFile utility', () => {
'node_modules/cliui/package.json': '{"version": "7.0.4"}',
'node_modules/js-yaml/package.json': '{"version": "4.1.0"}',
'node_modules/minimatch/package.json': '{"version": "3.0.5"}',
'node_modules/tslib/package.json': '{"version": "2.4.1"}',
'node_modules/.modules.yaml': require(joinPathFragments(
__dirname,
'__fixtures__/pruning/.modules.yaml'
@ -709,6 +708,20 @@ describe('pnpm LockFile utility', () => {
graph = builder.getUpdatedProjectGraph();
});
it('should parse hoisted versions', () => {
expect(graph.externalNodes['npm:tslib']).toMatchInlineSnapshot(`
{
"data": {
"hash": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==",
"packageName": "tslib",
"version": "2.5.0",
},
"name": "npm:tslib",
"type": "npm",
}
`);
});
it('should prune single package', () => {
const typescriptPackageJson = require(joinPathFragments(
__dirname,
@ -794,6 +807,20 @@ describe('pnpm LockFile utility', () => {
graph = builder.getUpdatedProjectGraph();
});
it('should parse hoisted versions', () => {
expect(graph.externalNodes['npm:tslib']).toMatchInlineSnapshot(`
{
"data": {
"hash": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==",
"packageName": "tslib",
"version": "2.5.0",
},
"name": "npm:tslib",
"type": "npm",
}
`);
});
it('should prune single package', () => {
const typescriptPackageJson = require(joinPathFragments(
__dirname,
@ -879,6 +906,20 @@ describe('pnpm LockFile utility', () => {
graph = builder.getUpdatedProjectGraph();
});
it('should parse hoisted versions', () => {
expect(graph.externalNodes['npm:tslib']).toMatchInlineSnapshot(`
{
"data": {
"hash": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==",
"packageName": "tslib",
"version": "2.5.0",
},
"name": "npm:tslib",
"type": "npm",
}
`);
});
it('should prune single package', () => {
const typescriptPackageJson = require(joinPathFragments(
__dirname,

View File

@ -338,7 +338,7 @@ function getHoistedVersion(
if (!version) {
const key = Object.keys(hoistedDependencies).find((k) =>
k.startsWith(isV5 ? `/${packageName}/` : `/${packageName}@`)
k.startsWith(`/${packageName}/`)
);
if (key) {
version = parseBaseVersion(getVersion(key.slice(1), packageName), isV5);