Skip to content

Commit

Permalink
fix: correct extension alias order to align with Node.js (#4308)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jan 1, 2025
1 parent 616d7d5 commit 3445b73
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions packages/compat/webpack/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
"extensionAlias": {
".js": [
".js",
".ts",
".tsx",
".js",
],
".jsx": [
".tsx",
".jsx",
".tsx",
],
},
"extensions": [
Expand Down Expand Up @@ -769,13 +769,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ
},
"extensionAlias": {
".js": [
".js",
".ts",
".tsx",
".js",
],
".jsx": [
".tsx",
".jsx",
".tsx",
],
},
"extensions": [
Expand Down Expand Up @@ -1105,13 +1105,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
"extensionAlias": {
".js": [
".js",
".ts",
".tsx",
".js",
],
".jsx": [
".tsx",
".jsx",
".tsx",
],
},
"extensions": [
Expand Down Expand Up @@ -1424,13 +1424,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
"extensionAlias": {
".js": [
".js",
".ts",
".tsx",
".js",
],
".jsx": [
".tsx",
".jsx",
".tsx",
],
},
"extensions": [
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ export const pluginResolve = (): RsbuildPlugin => ({
// TypeScript allows importing TS files with `.js` extension
// See: https://github.com/microsoft/TypeScript/blob/c09e2ab4/src/compiler/moduleNameResolver.ts#L2151-L2168
chain.resolve.extensionAlias.merge({
'.js': ['.ts', '.tsx', '.js'],
'.jsx': ['.tsx', '.jsx'],
'.js': ['.js', '.ts', '.tsx'],
'.jsx': ['.jsx', '.tsx'],
});
}

Expand Down
16 changes: 8 additions & 8 deletions packages/core/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
"extensionAlias": {
".js": [
".js",
".ts",
".tsx",
".js",
],
".jsx": [
".tsx",
".jsx",
".tsx",
],
},
"extensions": [
Expand Down Expand Up @@ -845,13 +845,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
},
"extensionAlias": {
".js": [
".js",
".ts",
".tsx",
".js",
],
".jsx": [
".tsx",
".jsx",
".tsx",
],
},
"extensions": [
Expand Down Expand Up @@ -1200,13 +1200,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
"extensionAlias": {
".js": [
".js",
".ts",
".tsx",
".js",
],
".jsx": [
".tsx",
".jsx",
".tsx",
],
},
"extensions": [
Expand Down Expand Up @@ -1633,13 +1633,13 @@ exports[`tools.rspack > should match snapshot 1`] = `
},
"extensionAlias": {
".js": [
".js",
".ts",
".tsx",
".js",
],
".jsx": [
".tsx",
".jsx",
".tsx",
],
},
"extensions": [
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-svelte/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ exports[`plugin-svelte > should add svelte loader and resolve config properly 2`
],
"extensionAlias": {
".js": [
".js",
".ts",
".tsx",
".js",
],
".jsx": [
".tsx",
".jsx",
".tsx",
],
},
"extensions": [
Expand Down
4 changes: 2 additions & 2 deletions website/docs/en/guide/basic/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Rsbuild supports this feature through Rspack's [extensionAlias](https://rspack.d
const rspackConfig = {
resolve: {
extensionAlias: {
'.js': ['.ts', '.tsx', '.js'],
'.jsx': ['.tsx', '.jsx'],
'.js': ['.js', '.ts', '.tsx'],
'.jsx': ['.jsx', '.tsx'],
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions website/docs/zh/guide/basic/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Rsbuild 通过 Rspack 的 [extensionAlias](https://rspack.dev/config/resolve#res
const rspackConfig = {
resolve: {
extensionAlias: {
'.js': ['.ts', '.tsx', '.js'],
'.jsx': ['.tsx', '.jsx'],
'.js': ['.js', '.ts', '.tsx'],
'.jsx': ['.jsx', '.tsx'],
},
},
};
Expand Down

1 comment on commit 3445b73

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
plugins ❌ failure
rspress ✅ success
rslib ❌ failure
examples ✅ success

Please sign in to comment.