From 9c8fa220af3f85dc7d4d75a6bac676dc21434209 Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 7 Nov 2024 16:00:47 +0800 Subject: [PATCH] feat: supp --- packages/rspack/src/Compiler.ts | 866 ++++++++++++++++++++++---------- 1 file changed, 588 insertions(+), 278 deletions(-) diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index d16e530b3301..a0205b270da3 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -773,63 +773,124 @@ class Compiler { this.#registers = { registerCompilerThisCompilationTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerThisCompilation, - () => that.deref()!.hooks.thisCompilation, - queried => (native: binding.JsCompilation) => { - that.deref()!.#createCompilation(native); - return queried.call( - that.deref()!.#compilation!, - that.deref()!.#compilationParams! - ); + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.hooks.thisCompilation; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function (native: binding.JsCompilation) { + that.deref()!.#createCompilation(native); + return queried.call( + that.deref()!.#compilation!, + that.deref()!.#compilationParams! + ); + }; } ), registerCompilerCompilationTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerCompilation, - () => that.deref()!.hooks.compilation, - queried => () => - queried.call( - that.deref()!.#compilation!, - that.deref()!.#compilationParams! - ) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.hooks.compilation; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function () { + return queried.call( + that.deref()!.#compilation!, + that.deref()!.#compilationParams! + ); + }; + } ), registerCompilerMakeTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerMake, - () => that.deref()!.hooks.make, - queried => async () => - await queried.promise(that.deref()!.#compilation!) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.hooks.make; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function () { + return await queried.promise(that.deref()!.#compilation!); + }; + } ), registerCompilerFinishMakeTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerFinishMake, - () => that.deref()!.hooks.finishMake, - queried => async () => - await queried.promise(that.deref()!.#compilation!) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.hooks.finishMake; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function () { + return await queried.promise(that.deref()!.#compilation!); + }; + } ), registerCompilerShouldEmitTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerShouldEmit, - () => that.deref()!.hooks.shouldEmit, - queried => () => queried.call(that.deref()!.#compilation!) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.hooks.shouldEmit; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function () { + return queried.call(that.deref()!.#compilation!); + }; + } ), registerCompilerEmitTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerEmit, - () => that.deref()!.hooks.emit, - queried => async () => - await queried.promise(that.deref()!.#compilation!) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.hooks.emit; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function () { + return await queried.promise(that.deref()!.#compilation!); + }; + } ), registerCompilerAfterEmitTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerAfterEmit, - () => that.deref()!.hooks.afterEmit, - queried => async () => - await queried.promise(that.deref()!.#compilation!) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.hooks.afterEmit; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function () { + return await queried.promise(that.deref()!.#compilation!); + }; + } ), registerCompilerAssetEmittedTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerAssetEmitted, - () => that.deref()!.hooks.assetEmitted, - queried => - async ({ + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.hooks.assetEmitted; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function ({ filename, targetPath, outputPath - }: binding.JsAssetEmittedArgs) => - queried.promise(filename, { + }: binding.JsAssetEmittedArgs) { + return queried.promise(filename, { compilation: that.deref()!.#compilation!, targetPath, outputPath, @@ -839,19 +900,26 @@ class Compiler { get content() { return this.source?.buffer(); } - }) + }); + }; + } ), registerCompilationAdditionalTreeRuntimeRequirements: this.#createHookRegisterTaps( binding.RegisterJsTapKind .CompilationAdditionalTreeRuntimeRequirements, - () => - that.deref()!.#compilation!.hooks.additionalTreeRuntimeRequirements, - queried => - ({ + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks + .additionalTreeRuntimeRequirements; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function ({ chunk, runtimeRequirements - }: binding.JsAdditionalTreeRuntimeRequirementsArg) => { + }: binding.JsAdditionalTreeRuntimeRequirementsArg) { const set = __from_binding_runtime_globals(runtimeRequirements); queried.call( Chunk.__from_binding(chunk, that.deref()!.#compilation!), @@ -860,17 +928,23 @@ class Compiler { return { runtimeRequirements: __to_binding_runtime_globals(set) }; - } + }; + } ), registerCompilationRuntimeRequirementInTree: this.#createHookMapRegisterTaps( binding.RegisterJsTapKind.CompilationRuntimeRequirementInTree, - () => that.deref()!.#compilation!.hooks.runtimeRequirementInTree, - queried => - ({ + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.runtimeRequirementInTree; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function ({ chunk: rawChunk, runtimeRequirements - }: binding.JsRuntimeRequirementInTreeArg) => { + }: binding.JsRuntimeRequirementInTreeArg) { const set = __from_binding_runtime_globals(runtimeRequirements); const chunk = Chunk.__from_binding( rawChunk, @@ -882,13 +956,19 @@ class Compiler { return { runtimeRequirements: __to_binding_runtime_globals(set) }; - } + }; + } ), registerCompilationRuntimeModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationRuntimeModule, - () => that.deref()!.#compilation!.hooks.runtimeModule, - queried => - ({ module, chunk }: binding.JsRuntimeModuleArg) => { + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.runtimeModule; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function ({ module, chunk }: binding.JsRuntimeModuleArg) { const originSource = module.source?.source; queried.call( module, @@ -899,36 +979,72 @@ class Compiler { return module; } return; - } + }; + } ), registerCompilationBuildModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationBuildModule, - () => that.deref()!.#compilation!.hooks.buildModule, - queired => (m: binding.JsModule) => - queired.call(Module.__from_binding(m, that.deref()!.#compilation)) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.buildModule; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function (m: binding.JsModule) { + return queried.call( + Module.__from_binding(m, that.deref()!.#compilation) + ); + }; + } ), registerCompilationStillValidModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationStillValidModule, - () => that.deref()!.#compilation!.hooks.stillValidModule, - queired => (m: binding.JsModule) => - queired.call(Module.__from_binding(m, that.deref()!.#compilation)) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.stillValidModule; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function (m: binding.JsModule) { + return queried.call( + Module.__from_binding(m, that.deref()!.#compilation) + ); + }; + } ), registerCompilationSucceedModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationSucceedModule, - () => that.deref()!.#compilation!.hooks.succeedModule, - queired => (m: binding.JsModule) => - queired.call(Module.__from_binding(m, that.deref()!.#compilation)) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.succeedModule; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function (m: binding.JsModule) { + return queried.call( + Module.__from_binding(m, that.deref()!.#compilation) + ); + }; + } ), registerCompilationExecuteModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationExecuteModule, - () => that.deref()!.#compilation!.hooks.executeModule, - queried => - ({ + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.executeModule; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function ({ entry, id, codegenResults, runtimeModules - }: binding.JsExecuteModuleArg) => { + }: binding.JsExecuteModuleArg) { const __webpack_require__: any = (id: string) => { const cached = moduleCache[id]; if (cached !== undefined) { @@ -992,101 +1108,223 @@ class Compiler { const executeResult = __webpack_require__(entry); that.deref()!.#moduleExecutionResultsMap.set(id, executeResult); - } + }; + } ), registerCompilationFinishModulesTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationFinishModules, - () => that.deref()!.#compilation!.hooks.finishModules, - queried => async () => - await queried.promise(that.deref()!.#compilation!.modules) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.finishModules; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function () { + return await queried.promise(that.deref()!.#compilation!.modules); + }; + } ), registerCompilationOptimizeModulesTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationOptimizeModules, - () => that.deref()!.#compilation!.hooks.optimizeModules, - queried => () => - queried.call(that.deref()!.#compilation!.modules.values()) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.optimizeModules; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function () { + return queried.call(that.deref()!.#compilation!.modules.values()); + }; + } ), registerCompilationAfterOptimizeModulesTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationAfterOptimizeModules, - () => that.deref()!.#compilation!.hooks.afterOptimizeModules, - queried => () => { - queried.call(that.deref()!.#compilation!.modules.values()); + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.afterOptimizeModules; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function () { + queried.call(that.deref()!.#compilation!.modules.values()); + }; } ), registerCompilationOptimizeTreeTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationOptimizeTree, - () => that.deref()!.#compilation!.hooks.optimizeTree, - queried => async () => - await queried.promise( - that.deref()!.#compilation!.chunks, - that.deref()!.#compilation!.modules - ) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.optimizeTree; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function () { + return await queried.promise( + that.deref()!.#compilation!.chunks, + that.deref()!.#compilation!.modules + ); + }; + } ), registerCompilationOptimizeChunkModulesTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationOptimizeChunkModules, - () => that.deref()!.#compilation!.hooks.optimizeChunkModules, - queried => async () => - await queried.promise( - that.deref()!.#compilation!.chunks, - that.deref()!.#compilation!.modules - ) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.optimizeChunkModules; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function () { + return await queried.promise( + that.deref()!.#compilation!.chunks, + that.deref()!.#compilation!.modules + ); + }; + } ), registerCompilationChunkHashTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationChunkHash, - () => that.deref()!.#compilation!.hooks.chunkHash, - queried => (chunk: binding.JsChunk) => { - if (!that.deref()!.options.output.hashFunction) { - throw new Error("'output.hashFunction' cannot be undefined"); - } - const hash = createHash(that.deref()!.options.output.hashFunction!); - queried.call( - Chunk.__from_binding(chunk, that.deref()!.#compilation!), - hash - ); - const digestResult = hash.digest( - that.deref()!.options.output.hashDigest - ); - return Buffer.from(digestResult); + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.chunkHash; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function (chunk: binding.JsChunk) { + if (!that.deref()!.options.output.hashFunction) { + throw new Error("'output.hashFunction' cannot be undefined"); + } + const hash = createHash(that.deref()!.options.output.hashFunction!); + queried.call( + Chunk.__from_binding(chunk, that.deref()!.#compilation!), + hash + ); + const digestResult = hash.digest( + that.deref()!.options.output.hashDigest + ); + return Buffer.from(digestResult); + }; } ), registerCompilationChunkAssetTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationChunkAsset, - () => that.deref()!.#compilation!.hooks.chunkAsset, - queried => - ({ chunk, filename }: binding.JsChunkAssetArgs) => - queried.call( + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.chunkAsset; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function ({ chunk, filename }: binding.JsChunkAssetArgs) { + return queried.call( Chunk.__from_binding(chunk, that.deref()!.#compilation!), filename - ) + ); + }; + } ), registerCompilationProcessAssetsTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationProcessAssets, - () => that.deref()!.#compilation!.hooks.processAssets, - queried => async () => - await queried.promise(that.deref()!.#compilation!.assets) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.processAssets; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function () { + return await queried.promise(that.deref()!.#compilation!.assets); + }; + } ), registerCompilationAfterProcessAssetsTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationAfterProcessAssets, - () => that.deref()!.#compilation!.hooks.afterProcessAssets, - queried => () => queried.call(that.deref()!.#compilation!.assets) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.afterProcessAssets; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function () { + return queried.call(that.deref()!.#compilation!.assets); + }; + } ), registerCompilationSealTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationSeal, - () => that.deref()!.#compilation!.hooks.seal, - queried => () => queried.call() + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.seal; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function () { + return queried.call(); + }; + } ), registerCompilationAfterSealTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationAfterSeal, - () => that.deref()!.#compilation!.hooks.afterSeal, - queried => async () => await queried.promise() + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilation!.hooks.afterSeal; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function () { + return await queried.promise(); + }; + } ), registerNormalModuleFactoryBeforeResolveTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.NormalModuleFactoryBeforeResolve, - () => - that.deref()!.#compilationParams!.normalModuleFactory.hooks - .beforeResolve, - queried => async (resolveData: binding.JsBeforeResolveArgs) => { + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilationParams!.normalModuleFactory.hooks + .beforeResolve; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function (resolveData: binding.JsBeforeResolveArgs) { + const normalizedResolveData: ResolveData = { + contextInfo: { + issuer: resolveData.issuer + }, + request: resolveData.request, + context: resolveData.context, + fileDependencies: [], + missingDependencies: [], + contextDependencies: [] + }; + const ret = await queried.promise(normalizedResolveData); + resolveData.request = normalizedResolveData.request; + resolveData.context = normalizedResolveData.context; + return [ret, resolveData]; + }; + } + ), + registerNormalModuleFactoryFactorizeTaps: this.#createHookRegisterTaps( + binding.RegisterJsTapKind.NormalModuleFactoryFactorize, + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilationParams!.normalModuleFactory.hooks + .factorize; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function (resolveData: binding.JsFactorizeArgs) { const normalizedResolveData: ResolveData = { contextInfo: { issuer: resolveData.issuer @@ -1097,114 +1335,124 @@ class Compiler { missingDependencies: [], contextDependencies: [] }; - const ret = await queried.promise(normalizedResolveData); + await queried.promise(normalizedResolveData); resolveData.request = normalizedResolveData.request; resolveData.context = normalizedResolveData.context; - return [ret, resolveData]; - } - ), - registerNormalModuleFactoryFactorizeTaps: this.#createHookRegisterTaps( - binding.RegisterJsTapKind.NormalModuleFactoryFactorize, - () => - that.deref()!.#compilationParams!.normalModuleFactory.hooks.factorize, - queried => async (resolveData: binding.JsFactorizeArgs) => { - const normalizedResolveData: ResolveData = { - contextInfo: { - issuer: resolveData.issuer - }, - request: resolveData.request, - context: resolveData.context, - fileDependencies: [], - missingDependencies: [], - contextDependencies: [] + return resolveData; }; - await queried.promise(normalizedResolveData); - resolveData.request = normalizedResolveData.request; - resolveData.context = normalizedResolveData.context; - return resolveData; } ), registerNormalModuleFactoryResolveTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.NormalModuleFactoryResolve, - () => - that.deref()!.#compilationParams!.normalModuleFactory.hooks.resolve, - queried => async (resolveData: binding.JsFactorizeArgs) => { - const normalizedResolveData: ResolveData = { - contextInfo: { - issuer: resolveData.issuer - }, - request: resolveData.request, - context: resolveData.context, - fileDependencies: [], - missingDependencies: [], - contextDependencies: [] + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilationParams!.normalModuleFactory.hooks + .resolve; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function (resolveData: binding.JsFactorizeArgs) { + const normalizedResolveData: ResolveData = { + contextInfo: { + issuer: resolveData.issuer + }, + request: resolveData.request, + context: resolveData.context, + fileDependencies: [], + missingDependencies: [], + contextDependencies: [] + }; + await queried.promise(normalizedResolveData); + resolveData.request = normalizedResolveData.request; + resolveData.context = normalizedResolveData.context; + return resolveData; }; - await queried.promise(normalizedResolveData); - resolveData.request = normalizedResolveData.request; - resolveData.context = normalizedResolveData.context; - return resolveData; } ), registerNormalModuleFactoryResolveForSchemeTaps: this.#createHookMapRegisterTaps( binding.RegisterJsTapKind.NormalModuleFactoryResolveForScheme, - () => - that.deref()!.#compilationParams!.normalModuleFactory.hooks - .resolveForScheme, - queried => async (args: binding.JsResolveForSchemeArgs) => { - const ret = await queried - .for(args.scheme) - .promise(args.resourceData); - return [ret, args.resourceData]; + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilationParams!.normalModuleFactory.hooks + .resolveForScheme; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function (args: binding.JsResolveForSchemeArgs) { + const ret = await queried + .for(args.scheme) + .promise(args.resourceData); + return [ret, args.resourceData]; + }; } ), registerNormalModuleFactoryAfterResolveTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.NormalModuleFactoryAfterResolve, - () => - that.deref()!.#compilationParams!.normalModuleFactory.hooks - .afterResolve, - queried => async (arg: binding.JsAfterResolveData) => { - const data: ResolveData = { - contextInfo: { - issuer: arg.issuer - }, - request: arg.request, - context: arg.context, - fileDependencies: arg.fileDependencies, - missingDependencies: arg.missingDependencies, - contextDependencies: arg.contextDependencies, - createData: arg.createData + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilationParams!.normalModuleFactory.hooks + .afterResolve; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function (arg: binding.JsAfterResolveData) { + const data: ResolveData = { + contextInfo: { + issuer: arg.issuer + }, + request: arg.request, + context: arg.context, + fileDependencies: arg.fileDependencies, + missingDependencies: arg.missingDependencies, + contextDependencies: arg.contextDependencies, + createData: arg.createData + }; + const ret = await queried.promise(data); + return [ret, data.createData]; }; - const ret = await queried.promise(data); - return [ret, data.createData]; } ), registerNormalModuleFactoryCreateModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.NormalModuleFactoryCreateModule, - () => - that.deref()!.#compilationParams!.normalModuleFactory.hooks - .createModule, - queried => - async (args: binding.JsNormalModuleFactoryCreateModuleArgs) => { + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilationParams!.normalModuleFactory.hooks + .createModule; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function ( + args: binding.JsNormalModuleFactoryCreateModuleArgs + ) { const data: NormalModuleCreateData = { ...args, settings: {} }; await queried.promise(data, {}); - } + }; + } ), registerContextModuleFactoryBeforeResolveTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.ContextModuleFactoryBeforeResolve, - () => - that.deref()!.#compilationParams!.contextModuleFactory.hooks - .beforeResolve, - queried => - async ( + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilationParams!.contextModuleFactory.hooks + .beforeResolve; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function ( bindingData: | false | binding.JsContextModuleFactoryBeforeResolveData - ) => { + ) { const data = bindingData ? ContextModuleFactoryBeforeResolveData.__from_binding( bindingData @@ -1214,20 +1462,25 @@ class Compiler { return result ? ContextModuleFactoryBeforeResolveData.__to_binding(result) : false; - } + }; + } ), registerContextModuleFactoryAfterResolveTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.ContextModuleFactoryAfterResolve, - () => - that.deref()!.#compilationParams!.contextModuleFactory.hooks - .afterResolve, - queried => - async ( + // biome-ignore lint/complexity/useArrowFunction: + function () { + return that.deref()!.#compilationParams!.contextModuleFactory.hooks + .afterResolve; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function ( bindingData: | false | binding.JsContextModuleFactoryAfterResolveData - ) => { + ) { const data = bindingData ? ContextModuleFactoryAfterResolveData.__from_binding( bindingData @@ -1237,37 +1490,92 @@ class Compiler { return result ? ContextModuleFactoryAfterResolveData.__to_binding(result) : false; - } + }; + } ), registerJavascriptModulesChunkHashTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.JavascriptModulesChunkHash, - () => - JavascriptModulesPlugin.getCompilationHooks( + // biome-ignore lint/complexity/useArrowFunction: + function () { + return JavascriptModulesPlugin.getCompilationHooks( that.deref()!.#compilation! - ).chunkHash, - queried => (chunk: binding.JsChunk) => { - if (!that.deref()!.options.output.hashFunction) { - throw new Error("'output.hashFunction' cannot be undefined"); - } - const hash = createHash(that.deref()!.options.output.hashFunction!); - queried.call( - Chunk.__from_binding(chunk, that.deref()!.#compilation!), - hash - ); - const digestResult = hash.digest( - that.deref()!.options.output.hashDigest - ); - return Buffer.from(digestResult); + ).chunkHash; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return function (chunk: binding.JsChunk) { + if (!that.deref()!.options.output.hashFunction) { + throw new Error("'output.hashFunction' cannot be undefined"); + } + const hash = createHash(that.deref()!.options.output.hashFunction!); + queried.call( + Chunk.__from_binding(chunk, that.deref()!.#compilation!), + hash + ); + const digestResult = hash.digest( + that.deref()!.options.output.hashDigest + ); + return Buffer.from(digestResult); + }; } ), registerHtmlPluginBeforeAssetTagGenerationTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.HtmlPluginBeforeAssetTagGeneration, - () => - HtmlRspackPlugin.getCompilationHooks(that.deref()!.#compilation!) - .beforeAssetTagGeneration, - queried => async (data: binding.JsBeforeAssetTagGenerationData) => - await queried.promise({ + // biome-ignore lint/complexity/useArrowFunction: + function () { + return HtmlRspackPlugin.getCompilationHooks( + that.deref()!.#compilation! + ).beforeAssetTagGeneration; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function ( + data: binding.JsBeforeAssetTagGenerationData + ) { + return await queried.promise({ + ...data, + plugin: { + options: + HtmlRspackPlugin.getCompilationOptions( + that.deref()!.#compilation! + ) || {} + } + }); + }; + } + ), + registerHtmlPluginAlterAssetTagsTaps: this.#createHookRegisterTaps( + binding.RegisterJsTapKind.HtmlPluginAlterAssetTags, + // biome-ignore lint/complexity/useArrowFunction: + function () { + return HtmlRspackPlugin.getCompilationHooks( + that.deref()!.#compilation! + ).alterAssetTags; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function (data: binding.JsAlterAssetTagsData) { + return await queried.promise(data); + }; + } + ), + registerHtmlPluginAlterAssetTagGroupsTaps: this.#createHookRegisterTaps( + binding.RegisterJsTapKind.HtmlPluginAlterAssetTagGroups, + // biome-ignore lint/complexity/useArrowFunction: + function () { + return HtmlRspackPlugin.getCompilationHooks( + that.deref()!.#compilation! + ).alterAssetTagGroups; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function (data: binding.JsAlterAssetTagGroupsData) { + return await queried.promise({ ...data, plugin: { options: @@ -1275,40 +1583,48 @@ class Compiler { that.deref()!.#compilation! ) || {} } - }) - ), - registerHtmlPluginAlterAssetTagsTaps: this.#createHookRegisterTaps( - binding.RegisterJsTapKind.HtmlPluginAlterAssetTags, - () => - HtmlRspackPlugin.getCompilationHooks(that.deref()!.#compilation!) - .alterAssetTags, - queried => async (data: binding.JsAlterAssetTagsData) => - await queried.promise(data) - ), - registerHtmlPluginAlterAssetTagGroupsTaps: this.#createHookRegisterTaps( - binding.RegisterJsTapKind.HtmlPluginAlterAssetTagGroups, - () => - HtmlRspackPlugin.getCompilationHooks(that.deref()!.#compilation!) - .alterAssetTagGroups, - queried => async (data: binding.JsAlterAssetTagGroupsData) => - await queried.promise({ - ...data, - plugin: { - options: - HtmlRspackPlugin.getCompilationOptions( - that.deref()!.#compilation! - ) || {} - } - }) + }); + }; + } ), registerHtmlPluginAfterTemplateExecutionTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.HtmlPluginAfterTemplateExecution, - () => - HtmlRspackPlugin.getCompilationHooks(that.deref()!.#compilation!) - .afterTemplateExecution, - queried => async (data: binding.JsAfterTemplateExecutionData) => - await queried.promise({ + // biome-ignore lint/complexity/useArrowFunction: + function () { + return HtmlRspackPlugin.getCompilationHooks( + that.deref()!.#compilation! + ).afterTemplateExecution; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function (data: binding.JsAfterTemplateExecutionData) { + return await queried.promise({ + ...data, + plugin: { + options: + HtmlRspackPlugin.getCompilationOptions( + that.deref()!.#compilation! + ) || {} + } + }); + }; + } + ), + registerHtmlPluginBeforeEmitTaps: this.#createHookRegisterTaps( + binding.RegisterJsTapKind.HtmlPluginBeforeEmit, + // biome-ignore lint/complexity/useArrowFunction: + function () { + return HtmlRspackPlugin.getCompilationHooks( + that.deref()!.#compilation! + ).beforeEmit; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function (data: binding.JsBeforeEmitData) { + return await queried.promise({ ...data, plugin: { options: @@ -1316,39 +1632,33 @@ class Compiler { that.deref()!.#compilation! ) || {} } - }) - ), - registerHtmlPluginBeforeEmitTaps: this.#createHookRegisterTaps( - binding.RegisterJsTapKind.HtmlPluginBeforeEmit, - () => - HtmlRspackPlugin.getCompilationHooks(that.deref()!.#compilation!) - .beforeEmit, - queried => async (data: binding.JsBeforeEmitData) => - await queried.promise({ - ...data, - plugin: { - options: - HtmlRspackPlugin.getCompilationOptions( - that.deref()!.#compilation! - ) || {} - } - }) + }); + }; + } ), registerHtmlPluginAfterEmitTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.HtmlPluginAfterEmit, - () => - HtmlRspackPlugin.getCompilationHooks(that.deref()!.#compilation!) - .afterEmit, - queried => async (data: binding.JsAfterEmitData) => - await queried.promise({ - ...data, - plugin: { - options: - HtmlRspackPlugin.getCompilationOptions( - that.deref()!.#compilation! - ) || {} - } - }) + // biome-ignore lint/complexity/useArrowFunction: + function () { + return HtmlRspackPlugin.getCompilationHooks( + that.deref()!.#compilation! + ).afterEmit; + }, + // biome-ignore lint/complexity/useArrowFunction: + function (queried) { + // biome-ignore lint/complexity/useArrowFunction: + return async function (data: binding.JsAfterEmitData) { + return await queried.promise({ + ...data, + plugin: { + options: + HtmlRspackPlugin.getCompilationOptions( + that.deref()!.#compilation! + ) || {} + } + }); + }; + } ) };