Repository navigation
fix(config): support npm's optional ${VAR?} placeholder in .npmrc - #15565
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: pnpm/pnpm/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe Rust environment replacer and pnpm11 configuration reader now support npm’s ChangesOptional environment-variable placeholders
Forward-slash local paths
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Assessment against linked issues
Out-of-scope changes
Suggested labels: Merge Risk: ⚪ Minimal · up to
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
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-replacenow expands${VAR?}as an empty-string fallback and avoids recording it as unresolved. - TypeScript
.npmrcloading injectsVAR?lookup entries soenvReplaceLossycan 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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
Open (1)
Resolved since last review (2)
There was a problem hiding this comment.
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)
Same-run regression checkHEAD 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.
Integrated-Benchmark Report (Linux)Commit: 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
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
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
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
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
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
Confirmation (reversed target order)
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
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
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
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
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
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 storeSame 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.
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
}
]
} |
8756bbb to
1c8b09b
Compare
There was a problem hiding this comment.
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.
1c8b09b to
e123717
Compare
Code Review by Qodo
1.
|
…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]>


Summary
npm's
.npmrcdocs define${VAR?}: it expands toVAR, or to an empty string whenVARis unset. Both pnpm stacks looked upVAR?as the variable name, so the placeholder never resolved and every run loggedFailed to replace env in config: ${VAR?}.pnpm-env-replacetreats${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, sopnpm-workspace.yamlplaceholders and the pnpr config file get the same form, with its own pnpr changeset.@pnpm/config.env-replacepackage, sosubstituteEnvinloadNpmrcFiles.tspassesenvReplaceLossya lookup table with aVAR?entry for each such placeholder. v11pnpm-workspace.yamlexpansion is unchanged.The triage bot tagged this
state: needs designbecause of the related${NAME-?}proposal in #11667. This PR adds only npm's documented${VAR?}form for compatibility with existing.npmrcfiles. It does not touch that proposal.Closes #14404
Squash Commit Body
Checklist
already linked to it solves it.
are implemented in every affected version.
pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Tests fail without the fix (source changes reverted with
git apply -R): 5 cases inpnpm11/config/reader/test/index.ts,optional_placeholder_expands_without_being_recordedinpnpm-env-replace,from_ini_expands_optional_auth_env_placeholder_without_warninginpnpm-config, andmalformed_optional_placeholder_is_recordedwithout the name guard.Written by an agent (Claude Code, Opus 5.5).
Summary by CodeRabbit
.npmrc, pnpr, andpnpm-workspace.yamlconfiguration 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.