main.d.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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?: '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. onRequest?: (args: ServeOnRequestArgs) => void
  227. }
  228. export interface ServeOnRequestArgs {
  229. remoteAddress: string
  230. method: string
  231. path: string
  232. status: number
  233. /** The time to generate the response, not to send it */
  234. timeInMS: number
  235. }
  236. /** Documentation: https://esbuild.github.io/api/#serve-return-values */
  237. export interface ServeResult {
  238. port: number
  239. host: string
  240. }
  241. export interface TransformOptions extends CommonOptions {
  242. /** Documentation: https://esbuild.github.io/api/#sourcefile */
  243. sourcefile?: string
  244. /** Documentation: https://esbuild.github.io/api/#loader */
  245. loader?: Loader
  246. /** Documentation: https://esbuild.github.io/api/#banner */
  247. banner?: string
  248. /** Documentation: https://esbuild.github.io/api/#footer */
  249. footer?: string
  250. }
  251. export interface TransformResult<ProvidedOptions extends TransformOptions = TransformOptions> {
  252. code: string
  253. map: string
  254. warnings: Message[]
  255. /** Only when "mangleCache" is present */
  256. mangleCache: Record<string, string | false> | (ProvidedOptions['mangleCache'] extends Object ? never : undefined)
  257. /** Only when "legalComments" is "external" */
  258. legalComments: string | (ProvidedOptions['legalComments'] extends 'external' ? never : undefined)
  259. }
  260. export interface TransformFailure extends Error {
  261. errors: Message[]
  262. warnings: Message[]
  263. }
  264. export interface Plugin {
  265. name: string
  266. setup: (build: PluginBuild) => (void | Promise<void>)
  267. }
  268. export interface PluginBuild {
  269. /** Documentation: https://esbuild.github.io/plugins/#build-options */
  270. initialOptions: BuildOptions
  271. /** Documentation: https://esbuild.github.io/plugins/#resolve */
  272. resolve(path: string, options?: ResolveOptions): Promise<ResolveResult>
  273. /** Documentation: https://esbuild.github.io/plugins/#on-start */
  274. onStart(callback: () =>
  275. (OnStartResult | null | void | Promise<OnStartResult | null | void>)): void
  276. /** Documentation: https://esbuild.github.io/plugins/#on-end */
  277. onEnd(callback: (result: BuildResult) =>
  278. (OnEndResult | null | void | Promise<OnEndResult | null | void>)): void
  279. /** Documentation: https://esbuild.github.io/plugins/#on-resolve */
  280. onResolve(options: OnResolveOptions, callback: (args: OnResolveArgs) =>
  281. (OnResolveResult | null | undefined | Promise<OnResolveResult | null | undefined>)): void
  282. /** Documentation: https://esbuild.github.io/plugins/#on-load */
  283. onLoad(options: OnLoadOptions, callback: (args: OnLoadArgs) =>
  284. (OnLoadResult | null | undefined | Promise<OnLoadResult | null | undefined>)): void
  285. /** Documentation: https://esbuild.github.io/plugins/#on-dispose */
  286. onDispose(callback: () => void): void
  287. // This is a full copy of the esbuild library in case you need it
  288. esbuild: {
  289. context: typeof context,
  290. build: typeof build,
  291. buildSync: typeof buildSync,
  292. transform: typeof transform,
  293. transformSync: typeof transformSync,
  294. formatMessages: typeof formatMessages,
  295. formatMessagesSync: typeof formatMessagesSync,
  296. analyzeMetafile: typeof analyzeMetafile,
  297. analyzeMetafileSync: typeof analyzeMetafileSync,
  298. initialize: typeof initialize,
  299. version: typeof version,
  300. }
  301. }
  302. /** Documentation: https://esbuild.github.io/plugins/#resolve-options */
  303. export interface ResolveOptions {
  304. pluginName?: string
  305. importer?: string
  306. namespace?: string
  307. resolveDir?: string
  308. kind?: ImportKind
  309. pluginData?: any
  310. with?: Record<string, string>
  311. }
  312. /** Documentation: https://esbuild.github.io/plugins/#resolve-results */
  313. export interface ResolveResult {
  314. errors: Message[]
  315. warnings: Message[]
  316. path: string
  317. external: boolean
  318. sideEffects: boolean
  319. namespace: string
  320. suffix: string
  321. pluginData: any
  322. }
  323. export interface OnStartResult {
  324. errors?: PartialMessage[]
  325. warnings?: PartialMessage[]
  326. }
  327. export interface OnEndResult {
  328. errors?: PartialMessage[]
  329. warnings?: PartialMessage[]
  330. }
  331. /** Documentation: https://esbuild.github.io/plugins/#on-resolve-options */
  332. export interface OnResolveOptions {
  333. filter: RegExp
  334. namespace?: string
  335. }
  336. /** Documentation: https://esbuild.github.io/plugins/#on-resolve-arguments */
  337. export interface OnResolveArgs {
  338. path: string
  339. importer: string
  340. namespace: string
  341. resolveDir: string
  342. kind: ImportKind
  343. pluginData: any
  344. with: Record<string, string>
  345. }
  346. export type ImportKind =
  347. | 'entry-point'
  348. // JS
  349. | 'import-statement'
  350. | 'require-call'
  351. | 'dynamic-import'
  352. | 'require-resolve'
  353. // CSS
  354. | 'import-rule'
  355. | 'composes-from'
  356. | 'url-token'
  357. /** Documentation: https://esbuild.github.io/plugins/#on-resolve-results */
  358. export interface OnResolveResult {
  359. pluginName?: string
  360. errors?: PartialMessage[]
  361. warnings?: PartialMessage[]
  362. path?: string
  363. external?: boolean
  364. sideEffects?: boolean
  365. namespace?: string
  366. suffix?: string
  367. pluginData?: any
  368. watchFiles?: string[]
  369. watchDirs?: string[]
  370. }
  371. /** Documentation: https://esbuild.github.io/plugins/#on-load-options */
  372. export interface OnLoadOptions {
  373. filter: RegExp
  374. namespace?: string
  375. }
  376. /** Documentation: https://esbuild.github.io/plugins/#on-load-arguments */
  377. export interface OnLoadArgs {
  378. path: string
  379. namespace: string
  380. suffix: string
  381. pluginData: any
  382. with: Record<string, string>
  383. }
  384. /** Documentation: https://esbuild.github.io/plugins/#on-load-results */
  385. export interface OnLoadResult {
  386. pluginName?: string
  387. errors?: PartialMessage[]
  388. warnings?: PartialMessage[]
  389. contents?: string | Uint8Array
  390. resolveDir?: string
  391. loader?: Loader
  392. pluginData?: any
  393. watchFiles?: string[]
  394. watchDirs?: string[]
  395. }
  396. export interface PartialMessage {
  397. id?: string
  398. pluginName?: string
  399. text?: string
  400. location?: Partial<Location> | null
  401. notes?: PartialNote[]
  402. detail?: any
  403. }
  404. export interface PartialNote {
  405. text?: string
  406. location?: Partial<Location> | null
  407. }
  408. /** Documentation: https://esbuild.github.io/api/#metafile */
  409. export interface Metafile {
  410. inputs: {
  411. [path: string]: {
  412. bytes: number
  413. imports: {
  414. path: string
  415. kind: ImportKind
  416. external?: boolean
  417. original?: string
  418. with?: Record<string, string>
  419. }[]
  420. format?: 'cjs' | 'esm'
  421. with?: Record<string, string>
  422. }
  423. }
  424. outputs: {
  425. [path: string]: {
  426. bytes: number
  427. inputs: {
  428. [path: string]: {
  429. bytesInOutput: number
  430. }
  431. }
  432. imports: {
  433. path: string
  434. kind: ImportKind | 'file-loader'
  435. external?: boolean
  436. }[]
  437. exports: string[]
  438. entryPoint?: string
  439. cssBundle?: string
  440. }
  441. }
  442. }
  443. export interface FormatMessagesOptions {
  444. kind: 'error' | 'warning'
  445. color?: boolean
  446. terminalWidth?: number
  447. }
  448. export interface AnalyzeMetafileOptions {
  449. color?: boolean
  450. verbose?: boolean
  451. }
  452. export interface WatchOptions {
  453. }
  454. export interface BuildContext<ProvidedOptions extends BuildOptions = BuildOptions> {
  455. /** Documentation: https://esbuild.github.io/api/#rebuild */
  456. rebuild(): Promise<BuildResult<ProvidedOptions>>
  457. /** Documentation: https://esbuild.github.io/api/#watch */
  458. watch(options?: WatchOptions): Promise<void>
  459. /** Documentation: https://esbuild.github.io/api/#serve */
  460. serve(options?: ServeOptions): Promise<ServeResult>
  461. cancel(): Promise<void>
  462. dispose(): Promise<void>
  463. }
  464. // This is a TypeScript type-level function which replaces any keys in "In"
  465. // that aren't in "Out" with "never". We use this to reject properties with
  466. // typos in object literals. See: https://stackoverflow.com/questions/49580725
  467. type SameShape<Out, In extends Out> = In & { [Key in Exclude<keyof In, keyof Out>]: never }
  468. /**
  469. * This function invokes the "esbuild" command-line tool for you. It returns a
  470. * promise that either resolves with a "BuildResult" object or rejects with a
  471. * "BuildFailure" object.
  472. *
  473. * - Works in node: yes
  474. * - Works in browser: yes
  475. *
  476. * Documentation: https://esbuild.github.io/api/#build
  477. */
  478. export declare function build<T extends BuildOptions>(options: SameShape<BuildOptions, T>): Promise<BuildResult<T>>
  479. /**
  480. * This is the advanced long-running form of "build" that supports additional
  481. * features such as watch mode and a local development server.
  482. *
  483. * - Works in node: yes
  484. * - Works in browser: no
  485. *
  486. * Documentation: https://esbuild.github.io/api/#build
  487. */
  488. export declare function context<T extends BuildOptions>(options: SameShape<BuildOptions, T>): Promise<BuildContext<T>>
  489. /**
  490. * This function transforms a single JavaScript file. It can be used to minify
  491. * JavaScript, convert TypeScript/JSX to JavaScript, or convert newer JavaScript
  492. * to older JavaScript. It returns a promise that is either resolved with a
  493. * "TransformResult" object or rejected with a "TransformFailure" object.
  494. *
  495. * - Works in node: yes
  496. * - Works in browser: yes
  497. *
  498. * Documentation: https://esbuild.github.io/api/#transform
  499. */
  500. export declare function transform<T extends TransformOptions>(input: string | Uint8Array, options?: SameShape<TransformOptions, T>): Promise<TransformResult<T>>
  501. /**
  502. * Converts log messages to formatted message strings suitable for printing in
  503. * the terminal. This allows you to reuse the built-in behavior of esbuild's
  504. * log message formatter. This is a batch-oriented API for efficiency.
  505. *
  506. * - Works in node: yes
  507. * - Works in browser: yes
  508. */
  509. export declare function formatMessages(messages: PartialMessage[], options: FormatMessagesOptions): Promise<string[]>
  510. /**
  511. * Pretty-prints an analysis of the metafile JSON to a string. This is just for
  512. * convenience to be able to match esbuild's pretty-printing exactly. If you want
  513. * to customize it, you can just inspect the data in the metafile yourself.
  514. *
  515. * - Works in node: yes
  516. * - Works in browser: yes
  517. *
  518. * Documentation: https://esbuild.github.io/api/#analyze
  519. */
  520. export declare function analyzeMetafile(metafile: Metafile | string, options?: AnalyzeMetafileOptions): Promise<string>
  521. /**
  522. * A synchronous version of "build".
  523. *
  524. * - Works in node: yes
  525. * - Works in browser: no
  526. *
  527. * Documentation: https://esbuild.github.io/api/#build
  528. */
  529. export declare function buildSync<T extends BuildOptions>(options: SameShape<BuildOptions, T>): BuildResult<T>
  530. /**
  531. * A synchronous version of "transform".
  532. *
  533. * - Works in node: yes
  534. * - Works in browser: no
  535. *
  536. * Documentation: https://esbuild.github.io/api/#transform
  537. */
  538. export declare function transformSync<T extends TransformOptions>(input: string | Uint8Array, options?: SameShape<TransformOptions, T>): TransformResult<T>
  539. /**
  540. * A synchronous version of "formatMessages".
  541. *
  542. * - Works in node: yes
  543. * - Works in browser: no
  544. */
  545. export declare function formatMessagesSync(messages: PartialMessage[], options: FormatMessagesOptions): string[]
  546. /**
  547. * A synchronous version of "analyzeMetafile".
  548. *
  549. * - Works in node: yes
  550. * - Works in browser: no
  551. *
  552. * Documentation: https://esbuild.github.io/api/#analyze
  553. */
  554. export declare function analyzeMetafileSync(metafile: Metafile | string, options?: AnalyzeMetafileOptions): string
  555. /**
  556. * This configures the browser-based version of esbuild. It is necessary to
  557. * call this first and wait for the returned promise to be resolved before
  558. * making other API calls when using esbuild in the browser.
  559. *
  560. * - Works in node: yes
  561. * - Works in browser: yes ("options" is required)
  562. *
  563. * Documentation: https://esbuild.github.io/api/#browser
  564. */
  565. export declare function initialize(options: InitializeOptions): Promise<void>
  566. export interface InitializeOptions {
  567. /**
  568. * The URL of the "esbuild.wasm" file. This must be provided when running
  569. * esbuild in the browser.
  570. */
  571. wasmURL?: string | URL
  572. /**
  573. * The result of calling "new WebAssembly.Module(buffer)" where "buffer"
  574. * is a typed array or ArrayBuffer containing the binary code of the
  575. * "esbuild.wasm" file.
  576. *
  577. * You can use this as an alternative to "wasmURL" for environments where it's
  578. * not possible to download the WebAssembly module.
  579. */
  580. wasmModule?: WebAssembly.Module
  581. /**
  582. * By default esbuild runs the WebAssembly-based browser API in a web worker
  583. * to avoid blocking the UI thread. This can be disabled by setting "worker"
  584. * to false.
  585. */
  586. worker?: boolean
  587. }
  588. export let version: string
  589. // Call this function to terminate esbuild's child process. The child process
  590. // is not terminated and re-created after each API call because it's more
  591. // efficient to keep it around when there are multiple API calls.
  592. //
  593. // In node this happens automatically before the parent node process exits. So
  594. // you only need to call this if you know you will not make any more esbuild
  595. // API calls and you want to clean up resources.
  596. //
  597. // Unlike node, Deno lacks the necessary APIs to clean up child processes
  598. // automatically. You must manually call stop() in Deno when you're done
  599. // using esbuild or Deno will continue running forever.
  600. //
  601. // Another reason you might want to call this is if you are using esbuild from
  602. // within a Deno test. Deno fails tests that create a child process without
  603. // killing it before the test ends, so you have to call this function (and
  604. // await the returned promise) in every Deno test that uses esbuild.
  605. export declare function stop(): Promise<void>
  606. // Note: These declarations exist to avoid type errors when you omit "dom" from
  607. // "lib" in your "tsconfig.json" file. TypeScript confusingly declares the
  608. // global "WebAssembly" type in "lib.dom.d.ts" even though it has nothing to do
  609. // with the browser DOM and is present in many non-browser JavaScript runtimes
  610. // (e.g. node and deno). Declaring it here allows esbuild's API to be used in
  611. // these scenarios.
  612. //
  613. // There's an open issue about getting this problem corrected (although these
  614. // declarations will need to remain even if this is fixed for backward
  615. // compatibility with older TypeScript versions):
  616. //
  617. // https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/826
  618. //
  619. declare global {
  620. namespace WebAssembly {
  621. interface Module {
  622. }
  623. }
  624. interface URL {
  625. }
  626. }