diff --git a/packages/rspack/etc/core.api.md b/packages/rspack/etc/core.api.md index 44c0b52eaee..3b3f0b1675b 100644 --- a/packages/rspack/etc/core.api.md +++ b/packages/rspack/etc/core.api.md @@ -153,9 +153,9 @@ interface AssetEmittedInfo { export type AssetGeneratorDataUrl = AssetGeneratorDataUrlOptions | AssetGeneratorDataUrlFunction; // @public (undocumented) -export type AssetGeneratorDataUrlFunction = (content: Buffer, context: { +export type AssetGeneratorDataUrlFunction = (options: { filename: string; - module: Module; + content: string; }) => string; // @public (undocumented) @@ -181,9 +181,6 @@ export type AssetInlineGeneratorOptions = { // @public export type AssetModuleFilename = Filename; -// @public -export type AssetModuleOutputPath = Filename; - // @public export type AssetParserDataUrl = AssetParserDataUrlOptions; @@ -201,7 +198,6 @@ export type AssetParserOptions = { export type AssetResourceGeneratorOptions = { emit?: boolean; filename?: Filename; - outputPath?: AssetModuleOutputPath; publicPath?: PublicPath; }; @@ -597,8 +593,6 @@ export class Compilation { // @internal __internal_getInner(): binding.JsCompilation; // (undocumented) - addInclude(context: string, dependency: ReturnType, options: EntryOptions, callback: (err?: null | WebpackError_2, module?: Module) => void): void; - // (undocumented) addRuntimeModule(chunk: Chunk, runtimeModule: RuntimeModule): void; get assets(): Record; // (undocumented) @@ -1640,12 +1634,6 @@ class EntryData { options: binding.JsEntryOptions; } -// @public (undocumented) -interface EntryDependency { - // (undocumented) - request: string; -} - // @public export type EntryDependOn = string | string[]; @@ -1703,12 +1691,15 @@ export type EntryOptions = Omit & { name?: string; }; -// @public (undocumented) -export const EntryPlugin: EntryPluginType; - -// @public (undocumented) -type EntryPluginType = typeof OriginEntryPlugin & { - createDependency(entry: string): EntryDependency; +// @public +export const EntryPlugin: { + new (context: string, entry: string, options?: string | EntryOptions | undefined): { + name: BuiltinPluginName; + _args: [context: string, entry: string, options?: string | EntryOptions | undefined]; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "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; + apply(compiler: Compiler_2): void; + }; }; // @public (undocumented) @@ -1938,7 +1929,7 @@ export type ExperimentCacheOptions = boolean | { unmanagedPaths?: Array; managedPaths?: Array; }; - storage?: { + storage: { type: "filesystem"; directory?: string; }; @@ -4144,7 +4135,7 @@ type OptimizationSplitChunksChunks = "initial" | "async" | "all" | RegExp | ((ch type OptimizationSplitChunksName = string | false | OptimizationSplitChunksNameFunction; // @public (undocumented) -export type OptimizationSplitChunksNameFunction = (module?: Module) => unknown; +export type OptimizationSplitChunksNameFunction = (module?: Module, chunks?: Chunk[]) => unknown; // @public export type OptimizationSplitChunksOptions = { @@ -4188,17 +4179,6 @@ interface OptimizerConfig { simplify?: boolean; } -// @public -const OriginEntryPlugin: { - new (context: string, entry: string, options?: string | EntryOptions | undefined): { - name: BuiltinPluginName; - _args: [context: string, entry: string, options?: string | EntryOptions | undefined]; - affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "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; - apply(compiler: Compiler_2): void; - }; -}; - // @public (undocumented) export type Output = { path?: Path; @@ -5320,7 +5300,6 @@ declare namespace rspackExports { AssetGeneratorDataUrlFunction, AssetGeneratorDataUrl, AssetInlineGeneratorOptions, - AssetModuleOutputPath, AssetResourceGeneratorOptions, AssetGeneratorOptions, CssGeneratorExportsConvention, @@ -6269,18 +6248,22 @@ export const rspackOptions: z.ZodObject<{ unmanagedPaths?: (string | RegExp)[] | undefined; managedPaths?: (string | RegExp)[] | undefined; }>>; - storage: z.ZodOptional; directory: z.ZodOptional; - }, "strip", z.ZodTypeAny, { + }, "strict", z.ZodTypeAny, { type: "filesystem"; directory?: string | undefined; }, { type: "filesystem"; directory?: string | undefined; - }>>; + }>; }, "strip", z.ZodTypeAny, { type: "persistent"; + storage: { + type: "filesystem"; + directory?: string | undefined; + }; version?: string | undefined; snapshot?: { immutablePaths?: (string | RegExp)[] | undefined; @@ -6288,12 +6271,12 @@ export const rspackOptions: z.ZodObject<{ managedPaths?: (string | RegExp)[] | undefined; } | undefined; buildDependencies?: string[] | undefined; - storage?: { - type: "filesystem"; - directory?: string | undefined; - } | undefined; }, { type: "persistent"; + storage: { + type: "filesystem"; + directory?: string | undefined; + }; version?: string | undefined; snapshot?: { immutablePaths?: (string | RegExp)[] | undefined; @@ -6301,10 +6284,6 @@ export const rspackOptions: z.ZodObject<{ managedPaths?: (string | RegExp)[] | undefined; } | undefined; buildDependencies?: string[] | undefined; - storage?: { - type: "filesystem"; - directory?: string | undefined; - } | undefined; }>]>]>; lazyCompilation: z.ZodUnion<[z.ZodOptional, z.ZodObject<{ backend: z.ZodOptional, z.ZodFunction, z.ZodObject<{ + }>, z.ZodFunction; }, "strict", z.ZodTypeAny, { - module: Module; + content: string; filename: string; }, { - module: Module; + content: string; filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; }, { @@ -7809,8 +7788,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; emit?: boolean | undefined; @@ -7820,8 +7799,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; emit?: boolean | undefined; @@ -7836,30 +7815,30 @@ export const rspackOptions: z.ZodObject<{ }, { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - }>, z.ZodFunction, z.ZodObject<{ + }>, z.ZodFunction; }, "strict", z.ZodTypeAny, { - module: Module; + content: string; filename: string; }, { - module: Module; + content: string; filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; }, "strict", z.ZodTypeAny, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; }, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; }>>; @@ -7929,8 +7908,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; emit?: boolean | undefined; @@ -7951,8 +7930,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; } | undefined; @@ -7972,8 +7951,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; emit?: boolean | undefined; @@ -7994,8 +7973,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; } | undefined; @@ -8120,8 +8099,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; emit?: boolean | undefined; @@ -8142,8 +8121,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; } | undefined; @@ -8268,8 +8247,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; emit?: boolean | undefined; @@ -8290,8 +8269,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; } | undefined; @@ -8437,8 +8416,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; emit?: boolean | undefined; @@ -8459,8 +8438,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; } | undefined; @@ -8490,6 +8469,10 @@ export const rspackOptions: z.ZodObject<{ type: "memory"; } | { type: "persistent"; + storage: { + type: "filesystem"; + directory?: string | undefined; + }; version?: string | undefined; snapshot?: { immutablePaths?: (string | RegExp)[] | undefined; @@ -8497,10 +8480,6 @@ export const rspackOptions: z.ZodObject<{ managedPaths?: (string | RegExp)[] | undefined; } | undefined; buildDependencies?: string[] | undefined; - storage?: { - type: "filesystem"; - directory?: string | undefined; - } | undefined; } | undefined; topLevelAwait?: boolean | undefined; layers?: boolean | undefined; @@ -9039,8 +9018,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; emit?: boolean | undefined; @@ -9061,8 +9040,8 @@ export const rspackOptions: z.ZodObject<{ dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; - } | ((args_0: Buffer, args_1: { - module: Module; + } | ((args_0: { + content: string; filename: string; }, ...args: unknown[]) => string) | undefined; } | undefined; @@ -9092,6 +9071,10 @@ export const rspackOptions: z.ZodObject<{ type: "memory"; } | { type: "persistent"; + storage: { + type: "filesystem"; + directory?: string | undefined; + }; version?: string | undefined; snapshot?: { immutablePaths?: (string | RegExp)[] | undefined; @@ -9099,10 +9082,6 @@ export const rspackOptions: z.ZodObject<{ managedPaths?: (string | RegExp)[] | undefined; } | undefined; buildDependencies?: string[] | undefined; - storage?: { - type: "filesystem"; - directory?: string | undefined; - } | undefined; } | undefined; topLevelAwait?: boolean | undefined; layers?: boolean | undefined; @@ -10465,7 +10444,6 @@ declare namespace t { AssetGeneratorDataUrlFunction, AssetGeneratorDataUrl, AssetInlineGeneratorOptions, - AssetModuleOutputPath, AssetResourceGeneratorOptions, AssetGeneratorOptions, CssGeneratorExportsConvention, diff --git a/packages/rspack/src/config/types.ts b/packages/rspack/src/config/types.ts index 879843399e4..6dd3d1571a7 100644 --- a/packages/rspack/src/config/types.ts +++ b/packages/rspack/src/config/types.ts @@ -2067,7 +2067,11 @@ export type OptimizationRuntimeChunk = name?: string | ((value: { name: string }) => string); }; -export type OptimizationSplitChunksNameFunction = (module?: Module) => unknown; +export type OptimizationSplitChunksNameFunction = ( + module: Module, + chunks: Chunk[], + cacheGroupKey: string +) => string | undefined; type OptimizationSplitChunksName = | string diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index 1efac5c3f03..2e81bdb09ff 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -1171,11 +1171,12 @@ const optimizationRuntimeChunk = z }) ) satisfies z.ZodType; -const optimizationSplitChunksNameFunction = z.function().args( - z.instanceof(Module).optional() - // FIXME: z.array(z.instanceof(Chunk)).optional(), z.string() - // FIXME: Chunk[], cacheChunkKey -) satisfies z.ZodType; +const optimizationSplitChunksNameFunction = z + .function() + .args(z.instanceof(Module), z.array(z.instanceof(Chunk)), z.string()) + .returns( + z.string().optional() + ) satisfies z.ZodType; const optimizationSplitChunksName = z .string()