Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return correct path in pnpm pack #5472

Merged
merged 3 commits into from Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'))
})