diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 5925fadc52a..e2d841c2fd2 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -1283,6 +1283,7 @@ export interface RawEvalDevToolModulePluginOptions { export interface RawExperiments { layers: boolean topLevelAwait: boolean + incremental?: RawIncremental rspackFuture: RawRspackFuture } @@ -1391,6 +1392,16 @@ export interface RawIgnorePluginOptions { checkResource?: (resource: string, context: string) => boolean } +export interface RawIncremental { + make: boolean + emitAssets: boolean + inferAsyncModules: boolean + providedExports: boolean + moduleHashes: boolean + moduleCodegen: boolean + moduleRuntimeRequirements: boolean +} + export interface RawInfo { immutable?: boolean minimized?: boolean @@ -1748,7 +1759,7 @@ export interface RawResolveTsconfigOptions { } export interface RawRspackFuture { - newIncremental: boolean + } export interface RawRuleSetCondition { diff --git a/crates/rspack_binding_options/src/options/mod.rs b/crates/rspack_binding_options/src/options/mod.rs index 1afd7aa5d94..ac11b7b8fc4 100644 --- a/crates/rspack_binding_options/src/options/mod.rs +++ b/crates/rspack_binding_options/src/options/mod.rs @@ -1,7 +1,7 @@ use napi_derive::napi; use rspack_core::{ - CacheOptions, CompilerOptions, Context, Experiments, IncrementalRebuild, - IncrementalRebuildMakeState, ModuleOptions, OutputOptions, References, Target, + CacheOptions, CompilerOptions, Context, Experiments, Incremental, ModuleOptions, OutputOptions, + References, Target, }; mod raw_builtins; @@ -72,13 +72,21 @@ impl TryFrom for CompilerOptions { let target = Target::new(&value.target)?; let cache = value.cache.into(); let experiments = Experiments { - incremental_rebuild: IncrementalRebuild { - make: if matches!(cache, CacheOptions::Disabled) { - None - } else { - Some(IncrementalRebuildMakeState::default()) + incremental: match value.experiments.incremental { + Some(value) => Incremental::Enabled { + make: if matches!(cache, CacheOptions::Disabled) { + false + } else { + value.make + }, + emit_assets: value.emit_assets, + infer_async_modules: value.infer_async_modules, + provided_exports: value.provided_exports, + module_hashes: value.module_hashes, + module_codegen: value.module_codegen, + module_runtime_requirements: value.module_runtime_requirements, }, - emit_asset: true, + None => Incremental::Disabled, }, layers: value.experiments.layers, top_level_await: value.experiments.top_level_await, diff --git a/crates/rspack_binding_options/src/options/raw_experiments.rs b/crates/rspack_binding_options/src/options/raw_experiments.rs index 086bcca67e7..91f248be79c 100644 --- a/crates/rspack_binding_options/src/options/raw_experiments.rs +++ b/crates/rspack_binding_options/src/options/raw_experiments.rs @@ -1,25 +1,48 @@ use napi_derive::napi; -use rspack_core::RspackFuture; - -#[allow(clippy::empty_structs_with_brackets)] -#[derive(Debug, Default)] -#[napi(object)] -pub struct RawRspackFuture { - pub new_incremental: bool, -} +use rspack_core::{Incremental, RspackFuture}; #[derive(Debug, Default)] #[napi(object)] pub struct RawExperiments { pub layers: bool, pub top_level_await: bool, + pub incremental: Option, pub rspack_future: RawRspackFuture, } -impl From for RspackFuture { - fn from(value: RawRspackFuture) -> Self { - Self { - new_incremental: value.new_incremental, +#[derive(Debug, Default)] +#[napi(object)] +pub struct RawIncremental { + pub make: bool, + pub emit_assets: bool, + pub infer_async_modules: bool, + pub provided_exports: bool, + pub module_hashes: bool, + pub module_codegen: bool, + pub module_runtime_requirements: bool, +} + +impl From for Incremental { + fn from(value: RawIncremental) -> Self { + Self::Enabled { + make: value.make, + emit_assets: value.emit_assets, + infer_async_modules: value.infer_async_modules, + provided_exports: value.provided_exports, + module_hashes: value.module_hashes, + module_codegen: value.module_codegen, + module_runtime_requirements: value.module_runtime_requirements, } } } + +#[allow(clippy::empty_structs_with_brackets)] +#[derive(Debug, Default)] +#[napi(object)] +pub struct RawRspackFuture {} + +impl From for RspackFuture { + fn from(_value: RawRspackFuture) -> Self { + Self {} + } +} diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index ef4d4d34475..3019109e193 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -234,7 +234,7 @@ impl Compilation { removed_files: HashSet, input_filesystem: Arc, ) -> Self { - let mutations = options.new_incremental_enabled().then(Mutations::default); + let mutations = options.incremental().enabled().then(Mutations::default); Self { id: CompilationId::new(), hot_index: 0, @@ -1068,7 +1068,8 @@ impl Compilation { )], )?; - if self.options.new_incremental_enabled() { + let incremental = self.options.incremental(); + if incremental.infer_async_modules_enabled() || incremental.provided_exports_enabled() { self .unaffected_modules_cache .compute_affected_modules_with_module_graph(self); @@ -1137,10 +1138,6 @@ impl Compilation { ) {} logger.time_end(start); - // if self.options.is_new_tree_shaking() { - // // let filter = |item: &str| ["config-provider"].iter().any(|pat| item.contains(pat)); - // // debug_all_exports_info!(&self.module_graph, filter); - // } let start = logger.time("create chunks"); use_code_splitting_cache(self, |compilation| async { build_chunk_graph(compilation)?; @@ -1194,31 +1191,52 @@ impl Compilation { self.assign_runtime_ids(); - if self.options.new_incremental_enabled() { + let incremental = self.options.incremental(); + let module_hashes_modules; + let module_codegen_modules; + let module_runtime_requirements_modules; + let all_modules: Option = if incremental.module_hashes_enabled() + && incremental.module_codegen_enabled() + && incremental.module_runtime_requirements_enabled() + { + None + } else { + Some(self.get_module_graph().modules().keys().copied().collect()) + }; + if (incremental.module_hashes_enabled() + || incremental.module_codegen_enabled() + || incremental.module_runtime_requirements_enabled()) + && let Some(mutations) = &self.mutations + { self .unaffected_modules_cache .compute_affected_modules_with_chunk_graph(self); - } - - let modules = if self.options.new_incremental_enabled() - && let Some(mutations) = &self.mutations - { - let mut modules = self + let mut affected_modules: IdentifierSet = self .unaffected_modules_cache .get_affected_modules_with_chunk_graph() .lock() .expect("should lock") .clone(); - modules.extend(mutations.iter().filter_map(|mutation| match mutation { - Mutation::ModuleGraphModuleSetAsync { module } => Some(module), + affected_modules.extend(mutations.iter().filter_map(|mutation| match mutation { + Mutation::ModuleSetAsync { module } => Some(module), _ => None, })); - modules + let create_task_modules = |enabled: bool| { + enabled + .then(|| affected_modules.clone()) + .unwrap_or_else(|| all_modules.clone().expect("failed")) + }; + module_hashes_modules = create_task_modules(incremental.module_hashes_enabled()); + module_codegen_modules = create_task_modules(incremental.module_codegen_enabled()); + module_runtime_requirements_modules = + create_task_modules(incremental.module_runtime_requirements_enabled()); } else { - self.get_module_graph().modules().keys().copied().collect() + module_hashes_modules = all_modules.clone().expect("failed"); + module_codegen_modules = all_modules.clone().expect("failed"); + module_runtime_requirements_modules = all_modules.clone().expect("failed"); }; - self.create_module_hashes(modules.clone())?; + self.create_module_hashes(module_hashes_modules)?; let start = logger.time("optimize code generation"); plugin_driver @@ -1228,13 +1246,13 @@ impl Compilation { logger.time_end(start); let start = logger.time("code generation"); - self.code_generation(modules.clone())?; + self.code_generation(module_codegen_modules)?; logger.time_end(start); let start = logger.time("runtime requirements"); self .process_runtime_requirements( - modules, + module_runtime_requirements_modules, self .chunk_by_ukey .keys() diff --git a/crates/rspack_core/src/compiler/hmr.rs b/crates/rspack_core/src/compiler/hmr.rs index 864cd3fecb5..7923ba1eb3c 100644 --- a/crates/rspack_core/src/compiler/hmr.rs +++ b/crates/rspack_core/src/compiler/hmr.rs @@ -76,14 +76,10 @@ impl Compiler { self.input_filesystem.clone(), ); - if let Some(state) = self.options.get_incremental_rebuild_make_state() { - state.set_is_not_first(); - } - new_compilation.hot_index = self.compilation.hot_index + 1; - let is_incremental_rebuild_make = self.options.is_incremental_rebuild_make_enabled(); - if is_incremental_rebuild_make { + let incremental = self.options.incremental(); + if incremental.make_enabled() { // copy field from old compilation // make stage used self @@ -97,12 +93,17 @@ impl Compiler { // reuse module executor new_compilation.module_executor = std::mem::take(&mut self.compilation.module_executor); } - - if self.options.new_incremental_enabled() { + if incremental.infer_async_modules_enabled() { new_compilation.async_modules = std::mem::take(&mut self.compilation.async_modules); + } + if incremental.module_hashes_enabled() { new_compilation.cgm_hash_results = std::mem::take(&mut self.compilation.cgm_hash_results); + } + if incremental.module_codegen_enabled() { new_compilation.code_generation_results = std::mem::take(&mut self.compilation.code_generation_results); + } + if incremental.module_runtime_requirements_enabled() { new_compilation.cgm_runtime_requirements_results = std::mem::take(&mut self.compilation.cgm_runtime_requirements_results); } diff --git a/crates/rspack_core/src/compiler/mod.rs b/crates/rspack_core/src/compiler/mod.rs index e59a6580fd2..530418a19eb 100644 --- a/crates/rspack_core/src/compiler/mod.rs +++ b/crates/rspack_core/src/compiler/mod.rs @@ -299,7 +299,7 @@ impl Compiler { .iter() .filter_map(|(filename, asset)| { // collect version info to new_emitted_asset_versions - if self.options.is_incremental_rebuild_emit_asset_enabled() { + if self.options.incremental().emit_assets_enabled() { new_emitted_asset_versions.insert(filename.to_string(), asset.info.version.clone()); } diff --git a/crates/rspack_core/src/old_cache/local/code_splitting_cache.rs b/crates/rspack_core/src/old_cache/local/code_splitting_cache.rs index 03871dfcc16..e718d07ffec 100644 --- a/crates/rspack_core/src/old_cache/local/code_splitting_cache.rs +++ b/crates/rspack_core/src/old_cache/local/code_splitting_cache.rs @@ -27,7 +27,7 @@ where T: Fn(&'a mut Compilation) -> F, F: Future>, { - let is_incremental_rebuild = compilation.options.is_incremental_rebuild_make_enabled(); + let is_incremental_rebuild = compilation.options.incremental().make_enabled(); if !is_incremental_rebuild { task(compilation).await?; return Ok(()); diff --git a/crates/rspack_core/src/options/compiler_options.rs b/crates/rspack_core/src/options/compiler_options.rs index c1d675454b3..c3c7b3639fd 100644 --- a/crates/rspack_core/src/options/compiler_options.rs +++ b/crates/rspack_core/src/options/compiler_options.rs @@ -1,7 +1,7 @@ +use super::Incremental; use crate::{ - CacheOptions, Context, DevServerOptions, Experiments, IncrementalRebuildMakeState, Mode, - ModuleOptions, NodeOption, Optimization, OutputOptions, Resolve, SnapshotOptions, StatsOptions, - Target, + CacheOptions, Context, DevServerOptions, Experiments, Mode, ModuleOptions, NodeOption, + Optimization, OutputOptions, Resolve, SnapshotOptions, StatsOptions, Target, }; #[derive(Debug)] @@ -29,19 +29,7 @@ pub struct CompilerOptions { pub type References = serde_json::Map; impl CompilerOptions { - pub fn is_incremental_rebuild_make_enabled(&self) -> bool { - self.experiments.incremental_rebuild.make.is_some() - } - - pub fn get_incremental_rebuild_make_state(&self) -> Option<&IncrementalRebuildMakeState> { - self.experiments.incremental_rebuild.make.as_ref() - } - - pub fn is_incremental_rebuild_emit_asset_enabled(&self) -> bool { - self.experiments.incremental_rebuild.emit_asset - } - - pub fn new_incremental_enabled(&self) -> bool { - self.experiments.rspack_future.new_incremental + pub fn incremental(&self) -> &Incremental { + &self.experiments.incremental } } diff --git a/crates/rspack_core/src/options/experiments.rs b/crates/rspack_core/src/options/experiments.rs index 6e7405a88e7..97086cc2903 100644 --- a/crates/rspack_core/src/options/experiments.rs +++ b/crates/rspack_core/src/options/experiments.rs @@ -1,36 +1,59 @@ -use once_cell::sync::OnceCell; - -#[derive(Debug, Default)] -pub struct IncrementalRebuild { - pub make: Option, - pub emit_asset: bool, +#[derive(Debug)] +pub struct Experiments { + pub layers: bool, + pub incremental: Incremental, + pub top_level_await: bool, + pub rspack_future: RspackFuture, } -#[derive(Debug, Default)] -pub struct IncrementalRebuildMakeState { - first: OnceCell<()>, +#[allow(clippy::empty_structs_with_brackets)] +#[derive(Debug)] +pub struct RspackFuture {} + +#[derive(Debug)] +pub enum Incremental { + Disabled, + Enabled { + make: bool, + emit_assets: bool, + infer_async_modules: bool, + provided_exports: bool, + module_hashes: bool, + module_codegen: bool, + module_runtime_requirements: bool, + }, } -impl IncrementalRebuildMakeState { - pub fn is_first(&self) -> bool { - self.first.get().is_none() +impl Incremental { + pub fn enabled(&self) -> bool { + matches!(self, Incremental::Enabled { .. }) } - pub fn set_is_not_first(&self) { - self.first.get_or_init(|| ()); + pub fn make_enabled(&self) -> bool { + matches!(self, Incremental::Enabled { make, .. } if *make) } -} -#[allow(clippy::empty_structs_with_brackets)] -#[derive(Debug, Default)] -pub struct RspackFuture { - pub new_incremental: bool, -} + pub fn emit_assets_enabled(&self) -> bool { + matches!(self, Incremental::Enabled { emit_assets, .. } if *emit_assets) + } -#[derive(Debug, Default)] -pub struct Experiments { - pub layers: bool, - pub incremental_rebuild: IncrementalRebuild, - pub top_level_await: bool, - pub rspack_future: RspackFuture, + pub fn infer_async_modules_enabled(&self) -> bool { + matches!(self, Incremental::Enabled { infer_async_modules, .. } if *infer_async_modules) + } + + pub fn provided_exports_enabled(&self) -> bool { + matches!(self, Incremental::Enabled { provided_exports, .. } if *provided_exports) + } + + pub fn module_hashes_enabled(&self) -> bool { + matches!(self, Incremental::Enabled { module_hashes, .. } if *module_hashes) + } + + pub fn module_codegen_enabled(&self) -> bool { + matches!(self, Incremental::Enabled { module_codegen, .. } if *module_codegen) + } + + pub fn module_runtime_requirements_enabled(&self) -> bool { + matches!(self, Incremental::Enabled { module_runtime_requirements, .. } if *module_runtime_requirements) + } } diff --git a/crates/rspack_core/src/unaffected_cache/mutations.rs b/crates/rspack_core/src/unaffected_cache/mutations.rs index a28e35a8f6e..33076e39fd0 100644 --- a/crates/rspack_core/src/unaffected_cache/mutations.rs +++ b/crates/rspack_core/src/unaffected_cache/mutations.rs @@ -7,7 +7,7 @@ pub struct Mutations { #[derive(Debug)] pub enum Mutation { - ModuleGraphModuleSetAsync { module: ModuleIdentifier }, + ModuleSetAsync { module: ModuleIdentifier }, PlaceholderForExtendable, } diff --git a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs index 3989f36aeb2..5451cfb0824 100644 --- a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs @@ -353,7 +353,7 @@ pub struct FlagDependencyExportsPlugin; #[plugin_hook(CompilationFinishModules for FlagDependencyExportsPlugin)] async fn finish_modules(&self, compilation: &mut Compilation) -> Result<()> { - let modules: IdentifierSet = if compilation.options.new_incremental_enabled() { + let modules: IdentifierSet = if compilation.options.incremental().provided_exports_enabled() { compilation .unaffected_modules_cache .get_affected_modules_with_module_graph() diff --git a/crates/rspack_plugin_javascript/src/plugin/infer_async_modules_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/infer_async_modules_plugin.rs index 45d1bc7d712..d8a393937e7 100644 --- a/crates/rspack_plugin_javascript/src/plugin/infer_async_modules_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/infer_async_modules_plugin.rs @@ -15,7 +15,11 @@ pub struct InferAsyncModulesPlugin; #[plugin_hook(CompilationFinishModules for InferAsyncModulesPlugin)] async fn finish_modules(&self, compilation: &mut Compilation) -> Result<()> { let module_graph = compilation.get_module_graph(); - let modules: IdentifierSet = if compilation.options.new_incremental_enabled() { + let modules: IdentifierSet = if compilation + .options + .incremental() + .infer_async_modules_enabled() + { compilation .unaffected_modules_cache .get_affected_modules_with_module_graph() @@ -42,7 +46,8 @@ async fn finish_modules(&self, compilation: &mut Compilation) -> Result<()> { let mut mutations = compilation .options - .new_incremental_enabled() + .incremental() + .enabled() .then(Mutations::default); set_sync_modules(compilation, sync_modules, &mut mutations); @@ -80,7 +85,7 @@ fn set_sync_modules( // This also applies to set_async_modules if ModuleGraph::set_async(compilation, module, false) { if let Some(mutations) = mutations { - mutations.add(Mutation::ModuleGraphModuleSetAsync { module }); + mutations.add(Mutation::ModuleSetAsync { module }); } let module_graph = compilation.get_module_graph(); module_graph @@ -116,7 +121,7 @@ fn set_async_modules( while let Some(module) = queue.pop_front() { if ModuleGraph::set_async(compilation, module, true) { if let Some(mutations) = mutations { - mutations.add(Mutation::ModuleGraphModuleSetAsync { module }); + mutations.add(Mutation::ModuleSetAsync { module }); } let module_graph = compilation.get_module_graph(); module_graph diff --git a/packages/rspack-test-tools/src/case/new-incremental.ts b/packages/rspack-test-tools/src/case/new-incremental.ts index 461bea45cef..3081a464e49 100644 --- a/packages/rspack-test-tools/src/case/new-incremental.ts +++ b/packages/rspack-test-tools/src/case/new-incremental.ts @@ -82,8 +82,14 @@ const watchCreator = new BasicCaseCreator({ compilerType: ECompilerType.Rspack, configFiles: ["rspack.config.js", "webpack.config.js"], experiments: { - rspackFuture: { - newIncremental: true + incremental: { + make: true, + emitAssets: true, + inferAsyncModules: true, + providedExports: true, + moduleHashes: true, + moduleCodegen: true, + moduleRuntimeRequirements: true } } }) diff --git a/packages/rspack-test-tools/src/processor/hot-new-incremental.ts b/packages/rspack-test-tools/src/processor/hot-new-incremental.ts index dbf7f51f78f..4967c58a6d2 100644 --- a/packages/rspack-test-tools/src/processor/hot-new-incremental.ts +++ b/packages/rspack-test-tools/src/processor/hot-new-incremental.ts @@ -50,8 +50,15 @@ export class HotNewIncrementalProcessor< if (this._hotOptions.compilerType === ECompilerType.Rspack) { const rspackOptions = options as TCompilerOptions; rspackOptions.experiments ??= {}; - rspackOptions.experiments.rspackFuture ??= {}; - rspackOptions.experiments.rspackFuture.newIncremental = true; + rspackOptions.experiments.incremental ??= { + make: true, + emitAssets: true, + inferAsyncModules: true, + providedExports: true, + moduleHashes: true, + moduleCodegen: true, + moduleRuntimeRequirements: true + }; } else { throw new Error( "HotNewIncrementalProcessor should only used for Rspack." diff --git a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap index fc3eacc35b9..20b588cac54 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap @@ -19,6 +19,15 @@ Object { "asyncWebAssembly": false, "css": undefined, "futureDefaults": false, + "incremental": Object { + "emitAssets": true, + "inferAsyncModules": false, + "make": true, + "moduleCodegen": false, + "moduleHashes": false, + "moduleRuntimeRequirements": false, + "providedExports": false, + }, "layers": false, "lazyCompilation": false, "rspackFuture": Object { @@ -27,7 +36,6 @@ Object { "force": true, "version": "$version$", }, - "newIncremental": false, }, "topLevelAwait": true, }, diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index ba62178c52a..f595de39522 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -3545,6 +3545,31 @@ const experiments_2: z.ZodObject<{ topLevelAwait: z.ZodOptional; css: z.ZodOptional; layers: z.ZodOptional; + incremental: z.ZodOptional; + emitAssets: z.ZodOptional; + inferAsyncModules: z.ZodOptional; + providedExports: z.ZodOptional; + moduleHashes: z.ZodOptional; + moduleCodegen: z.ZodOptional; + moduleRuntimeRequirements: z.ZodOptional; + }, "strict", z.ZodTypeAny, { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; + }, { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; + }>]>>; futureDefaults: z.ZodOptional; rspackFuture: z.ZodOptional>; - newIncremental: z.ZodOptional; }, "strict", z.ZodTypeAny, { bundlerInfo?: { force?: boolean | ("version" | "uniqueId")[] | undefined; version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; }, { bundlerInfo?: { force?: boolean | ("version" | "uniqueId")[] | undefined; version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; }>>; }, "strict", z.ZodTypeAny, { css?: boolean | undefined; @@ -3601,6 +3623,15 @@ const experiments_2: z.ZodObject<{ outputModule?: boolean | undefined; topLevelAwait?: boolean | undefined; layers?: boolean | undefined; + incremental?: boolean | { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; + } | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { bundlerInfo?: { @@ -3608,7 +3639,6 @@ const experiments_2: z.ZodObject<{ version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; } | undefined; }, { css?: boolean | undefined; @@ -3635,6 +3665,15 @@ const experiments_2: z.ZodObject<{ outputModule?: boolean | undefined; topLevelAwait?: boolean | undefined; layers?: boolean | undefined; + incremental?: boolean | { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; + } | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { bundlerInfo?: { @@ -3642,7 +3681,6 @@ const experiments_2: z.ZodObject<{ version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; } | undefined; }>; @@ -3655,6 +3693,8 @@ export interface ExperimentsNormalized { // (undocumented) futureDefaults?: boolean; // (undocumented) + incremental?: false | Incremental; + // (undocumented) layers?: boolean; // (undocumented) lazyCompilation?: false | LazyCompilationOptions; @@ -4910,6 +4950,36 @@ export type ImportMetaName = z.infer; // @public (undocumented) const importMetaName: z.ZodString; +// @public (undocumented) +export type Incremental = z.infer; + +// @public (undocumented) +const incremental: z.ZodObject<{ + make: z.ZodOptional; + emitAssets: z.ZodOptional; + inferAsyncModules: z.ZodOptional; + providedExports: z.ZodOptional; + moduleHashes: z.ZodOptional; + moduleCodegen: z.ZodOptional; + moduleRuntimeRequirements: z.ZodOptional; +}, "strict", z.ZodTypeAny, { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; +}, { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; +}>; + // @public (undocumented) export type InfrastructureLogging = z.infer; @@ -10329,6 +10399,7 @@ declare namespace rspackExports { Optimization, RspackFutureOptions, LazyCompilationOptions, + Incremental, Experiments, Watch, WatchOptions, @@ -10361,21 +10432,18 @@ const rspackFutureOptions: z.ZodObject<{ version?: string | undefined; bundler?: string | undefined; }>>; - newIncremental: z.ZodOptional; }, "strict", z.ZodTypeAny, { bundlerInfo?: { force?: boolean | ("version" | "uniqueId")[] | undefined; version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; }, { bundlerInfo?: { force?: boolean | ("version" | "uniqueId")[] | undefined; version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; }>; // @public (undocumented) @@ -11283,6 +11351,31 @@ export const rspackOptions: z.ZodObject<{ topLevelAwait: z.ZodOptional; css: z.ZodOptional; layers: z.ZodOptional; + incremental: z.ZodOptional; + emitAssets: z.ZodOptional; + inferAsyncModules: z.ZodOptional; + providedExports: z.ZodOptional; + moduleHashes: z.ZodOptional; + moduleCodegen: z.ZodOptional; + moduleRuntimeRequirements: z.ZodOptional; + }, "strict", z.ZodTypeAny, { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; + }, { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; + }>]>>; futureDefaults: z.ZodOptional; rspackFuture: z.ZodOptional>; - newIncremental: z.ZodOptional; }, "strict", z.ZodTypeAny, { bundlerInfo?: { force?: boolean | ("version" | "uniqueId")[] | undefined; version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; }, { bundlerInfo?: { force?: boolean | ("version" | "uniqueId")[] | undefined; version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; }>>; }, "strict", z.ZodTypeAny, { css?: boolean | undefined; @@ -11339,6 +11429,15 @@ export const rspackOptions: z.ZodObject<{ outputModule?: boolean | undefined; topLevelAwait?: boolean | undefined; layers?: boolean | undefined; + incremental?: boolean | { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; + } | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { bundlerInfo?: { @@ -11346,7 +11445,6 @@ export const rspackOptions: z.ZodObject<{ version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; } | undefined; }, { css?: boolean | undefined; @@ -11373,6 +11471,15 @@ export const rspackOptions: z.ZodObject<{ outputModule?: boolean | undefined; topLevelAwait?: boolean | undefined; layers?: boolean | undefined; + incremental?: boolean | { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; + } | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { bundlerInfo?: { @@ -11380,7 +11487,6 @@ export const rspackOptions: z.ZodObject<{ version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; } | undefined; }>>; externals: z.ZodOptional]>, z.ZodRecord, z.ZodArray]>, z.ZodRecord]>>]>>]>, z.ZodFunction> | ((args_0: { @@ -13979,6 +14093,15 @@ export const rspackOptions: z.ZodObject<{ outputModule?: boolean | undefined; topLevelAwait?: boolean | undefined; layers?: boolean | undefined; + incremental?: boolean | { + make?: boolean | undefined; + providedExports?: boolean | undefined; + emitAssets?: boolean | undefined; + inferAsyncModules?: boolean | undefined; + moduleHashes?: boolean | undefined; + moduleCodegen?: boolean | undefined; + moduleRuntimeRequirements?: boolean | undefined; + } | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { bundlerInfo?: { @@ -13986,7 +14109,6 @@ export const rspackOptions: z.ZodObject<{ version?: string | undefined; bundler?: string | undefined; } | undefined; - newIncremental?: boolean | undefined; } | undefined; } | undefined; externals?: string | RegExp | Record> | ((args_0: { diff --git a/packages/rspack/scripts/check-documentation-coverage.mjs b/packages/rspack/scripts/check-documentation-coverage.mjs index c6fec7d3e58..011c3f3d583 100644 --- a/packages/rspack/scripts/check-documentation-coverage.mjs +++ b/packages/rspack/scripts/check-documentation-coverage.mjs @@ -244,6 +244,7 @@ function checkConfigsDocumentationCoverage() { "module.generator", "experiments.rspackFuture", + "experiments.incremental", "output.library.amd", "output.library.commonjs", diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index cdcae9ff811..2bdac595950 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -15,6 +15,7 @@ import { type RawCssParserOptions, type RawFuncUseCtx, type RawGeneratorOptions, + type RawIncremental, type RawJavascriptParserOptions, type RawModuleRule, type RawModuleRuleUse, @@ -56,6 +57,7 @@ import type { CssGeneratorOptions, CssParserOptions, GeneratorOptionsByModuleType, + Incremental, JavascriptParserOptions, LibraryName, LibraryOptions, @@ -874,22 +876,43 @@ function getRawSnapshotOptions( function getRawExperiments( experiments: ExperimentsNormalized ): RawOptions["experiments"] { - const { topLevelAwait, layers, rspackFuture } = experiments; - assert(!isNil(topLevelAwait) && !isNil(rspackFuture) && !isNil(layers)); + const { topLevelAwait, layers, incremental, rspackFuture } = experiments; + assert( + !isNil(topLevelAwait) && + !isNil(rspackFuture) && + !isNil(layers) && + !isNil(incremental) + ); return { layers, topLevelAwait, + incremental: getRawIncremental(incremental), rspackFuture: getRawRspackFutureOptions(rspackFuture) }; } +function getRawIncremental( + incremental: false | Incremental +): RawIncremental | undefined { + if (incremental === false) { + return undefined; + } + return { + make: incremental.make!, + emitAssets: incremental.emitAssets!, + inferAsyncModules: incremental.inferAsyncModules!, + providedExports: incremental.providedExports!, + moduleHashes: incremental.moduleHashes!, + moduleCodegen: incremental.moduleCodegen!, + moduleRuntimeRequirements: incremental.moduleRuntimeRequirements! + }; +} + function getRawRspackFutureOptions( future: RspackFutureOptions ): RawRspackFuture { - return { - newIncremental: future.newIncremental! - }; + return {}; } function getRawNode(node: Node): RawOptions["node"] { diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 8dfdbb6defa..996ccf263e0 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -201,12 +201,20 @@ const applyExperimentsDefaults = (experiments: ExperimentsNormalized) => { D(experiments, "layers", false); D(experiments, "topLevelAwait", true); + // IGNORE(experiments.incremental): Rspack specific configuration for incremental + D(experiments, "incremental", {}); + if (typeof experiments.incremental === "object") { + D(experiments.incremental, "make", true); + D(experiments.incremental, "emitAssets", true); + D(experiments.incremental, "inferAsyncModules", false); + D(experiments.incremental, "providedExports", false); + D(experiments.incremental, "moduleHashes", false); + D(experiments.incremental, "moduleCodegen", false); + D(experiments.incremental, "moduleRuntimeRequirements", false); + } // IGNORE(experiments.rspackFuture): Rspack specific configuration D(experiments, "rspackFuture", {}); // rspackFuture.bundlerInfo default value is applied after applyDefaults - if (typeof experiments.rspackFuture === "object") { - D(experiments.rspackFuture, "newIncremental", false); - } }; const applybundlerInfoDefaults = ( diff --git a/packages/rspack/src/config/normalization.ts b/packages/rspack/src/config/normalization.ts index 451757c702e..fd3862cfa05 100644 --- a/packages/rspack/src/config/normalization.ts +++ b/packages/rspack/src/config/normalization.ts @@ -51,6 +51,7 @@ import type { Iife, ImportFunctionName, ImportMetaName, + Incremental, InfrastructureLogging, Layer, LazyCompilationOptions, @@ -309,6 +310,9 @@ export const getNormalizedRspackOptions = ( lazyCompilation: optionalNestedConfig( experiments.lazyCompilation, options => (options === true ? {} : options) + ), + incremental: optionalNestedConfig(experiments.incremental, options => + options === true ? {} : options ) })), watch: config.watch, @@ -520,6 +524,7 @@ export interface ExperimentsNormalized { topLevelAwait?: boolean; css?: boolean; layers?: boolean; + incremental?: false | Incremental; futureDefaults?: boolean; rspackFuture?: RspackFutureOptions; } diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index efbe32944d0..467bd63b5a9 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -1331,8 +1331,7 @@ const rspackFutureOptions = z.strictObject({ .or(z.array(z.enum(["version", "uniqueId"]))) .optional() }) - .optional(), - newIncremental: z.boolean().optional() + .optional() }); export type RspackFutureOptions = z.infer; @@ -1362,9 +1361,19 @@ const lazyCompilationOptions = z.object({ .or(z.function().args(z.custom()).returns(z.boolean())) .optional() }); - export type LazyCompilationOptions = z.infer; +const incremental = z.strictObject({ + make: z.boolean().optional(), + emitAssets: z.boolean().optional(), + inferAsyncModules: z.boolean().optional(), + providedExports: z.boolean().optional(), + moduleHashes: z.boolean().optional(), + moduleCodegen: z.boolean().optional(), + moduleRuntimeRequirements: z.boolean().optional() +}); +export type Incremental = z.infer; + const experiments = z.strictObject({ lazyCompilation: z.boolean().optional().or(lazyCompilationOptions), asyncWebAssembly: z.boolean().optional(), @@ -1372,6 +1381,7 @@ const experiments = z.strictObject({ topLevelAwait: z.boolean().optional(), css: z.boolean().optional(), layers: z.boolean().optional(), + incremental: z.boolean().or(incremental).optional(), futureDefaults: z.boolean().optional(), rspackFuture: rspackFutureOptions.optional() });