Skip to content

Commit

Permalink
feat: Add name of package that fails to publish (#3644)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokel81 committed May 9, 2023
1 parent 9d27d85 commit 11d8473
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions libs/commands/publish/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ class PublishCommand extends Command {
}

this.logger.silly("", err);
this.logger.warn("notice", `Package failed to publish: ${pkg.name}`);
this.logger.error(err.code, (err.body && err.body.error) || err.message);

// avoid dumping logs, this isn't a lerna problem
Expand Down
29 changes: 26 additions & 3 deletions libs/commands/publish/src/lib/publish-from-package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ const promptConfirmation = jest.mocked(_promptConfirmation);
const throwIfUncommitted = jest.mocked(_throwIfUncommitted);

// The mock differs from the real thing
const npmPublish = _npmPublish as any;
const writePkg = _writePkg as any;
const output = _output as any;
const npmPublish = _npmPublish as jest.MockedFunction<typeof _npmPublish> & { order: () => string[] };
const writePkg = _writePkg as jest.MockedFunction<typeof _writePkg> & {
updatedManifest: (name: string) => { gitHead?: string };
};
const output = _output as jest.MockedFunction<typeof _output> & { logged: () => string[] };

const initFixture = initFixtureFactory(__dirname);

Expand Down Expand Up @@ -105,6 +107,27 @@ describe("publish from-package", () => {
]);
});

it("logs the name of the package that fails to be published", async () => {
const cwd = await initFixture("independent");

getUnpublishedPackages.mockImplementationOnce((packageGraph) => Array.from(packageGraph.values()));

npmPublish.mockImplementation(async (pkg) => {
if (pkg.name === "package-2") {
throw new Error("some-error");
}
});

try {
await lernaPublish(cwd)("from-package");
} catch {
// ignore error
}

const logMessages = loggingOutput("notice");
expect(logMessages).toContain("Package failed to publish: package-2");
});

it("exits early when all packages are published", async () => {
const cwd = await initFixture("normal");

Expand Down

0 comments on commit 11d8473

Please sign in to comment.