main.d.ts 23 KB

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