fix: linking deps by absolute path

close #3025
PR #3055
This commit is contained in:
Zoltan Kochan
2021-01-03 01:50:05 +02:00
committed by GitHub
parent 0e546dd1f6
commit 409736b4d9
3 changed files with 41 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-installation": patch
---
Linking dependencies by absolute path should work.

View File

@@ -27,6 +27,8 @@ import pathAbsolute = require('path-absolute')
import R = require('ramda')
import renderHelp = require('render-help')
const isWindows = process.platform === 'win32' || global['FAKE_WINDOWS']
const isFilespec = isWindows ? /^(?:[.]|~[/]|[/\\]|[a-zA-Z]:)/ : /^(?:[.]|~[/]|[/]|[a-zA-Z]:)/
const installLimit = pLimit(4)
export const rcOptionsTypes = cliOptionsTypes
@@ -80,7 +82,7 @@ export async function handler (
| 'saveProd'
| 'workspaceDir'
> & Partial<Pick<Config, 'globalDir' | 'linkWorkspacePackages'>>,
params: string[]
params?: string[]
) {
const cwd = opts?.dir ?? process.cwd()
@@ -116,7 +118,7 @@ export async function handler (
return
}
const [pkgPaths, pkgNames] = R.partition((inp) => inp.startsWith('.'), params)
const [pkgPaths, pkgNames] = R.partition((inp) => isFilespec.test(inp), params)
if (pkgNames.length) {
let globalPkgNames!: string[]

View File

@@ -105,6 +105,38 @@ test('relative link', async () => {
expect(currentLockfile.dependencies['hello-world-js-bin']).toBe('link:../hello-world-js-bin') // link added to wanted lockfile
})
test('absolute link', async () => {
const project = prepare({
dependencies: {
'hello-world-js-bin': '*',
},
})
const linkedPkgName = 'hello-world-js-bin'
const linkedPkgPath = path.resolve('..', linkedPkgName)
await copyFixture(linkedPkgName, linkedPkgPath)
await link.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
npmGlobalBinDir: '',
}, [linkedPkgPath])
await project.isExecutable('.bin/hello-world-js-bin')
// The linked package has been installed successfully as well with bins linked
// to node_modules/.bin
const linkedProject = assertProject(linkedPkgPath)
await linkedProject.isExecutable('.bin/cowsay')
const wantedLockfile = await project.readLockfile()
expect(wantedLockfile.dependencies['hello-world-js-bin']).toBe('link:../hello-world-js-bin') // link added to wanted lockfile
expect(wantedLockfile.specifiers['hello-world-js-bin']).toBe('*') // specifier of linked dependency added to ${WANTED_LOCKFILE}
const currentLockfile = await project.readCurrentLockfile()
expect(currentLockfile.dependencies['hello-world-js-bin']).toBe('link:../hello-world-js-bin') // link added to wanted lockfile
})
test('link --production', async () => {
const projects = preparePackages([
{