import type { RuleMessage, RuleMessageCodeEnumerated } from './code/index.js'; import type { SourceRange } from '../sdk/index.js'; import type { CrossChunksPackageType, PackageBasicData, PackageInstance } from '../sdk/package.js'; export interface BaseRuleStoreData extends Pick { /** * unique of error */ id: number | string; /** * title of alerts */ title: string; /** * description of alerts */ description?: string; /** * level of error */ level: 'warn' | 'error'; /** * rule doc link */ link?: string; } export interface LinkRuleStoreData extends BaseRuleStoreData { type: 'link'; } export interface DependencyWithPackageData { /** * use to group files, such as different version of duplicate packages. * @example * [ * { group: "lodash@1.0.1", ... }, * { group: "lodash@1.0.1", ... }, * { group: "lodash@2.0.0", ... }, * ] */ group?: string; /** * module dependency id */ dependencyId: number; } export interface PackageRelationData { /** Target package data */ target: PackageBasicData; /** Target package size */ targetSize: { sourceSize: number; parsedSize: number; }; /** package dependency chain */ dependencies: DependencyWithPackageData[]; } /** * Generally serves to view package relationship detection rules. */ export interface PackageRelationDiffRuleStoreData extends BaseRuleStoreData { type: 'package-relation'; packages: PackageRelationData[]; } export interface CrossChunksPackageRuleStoreData extends BaseRuleStoreData { type: 'cross-chunks-package'; chunks: CrossChunksPackageType[]; package: Pick & { size: ReturnType; }; } /** * General service to view file relationship detection rules. */ export interface FileRelationRuleStoreData extends BaseRuleStoreData { type: 'file-relation'; /** Target file */ target: string; /** Dependency chain */ dependencies: number[]; } /** * the rule which code view only */ export interface CodeViewRuleStoreData extends BaseRuleStoreData { type: 'code-view'; file: { /** * file path */ path: string; /** * the code content */ content: string; /** * fix highlight range in source */ ranges?: SourceRange[]; }; } /** * the rule which need to change the file code. */ export interface CodeChangeRuleStoreData extends BaseRuleStoreData { type: 'code-change'; file: { /** * file path */ path: string; /** * the actual file content */ actual: string; /** * the expected file content */ expected: string; /** * fix code line in source */ line?: number; /** * whether this case is fixed * - @default `false` */ isFixed?: boolean; }; } export interface OverlayRuleStoreData extends BaseRuleStoreData { code: RuleMessageCodeEnumerated.Overlay; stack?: string; } /** * Rule for detecting modules that are included in both initial and async chunks. */ export interface ModuleMixedChunksRuleStoreData extends BaseRuleStoreData { type: 'module-mixed-chunks'; module: { id: number | string; path: string; webpackId?: string | number; }; initialChunks: Array<{ id: string; name: string; }>; asyncChunks: Array<{ id: string; name: string; }>; } /** * Rule for detecting modules that are only imported for their side effects, * which may indicate unintended tree-shaking failures. */ export interface ConnectionsOnlyImportsRuleStoreData extends BaseRuleStoreData { type: 'tree-shaking-side-effects-only'; module: { id: number | string; path: string; webpackId?: string | number; }; connections: Array<{ originModule: number; dependencyType: string; userRequest: string; }>; } /** * Rule for detecting modules imported via CJS require (bare require() call), * which prevents tree-shaking of the required module. */ export interface CjsRequireRuleStoreData extends BaseRuleStoreData { type: 'cjs-require'; /** The module that contains the require() call */ issuerModule: { id: number | string; path: string; webpackId?: string | number; }; /** The module being required */ requiredModule: { id: number | string; path: string; webpackId?: string | number; }; /** The original require string (e.g. 'lodash') */ request: string; } /** * Rule for detecting ESM imports that were resolved to a CJS module * even though the package provides an ESM entry. */ export interface EsmResolvedToCjsRuleStoreData extends BaseRuleStoreData { type: 'esm-resolved-to-cjs'; /** Package name */ packageName: string; /** Package version */ packageVersion: string; /** The ESM entry path declared in the package's package.json */ esmEntry: string; /** The actual resolved (CJS) module */ resolvedModule: { id: number | string; path: string; webpackId?: string | number; }; /** All issuer modules that imported this package via ESM import */ issuers: Array<{ id: number | string; path: string; /** The import request string (e.g. 'lodash') */ request: string; }>; } export type RuleStoreDataItem = LinkRuleStoreData | FileRelationRuleStoreData | CodeChangeRuleStoreData | PackageRelationDiffRuleStoreData | CodeViewRuleStoreData | CrossChunksPackageRuleStoreData | ModuleMixedChunksRuleStoreData | ConnectionsOnlyImportsRuleStoreData | CjsRequireRuleStoreData | EsmResolvedToCjsRuleStoreData; export type RuleStoreData = RuleStoreDataItem[];