Skip to content

Commit

Permalink
refactor(publish): Inline action pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Dec 10, 2018
1 parent f3339e3 commit e209bcb
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions commands/publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,19 +498,16 @@ class PublishCommand extends Command {
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepublishOnly"));
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepack"));

const actions = [
pkg =>
const mapper = pPipe(
[
// npm pack already runs prepare and prepublish
// prepublishOnly is _not_ run when publishing a tarball
// TECHNICALLY out of order, but not much we can do about that
this.runPackageLifecycle(pkg, "prepublishOnly"),
];
pkg => this.runPackageLifecycle(pkg, "prepublishOnly"),

if (this.options.requireScripts) {
actions.push(pkg => this.execScript(pkg, "prepublish"));
}

const mapper = pPipe(actions);
this.options.requireScripts && (pkg => this.execScript(pkg, "prepublish")),
].filter(Boolean)
);

chain = chain.then(() =>
pReduce(this.batchedPackages, (_, batch) =>
Expand Down Expand Up @@ -541,24 +538,23 @@ class PublishCommand extends Command {

let chain = Promise.resolve();

const actions = [
pkg => npmPublish(pkg, distTag, this.npmConfig),
// postpublish is _not_ run when publishing a tarball
pkg => this.runPackageLifecycle(pkg, "postpublish"),
];
const mapper = pPipe(
[
pkg => npmPublish(pkg, distTag, this.npmConfig),

if (this.options.requireScripts) {
actions.push(pkg => this.execScript(pkg, "postpublish"));
}
// postpublish is _not_ run when publishing a tarball
pkg => this.runPackageLifecycle(pkg, "postpublish"),

actions.push(pkg => {
tracker.info("published", pkg.name, pkg.version);
tracker.completeWork(1);
this.options.requireScripts && (pkg => this.execScript(pkg, "postpublish")),

return pkg;
});
pkg => {
tracker.info("published", pkg.name, pkg.version);
tracker.completeWork(1);

const mapper = pPipe(actions);
return pkg;
},
].filter(Boolean)
);

chain = chain.then(() => runParallelBatches(this.batchedPackages, this.concurrency, mapper));

Expand All @@ -575,7 +571,7 @@ class PublishCommand extends Command {

let chain = Promise.resolve();

const actions = [
const mapper = pPipe([
pkg => {
const spec = `${pkg.name}@${pkg.version}`;

Expand All @@ -584,15 +580,14 @@ class PublishCommand extends Command {
.then(() => npmDistTag.add(spec, distTag, this.conf))
.then(() => pkg);
},

pkg => {
tracker.info("dist-tag", "%s@%s => %j", pkg.name, pkg.version, distTag);
tracker.completeWork(1);

return pkg;
},
];

const mapper = pPipe(actions);
]);

chain = chain.then(() => runParallelBatches(this.batchedPackages, this.concurrency, mapper));

Expand Down

0 comments on commit e209bcb

Please sign in to comment.