Skip to content
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
5 changes: 3 additions & 2 deletions crates/node_binding/rspack.wasi-browser.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions crates/node_binding/rspack.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions crates/node_binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
///
Expand Down
3 changes: 1 addition & 2 deletions crates/node_binding/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,7 @@ thread_local! {
pub(crate) static COMPILATION_HOOKS_MAP_SYMBOL: OnceCell<OneShotRef> = 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| {
Expand Down
Loading