Skip to content

Commit

Permalink
feat(npm-publish): Resolve target package to aid chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Aug 27, 2018
1 parent 063d743 commit 928a707
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions commands/__mocks__/@lerna/npm-publish.js
Expand Up @@ -7,7 +7,7 @@ const registry = new Map();
const mockNpmPublish = jest.fn((pkg, tag) => {
registry.set(pkg.name, tag);

return Promise.resolve();
return Promise.resolve(pkg);
});

const mockNpmPack = jest.fn((rootManifest, packages) => {
Expand All @@ -20,7 +20,7 @@ const mockNpmPack = jest.fn((rootManifest, packages) => {
};
});

return Promise.resolve();
return Promise.resolve(packages.slice());
});

const mockMakePacker = jest.fn(rootManifest => batch => mockNpmPack(rootManifest, batch));
Expand Down
12 changes: 9 additions & 3 deletions utils/npm-publish/__tests__/npm-publish.test.js
Expand Up @@ -36,8 +36,9 @@ describe("npm-publish", () => {
};

it("runs npm publish in a directory with --tag support", async () => {
await npmPublish(pkg, "published-tag", { npmClient: "npm" });
const result = await npmPublish(pkg, "published-tag", { npmClient: "npm" });

expect(result).toBe(pkg);
expect(ChildProcessUtilities.exec).lastCalledWith(
"npm",
["publish", "--ignore-scripts", "--tag", "published-tag", "test-1.10.100.tgz"],
Expand Down Expand Up @@ -153,7 +154,9 @@ describe("npmPack", () => {
mockStream.emit("data", chunk2);

// resolve promise
await cmd;
const result = await cmd;

expect(result).toEqual([pkg1, pkg2]);

expect(pkg1.tarball.filename).toBe("mocked-pkg-1-pack.tgz");
expect(pkg2.tarball.filename).toBe("mocked-pkg-2-pack.tgz");
Expand Down Expand Up @@ -250,7 +253,10 @@ describe("makePacker", () => {
});

// resolve all promises
await Promise.all(commands);
const results = await Promise.all(commands);

expect(results[0]).toEqual(batches[0]);
expect(results[1]).toEqual(batches[1]);

expect(packages[0].tarball.filename).toBe("mocked-pkg-5-pack.tgz");
expect(packages[1].tarball.filename).toBe("mocked-pkg-6-pack.tgz");
Expand Down
4 changes: 2 additions & 2 deletions utils/npm-publish/npm-publish.js
Expand Up @@ -37,7 +37,7 @@ function npmPublish(pkg, tag, { npmClient, registry }) {
log.silly("exec", npmClient, args);
return ChildProcessUtilities.exec(npmClient, args, opts).then(() =>
// don't leave the generated tarball hanging around after success
fs.remove(path.join(pkg.location, pkg.tarball.filename))
fs.remove(path.join(pkg.location, pkg.tarball.filename)).then(() => pkg)
);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ function npmPack(rootManifest, packages, opts = makePackOptions(rootManifest)) {
const inRoot = path.join(pkg.rootPath, pkg.tarball.filename);
const toLeaf = path.join(pkg.location, pkg.tarball.filename);

return fs.move(inRoot, toLeaf, { overwrite: true });
return fs.move(inRoot, toLeaf, { overwrite: true }).then(() => pkg);
},
{ concurrency: 10 }
);
Expand Down

0 comments on commit 928a707

Please sign in to comment.