Navigation Menu

Skip to content

Commit

Permalink
fix(options): Explicit --ignore-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Oct 14, 2019
1 parent fa21723 commit efcb3bd
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
23 changes: 23 additions & 0 deletions commands/publish/__tests__/publish-lifecycle-scripts.test.js
Expand Up @@ -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,
})
);
});
});
6 changes: 5 additions & 1 deletion commands/publish/command.js
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions commands/publish/index.js
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions commands/version/__tests__/version-lifecycle-scripts.test.js
Expand Up @@ -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,
})
);
});
});
4 changes: 4 additions & 0 deletions commands/version/command.js
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions integration/lerna-publish-lifecycle.test.js
Expand Up @@ -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
`);
});

0 comments on commit efcb3bd

Please sign in to comment.