From 0b78577f53543cdb3456e50668ed146a4e38d4a5 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 8 Jan 2022 17:11:12 +0200 Subject: [PATCH] fix: run the install scripts of deps in a workspace with no root project (#4211) close #4209 --- .changeset/fresh-countries-smell.md | 5 ++++ .../core/test/hoistedNodeLinker/install.ts | 23 +++++++++++++++++++ packages/headless/src/index.ts | 5 ++-- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .changeset/fresh-countries-smell.md diff --git a/.changeset/fresh-countries-smell.md b/.changeset/fresh-countries-smell.md new file mode 100644 index 0000000000..a4286b751f --- /dev/null +++ b/.changeset/fresh-countries-smell.md @@ -0,0 +1,5 @@ +--- +"@pnpm/headless": patch +--- + +Run the install scripts of hoisted dependencies in a workspace with no root project. diff --git a/packages/core/test/hoistedNodeLinker/install.ts b/packages/core/test/hoistedNodeLinker/install.ts index 29e98cb5d0..b0f50e9499 100644 --- a/packages/core/test/hoistedNodeLinker/install.ts +++ b/packages/core/test/hoistedNodeLinker/install.ts @@ -160,3 +160,26 @@ test('run pre/postinstall scripts. bin files should be linked in a hoisted node_ const generatedByPostinstall = project.requireModule('pre-and-postinstall-scripts-example/generated-by-postinstall') expect(typeof generatedByPostinstall).toBe('function') }) + +// Covers https://github.com/pnpm/pnpm/issues/4209 +test('running install scripts in a workspace that has no root project', async () => { + prepareEmpty() + + await mutateModules([ + { + buildIndex: 0, + manifest: { + name: 'project-1', + version: '1.0.0', + + dependencies: { + 'pre-and-postinstall-scripts-example': '1.0.0', + }, + }, + mutation: 'install', + rootDir: path.resolve('project-1'), + }, + ], await testDefaults({ fastUnpack: false, nodeLinker: 'hoisted' })) + + expect(fs.existsSync('node_modules/pre-and-postinstall-scripts-example/generated-by-preinstall.js')).toBeTruthy() +}) diff --git a/packages/headless/src/index.ts b/packages/headless/src/index.ts index 1edc3b2c2f..00c26845a0 100644 --- a/packages/headless/src/index.ts +++ b/packages/headless/src/index.ts @@ -61,6 +61,7 @@ import equals from 'ramda/src/equals' import fromPairs from 'ramda/src/fromPairs' import omit from 'ramda/src/omit' import props from 'ramda/src/props' +import union from 'ramda/src/union' import realpathMissing from 'realpath-missing' import linkHoistedModules from './linkHoistedModules' import lockfileToDepGraph, { @@ -385,9 +386,9 @@ export default async (opts: HeadlessOptions) => { ) } else { const directNodes = new Set() - for (const id of importerIds) { + for (const id of union(importerIds, ['.'])) { Object - .values(directDependenciesByImporterId[id]) + .values(directDependenciesByImporterId[id] ?? {}) .filter((loc) => graph[loc]) .forEach((loc) => { directNodes.add(loc)