Commit 9a5fef9
feat: support tsx as a fallback loader for TypeScript and JSX configs (#4796)
* feat: support tsx as a fallback loader for TypeScript configs
Register `tsx/cjs` manually when the loaders known to `interpret` are
unavailable. It cannot go through `interpret`/`rechoir`: the `tsx/cjs`
entry point exists only in the package's `exports` map, which
`rechoir`'s resolver (legacy `resolve@1.x`) does not support, so it is
resolved with `createRequire` from the configuration file's location
and required directly, installing its require hook.
The loaders listed in `interpret` keep priority; `tsx` is tried only
after all of them have failed. For `.mts`, which has no `interpret`
entry at all, `tsx` is registered best-effort and the original error
reporting is preserved when it is missing. When nothing works, the
`tsx` resolution failure is appended to the existing loader failure
list before "Please install one of them".
The fixture shadows the `interpret` loaders with generated throwing
stubs (kept out of the repository — `test/**/node_modules` is already
ignored) so the tests exercise the real `tsx` package from the root
dev dependencies for both `.ts` and `.mts` configurations.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hv8piVkEGYdWzWoWCtMcif
* feat: extend the tsx fallback loader to .jsx configurations
`tsx/cjs` also installs a require hook for `.jsx` (esbuild transform,
including `@jsx` pragma support), so offer it as a fallback there too
when the `interpret` loaders (`@babel/register`, `sucrase`) are not
installed.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hv8piVkEGYdWzWoWCtMcif
* fix: address Copilot review feedback
- Normalize non-Error throws in the tsx registration so the
error-reporting path can rely on `.message`.
- Fix the pre-existing "Unable load" typo ("Unable to load").
- Cover `.cts` (special-cased extension mapping) and `.tsx` (types and
JSX together) in the fixture, alongside `.ts`, `.mts` and `.jsx`.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hv8piVkEGYdWzWoWCtMcif
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6cafa00 commit 9a5fef9
13 files changed
Lines changed: 747 additions & 8 deletions
File tree
- .changeset
- packages/webpack-cli/src
- test/build/config-format/typescript-tsx
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
0 commit comments