Skip to content

Commit b1aade3

Browse files
committed
fix(publish): Pass correct arguments to packDirectory()
1 parent 1575396 commit b1aade3

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

commands/publish/__tests__/publish-command.test.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,18 @@ Map {
316316

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

319-
expect(packDirectory).toHaveBeenCalledWith(
320-
expect.objectContaining({ name: "package-1" }),
321-
expect.stringContaining(path.normalize("packages/package-1/dist")),
322-
expect.any(Object)
323-
);
324-
expect(packDirectory).toHaveBeenCalledWith(
325-
expect.objectContaining({ name: "package-2" }),
326-
expect.stringContaining(path.normalize("packages/package-2/dist")),
327-
expect.any(Object)
328-
);
319+
const [[pkgOne, dirOne, opts], [pkgTwo, dirTwo]] = packDirectory.mock.calls;
320+
321+
// second argument to packDirectory() is the location, _not_ the contents
322+
expect(dirOne).toBe(pkgOne.location);
323+
expect(dirTwo).toBe(pkgTwo.location);
324+
325+
expect(pkgOne.contents).toBe(path.join(pkgOne.location, "dist"));
326+
expect(pkgTwo.contents).toBe(path.join(pkgTwo.location, "dist"));
327+
328+
// opts is a snapshot of npm-conf instance
329+
expect(packDirectory).toHaveBeenCalledWith(pkgOne, dirOne, opts);
330+
expect(packDirectory).toHaveBeenCalledWith(pkgTwo, dirTwo, opts);
329331
});
330332
});
331333

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

344346
expect(packDirectory).toHaveBeenCalledWith(
345-
expect.objectContaining({ name: "package-1" }),
346-
expect.stringMatching(/packages[\\/]+package-1[\\/]+dist$/),
347+
expect.objectContaining({
348+
name: "package-1",
349+
contents: path.join(cwd, "packages/package-1/dist"),
350+
}),
351+
path.join(cwd, "packages/package-1"),
347352
expect.any(Object)
348353
);
349354
expect(packDirectory).toHaveBeenCalledWith(
350-
expect.objectContaining({ name: "package-2" }),
351-
expect.stringMatching(/packages[\\/]+package-2$/),
355+
expect.objectContaining({
356+
name: "package-2",
357+
contents: path.join(cwd, "packages/package-2"),
358+
}),
359+
path.join(cwd, "packages/package-2"),
352360
expect.any(Object)
353361
);
354362
});
355363
});
364+
356365
describe("in a cyclical repo", () => {
357366
it("should throw an error with --reject-cycles", async () => {
358367
expect.assertions(1);

commands/publish/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,8 @@ class PublishCommand extends Command {
650650
this.options.requireScripts && (pkg => this.execScript(pkg, "prepublish")),
651651

652652
pkg =>
653-
pulseTillDone(packDirectory(pkg, pkg.contents, opts)).then(packed => {
654-
tracker.verbose("packed", pkg.name, path.relative(this.project.rootPath, pkg.contents));
653+
pulseTillDone(packDirectory(pkg, pkg.location, opts)).then(packed => {
654+
tracker.verbose("packed", path.relative(this.project.rootPath, pkg.contents));
655655
tracker.completeWork(1);
656656

657657
// store metadata for use in this.publishPacked()

0 commit comments

Comments
 (0)