Skip to content

Commit ae29097

Browse files
committedJan 2, 2019
fix(run-lifecycle): Short-circuit ignore options
1 parent 0ef71fb commit ae29097

File tree

2 files changed

+50
-21
lines changed

2 files changed

+50
-21
lines changed
 

‎utils/run-lifecycle/__tests__/run-lifecycle.test.js

+33-5
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ describe("runLifecycle()", () => {
7373
version: "1.0.0-dashed",
7474
location: "dashed-location",
7575
scripts: {
76-
prepublish: "test",
76+
"dashed-options": "test",
7777
},
7878
};
7979
const dir = pkg.location;
80-
const stage = "prepublish";
80+
const stage = "dashed-options";
8181
const opts = new Map([
8282
["ignore-prepublish", true],
83-
["ignore-scripts", true],
83+
["ignore-scripts", false],
8484
["node-options", true],
8585
["script-shell", true],
8686
["scripts-prepend-node-path", true],
@@ -96,15 +96,43 @@ describe("runLifecycle()", () => {
9696
dir,
9797
failOk: false,
9898
log: expect.any(Object),
99-
ignorePrepublish: true,
100-
ignoreScripts: true,
10199
nodeOptions: true,
102100
scriptShell: true,
103101
scriptsPrependNodePath: true,
104102
unsafePerm: true,
105103
});
106104
});
107105

106+
it("ignores prepublish when configured", async () => {
107+
const pkg = {
108+
name: "ignore-prepublish",
109+
scripts: {
110+
prepublish: "test",
111+
},
112+
};
113+
const stage = "prepublish";
114+
const opts = new Map().set("ignore-prepublish", true);
115+
116+
await runLifecycle(pkg, stage, opts);
117+
118+
expect(runScript).not.toHaveBeenCalled();
119+
});
120+
121+
it("ignores scripts when configured", async () => {
122+
const pkg = {
123+
name: "ignore-scripts",
124+
scripts: {
125+
ignored: "test",
126+
},
127+
};
128+
const stage = "ignored";
129+
const opts = new Map().set("ignore-scripts", true);
130+
131+
await runLifecycle(pkg, stage, opts);
132+
133+
expect(runScript).not.toHaveBeenCalled();
134+
});
135+
108136
it("omits circular opts", async () => {
109137
const pkg = {
110138
name: "circular-name",

‎utils/run-lifecycle/run-lifecycle.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,24 @@ function runLifecycle(pkg, stage, _opts) {
4545
const dir = pkg.location;
4646
const config = {};
4747

48+
if (opts.ignoreScripts) {
49+
opts.log.verbose("lifecycle", "%j ignored in %j", stage, pkg.name);
50+
51+
return Promise.resolve();
52+
}
53+
4854
if (!pkg.scripts || !pkg.scripts[stage]) {
4955
opts.log.silly("lifecycle", "No script for %j in %j, continuing", stage, pkg.name);
5056

5157
return Promise.resolve();
5258
}
5359

60+
if (stage === "prepublish" && opts.ignorePrepublish) {
61+
opts.log.verbose("lifecycle", "%j ignored in %j", stage, pkg.name);
62+
63+
return Promise.resolve();
64+
}
65+
5466
// https://github.com/zkat/figgy-pudding/blob/7d68bd3/index.js#L42-L64
5567
for (const [key, val] of opts) {
5668
// omit falsy values and circular objects
@@ -65,29 +77,18 @@ function runLifecycle(pkg, stage, _opts) {
6577
// TODO: remove pkg._id when npm-lifecycle no longer relies on it
6678
pkg._id = `${pkg.name}@${pkg.version}`; // eslint-disable-line
6779

68-
// bring along camelCased aliases
69-
const {
70-
ignorePrepublish,
71-
ignoreScripts,
72-
nodeOptions,
73-
scriptShell,
74-
scriptsPrependNodePath,
75-
unsafePerm,
76-
} = opts;
77-
7880
opts.log.silly("lifecycle", "%j starting in %j", stage, pkg.name);
7981

8082
return runScript(pkg, stage, dir, {
8183
config,
8284
dir,
8385
failOk: false,
8486
log: opts.log,
85-
ignorePrepublish,
86-
ignoreScripts,
87-
nodeOptions,
88-
scriptShell,
89-
scriptsPrependNodePath,
90-
unsafePerm,
87+
// bring along camelCased aliases
88+
nodeOptions: opts.nodeOptions,
89+
scriptShell: opts.scriptShell,
90+
scriptsPrependNodePath: opts.scriptsPrependNodePath,
91+
unsafePerm: opts.unsafePerm,
9192
}).then(
9293
() => {
9394
opts.log.silly("lifecycle", "%j finished in %j", stage, pkg.name);

0 commit comments

Comments
 (0)
Please sign in to comment.