/** * @typedef {import('esbuild').PartialMessage} PartialMessage */ /** * @typedef {import('esbuild').Loader} Loader */ /** * @typedef {import('esbuild').Platform} Platform */ /** * @typedef {import('esbuild').Format} Format */ /** * @typedef {import('esbuild').Plugin} Plugin */ /** * @typedef {import('esbuild').PluginBuild} PluginBuild */ /** * @typedef {import('esbuild').BuildOptions} BuildOptions */ /** * @typedef {import('esbuild').TransformOptions} TransformOptions */ /** * @typedef {import('esbuild').OnStartResult} OnStartResult */ /** * @typedef {import('esbuild').ResolveOptions} ResolveOptions */ /** * @typedef {import('esbuild').ResolveResult} ResolveResult */ /** * @typedef {import('esbuild').OnResolveOptions} OnResolveOptions */ /** * @typedef {import('esbuild').OnResolveArgs} OnResolveArgs */ /** * @typedef {import('esbuild').OnResolveResult} OnResolveResult */ /** * @typedef {import('esbuild').OnLoadOptions} OnLoadOptions */ /** * @typedef {import('esbuild').OnLoadArgs} OnLoadArgs */ /** * @typedef {import('esbuild').OnLoadResult} OnLoadResult */ /** * @typedef {import('esbuild').BuildResult} BuildResult */ /** * @typedef {import('esbuild').Metafile} Metafile */ /** * @typedef {Object} VirtualEntry * @property {string} path * @property {string|Buffer|Uint8Array} contents * @property {Loader} [loader] * @property {string} [resolveDir] */ /** * @typedef {BuildOptions & { path: string; contents?: string | Buffer }} EmitChunkOptions */ /** * @typedef {Omit & { entryPoints: (string | VirtualEntry)[] }} EmitBuildOptions */ /** * @typedef {(args: OnLoadArgs) => Promise | OnLoadResult | null | undefined} LoadCallback */ /** * @typedef {BuildResult & { metafile: Metafile; dependencies: Record }} Result */ /** * @typedef {Result & { id: string; path: string }} Chunk */ /** * @typedef {Result & { id: string; path: string }} File */ /** * @typedef {Object} OnLoadRule * @property {OnLoadOptions} options * @property {LoadCallback} callback */ /** * @typedef {Object} OnTransformOptions * @property {RegExp} [filter] * @property {Loader[]} [loaders] * @property {string[]} [extensions] * @property {string} [namespace] */ /** * @typedef {OnLoadArgs & { code?: string | Uint8Array, loader?: Loader, resolveDir?: string }} OnTransformArgs */ /** * @typedef {Object} OnTransformResult * @property {string} [code] * @property {string|Buffer|Uint8Array} [contents] * @property {import('@chialab/estransform').SourceMap|null} [map] * @property {string} [resolveDir] * @property {PartialMessage[]} [errors] * @property {PartialMessage[]} [warnings] * @property {string[]} [watchFiles] * @property {Metafile} [metafile] */ /** * @typedef {(args: OnLoadArgs & { code: string, loader: Loader, resolveDir?: string }) => Promise | OnTransformResult | null | undefined | void} TransformCallback */ /** * @typedef {Object} OnTransformRule * @property {OnTransformOptions} options * @property {TransformCallback} callback */ /** * Esbuild build handler. * @implements {PluginBuild} */ export class Build implements PluginBuild { static ENTRY: number; static CHUNK: number; static ASSET: number; /** * Create a build instance and state. * @param {PluginBuild} build * @param {import('./BuildManager.js').BuildManager} manager */ constructor(build: PluginBuild, manager: import("./BuildManager.js").BuildManager); /** * The current plugin instance. * @type {Plugin} */ plugin: Plugin; /** * The current plugin name. * @type {string} */ pluginName: string; /** * Manager instance. * @type {import('./BuildManager.js').BuildManager} * @readonly * @private */ private readonly manager; /** * Esbuild plugin build. * @type {PluginBuild} * @readonly * @private */ private readonly pluginBuild; /** * OnLoad rules. * @type {OnLoadRule[]} * @readonly * @private */ private readonly onLoadRules; /** * OnTransform rules. * @type {OnTransformRule[]} * @readonly * @private */ private readonly onTransformRules; /** * Build chunks. * @type {Map} * @readonly * @private */ private readonly chunks; /** * Build files. * @type {Map} * @readonly * @private */ private readonly files; /** * Build sub-builds. * @type {Set} * @readonly * @private */ private readonly builds; /** * Build dependencies map. * @type {Record} * @readonly * @private */ private readonly dependencies; get esbuild(): { context: typeof import("esbuild").context; build: typeof import("esbuild").build; buildSync: typeof import("esbuild").buildSync; transform: typeof import("esbuild").transform; transformSync: typeof import("esbuild").transformSync; formatMessages: typeof import("esbuild").formatMessages; formatMessagesSync: typeof import("esbuild").formatMessagesSync; analyzeMetafile: typeof import("esbuild").analyzeMetafile; analyzeMetafileSync: typeof import("esbuild").analyzeMetafileSync; initialize: typeof import("esbuild").initialize; version: typeof import("esbuild").version; }; initialOptions: { define: { [key: string]: string; }; external: string[]; bundle?: boolean; splitting?: boolean; preserveSymlinks?: boolean; outfile?: string; metafile?: boolean; outdir?: string; outbase?: string; packages?: "bundle" | "external"; alias?: Record; loader?: { [ext: string]: import("esbuild").Loader; }; resolveExtensions?: string[]; mainFields?: string[]; conditions?: string[]; write?: boolean; allowOverwrite?: boolean; tsconfig?: string; outExtension?: { [ext: string]: string; }; publicPath?: string; entryNames?: string; chunkNames?: string; assetNames?: string; inject?: string[]; banner?: { [type: string]: string; }; footer?: { [type: string]: string; }; entryPoints?: string[] | Record | { in: string; out: string; }[]; stdin?: import("esbuild").StdinOptions; plugins?: import("esbuild").Plugin[]; absWorkingDir?: string; nodePaths?: string[]; sourcemap?: boolean | "linked" | "inline" | "external" | "both"; legalComments?: "none" | "inline" | "eof" | "linked" | "external"; sourceRoot?: string; sourcesContent?: boolean; format?: import("esbuild").Format; globalName?: string; target?: string | string[]; supported?: Record; platform?: import("esbuild").Platform; mangleProps?: RegExp; reserveProps?: RegExp; mangleQuoted?: boolean; mangleCache?: Record; drop?: import("esbuild").Drop[]; dropLabels?: string[]; minify?: boolean; minifyWhitespace?: boolean; minifyIdentifiers?: boolean; minifySyntax?: boolean; lineLimit?: number; charset?: import("esbuild").Charset; treeShaking?: boolean; ignoreAnnotations?: boolean; jsx?: "transform" | "preserve" | "automatic"; jsxFactory?: string; jsxFragment?: string; jsxImportSource?: string; jsxDev?: boolean; jsxSideEffects?: boolean; pure?: string[]; keepNames?: boolean; color?: boolean; logLevel?: import("esbuild").LogLevel; logLimit?: number; logOverride?: Record; tsconfigRaw?: string | import("esbuild").TsconfigRaw; }; /** * Get esbuild instance of the build. * @returns A esbuild instance. */ getBuilder(): { context: typeof import("esbuild").context; build: typeof import("esbuild").build; buildSync: typeof import("esbuild").buildSync; transform: typeof import("esbuild").transform; transformSync: typeof import("esbuild").transformSync; formatMessages: typeof import("esbuild").formatMessages; formatMessagesSync: typeof import("esbuild").formatMessagesSync; analyzeMetafile: typeof import("esbuild").analyzeMetafile; analyzeMetafileSync: typeof import("esbuild").analyzeMetafileSync; initialize: typeof import("esbuild").initialize; version: typeof import("esbuild").version; }; /** * Get initial build options. * @returns The initial options object. */ getInitialOptions(): { define: { [key: string]: string; }; external: string[]; bundle?: boolean; splitting?: boolean; preserveSymlinks?: boolean; outfile?: string; metafile?: boolean; outdir?: string; outbase?: string; packages?: "bundle" | "external"; alias?: Record; loader?: { [ext: string]: import("esbuild").Loader; }; resolveExtensions?: string[]; mainFields?: string[]; conditions?: string[]; write?: boolean; allowOverwrite?: boolean; tsconfig?: string; outExtension?: { [ext: string]: string; }; publicPath?: string; entryNames?: string; chunkNames?: string; assetNames?: string; inject?: string[]; banner?: { [type: string]: string; }; footer?: { [type: string]: string; }; entryPoints?: string[] | Record | { in: string; out: string; }[]; stdin?: import("esbuild").StdinOptions; plugins?: import("esbuild").Plugin[]; absWorkingDir?: string; nodePaths?: string[]; sourcemap?: boolean | "linked" | "inline" | "external" | "both"; legalComments?: "none" | "inline" | "eof" | "linked" | "external"; sourceRoot?: string; sourcesContent?: boolean; format?: import("esbuild").Format; globalName?: string; target?: string | string[]; supported?: Record; platform?: import("esbuild").Platform; mangleProps?: RegExp; reserveProps?: RegExp; mangleQuoted?: boolean; mangleCache?: Record; drop?: import("esbuild").Drop[]; dropLabels?: string[]; minify?: boolean; minifyWhitespace?: boolean; minifyIdentifiers?: boolean; minifySyntax?: boolean; lineLimit?: number; charset?: import("esbuild").Charset; treeShaking?: boolean; ignoreAnnotations?: boolean; jsx?: "transform" | "preserve" | "automatic"; jsxFactory?: string; jsxFragment?: string; jsxImportSource?: string; jsxDev?: boolean; jsxSideEffects?: boolean; pure?: string[]; keepNames?: boolean; color?: boolean; logLevel?: import("esbuild").LogLevel; logLimit?: number; logOverride?: Record; tsconfigRaw?: string | import("esbuild").TsconfigRaw; }; /** * Get build options. * @returns The options object. */ getOptions(): import("esbuild").BuildOptions; /** * Get build option. * @template {keyof BuildOptions} K Option key. * @param {K} key The option key to get. * @returns {BuildOptions[K]} The option value. */ getOption(key: K): BuildOptions[K]; /** * Set build option. * @template {keyof BuildOptions} K Option key. * @param {K} key The option key to update. * @param {BuildOptions[K]} value The value to set. */ setOption(key: K, value: BuildOptions[K]): void; /** * Delete a build option. * @param {keyof BuildOptions} key The option key to remove. */ deleteOption(key: keyof BuildOptions): void; /** * Compute the working dir of the build. * @returns {string} The working dir. */ getWorkingDir(): string; /** * Compute the source root of the build. * @returns {string} The source root. */ getSourceRoot(): string; /** * Compute the output base dir of the build. * @returns {string} The output base dir. */ getOutBase(): string; /** * Compute the output dir of the build. * @returns {string|undefined} The output dir. */ getOutDir(): string | undefined; /** * Compute the full output dir of the build. * @returns {string|undefined} The full output dir. */ getFullOutDir(): string | undefined; /** * Get configured build loaders. * @returns {{ [ext: string]: Loader }} */ getLoaders(): { [ext: string]: Loader; }; /** * Set a loader rule. * @param {string} ext The file extension. * @param {Loader} loader The loader name. */ setLoader(ext: string, loader: Loader): void; /** * Get list of build plugins. * @returns {Plugin[]} A list of plugin. */ getPlugins(): Plugin[]; /** * Get the defined loader for given file path. * @param {string} filePath * @returns {Loader|null} The loader name. */ getLoader(filePath: string): Loader | null; /** * Get the list of emitted chunks. * @returns {Map} A list of chunks. */ getChunks(): Map; /** * Get the list of emitted files. * @returns {Map} A list of files. */ getFiles(): Map; /** * Get the list of emitted builds. * @returns {Set} A list of builds. */ getBuilds(): Set; /** * Get collected dependencies. * @returns {Record} The dependencies map. */ getDependencies(): Record; /** * Check if the build is a chunk of another build. * @returns {boolean} True if the build is a chunk. */ isChunk(): boolean; /** * Register a callback for start hook of the build. * @param {() => (OnStartResult | null | void | Promise)} callback The callback to register. */ onStart(callback: () => (OnStartResult | null | void | Promise)): void; /** * Register a callback for end hook of the build. * @param {(result: BuildResult) => void | Promise} callback The callback to register. */ onEnd(callback: (result: BuildResult) => void | Promise): void; /** * Add a resolution rule for the build. * @param {OnResolveOptions} options Resolve options. * @param {(args: OnResolveArgs) => OnResolveResult | null | undefined | Promise} callback The callback to register. */ onResolve(options: OnResolveOptions, callback: (args: OnResolveArgs) => OnResolveResult | null | undefined | Promise): void; /** * Register a callback for dispose hook of the build. * @param {() => void} callback The callback to register. */ onDispose(callback: () => void): void; /** * Add a load rule for the build. * Wrap esbuild onLoad hook in order to use it in the transform pipeline. * @param {OnLoadOptions} options Load options. * @param {(args: OnLoadArgs) => OnLoadResult | null | undefined | Promise} callback The callback to register. */ onLoad(options: OnLoadOptions, callback: (args: OnLoadArgs) => OnLoadResult | null | undefined | Promise): void; /** * Add a transform hook to the build. * Differently from onLoad, each onTransform callback matched by the resource is invoked. * @param {OnTransformOptions} options The filter for onTransform hook. * @param {TransformCallback} callback The function to invoke for transformation. */ onTransform(options: OnTransformOptions, callback: TransformCallback): void; /** * Run esbuild build with given options. * @param {BuildOptions} options * @returns {Promise} Build result with manifest. */ build(options: BuildOptions): Promise; /** * Use the build system to resolve a specifier. * @param {string} path The path to resolve. * @param {ResolveOptions} [options] Resolve options. * @returns {Promise} The resolved module. */ resolve(path: string, options?: ResolveOptions): Promise; /** * Iterate build.onLoad hooks in order to programmatically load file contents. * @param {OnLoadArgs} args The load arguments. * @returns {Promise} A load result with file contents. */ load(args: OnLoadArgs): Promise; /** * Load file contents and exec compatible transformation rules collected by `onTransform`. * @param {OnTransformArgs} args The transform arguments. * @returns {Promise} A load result with transform file contents. */ transform(args: OnTransformArgs): Promise; /** * Create an hash for the given buffer. * @param {Buffer|Uint8Array|string} buffer The buffer input. * @returns A buffer hash. */ hash(buffer: Buffer | Uint8Array | string): string; /** * Create file path replacing esbuild patterns. * @see https://esbuild.github.io/api/#chunk-names * @param {string} pattern The esbuild pattern. * @param {string} filePath The full file path. * @param {Buffer|string} buffer The file contents. * @returns {string} */ computeName(pattern: string, filePath: string, buffer: Buffer | string): string; /** * Add a virtual module to the build. * @param {VirtualEntry} entry The virtual module entry. */ addVirtualModule(entry: VirtualEntry): void; /** * Resolve file path from build working dir. * @param {string} filePath The file path to resolve. * @returns {string} Resolved file path. */ resolvePath(filePath: string): string; /** * Resolve file path from source root dir. * @param {string} filePath The file path to resolve. * @returns {string} Resolved file path. */ resolveSourcePath(filePath: string): string; /** * Resolve file path of an output file. * @param {string} filePath The output file path. * @param {number} [type] The type of the file. * @returns {string} Resolved file path. */ resolveOutputDir(filePath: string, type?: number): string; /** * Resolve file path of an output file. * @param {string} filePath The output file path. * @param {Buffer} buffer The output file buffer. * @param {number} [type] The type of the file. * @returns {string} Resolved file path. */ resolveOutputFile(filePath: string, buffer: Buffer, type?: number): string; /** * Resolve relative file path. * @param {string} filePath The path of the imported file. * @param {string|null} [from] The path of the importing file. * @param {string} [prefix] The prefix to add to the relative path. * @returns {string} Relative file path. */ resolveRelativePath(filePath: string, from?: string | null, prefix?: string): string; /** * Get the output name in manifest of a file. * @param {string} filePath The output file path. * @returns {string} Relative output name. */ getOutputName(filePath: string): string; /** * Insert dependency plugins in the build plugins list. * @param {Plugin[]} plugins A list of required plugins . * @param {'before'|'after'} [mode] Where insert the missing plugin. * @returns {Promise} */ setupPlugin(plugins: Plugin[], mode?: "before" | "after"): Promise; /** * Add dependencies to the build. * @param {string} importer The importer path. * @param {string[]} dependencies A list of loaded dependencies. * @returns {Record} The updated dependencies map. */ collectDependencies(importer: string, dependencies: string[]): Record; /** * Check if path has been emitted by build. * @param {string} id The chunk id to check. * @returns {boolean} True if path has been emitted by the build. */ isEmittedPath(id: string): boolean; /** * Programmatically emit file reference. * @param {string} source The path of the file. * @param {string|Buffer} [buffer] File contents. * @param {boolean} [collect] If true, the file will be added to the build. * @returns {Promise} The output file reference. */ emitFile(source: string, buffer?: string | Buffer, collect?: boolean): Promise; /** * Programmatically emit a chunk reference. * @param {EmitChunkOptions} options Esbuild transform options. * @param {boolean} [collect] Collect the output chunk reference. * @returns {Promise} The output chunk reference. */ emitChunk(options: EmitChunkOptions, collect?: boolean): Promise; /** * Programmatically emit a sub build. * @param {EmitBuildOptions} options Esbuild build options. * @param {boolean} [collect] Collect the output build reference. * @returns {Promise} The output build reference. */ emitBuild(options: EmitBuildOptions, collect?: boolean): Promise; } export type PartialMessage = import("esbuild").PartialMessage; export type Loader = import("esbuild").Loader; export type Platform = import("esbuild").Platform; export type Format = import("esbuild").Format; export type Plugin = import("esbuild").Plugin; export type PluginBuild = import("esbuild").PluginBuild; export type BuildOptions = import("esbuild").BuildOptions; export type TransformOptions = import("esbuild").TransformOptions; export type OnStartResult = import("esbuild").OnStartResult; export type ResolveOptions = import("esbuild").ResolveOptions; export type ResolveResult = import("esbuild").ResolveResult; export type OnResolveOptions = import("esbuild").OnResolveOptions; export type OnResolveArgs = import("esbuild").OnResolveArgs; export type OnResolveResult = import("esbuild").OnResolveResult; export type OnLoadOptions = import("esbuild").OnLoadOptions; export type OnLoadArgs = import("esbuild").OnLoadArgs; export type OnLoadResult = import("esbuild").OnLoadResult; export type BuildResult = import("esbuild").BuildResult; export type Metafile = import("esbuild").Metafile; export type VirtualEntry = { path: string; contents: string | Buffer | Uint8Array; loader?: import("esbuild").Loader | undefined; resolveDir?: string | undefined; }; export type EmitChunkOptions = BuildOptions & { path: string; contents?: string | Buffer; }; export type EmitBuildOptions = Omit & { entryPoints: (string | VirtualEntry)[]; }; export type LoadCallback = (args: OnLoadArgs) => Promise | OnLoadResult | null | undefined; export type Result = BuildResult & { metafile: Metafile; dependencies: Record; }; export type Chunk = Result & { id: string; path: string; }; export type File = Result & { id: string; path: string; }; export type OnLoadRule = { options: OnLoadOptions; callback: LoadCallback; }; export type OnTransformOptions = { filter?: RegExp | undefined; loaders?: import("esbuild").Loader[] | undefined; extensions?: string[] | undefined; namespace?: string | undefined; }; export type OnTransformArgs = OnLoadArgs & { code?: string | Uint8Array; loader?: Loader; resolveDir?: string; }; export type OnTransformResult = { code?: string | undefined; contents?: string | Buffer | Uint8Array | undefined; map?: import("@chialab/estransform").SourceMap | null | undefined; resolveDir?: string | undefined; errors?: import("esbuild").PartialMessage[] | undefined; warnings?: import("esbuild").PartialMessage[] | undefined; watchFiles?: string[] | undefined; metafile?: import("esbuild").Metafile | undefined; }; export type TransformCallback = (args: OnLoadArgs & { code: string; loader: Loader; resolveDir?: string; }) => Promise | OnTransformResult | null | undefined | void; export type OnTransformRule = { options: OnTransformOptions; callback: TransformCallback; }; import { Buffer } from 'node:buffer';