mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-08 15:08:27 -05:00
fix: do not print an info message about conflicting command names (#3912)
close #3575
This commit is contained in:
5
.changeset/warm-crabs-sparkle.md
Normal file
5
.changeset/warm-crabs-sparkle.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/link-bins": patch
|
||||
---
|
||||
|
||||
Do not warn about bin conflicts, just log a debug message.
|
||||
@@ -49,6 +49,7 @@
|
||||
"ramda": "^0.27.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@pnpm/logger": "^4.0.0",
|
||||
"@types/is-windows": "^1.0.0",
|
||||
"@types/ncp": "^2.0.4",
|
||||
"@types/node": "^14.14.33",
|
||||
@@ -59,5 +60,8 @@
|
||||
"path-exists": "^4.0.0",
|
||||
"tempy": "^1.0.0"
|
||||
},
|
||||
"funding": "https://opencollective.com/pnpm"
|
||||
"funding": "https://opencollective.com/pnpm",
|
||||
"peerDependencies": {
|
||||
"@pnpm/logger": "^4.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { promises as fs } from 'fs'
|
||||
import Module from 'module'
|
||||
import path from 'path'
|
||||
import PnpmError from '@pnpm/error'
|
||||
import logger from '@pnpm/logger'
|
||||
import { getAllDependenciesFromManifest } from '@pnpm/manifest-utils'
|
||||
import binify, { Command } from '@pnpm/package-bins'
|
||||
import readModulesDir from '@pnpm/read-modules-dir'
|
||||
@@ -21,6 +22,7 @@ import unnest from 'ramda/src/unnest'
|
||||
import partition from 'ramda/src/partition'
|
||||
import fixBin from 'bin-links/lib/fix-bin'
|
||||
|
||||
const binsConflictLogger = logger('bins-conflict')
|
||||
const IS_WINDOWS = isWindows()
|
||||
const EXECUTABLE_SHEBANG_SUPPORTED = !IS_WINDOWS
|
||||
const POWER_SHELL_IS_SUPPORTED = IS_WINDOWS
|
||||
@@ -118,7 +120,6 @@ async function linkBins (
|
||||
binsDir: string,
|
||||
opts: {
|
||||
extendNodePath?: boolean
|
||||
warn: WarnFunction
|
||||
}
|
||||
): Promise<string[]> {
|
||||
if (allCmds.length === 0) return [] as string[]
|
||||
@@ -132,7 +133,12 @@ async function linkBins (
|
||||
const usedNames = fromPairs(cmdsWithOwnName.map((cmd) => [cmd.name, cmd.name] as KeyValuePair<string, string>))
|
||||
const results2 = await pSettle(cmdsWithOtherNames.map(async (cmd) => {
|
||||
if (usedNames[cmd.name]) {
|
||||
opts.warn(`Cannot link binary '${cmd.name}' of '${cmd.pkgName}' to '${binsDir}': binary of '${usedNames[cmd.name]}' is already linked`, 'BINARIES_CONFLICT')
|
||||
binsConflictLogger.debug({
|
||||
binaryName: cmd.name,
|
||||
binsDir,
|
||||
linkedPkgName: usedNames[cmd.name],
|
||||
skippedPkgName: cmd.pkgName,
|
||||
})
|
||||
return Promise.resolve(undefined)
|
||||
}
|
||||
usedNames[cmd.name] = cmd.pkgName
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { promisify } from 'util'
|
||||
import { promises as fs } from 'fs'
|
||||
import path from 'path'
|
||||
import logger from '@pnpm/logger'
|
||||
import linkBins, {
|
||||
linkBinsOfPackages,
|
||||
} from '@pnpm/link-bins'
|
||||
@@ -12,8 +13,18 @@ import normalizePath from 'normalize-path'
|
||||
import exists from 'path-exists'
|
||||
import tempy from 'tempy'
|
||||
|
||||
jest.mock('@pnpm/logger', () => {
|
||||
const debug = jest.fn()
|
||||
return () => ({ debug })
|
||||
})
|
||||
|
||||
const binsConflictLogger = logger('bins-conflict')
|
||||
const ncp = promisify(ncpcb)
|
||||
|
||||
beforeEach(() => {
|
||||
binsConflictLogger.debug['mockClear']()
|
||||
})
|
||||
|
||||
// The fixtures directory is copied to fixtures_for_testing before the tests run
|
||||
// This happens because the tests conver some of the files into executables
|
||||
const fixtures = path.join(__dirname, 'fixtures_for_testing')
|
||||
@@ -163,7 +174,12 @@ test('linkBins() resolves conflicts. Prefer packages that use their name as bin
|
||||
|
||||
await linkBins(path.join(binNameConflictsFixture, 'node_modules'), binTarget, { warn })
|
||||
|
||||
expect(warn).toHaveBeenCalledWith(`Cannot link binary 'bar' of 'foo' to '${binTarget}': binary of 'bar' is already linked`, 'BINARIES_CONFLICT')
|
||||
expect(binsConflictLogger.debug).toHaveBeenCalledWith({
|
||||
binaryName: 'bar',
|
||||
binsDir: binTarget,
|
||||
linkedPkgName: 'bar',
|
||||
skippedPkgName: 'foo',
|
||||
})
|
||||
expect(await fs.readdir(binTarget)).toEqual(getExpectedBins(['bar', 'foofoo']))
|
||||
|
||||
{
|
||||
@@ -202,7 +218,12 @@ test('linkBinsOfPackages() resolves conflicts. Prefer packages that use their na
|
||||
{ warn }
|
||||
)
|
||||
|
||||
expect(warn).toHaveBeenCalledWith(`Cannot link binary 'bar' of 'foo' to '${binTarget}': binary of 'bar' is already linked`, 'BINARIES_CONFLICT')
|
||||
expect(binsConflictLogger.debug).toHaveBeenCalledWith({
|
||||
binaryName: 'bar',
|
||||
binsDir: binTarget,
|
||||
linkedPkgName: 'bar',
|
||||
skippedPkgName: 'foo',
|
||||
})
|
||||
expect(await fs.readdir(binTarget)).toEqual(getExpectedBins(['bar', 'foofoo']))
|
||||
|
||||
{
|
||||
|
||||
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@@ -1164,6 +1164,7 @@ importers:
|
||||
specifiers:
|
||||
'@pnpm/error': workspace:2.0.0
|
||||
'@pnpm/link-bins': 'link:'
|
||||
'@pnpm/logger': ^4.0.0
|
||||
'@pnpm/manifest-utils': workspace:2.1.0
|
||||
'@pnpm/package-bins': workspace:5.0.5
|
||||
'@pnpm/read-modules-dir': workspace:3.0.1
|
||||
@@ -1203,6 +1204,7 @@ importers:
|
||||
ramda: 0.27.1
|
||||
devDependencies:
|
||||
'@pnpm/link-bins': 'link:'
|
||||
'@pnpm/logger': 4.0.0
|
||||
'@types/is-windows': 1.0.0
|
||||
'@types/ncp': 2.0.5
|
||||
'@types/node': 14.17.27
|
||||
|
||||
Reference in New Issue
Block a user