Skip to content

Commit

Permalink
refactor(publish): Snapshot conf before passing as opts
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Dec 19, 2018
1 parent d0c677f commit 2de7234
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
15 changes: 2 additions & 13 deletions commands/publish/__tests__/publish-command.test.js
Expand Up @@ -314,17 +314,6 @@ Set {
});

describe("--registry", () => {
const confWithRegistry = registry =>
expect.objectContaining({
sources: expect.objectContaining({
cli: {
data: expect.objectContaining({
registry,
}),
},
}),
});

it("passes registry to npm commands", async () => {
const testDir = await initFixture("normal");
const registry = "https://my-private-registry";
Expand All @@ -335,7 +324,7 @@ Set {
expect.objectContaining({ name: "package-1" }),
"latest", // dist-tag
"/TEMP_DIR/package-1-MOCKED.tgz",
confWithRegistry(registry)
expect.objectContaining({ registry })
);
});

Expand All @@ -349,7 +338,7 @@ Set {
expect.objectContaining({ name: "package-1" }),
"latest", // dist-tag
"/TEMP_DIR/package-1-MOCKED.tgz",
confWithRegistry("https://registry.npmjs.org/")
expect.objectContaining({ registry: "https://registry.npmjs.org/" })
);

const logMessages = loggingOutput("warn");
Expand Down
8 changes: 1 addition & 7 deletions commands/publish/__tests__/publish-tagging.test.js
Expand Up @@ -42,13 +42,7 @@ test("publish --temp-tag", async () => {
expect(npmPublish.registry.get("package-4")).toBe("lerna-temp");

const conf = expect.objectContaining({
sources: expect.objectContaining({
cli: {
data: expect.objectContaining({
registry: "test-registry",
}),
},
}),
registry: "test-registry",
});
expect(npmDistTag.remove).toHaveBeenLastCalledWith("package-4@1.0.1", "lerna-temp", conf);
expect(npmDistTag.add).toHaveBeenLastCalledWith("package-4@1.0.1", "latest", conf);
Expand Down
11 changes: 7 additions & 4 deletions commands/publish/index.js
Expand Up @@ -513,12 +513,13 @@ class PublishCommand extends Command {
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepublishOnly"));
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepack"));

const opts = this.conf.snapshot;
const mapper = pPipe(
[
this.options.requireScripts && (pkg => this.execScript(pkg, "prepublish")),

pkg =>
packDirectory(pkg, this.conf).then(packed => {
packDirectory(pkg, opts).then(packed => {
pkg.packed = packed;

// manifest may be mutated by any previous lifecycle
Expand Down Expand Up @@ -554,12 +555,13 @@ class PublishCommand extends Command {

let chain = Promise.resolve();

const opts = this.conf.snapshot;
const mapper = pPipe(
[
pkg => {
logPacked(pkg.packed);

return npmPublish(pkg, distTag, pkg.packed.tarFilePath, this.conf);
return npmPublish(pkg, distTag, pkg.packed.tarFilePath, opts);
},

this.options.requireScripts && (pkg => this.execScript(pkg, "postpublish")),
Expand Down Expand Up @@ -588,13 +590,14 @@ class PublishCommand extends Command {

let chain = Promise.resolve();

const opts = this.conf.snapshot;
const mapper = pPipe([
pkg => {
const spec = `${pkg.name}@${pkg.version}`;

return Promise.resolve()
.then(() => npmDistTag.remove(spec, "lerna-temp", this.conf))
.then(() => npmDistTag.add(spec, distTag, this.conf))
.then(() => npmDistTag.remove(spec, "lerna-temp", opts))
.then(() => npmDistTag.add(spec, distTag, opts))
.then(() => pkg);
},

Expand Down

0 comments on commit 2de7234

Please sign in to comment.