diff --git a/.github/workflows/ci-rust.yaml b/.github/workflows/ci-rust.yaml index 1a0c23af47f1..5c07918e006e 100644 --- a/.github/workflows/ci-rust.yaml +++ b/.github/workflows/ci-rust.yaml @@ -120,6 +120,7 @@ jobs: --exclude rspack_node \ --exclude rspack_binding_builder \ --exclude rspack_binding_builder_macros \ + --exclude rspack_binding_builder_testing \ --exclude rspack_binding_build \ --exclude rspack_napi \ -- --nocapture diff --git a/.github/workflows/reusable-build-build.yml b/.github/workflows/reusable-build-build.yml index ce5bc930e824..927718763f2c 100644 --- a/.github/workflows/reusable-build-build.yml +++ b/.github/workflows/reusable-build-build.yml @@ -177,7 +177,7 @@ jobs: if: ${{ inputs.target == 'wasm32-wasip1-threads' }} run: | unset CC_x86_64_unknown_linux_gnu && unset CC # for jemallocator to compile - DISABLE_PLUGIN=1 RUST_TARGET=wasm32-wasip1-threads pnpm --filter @rspack/binding build:${{ inputs.profile }} + DISABLE_PLUGIN=1 RUST_TARGET=wasm32-wasip1-threads pnpm build:binding:${{ inputs.profile }} - name: Diff artifact run: | diff --git a/Cargo.lock b/Cargo.lock index fcfcbabe9ee2..4d85eaf95fc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4263,6 +4263,20 @@ dependencies = [ "syn 2.0.95", ] +[[package]] +name = "rspack_binding_builder_testing" +version = "0.2.0" +dependencies = [ + "napi", + "napi-derive", + "rspack_binding_build", + "rspack_binding_builder", + "rspack_binding_builder_macros", + "rspack_core", + "rspack_error", + "rspack_napi", +] + [[package]] name = "rspack_browserslist" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index effad41e61ef..536c1b491f17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -120,6 +120,7 @@ rspack_base64 = { version = "0.2.0", path = "crates/rsp rspack_binding_api = { version = "0.2.0", path = "crates/rspack_binding_api" } rspack_binding_build = { version = "0.2.0", path = "crates/rspack_binding_build" } rspack_binding_builder = { version = "0.2.0", path = "crates/rspack_binding_builder" } +rspack_binding_builder_macros = { version = "0.2.0", path = "crates/rspack_binding_builder_macros" } rspack_browserslist = { version = "0.2.0", path = "crates/rspack_browserslist" } rspack_builtin = { version = "0.2.0", path = "crates/rspack_builtin" } rspack_cacheable = { version = "0.2.0", path = "crates/rspack_cacheable" } diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 3c08919883db..f3cbc51a4609 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -10,6 +10,8 @@ export type RawLazyCompilationTest = RegExp | ((module: Module) => boolean); export type AssetInfo = KnownAssetInfo & Record; +export type CustomPluginName = string; + export const MODULE_IDENTIFIER_SYMBOL: unique symbol; export const COMPILATION_HOOKS_MAP_SYMBOL: unique symbol; @@ -439,7 +441,7 @@ export declare class Sources { } export interface BuiltinPlugin { - name: BuiltinPluginName + name: BuiltinPluginName | CustomPluginName options: unknown canInherentFromParent?: boolean } diff --git a/crates/node_binding/scripts/banner.d.ts b/crates/node_binding/scripts/banner.d.ts index 0b3df1420138..6d6502ab0576 100644 --- a/crates/node_binding/scripts/banner.d.ts +++ b/crates/node_binding/scripts/banner.d.ts @@ -10,6 +10,8 @@ export type RawLazyCompilationTest = RegExp | ((module: Module) => boolean); export type AssetInfo = KnownAssetInfo & Record; +export type CustomPluginName = string; + export const MODULE_IDENTIFIER_SYMBOL: unique symbol; export const COMPILATION_HOOKS_MAP_SYMBOL: unique symbol; diff --git a/crates/rspack_binding_api/src/raw_options/raw_builtins/mod.rs b/crates/rspack_binding_api/src/raw_options/raw_builtins/mod.rs index 361ffa4fcc93..651354e1376d 100644 --- a/crates/rspack_binding_api/src/raw_options/raw_builtins/mod.rs +++ b/crates/rspack_binding_api/src/raw_options/raw_builtins/mod.rs @@ -23,7 +23,7 @@ use std::cell::RefCell; use napi::{ bindgen_prelude::{FromNapiValue, JsObjectValue, Object}, - Env, Unknown, + Either, Env, Unknown, }; use napi_derive::napi; use raw_dll::{RawDllReferenceAgencyPluginOptions, RawFlagAllModulesAsUsedPluginOptions}; @@ -223,23 +223,22 @@ pub enum BuiltinPluginName { ModuleInfoHeaderPlugin, HttpUriPlugin, CssChunkingPlugin, - // Custom(String), } pub type CustomPluginBuilder = for<'a> fn(env: Env, options: Unknown<'a>) -> napi::Result; thread_local! { - static CUSTOMED_PLUGINS_CTOR: RefCell> = RefCell::new(HashMap::default()); + static CUSTOMED_PLUGINS_CTOR: RefCell> = RefCell::new(HashMap::default()); } #[doc(hidden)] #[allow(clippy::result_unit_err)] pub fn register_custom_plugin( - name: &'static str, + name: String, plugin_builder: CustomPluginBuilder, ) -> std::result::Result<(), ()> { - CUSTOMED_PLUGINS_CTOR.with_borrow_mut(|ctors| match ctors.entry(name.to_string()) { + CUSTOMED_PLUGINS_CTOR.with_borrow_mut(|ctors| match ctors.entry(name) { std::collections::hash_map::Entry::Occupied(_) => Err(()), std::collections::hash_map::Entry::Vacant(vacant_entry) => { vacant_entry.insert(plugin_builder); @@ -248,9 +247,11 @@ pub fn register_custom_plugin( }) } +type CustomPluginName = String; + #[napi(object)] pub struct BuiltinPlugin<'a> { - pub name: BuiltinPluginName, + pub name: Either, pub options: Unknown<'a>, pub can_inherent_from_parent: Option, } @@ -262,7 +263,20 @@ impl<'a> BuiltinPlugin<'a> { compiler_object: &mut Object, plugins: &mut Vec, ) -> napi::Result<()> { - match self.name { + let name = match self.name { + Either::A(name) => name, + Either::B(name) => { + CUSTOMED_PLUGINS_CTOR.with_borrow(|ctors| { + let ctor = ctors.get(&name).ok_or_else(|| { + napi::Error::from_reason(format!("Expected plugin installed '{name}'")) + })?; + plugins.push(ctor(env, self.options)?); + Ok::<_, napi::Error>(()) + })?; + return Ok(()); + } + }; + match name { // webpack also have these plugins BuiltinPluginName::DefinePlugin => { let plugin = DefinePlugin::new( @@ -762,15 +776,7 @@ impl<'a> BuiltinPlugin<'a> { let options = downcast_into::(self.options) .map_err(|report| napi::Error::from_reason(report.to_string()))?; plugins.push(CssChunkingPlugin::new(options.into()).boxed()); - } // BuiltinPluginName::Custom(ref name) => { - // CUSTOMED_PLUGINS_CTOR.with_borrow(|ctors| { - // let ctor = ctors.get(name).ok_or_else(|| { - // napi::Error::from_reason(format!("Expected plugin installed '{name}'")) - // })?; - // plugins.push(ctor(env, self.options)?); - // Ok::<_, napi::Error>(()) - // })?; - // } + } } Ok(()) } diff --git a/crates/rspack_binding_builder_macros/src/lib.rs b/crates/rspack_binding_builder_macros/src/lib.rs index 91f268abc5c0..3919ae3c67ab 100644 --- a/crates/rspack_binding_builder_macros/src/lib.rs +++ b/crates/rspack_binding_builder_macros/src/lib.rs @@ -1,49 +1,10 @@ -use proc_macro::TokenStream; -use proc_macro2::Span; -use quote::quote; -use syn::{ - parse::{Parse, ParseStream}, - parse_macro_input, Expr, Ident, LitStr, Token, -}; - -struct RegisterPluginInput { - name: LitStr, - _comma: Token![,], - plugin: Expr, -} +mod register_plugin; -impl Parse for RegisterPluginInput { - fn parse(input: ParseStream) -> syn::Result { - Ok(RegisterPluginInput { - name: input.parse()?, - _comma: input.parse()?, - plugin: input.parse()?, - }) - } -} +use proc_macro::TokenStream; +use syn::parse_macro_input; #[proc_macro] pub fn register_plugin(input: TokenStream) -> TokenStream { - let RegisterPluginInput { name, plugin, .. } = parse_macro_input!(input as RegisterPluginInput); - - let plugin_register_ident: Ident = - Ident::new(&format!("register_{}", name.value()), Span::call_site()); - - let expanded = quote! { - #[napi] - fn #plugin_register_ident() { - fn register<'a>( - env: Env, - options: Unknown<'a>, - ) -> Result { - (#plugin)(env, options) - } - match rspack_binding_builder::register_custom_plugin(#name, register as rspack_binding_builder::CustomPluginBuilder) { - Ok(_) => {} - Err(err) => panic!("Cannot register plugins under the same name"), - } - } - }; - - TokenStream::from(expanded) + let input = parse_macro_input!(input as register_plugin::RegisterPluginInput); + input.expand().into() } diff --git a/crates/rspack_binding_builder_macros/src/register_plugin.rs b/crates/rspack_binding_builder_macros/src/register_plugin.rs new file mode 100644 index 000000000000..cdbeaad8b392 --- /dev/null +++ b/crates/rspack_binding_builder_macros/src/register_plugin.rs @@ -0,0 +1,47 @@ +use proc_macro2::{Ident, Span, TokenStream}; +use quote::quote; +use syn::{ + parse::{Parse, ParseStream}, + Expr, LitStr, Token, +}; + +pub struct RegisterPluginInput { + name: LitStr, + plugin: Expr, +} + +impl Parse for RegisterPluginInput { + fn parse(input: ParseStream) -> syn::Result { + let name = input.parse()?; + ::parse(input)?; + let plugin = input.parse()?; + Ok(RegisterPluginInput { name, plugin }) + } +} + +impl RegisterPluginInput { + pub fn expand(self) -> TokenStream { + let RegisterPluginInput { name, plugin } = self; + + let plugin_register_ident: Ident = + Ident::new(&format!("register_{}", name.value()), Span::call_site()); + + let expanded = quote! { + #[napi] + fn #plugin_register_ident() -> napi::Result<()> { + fn register<'a>( + env: Env, + options: Unknown<'a>, + ) -> Result { + (#plugin)(env, options) + } + let name = #name.to_string(); + rspack_binding_builder::register_custom_plugin(name, register as rspack_binding_builder::CustomPluginBuilder).map_err(|e| { + napi::Error::from_reason(format!("Cannot register plugins under the same name: {}", #name)) + }) + } + }; + + expanded + } +} diff --git a/crates/rspack_binding_builder_testing/.gitignore b/crates/rspack_binding_builder_testing/.gitignore new file mode 100644 index 000000000000..41ca98c128b8 --- /dev/null +++ b/crates/rspack_binding_builder_testing/.gitignore @@ -0,0 +1,3 @@ +/*.node +/*.wasm +/*.d.ts \ No newline at end of file diff --git a/crates/rspack_binding_builder_testing/Cargo.toml b/crates/rspack_binding_builder_testing/Cargo.toml new file mode 100644 index 000000000000..35bd91a69dd8 --- /dev/null +++ b/crates/rspack_binding_builder_testing/Cargo.toml @@ -0,0 +1,32 @@ +[package] +description = "rspack node builder testing" +edition.workspace = true +license = "MIT" +name = "rspack_binding_builder_testing" +repository = "https://github.com/web-infra-dev/rspack" +version = "0.2.0" + +[lib] +crate-type = ["cdylib"] + + +[package.metadata.cargo-shear] +# `napi-derive` uses absolute path to `napi` +ignored = ["napi"] + +[features] +plugin = ["rspack_binding_builder/plugin"] + +[dependencies] +rspack_binding_builder = { workspace = true } +rspack_binding_builder_macros = { workspace = true } + +rspack_core = { workspace = true } +rspack_error = { workspace = true } +rspack_napi = { workspace = true } + +napi = { workspace = true, features = ["async", "tokio_rt", "serde-json", "anyhow", "napi7", "compat-mode"] } +napi-derive = { workspace = true, features = ["compat-mode"] } + +[build-dependencies] +rspack_binding_build = { workspace = true } diff --git a/crates/rspack_binding_builder_testing/binding.js b/crates/rspack_binding_builder_testing/binding.js new file mode 100644 index 000000000000..3a5b3c7da52c --- /dev/null +++ b/crates/rspack_binding_builder_testing/binding.js @@ -0,0 +1,231 @@ +const { existsSync } = require('fs') +const { join } = require('path') + +const { platform, arch } = process + +let nativeBinding = null +let localFileExisted = false +let loadError = null + +function isMusl() { + const { glibcVersionRuntime } = process.report.getReport().header + return !glibcVersionRuntime +} + +switch (platform) { + case 'android': + switch (arch) { + case 'arm64': + localFileExisted = existsSync(join(__dirname, 'rspack.android-arm64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.android-arm64.node') + } else { + nativeBinding = require('@rspack/binding-testing-android-arm64') + } + } catch (e) { + loadError = e + } + break + case 'arm': + localFileExisted = existsSync(join(__dirname, 'rspack.android-arm-eabi.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.android-arm-eabi.node') + } else { + nativeBinding = require('@rspack/binding-testing-android-arm-eabi') + } + } catch (e) { + loadError = e + } + break + default: + throw new Error(`Unsupported architecture on Android ${arch}`) + } + break + case 'win32': + switch (arch) { + case 'x64': + localFileExisted = existsSync(join(__dirname, 'rspack.win32-x64-msvc.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.win32-x64-msvc.node') + } else { + nativeBinding = require('@rspack/binding-testing-win32-x64-msvc') + } + } catch (e) { + loadError = e + } + break + case 'ia32': + localFileExisted = existsSync(join(__dirname, 'rspack.win32-ia32-msvc.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.win32-ia32-msvc.node') + } else { + nativeBinding = require('@rspack/binding-testing-win32-ia32-msvc') + } + } catch (e) { + loadError = e + } + break + case 'arm64': + localFileExisted = existsSync(join(__dirname, 'rspack.win32-arm64-msvc.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.win32-arm64-msvc.node') + } else { + nativeBinding = require('@rspack/binding-testing-win32-arm64-msvc') + } + } catch (e) { + loadError = e + } + break + default: + throw new Error(`Unsupported architecture on Windows: ${arch}`) + } + break + case 'darwin': + switch (arch) { + case 'x64': + localFileExisted = existsSync(join(__dirname, 'rspack.darwin-x64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.darwin-x64.node') + } else { + nativeBinding = require('@rspack/binding-testing-darwin-x64') + } + } catch (e) { + loadError = e + } + break + case 'arm64': + localFileExisted = existsSync(join(__dirname, 'rspack.darwin-arm64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.darwin-arm64.node') + } else { + nativeBinding = require('@rspack/binding-testing-darwin-arm64') + } + } catch (e) { + loadError = e + } + break + default: + throw new Error(`Unsupported architecture on macOS: ${arch}`) + } + break + case 'freebsd': + if (arch !== 'x64') { + throw new Error(`Unsupported architecture on FreeBSD: ${arch}`) + } + localFileExisted = existsSync(join(__dirname, 'rspack.freebsd-x64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.freebsd-x64.node') + } else { + nativeBinding = require('@rspack/binding-testing-freebsd-x64') + } + } catch (e) { + loadError = e + } + break + case 'linux': + switch (arch) { + case 'x64': + if (isMusl()) { + localFileExisted = existsSync(join(__dirname, 'rspack.linux-x64-musl.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.linux-x64-musl.node') + } else { + nativeBinding = require('@rspack/binding-testing-linux-x64-musl') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync(join(__dirname, 'rspack.linux-x64-gnu.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.linux-x64-gnu.node') + } else { + nativeBinding = require('@rspack/binding-testing-linux-x64-gnu') + } + } catch (e) { + loadError = e + } + } + break + case 'arm64': + if (isMusl()) { + localFileExisted = existsSync(join(__dirname, 'rspack.linux-arm64-musl.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.linux-arm64-musl.node') + } else { + nativeBinding = require('@rspack/binding-testing-linux-arm64-musl') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync(join(__dirname, 'rspack.linux-arm64-gnu.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.linux-arm64-gnu.node') + } else { + nativeBinding = require('@rspack/binding-testing-linux-arm64-gnu') + } + } catch (e) { + loadError = e + } + } + break + case 'arm': + localFileExisted = existsSync(join(__dirname, 'rspack.linux-arm-gnueabihf.node')) + try { + if (localFileExisted) { + nativeBinding = require('./rspack.linux-arm-gnueabihf.node') + } else { + nativeBinding = require('@rspack/binding-testing-linux-arm-gnueabihf') + } + } catch (e) { + loadError = e + } + break + default: + throw new Error(`Unsupported architecture on Linux: ${arch}`) + } + break + default: + throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) +} + +if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { + try { + nativeBinding = require('./rspack.wasi.cjs') + } catch (e) { + if (process.env.NAPI_RS_FORCE_WASI) { + loadError = e + } + } + if (!nativeBinding) { + try { + nativeBinding = require('@rspack/binding-testing-wasm32-wasi') + } catch (e) { + if (process.env.NAPI_RS_FORCE_WASI) { + loadError = e + } + } + } +} + +if (!nativeBinding) { + if (loadError) { + throw loadError + } + throw new Error(`Failed to load native binding`) +} + +module.exports.default = module.exports = nativeBinding diff --git a/crates/rspack_binding_builder_testing/build.rs b/crates/rspack_binding_builder_testing/build.rs new file mode 100644 index 000000000000..4d2c8891e045 --- /dev/null +++ b/crates/rspack_binding_builder_testing/build.rs @@ -0,0 +1,3 @@ +fn main() { + rspack_binding_build::setup(); +} diff --git a/crates/rspack_binding_builder_testing/package.json b/crates/rspack_binding_builder_testing/package.json new file mode 100644 index 000000000000..ffc306cc7940 --- /dev/null +++ b/crates/rspack_binding_builder_testing/package.json @@ -0,0 +1,53 @@ +{ + "name": "@rspack/binding-testing", + "version": "1.4.1", + "license": "MIT", + "description": "Node binding testing for rspack", + "main": "binding.js", + "types": "binding.d.ts", + "private": true, + "files": [ + "binding.js", + "binding.d.ts" + ], + "scripts": { + "build:dev": "node scripts/build.js", + "build:debug": "node scripts/build.js --profile release-debug", + "build:ci": "node scripts/build.js --profile ci", + "build:profiling": "node scripts/build.js --profile profiling", + "build:release": "node scripts/build.js --profile release" + }, + "homepage": "https://rspack.rs", + "bugs": "https://github.com/web-infra-dev/rspack/issues", + "repository": "web-infra-dev/rspack", + "devDependencies": { + "@napi-rs/cli": "3.0.0-alpha.88", + "@napi-rs/wasm-runtime": "^0.2.11", + "emnapi": "^1.4.3", + "typescript": "^5.8.3", + "@emnapi/core": "^1.4.3" + }, + "napi": { + "binaryName": "rspack", + "packageName": "@rspack/binding-testing", + "targets": [ + "x86_64-apple-darwin", + "x86_64-pc-windows-msvc", + "x86_64-unknown-linux-gnu", + "x86_64-unknown-linux-musl", + "x86_64-unknown-freebsd", + "i686-pc-windows-msvc", + "armv7-unknown-linux-gnueabihf", + "aarch64-unknown-linux-gnu", + "aarch64-apple-darwin", + "aarch64-unknown-linux-musl", + "aarch64-pc-windows-msvc" + ], + "wasm": { + "initialMemory": 16384, + "browser": { + "fs": true + } + } + } +} diff --git a/crates/rspack_binding_builder_testing/scripts/build.js b/crates/rspack_binding_builder_testing/scripts/build.js new file mode 100644 index 000000000000..ad2dcf5fb1fb --- /dev/null +++ b/crates/rspack_binding_builder_testing/scripts/build.js @@ -0,0 +1,63 @@ +const { positionals } = require("util").parseArgs({ + args: process.argv.slice(2), + options: { + profile: { + type: "string" + } + }, + strict: true, + allowPositionals: true +}); + +const { spawn } = require("child_process"); + +const CARGO_SAFELY_EXIT_CODE = 0; + +build().then((value) => { + // Regarding cargo's non-zero exit code as an error. + if (value !== CARGO_SAFELY_EXIT_CODE) { + process.exit(value); + } +}).catch(err => { + console.error(err); + process.exit(1); +}); + +async function build() { + return new Promise((resolve, reject) => { + let args = [ + "build", + "--platform", + "--no-js", + "--no-dts-header", + ]; + let features = []; + let envs = { ...process.env }; + + if (!process.env.DISABLE_PLUGIN) { + args.push("--no-default-features"); + features.push("plugin"); + } + args.push("--no-dts-cache"); + if (features.length) { + args.push("--features " + features.join(",")); + } + + if (positionals.length > 0) { + // napi need `--` to separate options and positional arguments. + args.push("--"); + args.push(...positionals); + } + + console.log(`Run command: napi ${args.join(" ")}`); + + let cp = spawn("napi", args, { + stdio: "inherit", + shell: true, + env: envs, + }); + + cp.on("error", reject); + cp.on("exit", resolve); + }); +} diff --git a/crates/rspack_binding_builder_testing/src/lib.rs b/crates/rspack_binding_builder_testing/src/lib.rs new file mode 100644 index 000000000000..d51ed8eb02ff --- /dev/null +++ b/crates/rspack_binding_builder_testing/src/lib.rs @@ -0,0 +1,32 @@ +#[macro_use] +extern crate napi_derive; +extern crate rspack_binding_builder; + +use rspack_binding_builder_macros::register_plugin; +use rspack_core::{ApplyContext, BoxPlugin, CompilerOptions, Plugin, PluginContext}; +use rspack_napi::{napi, napi::bindgen_prelude::*}; + +#[derive(Debug)] +#[allow(unused)] +struct BindingBuilderTestingPlugin; + +impl Plugin for BindingBuilderTestingPlugin { + fn apply( + &self, + _ctx: PluginContext<&mut ApplyContext>, + _options: &CompilerOptions, + ) -> rspack_error::Result<()> { + Ok(()) + } +} + +#[allow(unused)] +fn get_binding_plugin(_env: Env, options: Unknown<'_>) -> Result { + let options = options.coerce_to_object()?; + #[allow(clippy::disallowed_names, clippy::unwrap_used)] + let foo = options.get::("foo")?.unwrap(); + assert_eq!(foo, "bar".to_string()); + Ok(Box::new(BindingBuilderTestingPlugin) as BoxPlugin) +} + +register_plugin!("BindingBuilderTestingPlugin", get_binding_plugin); diff --git a/packages/rspack-test-tools/package.json b/packages/rspack-test-tools/package.json index 7f6903fd4c55..8f8c282604ad 100644 --- a/packages/rspack-test-tools/package.json +++ b/packages/rspack-test-tools/package.json @@ -72,6 +72,7 @@ "devDependencies": { "@rspack/cli": "workspace:*", "@rspack/core": "workspace:*", + "@rspack/binding-testing": "workspace:*", "@rspack/plugin-preact-refresh": "1.1.2", "@rspack/plugin-react-refresh": "^1.4.3", "@rspack/test-tools": "workspace:*", diff --git a/packages/rspack-test-tools/src/helper/setup-env.ts b/packages/rspack-test-tools/src/helper/setup-env.ts index 51ea46cd4239..39fe00bc7289 100644 --- a/packages/rspack-test-tools/src/helper/setup-env.ts +++ b/packages/rspack-test-tools/src/helper/setup-env.ts @@ -1,4 +1,13 @@ // @ts-nocheck +const path = require("node:path"); + +// Setup environment variable for binding testing +if (process.env.RSPACK_BINDING_BUILDER_TESTING) { + process.env.RSPACK_BINDING = path.resolve( + __dirname, + "../../node_modules/@rspack/binding-testing" + ); +} if (process.env.ALTERNATIVE_SORT) { const oldSort = Array.prototype.sort; diff --git a/packages/rspack-test-tools/tests/configCases/plugins/binding-builder-plugin/index.js b/packages/rspack-test-tools/tests/configCases/plugins/binding-builder-plugin/index.js new file mode 100644 index 000000000000..1554cd3b2352 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/plugins/binding-builder-plugin/index.js @@ -0,0 +1 @@ +it("should use createNativePlugin", () => {}); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/plugins/binding-builder-plugin/test.filter.js b/packages/rspack-test-tools/tests/configCases/plugins/binding-builder-plugin/test.filter.js new file mode 100644 index 000000000000..314d4ac4c725 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/plugins/binding-builder-plugin/test.filter.js @@ -0,0 +1,5 @@ +const enableBindingTesting = !!process.env.RSPACK_BINDING; + +module.exports = function (config) { + return enableBindingTesting +}; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/plugins/binding-builder-plugin/webpack.config.js b/packages/rspack-test-tools/tests/configCases/plugins/binding-builder-plugin/webpack.config.js new file mode 100644 index 000000000000..1da94120e5ef --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/plugins/binding-builder-plugin/webpack.config.js @@ -0,0 +1,19 @@ +/** @type {import("@rspack/core").experiments} */ +const experiments = require("@rspack/core").experiments; + +const binding = require(process.env.RSPACK_BINDING); +binding.registerBindingBuilderTestingPlugin(); + +const BindingBuilderTestingPlugin = experiments.createNativePlugin( + "BindingBuilderTestingPlugin", + options => options +); + +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + plugins: [ + new BindingBuilderTestingPlugin({ + foo: "bar" + }) + ] +}; diff --git a/packages/rspack/etc/core.api.md b/packages/rspack/etc/core.api.md index 941a3bd207c2..a91e5ae9ac96 100644 --- a/packages/rspack/etc/core.api.md +++ b/packages/rspack/etc/core.api.md @@ -378,7 +378,7 @@ type BannerFunction = (args: { // @public (undocumented) export const BannerPlugin: { new (args: BannerPluginArgument): { - name: BuiltinPluginName; + name: string; _args: [args: BannerPluginArgument]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -1604,7 +1604,7 @@ type ContextModuleFactoryBeforeResolveResult = false | ContextModuleFactoryBefor // @public (undocumented) export const ContextReplacementPlugin: { new (resourceRegExp: RegExp, newContentResource?: any, newContentRecursive?: any, newContentRegExp?: any): { - name: BuiltinPluginName; + name: string; _args: [resourceRegExp: RegExp, newContentResource?: any, newContentRecursive?: any, newContentRegExp?: any]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -1623,7 +1623,7 @@ interface ContinueStatement extends Node_4, HasSpan { // @public (undocumented) export const CopyRspackPlugin: { new (copy: CopyRspackPluginOptions): { - name: BuiltinPluginName; + name: string; _args: [copy: CopyRspackPluginOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -1639,6 +1639,17 @@ export type CopyRspackPluginOptions = { // @public (undocumented) type CreateData = Partial; +// @public +function createNativePlugin(name: CustomPluginName, resolve: (this: Compiler, ...args: T) => R, affectedHooks?: AffectedHooks): { + new (...args: T): { + name: string; + _args: T; + affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; + raw(compiler: Compiler): binding.BuiltinPlugin; + apply(compiler: Compiler): void; + }; +}; + // @public (undocumented) type CreateStatsOptionsContext = KnownCreateStatsOptionsContext & Record; @@ -1665,7 +1676,7 @@ export type CssChunkFilename = Filename; // @public (undocumented) const CssChunkingPlugin: { new (options?: CssChunkingPluginOptions | undefined): { - name: binding.BuiltinPluginName; + name: string; _args: [options?: CssChunkingPluginOptions | undefined]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): binding.BuiltinPlugin; @@ -1777,6 +1788,9 @@ export type CssParserOptions = { // @public (undocumented) export type CssParserUrl = boolean; +// @public (undocumented) +type CustomPluginName = string; + // @public (undocumented) interface DebuggerStatement extends Node_4, HasSpan { // (undocumented) @@ -1800,7 +1814,7 @@ type DefaultDecl = ClassExpression | FunctionExpression | TsInterfaceDeclaration // @public (undocumented) export const DefinePlugin: { new (define: DefinePluginOptions): { - name: BuiltinPluginName; + name: string; _args: [define: DefinePluginOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -2093,7 +2107,7 @@ export const electron: Electron; // @public (undocumented) const ElectronTargetPlugin: { new (context?: string | undefined): { - name: BuiltinPluginName; + name: string; _args: [context?: string | undefined]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -2120,7 +2134,7 @@ class EnableChunkLoadingPlugin extends EnableChunkLoadingPluginInner { // @public (undocumented) const EnableChunkLoadingPluginInner: { new (type: string): { - name: BuiltinPluginName; + name: string; _args: [type: string]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler): BuiltinPlugin; @@ -2153,7 +2167,7 @@ class EnableLibraryPlugin extends RspackBuiltinPlugin { // @public (undocumented) const EnableWasmLoadingPlugin: { new (type: string): { - name: BuiltinPluginName; + name: string; _args: [type: string]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -2391,7 +2405,7 @@ interface Etag { // @public (undocumented) export const EvalDevToolModulePlugin: { new (options: EvalDevToolModulePluginOptions): { - name: BuiltinPluginName; + name: string; _args: [options: EvalDevToolModulePluginOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -2404,7 +2418,7 @@ export { EvalDevToolModulePluginOptions } // @public (undocumented) export const EvalSourceMapDevToolPlugin: { new (options: SourceMapDevToolPluginOptions): { - name: BuiltinPluginName; + name: string; _args: [options: SourceMapDevToolPluginOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -2493,6 +2507,8 @@ export const experiments: Experiments_2; // @public (undocumented) interface Experiments_2 { + // (undocumented) + createNativePlugin: typeof createNativePlugin; // (undocumented) CssChunkingPlugin: typeof CssChunkingPlugin; // (undocumented) @@ -2781,7 +2797,7 @@ export type Falsy = false | "" | 0 | null | undefined; // @public (undocumented) const FetchCompileAsyncWasmPlugin: { new (): { - name: BuiltinPluginName; + name: string; _args: []; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -3109,7 +3125,7 @@ type HtmlRspackPluginHooks = { // @public (undocumented) const HtmlRspackPluginImpl: { new (c?: HtmlRspackPluginOptions | undefined): { - name: BuiltinPluginName; + name: string; _args: [c?: HtmlRspackPluginOptions | undefined]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler): BuiltinPlugin; @@ -3213,7 +3229,7 @@ interface IfStatement extends Node_4, HasSpan { // @public (undocumented) export const IgnorePlugin: { new (options: IgnorePluginOptions): { - name: BuiltinPluginName; + name: string; _args: [options: IgnorePluginOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -4287,7 +4303,7 @@ export type LightningcssLoaderOptions = { // @public (undocumented) export const LightningCssMinimizerRspackPlugin: { new (options?: LightningCssMinimizerRspackPluginOptions | undefined): { - name: BuiltinPluginName; + name: string; _args: [options?: LightningCssMinimizerRspackPluginOptions | undefined]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -4324,7 +4340,7 @@ type LimitChunkCountOptions = { // @public (undocumented) const LimitChunkCountPlugin: { new (options: LimitChunkCountOptions): { - name: BuiltinPluginName; + name: string; _args: [options: LimitChunkCountOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -4980,7 +4996,7 @@ interface NamedImportSpecifier extends Node_4, HasSpan { // @internal const NativeSubresourceIntegrityPlugin: { new (options: NativeSubresourceIntegrityPluginOptions): { - name: BuiltinPluginName; + name: string; _args: [options: NativeSubresourceIntegrityPluginOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler): BuiltinPlugin; @@ -5062,7 +5078,7 @@ export type NodeOptions = { // @public (undocumented) const NodeTargetPlugin: { new (): { - name: BuiltinPluginName; + name: string; _args: []; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -5085,7 +5101,7 @@ type NodeTemplatePluginOptions = { // @public (undocumented) export const NoEmitOnErrorsPlugin: { new (): { - name: BuiltinPluginName; + name: string; _args: []; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -5364,7 +5380,7 @@ interface Options extends Config_2 { // @public const OriginEntryPlugin: { new (context: string, entry: string, options?: string | EntryOptions | undefined): { - name: BuiltinPluginName; + name: string; _args: [context: string, entry: string, options?: string | EntryOptions | undefined]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -5731,7 +5747,7 @@ type Program = Module_2 | Script; // @public (undocumented) export const ProgressPlugin: { new (progress?: ProgressPluginArgument): { - name: BuiltinPluginName; + name: string; _args: [progress?: ProgressPluginArgument]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -5757,7 +5773,7 @@ type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropNa // @public (undocumented) export const ProvidePlugin: { new (provide: ProvidePluginOptions): { - name: BuiltinPluginName; + name: string; _args: [provide: ProvidePluginOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -6071,7 +6087,7 @@ export type RemotesObject = { // @public (undocumented) const RemoveDuplicateModulesPlugin: { new (): { - name: BuiltinPluginName; + name: string; _args: []; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -6251,7 +6267,7 @@ export type RsdoctorPluginHooks = { // @public (undocumented) const RsdoctorPluginImpl: { new (c?: RsdoctorPluginOptions | undefined): { - name: BuiltinPluginName; + name: string; _args: [c?: RsdoctorPluginOptions | undefined]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler): BuiltinPlugin; @@ -6268,7 +6284,7 @@ type RsdoctorPluginOptions = { // @public (undocumented) const RslibPlugin: { new (rslib: RawRslibPluginOptions): { - name: BuiltinPluginName; + name: string; _args: [rslib: RawRslibPluginOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -6312,7 +6328,7 @@ abstract class RspackBuiltinPlugin implements RspackPluginInstance { // (undocumented) apply(compiler: Compiler): void; // (undocumented) - abstract name: binding.BuiltinPluginName; + abstract name: binding.BuiltinPluginName | CustomPluginName; // (undocumented) abstract raw(compiler: Compiler): binding.BuiltinPlugin | undefined; } @@ -6813,7 +6829,7 @@ export const rspackVersion: string; // @public (undocumented) const RstestPlugin: { new (rstest: RawRstestPluginOptions): { - name: BuiltinPluginName; + name: string; _args: [rstest: RawRstestPluginOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -6903,7 +6919,7 @@ export type RuleSetUseItem = RuleSetLoader | RuleSetLoaderWithOptions; // @public (undocumented) const RuntimeChunkPlugin: { new (options: RawRuntimeChunkOptions): { - name: BuiltinPluginName; + name: string; _args: [options: RawRuntimeChunkOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -7052,7 +7068,7 @@ type RuntimePluginHooks = { // @public (undocumented) const RuntimePluginImpl: { new (): { - name: binding.BuiltinPluginName; + name: string; _args: []; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): binding.BuiltinPlugin; @@ -7272,7 +7288,7 @@ interface SourceMap { // @public (undocumented) export const SourceMapDevToolPlugin: { new (options: SourceMapDevToolPluginOptions): { - name: BuiltinPluginName; + name: string; _args: [options: SourceMapDevToolPluginOptions]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -7669,7 +7685,7 @@ interface SuperPropExpression extends ExpressionBase { // @public (undocumented) export const SwcJsMinimizerRspackPlugin: { new (options?: SwcJsMinimizerRspackPluginOptions | undefined): { - name: BuiltinPluginName; + name: string; _args: [options?: SwcJsMinimizerRspackPluginOptions | undefined]; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; @@ -8972,7 +8988,7 @@ export const version: string; // @public (undocumented) export const WarnCaseSensitiveModulesPlugin: { new (): { - name: BuiltinPluginName; + name: string; _args: []; affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; raw(compiler: Compiler_2): BuiltinPlugin; diff --git a/packages/rspack/package.json b/packages/rspack/package.json index 16fc527012a9..b7a1fb5e292c 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -22,9 +22,10 @@ }, "scripts": { "prepare": "prebundle && node ./move-tinypool.js", - "build": "rslib build && npm run prepare-container-runtime", + "build": "rslib build && npm run prepare-container-runtime && npm run codmod", "dev": "rslib build --watch", "prepare-container-runtime": "node ./scripts/prepare-container-runtime.js", + "codmod": "node ./scripts/codmod/index.js", "doc-coverage": "tsx ./scripts/check-documentation-coverage.ts", "api-extractor": "api-extractor run --verbose", "api-extractor:ci": "api-extractor run --verbose || diff temp/core.api.md etc/core.api.md" @@ -46,6 +47,7 @@ "directory": "packages/rspack" }, "devDependencies": { + "@ast-grep/napi": "^0.37.0", "@rslib/core": "0.10.0", "@swc/core": "1.12.0", "@swc/types": "0.1.22", diff --git a/packages/rspack/scripts/codmod/binding.js b/packages/rspack/scripts/codmod/binding.js new file mode 100644 index 000000000000..8dcf2e69bc31 --- /dev/null +++ b/packages/rspack/scripts/codmod/binding.js @@ -0,0 +1,19 @@ +/** + * Replaces `@rspack/binding` to code that reads env `RSPACK_BINDING` as the custom binding. + */ +function replaceBinding(root) { + const binding = root.find(`module.exports = require("@rspack/binding");`); + const bindingPkg = root.find( + `module.exports = require("@rspack/binding/package.json");` + ); + return [ + binding.replace( + `module.exports = require(process.env.RSPACK_BINDING ? process.env.RSPACK_BINDING : "@rspack/binding");` + ), + bindingPkg.replace( + `module.exports = require(process.env.RSPACK_BINDING ? require("node:path").resolve(process.env.RSPACK_BINDING, './package.json') : "@rspack/binding/package.json");` + ) + ]; +} + +exports.replaceBinding = replaceBinding; diff --git a/packages/rspack/scripts/codmod/index.js b/packages/rspack/scripts/codmod/index.js new file mode 100644 index 000000000000..421321f62f9c --- /dev/null +++ b/packages/rspack/scripts/codmod/index.js @@ -0,0 +1,15 @@ +const path = require("node:path"); +const fs = require("node:fs"); +const { parse, Lang } = require("@ast-grep/napi"); + +const dist = fs.readFileSync( + require.resolve(path.resolve(__dirname, "../../dist/index.js")), + "utf-8" +); +const root = parse(Lang.JavaScript, dist).root(); +const edits = [...require("./binding").replaceBinding(root)]; + +fs.writeFileSync( + require.resolve(path.resolve(__dirname, "../../dist/index.js")), + root.commitEdits(edits) +); diff --git a/packages/rspack/src/builtin-plugin/base.ts b/packages/rspack/src/builtin-plugin/base.ts index 70a131ab6fdd..aaaca3279f3f 100644 --- a/packages/rspack/src/builtin-plugin/base.ts +++ b/packages/rspack/src/builtin-plugin/base.ts @@ -1,4 +1,4 @@ -import type * as binding from "@rspack/binding"; +import * as binding from "@rspack/binding"; import type { Compiler, RspackPluginInstance } from ".."; @@ -24,7 +24,7 @@ export function canInherentFromParent(affectedHooks?: AffectedHooks): boolean { export abstract class RspackBuiltinPlugin implements RspackPluginInstance { abstract raw(compiler: Compiler): binding.BuiltinPlugin | undefined; - abstract name: binding.BuiltinPluginName; + abstract name: binding.BuiltinPluginName | CustomPluginName; affectedHooks?: AffectedHooks; apply(compiler: Compiler) { @@ -37,7 +37,7 @@ export abstract class RspackBuiltinPlugin implements RspackPluginInstance { } export function createBuiltinPlugin( - name: binding.BuiltinPluginName, + name: binding.BuiltinPluginName | CustomPluginName, options: R ): binding.BuiltinPlugin { return { @@ -46,8 +46,10 @@ export function createBuiltinPlugin( }; } +type CustomPluginName = string; + export function create( - name: binding.BuiltinPluginName, + name: binding.BuiltinPluginName | CustomPluginName, resolve: (this: Compiler, ...args: T) => R, // `affectedHooks` is used to inform `createChildCompile` about which builtin plugin can be reserved. // However, this has a drawback as it doesn't represent the actual condition but merely serves as an indicator. @@ -74,3 +76,32 @@ export function create( return Plugin; } + +const INTERNAL_PLUGIN_NAMES = Object.keys(binding.BuiltinPluginName); + +/** + * Create a wrapper class for builtin plugin. + * + * @example + * ```js + * const MyPlugin = createNativePlugin("MyPlugin", (options) => { + * return options; + * }); + * + * new MyPlugin({ + * foo: "bar" + * }).apply(compiler); + * ``` + */ +export function createNativePlugin( + name: CustomPluginName, + resolve: (this: Compiler, ...args: T) => R, + affectedHooks?: AffectedHooks +) { + if (INTERNAL_PLUGIN_NAMES.includes(name)) { + throw new Error( + `Cannot register native plugin with name '${name}', it conflicts with internal plugin names.` + ); + } + return create(name, resolve, affectedHooks); +} diff --git a/packages/rspack/src/builtin-plugin/index.ts b/packages/rspack/src/builtin-plugin/index.ts index 2133386d3767..d14668477209 100644 --- a/packages/rspack/src/builtin-plugin/index.ts +++ b/packages/rspack/src/builtin-plugin/index.ts @@ -1,4 +1,4 @@ -export { RspackBuiltinPlugin } from "./base"; +export { RspackBuiltinPlugin, createNativePlugin } from "./base"; export * from "./APIPlugin"; export * from "./ArrayPushCallbackChunkFormatPlugin"; diff --git a/packages/rspack/src/exports.ts b/packages/rspack/src/exports.ts index 9bfb1d96fa8a..25834a9b8efb 100644 --- a/packages/rspack/src/exports.ts +++ b/packages/rspack/src/exports.ts @@ -337,6 +337,7 @@ import { registerGlobalTrace, syncTraceEvent } from "@rspack/binding"; +import { createNativePlugin } from "./builtin-plugin"; import { JavaScriptTracer } from "./trace"; ///// Experiments SWC ///// @@ -364,6 +365,7 @@ interface Experiments { minifySync: typeof minifySync; }; CssChunkingPlugin: typeof CssChunkingPlugin; + createNativePlugin: typeof createNativePlugin; } export const experiments: Experiments = { @@ -407,5 +409,6 @@ export const experiments: Experiments = { minifySync, transformSync }, - CssChunkingPlugin + CssChunkingPlugin, + createNativePlugin }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3970b538f648..d9e827fda6f8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -129,6 +129,24 @@ importers: specifier: workspace:* version: link:../../npm/win32-x64-msvc + crates/rspack_binding_builder_testing: + devDependencies: + '@emnapi/core': + specifier: ^1.4.3 + version: 1.4.3 + '@napi-rs/cli': + specifier: 3.0.0-alpha.88 + version: 3.0.0-alpha.88(@emnapi/runtime@1.4.3)(@types/node@20.19.0)(emnapi@1.4.3) + '@napi-rs/wasm-runtime': + specifier: ^0.2.11 + version: 0.2.11 + emnapi: + specifier: ^1.4.3 + version: 1.4.3 + typescript: + specifier: ^5.8.3 + version: 5.8.3 + npm/darwin-arm64: {} npm/darwin-x64: {} @@ -295,6 +313,9 @@ importers: specifier: '>=0.5.1' version: 0.5.17 devDependencies: + '@ast-grep/napi': + specifier: ^0.37.0 + version: 0.37.0 '@rslib/core': specifier: 0.10.0 version: 0.10.0(@microsoft/api-extractor@7.52.8(@types/node@20.19.0))(typescript@5.8.3) @@ -483,6 +504,9 @@ importers: specifier: 3.3.2 version: 3.3.2(patch_hash=488e04e10706980da34067f6ad8c408b1eb45e65c49685929419ebb9abf9b96e) devDependencies: + '@rspack/binding-testing': + specifier: workspace:* + version: link:../../crates/rspack_binding_builder_testing '@rspack/cli': specifier: workspace:* version: link:../rspack-cli @@ -771,7 +795,7 @@ importers: version: 3.43.0 css-loader: specifier: ^7.1.2 - version: 7.1.2(@rspack/core@1.4.0(@swc/helpers@0.5.17))(webpack@5.99.9(@swc/core@1.12.0(@swc/helpers@0.5.17))) + version: 7.1.2(@rspack/core@1.4.1(@swc/helpers@0.5.17))(webpack@5.99.9(@swc/core@1.12.0(@swc/helpers@0.5.17))) date-fns: specifier: ^4.1.0 version: 4.1.0 @@ -2549,13 +2573,13 @@ packages: cpu: [arm64] os: [darwin] - '@rspack/binding-darwin-arm64@1.4.0': - resolution: {integrity: sha512-fOvbe71PAu9mM4f9KYssielLlTaQ0RcaS6fARkOuQRS3HfmZnAcMJA9kDkMAWBdsHQSW2RPHLji0Ng7lumAFvg==} + '@rspack/binding-darwin-arm64@1.4.0-beta.0': + resolution: {integrity: sha512-PQMH8mBQP8Auqw9vpoZp2Q9NbAa8yzqQ6MOq0f1NeV3XKx+Yyq6UPzMRAWcZjLK14JwQiKoSj06GBY4yN4fSGw==} cpu: [arm64] os: [darwin] - '@rspack/binding-darwin-arm64@1.4.0-beta.0': - resolution: {integrity: sha512-PQMH8mBQP8Auqw9vpoZp2Q9NbAa8yzqQ6MOq0f1NeV3XKx+Yyq6UPzMRAWcZjLK14JwQiKoSj06GBY4yN4fSGw==} + '@rspack/binding-darwin-arm64@1.4.1': + resolution: {integrity: sha512-enh5DYbpaexdEmjbcxj3BJDauP3w+20jFKWvKROtAQV350PUw0bf2b4WOgngIH9hBzlfjpXNYAk6T5AhVAlY3Q==} cpu: [arm64] os: [darwin] @@ -2564,13 +2588,13 @@ packages: cpu: [x64] os: [darwin] - '@rspack/binding-darwin-x64@1.4.0': - resolution: {integrity: sha512-1U7u5LdB+FwC90i3U9WDNeQoD8xoCfQBZPI0M6nB8pBCLW3HIP6Lzd60hTSKPuWOW6ZuXroUGoRG0z/ba8QlNg==} + '@rspack/binding-darwin-x64@1.4.0-beta.0': + resolution: {integrity: sha512-ydBmcIDHNOrrmyHV1sdYUdFbRlgijTEl6j5f1eD1r2t+KIDdFf1NqBcMVQ+1j93RxU4I54EI+ZbxYhy8heME9g==} cpu: [x64] os: [darwin] - '@rspack/binding-darwin-x64@1.4.0-beta.0': - resolution: {integrity: sha512-ydBmcIDHNOrrmyHV1sdYUdFbRlgijTEl6j5f1eD1r2t+KIDdFf1NqBcMVQ+1j93RxU4I54EI+ZbxYhy8heME9g==} + '@rspack/binding-darwin-x64@1.4.1': + resolution: {integrity: sha512-KoehyhBji4TLXhn4mqOUw6xsQNRzNVA9XcCm1Jx+M1Qb0dhMTNfduvBSyXuRV5+/QaRbk7+4UJbyRNFUtt96kA==} cpu: [x64] os: [darwin] @@ -2579,13 +2603,13 @@ packages: cpu: [arm64] os: [linux] - '@rspack/binding-linux-arm64-gnu@1.4.0': - resolution: {integrity: sha512-XYOfmHDYo88jruqAtyjklTqrNeixigP2QjsiZDiB0YvRQyaoLTw3hZ7RvhJbVruxFibwF75yiMlMD9LJgDTxrg==} + '@rspack/binding-linux-arm64-gnu@1.4.0-beta.0': + resolution: {integrity: sha512-tzLHo5upqlDWK3wSTit0m0iZ8N6pm6S42R/sfeOcPwERcTjhTrbQ6GOEbmwsay845EgzJbGWwaOzVeGLT55YCw==} cpu: [arm64] os: [linux] - '@rspack/binding-linux-arm64-gnu@1.4.0-beta.0': - resolution: {integrity: sha512-tzLHo5upqlDWK3wSTit0m0iZ8N6pm6S42R/sfeOcPwERcTjhTrbQ6GOEbmwsay845EgzJbGWwaOzVeGLT55YCw==} + '@rspack/binding-linux-arm64-gnu@1.4.1': + resolution: {integrity: sha512-PJ5cHqvrj1bK7jH5DVrdKoR8Fy+p6l9baxXajq/6xWTxP+4YTdEtLsRZnpLMS1Ho2RRpkxDWJn+gdlKuleNioQ==} cpu: [arm64] os: [linux] @@ -2594,13 +2618,13 @@ packages: cpu: [arm64] os: [linux] - '@rspack/binding-linux-arm64-musl@1.4.0': - resolution: {integrity: sha512-IvQNw3wN5Dro1CeT4f95W7R/ZAKREcsf9s0Kqk4NtBhaPxcEf+nV72mMDBzPUakEI/g32e5Evb91w3y0EFWhIg==} + '@rspack/binding-linux-arm64-musl@1.4.0-beta.0': + resolution: {integrity: sha512-g3YZCNB+oR8+CG83iOoACZrxiM9sKlB33QmJB2PFk5TTryhkNGEq3vwiyqe7AVPWYfuCCqoRdzPNzWBIN80cEg==} cpu: [arm64] os: [linux] - '@rspack/binding-linux-arm64-musl@1.4.0-beta.0': - resolution: {integrity: sha512-g3YZCNB+oR8+CG83iOoACZrxiM9sKlB33QmJB2PFk5TTryhkNGEq3vwiyqe7AVPWYfuCCqoRdzPNzWBIN80cEg==} + '@rspack/binding-linux-arm64-musl@1.4.1': + resolution: {integrity: sha512-cpDz+z3FwVQfK6VYfXQEb0ym6fFIVmvK4y3R/2VAbVGWYVxZB5I6AcSdOWdDnpppHmcHpf+qQFlwhHvbpMMJNQ==} cpu: [arm64] os: [linux] @@ -2609,13 +2633,13 @@ packages: cpu: [x64] os: [linux] - '@rspack/binding-linux-x64-gnu@1.4.0': - resolution: {integrity: sha512-b71w0Iflh/7gvwrpdfJYC4FsCb84mQen3YDYtiBF7VWdXKTN5OzWoibX/3i68l3HBncCf0vmWRr9XFrdejEZEg==} + '@rspack/binding-linux-x64-gnu@1.4.0-beta.0': + resolution: {integrity: sha512-TNIm9APDmcbbrwWgSxaIbq73r0cKrzyS0Ei7rB0TyX9EmFYSfsCdmdJMwG2yKP3p+egRIDMWU9AIrxL4HIMrBg==} cpu: [x64] os: [linux] - '@rspack/binding-linux-x64-gnu@1.4.0-beta.0': - resolution: {integrity: sha512-TNIm9APDmcbbrwWgSxaIbq73r0cKrzyS0Ei7rB0TyX9EmFYSfsCdmdJMwG2yKP3p+egRIDMWU9AIrxL4HIMrBg==} + '@rspack/binding-linux-x64-gnu@1.4.1': + resolution: {integrity: sha512-jjTx53CpiYWK7fAv5qS8xHEytFK6gLfZRk+0kt2YII6uqez/xQ3SRcboreH8XbJcBoxINBzMNMf5/SeMBZ939A==} cpu: [x64] os: [linux] @@ -2624,18 +2648,18 @@ packages: cpu: [x64] os: [linux] - '@rspack/binding-linux-x64-musl@1.4.0': - resolution: {integrity: sha512-aGanEWtYRBiuS6RdI3rOwcV/tetq5duyYRmm/i1RoGAyfGp7vtoPpKVl7PP/hODWp3lZ9PVn3FhxsEaV7LY36Q==} + '@rspack/binding-linux-x64-musl@1.4.0-beta.0': + resolution: {integrity: sha512-PCfGShh6y0CqUX8XxuxkEKOBLELuxDZ/sacM047CBIet3CgvqmT0Ff2DKXFIu8Q+NWrKnzvopO7hPv4Zelku6A==} cpu: [x64] os: [linux] - '@rspack/binding-linux-x64-musl@1.4.0-beta.0': - resolution: {integrity: sha512-PCfGShh6y0CqUX8XxuxkEKOBLELuxDZ/sacM047CBIet3CgvqmT0Ff2DKXFIu8Q+NWrKnzvopO7hPv4Zelku6A==} + '@rspack/binding-linux-x64-musl@1.4.1': + resolution: {integrity: sha512-FAyR3Og81Smtr/CnsuTiW4ZCYAPCqeV73lzMKZ9xdVUgM9324ryEgqgX38GZLB5Mo7cvQhv7/fpMeHQo16XQCw==} cpu: [x64] os: [linux] - '@rspack/binding-wasm32-wasi@1.4.0': - resolution: {integrity: sha512-3LMP/bs/qCQw7Os/Y9HXVZ15TyXhngM1EQtX0ULJLPdOaX5yO/znXwdzRCI03T8i3MIZxno9EdgHlg1FNt4Puw==} + '@rspack/binding-wasm32-wasi@1.4.1': + resolution: {integrity: sha512-3Q1VICIQP4GsaTJEmmwfowQ48NvhlL0CKH88l5+mbji2rBkGx7yR67pPdfCVNjXcCtFoemTYw98eaumJTjC++g==} cpu: [wasm32] '@rspack/binding-win32-arm64-msvc@1.3.12': @@ -2643,13 +2667,13 @@ packages: cpu: [arm64] os: [win32] - '@rspack/binding-win32-arm64-msvc@1.4.0': - resolution: {integrity: sha512-cduBQqs8bGMFui7gpq+NlMOq1lr78jCvfUNEvZ59hU9xIx3Xewq1yQRNKuCikx24HJCtKRgzYdSMKMpUwnNNMg==} + '@rspack/binding-win32-arm64-msvc@1.4.0-beta.0': + resolution: {integrity: sha512-4i9LjYePVsyDHM1DChU+lYDE2Gg654kVG6LlV71u2xz6ywi5E81E6IadFkiKSpXaPhQqzWykS3E4jgHHY7nSOw==} cpu: [arm64] os: [win32] - '@rspack/binding-win32-arm64-msvc@1.4.0-beta.0': - resolution: {integrity: sha512-4i9LjYePVsyDHM1DChU+lYDE2Gg654kVG6LlV71u2xz6ywi5E81E6IadFkiKSpXaPhQqzWykS3E4jgHHY7nSOw==} + '@rspack/binding-win32-arm64-msvc@1.4.1': + resolution: {integrity: sha512-DdLPOy1J98kn45uEhiEqlBKgMvet+AxOzX2OcrnU0wQXthGM9gty1YXYNryOhlK+X+eOcwcP3GbnDOAKi8nKqw==} cpu: [arm64] os: [win32] @@ -2658,13 +2682,13 @@ packages: cpu: [ia32] os: [win32] - '@rspack/binding-win32-ia32-msvc@1.4.0': - resolution: {integrity: sha512-ZNWutTwz4iL/9QD0rYk+JKpes5Nx+bQys5aBVM2z/BefvWInw+3beeIRV6SgY8UiO5jc5GEwmdwdv8duzUrhbg==} + '@rspack/binding-win32-ia32-msvc@1.4.0-beta.0': + resolution: {integrity: sha512-BUtCxpwDnxDniA37ia/r5kIHkT5AbKFj9nEDhYrGnRUJYWMwSg2gdDtAZvnHpqdGpGArn9UAOZ/YABEvCOkVKg==} cpu: [ia32] os: [win32] - '@rspack/binding-win32-ia32-msvc@1.4.0-beta.0': - resolution: {integrity: sha512-BUtCxpwDnxDniA37ia/r5kIHkT5AbKFj9nEDhYrGnRUJYWMwSg2gdDtAZvnHpqdGpGArn9UAOZ/YABEvCOkVKg==} + '@rspack/binding-win32-ia32-msvc@1.4.1': + resolution: {integrity: sha512-13s8fYtyC9DyvKosD2Kvzd6fVZDZZyPp91L4TEXWaO0CFhaCbtLTYIntExq9MwtKHYKKx7bchIFw93o0xjKjUg==} cpu: [ia32] os: [win32] @@ -2673,25 +2697,25 @@ packages: cpu: [x64] os: [win32] - '@rspack/binding-win32-x64-msvc@1.4.0': - resolution: {integrity: sha512-pNwpjFCVYQpmA156GgjEqnHly3UZqNXYCJPkouAnUvVE9m0Xoo9May7v7ovKUH4ayySTryL42Ii8tL4iStyJuA==} + '@rspack/binding-win32-x64-msvc@1.4.0-beta.0': + resolution: {integrity: sha512-XLqOM0VYdpChTpquR44CzkGT3d1RQfwVqhjvmXY8Jz8KFDpFf91ZLsXK4IEZhGL0p9TqegMD+GOuVlZ9NLbMKg==} cpu: [x64] os: [win32] - '@rspack/binding-win32-x64-msvc@1.4.0-beta.0': - resolution: {integrity: sha512-XLqOM0VYdpChTpquR44CzkGT3d1RQfwVqhjvmXY8Jz8KFDpFf91ZLsXK4IEZhGL0p9TqegMD+GOuVlZ9NLbMKg==} + '@rspack/binding-win32-x64-msvc@1.4.1': + resolution: {integrity: sha512-ubQW8FcLnwljDanwTzkC9Abyo59gmX8m9uVr1GHOEuEU9Cua0KMijX2j/MYfiziz4nuQgv1saobY7K1I5nE3YA==} cpu: [x64] os: [win32] '@rspack/binding@1.3.12': resolution: {integrity: sha512-4Ic8lV0+LCBfTlH5aIOujIRWZOtgmG223zC4L3o8WY/+ESAgpdnK6lSSMfcYgRanYLAy3HOmFIp20jwskMpbAg==} - '@rspack/binding@1.4.0': - resolution: {integrity: sha512-Kex9H6w44oTYzaQK/goV/BhUJoeWL8rPI1symDjRRvSK4ca/P4OceHvlQzfU0WGg2VKnhTAxH3+KMlpYQFabOQ==} - '@rspack/binding@1.4.0-beta.0': resolution: {integrity: sha512-Pk/T01umu934zxHzufRx1hgkHa/RlZo/M98BCGCWH8vPcD2Xu0bcBP8GoGPcxiJWtMtCsSWJfengz8UVmdAC4g==} + '@rspack/binding@1.4.1': + resolution: {integrity: sha512-zYgOmI+LC2zxB/LIcnaeK66ElFHaPChdWzRruTT1LAFFwpgGkBGAwFoP27PDnxQW0Aejci21Ld8X9tyxm08QFw==} + '@rspack/core@1.3.12': resolution: {integrity: sha512-mAPmV4LPPRgxpouUrGmAE4kpF1NEWJGyM5coebsjK/zaCMSjw3mkdxiU2b5cO44oIi0Ifv5iGkvwbdrZOvMyFA==} engines: {node: '>=16.0.0'} @@ -2701,8 +2725,8 @@ packages: '@swc/helpers': optional: true - '@rspack/core@1.4.0': - resolution: {integrity: sha512-eIzbMYdrpJLjfkelKFLpxUObuv2gAmAuebUJmXeyf2OlFT/DGgoWRDGOVX4MpIHgcE1XCi27sqvOdRU4HA7Zgw==} + '@rspack/core@1.4.0-beta.0': + resolution: {integrity: sha512-rFDM8Un/ap+05omHlTgMGpIJnXiHXnkt9qNKrnWVgvIprngrusWMb/SWrLDxKZeC7MVxuXBfTHMyMpyKIpjSkw==} engines: {node: '>=16.0.0'} peerDependencies: '@swc/helpers': '>=0.5.1' @@ -2710,8 +2734,8 @@ packages: '@swc/helpers': optional: true - '@rspack/core@1.4.0-beta.0': - resolution: {integrity: sha512-rFDM8Un/ap+05omHlTgMGpIJnXiHXnkt9qNKrnWVgvIprngrusWMb/SWrLDxKZeC7MVxuXBfTHMyMpyKIpjSkw==} + '@rspack/core@1.4.1': + resolution: {integrity: sha512-UTRCTQk2G8YiPBiMvfn8FcysxeO4Muek6a/Z39Cw2r4ZI8k5iPnKiyZboTJLS7120PwWBw2SO+QQje35Z44x0g==} engines: {node: '>=16.0.0'} peerDependencies: '@swc/helpers': '>=0.5.1' @@ -9674,58 +9698,58 @@ snapshots: '@rspack/binding-darwin-arm64@1.3.12': optional: true - '@rspack/binding-darwin-arm64@1.4.0': + '@rspack/binding-darwin-arm64@1.4.0-beta.0': optional: true - '@rspack/binding-darwin-arm64@1.4.0-beta.0': + '@rspack/binding-darwin-arm64@1.4.1': optional: true '@rspack/binding-darwin-x64@1.3.12': optional: true - '@rspack/binding-darwin-x64@1.4.0': + '@rspack/binding-darwin-x64@1.4.0-beta.0': optional: true - '@rspack/binding-darwin-x64@1.4.0-beta.0': + '@rspack/binding-darwin-x64@1.4.1': optional: true '@rspack/binding-linux-arm64-gnu@1.3.12': optional: true - '@rspack/binding-linux-arm64-gnu@1.4.0': + '@rspack/binding-linux-arm64-gnu@1.4.0-beta.0': optional: true - '@rspack/binding-linux-arm64-gnu@1.4.0-beta.0': + '@rspack/binding-linux-arm64-gnu@1.4.1': optional: true '@rspack/binding-linux-arm64-musl@1.3.12': optional: true - '@rspack/binding-linux-arm64-musl@1.4.0': + '@rspack/binding-linux-arm64-musl@1.4.0-beta.0': optional: true - '@rspack/binding-linux-arm64-musl@1.4.0-beta.0': + '@rspack/binding-linux-arm64-musl@1.4.1': optional: true '@rspack/binding-linux-x64-gnu@1.3.12': optional: true - '@rspack/binding-linux-x64-gnu@1.4.0': + '@rspack/binding-linux-x64-gnu@1.4.0-beta.0': optional: true - '@rspack/binding-linux-x64-gnu@1.4.0-beta.0': + '@rspack/binding-linux-x64-gnu@1.4.1': optional: true '@rspack/binding-linux-x64-musl@1.3.12': optional: true - '@rspack/binding-linux-x64-musl@1.4.0': + '@rspack/binding-linux-x64-musl@1.4.0-beta.0': optional: true - '@rspack/binding-linux-x64-musl@1.4.0-beta.0': + '@rspack/binding-linux-x64-musl@1.4.1': optional: true - '@rspack/binding-wasm32-wasi@1.4.0': + '@rspack/binding-wasm32-wasi@1.4.1': dependencies: '@napi-rs/wasm-runtime': 0.2.11 optional: true @@ -9733,28 +9757,28 @@ snapshots: '@rspack/binding-win32-arm64-msvc@1.3.12': optional: true - '@rspack/binding-win32-arm64-msvc@1.4.0': + '@rspack/binding-win32-arm64-msvc@1.4.0-beta.0': optional: true - '@rspack/binding-win32-arm64-msvc@1.4.0-beta.0': + '@rspack/binding-win32-arm64-msvc@1.4.1': optional: true '@rspack/binding-win32-ia32-msvc@1.3.12': optional: true - '@rspack/binding-win32-ia32-msvc@1.4.0': + '@rspack/binding-win32-ia32-msvc@1.4.0-beta.0': optional: true - '@rspack/binding-win32-ia32-msvc@1.4.0-beta.0': + '@rspack/binding-win32-ia32-msvc@1.4.1': optional: true '@rspack/binding-win32-x64-msvc@1.3.12': optional: true - '@rspack/binding-win32-x64-msvc@1.4.0': + '@rspack/binding-win32-x64-msvc@1.4.0-beta.0': optional: true - '@rspack/binding-win32-x64-msvc@1.4.0-beta.0': + '@rspack/binding-win32-x64-msvc@1.4.1': optional: true '@rspack/binding@1.3.12': @@ -9769,20 +9793,6 @@ snapshots: '@rspack/binding-win32-ia32-msvc': 1.3.12 '@rspack/binding-win32-x64-msvc': 1.3.12 - '@rspack/binding@1.4.0': - optionalDependencies: - '@rspack/binding-darwin-arm64': 1.4.0 - '@rspack/binding-darwin-x64': 1.4.0 - '@rspack/binding-linux-arm64-gnu': 1.4.0 - '@rspack/binding-linux-arm64-musl': 1.4.0 - '@rspack/binding-linux-x64-gnu': 1.4.0 - '@rspack/binding-linux-x64-musl': 1.4.0 - '@rspack/binding-wasm32-wasi': 1.4.0 - '@rspack/binding-win32-arm64-msvc': 1.4.0 - '@rspack/binding-win32-ia32-msvc': 1.4.0 - '@rspack/binding-win32-x64-msvc': 1.4.0 - optional: true - '@rspack/binding@1.4.0-beta.0': optionalDependencies: '@rspack/binding-darwin-arm64': 1.4.0-beta.0 @@ -9795,6 +9805,20 @@ snapshots: '@rspack/binding-win32-ia32-msvc': 1.4.0-beta.0 '@rspack/binding-win32-x64-msvc': 1.4.0-beta.0 + '@rspack/binding@1.4.1': + optionalDependencies: + '@rspack/binding-darwin-arm64': 1.4.1 + '@rspack/binding-darwin-x64': 1.4.1 + '@rspack/binding-linux-arm64-gnu': 1.4.1 + '@rspack/binding-linux-arm64-musl': 1.4.1 + '@rspack/binding-linux-x64-gnu': 1.4.1 + '@rspack/binding-linux-x64-musl': 1.4.1 + '@rspack/binding-wasm32-wasi': 1.4.1 + '@rspack/binding-win32-arm64-msvc': 1.4.1 + '@rspack/binding-win32-ia32-msvc': 1.4.1 + '@rspack/binding-win32-x64-msvc': 1.4.1 + optional: true + '@rspack/core@1.3.12(@swc/helpers@0.5.17)': dependencies: '@module-federation/runtime-tools': 0.14.0 @@ -9804,22 +9828,22 @@ snapshots: optionalDependencies: '@swc/helpers': 0.5.17 - '@rspack/core@1.4.0(@swc/helpers@0.5.17)': + '@rspack/core@1.4.0-beta.0(@swc/helpers@0.5.17)': dependencies: '@module-federation/runtime-tools': 0.15.0 - '@rspack/binding': 1.4.0 + '@rspack/binding': 1.4.0-beta.0 '@rspack/lite-tapable': 1.0.1 optionalDependencies: '@swc/helpers': 0.5.17 - optional: true - '@rspack/core@1.4.0-beta.0(@swc/helpers@0.5.17)': + '@rspack/core@1.4.1(@swc/helpers@0.5.17)': dependencies: '@module-federation/runtime-tools': 0.15.0 - '@rspack/binding': 1.4.0-beta.0 + '@rspack/binding': 1.4.1 '@rspack/lite-tapable': 1.0.1 optionalDependencies: '@swc/helpers': 0.5.17 + optional: true '@rspack/dev-server@1.1.3(@rspack/core@packages+rspack)(@types/express@4.17.22)(webpack@5.99.9(@swc/core@1.12.0(@swc/helpers@0.5.17)))': dependencies: @@ -11400,7 +11424,7 @@ snapshots: cspell-ban-words@0.0.4: {} - css-loader@7.1.2(@rspack/core@1.4.0(@swc/helpers@0.5.17))(webpack@5.99.9(@swc/core@1.12.0(@swc/helpers@0.5.17))): + css-loader@7.1.2(@rspack/core@1.4.1(@swc/helpers@0.5.17))(webpack@5.99.9(@swc/core@1.12.0(@swc/helpers@0.5.17))): dependencies: icss-utils: 5.1.0(postcss@8.5.4) postcss: 8.5.4 @@ -11411,7 +11435,7 @@ snapshots: postcss-value-parser: 4.2.0 semver: 7.7.2 optionalDependencies: - '@rspack/core': 1.4.0(@swc/helpers@0.5.17) + '@rspack/core': 1.4.1(@swc/helpers@0.5.17) webpack: 5.99.9(@swc/core@1.12.0(@swc/helpers@0.5.17)) css-loader@7.1.2(@rspack/core@packages+rspack)(webpack@5.99.9(@swc/core@1.12.0(@swc/helpers@0.5.17))): diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 7ef12cfc13c3..80b970c4bf31 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -6,6 +6,7 @@ packages: - "packages/create-rspack/**" - "npm/*" - "crates/node_binding" + - "crates/rspack_binding_builder_testing" - "examples/**" - "!examples/three" - "tests/e2e"