Skip to content

Commit

Permalink
refactor: rename Rspack to JsCompiler (#9327)
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist authored Feb 17, 2025
1 parent 85a3aba commit 1da55ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ export declare class JsCompilation {
addInclude(args: [string, RawDependency, JsEntryOptions | undefined][], callback: (errMsg: Error | null, results: [string | null, JsModule][]) => void): void
}

export declare class JsCompiler {
constructor(compilerPath: string, options: RawOptions, builtinPlugins: Array<BuiltinPlugin>, registerJsTaps: RegisterJsTaps, outputFilesystem: ThreadsafeNodeFS, intermediateFilesystem: ThreadsafeNodeFS | undefined | null, resolverFactoryReference: JsResolverFactory)
setNonSkippableRegisters(kinds: Array<RegisterJsTapKind>): void
/** Build with the given option passed to the constructor */
build(callback: (err: null | Error) => void): void
/** Rebuild with the given option passed to the constructor */
rebuild(changed_files: string[], removed_files: string[], callback: (err: null | Error) => void): void
}

export declare class JsContextModuleFactoryAfterResolveData {
get resource(): string
set resource(resource: string)
Expand Down Expand Up @@ -288,15 +297,6 @@ export declare class RawExternalItemFnCtx {
getResolver(): JsResolver
}

export declare class Rspack {
constructor(compilerPath: string, options: RawOptions, builtinPlugins: Array<BuiltinPlugin>, registerJsTaps: RegisterJsTaps, outputFilesystem: ThreadsafeNodeFS, intermediateFilesystem: ThreadsafeNodeFS | undefined | null, resolverFactoryReference: JsResolverFactory)
setNonSkippableRegisters(kinds: Array<RegisterJsTapKind>): void
/** Build with the given option passed to the constructor */
build(callback: (err: null | Error) => void): void
/** Rebuild with the given option passed to the constructor */
rebuild(changed_files: string[], removed_files: string[], callback: (err: null | Error) => void): void
}

export interface BuiltinPlugin {
name: BuiltinPluginName
options: unknown
Expand Down
12 changes: 6 additions & 6 deletions crates/node_binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ use tracing_subscriber::EnvFilter;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt as _, Layer, Registry};

#[napi]
pub struct Rspack {
pub struct JsCompiler {
js_plugin: JsHooksAdapterPlugin,
compiler: Pin<Box<Compiler>>,
state: CompilerState,
}

#[napi]
impl Rspack {
impl JsCompiler {
#[allow(clippy::too_many_arguments)]
#[napi(constructor)]
pub fn new(
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Rspack {

/// Build with the given option passed to the constructor
#[napi(ts_args_type = "callback: (err: null | Error) => void")]
pub fn build(&mut self, env: Env, reference: Reference<Rspack>, f: Function) -> Result<()> {
pub fn build(&mut self, env: Env, reference: Reference<JsCompiler>, f: Function) -> Result<()> {
unsafe {
self.run(env, reference, |compiler, _guard| {
callbackify(env, f, async move {
Expand All @@ -135,7 +135,7 @@ impl Rspack {
pub fn rebuild(
&mut self,
env: Env,
reference: Reference<Rspack>,
reference: Reference<JsCompiler>,
changed_files: Vec<String>,
removed_files: Vec<String>,
f: Function,
Expand Down Expand Up @@ -166,7 +166,7 @@ impl Rspack {
}
}

impl Rspack {
impl JsCompiler {
/// Run the given function with the compiler.
///
/// ## Safety
Expand All @@ -176,7 +176,7 @@ impl Rspack {
unsafe fn run<R>(
&mut self,
env: Env,
reference: Reference<Rspack>,
reference: Reference<JsCompiler>,
f: impl FnOnce(&'static mut Compiler, CompilerStateGuard) -> Result<R>,
) -> Result<R> {
if self.state.running() {
Expand Down
6 changes: 3 additions & 3 deletions packages/rspack/src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface AssetEmittedInfo {
const COMPILATION_WEAK_MAP = new WeakMap<binding.JsCompilation, Compilation>();

class Compiler {
#instance?: binding.Rspack;
#instance?: binding.JsCompiler;
#initial: boolean;

#compilation?: Compilation;
Expand Down Expand Up @@ -793,7 +793,7 @@ class Compiler {
* Lazy initialize instance so it could access the changed options
*/
#getInstance(
callback: (error: Error | null, instance?: binding.Rspack) => void
callback: (error: Error | null, instance?: binding.JsCompiler) => void
): void {
const error = checkVersion();
if (error) {
Expand All @@ -814,7 +814,7 @@ class Compiler {

this.#registers = this.#createHooksRegisters();

this.#instance = new instanceBinding.Rspack(
this.#instance = new instanceBinding.JsCompiler(
this.compilerPath,
rawOptions,
this.#builtinPlugins,
Expand Down

2 comments on commit 1da55ac

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 1da55ac Feb 17, 2025

Choose a reason for hiding this comment

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

📝 Ecosystem CI detail: Open

suite result
modernjs ✅ success
rspress ✅ success
rslib ✅ success
rsbuild ❌ failure
rsdoctor ❌ failure
examples ✅ success
devserver ✅ success
nuxt ✅ success

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 1da55ac Feb 17, 2025

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 (2025-02-17 85a3aba) Current Change
10000_big_production-mode_disable-minimize + exec 38.9 s ± 489 ms 40 s ± 899 ms +2.88 %
10000_development-mode + exec 1.87 s ± 17 ms 1.88 s ± 129 ms +0.63 %
10000_development-mode_hmr + exec 704 ms ± 13 ms 693 ms ± 31 ms -1.61 %
10000_production-mode + exec 2.41 s ± 87 ms 2.37 s ± 92 ms -1.97 %
10000_production-mode_persistent-cold + exec 2.55 s ± 84 ms 2.47 s ± 19 ms -3.06 %
10000_production-mode_persistent-hot + exec 1.73 s ± 46 ms 1.68 s ± 51 ms -3.17 %
arco-pro_development-mode + exec 1.81 s ± 149 ms 1.78 s ± 177 ms -1.48 %
arco-pro_development-mode_hmr + exec 391 ms ± 0.83 ms 388 ms ± 3.1 ms -0.86 %
arco-pro_production-mode + exec 3.75 s ± 103 ms 3.72 s ± 89 ms -0.74 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.83 s ± 152 ms 3.74 s ± 62 ms -2.21 %
arco-pro_production-mode_persistent-cold + exec 3.86 s ± 131 ms 3.82 s ± 162 ms -1.15 %
arco-pro_production-mode_persistent-hot + exec 2.51 s ± 206 ms 2.41 s ± 28 ms -3.79 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.72 s ± 186 ms 3.72 s ± 133 ms +0.19 %
large-dyn-imports_development-mode + exec 2.1 s ± 68 ms 2.16 s ± 110 ms +2.60 %
large-dyn-imports_production-mode + exec 2.16 s ± 34 ms 2.2 s ± 24 ms +1.97 %
threejs_development-mode_10x + exec 1.6 s ± 42 ms 1.54 s ± 13 ms -3.34 %
threejs_development-mode_10x_hmr + exec 834 ms ± 28 ms 775 ms ± 39 ms -7.14 %
threejs_production-mode_10x + exec 5.49 s ± 238 ms 5.24 s ± 48 ms -4.55 %
threejs_production-mode_10x_persistent-cold + exec 5.59 s ± 373 ms 5.33 s ± 248 ms -4.65 %
threejs_production-mode_10x_persistent-hot + exec 4.72 s ± 222 ms 4.56 s ± 284 ms -3.43 %
10000_big_production-mode_disable-minimize + rss memory 8689 MiB ± 61.4 MiB 8698 MiB ± 46.2 MiB +0.10 %
10000_development-mode + rss memory 635 MiB ± 26.3 MiB 654 MiB ± 32.1 MiB +3.00 %
10000_development-mode_hmr + rss memory 1283 MiB ± 216 MiB 1332 MiB ± 266 MiB +3.82 %
10000_production-mode + rss memory 616 MiB ± 14.1 MiB 634 MiB ± 14.6 MiB +2.93 %
10000_production-mode_persistent-cold + rss memory 736 MiB ± 6.99 MiB 741 MiB ± 17.8 MiB +0.61 %
10000_production-mode_persistent-hot + rss memory 714 MiB ± 9.4 MiB 724 MiB ± 21.9 MiB +1.42 %
arco-pro_development-mode + rss memory 571 MiB ± 28.2 MiB 567 MiB ± 29.1 MiB -0.70 %
arco-pro_development-mode_hmr + rss memory 658 MiB ± 88.1 MiB 637 MiB ± 78.2 MiB -3.28 %
arco-pro_production-mode + rss memory 729 MiB ± 30.7 MiB 716 MiB ± 48.9 MiB -1.74 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 728 MiB ± 20.1 MiB 731 MiB ± 30.1 MiB +0.39 %
arco-pro_production-mode_persistent-cold + rss memory 854 MiB ± 16.2 MiB 850 MiB ± 27.6 MiB -0.51 %
arco-pro_production-mode_persistent-hot + rss memory 718 MiB ± 30.1 MiB 712 MiB ± 22.6 MiB -0.78 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 719 MiB ± 27.4 MiB 735 MiB ± 49.1 MiB +2.25 %
large-dyn-imports_development-mode + rss memory 641 MiB ± 7.68 MiB 644 MiB ± 4.6 MiB +0.42 %
large-dyn-imports_production-mode + rss memory 522 MiB ± 6.17 MiB 529 MiB ± 2.3 MiB +1.34 %
threejs_development-mode_10x + rss memory 548 MiB ± 15.1 MiB 555 MiB ± 17.6 MiB +1.18 %
threejs_development-mode_10x_hmr + rss memory 1179 MiB ± 36.7 MiB 1154 MiB ± 98.1 MiB -2.10 %
threejs_production-mode_10x + rss memory 834 MiB ± 32.9 MiB 828 MiB ± 54.7 MiB -0.71 %
threejs_production-mode_10x_persistent-cold + rss memory 955 MiB ± 69.6 MiB 948 MiB ± 71.8 MiB -0.79 %
threejs_production-mode_10x_persistent-hot + rss memory 862 MiB ± 42.4 MiB 851 MiB ± 20.8 MiB -1.36 %

Please sign in to comment.