Skip to content

Commit

Permalink
fix: add -g to mismatch registries error info when original command h…
Browse files Browse the repository at this point in the history
…as -g option (#6365)

close #6224
  • Loading branch information
await-ovo authored and zkochan committed Apr 6, 2023
1 parent 0e5fc3d commit b7ba559
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/tender-birds-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@pnpm/get-context": patch
"@pnpm/core": patch
"pnpm": patch
---

Add -g to mismatch registries error info when original command has -g option [#6224](https://github.com/pnpm/pnpm/issues/6224).
16 changes: 16 additions & 0 deletions pkg-manager/core/test/lockfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,22 @@ test('lockfile is not getting broken if the used registry changes', async () =>
])
})

test('when using a different registry, add -g to the error report according to options.global', async () => {
prepareEmpty()

const manifest = await addDependenciesToPackage({}, ['is-positive@1'], await testDefaults())

const newOpts = await testDefaults({ registries: { default: 'https://registry.npmjs.org/' }, global: true })
let err!: PnpmError
try {
await addDependenciesToPackage(manifest, ['is-negative@1'], newOpts)
} catch (_err: any) { // eslint-disable-line
err = _err
}
expect(err.code).toBe('ERR_PNPM_REGISTRIES_MISMATCH')
expect(err.message).toContain('pnpm install -g')
})

test('broken lockfile is fixed even if it seems like up to date at first. Unless frozenLockfile option is set to true', async () => {
const project = prepareEmpty()
await addDistTag({ package: '@pnpm.e2e/pkg-with-1-dep', version: '100.0.0', distTag: 'latest' })
Expand Down
5 changes: 4 additions & 1 deletion pkg-manager/get-context/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface GetContextOptions {
forcePublicHoistPattern?: boolean

useLockfileV6?: boolean
global?: boolean
}

export async function getContext (
Expand All @@ -121,6 +122,7 @@ export async function getContext (

forcePublicHoistPattern: opts.forcePublicHoistPattern,
publicHoistPattern: opts.publicHoistPattern,
global: opts.global,
})
if (purged) {
importersContext = await readProjectsContext(opts.allProjects, {
Expand Down Expand Up @@ -218,6 +220,7 @@ async function validateModules (

publicHoistPattern?: string[] | undefined
forcePublicHoistPattern?: boolean
global?: boolean
}
): Promise<{ purged: boolean }> {
const rootProject = projects.find(({ id }) => id === '.')
Expand Down Expand Up @@ -281,7 +284,7 @@ async function validateModules (
await Promise.all(projects.map(purgeModulesDirsOfImporter.bind(null, opts.virtualStoreDir)))
return { purged: true }
}
throw new PnpmError('REGISTRIES_MISMATCH', `This modules directory was created using the following registries configuration: ${JSON.stringify(modules.registries)}. The current configuration is ${JSON.stringify(opts.registries)}. To recreate the modules directory using the new settings, run "pnpm install".`)
throw new PnpmError('REGISTRIES_MISMATCH', `This modules directory was created using the following registries configuration: ${JSON.stringify(modules.registries)}. The current configuration is ${JSON.stringify(opts.registries)}. To recreate the modules directory using the new settings, run "pnpm install${opts.global ? ' -g' : ''}".`)
}
if (purged && (rootProject == null)) {
await purgeModulesDirsOfImporter(opts.virtualStoreDir, {
Expand Down

0 comments on commit b7ba559

Please sign in to comment.