From fa217231c95d306bfdd3ffaf348c936a3232c998 Mon Sep 17 00:00:00 2001 From: Daniel Stockman Date: Mon, 14 Oct 2019 14:49:58 -0700 Subject: [PATCH] fix(options): Explicit `--ignore-prepublish` --- .../__tests__/publish-lifecycle-scripts.test.js | 17 +++++++++++++++++ commands/publish/command.js | 4 ++++ commands/publish/index.js | 1 + integration/lerna-publish-lifecycle.test.js | 9 +++++++++ 4 files changed, 31 insertions(+) diff --git a/commands/publish/__tests__/publish-lifecycle-scripts.test.js b/commands/publish/__tests__/publish-lifecycle-scripts.test.js index 9cf38a469d..267fc81735 100644 --- a/commands/publish/__tests__/publish-lifecycle-scripts.test.js +++ b/commands/publish/__tests__/publish-lifecycle-scripts.test.js @@ -119,4 +119,21 @@ Map { // (they are all run by pack-directory and npm-publish) ]); }); + + it("respects --ignore-prepublish", async () => { + const cwd = await initFixture("lifecycle"); + + await lernaPublish(cwd)("--ignore-prepublish"); + + expect(packDirectory).toHaveBeenCalledWith( + expect.objectContaining({ name: "package-2" }), + path.join(cwd, "packages/package-2"), + expect.objectContaining({ + "ignore-prepublish": true, + }) + ); + + // runLifecycle() is _called_ with "prepublish" for root, + // but it does not actually execute, and is tested elsewhere + }); }); diff --git a/commands/publish/command.js b/commands/publish/command.js index 57b905383c..a768374e29 100644 --- a/commands/publish/command.js +++ b/commands/publish/command.js @@ -46,6 +46,10 @@ exports.builder = yargs => { choices: ["all", "dependencies"], defaultDescription: "dependencies", }, + "ignore-prepublish": { + describe: "Disable deprecated 'prepublish' lifecycle script", + type: "boolean", + }, otp: { describe: "Supply a one-time password for publishing with two-factor authentication.", type: "string", diff --git a/commands/publish/index.js b/commands/publish/index.js index d4746943c7..6f3f1813f4 100644 --- a/commands/publish/index.js +++ b/commands/publish/index.js @@ -120,6 +120,7 @@ class PublishCommand extends Command { npmVersion: this.userAgent, otp: this.options.otp, registry: this.options.registry, + "ignore-prepublish": this.options.ignorePrepublish, }); // cache to hold a one-time-password across publishes diff --git a/integration/lerna-publish-lifecycle.test.js b/integration/lerna-publish-lifecycle.test.js index cd0191ad9d..409237a13f 100644 --- a/integration/lerna-publish-lifecycle.test.js +++ b/integration/lerna-publish-lifecycle.test.js @@ -115,3 +115,12 @@ Successfully published: - package-2@1.1.0 `); }); + +test("lerna publish --ignore-prepublish", async () => { + const { cwd } = await cloneFixture("lifecycle"); + const args = ["publish", "--ignore-prepublish", "patch", "--yes"]; + + const { stdout } = await cliRunner(cwd, env)(...args); + expect(stdout).not.toContain("prepublish-root"); + expect(stdout).not.toContain("prepublish-package-2"); +});