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(link): don't update version specs in package.json #6513

Merged
merged 2 commits into from May 9, 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/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