Skip to content

fix: accept uppercase PNPM_CONFIG_* env vars#11468

Merged
zkochan merged 4 commits into
mainfrom
fix/11465
May 5, 2026
Merged

fix: accept uppercase PNPM_CONFIG_* env vars#11468
zkochan merged 4 commits into
mainfrom
fix/11465

Conversation

@zkochan

@zkochan zkochan commented May 5, 2026

Copy link
Copy Markdown
Member

Summary

  • parseEnvVars now accepts both lowercase pnpm_config_* and uppercase PNPM_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's NPM_CONFIG_USERCONFIGPNPM_CONFIG_USERCONFIG rename was silently a no-op.
  • The env var is now also consulted before loadNpmrcConfig runs, so PNPM_CONFIG_USERCONFIG / PNPM_CONFIG_NPMRC_AUTH_FILE actually decide which user-level .npmrc gets loaded — previously the env loop ran too late to affect it.
  • Docs updated to mention that the uppercase prefix is accepted.

Closes #11465.

Test plan

  • pnpm --filter @pnpm/config.reader test — added cases cover PNPM_CONFIG_USERCONFIG, pnpm_config_userconfig, PNPM_CONFIG_NPMRC_AUTH_FILE, plus mixed-case rejection in env.test.ts.
  • End-to-end smoke: with a custom .npmrc containing registry=..., all four casings of the env var make pnpm config get registry return that registry, while no env var falls back to the default.

Summary by CodeRabbit

  • New Features

    • Support uppercase env var prefixes (PNPM_CONFIG_), in addition to lowercase, so config env vars work on case-sensitive systems.
    • Allow selecting a user-level .npmrc via these environment variables.
  • Bug Fixes

    • Env-specified .npmrc paths are now consulted earlier during config loading so custom files are applied correctly; lowercase form wins if both are set.
  • Tests

    • Added tests for uppercase env vars and env-driven .npmrc loading.

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
Copilot AI review requested due to automatic review settings May 5, 2026 12:37
@coderabbitai

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: dca837e9-e654-4136-b829-1f87af72d92d

📥 Commits

Reviewing files that changed from the base of the PR and between 657cc9d and 7eb444a.

📒 Files selected for processing (1)
  • config/reader/test/index.ts

📝 Walkthrough

Walkthrough

Accept uppercase PNPM_CONFIG_* alongside lowercase pnpm_config_* and read npmrc_auth_file / userconfig from env earlier (before loading ~/.npmrc). Parsing helpers, config wiring, tests, and changesets updated accordingly.

Changes

Uppercase Environment Variable Support & Early .npmrc Load

Layer / File(s) Summary
Constants & Validation Helpers
config/reader/src/env.ts
Adds PREFIX_UPPER and splits suffix validation into isLowerSnakeCase and isUpperSnakeCase.
Core Parsing Logic
config/reader/src/env.ts
getEnvKeySuffix recognizes both pnpm_config_ and PNPM_CONFIG_, validates suffix case against prefix, and lowercases suffixes from uppercase inputs.
Configuration Integration / Wiring
config/reader/src/index.ts
Adds readEnvVar(env, key) to check both lowercase and uppercase env names (treats empty string as unset). getConfig uses this to read npmrc_auth_file and userconfig early so custom .npmrc paths affect loading.
Tests & Changesets
config/reader/test/env.test.ts, config/reader/test/index.ts, `.changeset/*.md`
Tests expanded to accept fully lowercase or fully uppercase snake_case keys and to verify userconfig/npmrc_auth_file env inputs and precedence; changesets updated for patch releases and load-order fix.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I sniff the breeze of env and keys,
Upper hops meet lower in the lea,
Early paths now point the way,
.npmrc reads at break of day,
I nibble bugs and dance with glee.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding support for uppercase PNPM_CONFIG_* environment variables alongside existing lowercase variants.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/11465

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_* and PNPM_CONFIG_*, with strict snake_case suffix validation in matching case.
  • Read userconfig / npmrc-auth-file from env vars before loading .npmrc files 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
config/reader/test/index.ts (1)

1108-1160: ⚡ Quick win

Add 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 .npmrc selection).

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0c137bb and 2b4d08a.

📒 Files selected for processing (5)
  • .changeset/uppercase-pnpm-config-env-vars.md
  • config/reader/src/env.ts
  • config/reader/src/index.ts
  • config/reader/test/env.test.ts
  • config/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.
Copilot AI review requested due to automatic review settings May 5, 2026 12:46
@zkochan zkochan added this to the v11.0 milestone May 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zkochan zkochan merged commit d74ddaa into main May 5, 2026
13 checks passed
@zkochan zkochan deleted the fix/11465 branch May 5, 2026 14:16
zkochan added a commit that referenced this pull request May 5, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PNPM_CONFIG_USERCONFIG doesn't work

2 participants