Repository navigation
fix(core): run the .js file the entry point or a JavaScript importer names - #881
Merged
Merged
Conversation
…names Since #840, `./x.js` resolved to `x.ts` when both exist, for every resolve outside node_modules. That matches tsc and tsx for an import from a TypeScript file, but the entry point and imports from .js, .mjs and .cjs files ran the TypeScript sibling, where Node.js and tsx run the named .js file (#878). A new extension order, `Named`, tries the file a `.js`, `.jsx`, `.mjs` or `.cjs` specifier names first, then TypeScript. It applies to the entry point, `--import` preloads and importers that are not TypeScript or `.jsx` files. Imports from TypeScript keep the #840 order, and a package reached from JavaScript still runs what it compiled. Closes #878 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 603529af3a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #878
Problem
Since #840 every resolve outside
node_modulestried TypeScript first. That is right for an import from a TypeScript file, as tsc and tsx resolve it. But it also hit the entry point and imports from JavaScript files, where Node.js and tsx run the.jsfile that was named.Fix
There's a new order,
ExtensionOrder::Named: the file the specifier names first, then TypeScript.extension_order()picks the order from the importer:Namedaliases:.js → .js .ts .tsx .jsx,.jsx → .jsx .tsx .ts .js,.mjs → .mjs .mts,.cjs → .cjs .cts. A missing.jsstill finds its.ts, as tsx does../depstays TypeScript first, as tsx resolves it..jsximporters stay TypeScript first: tsx counts.jsxas TypeScript (/\.([cm]?ts|[tj]sx)$/).node_modulesre-resolve now runs for every order butPackage. Without that, a.jsfile importing a package withindex.jsbesideindex.tswould getindex.ts.require()is unchanged: it already goes to Node's own CommonJS lookup.Tests
named_order_tries_the_named_file_firstandextension_order_follows_the_importer.extension-order.spec.ts:.js,.mjs,.cjs,.jsxand extensionless names, with the TypeScript sibling present and with it missing.js,.mjsand.cjsimporters.jsximportercreateImporterwith a directory parentdirectory-parent-url.spec.ts:--import ./setup.jswithsetup.tsbeside it.main. The rest guard what must not change.vp run testandOXC_TRANSFORM_ALL=true vp run testpass (588), as docargo test, clippy, lint and fmt.Not changed
allowJs. oxc-node does not readallowJsfor this. Following it would bring this bug back inallowJsprojects.require()from TypeScript files still uses Node's lookup (JavaScript first), as before.🤖 Generated with Claude Code