Files
Zoltan Kochan 4edeef9176 style(ts): port the perfectionist lint rules to ESLint (#16415)
Add TypeScript ports of the perfectionist rules that the Rust workspace
enforces through dylint.toml to @pnpm/eslint-config, with the same limits,
and fix every finding that needs no refactor.

The size and shape rules (function length, cognitive complexity, nesting,
local bindings, file length) are enforced for packages that already meet
them. The packages that do not are listed in PENDING_SIZE_AND_SHAPE_REFACTOR
in eslint.config.mjs and are refactored in follow-up changes.

The custom rules mirror perfectionist's semantics rather than reusing
sonarjs or max-lines-per-function, so that one limit means the same thing
in both codebases: a closure is a level of the body that contains it, a
nested function declaration is measured on its own, and a test-framework
callback plays the role of a #[test] function.

Bugs found and fixed along the way:
- a registry error body cut at exactly 64 KiB lost its truncation marker
- removing a dependency could leave dangling .bin shims
- constructor/__proto__ names crashed the projects graph, were skipped by
  the injected-deps syncer, and were dropped from writeWantedLockfile's
  returned lockfile

The CI chunk runner learns to run the node:test suite of the ESLint
config package.
2026-09-30 15:10:08 +02:00
..
…
…

@pnpm/config.env-replace

Replaces env variable placeholders in configuration settings

envReplace

Strict mode — throws when a ${VAR} placeholder has no value and no default.

function envReplace(settingValue: string, env: NodeJS.ProcessEnv): string;
import { envReplace } from '@pnpm/config.env-replace'

envReplace('${foo}', process.env)

envReplaceLossy

Lossy mode — replaces unresolved ${VAR} placeholders with '' and reports them in unresolved instead of throwing. Resolvable placeholders and ${VAR-default} / ${VAR:-default} fallbacks elsewhere in the same string still expand normally; only the genuinely unresolved bare ones are dropped.

Use this when leaving the literal ${VAR} in the substituted value would be worse than dropping it (e.g. auth tokens in .npmrc under OIDC trusted publishing).

function envReplaceLossy(
  settingValue: string,
  env: NodeJS.ProcessEnv
): { value: string; unresolved: string[] };
import { envReplaceLossy } from '@pnpm/config.env-replace'

const { value, unresolved } = envReplaceLossy('${foo}-${missing}', process.env)
// value:      'foo_value-'
// unresolved: ['${missing}']

Placeholder syntax

  • ${NAME} — strict; the env var must be set (otherwise envReplace throws, or envReplaceLossy substitutes '' and records the placeholder).
  • ${NAME-fallback} — fallback if NAME is unset.
  • ${NAME:-fallback} — fallback if NAME is unset or an empty string.
  • A leading \ escapes the placeholder (\${NAME} stays literal).

{ NAME: undefined } in env is treated as unset for both functions — the same as the key being absent. This matches the Record<string, string | undefined> shape of NodeJS.ProcessEnv, where callers (notably tests) routinely model an unset variable as a present-but-undefined property.

License

MIT