Skip to content

Commit 054392b

Browse files
committed
feat(publish): Add --require-scripts option to opt-in to raw JS lifecycle 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.
1 parent e6ba19f commit 054392b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

commands/publish/command.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ exports.builder = yargs => {
8585
type: "string",
8686
requiresArg: true,
8787
},
88+
"require-scripts": {
89+
describe: "Execute ./scripts/prepublish.js and ./scripts/postpublish.js, relative to package root.",
90+
type: "boolean",
91+
},
8892
preid: {
8993
describe: "Specify the prerelease identifier (major.minor.patch-pre).",
9094
type: "string",

commands/publish/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class PublishCommand extends Command {
5656
// https://docs.npmjs.com/misc/config#save-prefix
5757
this.savePrefix = this.options.exact ? "" : "^";
5858

59+
if (this.options.requireScripts) {
60+
this.logger.info("require-scripts", "enabled");
61+
}
62+
5963
this.npmConfig = {
6064
npmClient: this.options.npmClient || "npm",
6165
registry: this.options.registry,
@@ -680,7 +684,9 @@ class PublishCommand extends Command {
680684
chain = chain.then(() => this.runPrepublishScripts(rootPkg));
681685
chain = chain.then(() =>
682686
pMap(this.updates, ({ pkg }) => {
683-
this.execScript(pkg, "prepublish");
687+
if (this.options.requireScripts) {
688+
this.execScript(pkg, "prepublish");
689+
}
684690

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

698-
this.execScript(pkg, "postpublish");
704+
if (this.options.requireScripts) {
705+
this.execScript(pkg, "postpublish");
706+
}
699707

700708
return this.runPackageLifecycle(pkg, "postpublish");
701709
});

0 commit comments

Comments
 (0)