Skip to content

Commit

Permalink
fix(publish): Pass correct arguments to packDirectory()
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Jul 23, 2019
1 parent 1575396 commit b1aade3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
37 changes: 23 additions & 14 deletions commands/publish/__tests__/publish-command.test.js
Expand Up @@ -316,16 +316,18 @@ Map {

await lernaPublish(cwd)("--contents", "dist");

expect(packDirectory).toHaveBeenCalledWith(
expect.objectContaining({ name: "package-1" }),
expect.stringContaining(path.normalize("packages/package-1/dist")),
expect.any(Object)
);
expect(packDirectory).toHaveBeenCalledWith(
expect.objectContaining({ name: "package-2" }),
expect.stringContaining(path.normalize("packages/package-2/dist")),
expect.any(Object)
);
const [[pkgOne, dirOne, opts], [pkgTwo, dirTwo]] = packDirectory.mock.calls;

// second argument to packDirectory() is the location, _not_ the contents
expect(dirOne).toBe(pkgOne.location);
expect(dirTwo).toBe(pkgTwo.location);

expect(pkgOne.contents).toBe(path.join(pkgOne.location, "dist"));
expect(pkgTwo.contents).toBe(path.join(pkgTwo.location, "dist"));

// opts is a snapshot of npm-conf instance
expect(packDirectory).toHaveBeenCalledWith(pkgOne, dirOne, opts);
expect(packDirectory).toHaveBeenCalledWith(pkgTwo, dirTwo, opts);
});
});

Expand All @@ -342,17 +344,24 @@ Map {
await lernaPublish(cwd)();

expect(packDirectory).toHaveBeenCalledWith(
expect.objectContaining({ name: "package-1" }),
expect.stringMatching(/packages[\\/]+package-1[\\/]+dist$/),
expect.objectContaining({
name: "package-1",
contents: path.join(cwd, "packages/package-1/dist"),
}),
path.join(cwd, "packages/package-1"),
expect.any(Object)
);
expect(packDirectory).toHaveBeenCalledWith(
expect.objectContaining({ name: "package-2" }),
expect.stringMatching(/packages[\\/]+package-2$/),
expect.objectContaining({
name: "package-2",
contents: path.join(cwd, "packages/package-2"),
}),
path.join(cwd, "packages/package-2"),
expect.any(Object)
);
});
});

describe("in a cyclical repo", () => {
it("should throw an error with --reject-cycles", async () => {
expect.assertions(1);
Expand Down
4 changes: 2 additions & 2 deletions commands/publish/index.js
Expand Up @@ -650,8 +650,8 @@ class PublishCommand extends Command {
this.options.requireScripts && (pkg => this.execScript(pkg, "prepublish")),

pkg =>
pulseTillDone(packDirectory(pkg, pkg.contents, opts)).then(packed => {
tracker.verbose("packed", pkg.name, path.relative(this.project.rootPath, pkg.contents));
pulseTillDone(packDirectory(pkg, pkg.location, opts)).then(packed => {
tracker.verbose("packed", path.relative(this.project.rootPath, pkg.contents));
tracker.completeWork(1);

// store metadata for use in this.publishPacked()
Expand Down

0 comments on commit b1aade3

Please sign in to comment.