diff --git a/commands/publish/__tests__/publish-lifecycle-scripts.test.js b/commands/publish/__tests__/publish-lifecycle-scripts.test.js index 267fc81735..ebf1ac89db 100644 --- a/commands/publish/__tests__/publish-lifecycle-scripts.test.js +++ b/commands/publish/__tests__/publish-lifecycle-scripts.test.js @@ -136,4 +136,27 @@ Map { // runLifecycle() is _called_ with "prepublish" for root, // but it does not actually execute, and is tested elsewhere }); + + it("respects --ignore-scripts", async () => { + const cwd = await initFixture("lifecycle"); + + await lernaPublish(cwd)("--ignore-scripts"); + + // despite all the scripts being passed to runLifecycle() (and implicitly, packDirectory()), + // none of them will actually execute as long as opts["ignore-scripts"] is provided + expect(runLifecycle).toHaveBeenCalledWith( + expect.objectContaining({ name: "lifecycle" }), + "prepare", + expect.objectContaining({ + "ignore-scripts": true, + }) + ); + expect(packDirectory).toHaveBeenCalledWith( + expect.objectContaining({ name: "package-2" }), + path.join(cwd, "packages/package-2"), + expect.objectContaining({ + "ignore-scripts": true, + }) + ); + }); }); diff --git a/commands/publish/command.js b/commands/publish/command.js index a768374e29..4498b157ea 100644 --- a/commands/publish/command.js +++ b/commands/publish/command.js @@ -50,6 +50,10 @@ exports.builder = yargs => { describe: "Disable deprecated 'prepublish' lifecycle script", type: "boolean", }, + "ignore-scripts": { + describe: "Disable all lifecycle scripts", + type: "boolean", + }, otp: { describe: "Supply a one-time password for publishing with two-factor authentication.", type: "string", @@ -99,7 +103,7 @@ exports.builder = yargs => { // "unhide" duplicate options const { hiddenOptions } = yargs.getOptions(); - const sharedKeys = ["preid", "y"]; + const sharedKeys = ["preid", "y", "ignore-scripts"]; for (const sharedKey of sharedKeys) { hiddenOptions.splice(hiddenOptions.findIndex(k => k === sharedKey), 1); diff --git a/commands/publish/index.js b/commands/publish/index.js index 6f3f1813f4..4d5466737f 100644 --- a/commands/publish/index.js +++ b/commands/publish/index.js @@ -121,6 +121,7 @@ class PublishCommand extends Command { otp: this.options.otp, registry: this.options.registry, "ignore-prepublish": this.options.ignorePrepublish, + "ignore-scripts": this.options.ignoreScripts, }); // cache to hold a one-time-password across publishes diff --git a/commands/version/__tests__/version-lifecycle-scripts.test.js b/commands/version/__tests__/version-lifecycle-scripts.test.js index 8b83bb1b16..f39581f442 100644 --- a/commands/version/__tests__/version-lifecycle-scripts.test.js +++ b/commands/version/__tests__/version-lifecycle-scripts.test.js @@ -95,4 +95,20 @@ Map { ["package-1", "postversion"], ]); }); + + it("respects --ignore-scripts", async () => { + const cwd = await initFixture("lifecycle"); + + await lernaVersion(cwd)("--ignore-scripts"); + + // despite all the scripts being passed to runLifecycle() + // none of them will actually execute as long as opts["ignore-scripts"] is provided + expect(runLifecycle).toHaveBeenCalledWith( + expect.objectContaining({ name: "lifecycle" }), + "version", + expect.objectContaining({ + "ignore-scripts": true, + }) + ); + }); }); diff --git a/commands/version/command.js b/commands/version/command.js index 9a2728ebe3..aff861b8f6 100644 --- a/commands/version/command.js +++ b/commands/version/command.js @@ -52,6 +52,10 @@ exports.builder = (yargs, composed) => { ].join("\n"), type: "array", }, + "ignore-scripts": { + describe: "Disable all lifecycle scripts", + type: "boolean", + }, "include-merged-tags": { describe: "Also include tags from merged branches", type: "boolean", diff --git a/integration/lerna-publish-lifecycle.test.js b/integration/lerna-publish-lifecycle.test.js index 409237a13f..762498da53 100644 --- a/integration/lerna-publish-lifecycle.test.js +++ b/integration/lerna-publish-lifecycle.test.js @@ -124,3 +124,20 @@ test("lerna publish --ignore-prepublish", async () => { expect(stdout).not.toContain("prepublish-root"); expect(stdout).not.toContain("prepublish-package-2"); }); + +test("lerna publish --ignore-scripts", async () => { + const { cwd } = await cloneFixture("lifecycle"); + const args = ["publish", "--ignore-scripts", "major", "--yes", "--loglevel=verbose"]; + + const { stdout } = await cliRunner(cwd, env)(...args); + expect(stdout).toMatchInlineSnapshot(` + + Changes: + - package-1: 1.0.0 => 2.0.0 + - package-2: 1.0.0 => 2.0.0 + + Successfully published: + - package-1@2.0.0 + - package-2@2.0.0 + `); +});