fix: run the install scripts of deps in a workspace with no root project (#4211)

close #4209
This commit is contained in:
Zoltan Kochan
2022-01-08 17:11:12 +02:00
committed by GitHub
parent 83a4ea0662
commit 0b78577f53
3 changed files with 31 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/headless": patch
---
Run the install scripts of hoisted dependencies in a workspace with no root project.

View File

@@ -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()
})

View File

@@ -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<string>()
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)