///
import { AsyncSeriesBailHook, AsyncSeriesHook, AsyncSeriesWaterfallHook, SyncHook } from 'tapable';
import { Stats } from 'fs';
import { CLIConfig, BuildConfig } from './config';
import { SpeedyPlugin, ResolveArgs, LoadArgs, ResolveResult, LoadResult, Chunk, Source, SpeedyManifest, AssetChunk, JsChunk, SourceMap } from './type';
import { IBundlerBase } from './bundler-base';
import { Callback } from './callback';
import { SpeedyErrorOptions } from './error';
export interface ISpeedyBundlerHooks {
/**
* Asynchronous initialization. Executed after normalized `buildConfig` and `plugins`.
*/
initialize: AsyncSeriesHook<[], void>;
/**
* modify environment variables.
*/
environment: SyncHook<[]>;
/**
* compilation stage.
*/
compilation: AsyncSeriesHook<[]>;
/**
* Equal to esbuild#onResolve and rollup#resolveId
*/
resolve: AsyncSeriesBailHook<[ResolveArgs, any], ResolveResult | undefined>;
/**
* Equal to esbuild#onLoad and rollup#load
*/
load: AsyncSeriesBailHook<[LoadArgs], LoadResult | undefined | void>;
/**
*
*/
transform: AsyncSeriesWaterfallHook;
/**
* 用于修改编译后的chunk产物
*/
processAsset: AsyncSeriesWaterfallHook<[Chunk]>;
/**
* backend bundler的onStart, watch会触发
*/
startCompilation: AsyncSeriesHook<[]>;
/**
* backend bundler的onEnd, watch会触发
*/
endCompilation: AsyncSeriesHook<[]>;
/**
* 所有assets的后续处理,如根据assets生成html文件
*/
processAssets: AsyncSeriesHook<[Map, SpeedyManifest]>;
processManifest: AsyncSeriesHook<[SpeedyManifest]>;
beforeEmit: AsyncSeriesHook<[]>;
transformHTML: AsyncSeriesHook<[ISpeedyBundler]>;
done: AsyncSeriesHook<[]>;
afterDone: SyncHook;
childCompiler: AsyncSeriesHook<[ISpeedyBundler]>;
/**
* watch related hook
*/
watchChange: SyncHook<[string, Stats]>;
/**
* bundler 关闭前触发
*/
shutdown: AsyncSeriesHook<[]>;
hmr: AsyncSeriesHook<[string[]]>;
error: AsyncSeriesHook<[string[]]>;
/**
* This hook is intended to be used by Speedy Internal Plugins, don't use it publicly or you maybe fired.
* @internal
*
*/
esbuild: AsyncSeriesBailHook<[], any>;
}
export declare interface ISpeedyBundlerStage {
/**
* Execute Before Internal Plugin
*/
PRE_INTERNAL: number;
/**
* Execute After Internal Plugin
*/
POST_INTERNAL: number;
/**
* The stage of generate html in processAssets hook.
*/
PROCESS_ASSETS_GENERATE_HTML: number;
/**
* The stage of modify generated html in processAssets hook.
*/
PROCESS_ASSETS_MODIFY_GENERATED_HTML: number;
}
export interface ISpeedyBundler {
name?: string;
parent?: ISpeedyBundler;
children: ISpeedyBundler[];
version: string;
compilation: IBundlerBase;
hooks: ISpeedyBundlerHooks;
STAGE: ISpeedyBundlerStage;
createChildCompiler(config: CLIConfig, name?: string): Promise;
isChild(): boolean;
config: BuildConfig;
plugins: SpeedyPlugin[];
outputChunk: Map;
init(config: CLIConfig): Promise;
build(): Promise;
close(callBack?: Callback): Promise;
emitAsset(name: string, chunk: AssetChunk): void;
emitAsset(name: string, chunk: JsChunk): void;
emitAsset(name: string, chunk: string): void;
watchedFiles: Set;
addWatchFile(id: string): void;
resolve(source: string, importer: string): Promise;
error(message: string, opts: SpeedyErrorOptions): void;
getTransformContext(path: string): ITransformContext;
getSourcemapContext(path: string): ISourcemapContext;
}
export interface ITransformContext extends ISourcemapContext {
addTransformResult(pluginId: number, result: CacheValue): void;
getValidCache(pluginId: number, code: string): undefined | CacheValue;
}
export interface CacheValue extends Source {
originCode: string;
}
export interface ISourcemapContext {
addSourceMap(map?: SourceMap, pluginId?: number): void;
getInlineSourceMap(): Promise;
getSourceMap(): Promise;
}