/** * The following code is modified based on * https://github.com/webpack/webpack/blob/4b4ca3bb53f36a5b8fc6bc1bd976ed7af161bd80/lib/Compiler.js * * MIT Licensed * Author Tobias Koppers @sokra * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack/blob/main/LICENSE */ import type binding from '@rspack/binding'; import * as liteTapable from '../compiled/@rspack/lite-tapable/dist/index.js'; import type Watchpack from '../compiled/watchpack/index.js'; import type { Source } from '../compiled/webpack-sources/types.js'; import type { Chunk } from './Chunk.js'; import type { CompilationParams } from './Compilation.js'; import { Compilation } from './Compilation.js'; import { ContextModuleFactory } from './ContextModuleFactory.js'; import type { EntryNormalized, OutputNormalized, RspackOptionsNormalized, RspackPluginInstance } from './config/index.js'; import type { ExtractedTargetProperties, PlatformTargetProperties } from './config/target.js'; import type { FileSystemInfoEntry } from './FileSystemInfo.js'; import type { rspack } from './index.js'; import Cache from './lib/Cache.js'; import CacheFacade from './lib/CacheFacade.js'; import { Logger } from './logging/Logger.js'; import { NormalModuleFactory } from './NormalModuleFactory.js'; import { ResolverFactory } from './ResolverFactory.js'; import { RuleSetCompiler } from './RuleSetCompiler.js'; import { Stats } from './Stats.js'; import type { InputFileSystem, IntermediateFileSystem, OutputFileSystem, WatchFileSystem } from './util/fs.js'; import { Watching } from './Watching.js'; export interface AssetEmittedInfo { content: Buffer; source: Source; outputPath: string; targetPath: string; compilation: Compilation; } export type CompilerHooks = { done: liteTapable.AsyncSeriesHook; afterDone: liteTapable.SyncHook; thisCompilation: liteTapable.SyncHook<[Compilation, CompilationParams]>; compilation: liteTapable.SyncHook<[Compilation, CompilationParams]>; invalid: liteTapable.SyncHook<[string | null, number]>; compile: liteTapable.SyncHook<[CompilationParams]>; normalModuleFactory: liteTapable.SyncHook; contextModuleFactory: liteTapable.SyncHook; initialize: liteTapable.SyncHook<[]>; shouldEmit: liteTapable.SyncBailHook<[Compilation], boolean>; /** * Called when infrastructure logging is triggered, allowing plugins to intercept, modify, or handle log messages. * If the hook returns `true`, the default infrastructure logging will be prevented. * If it returns `undefined`, the default logging will proceed. * @param name - The name of the logger * @param type - The log type (e.g., 'log', 'warn', 'error', ...) * @param args - An array of arguments passed to the logging method */ infrastructureLog: liteTapable.SyncBailHook<[ string, string, any[] ], true | void>; beforeRun: liteTapable.AsyncSeriesHook<[Compiler]>; run: liteTapable.AsyncSeriesHook<[Compiler]>; emit: liteTapable.AsyncSeriesHook<[Compilation]>; assetEmitted: liteTapable.AsyncSeriesHook<[string, AssetEmittedInfo]>; afterEmit: liteTapable.AsyncSeriesHook<[Compilation]>; failed: liteTapable.SyncHook<[Error]>; shutdown: liteTapable.AsyncSeriesHook<[]>; watchRun: liteTapable.AsyncSeriesHook<[Compiler]>; watchClose: liteTapable.SyncHook<[]>; environment: liteTapable.SyncHook<[]>; afterEnvironment: liteTapable.SyncHook<[]>; afterPlugins: liteTapable.SyncHook<[Compiler]>; afterResolvers: liteTapable.SyncHook<[Compiler]>; make: liteTapable.AsyncParallelHook<[Compilation]>; beforeCompile: liteTapable.AsyncSeriesHook<[CompilationParams]>; afterCompile: liteTapable.AsyncSeriesHook<[Compilation]>; finishMake: liteTapable.AsyncSeriesHook<[Compilation]>; entryOption: liteTapable.SyncBailHook<[string, EntryNormalized], any>; additionalPass: liteTapable.AsyncSeriesHook<[]>; }; export declare const GET_COMPILER_ID: unique symbol; declare class Compiler { #private; hooks: CompilerHooks; webpack: typeof rspack; rspack: typeof rspack; name?: string; parentCompilation?: Compilation; root: Compiler; outputPath: string; running: boolean; idle: boolean; resolverFactory: ResolverFactory; infrastructureLogger: any; watching?: Watching; inputFileSystem: InputFileSystem | null; intermediateFileSystem: IntermediateFileSystem | null; outputFileSystem: OutputFileSystem | null; watchFileSystem: WatchFileSystem | null; records: Record; modifiedFiles?: ReadonlySet; removedFiles?: ReadonlySet; fileTimestamps?: ReadonlyMap; contextTimestamps?: ReadonlyMap; fsStartTime?: number; watchMode: boolean; context: string; cache: Cache; compilerPath: string; options: RspackOptionsNormalized; /** * Whether to skip dropping Rust compiler instance to improve performance. * This is an internal option api and could be removed or changed at any time. * @internal * true: Skip dropping Rust compiler instance. * false: Drop Rust compiler instance when Compiler is garbage collected. */ unsafeFastDrop: boolean; /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ __internal_browser_require: (id: string) => unknown; constructor(context: string, options: RspackOptionsNormalized); get recordsInputPath(): never; get recordsOutputPath(): never; get managedPaths(): never; get immutablePaths(): never; get _lastCompilation(): Compilation | undefined; get platform(): PlatformTargetProperties; set platform(platform: PlatformTargetProperties); get target(): ExtractedTargetProperties; set target(target: ExtractedTargetProperties); /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ get __internal__builtinPlugins(): binding.BuiltinPlugin[]; /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ get __internal__ruleSet(): RuleSetCompiler; /** * @param name - cache name * @returns the cache facade instance */ getCache(name: string): CacheFacade; /** * @param name - name of the logger, or function called once to get the logger name * @returns a logger with that name */ getInfrastructureLogger(name: string | (() => string)): Logger; /** * @param watchOptions - the watcher's options * @param handler - signals when the call finishes * @returns a compiler watcher */ watch(watchOptions: Watchpack.WatchOptions, handler: liteTapable.Callback): Watching; /** * @param callback - signals when the call finishes * @param options - additional data like modifiedFiles, removedFiles */ run(callback: liteTapable.Callback, options?: { modifiedFiles?: ReadonlySet; removedFiles?: ReadonlySet; }): void; runAsChild(callback: (err?: null | Error, entries?: Chunk[], compilation?: Compilation) => any): void; purgeInputFileSystem(): void; /** * @param compilation - the compilation * @param compilerName - the compiler's name * @param compilerIndex - the compiler's index * @param outputOptions - the output options * @param plugins - the plugins to apply * @returns a child compiler */ createChildCompiler(compilation: Compilation, compilerName: string, compilerIndex: number, outputOptions: OutputNormalized, plugins: RspackPluginInstance[]): Compiler; isChild(): boolean; /** * Create a compilation and run it, which is the basic method that `compiler.run` and `compiler.watch` depend on. * TODO: make this method private in the next major release * @private this method is only used in Rspack core */ compile(callback: liteTapable.Callback): void; close(callback: (error?: Error | null) => void): void; /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ __internal__rebuild(modifiedFiles?: ReadonlySet, removedFiles?: ReadonlySet, callback?: (error: Error | null) => void): void; /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ __internal__create_compilation(native: binding.JsCompilation): Compilation; /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ __internal__get_virtual_file_store(): binding.VirtualFileStore | null | undefined; /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ __internal__registerBuiltinPlugin(plugin: binding.BuiltinPlugin): void; /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ __internal__takeModuleExecutionResult(id: number): any; /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ __internal__get_compilation(): Compilation | undefined; /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ __internal__get_compilation_params(): CompilationParams | undefined; /** * Note: This is not a webpack public API, maybe removed in future. * @internal */ __internal__get_module_execution_results_map(): Map; } export { Compiler };