mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-09 23:48:28 -05:00
fix(link-bins): don't throw error during install when bin points to path that doesn't exist (#4172)
close #3763
This commit is contained in:
6
.changeset/odd-garlics-crash.md
Normal file
6
.changeset/odd-garlics-crash.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/link-bins": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Don't throw an error during install when the bin of a dependency points to a path that doesn't exist [#3763](https://github.com/pnpm/pnpm/issues/3763).
|
||||
@@ -203,15 +203,15 @@ async function getPackageBinsFromManifest (manifest: DependencyManifest, pkgDir:
|
||||
async function linkBin (cmd: CommandInfo, binsDir: string, opts?: { extendNodePath?: boolean }) {
|
||||
const externalBinPath = path.join(binsDir, cmd.name)
|
||||
|
||||
let nodePath: string[] | undefined
|
||||
if (opts?.extendNodePath !== false) {
|
||||
nodePath = await getBinNodePaths(cmd.path)
|
||||
const binsParentDir = path.dirname(binsDir)
|
||||
if (path.relative(cmd.path, binsParentDir) !== '') {
|
||||
nodePath = union(nodePath, await getBinNodePaths(binsParentDir))
|
||||
}
|
||||
}
|
||||
try {
|
||||
let nodePath: string[] | undefined
|
||||
if (opts?.extendNodePath !== false) {
|
||||
nodePath = await getBinNodePaths(cmd.path)
|
||||
const binsParentDir = path.dirname(binsDir)
|
||||
if (path.relative(cmd.path, binsParentDir) !== '') {
|
||||
nodePath = union(nodePath, await getBinNodePaths(binsParentDir))
|
||||
}
|
||||
}
|
||||
await cmdShim(cmd.path, externalBinPath, {
|
||||
createPwshFile: cmd.makePowerShellShim,
|
||||
nodePath,
|
||||
|
||||
5
packages/link-bins/test/fixtures/bin-not-exist/node_modules/foo/package.json
generated
vendored
Normal file
5
packages/link-bins/test/fixtures/bin-not-exist/node_modules/foo/package.json
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "meow",
|
||||
"version": "1.0.0",
|
||||
"bin": "dist/not-exist.js"
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
import { promisify } from 'util'
|
||||
import { promises as fs } from 'fs'
|
||||
import path from 'path'
|
||||
import logger from '@pnpm/logger'
|
||||
import logger, { globalWarn } from '@pnpm/logger'
|
||||
import linkBins, {
|
||||
linkBinsOfPackages,
|
||||
} from '@pnpm/link-bins'
|
||||
@@ -15,7 +15,13 @@ import tempy from 'tempy'
|
||||
|
||||
jest.mock('@pnpm/logger', () => {
|
||||
const debug = jest.fn()
|
||||
return () => ({ debug })
|
||||
const globalWarn = jest.fn()
|
||||
|
||||
return {
|
||||
__esModule: true,
|
||||
default: () => ({ debug }),
|
||||
globalWarn,
|
||||
}
|
||||
})
|
||||
|
||||
const binsConflictLogger = logger('bins-conflict')
|
||||
@@ -35,6 +41,7 @@ const exoticManifestFixture = path.join(fixtures, 'exotic-manifest')
|
||||
const noNameFixture = path.join(fixtures, 'no-name')
|
||||
const noBinFixture = path.join(fixtures, 'no-bin')
|
||||
const windowShebangFixture = path.join(fixtures, 'bin-window-shebang')
|
||||
const binNotExistFixture = path.join(fixtures, 'bin-not-exist')
|
||||
|
||||
const POWER_SHELL_IS_SUPPORTED = isWindows()
|
||||
const IS_WINDOWS = isWindows()
|
||||
@@ -355,3 +362,17 @@ test('linkBins() fix window shebang line', async () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test("linkBins() emits global warning when bin points to path that doesn't exist", async () => {
|
||||
const binTarget = tempy.directory()
|
||||
|
||||
await linkBins(path.join(binNotExistFixture, 'node_modules'), binTarget, {
|
||||
allowExoticManifests: true,
|
||||
warn: () => {},
|
||||
})
|
||||
|
||||
expect(await fs.readdir(binTarget)).toEqual(getExpectedBins([]))
|
||||
expect(
|
||||
globalWarn
|
||||
).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user