Skip to content

Commit 453bcc7

Browse files
fix: restore WASI named exports
1 parent 51f2c54 commit 453bcc7

File tree

27 files changed

+460
-701
lines changed

27 files changed

+460
-701
lines changed

crates/node_binding/napi-binding.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,7 @@ export interface RawConsumeOptions {
18531853
export interface RawConsumeSharedPluginOptions {
18541854
consumes: Array<RawConsumeOptions>
18551855
enhanced: boolean
1856+
asyncStartup?: boolean
18561857
}
18571858

18581859
export interface RawContainerPluginOptions {

crates/node_binding/rspack.wasi-browser.js

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -63,63 +63,4 @@ const {
6363
},
6464
})
6565
export default __napiModule.exports
66-
export const Assets = __napiModule.exports.Assets
67-
export const AsyncDependenciesBlock = __napiModule.exports.AsyncDependenciesBlock
68-
export const Chunk = __napiModule.exports.Chunk
69-
export const ChunkGraph = __napiModule.exports.ChunkGraph
70-
export const ChunkGroup = __napiModule.exports.ChunkGroup
71-
export const Chunks = __napiModule.exports.Chunks
72-
export const CodeGenerationResult = __napiModule.exports.CodeGenerationResult
73-
export const CodeGenerationResults = __napiModule.exports.CodeGenerationResults
74-
export const ConcatenatedModule = __napiModule.exports.ConcatenatedModule
75-
export const ContextModule = __napiModule.exports.ContextModule
76-
export const Dependency = __napiModule.exports.Dependency
77-
export const Diagnostics = __napiModule.exports.Diagnostics
78-
export const EntryDataDto = __napiModule.exports.EntryDataDto
79-
export const EntryDataDTO = __napiModule.exports.EntryDataDTO
80-
export const EntryDependency = __napiModule.exports.EntryDependency
81-
export const EntryOptionsDto = __napiModule.exports.EntryOptionsDto
82-
export const EntryOptionsDTO = __napiModule.exports.EntryOptionsDTO
83-
export const ExternalModule = __napiModule.exports.ExternalModule
84-
export const JsCompilation = __napiModule.exports.JsCompilation
85-
export const JsCompiler = __napiModule.exports.JsCompiler
86-
export const JsContextModuleFactoryAfterResolveData = __napiModule.exports.JsContextModuleFactoryAfterResolveData
87-
export const JsContextModuleFactoryBeforeResolveData = __napiModule.exports.JsContextModuleFactoryBeforeResolveData
88-
export const JsDependencies = __napiModule.exports.JsDependencies
89-
export const JsEntries = __napiModule.exports.JsEntries
90-
export const JsExportsInfo = __napiModule.exports.JsExportsInfo
91-
export const JsModuleGraph = __napiModule.exports.JsModuleGraph
92-
export const JsResolver = __napiModule.exports.JsResolver
93-
export const JsResolverFactory = __napiModule.exports.JsResolverFactory
94-
export const JsStats = __napiModule.exports.JsStats
95-
export const KnownBuildInfo = __napiModule.exports.KnownBuildInfo
96-
export const Module = __napiModule.exports.Module
97-
export const ModuleGraphConnection = __napiModule.exports.ModuleGraphConnection
98-
export const NativeWatcher = __napiModule.exports.NativeWatcher
99-
export const NativeWatchResult = __napiModule.exports.NativeWatchResult
100-
export const NormalModule = __napiModule.exports.NormalModule
101-
export const RawExternalItemFnCtx = __napiModule.exports.RawExternalItemFnCtx
102-
export const ReadonlyResourceData = __napiModule.exports.ReadonlyResourceData
103-
export const ResolverFactory = __napiModule.exports.ResolverFactory
104-
export const Sources = __napiModule.exports.Sources
105-
export const VirtualFileStore = __napiModule.exports.VirtualFileStore
106-
export const JsVirtualFileStore = __napiModule.exports.JsVirtualFileStore
107-
export const async = __napiModule.exports.async
108-
export const BuiltinPluginName = __napiModule.exports.BuiltinPluginName
109-
export const cleanupGlobalTrace = __napiModule.exports.cleanupGlobalTrace
110-
export const EnforceExtension = __napiModule.exports.EnforceExtension
111-
export const EXPECTED_RSPACK_CORE_VERSION = __napiModule.exports.EXPECTED_RSPACK_CORE_VERSION
112-
export const formatDiagnostic = __napiModule.exports.formatDiagnostic
113-
export const JsLoaderState = __napiModule.exports.JsLoaderState
114-
export const JsRspackSeverity = __napiModule.exports.JsRspackSeverity
115-
export const loadBrowserslist = __napiModule.exports.loadBrowserslist
116-
export const minify = __napiModule.exports.minify
117-
export const minifySync = __napiModule.exports.minifySync
118-
export const RawJavascriptParserCommonjsExports = __napiModule.exports.RawJavascriptParserCommonjsExports
119-
export const RawRuleSetConditionType = __napiModule.exports.RawRuleSetConditionType
120-
export const registerGlobalTrace = __napiModule.exports.registerGlobalTrace
121-
export const RegisterJsTapKind = __napiModule.exports.RegisterJsTapKind
122-
export const sync = __napiModule.exports.sync
123-
export const syncTraceEvent = __napiModule.exports.syncTraceEvent
124-
export const transform = __napiModule.exports.transform
125-
export const transformSync = __napiModule.exports.transformSync
66+

crates/node_binding/rspack.wasi.cjs

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -108,63 +108,4 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
108108
},
109109
})
110110
module.exports = __napiModule.exports
111-
module.exports.Assets = __napiModule.exports.Assets
112-
module.exports.AsyncDependenciesBlock = __napiModule.exports.AsyncDependenciesBlock
113-
module.exports.Chunk = __napiModule.exports.Chunk
114-
module.exports.ChunkGraph = __napiModule.exports.ChunkGraph
115-
module.exports.ChunkGroup = __napiModule.exports.ChunkGroup
116-
module.exports.Chunks = __napiModule.exports.Chunks
117-
module.exports.CodeGenerationResult = __napiModule.exports.CodeGenerationResult
118-
module.exports.CodeGenerationResults = __napiModule.exports.CodeGenerationResults
119-
module.exports.ConcatenatedModule = __napiModule.exports.ConcatenatedModule
120-
module.exports.ContextModule = __napiModule.exports.ContextModule
121-
module.exports.Dependency = __napiModule.exports.Dependency
122-
module.exports.Diagnostics = __napiModule.exports.Diagnostics
123-
module.exports.EntryDataDto = __napiModule.exports.EntryDataDto
124-
module.exports.EntryDataDTO = __napiModule.exports.EntryDataDTO
125-
module.exports.EntryDependency = __napiModule.exports.EntryDependency
126-
module.exports.EntryOptionsDto = __napiModule.exports.EntryOptionsDto
127-
module.exports.EntryOptionsDTO = __napiModule.exports.EntryOptionsDTO
128-
module.exports.ExternalModule = __napiModule.exports.ExternalModule
129-
module.exports.JsCompilation = __napiModule.exports.JsCompilation
130-
module.exports.JsCompiler = __napiModule.exports.JsCompiler
131-
module.exports.JsContextModuleFactoryAfterResolveData = __napiModule.exports.JsContextModuleFactoryAfterResolveData
132-
module.exports.JsContextModuleFactoryBeforeResolveData = __napiModule.exports.JsContextModuleFactoryBeforeResolveData
133-
module.exports.JsDependencies = __napiModule.exports.JsDependencies
134-
module.exports.JsEntries = __napiModule.exports.JsEntries
135-
module.exports.JsExportsInfo = __napiModule.exports.JsExportsInfo
136-
module.exports.JsModuleGraph = __napiModule.exports.JsModuleGraph
137-
module.exports.JsResolver = __napiModule.exports.JsResolver
138-
module.exports.JsResolverFactory = __napiModule.exports.JsResolverFactory
139-
module.exports.JsStats = __napiModule.exports.JsStats
140-
module.exports.KnownBuildInfo = __napiModule.exports.KnownBuildInfo
141-
module.exports.Module = __napiModule.exports.Module
142-
module.exports.ModuleGraphConnection = __napiModule.exports.ModuleGraphConnection
143-
module.exports.NativeWatcher = __napiModule.exports.NativeWatcher
144-
module.exports.NativeWatchResult = __napiModule.exports.NativeWatchResult
145-
module.exports.NormalModule = __napiModule.exports.NormalModule
146-
module.exports.RawExternalItemFnCtx = __napiModule.exports.RawExternalItemFnCtx
147-
module.exports.ReadonlyResourceData = __napiModule.exports.ReadonlyResourceData
148-
module.exports.ResolverFactory = __napiModule.exports.ResolverFactory
149-
module.exports.Sources = __napiModule.exports.Sources
150-
module.exports.VirtualFileStore = __napiModule.exports.VirtualFileStore
151-
module.exports.JsVirtualFileStore = __napiModule.exports.JsVirtualFileStore
152-
module.exports.async = __napiModule.exports.async
153-
module.exports.BuiltinPluginName = __napiModule.exports.BuiltinPluginName
154-
module.exports.cleanupGlobalTrace = __napiModule.exports.cleanupGlobalTrace
155-
module.exports.EnforceExtension = __napiModule.exports.EnforceExtension
156-
module.exports.EXPECTED_RSPACK_CORE_VERSION = __napiModule.exports.EXPECTED_RSPACK_CORE_VERSION
157-
module.exports.formatDiagnostic = __napiModule.exports.formatDiagnostic
158-
module.exports.JsLoaderState = __napiModule.exports.JsLoaderState
159-
module.exports.JsRspackSeverity = __napiModule.exports.JsRspackSeverity
160-
module.exports.loadBrowserslist = __napiModule.exports.loadBrowserslist
161-
module.exports.minify = __napiModule.exports.minify
162-
module.exports.minifySync = __napiModule.exports.minifySync
163-
module.exports.RawJavascriptParserCommonjsExports = __napiModule.exports.RawJavascriptParserCommonjsExports
164-
module.exports.RawRuleSetConditionType = __napiModule.exports.RawRuleSetConditionType
165-
module.exports.registerGlobalTrace = __napiModule.exports.registerGlobalTrace
166-
module.exports.RegisterJsTapKind = __napiModule.exports.RegisterJsTapKind
167-
module.exports.sync = __napiModule.exports.sync
168-
module.exports.syncTraceEvent = __napiModule.exports.syncTraceEvent
169-
module.exports.transform = __napiModule.exports.transform
170-
module.exports.transformSync = __napiModule.exports.transformSync
111+

crates/rspack_binding_api/src/raw_options/raw_builtins/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ impl<'a> BuiltinPlugin<'a> {
503503
BuiltinPluginName::ModuleFederationRuntimePlugin => {
504504
let options = downcast_into::<RawModuleFederationRuntimePluginOptions>(self.options)
505505
.map_err(|report| napi::Error::from_reason(report.to_string()))?;
506+
if std::env::var("RSPACK_DEBUG_MF_ASYNC").is_ok() {
507+
eprintln!("[mf-async] raw runtime plugin opts: {:?}", options);
508+
}
506509
plugins.push(ModuleFederationRuntimePlugin::new(options.into()).boxed())
507510
}
508511
BuiltinPluginName::ModuleFederationManifestPlugin => {

crates/rspack_binding_api/src/raw_options/raw_builtins/raw_mf.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl From<RawProvideOptions> for (String, ProvideOptions) {
139139
pub struct RawConsumeSharedPluginOptions {
140140
pub consumes: Vec<RawConsumeOptions>,
141141
pub enhanced: bool,
142+
pub async_startup: Option<bool>,
142143
}
143144

144145
impl From<RawConsumeSharedPluginOptions> for ConsumeSharedPluginOptions {
@@ -151,6 +152,7 @@ impl From<RawConsumeSharedPluginOptions> for ConsumeSharedPluginOptions {
151152
.map(|(k, v)| (k, Arc::new(v)))
152153
.collect(),
153154
enhanced: value.enhanced,
155+
async_startup: value.async_startup.unwrap_or(false),
154156
}
155157
}
156158
}

crates/rspack_plugin_javascript/src/plugin/mod.rs

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ impl JsPlugin {
244244
let mut startup: Vec<Cow<str>> = Vec::new();
245245
let mut allow_inline_startup = true;
246246
let mut mf_async_startup = false;
247+
let mf_async_startup_flag =
248+
runtime_requirements.contains(RuntimeGlobals::ASYNC_FEDERATION_STARTUP);
247249
let supports_arrow_function = compilation
248250
.options
249251
.output
@@ -330,12 +332,20 @@ impl JsPlugin {
330332

331333
if !runtime_requirements.contains(RuntimeGlobals::STARTUP_NO_DEFAULT) {
332334
if chunk.has_entry_module(&compilation.chunk_graph) {
333-
let use_federation_async =
334-
runtime_requirements.contains(RuntimeGlobals::ASYNC_FEDERATION_STARTUP);
335+
let use_federation_async = mf_async_startup_flag;
336+
337+
if cfg!(debug_assertions) && mf_async_startup_flag {
338+
tracing::debug!(
339+
"render_startup async MF chunk={:?} has_entry_modules={} reqs={:?}",
340+
chunk_ukey,
341+
chunk.has_entry_module(&compilation.chunk_graph),
342+
runtime_requirements
343+
);
344+
}
335345

336346
if use_federation_async {
337347
let startup_fn = RuntimeGlobals::STARTUP_ENTRYPOINT;
338-
let needs_on_chunks_loaded =
348+
let _needs_on_chunks_loaded =
339349
runtime_requirements.contains(RuntimeGlobals::ON_CHUNKS_LOADED);
340350
mf_async_startup = true;
341351
let mut buf2: Vec<Cow<str>> = Vec::new();
@@ -353,7 +363,7 @@ impl JsPlugin {
353363
buf2.push("// Call federation runtime initialization".into());
354364
buf2.push("var runtimeInitialization = undefined;".into());
355365
buf2.push(format!("if (typeof {} === \"function\") {{", startup_fn).into());
356-
buf2.push(format!(" runtimeInitialization = {}();", startup_fn).into());
366+
buf2.push(format!(" runtimeInitialization = {};", startup_fn).into());
357367
buf2.push("} else {".into());
358368
buf2.push(
359369
format!(
@@ -488,7 +498,7 @@ impl JsPlugin {
488498
// ESM output with top-level await
489499
buf2.push(
490500
format!(
491-
"const {}Promise = Promise.resolve(runtimeInitialization).then(async () => {{",
501+
"const {}Promise = Promise.resolve().then(() => {{ return typeof runtimeInitialization === \"function\" ? runtimeInitialization() : runtimeInitialization; }}).then(() => {{ return typeof __webpack_require__.I === \"function\" ? __webpack_require__.I(\"default\") : undefined; }}).then(async () => {{",
492502
RuntimeGlobals::EXPORTS
493503
)
494504
.into(),
@@ -518,26 +528,22 @@ impl JsPlugin {
518528
buf2.push(format!(" return {};", entry_fn_body).into());
519529
}
520530
buf2.push("});".into());
521-
if needs_on_chunks_loaded {
522-
buf2.push(
523-
format!(
524-
"export default await {}Promise.then(res => {}(res));",
525-
RuntimeGlobals::EXPORTS,
526-
RuntimeGlobals::ON_CHUNKS_LOADED
527-
)
528-
.into(),
529-
);
530-
} else {
531-
buf2.push(
532-
format!("export default await {}Promise;", RuntimeGlobals::EXPORTS).into(),
533-
);
534-
}
531+
buf2.push("export default await ".into());
532+
buf2.push(
533+
format!(
534+
"{}Promise.then(res => typeof {} === \"function\" ? {}(res) : res);",
535+
RuntimeGlobals::EXPORTS,
536+
RuntimeGlobals::ON_CHUNKS_LOADED,
537+
RuntimeGlobals::ON_CHUNKS_LOADED
538+
)
539+
.into(),
540+
);
535541
} else {
536542
// CJS output with Promise chain
537-
buf2.push("// Wrap startup in Promise.all with federation handlers".into());
543+
buf2.push("// Wrap startup in Promise chain with federation handlers".into());
538544
buf2.push(
539545
format!(
540-
"var {} = Promise.resolve(runtimeInitialization).then(function() {{",
546+
"var {} = Promise.resolve().then(function() {{ return typeof runtimeInitialization === \"function\" ? runtimeInitialization() : runtimeInitialization; }}).then(function() {{ return typeof __webpack_require__.I === \"function\" ? __webpack_require__.I(\"default\") : undefined; }}).then(function() {{",
541547
RuntimeGlobals::EXPORTS
542548
)
543549
.into(),
@@ -571,23 +577,22 @@ impl JsPlugin {
571577
} else {
572578
buf2.push(format!(" return {};", entry_fn_body).into());
573579
}
574-
if needs_on_chunks_loaded {
575-
buf2.push(
576-
format!(
577-
"}}).then(function(res) {{ return {}(res); }});",
578-
RuntimeGlobals::ON_CHUNKS_LOADED
579-
)
580-
.into(),
581-
);
582-
} else {
583-
buf2.push("});".into());
584-
}
580+
buf2.push("}).then(function(res) {".into());
581+
buf2.push(
582+
format!(
583+
" return typeof {} === \"function\" ? {}(res) : res;",
584+
RuntimeGlobals::ON_CHUNKS_LOADED,
585+
RuntimeGlobals::ON_CHUNKS_LOADED
586+
)
587+
.into(),
588+
);
589+
buf2.push("});".into());
585590
}
586591
} else {
587-
buf2.push("// Wrap startup in Promise.all with federation handlers".into());
592+
buf2.push("// Wrap startup in Promise chain with federation handlers".into());
588593
buf2.push(
589594
format!(
590-
"var {} = Promise.resolve(runtimeInitialization).then(function() {{",
595+
"var {} = Promise.resolve().then(function() {{ return typeof runtimeInitialization === \"function\" ? runtimeInitialization() : runtimeInitialization; }}).then(function() {{ return typeof __webpack_require__.I === \"function\" ? __webpack_require__.I(\"default\") : undefined; }}).then(function() {{",
591596
RuntimeGlobals::EXPORTS
592597
)
593598
.into(),
@@ -621,6 +626,15 @@ impl JsPlugin {
621626
} else {
622627
buf2.push(format!(" return {};", entry_fn_body).into());
623628
}
629+
buf2.push("}).then(function(res) {".into());
630+
buf2.push(
631+
format!(
632+
" return typeof {} === \"function\" ? {}(res) : res;",
633+
RuntimeGlobals::ON_CHUNKS_LOADED,
634+
RuntimeGlobals::ON_CHUNKS_LOADED
635+
)
636+
.into(),
637+
);
624638
buf2.push("});".into());
625639
}
626640

@@ -1235,15 +1249,22 @@ impl JsPlugin {
12351249
startup_global
12361250
)));
12371251
result.add(RawStringSource::from(format!(
1238-
" runtimeInitialization = {}();\n",
1252+
" runtimeInitialization = {};\n",
12391253
startup_global
12401254
)));
12411255
result.add(RawStringSource::from("}\n"));
12421256
result.add(RawStringSource::from("var promises = [];\n"));
12431257
result.add(RawStringSource::from(format!(
1244-
"var {} = Promise.resolve(runtimeInitialization).then(function() {{\n",
1258+
"var {} = Promise.resolve().then(function() {{ return typeof runtimeInitialization === 'function' ? runtimeInitialization() : runtimeInitialization; }}).then(function() {{ return typeof __webpack_require__.I === 'function' ? __webpack_require__.I('default') : undefined; }}).then(function() {{\n",
12451259
RuntimeGlobals::EXPORTS.name()
12461260
)));
1261+
result.add(RawStringSource::from(
1262+
" if (__webpack_require__.federation && __webpack_require__.federation.bundlerRuntime && typeof __webpack_require__.federation.bundlerRuntime.flushInitialConsumes === 'function') {\n",
1263+
));
1264+
result.add(RawStringSource::from(
1265+
" __webpack_require__.federation.bundlerRuntime.flushInitialConsumes();\n",
1266+
));
1267+
result.add(RawStringSource::from(" }\n"));
12471268
result.add(RawStringSource::from(" var handlers = [\n"));
12481269
result.add(RawStringSource::from(" function(chunkId, promises) {\n"));
12491270
result.add(RawStringSource::from(" return (__webpack_require__.f.consumes || function(chunkId, promises) {})(chunkId, promises);\n"));

0 commit comments

Comments
 (0)