diff --git a/.changeset/itchy-pigs-deny.md b/.changeset/itchy-pigs-deny.md new file mode 100644 index 0000000000..0aa91bf855 --- /dev/null +++ b/.changeset/itchy-pigs-deny.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-installation": patch +--- + +pnpm i should work correctly on virtual drives instead of silently shutting down diff --git a/packages/plugin-commands-installation/package.json b/packages/plugin-commands-installation/package.json index bebee9f388..b9ea992089 100644 --- a/packages/plugin-commands-installation/package.json +++ b/packages/plugin-commands-installation/package.json @@ -54,7 +54,8 @@ "tempy": "^1.0.0", "write-json-file": "^4.3.0", "write-pkg": "4.0.0", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^4.2.0", + "symlink-dir": "^5.0.0" }, "dependencies": { "@pnpm/cli-utils": "workspace:0.6.49", diff --git a/packages/plugin-commands-installation/src/recursive.ts b/packages/plugin-commands-installation/src/recursive.ts index 8bc1a3c869..36756e9ff2 100755 --- a/packages/plugin-commands-installation/src/recursive.ts +++ b/packages/plugin-commands-installation/src/recursive.ts @@ -176,7 +176,7 @@ export default async function recursive ( // For a workspace with shared lockfile if (opts.lockfileDir && ['add', 'install', 'remove', 'update', 'import'].includes(cmdFullName)) { let importers = await getImporters() - const calculatedRepositoryRoot = calculateRepositoryRoot(opts.workspaceDir, importers.map(x => x.rootDir)) + const calculatedRepositoryRoot = await fs.realpath(calculateRepositoryRoot(opts.workspaceDir, importers.map(x => x.rootDir))) const isFromWorkspace = isSubdir.bind(null, calculatedRepositoryRoot) importers = await pFilter(importers, async ({ rootDir }: { rootDir: string }) => isFromWorkspace(await fs.realpath(rootDir))) if (importers.length === 0) return true diff --git a/packages/plugin-commands-installation/test/miscRecursive.ts b/packages/plugin-commands-installation/test/miscRecursive.ts index 084259723c..233e01cdad 100644 --- a/packages/plugin-commands-installation/test/miscRecursive.ts +++ b/packages/plugin-commands-installation/test/miscRecursive.ts @@ -12,6 +12,7 @@ import loadJsonFile from 'load-json-file' import writeJsonFile from 'write-json-file' import writeYamlFile from 'write-yaml-file' import { DEFAULT_OPTS } from './utils' +import symlinkDir from 'symlink-dir' test('recursive add/remove', async () => { const projects = preparePackages([ @@ -643,3 +644,30 @@ test('prefer-workspace-package', async () => { const lockfile = await readYamlFile(path.resolve('pnpm-lock.yaml')) expect(lockfile.importers['project-1'].dependencies?.foo).toBe('link:../foo') }) + +test('installing in monorepo with shared lockfile should work on virtual drives', async () => { + const projects = preparePackages([ + { + name: 'project-1', + version: '1.0.0', + dependencies: { + 'is-positive': '1.0.0', + }, + }, + ]) + const virtualPath = process.cwd() + '-virtual-disk' + // symlink simulates windows' subst + await symlinkDir(process.cwd(), virtualPath) + const { allProjects, selectedProjectsGraph } = await readProjects(virtualPath, []) + await install.handler({ + ...DEFAULT_OPTS, + lockfileDir: virtualPath, + allProjects, + dir: virtualPath, + recursive: true, + selectedProjectsGraph, + workspaceDir: virtualPath, + }) + + await projects['project-1'].has('is-positive') +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1a930fc6aa..566f061cf2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2154,6 +2154,7 @@ importers: read-yaml-file: ^2.1.0 render-help: ^1.0.1 sinon: ^11.1.1 + symlink-dir: ^5.0.0 tempy: ^1.0.0 version-selector-type: ^3.0.0 write-json-file: ^4.3.0 @@ -2225,6 +2226,7 @@ importers: proxyquire: 2.1.3 read-yaml-file: 2.1.0 sinon: 11.1.2 + symlink-dir: 5.0.1 tempy: 1.0.1 write-json-file: 4.3.0 write-pkg: 4.0.0