Skip to content

Commit

Permalink
fix: fallback to next main field when resolve failed (#7670)
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder authored Aug 26, 2024
1 parent 997fc80 commit af0cb1c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 141 deletions.
141 changes: 2 additions & 139 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rspack_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rspack_loader_runner = { version = "0.1.0", path = "../rspack_loader_runner" }
rspack_macros = { version = "0.1.0", path = "../rspack_macros" }
rspack_paths = { version = "0.1.0", path = "../rspack_paths" }
rspack_regex = { version = "0.1.0", path = "../rspack_regex" }
rspack_resolver = { version = "0.2.0", features = ["package_json_raw_json_api", "yarn_pnp"] }
rspack_resolver = { version = "0.3.0", features = ["package_json_raw_json_api"] }
rspack_sources = { workspace = true }
rspack_util = { version = "0.1.0", path = "../rspack_util" }
rustc-hash = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion crates/rspack_core/src/resolver/resolver_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ fn to_rspack_resolver_options(
roots,
builtin_modules: false,
imports_fields,
pnp_manifest: None,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { foo } from 'invalid-pkg'

it("should fallback from module to main when resolve failed", () => {
expect(foo).toBe(42);
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const path = require("path");

/**
* @type {import('webpack').Configuration | import('@rspack/cli').Configuration}
*/
module.exports = {
devtool: false,
entry: {
main: {
import: "./index.js",
},
},
resolve: {
mainFields: ['module', 'main'],
extensionAlias: {
'.js': ['.ts', '.js']
}
},
};

2 comments on commit af0cb1c

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2024-08-26 36df3c2) Current Change
10000_development-mode + exec 2.37 s ± 34 ms 2.34 s ± 38 ms -1.36 %
10000_development-mode_hmr + exec 698 ms ± 7 ms 711 ms ± 7.3 ms +1.87 %
10000_production-mode + exec 3.07 s ± 30 ms 3.01 s ± 34 ms -1.79 %
arco-pro_development-mode + exec 1.89 s ± 58 ms 1.86 s ± 66 ms -1.51 %
arco-pro_development-mode_hmr + exec 437 ms ± 2.7 ms 438 ms ± 1.5 ms +0.21 %
arco-pro_production-mode + exec 3.51 s ± 56 ms 3.5 s ± 53 ms -0.40 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.55 s ± 120 ms 3.53 s ± 72 ms -0.57 %
threejs_development-mode_10x + exec 1.69 s ± 7.3 ms 1.7 s ± 18 ms +0.14 %
threejs_development-mode_10x_hmr + exec 804 ms ± 9.6 ms 798 ms ± 6.6 ms -0.70 %
threejs_production-mode_10x + exec 5.57 s ± 17 ms 5.54 s ± 35 ms -0.48 %

@rspack-bot
Copy link

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 ✅ success
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rslib ❌ failure
rsbuild ✅ success
examples ✅ success

Please sign in to comment.