Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix module external not treated as async #9247

Merged
merged 4 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/rspack_core/src/external_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,23 @@ impl Module for ExternalModule {

async fn build(
&mut self,
_build_context: BuildContext,
build_context: BuildContext,
_: Option<&Compilation>,
) -> Result<BuildResult> {
self.build_info.module = build_context.compiler_options.output.module;
let resolved_external_type = self.resolve_external_type();

// TODO add exports_type for request
match resolved_external_type {
"this" => self.build_info.strict = false,
"system" => self.build_meta.exports_type = BuildMetaExportsType::Namespace,
"module" => self.build_meta.exports_type = BuildMetaExportsType::Namespace,
"module" => {
self.build_meta.exports_type = BuildMetaExportsType::Namespace;
// align with https://github.com/webpack/webpack/blob/3919c844eca394d73ca930e4fc5506fb86e2b094/lib/ExternalModule.js#L597
if !self.build_info.module {
self.build_meta.has_top_level_await = true;
}
}
"script" | "promise" => self.build_meta.has_top_level_await = true,
"import" => {
self.build_meta.has_top_level_await = true;
Expand Down
3 changes: 3 additions & 0 deletions crates/rspack_core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub struct BuildInfo {
pub top_level_declarations: Option<HashSet<Atom>>,
pub module_concatenation_bailout: Option<String>,
pub assets: HashMap<String, CompilationAsset>,
pub module: bool,
}

impl Default for BuildInfo {
Expand All @@ -87,6 +88,7 @@ impl Default for BuildInfo {
top_level_declarations: None,
module_concatenation_bailout: None,
assets: Default::default(),
module: false,
}
}
}
Expand Down Expand Up @@ -168,6 +170,7 @@ impl Display for ExportsArgument {
#[serde(rename_all = "camelCase")]
pub struct BuildMeta {
pub strict_esm_module: bool,
// same as is_async https://github.com/webpack/webpack/blob/3919c844eca394d73ca930e4fc5506fb86e2b094/lib/Module.js#L107
pub has_top_level_await: bool,
pub esm: bool,
pub exports_type: BuildMetaExportsType,
Expand Down
Loading