///
import type { RawSourceMap } from 'source-map';
import * as BabelTypes from '@babel/types';
import { ICompileOptions } from '..';
import { MiniProgramCore } from './core';
export type IBasicCodeExt = 'js' | 'wxml' | 'wxss' | 'json' | 'wxs';
export declare const BasicCodeExts: readonly ["js", "wxml", "wxss", "json", "wxs"];
export declare namespace MiniProgramSummer {
interface ModuleJSON {
code: string | null;
map?: SourceMap;
path: string;
sourcePath?: string;
depFileIds?: string[];
}
interface SummerCache {
modules: ModuleJSON[];
}
interface SummerBuild {
cache: SummerCache | undefined;
output: {
[key in string]: string;
};
watchFiles: string[];
}
interface PluginContext {
addWatchFile: (absFilePath: string) => void;
error: (err: any) => never;
runWorkerMethod: (method: string, ...args: any[]) => Promise;
rootPath?: string;
}
type SourceMap = Omit & {
version: number | string;
};
enum AstType {
Babel = "babel",
Acorn = "acorn"
}
type AstInfo = {
ast: AcornNode;
type: AstType.Acorn;
} | {
ast: BabelTypes.File;
type: AstType.Babel;
};
type SourceDescription = {
sourceCode: string;
inputMap?: SourceMap;
astInfo?: AstInfo;
largeFile?: boolean;
mtime?: number;
};
type GenerateDescription = {
code: string;
map?: SourceMap | string;
helpers?: string[];
wrappedByDefine?: boolean;
resultType?: MiniProgramCore.IResultType;
};
interface IPluginProcessInfo {
cost: number;
pluginName: string;
action: AsyncPluginHooks;
options?: Record;
}
interface ILoadResult {
targetPath: string;
source: SourceDescription;
process: IPluginProcessInfo[];
}
type ITransformResult = ILoadResult;
type AsyncPluginHooks = 'load' | 'transform' | 'optimize' | 'generate' | 'compress' | 'sealed' | 'compile';
type FirstPluginHooks = 'load' | 'generate' | 'compile';
type SequentialPluginHooks = 'transform' | 'optimize' | 'compress';
type ParallelPluginHooks = 'sealed';
type LoadHook = (this: PluginContext, targetPath: string, sourcePath: string, options: {
independentRoot: string;
isBabelIgnore: boolean;
}) => Promise;
type CompileHook = (this: PluginContext, targetPath: string, sourcePath: string, loadResult: ILoadResult, options: {
independentRoot: string;
isBabelIgnore: boolean;
} & ICompileOptions) => Promise;
type TransformHook = (this: PluginContext, loadResult: ILoadResult, targetPath: string, sourcePath: string, options: {
independentRoot: string;
isBabelIgnore: boolean;
} & ICompileOptions) => Promise;
interface IGenerateResult extends ITransformResult {
target: GenerateDescription;
}
type GenerateHook = (this: PluginContext, transformResult: ITransformResult, targetPath: string, sourcePath: string, options: {
independentRoot: string;
isBabelIgnore: boolean;
} & ICompileOptions) => Promise;
type OptimizeHook = (this: PluginContext, generatedResult: IGenerateResult, options: ICompileOptions) => Promise;
type CompressHook = (this: PluginContext, generatedResult: IGenerateResult, options: ICompileOptions) => Promise;
type SealedHook = (this: PluginContext, content: Record) => Promise;
interface PluginHooks {
load: LoadHook;
transform: TransformHook;
generate: GenerateHook;
optimize: OptimizeHook;
compress: CompressHook;
sealed: SealedHook;
compile: CompileHook;
}
interface ResolveExt {
json?: string | string[];
wxml?: string | string[];
wxss?: string | string[];
js?: string | string[];
wxs?: string | string[];
}
interface SummerPlugin extends Partial {
name: string;
supportWorker?: boolean;
workerMethods?: Record;
resolveExt?: ResolveExt;
}
type SummerPluginOptions = Record;
interface TypedEventEmitter any;
}> {
addListener(event: K, listener: T[K]): this;
emit(event: K, ...args: Parameters): boolean;
eventNames(): Array;
getMaxListeners(): number;
listenerCount(type: keyof T): number;
listeners(event: K): Array;
off(event: K, listener: T[K]): this;
on(event: K, listener: T[K]): this;
once(event: K, listener: T[K]): this;
prependListener(event: K, listener: T[K]): this;
prependOnceListener(event: K, listener: T[K]): this;
rawListeners(event: K): Array;
removeAllListeners(event?: K): this;
removeListener(event: K, listener: T[K]): this;
setMaxListeners(n: number): this;
}
type ChangeEvent = 'create' | 'update' | 'delete';
type SummerWatcherEvent = {
code: 'START';
} | {
code: 'BUILD_END';
duration: number;
output: SummerBuild['output'];
} | {
code: 'END';
};
interface SummerWatcher extends TypedEventEmitter<{
change: (id: string, change: {
event: ChangeEvent;
}) => void;
close: () => void;
event: (event: SummerWatcherEvent) => void;
restart: () => void;
}> {
close(): void;
}
interface WatcherOptions {
buildDelay?: number;
}
interface AcornNode {
end: number;
start: number;
type: string;
}
}