Skip to content

Commit

Permalink
fix: linking bins of local deps, when node-linker is hoisted (#6488)
Browse files Browse the repository at this point in the history
close #6486
  • Loading branch information
zkochan committed Apr 30, 2023
1 parent f15397d commit 8c93fcb
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/hot-buttons-train.md
@@ -0,0 +1,6 @@
---
"@pnpm/headless": patch
"pnpm": patch
---

Link the bin files of local workspace dependencies, when `node-linker` is set to `hoisted` [6486](https://github.com/pnpm/pnpm/issues/6486).
68 changes: 67 additions & 1 deletion pkg-manager/core/test/hoistedNodeLinker/install.ts
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'
import { addDependenciesToPackage, install, mutateModules, mutateModulesInSingleProject } from '@pnpm/core'
import { prepareEmpty } from '@pnpm/prepare'
import { prepareEmpty, preparePackages } from '@pnpm/prepare'
import { addDistTag } from '@pnpm/registry-mock'
import rimraf from '@zkochan/rimraf'
import { sync as loadJsonFile } from 'load-json-file'
Expand Down Expand Up @@ -250,3 +250,69 @@ test('externalDependencies should prevent package from being hoisted to the root
expect(fs.existsSync('node_modules/ms')).toBeFalsy()
expect(fs.existsSync('node_modules/send/node_modules/ms')).toBeTruthy()
})

test('linking bins of local projects when node-linker is set to hoisted', async () => {
const project1Manifest = {
name: 'project-1',
version: '1.0.0',

dependencies: {
'project-2': 'workspace:*',
},
}
const project2Manifest = {
name: 'project-2',
version: '1.0.0',
bin: {
'project-2': 'index.js',
},
}
preparePackages([
project1Manifest,
project2Manifest,
])
fs.writeFileSync('project-2/index.js', '#!/usr/bin/env node\nconsole.log("hello")', 'utf8')

const workspacePackages = {
'project-1': {
'1.0.0': {
dir: path.resolve('project-1'),
manifest: project1Manifest,
},
},
'project-2': {
'1.0.0': {
dir: path.resolve('project-2'),
manifest: project2Manifest,
},
},
}

await mutateModules([
{
mutation: 'install',
rootDir: path.resolve('project-1'),
},
{
mutation: 'install',
rootDir: path.resolve('project-2'),
},
], await testDefaults({
allProjects: [
{
buildIndex: 0,
manifest: project1Manifest,
rootDir: path.resolve('project-1'),
},
{
buildIndex: 1,
manifest: project2Manifest,
rootDir: path.resolve('project-2'),
},
],
nodeLinker: 'hoisted',
workspacePackages,
}))

expect(fs.existsSync('project-1/node_modules/.bin/project-2')).toBeTruthy()
})
2 changes: 1 addition & 1 deletion pkg-manager/headless/src/index.ts
Expand Up @@ -494,7 +494,7 @@ export async function headlessInstall (opts: HeadlessOptions) {
/** Skip linking and due to no project manifest */
if (!opts.ignorePackageManifest) {
await Promise.all(selectedProjects.map(async (project) => {
if (opts.publicHoistPattern?.length && path.relative(opts.lockfileDir, project.rootDir) === '') {
if (opts.nodeLinker === 'hoisted' || opts.publicHoistPattern?.length && path.relative(opts.lockfileDir, project.rootDir) === '') {
await linkBinsOfImporter(project, {
extraNodePaths: opts.extraNodePaths,
preferSymlinkedExecutables: opts.preferSymlinkedExecutables,
Expand Down

0 comments on commit 8c93fcb

Please sign in to comment.