Files
pnpm/cli/default-reporter/test/reportingScope.ts
Zoltan Kochan 3033bee430 refactor(config): split Config interface into settings + runtime context (#11197)
* 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.
2026-04-04 23:44:25 +02:00

113 lines
2.7 KiB
TypeScript

import { setTimeout } from 'node:timers/promises'
import { toOutput$ } from '@pnpm/cli.default-reporter'
import type { Config, ConfigContext } from '@pnpm/config.reader'
import { scopeLogger } from '@pnpm/core-loggers'
import { createStreamParser } from '@pnpm/logger'
import { firstValueFrom } from 'rxjs'
const NO_OUTPUT = Symbol('test should not log anything')
test('does not print scope of non-recursive install in a workspace', async () => {
const output$ = toOutput$({
context: {
argv: ['install'],
},
streamParser: createStreamParser(),
})
scopeLogger.debug({
selected: 1,
workspacePrefix: '/home/src',
})
const output = await Promise.race([
firstValueFrom(output$),
setTimeout(10).then(() => NO_OUTPUT),
])
expect(output).toEqual(NO_OUTPUT)
})
test('prints scope of recursive install in a workspace when not all packages are selected', async () => {
const output$ = toOutput$({
context: {
argv: ['install'],
config: { recursive: true } as Config & ConfigContext,
},
streamParser: createStreamParser(),
})
scopeLogger.debug({
selected: 2,
total: 10,
workspacePrefix: '/home/src',
})
expect.assertions(1)
const output = await firstValueFrom(output$)
expect(output).toBe('Scope: 2 of 10 workspace projects')
})
test('prints scope of recursive install in a workspace when all packages are selected', async () => {
const output$ = toOutput$({
context: {
argv: ['install'],
config: { recursive: true } as Config & ConfigContext,
},
streamParser: createStreamParser(),
})
scopeLogger.debug({
selected: 10,
total: 10,
workspacePrefix: '/home/src',
})
expect.assertions(1)
const output = await firstValueFrom(output$)
expect(output).toBe('Scope: all 10 workspace projects')
})
test('prints scope of recursive install not in a workspace when not all packages are selected', async () => {
const output$ = toOutput$({
context: {
argv: ['install'],
config: { recursive: true } as Config & ConfigContext,
},
streamParser: createStreamParser(),
})
scopeLogger.debug({
selected: 2,
total: 10,
})
expect.assertions(1)
const output = await firstValueFrom(output$)
expect(output).toBe('Scope: 2 of 10 projects')
})
test('prints scope of recursive install not in a workspace when all packages are selected', async () => {
const output$ = toOutput$({
context: {
argv: ['install'],
config: { recursive: true } as Config & ConfigContext,
},
streamParser: createStreamParser(),
})
scopeLogger.debug({
selected: 10,
total: 10,
})
expect.assertions(1)
const output = await firstValueFrom(output$)
expect(output).toBe('Scope: all 10 projects')
})