diff --git a/lib/shared/types.ts b/lib/shared/types.ts index a954bfb14f2..4b44a00f9ab 100644 --- a/lib/shared/types.ts +++ b/lib/shared/types.ts @@ -274,15 +274,25 @@ export interface Plugin { } export interface PluginBuild { + /** Documentation: https://esbuild.github.io/plugins/#build-options */ initialOptions: BuildOptions; + + /** Documentation: https://esbuild.github.io/plugins/#resolve */ resolve(path: string, options?: ResolveOptions): Promise; + /** Documentation: https://esbuild.github.io/plugins/#on-start */ onStart(callback: () => (OnStartResult | null | void | Promise)): void; + + /** Documentation: https://esbuild.github.io/plugins/#on-end */ onEnd(callback: (result: BuildResult) => (OnEndResult | null | void | Promise)): void; + + /** Documentation: https://esbuild.github.io/plugins/#on-resolve */ onResolve(options: OnResolveOptions, callback: (args: OnResolveArgs) => (OnResolveResult | null | undefined | Promise)): void; + + /** Documentation: https://esbuild.github.io/plugins/#on-load */ onLoad(options: OnLoadOptions, callback: (args: OnLoadArgs) => (OnLoadResult | null | undefined | Promise)): void; @@ -302,6 +312,7 @@ export interface PluginBuild { }; } +/** Documentation: https://esbuild.github.io/plugins/#resolve-options */ export interface ResolveOptions { pluginName?: string; importer?: string; @@ -311,6 +322,7 @@ export interface ResolveOptions { pluginData?: any; } +/** Documentation: https://esbuild.github.io/plugins/#resolve-results */ export interface ResolveResult { errors: Message[]; warnings: Message[]; @@ -333,11 +345,13 @@ export interface OnEndResult { warnings?: PartialMessage[]; } +/** Documentation: https://esbuild.github.io/plugins/#on-resolve-options */ export interface OnResolveOptions { filter: RegExp; namespace?: string; } +/** Documentation: https://esbuild.github.io/plugins/#on-resolve-arguments */ export interface OnResolveArgs { path: string; importer: string; @@ -360,6 +374,7 @@ export type ImportKind = | 'import-rule' | 'url-token' +/** Documentation: https://esbuild.github.io/plugins/#on-resolve-results */ export interface OnResolveResult { pluginName?: string; @@ -377,11 +392,13 @@ export interface OnResolveResult { watchDirs?: string[]; } +/** Documentation: https://esbuild.github.io/plugins/#on-load-options */ export interface OnLoadOptions { filter: RegExp; namespace?: string; } +/** Documentation: https://esbuild.github.io/plugins/#on-load-arguments */ export interface OnLoadArgs { path: string; namespace: string; @@ -389,6 +406,7 @@ export interface OnLoadArgs { pluginData: any; } +/** Documentation: https://esbuild.github.io/plugins/#on-load-results */ export interface OnLoadResult { pluginName?: string; @@ -418,6 +436,7 @@ export interface PartialNote { location?: Partial | null; } +/** Documentation: https://esbuild.github.io/api/#metafile */ export interface Metafile { inputs: { [path: string]: { @@ -466,9 +485,15 @@ export interface WatchOptions { } export interface BuildContext { + /** Documentation: https://esbuild.github.io/api/#rebuild */ rebuild(): Promise> + + /** Documentation: https://esbuild.github.io/api/#watch */ watch(options?: WatchOptions): void + + /** Documentation: https://esbuild.github.io/api/#serve */ serve(options?: ServeOptions): Promise + dispose(): Promise } @@ -480,7 +505,7 @@ export interface BuildContext(options: SpecificOptions): Promise>; export declare function build(options: BuildOptions): Promise; @@ -492,7 +517,7 @@ export declare function build(options: BuildOptions): Promise; * - Works in node: yes * - Works in browser: no * - * Documentation: https://esbuild.github.io/api/#context-api + * Documentation: https://esbuild.github.io/api/#build */ export declare function context(options: T): Promise>; export declare function context(options: BuildOptions): Promise; @@ -506,7 +531,7 @@ export declare function context(options: BuildOptions): Promise; * - Works in node: yes * - Works in browser: yes * - * Documentation: https://esbuild.github.io/api/#transform-api + * Documentation: https://esbuild.github.io/api/#transform */ export declare function transform(input: string | Uint8Array, options?: SpecificOptions): Promise>; export declare function transform(input: string | Uint8Array, options?: TransformOptions): Promise; @@ -539,7 +564,7 @@ export declare function analyzeMetafile(metafile: Metafile | string, options?: A * - Works in node: yes * - Works in browser: no * - * Documentation: https://esbuild.github.io/api/#build-api + * Documentation: https://esbuild.github.io/api/#build */ export declare function buildSync(options: SpecificOptions): BuildResult; export declare function buildSync(options: BuildOptions): BuildResult; @@ -550,7 +575,7 @@ export declare function buildSync(options: BuildOptions): BuildResult; * - Works in node: yes * - Works in browser: no * - * Documentation: https://esbuild.github.io/api/#transform-api + * Documentation: https://esbuild.github.io/api/#transform */ export declare function transformSync(input: string, options?: SpecificOptions): TransformResult; export declare function transformSync(input: string | Uint8Array, options?: TransformOptions): TransformResult; @@ -581,7 +606,7 @@ export declare function analyzeMetafileSync(metafile: Metafile | string, options * - Works in node: yes * - Works in browser: yes ("options" is required) * - * Documentation: https://esbuild.github.io/api/#running-in-the-browser + * Documentation: https://esbuild.github.io/api/#browser */ export declare function initialize(options: InitializeOptions): Promise; diff --git a/pkg/api/api.go b/pkg/api/api.go index 93c1f1241dd..ec7604d8017 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -366,7 +366,7 @@ type OutputFile struct { Contents []byte } -// Documentation: https://esbuild.github.io/api/#build-api +// Documentation: https://esbuild.github.io/api/#build func Build(options BuildOptions) BuildResult { start := time.Now() @@ -451,7 +451,7 @@ type TransformResult struct { MangleCache map[string]interface{} } -// Documentation: https://esbuild.github.io/api/#transform-api +// Documentation: https://esbuild.github.io/api/#transform func Transform(input string, options TransformOptions) TransformResult { return transformImpl(input, options) } @@ -483,16 +483,19 @@ type ServeResult struct { Host string } -type OnChangeArgs struct { -} - type WatchOptions struct { } type BuildContext interface { + // Documentation: https://esbuild.github.io/api/#rebuild Rebuild() BuildResult + + // Documentation: https://esbuild.github.io/api/#watch Watch(options WatchOptions) error + + // Documentation: https://esbuild.github.io/api/#serve Serve(options ServeOptions) (ServeResult, error) + Dispose() } @@ -507,7 +510,7 @@ func (err *ContextError) Error() string { return "Context creation failed" } -// Documentation: https://esbuild.github.io/api/#context-api +// Documentation: https://esbuild.github.io/api/#build func Context(buildOptions BuildOptions) (BuildContext, *ContextError) { ctx, errors := contextImpl(buildOptions) if ctx == nil { @@ -532,14 +535,26 @@ type Plugin struct { } type PluginBuild struct { + // Documentation: https://esbuild.github.io/plugins/#build-options InitialOptions *BuildOptions - Resolve func(path string, options ResolveOptions) ResolveResult - OnStart func(callback func() (OnStartResult, error)) - OnEnd func(callback func(result *BuildResult) (OnEndResult, error)) - OnResolve func(options OnResolveOptions, callback func(OnResolveArgs) (OnResolveResult, error)) - OnLoad func(options OnLoadOptions, callback func(OnLoadArgs) (OnLoadResult, error)) + + // Documentation: https://esbuild.github.io/plugins/#resolve + Resolve func(path string, options ResolveOptions) ResolveResult + + // Documentation: https://esbuild.github.io/plugins/#on-start + OnStart func(callback func() (OnStartResult, error)) + + // Documentation: https://esbuild.github.io/plugins/#on-end + OnEnd func(callback func(result *BuildResult) (OnEndResult, error)) + + // Documentation: https://esbuild.github.io/plugins/#on-resolve + OnResolve func(options OnResolveOptions, callback func(OnResolveArgs) (OnResolveResult, error)) + + // Documentation: https://esbuild.github.io/plugins/#on-load + OnLoad func(options OnLoadOptions, callback func(OnLoadArgs) (OnLoadResult, error)) } +// Documentation: https://esbuild.github.io/plugins/#resolve-options type ResolveOptions struct { PluginName string Importer string @@ -549,6 +564,7 @@ type ResolveOptions struct { PluginData interface{} } +// Documentation: https://esbuild.github.io/plugins/#resolve-results type ResolveResult struct { Errors []Message Warnings []Message @@ -571,11 +587,13 @@ type OnEndResult struct { Warnings []Message } +// Documentation: https://esbuild.github.io/plugins/#on-resolve-options type OnResolveOptions struct { Filter string Namespace string } +// Documentation: https://esbuild.github.io/plugins/#on-resolve-arguments type OnResolveArgs struct { Path string Importer string @@ -585,6 +603,7 @@ type OnResolveArgs struct { PluginData interface{} } +// Documentation: https://esbuild.github.io/plugins/#on-resolve-results type OnResolveResult struct { PluginName string @@ -602,11 +621,13 @@ type OnResolveResult struct { WatchDirs []string } +// Documentation: https://esbuild.github.io/plugins/#on-load-options type OnLoadOptions struct { Filter string Namespace string } +// Documentation: https://esbuild.github.io/plugins/#on-load-arguments type OnLoadArgs struct { Path string Namespace string @@ -614,6 +635,7 @@ type OnLoadArgs struct { PluginData interface{} } +// Documentation: https://esbuild.github.io/plugins/#on-load-results type OnLoadResult struct { PluginName string