Skip to content

Commit

Permalink
fix(core): fix lock file pruning multiple versions of dependencies (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
skrtheboss authored Dec 22, 2022
1 parent 3bb773d commit c51c178
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 36 deletions.
101 changes: 101 additions & 0 deletions packages/nx/src/lock-file/__fixtures__/npm.lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22952,3 +22952,104 @@ export const ssh2LockFileV3 = `{
}
}
`;

export const rxjsTslibLockFileV1 = `{
"name": "test",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"rxjs": {
"version": "7.8.0",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.0.tgz",
"integrity": "sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==",
"requires": {
"tslib": "^2.1.0"
}
},
"tslib": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
"integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA=="
}
}
}
`;
export const rxjsTslibLockFileV2 = `{
"name": "test",
"version": "0.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "test",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"rxjs": "^7.8.0",
"tslib": "^2.4.1"
}
},
"node_modules/rxjs": {
"version": "7.8.0",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.0.tgz",
"integrity": "sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==",
"dependencies": {
"tslib": "^2.1.0"
}
},
"node_modules/tslib": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
"integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA=="
}
},
"dependencies": {
"rxjs": {
"version": "7.8.0",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.0.tgz",
"integrity": "sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==",
"requires": {
"tslib": "^2.1.0"
}
},
"tslib": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
"integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA=="
}
}
}
`;

export const rxjsTslibLockFileV3 = `{
"name": "test",
"version": "0.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "test",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"rxjs": "^7.8.0",
"tslib": "^2.4.1"
}
},
"node_modules/rxjs": {
"version": "7.8.0",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.0.tgz",
"integrity": "sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==",
"dependencies": {
"tslib": "^2.1.0"
}
},
"node_modules/tslib": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
"integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA=="
}
}
}
`;
25 changes: 24 additions & 1 deletion packages/nx/src/lock-file/__fixtures__/pnpm.lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5776,7 +5776,7 @@ packages:
export const lockFileYargsAndDevkit = `lockfileVersion: 5.4
specifiers:
'@nrwl/devkit': 15.1.0
'@nrwl/devkit': 15.0.13
yargs: 17.6.2
dependencies:
Expand Down Expand Up @@ -6803,3 +6803,26 @@ packages:
resolution: {integrity: sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==}
dev: false
`;

export const rxjsTslibLockFile = `lockfileVersion: 5.4
specifiers:
rxjs: ^7.8.0
tslib: ^2.4.1
dependencies:
rxjs: 7.8.0
tslib: 2.4.1
packages:
/rxjs/7.8.0:
resolution: {integrity: sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==}
dependencies:
tslib: 2.4.1
dev: false
/tslib/2.4.1:
resolution: {integrity: sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==}
dev: false
`;
60 changes: 60 additions & 0 deletions packages/nx/src/lock-file/__fixtures__/yarn.lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8848,3 +8848,63 @@ __metadata:
languageName: node
linkType: hard
`;

/*
{
name: 'test',
version: '0.0.0',
dependencies: {
rxjs: '^7.8.0',
tslib: '^2.4.1',
},
}
*/

export const rxjsTslibLockFile = `# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
rxjs@^7.8.0:
version "7.8.0"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.0.tgz#90a938862a82888ff4c7359811a595e14e1e09a4"
integrity sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==
dependencies:
tslib "^2.1.0"
tslib@^2.1.0, tslib@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BO
`;

export const berryRxjsTslibLockFile = `# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!
__metadata:
version: 6
cacheKey: 8
"rxjs@npm:^7.8.0":
version: 7.8.0
resolution: "rxjs@npm:7.8.0"
dependencies:
tslib: ^2.1.0
checksum: 61b4d4fd323c1043d8d6ceb91f24183b28bcf5def4f01ca111511d5c6b66755bc5578587fe714ef5d67cf4c9f2e26f4490d4e1d8cabf9bd5967687835e9866a2
languageName: node
linkType: hard
"test@workspace:.":
version: 0.0.0-use.local
resolution: "test@workspace:."
dependencies:
rxjs: ^7.8.0
tslib: ^2.4.1
languageName: unknown
linkType: soft
"tslib@npm:^2.1.0, tslib@npm:^2.4.1":
version: 2.4.1
resolution: "tslib@npm:2.4.1"
checksum: 19480d6e0313292bd6505d4efe096a6b31c70e21cf08b5febf4da62e95c265c8f571f7b36fcc3d1a17e068032f59c269fab3459d6cd3ed6949eafecf64315fca
languageName: node
`;
56 changes: 50 additions & 6 deletions packages/nx/src/lock-file/npm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import {
stringifyNpmLockFile,
} from './npm';
import {
lockFileV2,
lockFileV1,
lockFileV3,
lockFileV3JustTypescript,
lockFileV3YargsAndDevkitOnly,
lockFileV2JustTypescript,
lockFileV1JustTypescript,
lockFileV1YargsAndDevkitOnly,
lockFileV2,
lockFileV2JustTypescript,
lockFileV2YargsAndDevkitOnly,
lockFileV3,
lockFileV3JustTypescript,
lockFileV3YargsAndDevkitOnly,
rxjsTslibLockFileV1,
rxjsTslibLockFileV2,
rxjsTslibLockFileV3,
ssh2LockFileV1,
ssh2LockFileV2,
ssh2LockFileV3,
ssh2LockFileV1,
} from './__fixtures__/npm.lock';
import { vol } from 'memfs';
import { npmLockFileWithWorkspaces } from './__fixtures__/workspaces.lock';
Expand Down Expand Up @@ -48,6 +51,14 @@ const Ssh2Package = {
ssh2: '1.11.0',
},
};
const RxjsTslibPackage = {
name: 'test',
version: '0.0.0',
dependencies: {
rxjs: '^7.8.0',
tslib: '^2.4.1',
},
};

describe('npm LockFile utility', () => {
describe('v3', () => {
Expand Down Expand Up @@ -176,6 +187,17 @@ describe('npm LockFile utility', () => {
)
).toEqual(ssh2LockFileV3);
});

it('should correctly prune lockfile with packages in multiple versions', () => {
expect(
stringifyNpmLockFile(
pruneNpmLockFile(
parseNpmLockFile(rxjsTslibLockFileV3),
RxjsTslibPackage
)
)
).toEqual(rxjsTslibLockFileV3);
});
});

describe('v2', () => {
Expand Down Expand Up @@ -310,6 +332,17 @@ describe('npm LockFile utility', () => {
)
).toEqual(ssh2LockFileV2);
});

it('should correctly prune lockfile with packages in multiple versions', () => {
expect(
stringifyNpmLockFile(
pruneNpmLockFile(
parseNpmLockFile(rxjsTslibLockFileV2),
RxjsTslibPackage
)
)
).toEqual(rxjsTslibLockFileV2);
});
});

describe('v1', () => {
Expand Down Expand Up @@ -438,6 +471,17 @@ describe('npm LockFile utility', () => {
)
).toEqual(ssh2LockFileV1);
});

it('should correctly prune lockfile with packages in multiple versions', () => {
expect(
stringifyNpmLockFile(
pruneNpmLockFile(
parseNpmLockFile(rxjsTslibLockFileV1),
RxjsTslibPackage
)
)
).toEqual(rxjsTslibLockFileV1);
});
});
});
});
20 changes: 20 additions & 0 deletions packages/nx/src/lock-file/pnpm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
lockFileJustTypescript,
lockFileWithInlineSpecifiers,
lockFileYargsAndDevkit,
rxjsTslibLockFile,
ssh2LockFile,
} from './__fixtures__/pnpm.lock';
import {
Expand All @@ -32,6 +33,14 @@ const Ssh2Package = {
ssh2: '1.11.0',
},
};
const RxjsTslibPackage = {
name: 'test',
version: '0.0.0',
dependencies: {
rxjs: '^7.8.0',
tslib: '^2.4.1',
},
};

describe('pnpm LockFile utility', () => {
describe('standard lock file', () => {
Expand Down Expand Up @@ -169,6 +178,17 @@ describe('pnpm LockFile utility', () => {
)
).toEqual(ssh2LockFile);
});

it('should correctly prune lockfile with packages in multiple versions', () => {
expect(
stringifyPnpmLockFile(
prunePnpmLockFile(
parsePnpmLockFile(rxjsTslibLockFile),
RxjsTslibPackage
)
)
).toEqual(rxjsTslibLockFile);
});
});

it('should parse lockfile with time-based resolution and workspaces', () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/nx/src/lock-file/pnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
PackageDependency,
PackageVersions,
} from './utils/lock-file-type';
import { load, dump } from '@zkochan/js-yaml';
import { TransitiveLookupFunctionInput, isRootVersion } from './utils/mapping';
import { hashString, generatePrunnedHash } from './utils/hashing';
import { dump, load } from '@zkochan/js-yaml';
import { isRootVersion, TransitiveLookupFunctionInput } from './utils/mapping';
import { generatePrunnedHash, hashString } from './utils/hashing';
import { satisfies } from 'semver';
import { PackageJsonDeps } from './utils/pruning';
import { sortObjectByKeys } from '../utils/object-sort';
Expand Down Expand Up @@ -422,11 +422,11 @@ function pruneDependencies(
): LockFileData['dependencies'] {
const result: LockFileData['dependencies'] = {};

Object.keys({
Object.entries({
...normalizedPackageJson.dependencies,
...normalizedPackageJson.devDependencies,
...normalizedPackageJson.peerDependencies,
}).forEach((packageName) => {
}).forEach(([packageName, packageVersion]) => {
if (dependencies[packageName]) {
const [key, { packageMeta, ...value }] = Object.entries(
dependencies[packageName]
Expand All @@ -446,7 +446,7 @@ function pruneDependencies(
isDevDependency:
!!normalizedPackageJson.devDependencies?.[packageName],
key: meta.key,
specifier: value.version,
specifier: packageVersion,
dependencyDetails: meta.dependencyDetails,
},
],
Expand Down
Loading

1 comment on commit c51c178

@vercel
Copy link

@vercel vercel bot commented on c51c178 Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.