diff --git a/crates/node_binding/rspack.wasi-browser.js b/crates/node_binding/rspack.wasi-browser.js index b275c5f85bfb..ee7296df2330 100644 --- a/crates/node_binding/rspack.wasi-browser.js +++ b/crates/node_binding/rspack.wasi-browser.js @@ -1,8 +1,8 @@ import { - instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync, + createOnMessage as __wasmCreateOnMessageForFsProxy, getDefaultContext as __emnapiGetDefaultContext, + instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync, WASI as __WASI, - createOnMessage as __wasmCreateOnMessageForFsProxy, } from '@napi-rs/wasm-runtime' import { memfs } from '@napi-rs/wasm-runtime/fs' import __wasmUrl from './rspack.wasm32-wasi.wasm?url' @@ -60,6 +60,7 @@ const { } }, }) +export default __napiModule.exports export const Assets = __napiModule.exports.Assets export const AsyncDependenciesBlock = __napiModule.exports.AsyncDependenciesBlock export const BuildInfo = __napiModule.exports.BuildInfo diff --git a/crates/node_binding/rspack.wasi.cjs b/crates/node_binding/rspack.wasi.cjs index 725e60c22d11..de1d4e0cc209 100644 --- a/crates/node_binding/rspack.wasi.cjs +++ b/crates/node_binding/rspack.wasi.cjs @@ -9,9 +9,9 @@ const { WASI: __nodeWASI } = require('node:wasi') const { Worker } = require('node:worker_threads') const { - instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync, - getDefaultContext: __emnapiGetDefaultContext, createOnMessage: __wasmCreateOnMessageForFsProxy, + getDefaultContext: __emnapiGetDefaultContext, + instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync, } = require('@napi-rs/wasm-runtime') const __rootDir = __nodePath.parse(process.cwd()).root @@ -84,7 +84,7 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } }, }) - +module.exports = __napiModule.exports module.exports.Assets = __napiModule.exports.Assets module.exports.AsyncDependenciesBlock = __napiModule.exports.AsyncDependenciesBlock module.exports.BuildInfo = __napiModule.exports.BuildInfo diff --git a/crates/node_binding/src/lib.rs b/crates/node_binding/src/lib.rs index d512ef5c7c9b..e8ab437e4c11 100644 --- a/crates/node_binding/src/lib.rs +++ b/crates/node_binding/src/lib.rs @@ -9,7 +9,7 @@ extern crate rspack_allocator; use std::{cell::RefCell, sync::Arc}; use compiler::{Compiler, CompilerState, CompilerStateGuard}; -use napi::{bindgen_prelude::*, CallContext, JsObject}; +use napi::{bindgen_prelude::*, CallContext}; use rspack_collections::UkeyMap; use rspack_core::{ BoxDependency, Compilation, CompilerId, EntryOptions, ModuleIdentifier, PluginExt, @@ -478,12 +478,18 @@ pub fn cleanup_global_trace() { }); } -#[module_exports] -fn node_init(mut _exports: JsObject, env: Env) -> Result<()> { +fn node_init(mut _exports: Object, env: Env) -> Result<()> { rspack_core::set_thread_local_allocator(Box::new(allocator::NapiAllocatorImpl::new(env))); Ok(()) } +#[napi(module_exports)] +pub fn rspack_module_exports(exports: Object, env: Env) -> Result<()> { + node_init(exports, env)?; + module::init(exports, env)?; + Ok(()) +} + #[napi] /// Shutdown the tokio runtime manually. /// diff --git a/crates/node_binding/src/module.rs b/crates/node_binding/src/module.rs index 78ca8f014388..a762df117d6a 100644 --- a/crates/node_binding/src/module.rs +++ b/crates/node_binding/src/module.rs @@ -807,8 +807,7 @@ thread_local! { pub(crate) static COMPILATION_HOOKS_MAP_SYMBOL: OnceCell = Default::default(); } -#[module_exports] -fn init(mut exports: JsObject, env: Env) -> napi::Result<()> { +pub(super) fn init(mut exports: Object, env: Env) -> napi::Result<()> { let module_identifier_symbol = OneShotRef::new(env.raw(), env.create_symbol(None)?)?; exports.set_named_property("MODULE_IDENTIFIER_SYMBOL", &module_identifier_symbol)?; MODULE_IDENTIFIER_SYMBOL.with(|once_cell| {