feat(hooks): pass registries to preResolution hook (#6326)

This commit is contained in:
Dominic Elm
2023-03-31 01:43:43 +02:00
committed by GitHub
parent 0c4b20ec8e
commit c36c87c1ce
4 changed files with 15 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/core": patch
"pnpm": patch
---
Registries are now passed to the preResolution hook.

View File

@@ -1,4 +1,5 @@
import type { Lockfile } from '@pnpm/lockfile-file'
import type { Registries } from '@pnpm/types'
export interface PreResolutionHookContext {
wantedLockfile: Lockfile
@@ -7,6 +8,7 @@ export interface PreResolutionHookContext {
existsWantedLockfile: boolean
lockfileDir: string
storeDir: string
registries: Registries
}
export interface PreResolutionHookLogger {

View File

@@ -239,6 +239,7 @@ export async function mutateModules (
existsWantedLockfile: ctx.existsWantedLockfile,
lockfileDir: ctx.lockfileDir,
storeDir: ctx.storeDir,
registries: ctx.registries,
})
}

View File

@@ -632,6 +632,7 @@ test('preResolution hook', async () => {
const npmrc = `
global-pnpmfile=.pnpmfile.cjs
@foo:registry=https://foo.com
`
await fs.writeFile('.npmrc', npmrc, 'utf8')
@@ -646,4 +647,9 @@ test('preResolution hook', async () => {
expect(ctx.storeDir).toBeDefined()
expect(ctx.existsCurrentLockfile).toBe(false)
expect(ctx.existsWantedLockfile).toBe(false)
expect(ctx.registries).toEqual({
default: 'http://localhost:7776/',
'@foo': 'https://foo.com/',
})
})