mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-11 02:29:48 -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
100 lines
3.5 KiB
TypeScript
100 lines
3.5 KiB
TypeScript
/// <reference path="../../../__typings__/index.d.ts"/>
|
|
import path from 'node:path'
|
|
|
|
import { createClient } from '@pnpm/installing.client'
|
|
import { createPackageStore } from '@pnpm/store.controller'
|
|
import type { FetchPackageToStoreFunction } from '@pnpm/store.controller-types'
|
|
import { StoreIndex } from '@pnpm/store.index'
|
|
import { temporaryDirectory } from 'tempy'
|
|
|
|
describe('store.importPackage()', () => {
|
|
it('selects import method automatically', async () => {
|
|
const tmp = temporaryDirectory()
|
|
const storeDir = path.join(tmp, 'store')
|
|
const cacheDir = path.join(tmp, 'cache')
|
|
const registry = 'https://registry.npmjs.org/'
|
|
const storeIndex = new StoreIndex(storeDir)
|
|
const { resolve, fetchers, clearResolutionCache } = createClient({
|
|
configByUri: {},
|
|
cacheDir: path.join(tmp, 'cache'),
|
|
storeDir: path.join(tmp, 'store'),
|
|
storeIndex,
|
|
registries: {
|
|
default: registry,
|
|
},
|
|
})
|
|
const storeController = createPackageStore(resolve, fetchers, {
|
|
storeDir,
|
|
cacheDir,
|
|
verifyStoreIntegrity: true,
|
|
virtualStoreDirMaxLength: 120,
|
|
clearResolutionCache,
|
|
storeIndex,
|
|
})
|
|
const pkgId = 'registry.npmjs.org/is-positive/1.0.0'
|
|
const fetchResponse = (storeController.fetchPackage as FetchPackageToStoreFunction)({
|
|
force: false,
|
|
lockfileDir: temporaryDirectory(),
|
|
pkg: {
|
|
id: pkgId,
|
|
resolution: {
|
|
integrity: 'sha512-xxzPGZ4P2uN6rROUa5N9Z7zTX6ERuE0hs6GUOc/cKBLF2NqKc16UwqHMt3tFg4CO6EBTE5UecUasg+3jZx3Ckg==',
|
|
tarball: 'https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz',
|
|
},
|
|
},
|
|
})
|
|
const importTo = temporaryDirectory()
|
|
const { importMethod } = await storeController.importPackage(importTo, {
|
|
filesResponse: (await fetchResponse.fetching()).files,
|
|
force: false,
|
|
})
|
|
expect(typeof importMethod).toBe('string')
|
|
expect(typeof (await import(importTo)).default).toBe('function')
|
|
})
|
|
|
|
it('uses copying', async () => {
|
|
const tmp = temporaryDirectory()
|
|
const storeDir = path.join(tmp, 'store')
|
|
const cacheDir = path.join(tmp, 'cache')
|
|
const registry = 'https://registry.npmjs.org/'
|
|
const storeIndex = new StoreIndex(storeDir)
|
|
const { resolve, fetchers, clearResolutionCache } = createClient({
|
|
configByUri: {},
|
|
cacheDir: path.join(tmp, 'cache'),
|
|
storeDir: path.join(tmp, 'store'),
|
|
storeIndex,
|
|
registries: {
|
|
default: registry,
|
|
},
|
|
})
|
|
const storeController = createPackageStore(resolve, fetchers, {
|
|
packageImportMethod: 'copy',
|
|
storeDir,
|
|
cacheDir,
|
|
verifyStoreIntegrity: true,
|
|
virtualStoreDirMaxLength: 120,
|
|
clearResolutionCache,
|
|
storeIndex,
|
|
})
|
|
const pkgId = 'registry.npmjs.org/is-positive/1.0.0'
|
|
const fetchResponse = (storeController.fetchPackage as FetchPackageToStoreFunction)({
|
|
force: false,
|
|
lockfileDir: temporaryDirectory(),
|
|
pkg: {
|
|
id: pkgId,
|
|
resolution: {
|
|
integrity: 'sha512-xxzPGZ4P2uN6rROUa5N9Z7zTX6ERuE0hs6GUOc/cKBLF2NqKc16UwqHMt3tFg4CO6EBTE5UecUasg+3jZx3Ckg==',
|
|
tarball: 'https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz',
|
|
},
|
|
},
|
|
})
|
|
const importTo = temporaryDirectory()
|
|
const { importMethod } = await storeController.importPackage(importTo, {
|
|
filesResponse: (await fetchResponse.fetching()).files,
|
|
force: false,
|
|
})
|
|
expect(importMethod).toBe('copy')
|
|
expect(typeof (await import(importTo)).default).toBe('function')
|
|
})
|
|
})
|