fix(trace): resolve package import wildcard trailers - #66
Conversation
📝 WalkthroughWalkthrough
ChangesWildcard import tracing
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Replace the `@vercel/nft` pnpm patch with a fallback resolver, so the fix does not have to be re-applied on every nft release (an exact-version `patchedDependencies` key hard-fails installs with ERR_PNPM_UNUSED_PATCH as soon as the version moves). nft exports its own resolver, so `nft.resolve` can wrap it and only fall back to exsolve — which implements the Node resolution algorithm — for specifiers nft throws on. exsolve had the same defect in its `imports` matching and fixes it in 1.1.1 (unjs/exsolve#56). This is purely additive: nft stays the primary resolver, so the fallback only ever turns a "Failed to resolve dependency" warning into a resolved file, and becomes a no-op once vercel/nft#604 lands. It also covers a case the patch did not: wildcard imports whose target is another package (`"#utils/*": "@fixture/nitro-utils/*"`). nft's wildcard branch only handles targets starting with `./`, so those stayed unresolved even with the patch applied. The fixture and test now assert both that and the original `"#*.js": "./runtime/*.js"` trailer case. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@pnpm-workspace.yaml`:
- Line 10: Update the minimumReleaseAgeExclude entry in pnpm-workspace.yaml from
the broad exsolve* glob to the exact exsolve package name, preserving the
release-age bypass only for the declared dependency.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: bc42f7b3-4344-49a7-b1e1-d4e830234cfa
⛔ Files ignored due to path filters (3)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yamltest/fixture/node_modules/@fixture/imports-wildcard/index.mjsis excluded by!**/node_modules/**test/fixture/node_modules/@fixture/imports-wildcard/package.jsonis excluded by!**/node_modules/**
📒 Files selected for processing (5)
package.jsonpnpm-workspace.yamlsrc/trace.tstest/fixture/package-imports.mjstest/trace.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- test/fixture/package-imports.mjs
- test/trace.test.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66 +/- ##
==========================================
+ Coverage 80.44% 80.70% +0.26%
==========================================
Files 5 5
Lines 588 596 +8
Branches 170 172 +2
==========================================
+ Hits 473 481 +8
Misses 84 84
Partials 31 31 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Note
Edited by @pi0x (claude) in 8ae0920: swapped the
@vercel/nftpatch for a fallback resolver (see Update below). Reviewed and implemented with AI assistance (Claude Code); all changes were verified locally.Summary
#*.js, which nft does not matchContext
NFT currently handles wildcard keys only when they end in
*. A valid package import map such as:{ "imports": { "#*.js": "./runtime/*.js" } }therefore fails to trace
#internal/marker.js. nf3 copies the package entry and manifest but omits the internal target, resulting inERR_MODULE_NOT_FOUNDat runtime.Update
The original approach patched the bundled
@vercel/nft@1.10.2viapnpm.patchedDependencies. That patch has been replaced with a fallback resolver insrc/trace.ts:nft exports its own resolver (
exports.resolve = resolveDependency), so it stays the primary resolver and exsolve — which implements the Node resolution algorithm — is only consulted for specifiers nft throws on.Why this over the patch:
patchedDependencieskey hard-fails installs withERR_PNPM_UNUSED_PATCHthe moment the nft version moves, which would break every renovate PR (@vercel/nft*is inminimumReleaseAgeExclude, so those land quickly)."#utils/*": "@fixture/nitro-utils/*") failed even with the patch applied, because nft's wildcard branch only handles targets starting with./while its exact-match branch handles bare specifiers. exsolve handles both.exsolve had the same defect in its
importsmatching (key.slice(0, -1)instead ofkey.slice(0, patternIndex)); fixed in exsolve 1.1.1, which this PR bumps to.exsolve*was added tominimumReleaseAgeExcludeso the release installs.Regression testing
The
@fixture/imports-wildcardpackage exports an entry that imports#internal/marker.jsthrough a#*.jsmapping, and#utils/extrathrough a"#utils/*": "@fixture/nitro-utils/*"mapping to another package. The nf3 test traces the package, asserts both targets exist in the emittednode_modules, and imports the copied entry.Without the fallback the test fails with
ENOENT … runtime/internal/marker.js; with it, both cases resolve.Validation
pnpm vitest run— 43 tests passedpnpm test:typespnpm lintpnpm build— bundled dist size check passed (547 kB / 155 files)Summary by CodeRabbit
Bug Fixes
Tests