Skip to content

Commit

Permalink
feat(publish): Add --require-scripts option to opt-in to raw JS lifec…
Browse files Browse the repository at this point in the history
…ycle scripts

BREAKING CHANGE: External `$PKGDIR/scripts/{pre,post}publish.js` lifecycles are now opt-in instead of automatic. Pass `--require-scripts` explicitly to restore previous functionality.
  • Loading branch information
evocateur committed Jul 25, 2018
1 parent e6ba19f commit 054392b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions commands/publish/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ exports.builder = yargs => {
type: "string",
requiresArg: true,
},
"require-scripts": {
describe: "Execute ./scripts/prepublish.js and ./scripts/postpublish.js, relative to package root.",
type: "boolean",
},
preid: {
describe: "Specify the prerelease identifier (major.minor.patch-pre).",
type: "string",
Expand Down
12 changes: 10 additions & 2 deletions commands/publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class PublishCommand extends Command {
// https://docs.npmjs.com/misc/config#save-prefix
this.savePrefix = this.options.exact ? "" : "^";

if (this.options.requireScripts) {
this.logger.info("require-scripts", "enabled");
}

this.npmConfig = {
npmClient: this.options.npmClient || "npm",
registry: this.options.registry,
Expand Down Expand Up @@ -680,7 +684,9 @@ class PublishCommand extends Command {
chain = chain.then(() => this.runPrepublishScripts(rootPkg));
chain = chain.then(() =>
pMap(this.updates, ({ pkg }) => {
this.execScript(pkg, "prepublish");
if (this.options.requireScripts) {
this.execScript(pkg, "prepublish");
}

return this.runPrepublishScripts(pkg);
})
Expand All @@ -695,7 +701,9 @@ class PublishCommand extends Command {
tracker.info("published", pkg.name);
tracker.completeWork(1);

this.execScript(pkg, "postpublish");
if (this.options.requireScripts) {
this.execScript(pkg, "postpublish");
}

return this.runPackageLifecycle(pkg, "postpublish");
});
Expand Down

0 comments on commit 054392b

Please sign in to comment.