mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-13 11:05:52 -04:00
* refactor(config): split Config interface into settings + runtime context
Create ConfigContext for runtime state (hooks, finders, workspace graph,
CLI metadata) and keep Config for user-facing settings only. Functions
use Pick<Config, ...> & Pick<ConfigContext, ...> to express which fields
they need from each interface.
getConfig() now returns { config, context, warnings }. The CLI wrapper
returns { config, context } and spreads both when calling command
handlers (to be refactored to separate params in follow-up PRs).
Closes #11195
* fix: address review feedback
- Initialize cliOptions on pnpmConfig so context.cliOptions is never undefined
- Move rootProjectManifestDir assignment before ignoreLocalSettings guard
- Add allProjectsGraph to INTERNAL_CONFIG_KEYS
* refactor: remove INTERNAL_CONFIG_KEYS from configToRecord
configToRecord now accepts Config and ConfigContext separately, so
context fields are never in scope. Only auth-related Config fields
(authConfig, authInfos, sslConfigs) need filtering.
* refactor: eliminate INTERNAL_CONFIG_KEYS from configToRecord
configToRecord now receives the clean Config object and explicitlySetKeys
separately (via opts.config and opts.context), so context fields are
never in scope. main.ts passes the original split objects alongside
the spread for command handlers that need them.
* fix: spelling
* fix: import sorting
* fix: --config.xxx nconf overrides conflicting with --config CLI flag
When `pnpm add` registers `config: Boolean`, nopt captures
--config.xxx=yyy as the --config flag value instead of treating it
as a nconf-style config override. Fix by extracting --config.xxx args
before nopt parsing and re-parsing them separately.
Also rename the split config/context properties on the command opts
object to _config/_context to avoid clashing with the --config CLI option.
110 lines
3.1 KiB
TypeScript
110 lines
3.1 KiB
TypeScript
import path from 'node:path'
|
|
|
|
import {
|
|
cacheDelete,
|
|
cacheList,
|
|
cacheListRegistries,
|
|
cacheView,
|
|
} from '@pnpm/cache.api'
|
|
import { docsUrl } from '@pnpm/cli.utils'
|
|
import { type Config, type ConfigContext, types as allTypes } from '@pnpm/config.reader'
|
|
import { ABBREVIATED_META_DIR, FULL_FILTERED_META_DIR } from '@pnpm/constants'
|
|
import { PnpmError } from '@pnpm/error'
|
|
import { getStorePath } from '@pnpm/store.path'
|
|
import { pick } from 'ramda'
|
|
import { renderHelp } from 'render-help'
|
|
|
|
export const rcOptionsTypes = cliOptionsTypes
|
|
|
|
export function cliOptionsTypes (): Record<string, unknown> {
|
|
return {
|
|
...pick([
|
|
'registry',
|
|
'store-dir',
|
|
], allTypes),
|
|
}
|
|
}
|
|
|
|
export const commandNames = ['cache']
|
|
|
|
export function help (): string {
|
|
return renderHelp({
|
|
description: 'Inspect and manage the metadata cache',
|
|
descriptionLists: [
|
|
{
|
|
title: 'Commands',
|
|
|
|
list: [
|
|
{
|
|
description: 'Lists the available packages metadata cache. Supports filtering by glob',
|
|
name: 'list',
|
|
},
|
|
{
|
|
description: 'Lists all registries that have their metadata cache locally',
|
|
name: 'list-registries',
|
|
},
|
|
{
|
|
description: "Views information from the specified package's cache",
|
|
name: 'view',
|
|
},
|
|
{
|
|
description: 'Deletes metadata cache for the specified package(s). Supports patterns',
|
|
name: 'delete',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
url: docsUrl('cache'),
|
|
usages: ['pnpm cache <command>'],
|
|
})
|
|
}
|
|
|
|
export type CacheCommandOptions = Pick<Config, 'cacheDir' | 'storeDir' | 'pnpmHomeDir' | 'resolutionMode' | 'registrySupportsTimeField'> & Pick<ConfigContext, 'cliOptions'>
|
|
|
|
export async function handler (opts: CacheCommandOptions, params: string[]): Promise<string | undefined> {
|
|
const cacheType = (opts.resolutionMode === 'time-based' && !opts.registrySupportsTimeField)
|
|
? FULL_FILTERED_META_DIR
|
|
: ABBREVIATED_META_DIR
|
|
const cacheDir = path.join(opts.cacheDir, cacheType)
|
|
switch (params[0]) {
|
|
case 'list-registries':
|
|
return cacheListRegistries({
|
|
...opts,
|
|
cacheDir,
|
|
})
|
|
case 'list':
|
|
return cacheList({
|
|
...opts,
|
|
cacheDir,
|
|
registry: opts.cliOptions['registry'],
|
|
}, params.slice(1))
|
|
case 'delete':
|
|
return cacheDelete({
|
|
...opts,
|
|
cacheDir,
|
|
registry: opts.cliOptions['registry'],
|
|
}, params.slice(1))
|
|
case 'view': {
|
|
if (!params[1]) {
|
|
throw new PnpmError('MISSING_PACKAGE_NAME', '`pnpm cache view` requires the package name')
|
|
}
|
|
if (params.length > 2) {
|
|
throw new PnpmError('TOO_MANY_PARAMS', '`pnpm cache view` only accepts one package name')
|
|
}
|
|
const storeDir = await getStorePath({
|
|
pkgRoot: process.cwd(),
|
|
storePath: opts.storeDir,
|
|
pnpmHomeDir: opts.pnpmHomeDir,
|
|
})
|
|
return cacheView({
|
|
...opts,
|
|
cacheDir,
|
|
storeDir,
|
|
registry: opts.cliOptions['registry'],
|
|
}, params[1])
|
|
}
|
|
default:
|
|
return help()
|
|
}
|
|
}
|