diff --git a/.changeset/fluffy-insects-jump.md b/.changeset/fluffy-insects-jump.md new file mode 100644 index 00000000000..8b1c49ad9d7 --- /dev/null +++ b/.changeset/fluffy-insects-jump.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-publishing": patch +"pnpm": patch +--- + +`pnpm publish ` should exit with non-0 exit code when publish fails [#5396](https://github.com/pnpm/pnpm/issues/5396). diff --git a/releasing/plugin-commands-publishing/src/publish.ts b/releasing/plugin-commands-publishing/src/publish.ts index 823de782617..70666ad6131 100644 --- a/releasing/plugin-commands-publishing/src/publish.ts +++ b/releasing/plugin-commands-publishing/src/publish.ts @@ -162,8 +162,8 @@ Do you want to continue?`, return } if ((params.length > 0) && params[0].endsWith('.tgz')) { - runNpm(opts.npmPath, ['publish', ...params]) - return + const { status } = runNpm(opts.npmPath, ['publish', ...params]) + return { exitCode: status ?? 0 } } const dirInParams = (params.length > 0) && params[0] const dir = dirInParams || opts.dir || process.cwd() diff --git a/releasing/plugin-commands-publishing/test/publish.ts b/releasing/plugin-commands-publishing/test/publish.ts index 0ead0720ee5..26acd04e073 100644 --- a/releasing/plugin-commands-publishing/test/publish.ts +++ b/releasing/plugin-commands-publishing/test/publish.ts @@ -708,3 +708,21 @@ test('publish: with specified publish branch name', async () => { publishBranch: branch, }, []) }) + +test('publish: exit with non-zero code when publish tgz', async () => { + prepare({ + name: 'test-publish-package.json', + version: '0.0.2', + }) + + const result = await publish.handler({ + ...DEFAULT_OPTS, + argv: { original: ['publish', './non-exists.tgz', '--no-git-checks'] }, + dir: process.cwd(), + gitChecks: false, + + }, [ + './non-exists.tgz', + ]) + expect(result?.exitCode).not.toBe(0) +})