[d565449] | 1 | export type Platform = 'browser' | 'node' | 'neutral'
|
---|
| 2 | export type Format = 'iife' | 'cjs' | 'esm'
|
---|
| 3 | export type Loader = 'base64' | 'binary' | 'copy' | 'css' | 'dataurl' | 'default' | 'empty' | 'file' | 'js' | 'json' | 'jsx' | 'local-css' | 'text' | 'ts' | 'tsx'
|
---|
| 4 | export type LogLevel = 'verbose' | 'debug' | 'info' | 'warning' | 'error' | 'silent'
|
---|
| 5 | export type Charset = 'ascii' | 'utf8'
|
---|
| 6 | export type Drop = 'console' | 'debugger'
|
---|
| 7 |
|
---|
| 8 | interface CommonOptions {
|
---|
| 9 | /** Documentation: https://esbuild.github.io/api/#sourcemap */
|
---|
| 10 | sourcemap?: boolean | 'linked' | 'inline' | 'external' | 'both'
|
---|
| 11 | /** Documentation: https://esbuild.github.io/api/#legal-comments */
|
---|
| 12 | legalComments?: 'none' | 'inline' | 'eof' | 'linked' | 'external'
|
---|
| 13 | /** Documentation: https://esbuild.github.io/api/#source-root */
|
---|
| 14 | sourceRoot?: string
|
---|
| 15 | /** Documentation: https://esbuild.github.io/api/#sources-content */
|
---|
| 16 | sourcesContent?: boolean
|
---|
| 17 |
|
---|
| 18 | /** Documentation: https://esbuild.github.io/api/#format */
|
---|
| 19 | format?: Format
|
---|
| 20 | /** Documentation: https://esbuild.github.io/api/#global-name */
|
---|
| 21 | globalName?: string
|
---|
| 22 | /** Documentation: https://esbuild.github.io/api/#target */
|
---|
| 23 | target?: string | string[]
|
---|
| 24 | /** Documentation: https://esbuild.github.io/api/#supported */
|
---|
| 25 | supported?: Record<string, boolean>
|
---|
| 26 | /** Documentation: https://esbuild.github.io/api/#platform */
|
---|
| 27 | platform?: Platform
|
---|
| 28 |
|
---|
| 29 | /** Documentation: https://esbuild.github.io/api/#mangle-props */
|
---|
| 30 | mangleProps?: RegExp
|
---|
| 31 | /** Documentation: https://esbuild.github.io/api/#mangle-props */
|
---|
| 32 | reserveProps?: RegExp
|
---|
| 33 | /** Documentation: https://esbuild.github.io/api/#mangle-props */
|
---|
| 34 | mangleQuoted?: boolean
|
---|
| 35 | /** Documentation: https://esbuild.github.io/api/#mangle-props */
|
---|
| 36 | mangleCache?: Record<string, string | false>
|
---|
| 37 | /** Documentation: https://esbuild.github.io/api/#drop */
|
---|
| 38 | drop?: Drop[]
|
---|
| 39 | /** Documentation: https://esbuild.github.io/api/#drop-labels */
|
---|
| 40 | dropLabels?: string[]
|
---|
| 41 | /** Documentation: https://esbuild.github.io/api/#minify */
|
---|
| 42 | minify?: boolean
|
---|
| 43 | /** Documentation: https://esbuild.github.io/api/#minify */
|
---|
| 44 | minifyWhitespace?: boolean
|
---|
| 45 | /** Documentation: https://esbuild.github.io/api/#minify */
|
---|
| 46 | minifyIdentifiers?: boolean
|
---|
| 47 | /** Documentation: https://esbuild.github.io/api/#minify */
|
---|
| 48 | minifySyntax?: boolean
|
---|
| 49 | /** Documentation: https://esbuild.github.io/api/#line-limit */
|
---|
| 50 | lineLimit?: number
|
---|
| 51 | /** Documentation: https://esbuild.github.io/api/#charset */
|
---|
| 52 | charset?: Charset
|
---|
| 53 | /** Documentation: https://esbuild.github.io/api/#tree-shaking */
|
---|
| 54 | treeShaking?: boolean
|
---|
| 55 | /** Documentation: https://esbuild.github.io/api/#ignore-annotations */
|
---|
| 56 | ignoreAnnotations?: boolean
|
---|
| 57 |
|
---|
| 58 | /** Documentation: https://esbuild.github.io/api/#jsx */
|
---|
| 59 | jsx?: 'transform' | 'preserve' | 'automatic'
|
---|
| 60 | /** Documentation: https://esbuild.github.io/api/#jsx-factory */
|
---|
| 61 | jsxFactory?: string
|
---|
| 62 | /** Documentation: https://esbuild.github.io/api/#jsx-fragment */
|
---|
| 63 | jsxFragment?: string
|
---|
| 64 | /** Documentation: https://esbuild.github.io/api/#jsx-import-source */
|
---|
| 65 | jsxImportSource?: string
|
---|
| 66 | /** Documentation: https://esbuild.github.io/api/#jsx-development */
|
---|
| 67 | jsxDev?: boolean
|
---|
| 68 | /** Documentation: https://esbuild.github.io/api/#jsx-side-effects */
|
---|
| 69 | jsxSideEffects?: boolean
|
---|
| 70 |
|
---|
| 71 | /** Documentation: https://esbuild.github.io/api/#define */
|
---|
| 72 | define?: { [key: string]: string }
|
---|
| 73 | /** Documentation: https://esbuild.github.io/api/#pure */
|
---|
| 74 | pure?: string[]
|
---|
| 75 | /** Documentation: https://esbuild.github.io/api/#keep-names */
|
---|
| 76 | keepNames?: boolean
|
---|
| 77 |
|
---|
| 78 | /** Documentation: https://esbuild.github.io/api/#color */
|
---|
| 79 | color?: boolean
|
---|
| 80 | /** Documentation: https://esbuild.github.io/api/#log-level */
|
---|
| 81 | logLevel?: LogLevel
|
---|
| 82 | /** Documentation: https://esbuild.github.io/api/#log-limit */
|
---|
| 83 | logLimit?: number
|
---|
| 84 | /** Documentation: https://esbuild.github.io/api/#log-override */
|
---|
| 85 | logOverride?: Record<string, LogLevel>
|
---|
| 86 |
|
---|
| 87 | /** Documentation: https://esbuild.github.io/api/#tsconfig-raw */
|
---|
| 88 | tsconfigRaw?: string | TsconfigRaw
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | export interface TsconfigRaw {
|
---|
| 92 | compilerOptions?: {
|
---|
| 93 | alwaysStrict?: boolean
|
---|
| 94 | baseUrl?: string
|
---|
| 95 | experimentalDecorators?: boolean
|
---|
| 96 | importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
|
---|
| 97 | jsx?: 'preserve' | 'react-native' | 'react' | 'react-jsx' | 'react-jsxdev'
|
---|
| 98 | jsxFactory?: string
|
---|
| 99 | jsxFragmentFactory?: string
|
---|
| 100 | jsxImportSource?: string
|
---|
| 101 | paths?: Record<string, string[]>
|
---|
| 102 | preserveValueImports?: boolean
|
---|
| 103 | strict?: boolean
|
---|
| 104 | target?: string
|
---|
| 105 | useDefineForClassFields?: boolean
|
---|
| 106 | verbatimModuleSyntax?: boolean
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | export interface BuildOptions extends CommonOptions {
|
---|
| 111 | /** Documentation: https://esbuild.github.io/api/#bundle */
|
---|
| 112 | bundle?: boolean
|
---|
| 113 | /** Documentation: https://esbuild.github.io/api/#splitting */
|
---|
| 114 | splitting?: boolean
|
---|
| 115 | /** Documentation: https://esbuild.github.io/api/#preserve-symlinks */
|
---|
| 116 | preserveSymlinks?: boolean
|
---|
| 117 | /** Documentation: https://esbuild.github.io/api/#outfile */
|
---|
| 118 | outfile?: string
|
---|
| 119 | /** Documentation: https://esbuild.github.io/api/#metafile */
|
---|
| 120 | metafile?: boolean
|
---|
| 121 | /** Documentation: https://esbuild.github.io/api/#outdir */
|
---|
| 122 | outdir?: string
|
---|
| 123 | /** Documentation: https://esbuild.github.io/api/#outbase */
|
---|
| 124 | outbase?: string
|
---|
| 125 | /** Documentation: https://esbuild.github.io/api/#external */
|
---|
| 126 | external?: string[]
|
---|
| 127 | /** Documentation: https://esbuild.github.io/api/#packages */
|
---|
| 128 | packages?: 'external'
|
---|
| 129 | /** Documentation: https://esbuild.github.io/api/#alias */
|
---|
| 130 | alias?: Record<string, string>
|
---|
| 131 | /** Documentation: https://esbuild.github.io/api/#loader */
|
---|
| 132 | loader?: { [ext: string]: Loader }
|
---|
| 133 | /** Documentation: https://esbuild.github.io/api/#resolve-extensions */
|
---|
| 134 | resolveExtensions?: string[]
|
---|
| 135 | /** Documentation: https://esbuild.github.io/api/#main-fields */
|
---|
| 136 | mainFields?: string[]
|
---|
| 137 | /** Documentation: https://esbuild.github.io/api/#conditions */
|
---|
| 138 | conditions?: string[]
|
---|
| 139 | /** Documentation: https://esbuild.github.io/api/#write */
|
---|
| 140 | write?: boolean
|
---|
| 141 | /** Documentation: https://esbuild.github.io/api/#allow-overwrite */
|
---|
| 142 | allowOverwrite?: boolean
|
---|
| 143 | /** Documentation: https://esbuild.github.io/api/#tsconfig */
|
---|
| 144 | tsconfig?: string
|
---|
| 145 | /** Documentation: https://esbuild.github.io/api/#out-extension */
|
---|
| 146 | outExtension?: { [ext: string]: string }
|
---|
| 147 | /** Documentation: https://esbuild.github.io/api/#public-path */
|
---|
| 148 | publicPath?: string
|
---|
| 149 | /** Documentation: https://esbuild.github.io/api/#entry-names */
|
---|
| 150 | entryNames?: string
|
---|
| 151 | /** Documentation: https://esbuild.github.io/api/#chunk-names */
|
---|
| 152 | chunkNames?: string
|
---|
| 153 | /** Documentation: https://esbuild.github.io/api/#asset-names */
|
---|
| 154 | assetNames?: string
|
---|
| 155 | /** Documentation: https://esbuild.github.io/api/#inject */
|
---|
| 156 | inject?: string[]
|
---|
| 157 | /** Documentation: https://esbuild.github.io/api/#banner */
|
---|
| 158 | banner?: { [type: string]: string }
|
---|
| 159 | /** Documentation: https://esbuild.github.io/api/#footer */
|
---|
| 160 | footer?: { [type: string]: string }
|
---|
| 161 | /** Documentation: https://esbuild.github.io/api/#entry-points */
|
---|
| 162 | entryPoints?: string[] | Record<string, string> | { in: string, out: string }[]
|
---|
| 163 | /** Documentation: https://esbuild.github.io/api/#stdin */
|
---|
| 164 | stdin?: StdinOptions
|
---|
| 165 | /** Documentation: https://esbuild.github.io/plugins/ */
|
---|
| 166 | plugins?: Plugin[]
|
---|
| 167 | /** Documentation: https://esbuild.github.io/api/#working-directory */
|
---|
| 168 | absWorkingDir?: string
|
---|
| 169 | /** Documentation: https://esbuild.github.io/api/#node-paths */
|
---|
| 170 | nodePaths?: string[]; // The "NODE_PATH" variable from Node.js
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | export interface StdinOptions {
|
---|
| 174 | contents: string | Uint8Array
|
---|
| 175 | resolveDir?: string
|
---|
| 176 | sourcefile?: string
|
---|
| 177 | loader?: Loader
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | export interface Message {
|
---|
| 181 | id: string
|
---|
| 182 | pluginName: string
|
---|
| 183 | text: string
|
---|
| 184 | location: Location | null
|
---|
| 185 | notes: Note[]
|
---|
| 186 |
|
---|
| 187 | /**
|
---|
| 188 | * Optional user-specified data that is passed through unmodified. You can
|
---|
| 189 | * use this to stash the original error, for example.
|
---|
| 190 | */
|
---|
| 191 | detail: any
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | export interface Note {
|
---|
| 195 | text: string
|
---|
| 196 | location: Location | null
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | export interface Location {
|
---|
| 200 | file: string
|
---|
| 201 | namespace: string
|
---|
| 202 | /** 1-based */
|
---|
| 203 | line: number
|
---|
| 204 | /** 0-based, in bytes */
|
---|
| 205 | column: number
|
---|
| 206 | /** in bytes */
|
---|
| 207 | length: number
|
---|
| 208 | lineText: string
|
---|
| 209 | suggestion: string
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | export interface OutputFile {
|
---|
| 213 | path: string
|
---|
| 214 | contents: Uint8Array
|
---|
| 215 | hash: string
|
---|
| 216 | /** "contents" as text (changes automatically with "contents") */
|
---|
| 217 | readonly text: string
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | export interface BuildResult<ProvidedOptions extends BuildOptions = BuildOptions> {
|
---|
| 221 | errors: Message[]
|
---|
| 222 | warnings: Message[]
|
---|
| 223 | /** Only when "write: false" */
|
---|
| 224 | outputFiles: OutputFile[] | (ProvidedOptions['write'] extends false ? never : undefined)
|
---|
| 225 | /** Only when "metafile: true" */
|
---|
| 226 | metafile: Metafile | (ProvidedOptions['metafile'] extends true ? never : undefined)
|
---|
| 227 | /** Only when "mangleCache" is present */
|
---|
| 228 | mangleCache: Record<string, string | false> | (ProvidedOptions['mangleCache'] extends Object ? never : undefined)
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | export interface BuildFailure extends Error {
|
---|
| 232 | errors: Message[]
|
---|
| 233 | warnings: Message[]
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | /** Documentation: https://esbuild.github.io/api/#serve-arguments */
|
---|
| 237 | export interface ServeOptions {
|
---|
| 238 | port?: number
|
---|
| 239 | host?: string
|
---|
| 240 | servedir?: string
|
---|
| 241 | keyfile?: string
|
---|
| 242 | certfile?: string
|
---|
| 243 | fallback?: string
|
---|
| 244 | onRequest?: (args: ServeOnRequestArgs) => void
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | export interface ServeOnRequestArgs {
|
---|
| 248 | remoteAddress: string
|
---|
| 249 | method: string
|
---|
| 250 | path: string
|
---|
| 251 | status: number
|
---|
| 252 | /** The time to generate the response, not to send it */
|
---|
| 253 | timeInMS: number
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | /** Documentation: https://esbuild.github.io/api/#serve-return-values */
|
---|
| 257 | export interface ServeResult {
|
---|
| 258 | port: number
|
---|
| 259 | host: string
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | export interface TransformOptions extends CommonOptions {
|
---|
| 263 | /** Documentation: https://esbuild.github.io/api/#sourcefile */
|
---|
| 264 | sourcefile?: string
|
---|
| 265 | /** Documentation: https://esbuild.github.io/api/#loader */
|
---|
| 266 | loader?: Loader
|
---|
| 267 | /** Documentation: https://esbuild.github.io/api/#banner */
|
---|
| 268 | banner?: string
|
---|
| 269 | /** Documentation: https://esbuild.github.io/api/#footer */
|
---|
| 270 | footer?: string
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | export interface TransformResult<ProvidedOptions extends TransformOptions = TransformOptions> {
|
---|
| 274 | code: string
|
---|
| 275 | map: string
|
---|
| 276 | warnings: Message[]
|
---|
| 277 | /** Only when "mangleCache" is present */
|
---|
| 278 | mangleCache: Record<string, string | false> | (ProvidedOptions['mangleCache'] extends Object ? never : undefined)
|
---|
| 279 | /** Only when "legalComments" is "external" */
|
---|
| 280 | legalComments: string | (ProvidedOptions['legalComments'] extends 'external' ? never : undefined)
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | export interface TransformFailure extends Error {
|
---|
| 284 | errors: Message[]
|
---|
| 285 | warnings: Message[]
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | export interface Plugin {
|
---|
| 289 | name: string
|
---|
| 290 | setup: (build: PluginBuild) => (void | Promise<void>)
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | export interface PluginBuild {
|
---|
| 294 | /** Documentation: https://esbuild.github.io/plugins/#build-options */
|
---|
| 295 | initialOptions: BuildOptions
|
---|
| 296 |
|
---|
| 297 | /** Documentation: https://esbuild.github.io/plugins/#resolve */
|
---|
| 298 | resolve(path: string, options?: ResolveOptions): Promise<ResolveResult>
|
---|
| 299 |
|
---|
| 300 | /** Documentation: https://esbuild.github.io/plugins/#on-start */
|
---|
| 301 | onStart(callback: () =>
|
---|
| 302 | (OnStartResult | null | void | Promise<OnStartResult | null | void>)): void
|
---|
| 303 |
|
---|
| 304 | /** Documentation: https://esbuild.github.io/plugins/#on-end */
|
---|
| 305 | onEnd(callback: (result: BuildResult) =>
|
---|
| 306 | (OnEndResult | null | void | Promise<OnEndResult | null | void>)): void
|
---|
| 307 |
|
---|
| 308 | /** Documentation: https://esbuild.github.io/plugins/#on-resolve */
|
---|
| 309 | onResolve(options: OnResolveOptions, callback: (args: OnResolveArgs) =>
|
---|
| 310 | (OnResolveResult | null | undefined | Promise<OnResolveResult | null | undefined>)): void
|
---|
| 311 |
|
---|
| 312 | /** Documentation: https://esbuild.github.io/plugins/#on-load */
|
---|
| 313 | onLoad(options: OnLoadOptions, callback: (args: OnLoadArgs) =>
|
---|
| 314 | (OnLoadResult | null | undefined | Promise<OnLoadResult | null | undefined>)): void
|
---|
| 315 |
|
---|
| 316 | /** Documentation: https://esbuild.github.io/plugins/#on-dispose */
|
---|
| 317 | onDispose(callback: () => void): void
|
---|
| 318 |
|
---|
| 319 | // This is a full copy of the esbuild library in case you need it
|
---|
| 320 | esbuild: {
|
---|
| 321 | context: typeof context,
|
---|
| 322 | build: typeof build,
|
---|
| 323 | buildSync: typeof buildSync,
|
---|
| 324 | transform: typeof transform,
|
---|
| 325 | transformSync: typeof transformSync,
|
---|
| 326 | formatMessages: typeof formatMessages,
|
---|
| 327 | formatMessagesSync: typeof formatMessagesSync,
|
---|
| 328 | analyzeMetafile: typeof analyzeMetafile,
|
---|
| 329 | analyzeMetafileSync: typeof analyzeMetafileSync,
|
---|
| 330 | initialize: typeof initialize,
|
---|
| 331 | version: typeof version,
|
---|
| 332 | }
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | /** Documentation: https://esbuild.github.io/plugins/#resolve-options */
|
---|
| 336 | export interface ResolveOptions {
|
---|
| 337 | pluginName?: string
|
---|
| 338 | importer?: string
|
---|
| 339 | namespace?: string
|
---|
| 340 | resolveDir?: string
|
---|
| 341 | kind?: ImportKind
|
---|
| 342 | pluginData?: any
|
---|
| 343 | with?: Record<string, string>
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | /** Documentation: https://esbuild.github.io/plugins/#resolve-results */
|
---|
| 347 | export interface ResolveResult {
|
---|
| 348 | errors: Message[]
|
---|
| 349 | warnings: Message[]
|
---|
| 350 |
|
---|
| 351 | path: string
|
---|
| 352 | external: boolean
|
---|
| 353 | sideEffects: boolean
|
---|
| 354 | namespace: string
|
---|
| 355 | suffix: string
|
---|
| 356 | pluginData: any
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | export interface OnStartResult {
|
---|
| 360 | errors?: PartialMessage[]
|
---|
| 361 | warnings?: PartialMessage[]
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | export interface OnEndResult {
|
---|
| 365 | errors?: PartialMessage[]
|
---|
| 366 | warnings?: PartialMessage[]
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 | /** Documentation: https://esbuild.github.io/plugins/#on-resolve-options */
|
---|
| 370 | export interface OnResolveOptions {
|
---|
| 371 | filter: RegExp
|
---|
| 372 | namespace?: string
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | /** Documentation: https://esbuild.github.io/plugins/#on-resolve-arguments */
|
---|
| 376 | export interface OnResolveArgs {
|
---|
| 377 | path: string
|
---|
| 378 | importer: string
|
---|
| 379 | namespace: string
|
---|
| 380 | resolveDir: string
|
---|
| 381 | kind: ImportKind
|
---|
| 382 | pluginData: any
|
---|
| 383 | with: Record<string, string>
|
---|
| 384 | }
|
---|
| 385 |
|
---|
| 386 | export type ImportKind =
|
---|
| 387 | | 'entry-point'
|
---|
| 388 |
|
---|
| 389 | // JS
|
---|
| 390 | | 'import-statement'
|
---|
| 391 | | 'require-call'
|
---|
| 392 | | 'dynamic-import'
|
---|
| 393 | | 'require-resolve'
|
---|
| 394 |
|
---|
| 395 | // CSS
|
---|
| 396 | | 'import-rule'
|
---|
| 397 | | 'composes-from'
|
---|
| 398 | | 'url-token'
|
---|
| 399 |
|
---|
| 400 | /** Documentation: https://esbuild.github.io/plugins/#on-resolve-results */
|
---|
| 401 | export interface OnResolveResult {
|
---|
| 402 | pluginName?: string
|
---|
| 403 |
|
---|
| 404 | errors?: PartialMessage[]
|
---|
| 405 | warnings?: PartialMessage[]
|
---|
| 406 |
|
---|
| 407 | path?: string
|
---|
| 408 | external?: boolean
|
---|
| 409 | sideEffects?: boolean
|
---|
| 410 | namespace?: string
|
---|
| 411 | suffix?: string
|
---|
| 412 | pluginData?: any
|
---|
| 413 |
|
---|
| 414 | watchFiles?: string[]
|
---|
| 415 | watchDirs?: string[]
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | /** Documentation: https://esbuild.github.io/plugins/#on-load-options */
|
---|
| 419 | export interface OnLoadOptions {
|
---|
| 420 | filter: RegExp
|
---|
| 421 | namespace?: string
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | /** Documentation: https://esbuild.github.io/plugins/#on-load-arguments */
|
---|
| 425 | export interface OnLoadArgs {
|
---|
| 426 | path: string
|
---|
| 427 | namespace: string
|
---|
| 428 | suffix: string
|
---|
| 429 | pluginData: any
|
---|
| 430 | with: Record<string, string>
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | /** Documentation: https://esbuild.github.io/plugins/#on-load-results */
|
---|
| 434 | export interface OnLoadResult {
|
---|
| 435 | pluginName?: string
|
---|
| 436 |
|
---|
| 437 | errors?: PartialMessage[]
|
---|
| 438 | warnings?: PartialMessage[]
|
---|
| 439 |
|
---|
| 440 | contents?: string | Uint8Array
|
---|
| 441 | resolveDir?: string
|
---|
| 442 | loader?: Loader
|
---|
| 443 | pluginData?: any
|
---|
| 444 |
|
---|
| 445 | watchFiles?: string[]
|
---|
| 446 | watchDirs?: string[]
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | export interface PartialMessage {
|
---|
| 450 | id?: string
|
---|
| 451 | pluginName?: string
|
---|
| 452 | text?: string
|
---|
| 453 | location?: Partial<Location> | null
|
---|
| 454 | notes?: PartialNote[]
|
---|
| 455 | detail?: any
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 | export interface PartialNote {
|
---|
| 459 | text?: string
|
---|
| 460 | location?: Partial<Location> | null
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 | /** Documentation: https://esbuild.github.io/api/#metafile */
|
---|
| 464 | export interface Metafile {
|
---|
| 465 | inputs: {
|
---|
| 466 | [path: string]: {
|
---|
| 467 | bytes: number
|
---|
| 468 | imports: {
|
---|
| 469 | path: string
|
---|
| 470 | kind: ImportKind
|
---|
| 471 | external?: boolean
|
---|
| 472 | original?: string
|
---|
| 473 | with?: Record<string, string>
|
---|
| 474 | }[]
|
---|
| 475 | format?: 'cjs' | 'esm'
|
---|
| 476 | with?: Record<string, string>
|
---|
| 477 | }
|
---|
| 478 | }
|
---|
| 479 | outputs: {
|
---|
| 480 | [path: string]: {
|
---|
| 481 | bytes: number
|
---|
| 482 | inputs: {
|
---|
| 483 | [path: string]: {
|
---|
| 484 | bytesInOutput: number
|
---|
| 485 | }
|
---|
| 486 | }
|
---|
| 487 | imports: {
|
---|
| 488 | path: string
|
---|
| 489 | kind: ImportKind | 'file-loader'
|
---|
| 490 | external?: boolean
|
---|
| 491 | }[]
|
---|
| 492 | exports: string[]
|
---|
| 493 | entryPoint?: string
|
---|
| 494 | cssBundle?: string
|
---|
| 495 | }
|
---|
| 496 | }
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | export interface FormatMessagesOptions {
|
---|
| 500 | kind: 'error' | 'warning'
|
---|
| 501 | color?: boolean
|
---|
| 502 | terminalWidth?: number
|
---|
| 503 | }
|
---|
| 504 |
|
---|
| 505 | export interface AnalyzeMetafileOptions {
|
---|
| 506 | color?: boolean
|
---|
| 507 | verbose?: boolean
|
---|
| 508 | }
|
---|
| 509 |
|
---|
| 510 | export interface WatchOptions {
|
---|
| 511 | }
|
---|
| 512 |
|
---|
| 513 | export interface BuildContext<ProvidedOptions extends BuildOptions = BuildOptions> {
|
---|
| 514 | /** Documentation: https://esbuild.github.io/api/#rebuild */
|
---|
| 515 | rebuild(): Promise<BuildResult<ProvidedOptions>>
|
---|
| 516 |
|
---|
| 517 | /** Documentation: https://esbuild.github.io/api/#watch */
|
---|
| 518 | watch(options?: WatchOptions): Promise<void>
|
---|
| 519 |
|
---|
| 520 | /** Documentation: https://esbuild.github.io/api/#serve */
|
---|
| 521 | serve(options?: ServeOptions): Promise<ServeResult>
|
---|
| 522 |
|
---|
| 523 | cancel(): Promise<void>
|
---|
| 524 | dispose(): Promise<void>
|
---|
| 525 | }
|
---|
| 526 |
|
---|
| 527 | // This is a TypeScript type-level function which replaces any keys in "In"
|
---|
| 528 | // that aren't in "Out" with "never". We use this to reject properties with
|
---|
| 529 | // typos in object literals. See: https://stackoverflow.com/questions/49580725
|
---|
| 530 | type SameShape<Out, In extends Out> = In & { [Key in Exclude<keyof In, keyof Out>]: never }
|
---|
| 531 |
|
---|
| 532 | /**
|
---|
| 533 | * This function invokes the "esbuild" command-line tool for you. It returns a
|
---|
| 534 | * promise that either resolves with a "BuildResult" object or rejects with a
|
---|
| 535 | * "BuildFailure" object.
|
---|
| 536 | *
|
---|
| 537 | * - Works in node: yes
|
---|
| 538 | * - Works in browser: yes
|
---|
| 539 | *
|
---|
| 540 | * Documentation: https://esbuild.github.io/api/#build
|
---|
| 541 | */
|
---|
| 542 | export declare function build<T extends BuildOptions>(options: SameShape<BuildOptions, T>): Promise<BuildResult<T>>
|
---|
| 543 |
|
---|
| 544 | /**
|
---|
| 545 | * This is the advanced long-running form of "build" that supports additional
|
---|
| 546 | * features such as watch mode and a local development server.
|
---|
| 547 | *
|
---|
| 548 | * - Works in node: yes
|
---|
| 549 | * - Works in browser: no
|
---|
| 550 | *
|
---|
| 551 | * Documentation: https://esbuild.github.io/api/#build
|
---|
| 552 | */
|
---|
| 553 | export declare function context<T extends BuildOptions>(options: SameShape<BuildOptions, T>): Promise<BuildContext<T>>
|
---|
| 554 |
|
---|
| 555 | /**
|
---|
| 556 | * This function transforms a single JavaScript file. It can be used to minify
|
---|
| 557 | * JavaScript, convert TypeScript/JSX to JavaScript, or convert newer JavaScript
|
---|
| 558 | * to older JavaScript. It returns a promise that is either resolved with a
|
---|
| 559 | * "TransformResult" object or rejected with a "TransformFailure" object.
|
---|
| 560 | *
|
---|
| 561 | * - Works in node: yes
|
---|
| 562 | * - Works in browser: yes
|
---|
| 563 | *
|
---|
| 564 | * Documentation: https://esbuild.github.io/api/#transform
|
---|
| 565 | */
|
---|
| 566 | export declare function transform<T extends TransformOptions>(input: string | Uint8Array, options?: SameShape<TransformOptions, T>): Promise<TransformResult<T>>
|
---|
| 567 |
|
---|
| 568 | /**
|
---|
| 569 | * Converts log messages to formatted message strings suitable for printing in
|
---|
| 570 | * the terminal. This allows you to reuse the built-in behavior of esbuild's
|
---|
| 571 | * log message formatter. This is a batch-oriented API for efficiency.
|
---|
| 572 | *
|
---|
| 573 | * - Works in node: yes
|
---|
| 574 | * - Works in browser: yes
|
---|
| 575 | */
|
---|
| 576 | export declare function formatMessages(messages: PartialMessage[], options: FormatMessagesOptions): Promise<string[]>
|
---|
| 577 |
|
---|
| 578 | /**
|
---|
| 579 | * Pretty-prints an analysis of the metafile JSON to a string. This is just for
|
---|
| 580 | * convenience to be able to match esbuild's pretty-printing exactly. If you want
|
---|
| 581 | * to customize it, you can just inspect the data in the metafile yourself.
|
---|
| 582 | *
|
---|
| 583 | * - Works in node: yes
|
---|
| 584 | * - Works in browser: yes
|
---|
| 585 | *
|
---|
| 586 | * Documentation: https://esbuild.github.io/api/#analyze
|
---|
| 587 | */
|
---|
| 588 | export declare function analyzeMetafile(metafile: Metafile | string, options?: AnalyzeMetafileOptions): Promise<string>
|
---|
| 589 |
|
---|
| 590 | /**
|
---|
| 591 | * A synchronous version of "build".
|
---|
| 592 | *
|
---|
| 593 | * - Works in node: yes
|
---|
| 594 | * - Works in browser: no
|
---|
| 595 | *
|
---|
| 596 | * Documentation: https://esbuild.github.io/api/#build
|
---|
| 597 | */
|
---|
| 598 | export declare function buildSync<T extends BuildOptions>(options: SameShape<BuildOptions, T>): BuildResult<T>
|
---|
| 599 |
|
---|
| 600 | /**
|
---|
| 601 | * A synchronous version of "transform".
|
---|
| 602 | *
|
---|
| 603 | * - Works in node: yes
|
---|
| 604 | * - Works in browser: no
|
---|
| 605 | *
|
---|
| 606 | * Documentation: https://esbuild.github.io/api/#transform
|
---|
| 607 | */
|
---|
| 608 | export declare function transformSync<T extends TransformOptions>(input: string | Uint8Array, options?: SameShape<TransformOptions, T>): TransformResult<T>
|
---|
| 609 |
|
---|
| 610 | /**
|
---|
| 611 | * A synchronous version of "formatMessages".
|
---|
| 612 | *
|
---|
| 613 | * - Works in node: yes
|
---|
| 614 | * - Works in browser: no
|
---|
| 615 | */
|
---|
| 616 | export declare function formatMessagesSync(messages: PartialMessage[], options: FormatMessagesOptions): string[]
|
---|
| 617 |
|
---|
| 618 | /**
|
---|
| 619 | * A synchronous version of "analyzeMetafile".
|
---|
| 620 | *
|
---|
| 621 | * - Works in node: yes
|
---|
| 622 | * - Works in browser: no
|
---|
| 623 | *
|
---|
| 624 | * Documentation: https://esbuild.github.io/api/#analyze
|
---|
| 625 | */
|
---|
| 626 | export declare function analyzeMetafileSync(metafile: Metafile | string, options?: AnalyzeMetafileOptions): string
|
---|
| 627 |
|
---|
| 628 | /**
|
---|
| 629 | * This configures the browser-based version of esbuild. It is necessary to
|
---|
| 630 | * call this first and wait for the returned promise to be resolved before
|
---|
| 631 | * making other API calls when using esbuild in the browser.
|
---|
| 632 | *
|
---|
| 633 | * - Works in node: yes
|
---|
| 634 | * - Works in browser: yes ("options" is required)
|
---|
| 635 | *
|
---|
| 636 | * Documentation: https://esbuild.github.io/api/#browser
|
---|
| 637 | */
|
---|
| 638 | export declare function initialize(options: InitializeOptions): Promise<void>
|
---|
| 639 |
|
---|
| 640 | export interface InitializeOptions {
|
---|
| 641 | /**
|
---|
| 642 | * The URL of the "esbuild.wasm" file. This must be provided when running
|
---|
| 643 | * esbuild in the browser.
|
---|
| 644 | */
|
---|
| 645 | wasmURL?: string | URL
|
---|
| 646 |
|
---|
| 647 | /**
|
---|
| 648 | * The result of calling "new WebAssembly.Module(buffer)" where "buffer"
|
---|
| 649 | * is a typed array or ArrayBuffer containing the binary code of the
|
---|
| 650 | * "esbuild.wasm" file.
|
---|
| 651 | *
|
---|
| 652 | * You can use this as an alternative to "wasmURL" for environments where it's
|
---|
| 653 | * not possible to download the WebAssembly module.
|
---|
| 654 | */
|
---|
| 655 | wasmModule?: WebAssembly.Module
|
---|
| 656 |
|
---|
| 657 | /**
|
---|
| 658 | * By default esbuild runs the WebAssembly-based browser API in a web worker
|
---|
| 659 | * to avoid blocking the UI thread. This can be disabled by setting "worker"
|
---|
| 660 | * to false.
|
---|
| 661 | */
|
---|
| 662 | worker?: boolean
|
---|
| 663 | }
|
---|
| 664 |
|
---|
| 665 | export let version: string
|
---|
| 666 |
|
---|
| 667 | // Call this function to terminate esbuild's child process. The child process
|
---|
| 668 | // is not terminated and re-created after each API call because it's more
|
---|
| 669 | // efficient to keep it around when there are multiple API calls.
|
---|
| 670 | //
|
---|
| 671 | // In node this happens automatically before the parent node process exits. So
|
---|
| 672 | // you only need to call this if you know you will not make any more esbuild
|
---|
| 673 | // API calls and you want to clean up resources.
|
---|
| 674 | //
|
---|
| 675 | // Unlike node, Deno lacks the necessary APIs to clean up child processes
|
---|
| 676 | // automatically. You must manually call stop() in Deno when you're done
|
---|
| 677 | // using esbuild or Deno will continue running forever.
|
---|
| 678 | //
|
---|
| 679 | // Another reason you might want to call this is if you are using esbuild from
|
---|
| 680 | // within a Deno test. Deno fails tests that create a child process without
|
---|
| 681 | // killing it before the test ends, so you have to call this function (and
|
---|
| 682 | // await the returned promise) in every Deno test that uses esbuild.
|
---|
| 683 | export declare function stop(): Promise<void>
|
---|
| 684 |
|
---|
| 685 | // Note: These declarations exist to avoid type errors when you omit "dom" from
|
---|
| 686 | // "lib" in your "tsconfig.json" file. TypeScript confusingly declares the
|
---|
| 687 | // global "WebAssembly" type in "lib.dom.d.ts" even though it has nothing to do
|
---|
| 688 | // with the browser DOM and is present in many non-browser JavaScript runtimes
|
---|
| 689 | // (e.g. node and deno). Declaring it here allows esbuild's API to be used in
|
---|
| 690 | // these scenarios.
|
---|
| 691 | //
|
---|
| 692 | // There's an open issue about getting this problem corrected (although these
|
---|
| 693 | // declarations will need to remain even if this is fixed for backward
|
---|
| 694 | // compatibility with older TypeScript versions):
|
---|
| 695 | //
|
---|
| 696 | // https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/826
|
---|
| 697 | //
|
---|
| 698 | declare global {
|
---|
| 699 | namespace WebAssembly {
|
---|
| 700 | interface Module {
|
---|
| 701 | }
|
---|
| 702 | }
|
---|
| 703 | interface URL {
|
---|
| 704 | }
|
---|
| 705 | }
|
---|