Skip to content

Commit

Permalink
fix(link): don't update version specs in package.json (#6513)
Browse files Browse the repository at this point in the history
close #4341
  • Loading branch information
zkochan committed May 9, 2023
1 parent 3f85e75 commit d5c40b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/angry-bobcats-develop.md
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-installation": patch
"pnpm": patch
---

`pnpm link -g <pkg-name>` should not modify the `package.json` file [#4341](https://github.com/pnpm/pnpm/issues/4341).
4 changes: 3 additions & 1 deletion pkg-manager/plugin-commands-installation/src/link.ts
Expand Up @@ -200,7 +200,9 @@ export async function handler (
storeDir: storeL.dir,
manifest,
} as LinkFunctionOptions)
await writeProjectManifest(newManifest)
if (!opts.cliOptions?.global) {
await writeProjectManifest(newManifest)
}

await Promise.all(
Array.from(storeControllerCache.values())
Expand Down
9 changes: 7 additions & 2 deletions pkg-manager/plugin-commands-installation/test/link.ts
Expand Up @@ -5,6 +5,7 @@ import { install, link } from '@pnpm/plugin-commands-installation'
import { prepare, preparePackages } from '@pnpm/prepare'
import { assertProject, isExecutable } from '@pnpm/assert-project'
import { fixtures } from '@pnpm/test-fixtures'
import { sync as loadJsonFile } from 'load-json-file'
import PATH from 'path-name'
import writePkg from 'write-pkg'
import { DEFAULT_OPTS } from './utils'
Expand Down Expand Up @@ -107,7 +108,7 @@ test('link to global bin from the specified directory', async function () {
})

test('link a global package to the specified directory', async function () {
const project = prepare()
const project = prepare({ dependencies: { 'global-package-with-bin': '0.0.0' } })
process.chdir('..')

const globalDir = path.resolve('global')
Expand All @@ -132,20 +133,24 @@ test('link a global package to the specified directory', async function () {
})

process.chdir('..')
const projectDir = path.resolve('./project')

// link from global
await link.handler({
...DEFAULT_OPTS,
cliOptions: {
global: true,
dir: path.resolve('./project'),
dir: projectDir,
},
bin: globalBin,
dir: globalDir,
saveProd: true, // @pnpm/config sets this setting to true when global is true. This should probably be changed.
}, ['global-package-with-bin'])

process.env[PATH] = oldPath

const manifest = loadJsonFile<any>(path.join(projectDir, 'package.json')) // eslint-disable-line @typescript-eslint/no-explicit-any
expect(manifest.dependencies).toStrictEqual({ 'global-package-with-bin': '0.0.0' })
await project.has('global-package-with-bin')
})

Expand Down

0 comments on commit d5c40b5

Please sign in to comment.