Skip to content

Commit

Permalink
feat(publish): Support prepack/postpack lifecycle in root manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Aug 27, 2018
1 parent dda9812 commit 9df88a4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
Expand Up @@ -8,6 +8,8 @@
"prepublish": "echo prepublish-root",
"prepare": "echo prepare-root",
"prepublishOnly": "echo prepublishOnly-root",
"prepack": "echo prepack-root",
"postpack": "echo postpack-root",
"postpublish": "echo postpublish-root"
}
}
4 changes: 3 additions & 1 deletion commands/publish/__tests__/publish-lifecycle-scripts.test.js
Expand Up @@ -24,7 +24,7 @@ describe("lifecycle scripts", () => {

await lernaPublish(cwd)();

["prepare", "prepublishOnly", "postpublish"].forEach(script => {
["prepare", "prepublishOnly", "prepack", "postpack", "postpublish"].forEach(script => {
// "lifecycle" is the root manifest name
expect(runLifecycle).toHaveBeenCalledWith(expect.objectContaining({ name: "lifecycle" }), script);
});
Expand Down Expand Up @@ -60,7 +60,9 @@ describe("lifecycle scripts", () => {
// publish-specific
["lifecycle", "prepare"],
["lifecycle", "prepublishOnly"],
["lifecycle", "prepack"],
["package-1", "prepublishOnly"],
["lifecycle", "postpack"],
["package-1", "postpublish"],
["lifecycle", "postpublish"],
]);
Expand Down
3 changes: 3 additions & 0 deletions commands/publish/index.js
Expand Up @@ -423,6 +423,7 @@ class PublishCommand extends Command {

chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepare"));
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepublishOnly"));
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepack"));

const actions = [
pkg =>
Expand Down Expand Up @@ -453,6 +454,8 @@ class PublishCommand extends Command {
// remove temporary license files if _any_ error occurs _anywhere_ in the promise chain
chain = chain.catch(error => this.removeTempLicensesOnError(error));

chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "postpack"));

return pFinally(chain, () => tracker.finish());
}

Expand Down
2 changes: 2 additions & 0 deletions integration/lerna-publish-lifecycle-silent.test.js
Expand Up @@ -37,9 +37,11 @@ postversion-package-1
postversion-root
prepare-root
prepublishOnly-root
prepack-root
prepublishOnly-package-1
prepublish-package-1
prepare-package-1
postpack-root
postpublish-package-1
postpublish-root
Successfully published:
Expand Down
10 changes: 10 additions & 0 deletions integration/lerna-publish-lifecycle.test.js
Expand Up @@ -70,6 +70,11 @@ prepare-root
prepublishOnly-root
> lifecycle@0.0.0-monorepo prepack __TEST_ROOTDIR__
> echo prepack-root
prepack-root
> package-1@1.1.0 prepublishOnly __TEST_ROOTDIR__/packages/package-1
> echo prepublishOnly-package-1
Expand All @@ -85,6 +90,11 @@ prepublish-package-1
prepare-package-1
> lifecycle@0.0.0-monorepo postpack __TEST_ROOTDIR__
> echo postpack-root
postpack-root
> package-1@1.1.0 postpublish __TEST_ROOTDIR__/packages/package-1
> echo postpublish-package-1
Expand Down

0 comments on commit 9df88a4

Please sign in to comment.