From c69a36177d884f56675d54b9fce5a4aa6eed0da1 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Mon, 23 Sep 2024 16:09:44 +0800 Subject: [PATCH] feat: update test case --- crates/node_binding/binding.d.ts | 2 +- .../rspack_binding_values/src/dependency.rs | 16 +++---- .../rspack.config.js | 4 ++ packages/rspack/etc/api.md | 42 +++++++++++++++---- packages/rspack/src/Dependency.ts | 2 +- packages/rspack/src/Module.ts | 10 ++--- 6 files changed, 54 insertions(+), 22 deletions(-) diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 2b39aa7414f..244d776acb5 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -150,7 +150,7 @@ export class JsDependency { get category(): string get request(): string | undefined get critical(): boolean | undefined - set critical(val: boolean) + set critical(val?: boolean | undefined | null) } export class JsEntries { diff --git a/crates/rspack_binding_values/src/dependency.rs b/crates/rspack_binding_values/src/dependency.rs index ae84d2bc218..97c62d0a3ca 100644 --- a/crates/rspack_binding_values/src/dependency.rs +++ b/crates/rspack_binding_values/src/dependency.rs @@ -113,15 +113,17 @@ impl JsDependency { } #[napi(setter)] - pub fn set_critical(&mut self, val: bool) { - match self.0.as_context_dependency_mut() { - Some(dep) => { - let critical = dep.critical_mut(); - if !val { - *critical = None; + pub fn set_critical(&mut self, val: Option) { + if let Some(val) = val { + match self.0.as_context_dependency_mut() { + Some(dep) => { + let critical = dep.critical_mut(); + if !val { + *critical = None; + } } + None => (), } - None => (), } } } diff --git a/packages/rspack-test-tools/tests/configCases/hooks/context-module-before-resolve/rspack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/context-module-before-resolve/rspack.config.js index dfb8bfdac3f..52848a17dd5 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/context-module-before-resolve/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/context-module-before-resolve/rspack.config.js @@ -10,11 +10,15 @@ class Plugin { resolveData.regExp = /[/\\](en(\.js)?|zh(\.js)?)$/; return resolveData; } + for (const d of resolveData.dependencies) { + if (d.critical) d.critical = false; + } }); } ); } } + /**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index ba62178c52a..ba0eaf630db 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -18,7 +18,6 @@ import { cleanupGlobalTrace } from '@rspack/binding'; import { Compiler as Compiler_2 } from '../Compiler'; import { default as default_2 } from './util/hash'; import type { DependenciesBlockDTO } from '@rspack/binding'; -import type { DependencyDTO } from '@rspack/binding'; import { RawEvalDevToolModulePluginOptions as EvalDevToolModulePluginOptions } from '@rspack/binding'; import { EventEmitter } from 'events'; import { ExternalObject } from '@rspack/binding'; @@ -39,8 +38,11 @@ import { JsChunkGroup } from '@rspack/binding'; import { JsChunkGroupOrigin } from '@rspack/binding'; import type { JsCodegenerationResult } from '@rspack/binding'; import { JsCompilation } from '@rspack/binding'; +import { JsCompiledDependency } from '@rspack/binding'; import type { JsContextModuleFactoryAfterResolveData } from '@rspack/binding'; +import type { JsContextModuleFactoryBeforeResolveData } from '@rspack/binding'; import type { JsCreateData } from '@rspack/binding'; +import { JsDependency } from '@rspack/binding'; import type { JsFactoryMeta } from '@rspack/binding'; import { JsHtmlPluginTag } from '@rspack/binding'; import { JsLibraryOptions } from '@rspack/binding'; @@ -1577,7 +1579,8 @@ class ContextModuleFactory { // @public (undocumented) class ContextModuleFactoryAfterResolveData { - constructor(data: JsContextModuleFactoryAfterResolveData); + // (undocumented) + static __drop(data: ContextModuleFactoryAfterResolveData): void; // (undocumented) static __from_binding(binding: JsContextModuleFactoryAfterResolveData): ContextModuleFactoryAfterResolveData; // (undocumented) @@ -1605,10 +1608,29 @@ class ContextModuleFactoryAfterResolveData { type ContextModuleFactoryAfterResolveResult = false | ContextModuleFactoryAfterResolveData; // @public (undocumented) -type ContextModuleFactoryBeforeResolveResult = false | { - context: string; - request?: string; -}; +class ContextModuleFactoryBeforeResolveData { + // (undocumented) + static __drop(data: ContextModuleFactoryBeforeResolveData): void; + // (undocumented) + static __from_binding(binding: JsContextModuleFactoryBeforeResolveData): ContextModuleFactoryBeforeResolveData; + // (undocumented) + static __to_binding(data: ContextModuleFactoryBeforeResolveData): JsContextModuleFactoryBeforeResolveData; + // (undocumented) + get context(): string; + set context(val: string); + // (undocumented) + get recursive(): boolean; + set recursive(val: boolean); + // (undocumented) + get regExp(): RegExp | undefined; + set regExp(val: RegExp | undefined); + // (undocumented) + get request(): string; + set request(val: string); +} + +// @public (undocumented) +type ContextModuleFactoryBeforeResolveResult = false | ContextModuleFactoryBeforeResolveData; // @public (undocumented) export const ContextReplacementPlugin: { @@ -1866,10 +1888,16 @@ class DependenciesBlock { // @public (undocumented) class Dependency { - constructor(binding: DependencyDTO); + // (undocumented) + static __drop(dependency: Dependency): void; + // (undocumented) + static __from_binding(binding: JsDependency | JsCompiledDependency): Dependency; // (undocumented) get category(): string; // (undocumented) + get critital(): boolean | undefined; + set critital(critital: boolean | undefined); + // (undocumented) get request(): string | undefined; // (undocumented) get type(): string; diff --git a/packages/rspack/src/Dependency.ts b/packages/rspack/src/Dependency.ts index 2c037d147e8..3eb8be9860d 100644 --- a/packages/rspack/src/Dependency.ts +++ b/packages/rspack/src/Dependency.ts @@ -1,4 +1,4 @@ -import { JsDependency, JsCompiledDependency } from "@rspack/binding"; +import { type JsCompiledDependency, JsDependency } from "@rspack/binding"; export class Dependency { #binding: JsDependency | JsCompiledDependency; diff --git a/packages/rspack/src/Module.ts b/packages/rspack/src/Module.ts index 8b38314d547..20e782d366d 100644 --- a/packages/rspack/src/Module.ts +++ b/packages/rspack/src/Module.ts @@ -126,7 +126,6 @@ export class ContextModuleFactoryAfterResolveData { #inner: JsContextModuleFactoryAfterResolveData; #resolvedDependencies?: Dependency[]; #dropped = false; - #dropWarningMessage?: string; static __from_binding(binding: JsContextModuleFactoryAfterResolveData) { return new ContextModuleFactoryAfterResolveData(binding); @@ -141,17 +140,16 @@ export class ContextModuleFactoryAfterResolveData { static __drop(data: ContextModuleFactoryAfterResolveData) { data.#dropped = true; if (data.#resolvedDependencies) { - data.#resolvedDependencies.forEach(dependency => - Dependency.__drop(dependency) - ); + for (const dependency of data.#resolvedDependencies) { + Dependency.__drop(dependency); + } } } private ensureValidLifecycle() { if (this.#dropped) { throw new Error( - this.#dropWarningMessage ?? - "The ContextModuleFactoryAfterResolveData has exceeded its lifecycle and has been dropped by Rust." + "The ContextModuleFactoryAfterResolveData has exceeded its lifecycle and has been dropped by Rust." ); } }