mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-28 11:01:30 -04:00
Replaces the dual `authConfig` (raw .npmrc) + `authInfos` (parsed auth) + `sslConfigs` (parsed SSL) pattern with a single structured `configByUri: Record<string, RegistryConfig>` field on Config.
### New types (`@pnpm/types`)
- **`RegistryConfig`** — per-registry config: `{ creds?: Creds, tls?: TlsConfig }`
- **`Creds`** — auth credentials: `{ authToken?, basicAuth?, tokenHelper? }`
- **`TlsConfig`** — TLS config: `{ cert?, key?, ca? }`
### Key changes
- Rewrite `createGetAuthHeaderByURI` to accept `Record<string, RegistryConfig>` instead of raw .npmrc key-value pairs
- Eliminate duplicate auth parsing between `getAuthHeadersFromConfig` and `getNetworkConfigs`
- Remove `authConfig` from the install pipeline (`StrictInstallOptions`, `HeadlessOptions`), replaced by `configByUri`
- Remove `sslConfigs` from Config — SSL fields now live in `configByUri[uri].tls`
- Remove `authConfig['registry']` mutation in `extendInstallOptions` (default registry now passed directly to `createGetAuthHeaderByURI`)
- `authConfig` remains on Config only for raw .npmrc access (config commands, error reporting, config inheritance)
### Security
- tokenHelper in project .npmrc now throws instead of being silently stripped
- tokenHelper execution uses `shell: false` to prevent shell metacharacter injection
- Basic auth uses `Buffer.from().toString('base64')` instead of `btoa()` for Unicode safety
- Dispatcher only creates custom agents when entries actually have TLS fields
98 lines
2.3 KiB
TypeScript
98 lines
2.3 KiB
TypeScript
import path from 'node:path'
|
|
|
|
import { jest } from '@jest/globals'
|
|
import { preparePackages } from '@pnpm/prepare'
|
|
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
|
import { filterProjectsBySelectorObjectsFromDir } from '@pnpm/workspace.projects-filter'
|
|
|
|
jest.unstable_mockModule('enquirer', () => ({ default: { prompt: jest.fn() } }))
|
|
|
|
const { default: enquirer } = await import('enquirer')
|
|
const { update, install } = await import('@pnpm/installing.commands')
|
|
|
|
const prompt = jest.mocked(enquirer.prompt)
|
|
|
|
const REGISTRY_URL = `http://localhost:${REGISTRY_MOCK_PORT}`
|
|
|
|
const DEFAULT_OPTIONS = {
|
|
argv: {
|
|
original: [],
|
|
},
|
|
bail: false,
|
|
bin: 'node_modules/.bin',
|
|
excludeLinksFromLockfile: false,
|
|
extraEnv: {},
|
|
cliOptions: {},
|
|
deployAllFiles: false,
|
|
include: {
|
|
dependencies: true,
|
|
devDependencies: true,
|
|
optionalDependencies: true,
|
|
},
|
|
lock: true,
|
|
pnpmfile: ['.pnpmfile.cjs'],
|
|
pnpmHomeDir: '',
|
|
preferWorkspacePackages: true,
|
|
configByUri: {},
|
|
registries: {
|
|
default: REGISTRY_URL,
|
|
},
|
|
rootProjectManifestDir: '',
|
|
sort: true,
|
|
userConfig: {},
|
|
workspaceConcurrency: 1,
|
|
virtualStoreDirMaxLength: process.platform === 'win32' ? 60 : 120,
|
|
}
|
|
|
|
test('interactive recursive should not error on git specifier override', async () => {
|
|
preparePackages([
|
|
{
|
|
location: '.',
|
|
package: {},
|
|
},
|
|
{
|
|
location: './project-1',
|
|
package: {
|
|
dependencies: {
|
|
'is-negative': '2.1.0',
|
|
},
|
|
},
|
|
},
|
|
])
|
|
|
|
prompt.mockResolvedValue({
|
|
updateDependencies: [],
|
|
})
|
|
|
|
const { allProjects, selectedProjectsGraph } = await filterProjectsBySelectorObjectsFromDir(process.cwd(), [])
|
|
const sharedOptions = {
|
|
...DEFAULT_OPTIONS,
|
|
allProjects,
|
|
selectedProjectsGraph,
|
|
recursive: true,
|
|
linkWorkspacePackages: true,
|
|
cacheDir: path.resolve('cache'),
|
|
storeDir: path.resolve('store'),
|
|
dir: process.cwd(),
|
|
lockfileDir: process.cwd(),
|
|
workspaceDir: process.cwd(),
|
|
overrides: {
|
|
'is-negative': 'github:kevva/is-negative#2.1.0',
|
|
},
|
|
}
|
|
|
|
await install.handler({
|
|
...sharedOptions,
|
|
})
|
|
await update.handler({
|
|
...sharedOptions,
|
|
interactive: true,
|
|
latest: true,
|
|
cliOptions: {
|
|
dev: true,
|
|
optional: true,
|
|
production: true,
|
|
},
|
|
})
|
|
})
|