Conversation
Env vars are case-sensitive on macOS/Linux, so PNPM_CONFIG_USERCONFIG — the rename suggested by the v11 migration guide — was silently ignored because parseEnvVars only matched lowercase pnpm_config_*. Also wire the env var into the early npmrcAuthFile lookup so it actually decides which user-level .npmrc gets read. Closes #11465
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAccept uppercase ChangesUppercase Environment Variable Support & Early .npmrc Load
Sequence Diagram(s)sequenceDiagram
participant Env as Environment
participant Reader as Config Reader
participant Loader as npmrc Loader
participant FS as FileSystem
Env->>Reader: provide env vars (`pnpm_config_*`, `PNPM_CONFIG_*`)
Reader->>Reader: readEnvVar(key) checks lowercase and uppercase forms
Reader->>Loader: supply resolved `userconfig` / `npmrc_auth_file` (if present)
Loader->>FS: read specified .npmrc path early (before `~/.npmrc`)
FS-->>Loader: return .npmrc contents
Loader-->>Reader: parsed config merged into final config
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes pnpm v11’s environment-variable config migration by allowing uppercase PNPM_CONFIG_* variables (in addition to the existing lowercase pnpm_config_*) and by reading PNPM_CONFIG_USERCONFIG / PNPM_CONFIG_NPMRC_AUTH_FILE early enough to affect which user-level .npmrc file gets loaded on case-sensitive systems (macOS/Linux).
Changes:
- Extend env var parsing to accept both
pnpm_config_*andPNPM_CONFIG_*, with strict snake_case suffix validation in matching case. - Read
userconfig/npmrc-auth-filefrom env vars before loading.npmrcfiles so env overrides actually take effect. - Add unit tests covering uppercase/lowercase acceptance and mixed-case rejection, plus config-reader tests verifying the env vars change the loaded user config.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| config/reader/src/env.ts | Accepts uppercase PNPM_CONFIG_* keys and validates suffix casing strictly, normalizing uppercase suffixes to lowercase for downstream parsing. |
| config/reader/src/index.ts | Reads userconfig / npmrc-auth-file from env earlier so env vars can select the user .npmrc before it’s loaded. |
| config/reader/test/env.test.ts | Adds coverage for uppercase acceptance and mixed-case rejection in parseEnvVars. |
| config/reader/test/index.ts | Adds integration-style tests ensuring getConfig() honors env-provided userconfig/auth file paths. |
| .changeset/uppercase-pnpm-config-env-vars.md | Documents the behavior change and adds a patch changeset for @pnpm/config.reader and pnpm. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
config/reader/test/index.ts (1)
1108-1160: ⚡ Quick winAdd an explicit conflict-precedence test for dual env forms.
Current cases validate each env form independently, but not when both are set with different values. A single precedence test here would lock deterministic behavior for future refactors (especially around
.npmrcselection).Proposed test addition
+test('getConfig() resolves deterministic precedence when both PNPM_CONFIG_USERCONFIG and pnpm_config_userconfig are set', async () => { + prepareEmpty() + fs.mkdirSync('user-home') + fs.writeFileSync(path.resolve('user-home', 'upper.npmrc'), 'registry = https://upper.example.test', 'utf-8') + fs.writeFileSync(path.resolve('user-home', 'lower.npmrc'), 'registry = https://lower.example.test', 'utf-8') + + const { config } = await getConfig({ + cliOptions: {}, + env: { + ...env, + PNPM_CONFIG_USERCONFIG: path.resolve('user-home', 'upper.npmrc'), + pnpm_config_userconfig: path.resolve('user-home', 'lower.npmrc'), + }, + packageManager: { + name: 'pnpm', + version: '1.0.0', + }, + }) + + // Assert the intended winner explicitly. + expect(config.userConfig).toEqual({ registry: 'https://lower.example.test' }) +})🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@config/reader/test/index.ts` around lines 1108 - 1160, Add a test that verifies precedence when both env variants are set with different paths: call getConfig(...) with env containing both PNPM_CONFIG_USERCONFIG and pnpm_config_userconfig pointing to two different .npmrc files, then assert which file wins by checking config.userConfig contents; place this alongside the existing tests (referencing getConfig and config.userConfig) and ensure the test creates two distinct user-home directories/files so the expected precedence behavior is locked in.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@config/reader/test/index.ts`:
- Around line 1108-1160: Add a test that verifies precedence when both env
variants are set with different paths: call getConfig(...) with env containing
both PNPM_CONFIG_USERCONFIG and pnpm_config_userconfig pointing to two different
.npmrc files, then assert which file wins by checking config.userConfig
contents; place this alongside the existing tests (referencing getConfig and
config.userConfig) and ensure the test creates two distinct user-home
directories/files so the expected precedence behavior is locked in.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ccc1233a-9be9-4ddf-a65e-ace7a4acf463
📒 Files selected for processing (5)
.changeset/uppercase-pnpm-config-env-vars.mdconfig/reader/src/env.tsconfig/reader/src/index.tsconfig/reader/test/env.test.tsconfig/reader/test/index.ts
Matches the exact env var name reported in #11465. Without the early env-var lookup before loadNpmrcConfig, this case is parsed too late to actually load the custom .npmrc.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* fix(config): accept uppercase PNPM_CONFIG_* env vars Env vars are case-sensitive on macOS/Linux, so PNPM_CONFIG_USERCONFIG — the rename suggested by the v11 migration guide — was silently ignored because parseEnvVars only matched lowercase pnpm_config_*. Also wire the env var into the early npmrcAuthFile lookup so it actually decides which user-level .npmrc gets read. Closes #11465 * chore: add changeset for npmrc auth file env-var load order * test: cover lowercase pnpm_config_npmrc_auth_file env var Matches the exact env var name reported in #11465. Without the early env-var lookup before loadNpmrcConfig, this case is parsed too late to actually load the custom .npmrc. * test: lock precedence when both lowercase and uppercase env vars are set
Summary
parseEnvVarsnow accepts both lowercasepnpm_config_*and uppercasePNPM_CONFIG_*env-var prefixes (suffix must be fully snake_case in the matching case). On macOS/Linux env vars are case-sensitive, so the v11 migration guide'sNPM_CONFIG_USERCONFIG→PNPM_CONFIG_USERCONFIGrename was silently a no-op.loadNpmrcConfigruns, soPNPM_CONFIG_USERCONFIG/PNPM_CONFIG_NPMRC_AUTH_FILEactually decide which user-level.npmrcgets loaded — previously the env loop ran too late to affect it.Closes #11465.
Test plan
pnpm --filter @pnpm/config.reader test— added cases coverPNPM_CONFIG_USERCONFIG,pnpm_config_userconfig,PNPM_CONFIG_NPMRC_AUTH_FILE, plus mixed-case rejection inenv.test.ts..npmrccontainingregistry=..., all four casings of the env var makepnpm config get registryreturn that registry, while no env var falls back to the default.Summary by CodeRabbit
New Features
Bug Fixes
Tests