Skip to content

Commit

Permalink
feat: support NPM lockfile v3
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Oct 31, 2023
1 parent 883aadb commit 2d70387
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/lib/package-managers/npm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function walkLockfileV1(
}
}

function walkLockfileV2(
function walkLockfileV2V3(
root: Record<string, any>,
dir: string,
overrides: Record<string, ResolvedDependency>,
Expand Down Expand Up @@ -334,7 +334,8 @@ export class Npm extends PackageManager {

if (
rootPackageLock.lockfileVersion !== 1 &&
rootPackageLock.lockfileVersion !== 2
rootPackageLock.lockfileVersion !== 2 &&
rootPackageLock.lockfileVersion !== 3
) {
return fail(
`Lockfile version ${rootPackageLock.lockfileVersion} is not supported!`,
Expand All @@ -354,8 +355,11 @@ export class Npm extends PackageManager {
// Walk through the lockfile, edit it and find the package.jsons we need to update
const affectedPackageJsons = new Set<string>();
affectedPackageJsons.add(rootPackageJsonPath);
if (rootPackageLock.lockfileVersion === 2) {
walkLockfileV2(
if (
rootPackageLock.lockfileVersion === 2 ||
rootPackageLock.lockfileVersion === 3
) {
walkLockfileV2V3(
rootPackageLock,
root,
overrides,
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe("End to end tests - npm", () => {
const result = await npm.pack({
targetDir: path.join(testDir, "foo/bar"),
});
console.log(result.stdall);
// console.log(result.stdall);

expect(result.stdout).toBe(
path.join(testDir, "foo/bar/test-0.0.1.tgz"),
Expand All @@ -177,7 +177,7 @@ describe("End to end tests - npm", () => {
npm.cwd = testDir;

const result = await npm.pack();
console.log(result.stdall);
// console.log(result.stdall);
expect(result.stdout).toBe(
path.join(testDir, "scope-test-0.0.1-beta.0+1234.tgz"),
);
Expand Down

0 comments on commit 2d70387

Please sign in to comment.