mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-26 07:27:20 -04:00
fix: local dependencies pointing to a symlink (#6854)
This commit is contained in:
6
.changeset/eight-countries-poke.md
Normal file
6
.changeset/eight-countries-poke.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/symlink-dependency": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
When dealing with a local dependency that is a path to a symlink, a new symlink should be created to the original symlink, not to the actual directory location.
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
type DependencyType,
|
||||
rootLogger,
|
||||
} from '@pnpm/core-loggers'
|
||||
import { globalWarn } from '@pnpm/logger'
|
||||
import { type DependenciesField } from '@pnpm/types'
|
||||
import symlinkDir from 'symlink-dir'
|
||||
|
||||
@@ -44,25 +43,13 @@ export async function symlinkDirectRootDependency (
|
||||
}
|
||||
}
|
||||
|
||||
let dependencyRealLocation!: string
|
||||
try {
|
||||
dependencyRealLocation = await fs.realpath(dependencyLocation)
|
||||
} catch (err: any) { // eslint-disable-line
|
||||
if (err.code !== 'ENOENT') throw err
|
||||
globalWarn(`Local dependency not found at ${dependencyLocation}`)
|
||||
// Sometimes the linked in local package does not exist during installation
|
||||
// and is created later via a build script.
|
||||
// That is why we create the symlink even if the target directory does not exist.
|
||||
dependencyRealLocation = dependencyLocation
|
||||
}
|
||||
|
||||
const dest = path.join(destModulesDirReal, importAs)
|
||||
const { reused } = await symlinkDir(dependencyRealLocation, dest)
|
||||
const { reused } = await symlinkDir(dependencyLocation, dest)
|
||||
if (reused) return // if the link was already present, don't log
|
||||
rootLogger.debug({
|
||||
added: {
|
||||
dependencyType: opts.fromDependenciesField && DEP_TYPE_BY_DEPS_FIELD_NAME[opts.fromDependenciesField] as DependencyType,
|
||||
linkedFrom: dependencyRealLocation,
|
||||
linkedFrom: dependencyLocation,
|
||||
name: importAs,
|
||||
realName: opts.linkedPackage.name,
|
||||
version: opts.linkedPackage.version,
|
||||
|
||||
@@ -59,6 +59,17 @@ test('local file', async () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('a symlink to a symlink to a local dependency is preserved', async () => {
|
||||
prepareEmpty()
|
||||
const localPkgDir = path.resolve('..', 'local-pkg')
|
||||
f.copy('local-pkg', localPkgDir)
|
||||
await symlinkDir(localPkgDir, path.resolve('../symlink'))
|
||||
|
||||
await addDependenciesToPackage({}, ['link:../symlink'], await testDefaults())
|
||||
|
||||
expect(await fs.readlink(path.resolve('node_modules/local-pkg'))).toContain('symlink')
|
||||
})
|
||||
|
||||
test('local directory with no package.json', async () => {
|
||||
const project = prepareEmpty()
|
||||
await fs.mkdir('pkg')
|
||||
|
||||
Reference in New Issue
Block a user