fix(directory-fetcher): respect absolute paths in resolution.directory (#11318)

`path.join(lockfileDir, resolution.directory)` mangles absolute cross-drive
Windows paths by literally concatenating them (`path.join('D:\\foo',
'C:\\bar')` → `'D:\\foo\\C:\\bar'`). Switch to `path.resolve` so stored
absolute paths are used as-is.

This surfaced as an ENOENT during `pnpm setup` in CI when `PNPM_HOME` and
the OS temp dir (containing the extracted v11 tarball that setup installs
via `pnpm add -g file:<dir>`) were on different drives.
This commit is contained in:
Zoltan Kochan
2026-04-20 21:11:29 +02:00
committed by GitHub
parent 5a293d250c
commit e03e8f4d8d
3 changed files with 30 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/fetching.directory-fetcher": patch
"pnpm": patch
---
Fix installing a directory dependency (`file:<dir>`) from an absolute path on a different drive on Windows. The directory fetcher was joining the stored directory onto `lockfileDir`, which on Windows concatenates an absolute cross-drive path literally (`path.join('D:\\...', 'C:\\Users\\...')``'D:\\...\\C:\\Users\\...'`). Use `path.resolve` so absolute paths are respected. This surfaced as an ENOENT during `pnpm setup` in CI when `PNPM_HOME` and the OS temp directory were on different drives.

View File

@@ -24,7 +24,10 @@ export function createDirectoryFetcher (
const fetchFromDir = opts?.includeOnlyPackageFiles ? fetchPackageFilesFromDir : fetchAllFilesFromDir.bind(null, readFileStat)
const directoryFetcher: DirectoryFetcher = (cafs, resolution, opts) => {
const dir = path.join(opts.lockfileDir, resolution.directory)
// Use path.resolve so absolute directories (e.g. cross-drive Windows paths
// stored by `file:` deps) are respected instead of being concatenated
// onto lockfileDir.
const dir = path.resolve(opts.lockfileDir, resolution.directory)
return fetchFromDir(dir)
}

View File

@@ -111,6 +111,26 @@ test('fetch does not fail on package with broken symlink', async () => {
expect(debug).toHaveBeenCalledWith({ brokenSymlink: path.resolve('not-exists') })
})
test('fetch respects absolute directory regardless of lockfileDir', async () => {
const absDir = f.find('simple-pkg')
const fetcher = createDirectoryFetcher({ includeOnlyPackageFiles: true })
// lockfileDir is unrelated to the directory being fetched. When the
// stored directory is absolute (e.g. cross-drive `file:` deps on Windows)
// the fetcher must use the absolute path as-is rather than joining it
// onto lockfileDir.
// eslint-disable-next-line
const fetchResult = await fetcher.directory({} as any, {
directory: absDir,
type: 'directory',
}, {
lockfileDir: f.find('no-manifest'),
})
expect(fetchResult.local).toBe(true)
expect(fetchResult.filesMap.get('package.json')).toBe(path.join(absDir, 'package.json'))
})
describe('fetch resolves symlinked files to their real locations', () => {
const indexJsPath = path.join(f.find('no-manifest'), 'index.js')
const srcPath = f.find('simple-pkg')