main.d.ts 23 KB

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