import type { Program } from 'estree'; import type { SourceMapConsumer } from 'source-map'; import type { NonFunctionProperties } from '../common.js'; import type { ChunkInstance } from './chunk.js'; import type { BriefModeOptions } from '../config.js'; import type { StatementInstance, StatementData } from './statement.js'; import type { PackageData } from './package.js'; import type { ModuleGraphModuleInstance, ModuleGraphModuleData, ExportData, ExportInstance, SideEffectData, SideEffectInstance, VariableData, VariableInstance } from './treeShaking.js'; import type { StatsModule } from '../plugin/index.js'; export declare enum DependencyKind { Unknown = 0, ImportStatement = 1, DynamicImport = 2, RequireCall = 3, AMDRequire = 4 } /** Source code location */ export interface SourcePosition { line?: number; column?: number; index?: number; } /** Source code range */ export interface SourceRange { start: SourcePosition; end?: SourcePosition; } /** Side effect location from bundler (e.g. Rspack JsRsdoctorSideEffectLocation) */ export interface SideEffectLocationData { location: string; nodeType: string; module: number; request: string; } /** Pre-computed side-effects-only import result (from Rust analysis) */ export interface ConnectionsOnlyImportData { moduleUkey: number; modulePath: string; connections: Array<{ originModule?: number; dependencyType: string; userRequest: string; }>; } /** Side effect code snippet data */ export interface SideEffectCodeData { /** Module ID */ moduleId: number; /** Start line number (1-indexed) */ startLine: number; /** Extracted source code snippet */ code: string; } /** Module size */ export interface ModuleSize { sourceSize: number; /** Code size after transformed */ transformedSize: number; /** * Code size after compiled * - The size the module occupies in the product after packing. */ parsedSize: number; /** * Gzipped size of the module source (optional) */ gzipSize: number; } /** Module source code */ export interface ModuleSource { /** source code */ source: string; /** transformed code */ transformed: string; parsedSource: string; } /** Module Metadata */ export interface ModuleBuildMeta { /** * Whether to include the esModule flag statement * ```js * Object.defineProperty(exports, "__esModule", { value: true }); * ``` * - This statement usually appears in the object code of the tsc to cjs module. */ hasSetEsModuleStatement: boolean; /** * Strict ESM module. */ strictHarmonyModule: boolean; packageData?: PackageData; } /** Module type */ export declare enum ModuleKind { /** Normal module */ Normal = 0, /** Aggregation module */ Concatenation = 1 } export declare enum ToDataType { NoCode = 0, /** Normal mode */ Normal = 1, /** Lite mode: no source code */ NoSource = 2, /** Lite & No Assets Code mode */ NoSourceAndAssets = 3, /** All Data, include module transformed data. */ All = 4 } export interface ModuleInstance { /** Module identifier */ readonly id: number; /** webpack render identifier */ readonly renderId?: string; /** webpack identifier */ readonly webpackId: string; /** Module path */ readonly path: string; readonly isEntry: boolean; readonly kind: ModuleKind; /** Root module in aggregate module */ readonly rootModule?: ModuleInstance; readonly layer?: string; /** * Preference to source location * - Indicates that the source code is not empty and there is source code location mapping data. */ isPreferSource: boolean; /** Build properties */ meta: ModuleBuildMeta; /** Issuer paths */ issuerPath?: StatsModule['issuerPath']; bailoutReason?: string[]; /** Get the Chunks instance where the module in.*/ getChunks(): ChunkInstance[]; /** Add Chunk instance */ addChunk(chunk: ChunkInstance): void; removeChunk(chunk: ChunkInstance): void; getDependencies(): DependencyInstance[]; getDependencyByRequest(request: string): DependencyInstance | undefined; /** Get dependency data from module */ getDependencyByModule(module: ModuleInstance): DependencyInstance | undefined; removeDependency(dependency: DependencyInstance): void; /** Remove dependency data from module */ removeDependencyByModule(module: ModuleInstance): void; removeImported(module: ModuleInstance): void; getImported(): ModuleInstance[]; addImported(module: ModuleInstance): void; addDependency(request: string, module: ModuleInstance, kind: DependencyKind, statements?: StatementInstance[]): DependencyInstance | undefined; toData(contextPath?: string, isBrief?: boolean): ModuleData; setSource(source: Partial): void; getSource(type?: ToDataType): ModuleSource; /**Set code AST after transform */ setProgram(program: Program): void; /** Get the converted code AST */ getProgram(): Program | undefined; /** Set module size information */ setSize(size: Partial): void; getSize(): ModuleSize; setSourceMap(sourcemap: SourceMapConsumer): void; /** Get source code mapping */ getSourceMap(): SourceMapConsumer | undefined; /** * Generate statement instances * @param transformed {SourceRange} The location of the transformed code. */ getStatement(transformed: SourceRange): StatementInstance | undefined; /** * Generate original code location * @param transformed {SourceRange} The location of the transformed code. */ getSourceRange(transformed: SourceRange): SourceRange | undefined; /** Add connected submodules */ addNormalModule(module: ModuleInstance): void; /** If it is currently a connection module, return all connected base sub packages */ getNormalModules(): ModuleInstance[]; /** Added aggregation module */ addConcatenationModule(module: ModuleInstance): void; /** Get all aggregated modules to which the current module belongs */ getConcatenationModules(): ModuleInstance[]; setId(id: number): void; setChunks(chunks: ChunkInstance[]): void; setDependencies(dependencies: DependencyInstance[]): void; setImported(imported: ModuleInstance[]): void; setModules(modules: ModuleInstance[]): void; setConcatenationModules(modules: ModuleInstance[]): void; setRenderId(renderId: string): void; /** Add an issuer path */ addIssuerPath(issuerPath: StatsModule['issuerPath']): void; /** Get issuer path */ getIssuerPath(): StatsModule['issuerPath']; /** Add bailout reason */ addBailoutReason(reason: string): void; /** Get bailout reason */ getBailoutReason(): string[]; /** Side effect location data (e.g. from Rspack sideEffectsLocations) */ sideEffectLocations?: SideEffectLocationData[]; /** Add a side effect location */ addSideEffectLocation(location: SideEffectLocationData): void; /** Get side effect locations */ getSideEffectLocations(): SideEffectLocationData[]; /** Add side effect code */ addSideEffectCode(codeData: SideEffectCodeData): void; /** Get side effect codes */ getSideEffectCodes(): SideEffectCodeData[]; } /** Depends on Metadata */ export interface DependencyBuildMeta { /** * Types of dependencies between modules * - The basis for webpack to add runtime to modules. * * @link https://github.com/webpack/webpack/blob/v5.75.0/lib/Module.js#L428 * @link https://github.com/webpack/webpack/blob/v4.46.0/lib/RuntimeTemplate.js#L215 */ exportsType: 'namespace' | 'default-only' | 'default-with-named' | 'dynamic'; } export interface DependencyInstance { /** Identifier */ readonly id: number; /** * Original request * - refers to the original request in the import statement * - @example `import {Instance} from'chalk'` in the statement 'chalk' */ readonly request: string; /** actual requested path */ readonly resolvedRequest: string; /** Module */ readonly module: ModuleInstance; /** * Dependency Module * - Always non-aggregated modules */ readonly dependency: ModuleInstance; /** * Original dependency module * - Aggregation module preferred */ readonly originDependency: ModuleInstance; /** * Citation method * - Numeric enumeration */ readonly kind: DependencyKind; /** * Citation method * - string enumeration */ readonly kindString: keyof typeof DependencyKind; /** * Original dependency type string from the bundler (e.g. 'cjs require', 'cjs full require', 'esm import') */ typeString?: string; /** Whether to connect to the aggregation module */ readonly resolveConcatenationModule: boolean; /** quote statement */ readonly statements: StatementInstance[]; /** build attribute */ meta: DependencyBuildMeta; /** Generate data */ toData(): DependencyData; /** Add statement */ addStatement(statement: StatementInstance): void; /** Whether this statement is included */ hasStatement(statement: StatementInstance): boolean; /** * Is it the same dependency? * - Check properties other than id and statements */ isSameWithoutStatements(dep: DependencyInstance): boolean; setBuildMeta(data: DependencyBuildMeta): void; setId(id: number): void; } export type ModuleGraphToDataArgs = { contextPath: string; briefOptions?: BriefModeOptions; }; export interface ModuleGraphInstance { /** Clear data */ clear(): void; /** How many modules are there in total */ size(): number; /** overwrite data */ fromInstance(data: ModuleGraphInstance): void; /** Create module connection data */ addModuleGraphModule(info: ModuleGraphModuleInstance): void; /** Get module connection data */ getModuleGraphModule(module: ModuleInstance): ModuleGraphModuleInstance; /** Get all module connection data */ getModuleGraphModules(): ModuleGraphModuleInstance[]; /** Get all modules */ getModules(): ModuleInstance[]; /** Get all modules */ getDependencies(): DependencyInstance[]; /** Get connection by id */ getDependencyById(id: number): DependencyInstance | undefined; /** Get entrance module */ getEntryModules(): ModuleInstance[]; /** Get the subgraph of the current node as the entry point */ getSubGraphByModule(module: ModuleInstance): ModuleInstance[]; /** Get module by id */ getModuleById(id: number): ModuleInstance | undefined; /** get module by webpackId */ getModuleByWebpackId(webpackId: string): ModuleInstance | undefined; /** Get module by path */ getModuleByFile(file: string, layer?: string): ModuleInstance[] | []; /** Add Module */ addModule(module: ModuleInstance): void; /** Add module connection */ addDependency(module: DependencyInstance): void; /** * Remove module * - The connection relationship of this module will also be removed */ removeModule(module: ModuleInstance): void; /** * Remove connection * - If one of the connected endpoints is an independent module, this module will also be removed from the module diagram */ removeDependency(dependency: DependencyInstance): void; /** Add export data */ addExportInfo(data: ExportInstance): void; /** Add side effect data */ addSideEffect(data: SideEffectInstance): void; /** Add variable data */ addVariable(data: VariableInstance): void; /** Generate data */ toData(configs?: ModuleGraphToDataArgs): ModuleGraphData; /** Generate tree shaking data */ toTreeShakingData(): TreeShakingData; /** Generate data */ toCodeData(type?: ToDataType): ModuleCodeData; setModules(modules: ModuleInstance[]): void; setDependencies(dependencies: DependencyInstance[]): void; setConnectionsOnlyImports(items: ConnectionsOnlyImportData[]): void; getConnectionsOnlyImports(): ConnectionsOnlyImportData[]; } export interface ModuleData extends Omit, 'rootModule' | 'isEntry' | 'concatenationModules' | 'meta' | 'issuerPath'> { /** chunk identifier */ chunks: string[]; /** Module identifier on which the module depends */ dependencies: number[]; /** Identifier of the dependent module */ imported: number[]; /** Is it an entrance module */ isEntry?: boolean | undefined; /** Use source code location first */ isPreferSource: boolean; /** Module size */ size: ModuleSize; layer?: string; /** Connected base subpackage */ modules?: number[]; /** root module number */ rootModule?: number; /** Affiliated aggregation module number */ concatenationModules?: number[]; /** Module Id */ webpackId: string; /** Build original attributes */ meta?: Partial>; /** Issuer path */ issuerPath?: string[] | number[]; /** Side effect location data (e.g. from Rspack sideEffectsLocations) */ sideEffectLocations?: SideEffectLocationData[]; } export type ModuleCodeData = Record; /** Tree shaking analysis data */ export interface TreeShakingData { sideEffectCodes: Record; } export interface DependencyData extends Omit, 'module' | 'dependency' | 'statements' | 'originDependency' | 'kindString' | 'resolveConcatenationModule' | 'meta'> { /** Module Identifier */ module: number; /** Dependency Module Identifier */ dependency: number; /** Original module identifier */ originDependency: number; /** quote statement */ statements: StatementData[]; } /** Module connection data from rspack module graph */ export interface ConnectionData { ukey: number; dependencyId: string; module: number; originModule?: number; resolvedModule: number; dependencyType: string; userRequest: string; loc?: string; active: boolean; } export interface ModuleGraphData { dependencies: DependencyData[]; modules: ModuleData[]; moduleGraphModules: ModuleGraphModuleData[]; exports: ExportData[]; sideEffects: SideEffectData[]; variables: VariableData[]; layers?: string[]; connections?: ConnectionData[]; }