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: error in pnpm --dir <path> link --global #5371

Merged
merged 2 commits into from Sep 21, 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
5 changes: 5 additions & 0 deletions .changeset/orange-apes-scream.md
@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-installation": patch
---

add path join and add test case for pnpm --dir <path> link global
5 changes: 5 additions & 0 deletions .changeset/stale-rice-nail.md
@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-installation": patch
---

fix error in pnpm --dir <path> link --global
2 changes: 1 addition & 1 deletion packages/plugin-commands-installation/src/link.ts
Expand Up @@ -116,7 +116,7 @@ export async function handler (
const { manifest, writeProjectManifest } = await tryReadProjectManifest(opts.dir, opts)
const newManifest = await addDependenciesToPackage(
manifest ?? {},
[`link:${cwd}`],
[`link:${opts.cliOptions?.dir ? path.join(cwd, opts.cliOptions.dir) : cwd}`],
linkOpts
)
await writeProjectManifest(newManifest)
Expand Down
26 changes: 26 additions & 0 deletions packages/plugin-commands-installation/test/link.ts
Expand Up @@ -72,6 +72,32 @@ test('link global bin', async function () {
await isExecutable((value) => expect(value).toBeTruthy(), path.join(globalBin, 'package-with-bin'))
})

test('link --dir global bin', async function () {
prepare()
process.chdir('..')

const globalDir = path.resolve('global')
const globalBin = path.join(globalDir, 'bin')
const oldPath = process.env[PATH]
process.env[PATH] = `${globalBin}${path.delimiter}${oldPath ?? ''}`
await fs.mkdir(globalBin, { recursive: true })

await writePkg('./dir/package-with-bin-in-dir', { name: 'package-with-bin-in-dir', version: '1.0.0', bin: 'bin.js' })
await fs.writeFile('./dir/package-with-bin-in-dir/bin.js', '#!/usr/bin/env node\nconsole.log(/hi/)\n', 'utf8')

await link.handler({
...DEFAULT_OPTS,
cliOptions: {
dir: './dir/package-with-bin-in-dir',
},
bin: globalBin,
dir: globalDir,
})
process.env[PATH] = oldPath

await isExecutable((value) => expect(value).toBeTruthy(), path.join(globalBin, 'package-with-bin-in-dir'))
})

test('relative link', async () => {
const project = prepare({
dependencies: {
Expand Down