Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: linking bins of local deps, when node-linker is hoisted #6488

Merged
merged 2 commits into from Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -516,7 +516,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