esbuild 0.17.19 → 0.25.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/esbuild CHANGED
@@ -37,6 +37,7 @@ var knownWindowsPackages = {
37
37
  "win32 x64 LE": "@esbuild/win32-x64"
38
38
  };
39
39
  var knownUnixlikePackages = {
40
+ "aix ppc64 BE": "@esbuild/aix-ppc64",
40
41
  "android arm64 LE": "@esbuild/android-arm64",
41
42
  "darwin arm64 LE": "@esbuild/darwin-arm64",
42
43
  "darwin x64 LE": "@esbuild/darwin-x64",
@@ -51,13 +52,16 @@ var knownUnixlikePackages = {
51
52
  "linux s390x BE": "@esbuild/linux-s390x",
52
53
  "linux x64 LE": "@esbuild/linux-x64",
53
54
  "linux loong64 LE": "@esbuild/linux-loong64",
55
+ "netbsd arm64 LE": "@esbuild/netbsd-arm64",
54
56
  "netbsd x64 LE": "@esbuild/netbsd-x64",
57
+ "openbsd arm64 LE": "@esbuild/openbsd-arm64",
55
58
  "openbsd x64 LE": "@esbuild/openbsd-x64",
56
59
  "sunos x64 LE": "@esbuild/sunos-x64"
57
60
  };
58
61
  var knownWebAssemblyFallbackPackages = {
59
62
  "android arm LE": "@esbuild/android-arm",
60
- "android x64 LE": "@esbuild/android-x64"
63
+ "android x64 LE": "@esbuild/android-x64",
64
+ "openharmony arm64 LE": "@esbuild/openharmony-arm64"
61
65
  };
62
66
  function pkgAndSubpathForCurrentPlatform() {
63
67
  let pkg;
@@ -86,16 +90,14 @@ function pkgForSomeOtherPlatform() {
86
90
  for (const unixKey in knownUnixlikePackages) {
87
91
  try {
88
92
  const pkg = knownUnixlikePackages[unixKey];
89
- if (fs.existsSync(path.join(nodeModulesDirectory, pkg)))
90
- return pkg;
93
+ if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
91
94
  } catch {
92
95
  }
93
96
  }
94
97
  for (const windowsKey in knownWindowsPackages) {
95
98
  try {
96
99
  const pkg = knownWindowsPackages[windowsKey];
97
- if (fs.existsSync(path.join(nodeModulesDirectory, pkg)))
98
- return pkg;
100
+ if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
99
101
  } catch {
100
102
  }
101
103
  }
@@ -199,7 +201,7 @@ for your current platform.`);
199
201
  "node_modules",
200
202
  ".cache",
201
203
  "esbuild",
202
- `pnpapi-${pkg.replace("/", "-")}-${"0.17.19"}-${path.basename(subpath)}`
204
+ `pnpapi-${pkg.replace("/", "-")}-${"0.25.10"}-${path.basename(subpath)}`
203
205
  );
204
206
  if (!fs.existsSync(binTargetPath)) {
205
207
  fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
package/install.js CHANGED
@@ -34,6 +34,7 @@ var knownWindowsPackages = {
34
34
  "win32 x64 LE": "@esbuild/win32-x64"
35
35
  };
36
36
  var knownUnixlikePackages = {
37
+ "aix ppc64 BE": "@esbuild/aix-ppc64",
37
38
  "android arm64 LE": "@esbuild/android-arm64",
38
39
  "darwin arm64 LE": "@esbuild/darwin-arm64",
39
40
  "darwin x64 LE": "@esbuild/darwin-x64",
@@ -48,13 +49,16 @@ var knownUnixlikePackages = {
48
49
  "linux s390x BE": "@esbuild/linux-s390x",
49
50
  "linux x64 LE": "@esbuild/linux-x64",
50
51
  "linux loong64 LE": "@esbuild/linux-loong64",
52
+ "netbsd arm64 LE": "@esbuild/netbsd-arm64",
51
53
  "netbsd x64 LE": "@esbuild/netbsd-x64",
54
+ "openbsd arm64 LE": "@esbuild/openbsd-arm64",
52
55
  "openbsd x64 LE": "@esbuild/openbsd-x64",
53
56
  "sunos x64 LE": "@esbuild/sunos-x64"
54
57
  };
55
58
  var knownWebAssemblyFallbackPackages = {
56
59
  "android arm LE": "@esbuild/android-arm",
57
- "android x64 LE": "@esbuild/android-x64"
60
+ "android x64 LE": "@esbuild/android-x64",
61
+ "openharmony arm64 LE": "@esbuild/openharmony-arm64"
58
62
  };
59
63
  function pkgAndSubpathForCurrentPlatform() {
60
64
  let pkg;
@@ -166,8 +170,7 @@ function extractFileFromTarGzip(buffer, subpath) {
166
170
  let size = parseInt(str(offset + 124, 12), 8);
167
171
  offset += 512;
168
172
  if (!isNaN(size)) {
169
- if (name === subpath)
170
- return buffer.subarray(offset, offset + size);
173
+ if (name === subpath) return buffer.subarray(offset, offset + size);
171
174
  offset += size + 511 & ~511;
172
175
  }
173
176
  }
@@ -202,10 +205,8 @@ function removeRecursive(dir) {
202
205
  } catch {
203
206
  continue;
204
207
  }
205
- if (stats.isDirectory())
206
- removeRecursive(entryPath);
207
- else
208
- fs2.unlinkSync(entryPath);
208
+ if (stats.isDirectory()) removeRecursive(entryPath);
209
+ else fs2.unlinkSync(entryPath);
209
210
  }
210
211
  fs2.rmdirSync(dir);
211
212
  }
@@ -220,7 +221,8 @@ require('child_process').execFileSync(${pathString}, process.argv.slice(2), { st
220
221
  ${code}`);
221
222
  }
222
223
  function maybeOptimizePackage(binPath) {
223
- if (os2.platform() !== "win32" && !isYarn()) {
224
+ const { isWASM } = pkgAndSubpathForCurrentPlatform();
225
+ if (os2.platform() !== "win32" && !isYarn() && !isWASM) {
224
226
  const tempPath = path2.join(__dirname, "bin-esbuild");
225
227
  try {
226
228
  fs2.linkSync(binPath, tempPath);
package/lib/main.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  export type Platform = 'browser' | 'node' | 'neutral'
2
2
  export type Format = 'iife' | 'cjs' | 'esm'
3
- export type Loader = 'base64' | 'binary' | 'copy' | 'css' | 'dataurl' | 'default' | 'empty' | 'file' | 'js' | 'json' | 'jsx' | 'text' | 'ts' | 'tsx'
3
+ export type Loader = 'base64' | 'binary' | 'copy' | 'css' | 'dataurl' | 'default' | 'empty' | 'file' | 'js' | 'json' | 'jsx' | 'local-css' | 'text' | 'ts' | 'tsx'
4
4
  export type LogLevel = 'verbose' | 'debug' | 'info' | 'warning' | 'error' | 'silent'
5
5
  export type Charset = 'ascii' | 'utf8'
6
6
  export type Drop = 'console' | 'debugger'
7
+ export type AbsPaths = 'code' | 'log' | 'metafile'
7
8
 
8
9
  interface CommonOptions {
9
10
  /** Documentation: https://esbuild.github.io/api/#sourcemap */
@@ -36,6 +37,8 @@ interface CommonOptions {
36
37
  mangleCache?: Record<string, string | false>
37
38
  /** Documentation: https://esbuild.github.io/api/#drop */
38
39
  drop?: Drop[]
40
+ /** Documentation: https://esbuild.github.io/api/#drop-labels */
41
+ dropLabels?: string[]
39
42
  /** Documentation: https://esbuild.github.io/api/#minify */
40
43
  minify?: boolean
41
44
  /** Documentation: https://esbuild.github.io/api/#minify */
@@ -44,6 +47,8 @@ interface CommonOptions {
44
47
  minifyIdentifiers?: boolean
45
48
  /** Documentation: https://esbuild.github.io/api/#minify */
46
49
  minifySyntax?: boolean
50
+ /** Documentation: https://esbuild.github.io/api/#line-limit */
51
+ lineLimit?: number
47
52
  /** Documentation: https://esbuild.github.io/api/#charset */
48
53
  charset?: Charset
49
54
  /** Documentation: https://esbuild.github.io/api/#tree-shaking */
@@ -71,6 +76,8 @@ interface CommonOptions {
71
76
  /** Documentation: https://esbuild.github.io/api/#keep-names */
72
77
  keepNames?: boolean
73
78
 
79
+ /** Documentation: https://esbuild.github.io/api/#abs-paths */
80
+ absPaths?: AbsPaths[]
74
81
  /** Documentation: https://esbuild.github.io/api/#color */
75
82
  color?: boolean
76
83
  /** Documentation: https://esbuild.github.io/api/#log-level */
@@ -79,6 +86,28 @@ interface CommonOptions {
79
86
  logLimit?: number
80
87
  /** Documentation: https://esbuild.github.io/api/#log-override */
81
88
  logOverride?: Record<string, LogLevel>
89
+
90
+ /** Documentation: https://esbuild.github.io/api/#tsconfig-raw */
91
+ tsconfigRaw?: string | TsconfigRaw
92
+ }
93
+
94
+ export interface TsconfigRaw {
95
+ compilerOptions?: {
96
+ alwaysStrict?: boolean
97
+ baseUrl?: string
98
+ experimentalDecorators?: boolean
99
+ importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
100
+ jsx?: 'preserve' | 'react-native' | 'react' | 'react-jsx' | 'react-jsxdev'
101
+ jsxFactory?: string
102
+ jsxFragmentFactory?: string
103
+ jsxImportSource?: string
104
+ paths?: Record<string, string[]>
105
+ preserveValueImports?: boolean
106
+ strict?: boolean
107
+ target?: string
108
+ useDefineForClassFields?: boolean
109
+ verbatimModuleSyntax?: boolean
110
+ }
82
111
  }
83
112
 
84
113
  export interface BuildOptions extends CommonOptions {
@@ -99,7 +128,7 @@ export interface BuildOptions extends CommonOptions {
99
128
  /** Documentation: https://esbuild.github.io/api/#external */
100
129
  external?: string[]
101
130
  /** Documentation: https://esbuild.github.io/api/#packages */
102
- packages?: 'external'
131
+ packages?: 'bundle' | 'external'
103
132
  /** Documentation: https://esbuild.github.io/api/#alias */
104
133
  alias?: Record<string, string>
105
134
  /** Documentation: https://esbuild.github.io/api/#loader */
@@ -133,7 +162,7 @@ export interface BuildOptions extends CommonOptions {
133
162
  /** Documentation: https://esbuild.github.io/api/#footer */
134
163
  footer?: { [type: string]: string }
135
164
  /** Documentation: https://esbuild.github.io/api/#entry-points */
136
- entryPoints?: string[] | Record<string, string> | { in: string, out: string }[]
165
+ entryPoints?: (string | { in: string, out: string })[] | Record<string, string>
137
166
  /** Documentation: https://esbuild.github.io/api/#stdin */
138
167
  stdin?: StdinOptions
139
168
  /** Documentation: https://esbuild.github.io/plugins/ */
@@ -185,21 +214,21 @@ export interface Location {
185
214
 
186
215
  export interface OutputFile {
187
216
  path: string
188
- /** "text" as bytes */
189
217
  contents: Uint8Array
218
+ hash: string
190
219
  /** "contents" as text (changes automatically with "contents") */
191
220
  readonly text: string
192
221
  }
193
222
 
194
- export interface BuildResult<SpecificOptions extends BuildOptions = BuildOptions> {
223
+ export interface BuildResult<ProvidedOptions extends BuildOptions = BuildOptions> {
195
224
  errors: Message[]
196
225
  warnings: Message[]
197
226
  /** Only when "write: false" */
198
- outputFiles: OutputFile[] | (SpecificOptions['write'] extends false ? never : undefined)
227
+ outputFiles: OutputFile[] | (ProvidedOptions['write'] extends false ? never : undefined)
199
228
  /** Only when "metafile: true" */
200
- metafile: Metafile | (SpecificOptions['metafile'] extends true ? never : undefined)
229
+ metafile: Metafile | (ProvidedOptions['metafile'] extends true ? never : undefined)
201
230
  /** Only when "mangleCache" is present */
202
- mangleCache: Record<string, string | false> | (SpecificOptions['mangleCache'] extends Object ? never : undefined)
231
+ mangleCache: Record<string, string | false> | (ProvidedOptions['mangleCache'] extends Object ? never : undefined)
203
232
  }
204
233
 
205
234
  export interface BuildFailure extends Error {
@@ -214,9 +243,16 @@ export interface ServeOptions {
214
243
  servedir?: string
215
244
  keyfile?: string
216
245
  certfile?: string
246
+ fallback?: string
247
+ cors?: CORSOptions
217
248
  onRequest?: (args: ServeOnRequestArgs) => void
218
249
  }
219
250
 
251
+ /** Documentation: https://esbuild.github.io/api/#cors */
252
+ export interface CORSOptions {
253
+ origin?: string | string[]
254
+ }
255
+
220
256
  export interface ServeOnRequestArgs {
221
257
  remoteAddress: string
222
258
  method: string
@@ -229,38 +265,28 @@ export interface ServeOnRequestArgs {
229
265
  /** Documentation: https://esbuild.github.io/api/#serve-return-values */
230
266
  export interface ServeResult {
231
267
  port: number
232
- host: string
268
+ hosts: string[]
233
269
  }
234
270
 
235
271
  export interface TransformOptions extends CommonOptions {
236
- tsconfigRaw?: string | {
237
- compilerOptions?: {
238
- alwaysStrict?: boolean,
239
- importsNotUsedAsValues?: 'remove' | 'preserve' | 'error',
240
- jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve',
241
- jsxFactory?: string,
242
- jsxFragmentFactory?: string,
243
- jsxImportSource?: string,
244
- preserveValueImports?: boolean,
245
- target?: string,
246
- useDefineForClassFields?: boolean,
247
- },
248
- }
249
-
272
+ /** Documentation: https://esbuild.github.io/api/#sourcefile */
250
273
  sourcefile?: string
274
+ /** Documentation: https://esbuild.github.io/api/#loader */
251
275
  loader?: Loader
276
+ /** Documentation: https://esbuild.github.io/api/#banner */
252
277
  banner?: string
278
+ /** Documentation: https://esbuild.github.io/api/#footer */
253
279
  footer?: string
254
280
  }
255
281
 
256
- export interface TransformResult<SpecificOptions extends TransformOptions = TransformOptions> {
282
+ export interface TransformResult<ProvidedOptions extends TransformOptions = TransformOptions> {
257
283
  code: string
258
284
  map: string
259
285
  warnings: Message[]
260
286
  /** Only when "mangleCache" is present */
261
- mangleCache: Record<string, string | false> | (SpecificOptions['mangleCache'] extends Object ? never : undefined)
287
+ mangleCache: Record<string, string | false> | (ProvidedOptions['mangleCache'] extends Object ? never : undefined)
262
288
  /** Only when "legalComments" is "external" */
263
- legalComments: string | (SpecificOptions['legalComments'] extends 'external' ? never : undefined)
289
+ legalComments: string | (ProvidedOptions['legalComments'] extends 'external' ? never : undefined)
264
290
  }
265
291
 
266
292
  export interface TransformFailure extends Error {
@@ -323,6 +349,7 @@ export interface ResolveOptions {
323
349
  resolveDir?: string
324
350
  kind?: ImportKind
325
351
  pluginData?: any
352
+ with?: Record<string, string>
326
353
  }
327
354
 
328
355
  /** Documentation: https://esbuild.github.io/plugins/#resolve-results */
@@ -362,6 +389,7 @@ export interface OnResolveArgs {
362
389
  resolveDir: string
363
390
  kind: ImportKind
364
391
  pluginData: any
392
+ with: Record<string, string>
365
393
  }
366
394
 
367
395
  export type ImportKind =
@@ -375,6 +403,7 @@ export type ImportKind =
375
403
 
376
404
  // CSS
377
405
  | 'import-rule'
406
+ | 'composes-from'
378
407
  | 'url-token'
379
408
 
380
409
  /** Documentation: https://esbuild.github.io/plugins/#on-resolve-results */
@@ -407,6 +436,7 @@ export interface OnLoadArgs {
407
436
  namespace: string
408
437
  suffix: string
409
438
  pluginData: any
439
+ with: Record<string, string>
410
440
  }
411
441
 
412
442
  /** Documentation: https://esbuild.github.io/plugins/#on-load-results */
@@ -449,8 +479,10 @@ export interface Metafile {
449
479
  kind: ImportKind
450
480
  external?: boolean
451
481
  original?: string
482
+ with?: Record<string, string>
452
483
  }[]
453
484
  format?: 'cjs' | 'esm'
485
+ with?: Record<string, string>
454
486
  }
455
487
  }
456
488
  outputs: {
@@ -484,12 +516,14 @@ export interface AnalyzeMetafileOptions {
484
516
  verbose?: boolean
485
517
  }
486
518
 
519
+ /** Documentation: https://esbuild.github.io/api/#watch-arguments */
487
520
  export interface WatchOptions {
521
+ delay?: number // In milliseconds
488
522
  }
489
523
 
490
- export interface BuildContext<SpecificOptions extends BuildOptions = BuildOptions> {
524
+ export interface BuildContext<ProvidedOptions extends BuildOptions = BuildOptions> {
491
525
  /** Documentation: https://esbuild.github.io/api/#rebuild */
492
- rebuild(): Promise<BuildResult<SpecificOptions>>
526
+ rebuild(): Promise<BuildResult<ProvidedOptions>>
493
527
 
494
528
  /** Documentation: https://esbuild.github.io/api/#watch */
495
529
  watch(options?: WatchOptions): Promise<void>
@@ -501,6 +535,11 @@ export interface BuildContext<SpecificOptions extends BuildOptions = BuildOption
501
535
  dispose(): Promise<void>
502
536
  }
503
537
 
538
+ // This is a TypeScript type-level function which replaces any keys in "In"
539
+ // that aren't in "Out" with "never". We use this to reject properties with
540
+ // typos in object literals. See: https://stackoverflow.com/questions/49580725
541
+ type SameShape<Out, In extends Out> = In & { [Key in Exclude<keyof In, keyof Out>]: never }
542
+
504
543
  /**
505
544
  * This function invokes the "esbuild" command-line tool for you. It returns a
506
545
  * promise that either resolves with a "BuildResult" object or rejects with a
@@ -511,8 +550,7 @@ export interface BuildContext<SpecificOptions extends BuildOptions = BuildOption
511
550
  *
512
551
  * Documentation: https://esbuild.github.io/api/#build
513
552
  */
514
- export declare function build<SpecificOptions extends BuildOptions>(options: SpecificOptions): Promise<BuildResult<SpecificOptions>>
515
- export declare function build(options: BuildOptions): Promise<BuildResult>
553
+ export declare function build<T extends BuildOptions>(options: SameShape<BuildOptions, T>): Promise<BuildResult<T>>
516
554
 
517
555
  /**
518
556
  * This is the advanced long-running form of "build" that supports additional
@@ -523,8 +561,7 @@ export declare function build(options: BuildOptions): Promise<BuildResult>
523
561
  *
524
562
  * Documentation: https://esbuild.github.io/api/#build
525
563
  */
526
- export declare function context<T extends BuildOptions>(options: T): Promise<BuildContext<T>>
527
- export declare function context(options: BuildOptions): Promise<BuildContext>
564
+ export declare function context<T extends BuildOptions>(options: SameShape<BuildOptions, T>): Promise<BuildContext<T>>
528
565
 
529
566
  /**
530
567
  * This function transforms a single JavaScript file. It can be used to minify
@@ -537,8 +574,7 @@ export declare function context(options: BuildOptions): Promise<BuildContext>
537
574
  *
538
575
  * Documentation: https://esbuild.github.io/api/#transform
539
576
  */
540
- export declare function transform<SpecificOptions extends TransformOptions>(input: string | Uint8Array, options?: SpecificOptions): Promise<TransformResult<SpecificOptions>>
541
- export declare function transform(input: string | Uint8Array, options?: TransformOptions): Promise<TransformResult>
577
+ export declare function transform<T extends TransformOptions>(input: string | Uint8Array, options?: SameShape<TransformOptions, T>): Promise<TransformResult<T>>
542
578
 
543
579
  /**
544
580
  * Converts log messages to formatted message strings suitable for printing in
@@ -570,8 +606,7 @@ export declare function analyzeMetafile(metafile: Metafile | string, options?: A
570
606
  *
571
607
  * Documentation: https://esbuild.github.io/api/#build
572
608
  */
573
- export declare function buildSync<SpecificOptions extends BuildOptions>(options: SpecificOptions): BuildResult<SpecificOptions>
574
- export declare function buildSync(options: BuildOptions): BuildResult
609
+ export declare function buildSync<T extends BuildOptions>(options: SameShape<BuildOptions, T>): BuildResult<T>
575
610
 
576
611
  /**
577
612
  * A synchronous version of "transform".
@@ -581,8 +616,7 @@ export declare function buildSync(options: BuildOptions): BuildResult
581
616
  *
582
617
  * Documentation: https://esbuild.github.io/api/#transform
583
618
  */
584
- export declare function transformSync<SpecificOptions extends TransformOptions>(input: string, options?: SpecificOptions): TransformResult<SpecificOptions>
585
- export declare function transformSync(input: string | Uint8Array, options?: TransformOptions): TransformResult
619
+ export declare function transformSync<T extends TransformOptions>(input: string | Uint8Array, options?: SameShape<TransformOptions, T>): TransformResult<T>
586
620
 
587
621
  /**
588
622
  * A synchronous version of "formatMessages".
@@ -640,3 +674,43 @@ export interface InitializeOptions {
640
674
  }
641
675
 
642
676
  export let version: string
677
+
678
+ // Call this function to terminate esbuild's child process. The child process
679
+ // is not terminated and re-created after each API call because it's more
680
+ // efficient to keep it around when there are multiple API calls.
681
+ //
682
+ // In node this happens automatically before the parent node process exits. So
683
+ // you only need to call this if you know you will not make any more esbuild
684
+ // API calls and you want to clean up resources.
685
+ //
686
+ // Unlike node, Deno lacks the necessary APIs to clean up child processes
687
+ // automatically. You must manually call stop() in Deno when you're done
688
+ // using esbuild or Deno will continue running forever.
689
+ //
690
+ // Another reason you might want to call this is if you are using esbuild from
691
+ // within a Deno test. Deno fails tests that create a child process without
692
+ // killing it before the test ends, so you have to call this function (and
693
+ // await the returned promise) in every Deno test that uses esbuild.
694
+ export declare function stop(): Promise<void>
695
+
696
+ // Note: These declarations exist to avoid type errors when you omit "dom" from
697
+ // "lib" in your "tsconfig.json" file. TypeScript confusingly declares the
698
+ // global "WebAssembly" type in "lib.dom.d.ts" even though it has nothing to do
699
+ // with the browser DOM and is present in many non-browser JavaScript runtimes
700
+ // (e.g. node and deno). Declaring it here allows esbuild's API to be used in
701
+ // these scenarios.
702
+ //
703
+ // There's an open issue about getting this problem corrected (although these
704
+ // declarations will need to remain even if this is fixed for backward
705
+ // compatibility with older TypeScript versions):
706
+ //
707
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/826
708
+ //
709
+ declare global {
710
+ namespace WebAssembly {
711
+ interface Module {
712
+ }
713
+ }
714
+ interface URL {
715
+ }
716
+ }