mirror of
https://github.com/pnpm/pnpm.git
synced 2026-02-09 14:42:41 -05:00
fix: linking package globally from workspace should work (#9521)
close #9506 close #9515
This commit is contained in:
6
.changeset/gentle-turtles-ring.md
Normal file
6
.changeset/gentle-turtles-ring.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/config": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
`pnpm link` should work from inside a workspace [#9506](https://github.com/pnpm/pnpm/issues/9506).
|
||||
@@ -288,6 +288,7 @@ export async function getConfig (opts: {
|
||||
}
|
||||
pnpmConfig.globalPkgDir = path.join(globalDirRoot, LAYOUT_VERSION.toString())
|
||||
if (cliOptions['global']) {
|
||||
delete pnpmConfig.workspaceDir
|
||||
pnpmConfig.dir = pnpmConfig.globalPkgDir
|
||||
pnpmConfig.bin = npmConfig.get('global-bin-dir') ?? env.PNPM_HOME
|
||||
if (pnpmConfig.bin) {
|
||||
|
||||
@@ -3,7 +3,8 @@ import PATH_NAME from 'path-name'
|
||||
import fs from 'fs'
|
||||
import { isExecutable } from '@pnpm/assert-project'
|
||||
import { LAYOUT_VERSION } from '@pnpm/constants'
|
||||
import { prepare } from '@pnpm/prepare'
|
||||
import { prepare, preparePackages } from '@pnpm/prepare'
|
||||
import { sync as writeYamlFile } from 'write-yaml-file'
|
||||
import { execPnpm } from './utils'
|
||||
|
||||
const testLinkGlobal = (specifyGlobalOption: boolean) => async () => {
|
||||
@@ -33,3 +34,25 @@ console.log("hello world");`, 'utf8')
|
||||
test('link globally the command of a package that has no name in package.json', testLinkGlobal(true))
|
||||
|
||||
test('link a package globally without specifying the global option', testLinkGlobal(false))
|
||||
|
||||
test('link a package from a workspace to the global package', async () => {
|
||||
preparePackages([
|
||||
{
|
||||
name: 'project-1',
|
||||
version: '1.0.0',
|
||||
},
|
||||
])
|
||||
const global = path.resolve('..', 'global')
|
||||
const pnpmHome = path.join(global, 'pnpm')
|
||||
fs.mkdirSync(global)
|
||||
const env = { [PATH_NAME]: pnpmHome, PNPM_HOME: pnpmHome, XDG_DATA_HOME: global }
|
||||
|
||||
writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })
|
||||
|
||||
process.chdir('project-1')
|
||||
|
||||
await execPnpm(['link'], { env })
|
||||
|
||||
const globalPrefix = path.join(global, `pnpm/global/${LAYOUT_VERSION}`)
|
||||
expect(fs.existsSync(path.join(globalPrefix, 'node_modules/project-1'))).toBeTruthy()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user