-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathesbuild.ts
620 lines (612 loc) · 20.7 KB
/
esbuild.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
import { keyValueList, valueList } from "@fig/autocomplete-generators";
const icon =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAbxSURBVHgBpVdbbBxXGf7OzOzs2rt21o3jLFC1tuqW9ok+k4dWSFyeSHngJgpK1FDxQEWztI5EpcbOA1KCcYrgAZFWKaKIi4JIH1BBgNS+gxR46S2J3apVd921Yzvu3jxzTr//nNnL7K4bqZ3V0dmZ+ed83/+d/z/nPwojrtWLKLYiHFMKD/D2frZZfJxL4QoM1pTGi/c8iudHmwxcrz+Lh9hdzI7ni/niFLL5AjJhSEv1EV8ll+nvDVqNBvaaDdR3dtDc3REiS4NEUkO98RzO+0H4+NSnb8cYgeEpKM+ZWfz9gEcQMQkJo2Fv2s0Wam+vQkftxbsfwdIQgTefw2k/O7Z46I45BJkAyhdwZS2UUj3LW5Ew/SSM67WBjg3ivQjvv3UdUbv5zD2P4GR3OHp+zAvCizOzdyEIM/B8z4JbAl4/ATMCUfUh97EjuFVBehIwsSMRtfewvnoNcdT+2mdP4LL9gvO+OjN392w4loPv+8579pD/HnslI8XspNdpYDtHnuut3pqYOpHAeQ9tuiroSKOxcxMb76xthT7mAvE+HJ+cDTJZ56mMJeCZMSqR533GgsM0kqb6lKCdlyP2mPtPO6MbULrRJSNxZLUxL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jnvgy9/moDvWI2jKqpme2MOZpS/z/YERngs4PddxUhWhB04MrZ0C/mNfxbFMfrLosQjxlCvDpBKbmMjiyJF7cf36Js4sfgWl2xjBcdWukBA5Ex8mCiGOfP4+XLtew5mnSWaadlHNrgluzhPPpSribRxrRGztZhPt3a0r6vULuDw2XTqamywiE/jcJn34rAt9VkQq4BLqhcxxl0KuIoq74LYuYLzYnVFmk9Ni7XTTkrRFaeKtjowD35MWo7G9hfpG5cWAJi+3d7ePUoVU9Wv4oRe1bHmmVKcWTGq9bs5wGpQQarjv7Ku4VxvqjuQEZy0oLZImxWldApNFqZyC2jFWc9O3F8PxcQSBB1+aTIlUxlKgqs7o7nzQqX87NPrr4t6fZN6TuIqlLI9iNoO9Vgv16toaq+K5YO44tlgVH2/dqP5VhXe4isA41jYeYkcgdTa41ZWcCaRpUSDuI8GzQbP2jjxf6ieP157FM14m+6Ps9GcS7z2nQHIuUCnr4UsNKOCWlt4UWAJUoFV7lyRaS/d9H4tDQ756AYt+EJzO3EYScjqS+rBTTCJ9PLyFAMni1lMibtaxt71ONaJf3HsCj/cTT12vyinJ4LSXzc/6WVauPJh6QXYf649mQTBuFQ2C3+Sy0ZBV7bichvrN9h0yIXIUn+R4DqyxXaEAr2QDPC/xNmjwIUaooIoMmqx/AAAAAElFTkSuQmCC";
const ignoreExtensions = new Set(["", "sample", "env"]);
const extensions: Fig.Generator["custom"] = async (_, executeShellCommand) => {
const { stdout } = await executeShellCommand({
command: "bash",
args: [
"-c",
"find . -depth 3 -type f -name '*.*' -not -path '*/node_modules/*' | sed 's/.*\\.//' | sort -u",
],
});
const lines = stdout.trim().split("\n");
return lines
.filter((line) => !ignoreExtensions.has(line))
.map((line) => ({ name: "." + line }));
};
const spec: Fig.Spec = {
name: "esbuild",
description: "An extremely fast JavaScript bundler",
icon,
parserDirectives: {
optionArgSeparators: ["=", ":"],
},
args: {
name: "entry points",
isVariadic: true,
template: "filepaths",
},
options: (
[
// Simple options:
{
name: "--bundle",
description: "Bundle all dependencies into the output files",
priority: 51,
},
{
name: "--define",
description:
"Replace variable names with a literal value, eg. --define:DEBUG=true",
requiresSeparator: ":",
args: { name: "name=value" },
priority: 51,
},
{
name: "--external",
description: "Exclude modules from the build",
requiresSeparator: ":",
args: { name: "module specifier" },
priority: 51,
},
{
name: "--format",
description: "The output format",
requiresSeparator: "=",
args: { name: "format", suggestions: ["iife", "cjs", "esm"] },
priority: 51,
},
{
name: "--loader",
description: "For a given file extension, specify a loader",
requiresSeparator: ":",
args: {
name: "loaders",
generators: keyValueList({
keys: extensions,
values: [
"js",
"jsx",
"ts",
"tsx",
"css",
"json",
"text",
"base64",
"file",
"dataurl",
"binary",
"copy",
],
cache: true,
}),
},
priority: 51,
},
{
name: "--minify",
description: "Minify the output (sets all the --minify-* options)",
priority: 51,
},
{
name: "--outdir",
description: "The output directory for multiple entrypoints",
requiresSeparator: "=",
args: { name: "path", template: "folders" },
priority: 51,
},
{
name: "--outfile",
description: "The output file for one entrypoint",
requiresSeparator: "=",
args: { name: "path", template: "filepaths" },
priority: 51,
},
{
name: "--platform",
description: "The platform target",
requiresSeparator: "=",
args: { name: "name", suggestions: ["browser", "node", "neutral"] },
priority: 51,
},
{
name: "--serve",
description: "Start a local HTTP server on this host:port",
requiresSeparator: "=",
args: { isOptional: true, name: "[address:]port" },
priority: 51,
},
{
name: "--splitting",
description: "Enable code splitting",
priority: 51,
},
{
name: "--target",
description:
"Set the environment target. Can be a particular ES version or browser version, eg. chrome101",
requiresSeparator: "=",
args: {
name: "target",
generators: valueList({
values: [
"esnext",
"es2016",
"es2022",
"chrome",
"firefox",
"ie",
"node",
"safari",
"opera",
],
}),
},
priority: 51,
},
{
name: "--watch",
description: "Rebuild on file system changes",
priority: 51,
requiresSeparator: "=",
args: {
name: "forever",
suggestions: ["forever"],
isOptional: true,
},
},
// Advanced options:
{
name: "--allow-overwrite",
description: "Allow output files to overwrite input files",
},
{
name: "--analyze",
description: "Print a report about the contents of the bundle",
requiresSeparator: "=",
args: { name: "verbose", isOptional: true, suggestions: ["verbose"] },
},
{
name: "--asset-names",
description: "Path template for 'file' loader files",
requiresSeparator: "=",
args: { name: "template", default: "[name]-[hash]" },
},
{
name: "--banner",
description: "Text to be prepended to each output file type",
requiresSeparator: ":",
args: {
name: "ext=text[,ext=text...]",
generators: keyValueList({ keys: extensions, cache: true }),
},
},
{
name: "--charset",
description: "Use UTF-8 instead of escaped codepoints in ASCII",
insertValue: "--charset=utf8",
displayName: "--charset=utf8",
requiresSeparator: "=",
args: {},
},
{
name: "--chunk-names",
description: "Path template to use for code splitting chunks",
requiresSeparator: "=",
args: { name: "template", default: "[name]-[hash]" },
},
{
name: "--color",
description: "Force use of terminal colors",
requiresSeparator: "=",
args: { name: "enabled", suggestions: ["true", "false"] },
},
{
name: "--drop",
description: "Remove certain constructs",
requiresSeparator: ":",
args: { suggestions: ["console", "debugger"] },
},
{
name: "--entry-names",
description: "Path template to use for entry point output paths",
requiresSeparator: "=",
args: { name: "template", default: "[dir]/[name]" },
},
{
name: "--footer",
description: "Text to be appended to each file type",
requiresSeparator: ":",
args: {
name: "ext=text",
generators: keyValueList({ keys: ["css", "js"] }),
},
},
{
name: "--global-name",
description: "The name of the global if using --format=iife",
requiresSeparator: "=",
args: { name: "name" },
},
{
name: "--ignore-annotations",
description:
"Enable this to work with packages that have incorrect tree-shaking annotations",
},
{
name: "--inject",
description:
"Import the file into all input files, automatically replace matching globals",
requiresSeparator: ":",
args: { name: "import", template: "filepaths" },
},
{
name: "--jsx-factory",
description: "What to use for the JSX factory",
requiresSeparator: "=",
args: {
name: "factory",
suggestions: ["React.createElement", "h", "preact.h"],
},
},
{
name: "--jsx-fragment",
description: "What to use for the JS Fragment factory",
requiresSeparator: "=",
args: { name: "fragment", suggestions: ["React.Fragment", "Fragment"] },
},
{
name: "--jsx",
description: "Preserve JSX instead of transforming",
requiresSeparator: "=",
args: {
suggestions: [
{
name: "preserve",
description: "Preserve JSX instead of transforming",
},
{
name: "automatic",
description: "Use React's new automatic JSX transform",
},
],
},
},
{
name: "--jsx-dev",
description: "Toggles development mode for the automatic runtime",
},
{
name: "--jsx-import-source",
description:
"Overrides the root import for runtime functions (default: react)",
requiresSeparator: "=",
args: { name: "source", default: "react" },
},
{
name: "--keep-names",
description: "Preserve 'name' on functions and classes",
},
{
name: "--legal-comments",
description: "Where to place legal comments",
requiresSeparator: "=",
args: {
name: "location",
suggestions: ["none", "inline", "eof", "linked", "external"],
},
},
{
name: "--log-level",
description: "Set the log level",
requiresSeparator: "=",
args: {
name: "level",
suggestions: [
"verbose",
"debug",
"info",
"warning",
"error",
"silent",
],
default: "info",
},
},
{
name: "--log-limit",
description: "Maximum message count, 0 to disable",
requiresSeparator: "=",
args: { name: "count", default: "6" },
},
{
name: "--log-override",
description: "For a particular identifier, set the log level",
requiresSeparator: ":",
args: {
name: "identifier:level",
generators: keyValueList({
keys: [
// JS
"assign-to-constant",
"assign-to-import",
"call-import-namespace",
"commonjs-variable-in-esm",
"delete-super-property",
"direct-eval",
"duplicate-case",
"duplicate-object-key",
"empty-import-meta",
"equals-nan",
"equals-negative-zero",
"equals-new-object",
"html-comment-in-js",
"impossible-typeof",
"indirect-require",
"private-name-will-throw",
"semicolon-after-return",
"suspicious-boolean-not",
"this-is-undefined-in-esm",
"unsupported-dynamic-import",
"unsupported-jsx-comment",
"unsupported-regexp",
"unsupported-require-call",
// CSS
"css-syntax-error",
"invalid-@charset",
"invalid-@import",
"invalid-@nest",
"invalid-@layer",
"invalid-calc",
"js-comment-in-css",
"unsupported-@charset",
"unsupported-@namespace",
"unsupported-css-property",
// Bundler
"ambiguous-reexport",
"different-path-case",
"ignored-bare-import",
"ignored-dynamic-import",
"import-is-undefined",
"require-resolve-not-external",
// Source maps
"invalid-source-mappings",
"sections-in-source-map",
"missing-source-map",
"unsupported-source-map-comment",
],
values: ["verbose", "debug", "info", "warning", "error", "silent"],
}),
},
},
{
name: "--main-fields",
description: "Override the main file order in package.json",
requiresSeparator: "=",
args: { name: "field order", default: "browser,module,main" },
},
{
name: "--mangle-cache",
description: "Save 'mangle props' decisions to a JSON file",
requiresSeparator: "=",
args: {
name: "path",
template: "filepaths",
suggestCurrentToken: true,
},
},
{
name: "--mangle-props",
description: "Rename all properties matching a regular expression",
requiresSeparator: "=",
args: { name: "regex" },
},
{
name: "--mangle-quoted",
description: "Enable mangling (renaming) quoted properties",
requiresSeparator: "=",
args: { name: "status", suggestions: ["true", "false"] },
},
{
name: "--metafile",
description: "Write metadata about the build to a JSON file",
requiresSeparator: "=",
args: {
name: "path",
template: "filepaths",
suggestCurrentToken: true,
},
},
{
name: "--minify-whitespace",
description: "Remove unnecessary whitespace in output files",
},
{
name: "--minify-identifiers",
description: "Shorten identifiers in output files",
},
{
name: "--minify-syntax",
description: "Use equivalent but shorter syntax in output files",
},
{
name: "--out-extension",
description: "Use a custom output extension for each extension",
requiresSeparator: ":",
args: {
name: "ext=new",
generators: keyValueList({ keys: extensions, cache: true }),
},
},
{
name: "--outbase",
description:
"Base path used to determine entrypoint output paths, for multiple entrypoints",
requiresSeparator: "=",
args: { name: "path", template: "folders" },
},
{
name: "--preserve-symlinks",
description: "Disable symlink resolution",
},
{
name: "--public-path",
description: "Set the base URL for the 'file' loader",
requiresSeparator: "=",
args: { name: "path", template: "folders" },
},
{
name: "--pure",
description: "Mark the name as a pure function for tree shaking",
requiresSeparator: ":",
args: { name: "name" },
},
{
name: "--reserve-props",
description: "Do not mangle these properties",
requiresSeparator: "=",
args: { name: "properties" },
},
{
name: "--resolve-extensions",
description: "Comma-separated list of implicit extensions",
requiresSeparator: "=",
args: {
name: "extensions",
generators: keyValueList({ keys: extensions, cache: true }),
},
},
{
name: "--servedir",
description: "What to serve in addition to the generated output files",
requiresSeparator: "=",
args: { name: "path", template: "folders" },
},
{
name: "--source-root",
description: "Set the sourceRoot field in generated source maps",
requiresSeparator: "=",
args: { name: "URL" },
},
{
name: "--sourcefile",
description:
"Set the source file for the source map if there's no file name to use",
requiresSeparator: "=",
args: { name: "name" },
},
{
name: "--sourcemap",
description: "Generate source maps?",
requiresSeparator: "=",
args: {
name: "options",
isOptional: true,
suggestions: [
{
name: "external",
description: "Generate a separate .map.js file with no comment",
},
{ name: "inline", description: "Append source maps to JS files" },
],
},
priority: 51,
},
{
name: "--sources-content",
description: "Omit the sourcesContent field in generated source maps",
insertValue: "--sources-content=false",
displayName: "--sources-content=false",
requiresSeparator: "=",
args: { suggestions: ["false"] },
},
{
name: "--supported",
description: "Consider a given syntax to be supported",
requiresSeparator: ":",
args: {
name: "syntax=status",
generators: keyValueList({
keys: [
"arbitrary-module-namespace-names",
"array-spread",
"arrow",
"async-await",
"async-generator",
"bigint",
"class",
"class-field",
"class-private-accessor",
"class-private-brand-check",
"class-private-field",
"class-private-method",
"class-private-static-accessor",
"class-private-static-field",
"class-private-static-method",
"class-static-blocks",
"class-static-field",
"const-and-let",
"default-argument",
"destructuring",
"dynamic-import",
"exponent-operator",
"export-star-as",
"for-await",
"for-of",
"generator",
"hashbang",
"import-assertions",
"import-meta",
"logical-assignment",
"nested-rest-binding",
"new-target",
"node-colon-prefix-import",
"node-colon-prefix-require",
"nullish-coalescing",
"object-accessors",
"object-extensions",
"object-rest-spread",
"optional-catch-binding",
"optional-chain",
"regexp-dot-all-flag",
"regexp-lookbehind-assertions",
"regexp-match-indices",
"regexp-named-capture-groups",
"regexp-sticky-and-unicode-flags",
"regexp-unicode-property-escapes",
"rest-argument",
"template-literal",
"top-level-await",
"typeof-exotic-object-is-object",
"unicode-escapes",
"hex-rgba",
"rebecca-purple",
"modern-rgb-hsl",
"inset-property",
"nesting",
],
values: ["true", "false"],
}),
},
},
{
name: "--tree-shaking",
description: "Force tree shaking on or off",
requiresSeparator: "=",
args: { name: "status", suggestions: ["true", "false"] },
},
{
name: "--tsconfig",
description: "Use this TypeScript config instead of the default",
requiresSeparator: "=",
args: { name: "path", template: "filepaths" },
},
{
name: "--version",
description: "Print the current version and exit",
},
] as Fig.Option[]
).map((option) => ({ ...option, icon })),
};
export default spec;