mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-08 15:08:27 -05:00
fix(link-bins): ensure permission of bin file when symlinked (#5913)
close #5822 close #5890
This commit is contained in:
6
.changeset/light-dots-buy.md
Normal file
6
.changeset/light-dots-buy.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/link-bins": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Ensure the permission of bin file when `prefer-symlinked-executables` is set to `true` [#5913](https://github.com/pnpm/pnpm/pull/5913).
|
||||
@@ -210,6 +210,7 @@ async function linkBin (cmd: CommandInfo, binsDir: string, opts?: LinkBinOptions
|
||||
|
||||
if (opts?.preferSymlinkedExecutables && !IS_WINDOWS && cmd.nodeExecPath == null) {
|
||||
await symlinkDir(cmd.path, externalBinPath)
|
||||
await fixBin(cmd.path, 0o755)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
1
pkg-manager/link-bins/test/fixtures/simple-fixture/node_modules/simple/index.js
generated
vendored
1
pkg-manager/link-bins/test/fixtures/simple-fixture/node_modules/simple/index.js
generated
vendored
@@ -1 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
console.log('hello_world')
|
||||
|
||||
@@ -12,6 +12,7 @@ import isWindows from 'is-windows'
|
||||
import normalizePath from 'normalize-path'
|
||||
import exists from 'path-exists'
|
||||
import tempy from 'tempy'
|
||||
import { spawnSync } from 'child_process'
|
||||
|
||||
jest.mock('@pnpm/logger', () => {
|
||||
const debug = jest.fn()
|
||||
@@ -71,6 +72,34 @@ test('linkBins()', async () => {
|
||||
}
|
||||
})
|
||||
|
||||
test('linkBins() should work when prefer-symlinked-executables enabled', async () => {
|
||||
const binTarget = tempy.directory()
|
||||
const warn = jest.fn()
|
||||
const simpleFixture = f.prepare('simple-fixture')
|
||||
|
||||
await linkBins(path.join(simpleFixture, 'node_modules'), binTarget, { warn, preferSymlinkedExecutables: true })
|
||||
|
||||
expect(warn).not.toHaveBeenCalled()
|
||||
expect(await fs.readdir(binTarget)).toEqual(getExpectedBins(['simple']))
|
||||
const binLocation = path.join(binTarget, 'simple')
|
||||
expect(await exists(binLocation)).toBe(true)
|
||||
const content = await fs.readFile(binLocation, 'utf8')
|
||||
if (IS_WINDOWS) {
|
||||
expect(content).toMatch('node_modules/simple/index.js')
|
||||
} else {
|
||||
expect(content).toMatch('console.log(\'hello_world\')')
|
||||
}
|
||||
|
||||
if (EXECUTABLE_SHEBANG_SUPPORTED) {
|
||||
const binFile = path.join(binTarget, 'simple')
|
||||
const stat = await fs.stat(binFile)
|
||||
expect(stat.mode).toBe(parseInt('100755', 8))
|
||||
expect(stat.isFile()).toBe(true)
|
||||
const stdout = spawnSync(binFile).stdout.toString('utf-8')
|
||||
expect(stdout).toMatch('hello_world')
|
||||
}
|
||||
})
|
||||
|
||||
test('linkBins() never creates a PowerShell shim for the pnpm CLI', async () => {
|
||||
const binTarget = tempy.directory()
|
||||
const fixture = f.prepare('pnpm-cli')
|
||||
|
||||
Reference in New Issue
Block a user