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(version): Ignore npm lifecycle scripts on package lock update #3295

Merged
merged 2 commits into from
Aug 16, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions commands/version/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,11 @@ class VersionCommand extends Command {
if (fs.existsSync(lockfilePath)) {
chain = chain.then(() => {
this.logger.verbose("version", "Updating root package-lock.json");
return childProcess.exec("npm", ["install", "--package-lock-only"], this.execOpts).then(() => {
changedFiles.add(lockfilePath);
});
return childProcess
.exec("npm", ["install", "--package-lock-only", "--ignore-scripts"], this.execOpts)
.then(() => {
changedFiles.add(lockfilePath);
});
});
}
}
Expand Down
39 changes: 39 additions & 0 deletions e2e/tests/lerna-version/npm-workspaces.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,43 @@ describe("lerna-version-with-workspaces", () => {
expect(packages["packages/package-b"].version).toEqual("3.3.3");
expect(packages["packages/package-b"].dependencies["package-a"]).toEqual("^3.3.3");
});

it("should not run npm install lifecycle scripts, but still update package-lock.json", async () => {
await fixture.updateJson("package.json", (json) => ({
...json,
scripts: {
preinstall: "exit 1",
install: "exit 1",
postinstall: "exit 1",
prepublish: "exit 1",
prepare: "exit 1",
},
}));
await fixture.exec("git add package.json");
await fixture.exec("git commit -m 'update package.json with failing install lifecycle scripts'");

const output = await fixture.lerna("version 3.3.3 -y");
expect(output.combinedOutput).toMatchInlineSnapshot(`
lerna notice cli v999.9.9-e2e.0
lerna info current version 0.0.0
lerna info Assuming all packages changed

Changes:
- package-a: 0.0.0 => 3.3.3
- package-b: 0.0.0 => 3.3.3

lerna info auto-confirmed
lerna info execute Skipping releases
lerna info git Pushing tags...
lerna success version finished

`);

const packageLockJson = await fixture.readWorkspaceFile("package-lock.json");
const packages = JSON.parse(packageLockJson).packages;

expect(packages["packages/package-a"].version).toEqual("3.3.3");
expect(packages["packages/package-b"].version).toEqual("3.3.3");
expect(packages["packages/package-b"].dependencies["package-a"]).toEqual("^3.3.3");
});
});