From e072256518cedc7a6f09550515210c1053837cb0 Mon Sep 17 00:00:00 2001 From: Juanra GM <54169354+juanrgm@users.noreply.github.com> Date: Sun, 9 Oct 2022 15:17:16 +0200 Subject: [PATCH] fix: return correct path in `pnpm pack` (#5472) close #5471 Co-authored-by: Zoltan Kochan --- .changeset/thick-dancers-guess.md | 6 ++++++ .../plugin-commands-publishing/src/pack.ts | 5 +++-- .../plugin-commands-publishing/test/pack.ts | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .changeset/thick-dancers-guess.md diff --git a/.changeset/thick-dancers-guess.md b/.changeset/thick-dancers-guess.md new file mode 100644 index 00000000000..f193ed61964 --- /dev/null +++ b/.changeset/thick-dancers-guess.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-publishing": patch +"pnpm": patch +--- + +Fix the return path of `pnpm pack`, when a custom destination directory is used [#5471](https://github.com/pnpm/pnpm/issues/5471). diff --git a/packages/plugin-commands-publishing/src/pack.ts b/packages/plugin-commands-publishing/src/pack.ts index ed894d299c4..1eca9175ff9 100644 --- a/packages/plugin-commands-publishing/src/pack.ts +++ b/packages/plugin-commands-publishing/src/pack.ts @@ -105,6 +105,7 @@ export async function handler ( const destDir = opts.packDestination ? (path.isAbsolute(opts.packDestination) ? opts.packDestination : path.join(dir, opts.packDestination ?? '.')) : dir + await fs.promises.mkdir(destDir, { recursive: true }) await packPkg({ destFile: path.join(destDir, tarballName), filesMap, @@ -115,8 +116,8 @@ export async function handler ( if (!opts.ignoreScripts) { await _runScriptsIfPresent(['postpack'], entryManifest) } - if (opts.dir !== dir) { - return path.join(dir, tarballName) + if (opts.dir !== destDir) { + return path.join(destDir, tarballName) } return path.relative(opts.dir, path.join(dir, tarballName)) } diff --git a/packages/plugin-commands-publishing/test/pack.ts b/packages/plugin-commands-publishing/test/pack.ts index acb9e2c056a..3715c2f0331 100644 --- a/packages/plugin-commands-publishing/test/pack.ts +++ b/packages/plugin-commands-publishing/test/pack.ts @@ -262,3 +262,21 @@ test('pack should read from the correct node_modules when publishing from a cust }, }) }) + +test('pack to custom destination directory', async () => { + prepare({ + name: 'custom-dest', + version: '0.0.0', + }) + + const output = await pack.handler({ + ...DEFAULT_OPTS, + argv: { original: [] }, + dir: process.cwd(), + extraBinPaths: [], + packDestination: path.resolve('custom-dest'), + embedReadme: false, + }) + + expect(output).toBe(path.resolve('custom-dest/custom-dest-0.0.0.tgz')) +})