From 1da55aca6bf303c11b931b465a6fd77ced4d8643 Mon Sep 17 00:00:00 2001 From: hardfist Date: Mon, 17 Feb 2025 11:01:54 +0800 Subject: [PATCH] refactor: rename Rspack to JsCompiler (#9327) --- crates/node_binding/binding.d.ts | 18 +++++++++--------- crates/node_binding/src/lib.rs | 12 ++++++------ packages/rspack/src/Compiler.ts | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 3608aa737463..c17d729553c5 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -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, registerJsTaps: RegisterJsTaps, outputFilesystem: ThreadsafeNodeFS, intermediateFilesystem: ThreadsafeNodeFS | undefined | null, resolverFactoryReference: JsResolverFactory) + setNonSkippableRegisters(kinds: Array): 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) @@ -288,15 +297,6 @@ export declare class RawExternalItemFnCtx { getResolver(): JsResolver } -export declare class Rspack { - constructor(compilerPath: string, options: RawOptions, builtinPlugins: Array, registerJsTaps: RegisterJsTaps, outputFilesystem: ThreadsafeNodeFS, intermediateFilesystem: ThreadsafeNodeFS | undefined | null, resolverFactoryReference: JsResolverFactory) - setNonSkippableRegisters(kinds: Array): 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 diff --git a/crates/node_binding/src/lib.rs b/crates/node_binding/src/lib.rs index 4bed566b0709..7a946961b7a2 100644 --- a/crates/node_binding/src/lib.rs +++ b/crates/node_binding/src/lib.rs @@ -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>, state: CompilerState, } #[napi] -impl Rspack { +impl JsCompiler { #[allow(clippy::too_many_arguments)] #[napi(constructor)] pub fn new( @@ -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, f: Function) -> Result<()> { + pub fn build(&mut self, env: Env, reference: Reference, f: Function) -> Result<()> { unsafe { self.run(env, reference, |compiler, _guard| { callbackify(env, f, async move { @@ -135,7 +135,7 @@ impl Rspack { pub fn rebuild( &mut self, env: Env, - reference: Reference, + reference: Reference, changed_files: Vec, removed_files: Vec, f: Function, @@ -166,7 +166,7 @@ impl Rspack { } } -impl Rspack { +impl JsCompiler { /// Run the given function with the compiler. /// /// ## Safety @@ -176,7 +176,7 @@ impl Rspack { unsafe fn run( &mut self, env: Env, - reference: Reference, + reference: Reference, f: impl FnOnce(&'static mut Compiler, CompilerStateGuard) -> Result, ) -> Result { if self.state.running() { diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index d3ca800d5e12..1f1376da9f9b 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -84,7 +84,7 @@ export interface AssetEmittedInfo { const COMPILATION_WEAK_MAP = new WeakMap(); class Compiler { - #instance?: binding.Rspack; + #instance?: binding.JsCompiler; #initial: boolean; #compilation?: Compilation; @@ -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) { @@ -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,