Skip to content

fix(config): support npm's optional ${VAR?} placeholder in .npmrc - #15565

Merged
zkochan merged 6 commits into
pnpm:mainfrom
altaywtf:fix/npmrc-optional-env-var
Sep 25, 2026
Merged

zkochan merged 6 commits into
pnpm:mainfrom
altaywtf:fix/npmrc-optional-env-var

Conversation

@altaywtf

@altaywtf altaywtf commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

npm's .npmrc docs define ${VAR?}: it expands to VAR, or to an empty string when VAR is unset. Both pnpm stacks looked up VAR? as the variable name, so the placeholder never resolved and every run logged Failed to replace env in config: ${VAR?}.

  • v12 (Rust): pnpm-env-replace treats ${VAR?} like ${VAR:-}, so it expands to the value or "" and is not reported as unresolved. Only a non-empty name without another ? or a trailing - counts, so ${?}, ${VAR??}, and ${NAME-?} are still reported. The crate is shared, so pnpm-workspace.yaml placeholders and the pnpr config file get the same form, with its own pnpr changeset.
  • v11 (TypeScript): the parser lives in the external @pnpm/config.env-replace package, so substituteEnv in loadNpmrcFiles.ts passes envReplaceLossy a lookup table with a VAR? entry for each such placeholder. v11 pnpm-workspace.yaml expansion is unchanged.

The triage bot tagged this state: needs design because of the related ${NAME-?} proposal in #11667. This PR adds only npm's documented ${VAR?} form for compatibility with existing .npmrc files. It does not touch that proposal.

Closes #14404

Squash Commit Body

npm expands `${VAR?}` in .npmrc to the variable's value, or to an empty
string when the variable is unset. Both pnpm stacks looked up `VAR?` as
the variable name, so the placeholder never resolved and a
"Failed to replace env in config" warning was logged.

The Rust env-replace crate treats `${VAR?}` as `${VAR:-}` without
recording it as unresolved. Only a non-empty name without another `?`
or a trailing `-` counts, which keeps `${NAME-?}` free for
pnpm/pnpm#11667. The TypeScript reader gives envReplaceLossy
a `VAR?` entry for each such placeholder, since the parser lives in the
external `@pnpm/config.env-replace` package.

Closes pnpm/pnpm#14404

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Tests fail without the fix (source changes reverted with git apply -R): 5 cases in pnpm11/config/reader/test/index.ts, optional_placeholder_expands_without_being_recorded in pnpm-env-replace, from_ini_expands_optional_auth_env_placeholder_without_warning in pnpm-config, and malformed_optional_placeholder_is_recorded without the name guard.


Written by an agent (Claude Code, Opus 5.5).

Summary by CodeRabbit

  • New Features
    • .npmrc, pnpr, and pnpm-workspace.yaml configuration support optional environment-variable placeholders in the form ${VAR?}. If the variable is set, its value is used; if unset, the placeholder becomes an empty string without a warning.
    • Escaped placeholders remain literal, and existing fallback placeholders continue to work. Optional placeholders can be used in values such as proxy settings.
    • On Windows, pnpm recognizes local paths written with forward slashes.

@altaywtf
altaywtf requested a review from zkochan as a code owner September 24, 2026 14:44
Copilot AI lite review requested due to automatic review settings September 24, 2026 14:44
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 30720cf9-45d0-4244-85e0-8dfa4b75b421

📥 Commits

Reviewing files that changed from the base of the PR and between 02998f6 and d6e8019.

📒 Files selected for processing (4)
  • .changeset/npmrc-optional-env-var.md
  • .changeset/pacquet-optional-env-var.md
  • pnpm11/resolving/local-resolver/src/parseBareSpecifier.ts
  • pnpm11/resolving/local-resolver/test/parseBareSpecifier.win32.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/npmrc-optional-env-var.md

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The Rust environment replacer and pnpm11 configuration reader now support npm’s ${VAR?} placeholder. A set variable expands to its value; an unset variable expands to an empty string without a warning. The local resolver also recognizes forward-slash-separated bare specifiers as local paths.

Changes

Optional environment-variable placeholders

Layer / File(s) Summary
Rust optional placeholder expansion
pnpm/crates/env-replace/src/lib.rs, pnpm/crates/env-replace/src/tests.rs, pnpm/crates/config/src/npmrc_auth/tests/authorization.rs
The Rust environment replacer recognizes valid ${NAME?} placeholders and uses an empty-string default. Tests cover set, empty, unset, escaped, and malformed placeholders, including trusted auth tokens.
Configuration loading and release notes
pnpm11/config/reader/src/loadNpmrcFiles.ts, pnpm11/config/reader/test/index.ts, .changeset/npmrc-optional-env-var.md, .changeset/pnpr-optional-env-var.md, .changeset/pacquet-optional-env-var.md
The configuration reader prepares optional placeholders for environment replacement. Tests cover trusted auth and no-proxy values. Changesets record patch releases and describe the syntax.

Forward-slash local paths

Layer / File(s) Summary
Local path recognition
pnpm11/resolving/local-resolver/src/parseBareSpecifier.ts, pnpm11/resolving/local-resolver/test/parseBareSpecifier.win32.test.ts, pnpm11/resolving/local-resolver/test/index.ts, .changeset/local-resolver-forward-slash-windows.md
The parser recognizes bare specifiers containing / as local paths. Tests cover parsing and resolving some/local/dir, and a changeset records patch releases.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Assessment against linked issues

Objective Addressed Explanation
Support ${VAR?} in .npmrc: expand to the variable value when set, or an empty string without a warning when unset. [#14404] ✅

Out-of-scope changes

Code Change Explanation
Recognizes slash-containing specifiers as local paths (pnpm11/resolving/local-resolver/src/parseBareSpecifier.ts:152) Issue #14404 concerns optional environment-variable placeholders in .npmrc; it does not identify local path parsing as an objective.

Suggested labels: product: pnpm@11, product: pacquet

Merge Risk: ⚪ Minimal · up to d6e80

.npmrc files now support npm's ${VAR?} placeholder: it expands to the variable's value, or to an empty string without a warning when the variable is unset. On Windows, local paths written with forward slashes are now recognized, matching other platforms. Scoped registry packages still resolve from the registry first. No blocking issues remain.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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.

Copilot review overview

🟡 Changes recommended

The Rust ${VAR?} parsing currently treats any placeholder ending in ? as optional (including ${NAME-?} / ${?} / ${VAR??}), which can suppress unresolved warnings and partially overlaps with the explicitly out-of-scope ${NAME-?} proposal.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Adds support for npm’s optional ${VAR?} placeholder so .npmrc settings can expand to an empty string (without warnings) when an env var is unset, aligning pnpm v11 (TypeScript) and v12 (Rust/pacquet) behavior with npm’s documented semantics.

Changes:

  • Rust env-replace now expands ${VAR?} as an empty-string fallback and avoids recording it as unresolved.
  • TypeScript .npmrc loading injects VAR? lookup entries so envReplaceLossy can resolve ${VAR?} without warninging.
  • New/updated tests cover ${VAR?} expansion for auth and non-auth settings; changeset added for published packages.
File Description
pnpm11/​config/​reader/​test/​index.ts Adds v11 tests ensuring ${VAR?} expands without “Failed to replace env” warnings (auth + no-proxy).
pnpm11/​config/​reader/​src/​loadNpmrcFiles.ts Implements v11 workaround by augmenting the env lookup table to resolve ${VAR?} via envReplaceLossy.
pnpm/​crates/​env-replace/​src/​tests.rs Adds v12 unit coverage for ${VAR?} behavior and escaping rules.
pnpm/​crates/​env-replace/​src/​lib.rs Implements ${VAR?} parsing/expansion and documents that it should not be recorded as unresolved.
pnpm/​crates/​config/​src/​npmrc_auth/​tests/​authorization.rs Ensures npmrc auth parsing expands ${VAR?} without warnings in v12 config layer.
.changeset/​npmrc-optional-env-var.md Release note for ${VAR?} support across v11 (pnpm) and v12 (pacquet).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pnpm/crates/env-replace/src/lib.rs Resolved
@codecov-commenter

codecov-commenter commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.85%. Comparing base (f26a8f0) to head (9575ac3).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15565      +/-   ##
==========================================
+ Coverage   91.84%   91.85%   +0.01%     
==========================================
  Files        1447     1450       +3     
  Lines      195554   195785     +231     
==========================================
+ Hits       179602   179841     +239     
+ Misses      15952    15944       -8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI review requested due to automatic review settings September 24, 2026 14:55

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.

Copilot review overview

🟡 Changes recommended

The changeset should also target @pnpm/pnpr because pnpr depends on pnpm-env-replace, so this behavior change affects pnpr releases too.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
Resolved since last review (2)

Comment thread .changeset/npmrc-optional-env-var.md Resolved

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.

Copilot review overview

🟢 Approval recommended

The implementation matches npm’s documented ${VAR?} behavior, includes guards against malformed placeholders, and adds focused tests plus appropriate changesets for affected release targets.

Review effort: Lite
Findings: None

Resolved since last review (1)

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Same-run regression check

HEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval.

Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.

Scenario Engine main median HEAD median Change Tolerance Result
isolated-fresh-restore-cold-cache-cold-store pacquet 2428.51 ms 2501.74 ms 3.0% 121.43 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store pnpr 1367.76 ms 1520.05 ms 11.1% 68.39 ms Inconclusive (overlapping samples)
isolated-fresh-restore-hot-cache-hot-store pacquet 287.24 ms 312.45 ms 8.8% 14.36 ms Inconclusive (overlapping samples)
isolated-fresh-restore-hot-cache-hot-store pnpr 311.62 ms 307.83 ms -1.2% 15.58 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pacquet 13.01 ms 16.47 ms 26.6% 2.00 ms Inconclusive (overlapping samples)
isolated-repeat-install-hot-cache-hot-store pnpr 13.44 ms 13.84 ms 2.9% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pacquet 8.22 ms 8.64 ms 5.1% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 7.88 ms 8.33 ms 5.7% 2.00 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet 2631.34 ms 2639.35 ms 0.3% 131.57 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1526.98 ms 1538.61 ms 0.8% 76.35 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pacquet 426.29 ms 640.59 ms 50.3% 21.31 ms Inconclusive (not reproduced)
isolated-fresh-install-hot-cache-hot-store pnpr 282.43 ms 272.63 ms -3.5% 14.12 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet 1684.32 ms 1606.63 ms -4.6% 84.22 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pnpr 293.55 ms 296.50 ms 1.0% 14.68 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pacquet 251.83 ms 255.72 ms 1.5% 12.59 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pnpr 99.16 ms 99.27 ms 0.1% 4.96 ms Within tolerance
isolated-peer-heavy-resolve-hot-cache-offline pacquet 697.82 ms 735.96 ms 5.5% 34.89 ms Inconclusive (overlapping samples)
isolated-linked-workspace-resolve-hot-cache-offline pacquet 224.62 ms 229.68 ms 2.3% 11.23 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4506.60 ms 4436.32 ms -1.6% 225.33 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 3479.79 ms 3491.62 ms 0.3% 173.99 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet 141.02 ms 136.35 ms -3.3% 7.05 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pnpr 137.74 ms 130.64 ms -5.2% 6.89 ms Within tolerance

Integrated-Benchmark Report (Linux)

Commit: 9575ac38cef5

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked-workspace scenario compares current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs.

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.498 ± 0.135 2.310 2.685 1.80 ± 0.14
pacquet@main 2.419 ± 0.089 2.255 2.556 1.74 ± 0.12
pnpr@HEAD 1.478 ± 0.146 1.296 1.707 1.06 ± 0.12
pnpr@main 1.388 ± 0.080 1.298 1.544 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.4982361898600005,
      "stddev": 0.13532105069412834,
      "median": 2.5017383421600004,
      "user": 1.72139186,
      "system": 1.5611484599999998,
      "min": 2.30991653866,
      "max": 2.68483495866
    },
    {
      "command": "pacquet@main",
      "mean": 2.4190498305599997,
      "stddev": 0.08871051911581701,
      "median": 2.42850945016,
      "user": 1.5849822599999999,
      "system": 1.43232106,
      "min": 2.25535410666,
      "max": 2.55609088766
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.47759303526,
      "stddev": 0.1457413672887505,
      "median": 1.52004973466,
      "user": 1.3578618599999996,
      "system": 1.2871935599999997,
      "min": 1.29586942166,
      "max": 1.70708299766
    },
    {
      "command": "pnpr@main",
      "mean": 1.3878667279599999,
      "stddev": 0.08045654940212783,
      "median": 1.3677646451599998,
      "user": 1.33363856,
      "system": 1.24594366,
      "min": 1.2983897146599999,
      "max": 1.54439699166
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 375.0 ± 97.2 290.6 528.7 1.30 ± 0.34
pacquet@main 288.7 ± 9.3 277.0 304.6 1.00
pnpr@HEAD 306.5 ± 10.5 291.1 322.6 1.06 ± 0.05
pnpr@main 311.1 ± 10.6 295.2 324.1 1.08 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.37500943170000006,
      "stddev": 0.09724398973250328,
      "median": 0.31244830700000004,
      "user": 0.40985728000000005,
      "system": 0.96010174,
      "min": 0.290550511,
      "max": 0.528692421
    },
    {
      "command": "pacquet@main",
      "mean": 0.28866864220000005,
      "stddev": 0.009338192999239232,
      "median": 0.2872376365,
      "user": 0.32108017999999994,
      "system": 0.75714294,
      "min": 0.27698733600000003,
      "max": 0.30455481
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.3065351606,
      "stddev": 0.010518540307555134,
      "median": 0.3078321865,
      "user": 0.32154308,
      "system": 0.77363654,
      "min": 0.291140497,
      "max": 0.322558481
    },
    {
      "command": "pnpr@main",
      "mean": 0.3111485637,
      "stddev": 0.010585145210823866,
      "median": 0.31162070100000006,
      "user": 0.32740317999999996,
      "system": 0.77142684,
      "min": 0.295170678,
      "max": 0.324116104
    }
  ]
}

Scenario: Isolated linker: repeat install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 17.3 ± 3.9 12.2 28.7 1.24 ± 0.40
pacquet@main 14.0 ± 3.2 9.8 27.3 1.00
pnpr@HEAD 14.5 ± 2.8 10.5 23.4 1.04 ± 0.31
pnpr@main 14.0 ± 2.9 9.9 24.0 1.00 ± 0.31
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.017323042277586208,
      "stddev": 0.003916820576071493,
      "median": 0.0164682037,
      "user": 0.00841678,
      "system": 0.01006931103448276,
      "min": 0.012229508200000001,
      "max": 0.0286572992
    },
    {
      "command": "pacquet@main",
      "mean": 0.01400264705245902,
      "stddev": 0.0032067388322070157,
      "median": 0.013010148700000002,
      "user": 0.007118525901639345,
      "system": 0.007905171147540985,
      "min": 0.0097640142,
      "max": 0.0272947332
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.014515566220979026,
      "stddev": 0.002779523085303404,
      "median": 0.013838510200000001,
      "user": 0.007575377902097903,
      "system": 0.007946982097902096,
      "min": 0.010463047200000002,
      "max": 0.0234137422
    },
    {
      "command": "pnpr@main",
      "mean": 0.014012862500578033,
      "stddev": 0.0028600202393610297,
      "median": 0.013443680200000002,
      "user": 0.007523877919075146,
      "system": 0.007478332023121382,
      "min": 0.009863442200000001,
      "max": 0.0240400382
    }
  ]
}

Scenario: Isolated linker: repeat install, cold cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 8.8 ± 1.1 7.1 12.7 1.06 ± 0.20
pacquet@main 8.4 ± 1.0 6.8 12.4 1.01 ± 0.18
pnpr@HEAD 8.6 ± 1.2 6.7 12.1 1.03 ± 0.20
pnpr@main 8.3 ± 1.2 6.8 13.4 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.008812091384070795,
      "stddev": 0.0010697597100994209,
      "median": 0.0086390203,
      "user": 0.004951422831858405,
      "system": 0.004287854690265484,
      "min": 0.0071351093,
      "max": 0.0127455923
    },
    {
      "command": "pacquet@main",
      "mean": 0.008375714193280636,
      "stddev": 0.0009883793264429252,
      "median": 0.0082205953,
      "user": 0.004839810988142289,
      "system": 0.004003743715415019,
      "min": 0.0067772393000000005,
      "max": 0.0123514533
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.008550654086885247,
      "stddev": 0.0012075437104049698,
      "median": 0.0083271193,
      "user": 0.004956263278688528,
      "system": 0.0040451202622950825,
      "min": 0.0066811583,
      "max": 0.0120900023
    },
    {
      "command": "pnpr@main",
      "mean": 0.00831804842145749,
      "stddev": 0.0011640210909514056,
      "median": 0.0078783573,
      "user": 0.004493205748987852,
      "system": 0.004262571012145749,
      "min": 0.0068114023,
      "max": 0.0133729563
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.689 ± 0.111 2.600 2.915 1.73 ± 0.14
pacquet@main 2.637 ± 0.032 2.606 2.706 1.70 ± 0.12
pnpr@HEAD 1.566 ± 0.088 1.461 1.733 1.01 ± 0.09
pnpr@main 1.551 ± 0.108 1.442 1.747 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.68861355632,
      "stddev": 0.1113817912496237,
      "median": 2.63934759772,
      "user": 2.36885882,
      "system": 2.13507296,
      "min": 2.60041604672,
      "max": 2.91518049672
    },
    {
      "command": "pacquet@main",
      "mean": 2.63743636202,
      "stddev": 0.03205909994370004,
      "median": 2.6313359032199997,
      "user": 2.2503454199999995,
      "system": 2.0095791600000004,
      "min": 2.60578037372,
      "max": 2.70607752872
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5658016439200002,
      "stddev": 0.08802424594837163,
      "median": 1.5386138467200001,
      "user": 1.43427632,
      "system": 1.58961466,
      "min": 1.46122611472,
      "max": 1.73325631572
    },
    {
      "command": "pnpr@main",
      "mean": 1.5514653522200001,
      "stddev": 0.10753890329535501,
      "median": 1.5269754247200003,
      "user": 1.4588813200000001,
      "system": 1.61582966,
      "min": 1.44218530572,
      "max": 1.74715240872
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 643.4 ± 102.4 413.6 758.8 2.37 ± 0.38
pacquet@main 431.7 ± 21.2 403.4 481.1 1.59 ± 0.09
pnpr@HEAD 272.0 ± 5.9 259.3 278.1 1.00
pnpr@main 290.6 ± 37.7 262.3 393.1 1.07 ± 0.14

Confirmation (reversed target order)

Command Mean [ms] Min [ms] Max [ms] Relative
pnpr@main 463.1 ± 43.6 393.1 549.8 1.00
pnpr@HEAD 464.3 ± 23.7 418.1 492.4 1.00 ± 0.11
pacquet@main 749.4 ± 78.0 610.0 848.1 1.62 ± 0.23
pacquet@HEAD 725.2 ± 108.7 483.7 835.7 1.57 ± 0.28
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6434042423800002,
      "stddev": 0.10236720330188036,
      "median": 0.64058986588,
      "user": 0.95088866,
      "system": 1.0342527599999998,
      "min": 0.41359170638000003,
      "max": 0.75876417638
    },
    {
      "command": "pacquet@main",
      "mean": 0.43169950108000005,
      "stddev": 0.021197290006747863,
      "median": 0.42628885138000006,
      "user": 0.6294630599999999,
      "system": 0.7233306599999999,
      "min": 0.40339108438000004,
      "max": 0.48105527038000007
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.27203391188000003,
      "stddev": 0.005912442297742343,
      "median": 0.27263232188000003,
      "user": 0.21044896,
      "system": 0.50348756,
      "min": 0.25925298838000005,
      "max": 0.27807357938000005
    },
    {
      "command": "pnpr@main",
      "mean": 0.29061370138000003,
      "stddev": 0.03768224679056247,
      "median": 0.28243176938000003,
      "user": 0.23069635999999996,
      "system": 0.5466761599999999,
      "min": 0.26225719338000003,
      "max": 0.39312265838000005
    }
  ],
  "confirmation": {
    "results": [
      {
        "command": "pnpr@main",
        "mean": 0.46311218726000003,
        "stddev": 0.04356392411831997,
        "median": 0.45640196746000006,
        "user": 0.42521822,
        "system": 0.8540149600000001,
        "min": 0.39306350496000003,
        "max": 0.5498448569600001
      },
      {
        "command": "pnpr@HEAD",
        "mean": 0.46433117526000006,
        "stddev": 0.02367467719682548,
        "median": 0.46631213396000004,
        "user": 0.42364502000000004,
        "system": 0.83979666,
        "min": 0.41811865896,
        "max": 0.49239472796
      },
      {
        "command": "pacquet@main",
        "mean": 0.74939384456,
        "stddev": 0.07802904834461136,
        "median": 0.75928740096,
        "user": 1.08150912,
        "system": 1.13603746,
        "min": 0.60995350096,
        "max": 0.84810227896
      },
      {
        "command": "pacquet@HEAD",
        "mean": 0.72522634986,
        "stddev": 0.10870978280646207,
        "median": 0.74588772746,
        "user": 1.03740872,
        "system": 1.08214916,
        "min": 0.48371767796000004,
        "max": 0.83565114096
      }
    ]
  }
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.607 ± 0.015 1.580 1.635 5.41 ± 0.25
pacquet@main 1.704 ± 0.099 1.609 1.956 5.74 ± 0.42
pnpr@HEAD 0.304 ± 0.027 0.283 0.375 1.02 ± 0.10
pnpr@main 0.297 ± 0.013 0.279 0.318 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.6065128507999997,
      "stddev": 0.015197284229791932,
      "median": 1.6066347134999999,
      "user": 0.8415775799999998,
      "system": 0.77634448,
      "min": 1.579834391,
      "max": 1.634717642
    },
    {
      "command": "pacquet@main",
      "mean": 1.7042167052,
      "stddev": 0.09870021936617689,
      "median": 1.6843238395,
      "user": 1.0351080799999999,
      "system": 0.9329249799999999,
      "min": 1.608519488,
      "max": 1.9564516749999998
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.30353021210000003,
      "stddev": 0.02657534707800613,
      "median": 0.296495497,
      "user": 0.26053768,
      "system": 0.5215823799999999,
      "min": 0.282744724,
      "max": 0.374749864
    },
    {
      "command": "pnpr@main",
      "mean": 0.2970797096000001,
      "stddev": 0.013283864030065998,
      "median": 0.293549285,
      "user": 0.25328918,
      "system": 0.5660351799999999,
      "min": 0.279212027,
      "max": 0.318207991
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 259.4 ± 15.0 236.5 288.5 2.62 ± 0.17
pacquet@main 245.3 ± 13.3 218.6 263.7 2.48 ± 0.15
pnpr@HEAD 99.4 ± 2.9 95.3 105.6 1.00 ± 0.04
pnpr@main 98.9 ± 2.9 93.3 103.6 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.25937914526000005,
      "stddev": 0.01501681722579309,
      "median": 0.25571793316,
      "user": 0.2703485200000001,
      "system": 0.10322278,
      "min": 0.23651280616,
      "max": 0.28845644816000005
    },
    {
      "command": "pacquet@main",
      "mean": 0.24530402643272733,
      "stddev": 0.013347795340472889,
      "median": 0.25182626016000004,
      "user": 0.2669326927272727,
      "system": 0.09013956181818181,
      "min": 0.21862308916,
      "max": 0.26368120516000004
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09937066781517247,
      "stddev": 0.0029434771733766836,
      "median": 0.09927284216000001,
      "user": 0.04225604068965517,
      "system": 0.01941306965517241,
      "min": 0.09530222716000002,
      "max": 0.10562570616000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.09888888739333335,
      "stddev": 0.0028695119953593183,
      "median": 0.09916441766,
      "user": 0.04469805333333334,
      "system": 0.018298187999999996,
      "min": 0.09328418916000002,
      "max": 0.10363951816000001
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 736.7 ± 54.3 678.0 846.9 1.08 ± 0.24
pacquet@main 679.5 ± 141.1 414.8 826.8 1.00
pnpm@HEAD 3620.4 ± 82.8 3520.0 3756.4 5.33 ± 1.11
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.7366621312200002,
      "stddev": 0.054298398626451964,
      "median": 0.7359630582200001,
      "user": 0.7853047377777778,
      "system": 0.20762105777777776,
      "min": 0.6780411042200001,
      "max": 0.8468559642200001
    },
    {
      "command": "pacquet@main",
      "mean": 0.6794968821088889,
      "stddev": 0.14108265496332026,
      "median": 0.69782107922,
      "user": 0.7319214044444444,
      "system": 0.18486516888888888,
      "min": 0.41481912122000003,
      "max": 0.8267910732200001
    },
    {
      "command": "pnpm@HEAD",
      "mean": 3.62035725022,
      "stddev": 0.08277813463408647,
      "median": 3.61465375522,
      "user": 5.804104515555554,
      "system": 0.2588150577777777,
      "min": 3.52001300322,
      "max": 3.75641127222
    }
  ]
}

Scenario: Isolated linker: linked-workspace resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 231.2 ± 6.8 222.5 244.2 1.03 ± 0.04
pacquet@main 224.7 ± 4.6 218.4 232.4 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.23122084537666668,
      "stddev": 0.006808251145820041,
      "median": 0.22967884646000003,
      "user": 0.18655196999999998,
      "system": 0.09495137666666668,
      "min": 0.22248172246,
      "max": 0.24422395146
    },
    {
      "command": "pacquet@main",
      "mean": 0.22469976946000003,
      "stddev": 0.00457072319216097,
      "median": 0.22462039846,
      "user": 0.17711275846153846,
      "system": 0.09321976769230769,
      "min": 0.21841812246,
      "max": 0.23237365846000002
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.474 ± 0.100 4.387 4.660 1.28 ± 0.03
pacquet@main 4.545 ± 0.157 4.397 4.952 1.30 ± 0.05
pnpr@HEAD 3.491 ± 0.050 3.421 3.569 1.00
pnpr@main 3.538 ± 0.120 3.442 3.741 1.01 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.47391675594,
      "stddev": 0.09987638840511835,
      "median": 4.43632169154,
      "user": 1.7560143999999998,
      "system": 1.9516281,
      "min": 4.38670943604,
      "max": 4.659540667040001
    },
    {
      "command": "pacquet@main",
      "mean": 4.54537092614,
      "stddev": 0.15681908033675337,
      "median": 4.506599574040001,
      "user": 1.8238565999999998,
      "system": 2.0065622000000003,
      "min": 4.39656517904,
      "max": 4.95233983504
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.4909727618399993,
      "stddev": 0.05021513304155485,
      "median": 3.49161836804,
      "user": 1.6615376999999998,
      "system": 1.7848619,
      "min": 3.42125027504,
      "max": 3.5689136530399996
    },
    {
      "command": "pnpr@main",
      "mean": 3.53801924844,
      "stddev": 0.11979978899049303,
      "median": 3.4797906040399997,
      "user": 1.6753712,
      "system": 1.8164541,
      "min": 3.44177897304,
      "max": 3.74087571604
    }
  ]
}

Scenario: GVS linker: fresh restore, hot cache + hot store

Same install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 139.9 ± 16.7 118.8 187.8 1.07 ± 0.14
pacquet@main 159.5 ± 36.9 127.4 228.5 1.22 ± 0.29
pnpr@HEAD 131.3 ± 8.1 121.1 150.3 1.00
pnpr@main 136.9 ± 5.9 126.2 147.4 1.04 ± 0.08
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.13988989004000005,
      "stddev": 0.01671282064198782,
      "median": 0.13635334904000002,
      "user": 0.16320957904761907,
      "system": 0.1495014257142857,
      "min": 0.11876363204,
      "max": 0.18775463604000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.15953010258545455,
      "stddev": 0.03686943745018465,
      "median": 0.14102088204000002,
      "user": 0.20042177818181817,
      "system": 0.1414963218181818,
      "min": 0.12735851104,
      "max": 0.22854747404000003
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.13129905870666667,
      "stddev": 0.008130231178364684,
      "median": 0.13064149854,
      "user": 0.15281668222222225,
      "system": 0.1258604733333333,
      "min": 0.12110068304,
      "max": 0.15034774104
    },
    {
      "command": "pnpr@main",
      "mean": 0.13691179170666667,
      "stddev": 0.005915598252798845,
      "median": 0.13774111604,
      "user": 0.16048429333333336,
      "system": 0.1361153622222222,
      "min": 0.12623953904000002,
      "max": 0.14743338904000003
    }
  ]
}

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.

Copilot review overview

🟢 Approval recommended

The implementation matches the PR’s stated compatibility goals, includes guardrails against malformed placeholders, and is covered by new cross-stack tests plus appropriate changesets.

Review effort: Lite
Findings: None

npm expands `${VAR?}` to the variable's value, or to an empty string
when the variable is unset. Both pnpm stacks looked up `VAR?` as the
variable name, so the placeholder never resolved and a
"Failed to replace env in config" warning was logged.

The Rust env-replace crate treats `${VAR?}` as `${VAR:-}` without
recording it as unresolved. The TypeScript reader gives
envReplaceLossy a `VAR?` entry for each such placeholder, since the
parser lives in the external `@pnpm/config.env-replace` package.

Closes #14404
`${?}` and `${NAME??}` fall outside npm's grammar and keep being
reported as unresolved. A name ending in `-` is left out so
`${NAME-?}` stays open for the proposal in
#11667.
Copilot AI review requested due to automatic review settings September 24, 2026 23:36
@zkochan
zkochan force-pushed the fix/npmrc-optional-env-var branch from 1c8b09b to e123717 Compare September 24, 2026 23:36
@qodo-code-review

qodo-code-review Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 🔗 Cross-repo conflicts (1) 📜 Skill insights (0)

Grey Divider


Action required

1. Workspace expansion lacks a release note ✗ Dismissed 📜 Skill insight ≡ Correctness
Description
npmrc-optional-env-var.md targets both pnpm and pacquet but describes only .npmrc, while the
shared Rust replacement also changes ${VAR?} expansion in pnpm-workspace.yaml. When the v12
package is released, its additional workspace-configuration behavior is absent from the release
note, so the differing v11 and v12 outcomes cannot be represented accurately by this combined entry.
Code

.changeset/npmrc-optional-env-var.md[R2-4]

+"@pnpm/config.reader": patch
+"pnpm": patch
+"pacquet": patch
Evidence
The changed front matter combines the v11 packages with pacquet, but the entry mentions only
.npmrc. The shared Rust environment replacer is also called while substituting workspace YAML
values, making the v12 behavior broader; rule 3405920 requires separate changesets when release
lines have different user-visible behavior.

.changeset/npmrc-optional-env-var.md[2-7]
pnpm/crates/env-replace/src/lib.rs[175-178]
pnpm/crates/config/src/workspace_yaml/environment_values.rs[98-115]
Skill: review-code

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The combined changeset targets both pnpm release lines even though the Rust package also gains `${VAR?}` expansion in `pnpm-workspace.yaml`, which the TypeScript package does not. Its current text documents only the shared `.npmrc` behavior.

## Fix Focus Areas
- .changeset/npmrc-optional-env-var.md[1-7]

## Recommended Fix
Split this into version-specific changesets. Keep `@pnpm/config.reader` and `pnpm` together with the `.npmrc` wording, and create a separate `pacquet` changeset that accurately describes both its `.npmrc` and `pnpm-workspace.yaml` behavior.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Windows paths lack a separator test ✓ Resolved 📜 Skill insight ▣ Testability ⭐ New
Description
The new local-path regression test uses only some/local/dir, which exercises the platform-native
separator on Unix rather than the Windows-specific forward-slash case. On Windows, the added
includes('/') branch is not directly covered, so the test can pass without proving that
forward-slash paths are recognized there.
Code

pnpm11/resolving/local-resolver/test/index.ts[R440-443]

+test('resolveFromLocalPath claims a forward-slash separated path', async () => {
+  const result = await resolveFromLocalPath({}, { bareSpecifier: 'some/local/dir' }, { projectDir: import.meta.dirname })
+  expect(result?.manifest?.name).toBe('dir')
+})
Relevance

●●● Strong

Windows-specific path behavior merits explicit regression coverage; recent local-resolver test
feedback was accepted.

PR-#15190

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed parser adds explicit support for / in addition to path.sep, but the new test uses a
generic forward-slash path and does not establish that it runs under Windows or otherwise covers the
Windows separator difference. The checklist requires path and link changes to include
Windows-separator or explicit Windows-specific regression coverage.

pnpm11/resolving/local-resolver/src/parseBareSpecifier.ts[150-153]
pnpm11/resolving/local-resolver/test/index.ts[440-443]
Skill: review-code

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The regression test only supplies a forward-slash path without constraining execution to Windows, so it does not reliably exercise the behavior added for Windows where `path.sep` is a backslash.

## Fix Focus Areas
- pnpm11/resolving/local-resolver/test/index.ts[439-444]

## Recommended Fix
Add an explicit Windows-specific test case, or parameterize the test to run with a forward-slash local path on Windows and assert that it resolves successfully. Keep the existing cross-platform coverage if it verifies separate behavior.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Inherited names corrupt optional values 🐞 Bug ≡ Correctness
Description
withOptionalEnvPlaceholders reads env[name] through the prototype chain, so an unset name such
as toString supplies an inherited function instead of the required empty string. This occurs with
ordinary object-backed environments, including the default process.env, and affects every .npmrc
key or value passed through substituteEnv.
Code

pnpm11/config/reader/src/loadNpmrcFiles.ts[634]

+    envWithOptional[`${name}?`] = env[name] ?? ''
Relevance

●●● Strong

Direct prototype-chain lookup is a deterministic correctness bug; own-property-safe environment
handling is consistently accepted.

PR-#14295

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The loader defaults env to process.env, and the new helper indexes that object directly before
creating the synthetic optional-placeholder entry. Because direct property access includes
Object.prototype, env['toString'] is not nullish when no such environment variable exists; the
resulting value is then passed directly to envReplaceLossy.

pnpm11/config/reader/src/loadNpmrcFiles.ts[87-87]
pnpm11/config/reader/src/loadNpmrcFiles.ts[615-615]
pnpm11/config/reader/src/loadNpmrcFiles.ts[629-635]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Optional environment placeholders whose names match inherited object properties resolve those prototype values instead of behaving as unset variables.

## Fix Focus Areas
- pnpm11/config/reader/src/loadNpmrcFiles.ts[629-635]
- pnpm11/config/reader/test/index.ts[4723-4729]

## Recommended Fix
Check that `name` is an own property of `env` before reading it, otherwise assign `''` to the synthetic `${name}?` entry. Add a regression test using an unset inherited name such as `toString`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Users miss optional placeholder syntax 🔗 Cross-repo conflict ≡ Correctness
Description
expand_placeholder and the pnpm 11 adapter add ${NAME?} semantics, but pnpm.io still documents
only ${NAME}, dash defaults, and colon-dash defaults. This occurs in current and versioned pnpm
configuration guidance as well as pnpr’s configuration reference, leaving every newly changed public
surface undocumented.
Code

pnpm/crates/env-replace/src/lib.rs[R175-177]

+        None => match optional_var_name(inside) {
+            Some(var_name) => (var_name, Some(""), false),
+            None => (inside, None, false),
Relevance

●● Moderate

Documentation omissions for new syntax are plausible, but no closely matching pnpm.io documentation
precedent was found.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR implements optional expansion in the shared Rust parser and the pnpm 11 npmrc adapter, while
the website’s current, versioned, and pnpr references enumerate only the older placeholder syntax.

pnpm -> pnpm.io
pnpm/crates/env-replace/src/lib.rs[168-195]
pnpm11/config/reader/src/loadNpmrcFiles.ts[612-636]
External repo: pnpm/pnpm.io, docs/npmrc.md [33-39]
External repo: pnpm/pnpm.io, docs/settings.md [20-31]
External repo: pnpm/pnpm.io, versioned_docs/version-11.x/npmrc.md [25-31]
External repo: pnpm/pnpm.io, versioned_docs/version-11.x/settings.md [20-31]
External repo: pnpm/pnpm.io, pnpr-docs/configuration.md [527-537]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
pnpm, pnpm 11, and pnpr now support `${NAME?}`, but their canonical pnpm.io documentation still lists only the existing environment-placeholder forms.

## Fix Focus Areas
- pnpm/crates/env-replace/src/lib.rs[175-177]
- pnpm11/config/reader/src/loadNpmrcFiles.ts[625-636]
- docs/npmrc.md[33-39]
- docs/settings.md[27-27]
- versioned_docs/version-11.x/npmrc.md[25-31]
- versioned_docs/version-11.x/settings.md[27-27]
- pnpr-docs/configuration.md[527-537]

## Recommended Fix
Update pnpm.io’s current, version 11, and pnpr documentation to describe `${NAME?}` as expanding to the variable value when set and to an empty string without an unresolved-placeholder warning when unset. Preserve the existing warnings about restricted expansion in repository-controlled registry, proxy, and credential settings.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 64 rules
✅ Skills: review-code
✅ Cross-repo context — repo relationships
  Explored: repo: pnpm/update (sha: fcaa952e) — View relationship
  Explored: repo: pnpm/setup (sha: fbda4c85) — View relationship
  Explored: repo: pnpm/pnpm.io (sha: e3bc12c9) — View relationship
Review mode: 🚀 Fast: This is a small, localized test-only change that strengthens coverage for local path resolution without modifying runtime behavior or high-risk code.

Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit 9575ac3

Results up to commit e123717 ⚖️ Balanced


🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (1) 📜 Skill insights (0)


Action required
1. Workspace expansion lacks a release note ✗ Dismissed 📜 Skill insight ≡ Correctness
Description
npmrc-optional-env-var.md targets both pnpm and pacquet but describes only .npmrc, while the
shared Rust replacement also changes ${VAR?} expansion in pnpm-workspace.yaml. When the v12
package is released, its additional workspace-configuration behavior is absent from the release
note, so the differing v11 and v12 outcomes cannot be represented accurately by this combined entry.
Code

.changeset/npmrc-optional-env-var.md[R2-4]

+"@pnpm/config.reader": patch
+"pnpm": patch
+"pacquet": patch
Evidence
The changed front matter combines the v11 packages with pacquet, but the entry mentions only
.npmrc. The shared Rust environment replacer is also called while substituting workspace YAML
values, making the v12 behavior broader; rule 3405920 requires separate changesets when release
lines have different user-visible behavior.

.changeset/npmrc-optional-env-var.md[2-7]
pnpm/crates/env-replace/src/lib.rs[175-178]
pnpm/crates/config/src/workspace_yaml/environment_values.rs[98-115]
Skill: review-code

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The combined changeset targets both pnpm release lines even though the Rust package also gains `${VAR?}` expansion in `pnpm-workspace.yaml`, which the TypeScript package does not. Its current text documents only the shared `.npmrc` behavior.

## Fix Focus Areas
- .changeset/npmrc-optional-env-var.md[1-7]

## Recommended Fix
Split this into version-specific changesets. Keep `@pnpm/config.reader` and `pnpm` together with the `.npmrc` wording, and create a separate `pacquet` changeset that accurately describes both its `.npmrc` and `pnpm-workspace.yaml` behavior.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Inherited names corrupt optional values 🐞 Bug ≡ Correctness
Description
withOptionalEnvPlaceholders reads env[name] through the prototype chain, so an unset name such
as toString supplies an inherited function instead of the required empty string. This occurs with
ordinary object-backed environments, including the default process.env, and affects every .npmrc
key or value passed through substituteEnv.
Code

pnpm11/config/reader/src/loadNpmrcFiles.ts[634]

+    envWithOptional[`${name}?`] = env[name] ?? ''
Relevance

●●● Strong

Direct prototype-chain lookup is a deterministic correctness bug; own-property-safe environment
handling is consistently accepted.

PR-#14295

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The loader defaults env to process.env, and the new helper indexes that object directly before
creating the synthetic optional-placeholder entry. Because direct property access includes
Object.prototype, env['toString'] is not nullish when no such environment variable exists; the
resulting value is then passed directly to envReplaceLossy.

pnpm11/config/reader/src/loadNpmrcFiles.ts[87-87]
pnpm11/config/reader/src/loadNpmrcFiles.ts[615-615]
pnpm11/config/reader/src/loadNpmrcFiles.ts[629-635]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Optional environment placeholders whose names match inherited object properties resolve those prototype values instead of behaving as unset variables.

## Fix Focus Areas
- pnpm11/config/reader/src/loadNpmrcFiles.ts[629-635]
- pnpm11/config/reader/test/index.ts[4723-4729]

## Recommended Fix
Check that `name` is an own property of `env` before reading it, otherwise assign `''` to the synthetic `${name}?` entry. Add a regression test using an unset inherited name such as `toString`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Users miss optional placeholder syntax 🔗 Cross-repo conflict ≡ Correctness
Description
expand_placeholder and the pnpm 11 adapter add ${NAME?} semantics, but pnpm.io still documents
only ${NAME}, dash defaults, and colon-dash defaults. This occurs in current and versioned pnpm
configuration guidance as well as pnpr’s configuration reference, leaving every newly changed public
surface undocumented.
Code

pnpm/crates/env-replace/src/lib.rs[R175-177]

+        None => match optional_var_name(inside) {
+            Some(var_name) => (var_name, Some(""), false),
+            None => (inside, None, false),
Relevance

●● Moderate

Documentation omissions for new syntax are plausible, but no closely matching pnpm.io documentation
precedent was found.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR implements optional expansion in the shared Rust parser and the pnpm 11 npmrc adapter, while
the website’s current, versioned, and pnpr references enumerate only the older placeholder syntax.

pnpm -> pnpm.io
pnpm/crates/env-replace/src/lib.rs[168-195]
pnpm11/config/reader/src/loadNpmrcFiles.ts[612-636]
External repo: pnpm/pnpm.io, docs/npmrc.md [33-39]
External repo: pnpm/pnpm.io, docs/settings.md [20-31]
External repo: pnpm/pnpm.io, versioned_docs/version-11.x/npmrc.md [25-31]
External repo: pnpm/pnpm.io, versioned_docs/version-11.x/settings.md [20-31]
External repo: pnpm/pnpm.io, pnpr-docs/configuration.md [527-537]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
pnpm, pnpm 11, and pnpr now support `${NAME?}`, but their canonical pnpm.io documentation still lists only the existing environment-placeholder forms.

## Fix Focus Areas
- pnpm/crates/env-replace/src/lib.rs[175-177]
- pnpm11/config/reader/src/loadNpmrcFiles.ts[625-636]
- docs/npmrc.md[33-39]
- docs/settings.md[27-27]
- versioned_docs/version-11.x/npmrc.md[25-31]
- versioned_docs/version-11.x/settings.md[27-27]
- pnpr-docs/configuration.md[527-537]

## Recommended Fix
Update pnpm.io’s current, version 11, and pnpr documentation to describe `${NAME?}` as expanding to the variable value when set and to an empty string without an unresolved-placeholder warning when unset. Preserve the existing warnings about restricted expansion in repository-controlled registry, proxy, and credential settings.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
…npm#15565)

npm expands `${VAR?}` in .npmrc to the variable's value, or to an empty
string when the variable is unset. Both pnpm stacks looked up `VAR?` as
the variable name, so the placeholder never resolved and a
"Failed to replace env in config" warning was logged.

The Rust env-replace crate treats `${VAR?}` as `${VAR:-}` without
recording it as unresolved. Only a non-empty name without another `?`
or a trailing `-` counts, which keeps `${NAME-?}` free for
pnpm#11667. The TypeScript reader gives envReplaceLossy
a `VAR?` entry for each such placeholder, since the parser lives in the
external `@pnpm/config.env-replace` package.

Closes pnpm#14404

---------

Co-authored-by: Zoltan Kochan <[email protected]>
This was referenced Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

npmrc ${VAR?} optional-variable syntax is unsupported, line dropped and logs warning

4 participants