typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Port TypeScript PR #62844: Gate `#/` subpath imports on NodeNext and Bundler

Open Copilot opened this issue 2 weeks ago • 4 comments

Port microsoft/TypeScript PR #62844 - Gate #/ subpath imports on NodeNext and Bundler module resolution modes

This PR aligns with Node.js PR nodejs/node#60864, which allows defining symmetric exports and imports fields in package.json:

{
  "exports": { "./*": "./src/*" },
  "imports": { "#/*": "./src/*" }
}

Changes

  • Added NodeResolutionFeaturesImportsPatternRoot flag (bit 6) to gate #/ root wildcard imports
  • Updated NodeNextDefault and BundlerDefault to include the new flag, while Node16Default excludes it
  • Modified loadModuleFromImports() to check feature flag before rejecting #/ patterns
  • Added compiler test cases from the original TypeScript PR to verify the behavior

Test Coverage

Added two test cases:

  1. nodeModulesPackageImportsRootWildcard.ts - Tests that #/ imports work in NodeNext mode
  2. nodeModulesPackageImportsRootWildcardNode16.ts - Tests that #/ imports are rejected in Node16 mode

Behavior

Mode #/ imports
Node16 Rejected (backward compatible)
NodeNext Allowed
Bundler Allowed

Imports like #cjs or #utils (not starting with #/) continue to work in all modes.

Original prompt

Port https://github.com/microsoft/TypeScript/pull/62844

Custom agent used: Strada to Corsa Port Expert A Go and TypeScript expert who can easily figure out how to port PRs from one language to another


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Dec 10 '25 22:12 Copilot

Sad there's no test but it's correct, so

jakebailey avatar Dec 10 '25 23:12 jakebailey

@copilot also copy the compiler testcases from the original PR. Do not port the fourslash test

Added the compiler test cases from the original PR in commit 400b4d7. The tests verify that:

  • #/ patterns work correctly in NodeNext mode (resolves to the mapped path)
  • #/ patterns are rejected in Node16 mode with error TS2307

Did not port the fourslash test as requested.

Copilot avatar Dec 11 '25 00:12 Copilot

A bit sad I didn't notice that the original PR didn't just use one test with node16,nodenext,bundler, but, oh well

Thanks for the feedback! I intentionally separated the error cases into a distinct test file because I thought it would make the error baselines cleaner and easier to read. But now I'm wondering if that separation was actually necessary. For future reference, would it be better to combine them into a single test with node16,nodenext,bundler? I'd appreciate any guidance!

magic-akari avatar Dec 11 '25 01:12 magic-akari

Yeah, it makes separate baselines, so is a pretty good solution to this.

jakebailey avatar Dec 11 '25 02:12 jakebailey