Skip to content

fix: resolve package import wildcard trailers - #604

Open
cmpadden wants to merge 1 commit into
mainfrom
fix/package-import-wildcard-trailers
Open

fix: resolve package import wildcard trailers#604
cmpadden wants to merge 1 commit into
mainfrom
fix/package-import-wildcard-trailers

Conversation

@cmpadden

Copy link
Copy Markdown

Summary

  • resolve package.json import/export wildcard patterns that include a trailer, such as #*.js
  • match both the pattern prefix and trailer before substituting the captured wildcard
  • use Node-compatible pattern precedence and reject patterns containing multiple wildcards
  • add an imports-wildcard trace fixture covering #internal/marker.js mapped through #*.js

Context

NFT previously recognized wildcard keys only when they ended in *. A valid import map such as:

{
  "imports": {
    "#*.js": "./dist/*.js"
  }
}

therefore failed to resolve #internal/marker.js. Consumers such as Nitro/nf3 would trace the package entry point but omit the internal target, producing an incomplete deployment artifact that failed at runtime with ERR_MODULE_NOT_FOUND.

Related reproduction and downstream workaround:

Regression testing

The new test/unit/imports-wildcard fixture imports #internal/marker.js and expects dist/internal/marker.js in the trace.

Before this change, both the cwd-based and root-based fixture variants failed because the marker file was absent. After the resolver change, both variants pass.

Validation performed:

  • pnpm build
  • pnpm prettier-check
  • pnpm exec jest test/unit.test.js --runInBand -t 'imports|exports-wildcard'
  • pnpm exec jest --runInBand --silent — 1,475 tests passed

@cmpadden
cmpadden requested review from a team, icyJoseph, ijjk and styfle as code owners July 27, 2026 15:16
pi0x pushed a commit to cmpadden/nf3 that referenced this pull request Jul 27, 2026
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>
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.

1 participant