Skip to content

Commit

Permalink
fix: return correct path in pnpm pack (#5472)
Browse files Browse the repository at this point in the history
close #5471

Co-authored-by: Zoltan Kochan <z@kochan.io>
  • Loading branch information
juanrgm and zkochan committed Oct 9, 2022
1 parent 3ae888c commit e072256
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .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).
5 changes: 3 additions & 2 deletions packages/plugin-commands-publishing/src/pack.ts
Expand Up @@ -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,
Expand All @@ -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))
}
Expand Down
18 changes: 18 additions & 0 deletions packages/plugin-commands-publishing/test/pack.ts
Expand Up @@ -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'))
})

0 comments on commit e072256

Please sign in to comment.