esbuild 0.20.2 → 0.21.0
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 +3 -5
- package/install.js +3 -6
- package/lib/main.js +241 -450
- package/package.json +24 -24
package/lib/main.js
CHANGED
|
@@ -220,8 +220,7 @@ var buildLogLevelDefault = "warning";
|
|
|
220
220
|
var transformLogLevelDefault = "silent";
|
|
221
221
|
function validateTarget(target) {
|
|
222
222
|
validateStringValue(target, "target");
|
|
223
|
-
if (target.indexOf(",") >= 0)
|
|
224
|
-
throw new Error(`Invalid target: ${target}`);
|
|
223
|
+
if (target.indexOf(",") >= 0) throw new Error(`Invalid target: ${target}`);
|
|
225
224
|
return target;
|
|
226
225
|
}
|
|
227
226
|
var canBeAnything = () => null;
|
|
@@ -243,11 +242,9 @@ var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof
|
|
|
243
242
|
function getFlag(object, keys, key, mustBeFn) {
|
|
244
243
|
let value = object[key];
|
|
245
244
|
keys[key + ""] = true;
|
|
246
|
-
if (value === void 0)
|
|
247
|
-
return void 0;
|
|
245
|
+
if (value === void 0) return void 0;
|
|
248
246
|
let mustBe = mustBeFn(value);
|
|
249
|
-
if (mustBe !== null)
|
|
250
|
-
throw new Error(`${quote(key)} must be ${mustBe}`);
|
|
247
|
+
if (mustBe !== null) throw new Error(`${quote(key)} must be ${mustBe}`);
|
|
251
248
|
return value;
|
|
252
249
|
}
|
|
253
250
|
function checkForInvalidFlags(object, keys, where) {
|
|
@@ -288,10 +285,8 @@ function pushLogFlags(flags, options, keys, isTTY2, logLevelDefault) {
|
|
|
288
285
|
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
289
286
|
let logLevel = getFlag(options, keys, "logLevel", mustBeString);
|
|
290
287
|
let logLimit = getFlag(options, keys, "logLimit", mustBeInteger);
|
|
291
|
-
if (color !== void 0)
|
|
292
|
-
|
|
293
|
-
else if (isTTY2)
|
|
294
|
-
flags.push(`--color=true`);
|
|
288
|
+
if (color !== void 0) flags.push(`--color=${color}`);
|
|
289
|
+
else if (isTTY2) flags.push(`--color=true`);
|
|
295
290
|
flags.push(`--log-level=${logLevel || logLevelDefault}`);
|
|
296
291
|
flags.push(`--log-limit=${logLimit || 0}`);
|
|
297
292
|
}
|
|
@@ -334,94 +329,58 @@ function pushCommonFlags(flags, options, keys) {
|
|
|
334
329
|
let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
|
|
335
330
|
let platform = getFlag(options, keys, "platform", mustBeString);
|
|
336
331
|
let tsconfigRaw = getFlag(options, keys, "tsconfigRaw", mustBeStringOrObject);
|
|
337
|
-
if (legalComments)
|
|
338
|
-
|
|
339
|
-
if (
|
|
340
|
-
flags.push(`--source-root=${sourceRoot}`);
|
|
341
|
-
if (sourcesContent !== void 0)
|
|
342
|
-
flags.push(`--sources-content=${sourcesContent}`);
|
|
332
|
+
if (legalComments) flags.push(`--legal-comments=${legalComments}`);
|
|
333
|
+
if (sourceRoot !== void 0) flags.push(`--source-root=${sourceRoot}`);
|
|
334
|
+
if (sourcesContent !== void 0) flags.push(`--sources-content=${sourcesContent}`);
|
|
343
335
|
if (target) {
|
|
344
|
-
if (Array.isArray(target))
|
|
345
|
-
|
|
346
|
-
else
|
|
347
|
-
flags.push(`--target=${validateTarget(target)}`);
|
|
336
|
+
if (Array.isArray(target)) flags.push(`--target=${Array.from(target).map(validateTarget).join(",")}`);
|
|
337
|
+
else flags.push(`--target=${validateTarget(target)}`);
|
|
348
338
|
}
|
|
349
|
-
if (format)
|
|
350
|
-
|
|
351
|
-
if (
|
|
352
|
-
|
|
353
|
-
if (
|
|
354
|
-
|
|
355
|
-
if (
|
|
356
|
-
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
if (
|
|
360
|
-
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
if (
|
|
364
|
-
|
|
365
|
-
if (
|
|
366
|
-
|
|
367
|
-
if (
|
|
368
|
-
|
|
369
|
-
if (
|
|
370
|
-
|
|
371
|
-
if (
|
|
372
|
-
flags.push(`--ignore-annotations`);
|
|
373
|
-
if (drop)
|
|
374
|
-
for (let what of drop)
|
|
375
|
-
flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
|
376
|
-
if (dropLabels)
|
|
377
|
-
flags.push(`--drop-labels=${Array.from(dropLabels).map((what) => validateStringValue(what, "dropLabels")).join(",")}`);
|
|
378
|
-
if (mangleProps)
|
|
379
|
-
flags.push(`--mangle-props=${mangleProps.source}`);
|
|
380
|
-
if (reserveProps)
|
|
381
|
-
flags.push(`--reserve-props=${reserveProps.source}`);
|
|
382
|
-
if (mangleQuoted !== void 0)
|
|
383
|
-
flags.push(`--mangle-quoted=${mangleQuoted}`);
|
|
384
|
-
if (jsx)
|
|
385
|
-
flags.push(`--jsx=${jsx}`);
|
|
386
|
-
if (jsxFactory)
|
|
387
|
-
flags.push(`--jsx-factory=${jsxFactory}`);
|
|
388
|
-
if (jsxFragment)
|
|
389
|
-
flags.push(`--jsx-fragment=${jsxFragment}`);
|
|
390
|
-
if (jsxImportSource)
|
|
391
|
-
flags.push(`--jsx-import-source=${jsxImportSource}`);
|
|
392
|
-
if (jsxDev)
|
|
393
|
-
flags.push(`--jsx-dev`);
|
|
394
|
-
if (jsxSideEffects)
|
|
395
|
-
flags.push(`--jsx-side-effects`);
|
|
339
|
+
if (format) flags.push(`--format=${format}`);
|
|
340
|
+
if (globalName) flags.push(`--global-name=${globalName}`);
|
|
341
|
+
if (platform) flags.push(`--platform=${platform}`);
|
|
342
|
+
if (tsconfigRaw) flags.push(`--tsconfig-raw=${typeof tsconfigRaw === "string" ? tsconfigRaw : JSON.stringify(tsconfigRaw)}`);
|
|
343
|
+
if (minify) flags.push("--minify");
|
|
344
|
+
if (minifySyntax) flags.push("--minify-syntax");
|
|
345
|
+
if (minifyWhitespace) flags.push("--minify-whitespace");
|
|
346
|
+
if (minifyIdentifiers) flags.push("--minify-identifiers");
|
|
347
|
+
if (lineLimit) flags.push(`--line-limit=${lineLimit}`);
|
|
348
|
+
if (charset) flags.push(`--charset=${charset}`);
|
|
349
|
+
if (treeShaking !== void 0) flags.push(`--tree-shaking=${treeShaking}`);
|
|
350
|
+
if (ignoreAnnotations) flags.push(`--ignore-annotations`);
|
|
351
|
+
if (drop) for (let what of drop) flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
|
352
|
+
if (dropLabels) flags.push(`--drop-labels=${Array.from(dropLabels).map((what) => validateStringValue(what, "dropLabels")).join(",")}`);
|
|
353
|
+
if (mangleProps) flags.push(`--mangle-props=${mangleProps.source}`);
|
|
354
|
+
if (reserveProps) flags.push(`--reserve-props=${reserveProps.source}`);
|
|
355
|
+
if (mangleQuoted !== void 0) flags.push(`--mangle-quoted=${mangleQuoted}`);
|
|
356
|
+
if (jsx) flags.push(`--jsx=${jsx}`);
|
|
357
|
+
if (jsxFactory) flags.push(`--jsx-factory=${jsxFactory}`);
|
|
358
|
+
if (jsxFragment) flags.push(`--jsx-fragment=${jsxFragment}`);
|
|
359
|
+
if (jsxImportSource) flags.push(`--jsx-import-source=${jsxImportSource}`);
|
|
360
|
+
if (jsxDev) flags.push(`--jsx-dev`);
|
|
361
|
+
if (jsxSideEffects) flags.push(`--jsx-side-effects`);
|
|
396
362
|
if (define) {
|
|
397
363
|
for (let key in define) {
|
|
398
|
-
if (key.indexOf("=") >= 0)
|
|
399
|
-
throw new Error(`Invalid define: ${key}`);
|
|
364
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid define: ${key}`);
|
|
400
365
|
flags.push(`--define:${key}=${validateStringValue(define[key], "define", key)}`);
|
|
401
366
|
}
|
|
402
367
|
}
|
|
403
368
|
if (logOverride) {
|
|
404
369
|
for (let key in logOverride) {
|
|
405
|
-
if (key.indexOf("=") >= 0)
|
|
406
|
-
throw new Error(`Invalid log override: ${key}`);
|
|
370
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid log override: ${key}`);
|
|
407
371
|
flags.push(`--log-override:${key}=${validateStringValue(logOverride[key], "log override", key)}`);
|
|
408
372
|
}
|
|
409
373
|
}
|
|
410
374
|
if (supported) {
|
|
411
375
|
for (let key in supported) {
|
|
412
|
-
if (key.indexOf("=") >= 0)
|
|
413
|
-
throw new Error(`Invalid supported: ${key}`);
|
|
376
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid supported: ${key}`);
|
|
414
377
|
const value = supported[key];
|
|
415
|
-
if (typeof value !== "boolean")
|
|
416
|
-
throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
|
|
378
|
+
if (typeof value !== "boolean") throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
|
|
417
379
|
flags.push(`--supported:${key}=${value}`);
|
|
418
380
|
}
|
|
419
381
|
}
|
|
420
|
-
if (pure)
|
|
421
|
-
|
|
422
|
-
flags.push(`--pure:${validateStringValue(fn, "pure")}`);
|
|
423
|
-
if (keepNames)
|
|
424
|
-
flags.push(`--keep-names`);
|
|
382
|
+
if (pure) for (let fn of pure) flags.push(`--pure:${validateStringValue(fn, "pure")}`);
|
|
383
|
+
if (keepNames) flags.push(`--keep-names`);
|
|
425
384
|
}
|
|
426
385
|
function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeDefault) {
|
|
427
386
|
var _a2;
|
|
@@ -465,52 +424,35 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
465
424
|
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
466
425
|
keys.plugins = true;
|
|
467
426
|
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
468
|
-
if (sourcemap)
|
|
469
|
-
|
|
470
|
-
if (
|
|
471
|
-
|
|
472
|
-
if (
|
|
473
|
-
|
|
474
|
-
if (
|
|
475
|
-
|
|
476
|
-
if (
|
|
477
|
-
|
|
478
|
-
if (
|
|
479
|
-
flags.push(`--metafile`);
|
|
480
|
-
if (outfile)
|
|
481
|
-
flags.push(`--outfile=${outfile}`);
|
|
482
|
-
if (outdir)
|
|
483
|
-
flags.push(`--outdir=${outdir}`);
|
|
484
|
-
if (outbase)
|
|
485
|
-
flags.push(`--outbase=${outbase}`);
|
|
486
|
-
if (tsconfig)
|
|
487
|
-
flags.push(`--tsconfig=${tsconfig}`);
|
|
488
|
-
if (packages)
|
|
489
|
-
flags.push(`--packages=${packages}`);
|
|
427
|
+
if (sourcemap) flags.push(`--sourcemap${sourcemap === true ? "" : `=${sourcemap}`}`);
|
|
428
|
+
if (bundle) flags.push("--bundle");
|
|
429
|
+
if (allowOverwrite) flags.push("--allow-overwrite");
|
|
430
|
+
if (splitting) flags.push("--splitting");
|
|
431
|
+
if (preserveSymlinks) flags.push("--preserve-symlinks");
|
|
432
|
+
if (metafile) flags.push(`--metafile`);
|
|
433
|
+
if (outfile) flags.push(`--outfile=${outfile}`);
|
|
434
|
+
if (outdir) flags.push(`--outdir=${outdir}`);
|
|
435
|
+
if (outbase) flags.push(`--outbase=${outbase}`);
|
|
436
|
+
if (tsconfig) flags.push(`--tsconfig=${tsconfig}`);
|
|
437
|
+
if (packages) flags.push(`--packages=${packages}`);
|
|
490
438
|
if (resolveExtensions) {
|
|
491
439
|
let values = [];
|
|
492
440
|
for (let value of resolveExtensions) {
|
|
493
441
|
validateStringValue(value, "resolve extension");
|
|
494
|
-
if (value.indexOf(",") >= 0)
|
|
495
|
-
throw new Error(`Invalid resolve extension: ${value}`);
|
|
442
|
+
if (value.indexOf(",") >= 0) throw new Error(`Invalid resolve extension: ${value}`);
|
|
496
443
|
values.push(value);
|
|
497
444
|
}
|
|
498
445
|
flags.push(`--resolve-extensions=${values.join(",")}`);
|
|
499
446
|
}
|
|
500
|
-
if (publicPath)
|
|
501
|
-
|
|
502
|
-
if (
|
|
503
|
-
|
|
504
|
-
if (chunkNames)
|
|
505
|
-
flags.push(`--chunk-names=${chunkNames}`);
|
|
506
|
-
if (assetNames)
|
|
507
|
-
flags.push(`--asset-names=${assetNames}`);
|
|
447
|
+
if (publicPath) flags.push(`--public-path=${publicPath}`);
|
|
448
|
+
if (entryNames) flags.push(`--entry-names=${entryNames}`);
|
|
449
|
+
if (chunkNames) flags.push(`--chunk-names=${chunkNames}`);
|
|
450
|
+
if (assetNames) flags.push(`--asset-names=${assetNames}`);
|
|
508
451
|
if (mainFields) {
|
|
509
452
|
let values = [];
|
|
510
453
|
for (let value of mainFields) {
|
|
511
454
|
validateStringValue(value, "main field");
|
|
512
|
-
if (value.indexOf(",") >= 0)
|
|
513
|
-
throw new Error(`Invalid main field: ${value}`);
|
|
455
|
+
if (value.indexOf(",") >= 0) throw new Error(`Invalid main field: ${value}`);
|
|
514
456
|
values.push(value);
|
|
515
457
|
}
|
|
516
458
|
flags.push(`--main-fields=${values.join(",")}`);
|
|
@@ -519,50 +461,40 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
519
461
|
let values = [];
|
|
520
462
|
for (let value of conditions) {
|
|
521
463
|
validateStringValue(value, "condition");
|
|
522
|
-
if (value.indexOf(",") >= 0)
|
|
523
|
-
throw new Error(`Invalid condition: ${value}`);
|
|
464
|
+
if (value.indexOf(",") >= 0) throw new Error(`Invalid condition: ${value}`);
|
|
524
465
|
values.push(value);
|
|
525
466
|
}
|
|
526
467
|
flags.push(`--conditions=${values.join(",")}`);
|
|
527
468
|
}
|
|
528
|
-
if (external)
|
|
529
|
-
for (let name of external)
|
|
530
|
-
flags.push(`--external:${validateStringValue(name, "external")}`);
|
|
469
|
+
if (external) for (let name of external) flags.push(`--external:${validateStringValue(name, "external")}`);
|
|
531
470
|
if (alias) {
|
|
532
471
|
for (let old in alias) {
|
|
533
|
-
if (old.indexOf("=") >= 0)
|
|
534
|
-
throw new Error(`Invalid package name in alias: ${old}`);
|
|
472
|
+
if (old.indexOf("=") >= 0) throw new Error(`Invalid package name in alias: ${old}`);
|
|
535
473
|
flags.push(`--alias:${old}=${validateStringValue(alias[old], "alias", old)}`);
|
|
536
474
|
}
|
|
537
475
|
}
|
|
538
476
|
if (banner) {
|
|
539
477
|
for (let type in banner) {
|
|
540
|
-
if (type.indexOf("=") >= 0)
|
|
541
|
-
throw new Error(`Invalid banner file type: ${type}`);
|
|
478
|
+
if (type.indexOf("=") >= 0) throw new Error(`Invalid banner file type: ${type}`);
|
|
542
479
|
flags.push(`--banner:${type}=${validateStringValue(banner[type], "banner", type)}`);
|
|
543
480
|
}
|
|
544
481
|
}
|
|
545
482
|
if (footer) {
|
|
546
483
|
for (let type in footer) {
|
|
547
|
-
if (type.indexOf("=") >= 0)
|
|
548
|
-
throw new Error(`Invalid footer file type: ${type}`);
|
|
484
|
+
if (type.indexOf("=") >= 0) throw new Error(`Invalid footer file type: ${type}`);
|
|
549
485
|
flags.push(`--footer:${type}=${validateStringValue(footer[type], "footer", type)}`);
|
|
550
486
|
}
|
|
551
487
|
}
|
|
552
|
-
if (inject)
|
|
553
|
-
for (let path3 of inject)
|
|
554
|
-
flags.push(`--inject:${validateStringValue(path3, "inject")}`);
|
|
488
|
+
if (inject) for (let path3 of inject) flags.push(`--inject:${validateStringValue(path3, "inject")}`);
|
|
555
489
|
if (loader) {
|
|
556
490
|
for (let ext in loader) {
|
|
557
|
-
if (ext.indexOf("=") >= 0)
|
|
558
|
-
throw new Error(`Invalid loader extension: ${ext}`);
|
|
491
|
+
if (ext.indexOf("=") >= 0) throw new Error(`Invalid loader extension: ${ext}`);
|
|
559
492
|
flags.push(`--loader:${ext}=${validateStringValue(loader[ext], "loader", ext)}`);
|
|
560
493
|
}
|
|
561
494
|
}
|
|
562
495
|
if (outExtension) {
|
|
563
496
|
for (let ext in outExtension) {
|
|
564
|
-
if (ext.indexOf("=") >= 0)
|
|
565
|
-
throw new Error(`Invalid out extension: ${ext}`);
|
|
497
|
+
if (ext.indexOf("=") >= 0) throw new Error(`Invalid out extension: ${ext}`);
|
|
566
498
|
flags.push(`--out-extension:${ext}=${validateStringValue(outExtension[ext], "out extension", ext)}`);
|
|
567
499
|
}
|
|
568
500
|
}
|
|
@@ -575,10 +507,8 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
575
507
|
let input = getFlag(entryPoint, entryPointKeys, "in", mustBeString);
|
|
576
508
|
let output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
|
|
577
509
|
checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i);
|
|
578
|
-
if (input === void 0)
|
|
579
|
-
|
|
580
|
-
if (output === void 0)
|
|
581
|
-
throw new Error('Missing property "out" for entry point at index ' + i);
|
|
510
|
+
if (input === void 0) throw new Error('Missing property "in" for entry point at index ' + i);
|
|
511
|
+
if (output === void 0) throw new Error('Missing property "out" for entry point at index ' + i);
|
|
582
512
|
entries.push([output, input]);
|
|
583
513
|
} else {
|
|
584
514
|
entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
|
|
@@ -597,16 +527,11 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
597
527
|
let sourcefile = getFlag(stdin, stdinKeys, "sourcefile", mustBeString);
|
|
598
528
|
let loader2 = getFlag(stdin, stdinKeys, "loader", mustBeString);
|
|
599
529
|
checkForInvalidFlags(stdin, stdinKeys, 'in "stdin" object');
|
|
600
|
-
if (sourcefile)
|
|
601
|
-
|
|
602
|
-
if (
|
|
603
|
-
|
|
604
|
-
if (
|
|
605
|
-
stdinResolveDir = resolveDir;
|
|
606
|
-
if (typeof contents === "string")
|
|
607
|
-
stdinContents = encodeUTF8(contents);
|
|
608
|
-
else if (contents instanceof Uint8Array)
|
|
609
|
-
stdinContents = contents;
|
|
530
|
+
if (sourcefile) flags.push(`--sourcefile=${sourcefile}`);
|
|
531
|
+
if (loader2) flags.push(`--loader=${loader2}`);
|
|
532
|
+
if (resolveDir) stdinResolveDir = resolveDir;
|
|
533
|
+
if (typeof contents === "string") stdinContents = encodeUTF8(contents);
|
|
534
|
+
else if (contents instanceof Uint8Array) stdinContents = contents;
|
|
610
535
|
}
|
|
611
536
|
let nodePaths = [];
|
|
612
537
|
if (nodePathsInput) {
|
|
@@ -638,16 +563,11 @@ function flagsForTransformOptions(callName, options, isTTY2, logLevelDefault) {
|
|
|
638
563
|
let footer = getFlag(options, keys, "footer", mustBeString);
|
|
639
564
|
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
640
565
|
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
641
|
-
if (sourcemap)
|
|
642
|
-
|
|
643
|
-
if (
|
|
644
|
-
|
|
645
|
-
if (
|
|
646
|
-
flags.push(`--loader=${loader}`);
|
|
647
|
-
if (banner)
|
|
648
|
-
flags.push(`--banner=${banner}`);
|
|
649
|
-
if (footer)
|
|
650
|
-
flags.push(`--footer=${footer}`);
|
|
566
|
+
if (sourcemap) flags.push(`--sourcemap=${sourcemap === true ? "external" : sourcemap}`);
|
|
567
|
+
if (sourcefile) flags.push(`--sourcefile=${sourcefile}`);
|
|
568
|
+
if (loader) flags.push(`--loader=${loader}`);
|
|
569
|
+
if (banner) flags.push(`--banner=${banner}`);
|
|
570
|
+
if (footer) flags.push(`--footer=${footer}`);
|
|
651
571
|
return {
|
|
652
572
|
flags,
|
|
653
573
|
mangleCache: validateMangleCache(mangleCache)
|
|
@@ -687,8 +607,7 @@ function createChannel(streamIn) {
|
|
|
687
607
|
};
|
|
688
608
|
let afterClose = (error) => {
|
|
689
609
|
closeData.didClose = true;
|
|
690
|
-
if (error)
|
|
691
|
-
closeData.reason = ": " + (error.message || error);
|
|
610
|
+
if (error) closeData.reason = ": " + (error.message || error);
|
|
692
611
|
const text = "The service was stopped" + closeData.reason;
|
|
693
612
|
for (let id in responseCallbacks) {
|
|
694
613
|
responseCallbacks[id](text, null);
|
|
@@ -696,24 +615,20 @@ function createChannel(streamIn) {
|
|
|
696
615
|
responseCallbacks = {};
|
|
697
616
|
};
|
|
698
617
|
let sendRequest = (refs, value, callback) => {
|
|
699
|
-
if (closeData.didClose)
|
|
700
|
-
return callback("The service is no longer running" + closeData.reason, null);
|
|
618
|
+
if (closeData.didClose) return callback("The service is no longer running" + closeData.reason, null);
|
|
701
619
|
let id = nextRequestID++;
|
|
702
620
|
responseCallbacks[id] = (error, response) => {
|
|
703
621
|
try {
|
|
704
622
|
callback(error, response);
|
|
705
623
|
} finally {
|
|
706
|
-
if (refs)
|
|
707
|
-
refs.unref();
|
|
624
|
+
if (refs) refs.unref();
|
|
708
625
|
}
|
|
709
626
|
};
|
|
710
|
-
if (refs)
|
|
711
|
-
refs.ref();
|
|
627
|
+
if (refs) refs.ref();
|
|
712
628
|
streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
|
|
713
629
|
};
|
|
714
630
|
let sendResponse = (id, value) => {
|
|
715
|
-
if (closeData.didClose)
|
|
716
|
-
throw new Error("The service is no longer running" + closeData.reason);
|
|
631
|
+
if (closeData.didClose) throw new Error("The service is no longer running" + closeData.reason);
|
|
717
632
|
streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
|
|
718
633
|
};
|
|
719
634
|
let handleRequest = async (id, request) => {
|
|
@@ -747,8 +662,8 @@ function createChannel(streamIn) {
|
|
|
747
662
|
if (isFirstPacket) {
|
|
748
663
|
isFirstPacket = false;
|
|
749
664
|
let binaryVersion = String.fromCharCode(...bytes);
|
|
750
|
-
if (binaryVersion !== "0.
|
|
751
|
-
throw new Error(`Cannot start service: Host version "${"0.
|
|
665
|
+
if (binaryVersion !== "0.21.0") {
|
|
666
|
+
throw new Error(`Cannot start service: Host version "${"0.21.0"}" does not match binary version ${quote(binaryVersion)}`);
|
|
752
667
|
}
|
|
753
668
|
return;
|
|
754
669
|
}
|
|
@@ -758,10 +673,8 @@ function createChannel(streamIn) {
|
|
|
758
673
|
} else {
|
|
759
674
|
let callback = responseCallbacks[packet.id];
|
|
760
675
|
delete responseCallbacks[packet.id];
|
|
761
|
-
if (packet.value.error)
|
|
762
|
-
|
|
763
|
-
else
|
|
764
|
-
callback(null, packet.value);
|
|
676
|
+
if (packet.value.error) callback(packet.value.error, {});
|
|
677
|
+
else callback(null, packet.value);
|
|
765
678
|
}
|
|
766
679
|
};
|
|
767
680
|
let buildOrContext = ({ callName, refs, options, isTTY: isTTY2, defaultWD: defaultWD2, callback }) => {
|
|
@@ -771,15 +684,13 @@ function createChannel(streamIn) {
|
|
|
771
684
|
const buildRefs = {
|
|
772
685
|
ref() {
|
|
773
686
|
if (++refCount === 1) {
|
|
774
|
-
if (refs)
|
|
775
|
-
refs.ref();
|
|
687
|
+
if (refs) refs.ref();
|
|
776
688
|
}
|
|
777
689
|
},
|
|
778
690
|
unref() {
|
|
779
691
|
if (--refCount === 0) {
|
|
780
692
|
delete requestCallbacksByKey[buildKey];
|
|
781
|
-
if (refs)
|
|
782
|
-
refs.unref();
|
|
693
|
+
if (refs) refs.unref();
|
|
783
694
|
}
|
|
784
695
|
}
|
|
785
696
|
};
|
|
@@ -821,11 +732,9 @@ function createChannel(streamIn) {
|
|
|
821
732
|
inputFS: inputPath !== null,
|
|
822
733
|
input: inputPath !== null ? encodeUTF8(inputPath) : typeof input === "string" ? encodeUTF8(input) : input
|
|
823
734
|
};
|
|
824
|
-
if (mangleCache)
|
|
825
|
-
request.mangleCache = mangleCache;
|
|
735
|
+
if (mangleCache) request.mangleCache = mangleCache;
|
|
826
736
|
sendRequest(refs, request, (error, response) => {
|
|
827
|
-
if (error)
|
|
828
|
-
return callback(new Error(error), null);
|
|
737
|
+
if (error) return callback(new Error(error), null);
|
|
829
738
|
let errors = replaceDetailsInMessages(response.errors, details);
|
|
830
739
|
let warnings = replaceDetailsInMessages(response.warnings, details);
|
|
831
740
|
let outstanding = 1;
|
|
@@ -838,15 +747,12 @@ function createChannel(streamIn) {
|
|
|
838
747
|
mangleCache: void 0,
|
|
839
748
|
legalComments: void 0
|
|
840
749
|
};
|
|
841
|
-
if ("legalComments" in response)
|
|
842
|
-
|
|
843
|
-
if (response.mangleCache)
|
|
844
|
-
result.mangleCache = response == null ? void 0 : response.mangleCache;
|
|
750
|
+
if ("legalComments" in response) result.legalComments = response == null ? void 0 : response.legalComments;
|
|
751
|
+
if (response.mangleCache) result.mangleCache = response == null ? void 0 : response.mangleCache;
|
|
845
752
|
callback(null, result);
|
|
846
753
|
}
|
|
847
754
|
};
|
|
848
|
-
if (errors.length > 0)
|
|
849
|
-
return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
|
|
755
|
+
if (errors.length > 0) return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
|
|
850
756
|
if (response.codeFS) {
|
|
851
757
|
outstanding++;
|
|
852
758
|
fs3.readFile(response.code, (err, contents) => {
|
|
@@ -891,35 +797,28 @@ function createChannel(streamIn) {
|
|
|
891
797
|
start(null);
|
|
892
798
|
};
|
|
893
799
|
let formatMessages2 = ({ callName, refs, messages, options, callback }) => {
|
|
894
|
-
if (!options)
|
|
895
|
-
throw new Error(`Missing second argument in ${callName}() call`);
|
|
800
|
+
if (!options) throw new Error(`Missing second argument in ${callName}() call`);
|
|
896
801
|
let keys = {};
|
|
897
802
|
let kind = getFlag(options, keys, "kind", mustBeString);
|
|
898
803
|
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
899
804
|
let terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger);
|
|
900
805
|
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
901
|
-
if (kind === void 0)
|
|
902
|
-
|
|
903
|
-
if (kind !== "error" && kind !== "warning")
|
|
904
|
-
throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
|
|
806
|
+
if (kind === void 0) throw new Error(`Missing "kind" in ${callName}() call`);
|
|
807
|
+
if (kind !== "error" && kind !== "warning") throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
|
|
905
808
|
let request = {
|
|
906
809
|
command: "format-msgs",
|
|
907
810
|
messages: sanitizeMessages(messages, "messages", null, "", terminalWidth),
|
|
908
811
|
isWarning: kind === "warning"
|
|
909
812
|
};
|
|
910
|
-
if (color !== void 0)
|
|
911
|
-
|
|
912
|
-
if (terminalWidth !== void 0)
|
|
913
|
-
request.terminalWidth = terminalWidth;
|
|
813
|
+
if (color !== void 0) request.color = color;
|
|
814
|
+
if (terminalWidth !== void 0) request.terminalWidth = terminalWidth;
|
|
914
815
|
sendRequest(refs, request, (error, response) => {
|
|
915
|
-
if (error)
|
|
916
|
-
return callback(new Error(error), null);
|
|
816
|
+
if (error) return callback(new Error(error), null);
|
|
917
817
|
callback(null, response.messages);
|
|
918
818
|
});
|
|
919
819
|
};
|
|
920
820
|
let analyzeMetafile2 = ({ callName, refs, metafile, options, callback }) => {
|
|
921
|
-
if (options === void 0)
|
|
922
|
-
options = {};
|
|
821
|
+
if (options === void 0) options = {};
|
|
923
822
|
let keys = {};
|
|
924
823
|
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
925
824
|
let verbose = getFlag(options, keys, "verbose", mustBeBoolean);
|
|
@@ -928,13 +827,10 @@ function createChannel(streamIn) {
|
|
|
928
827
|
command: "analyze-metafile",
|
|
929
828
|
metafile
|
|
930
829
|
};
|
|
931
|
-
if (color !== void 0)
|
|
932
|
-
|
|
933
|
-
if (verbose !== void 0)
|
|
934
|
-
request.verbose = verbose;
|
|
830
|
+
if (color !== void 0) request.color = color;
|
|
831
|
+
if (verbose !== void 0) request.verbose = verbose;
|
|
935
832
|
sendRequest(refs, request, (error, response) => {
|
|
936
|
-
if (error)
|
|
937
|
-
return callback(new Error(error), null);
|
|
833
|
+
if (error) return callback(new Error(error), null);
|
|
938
834
|
callback(null, response.result);
|
|
939
835
|
});
|
|
940
836
|
};
|
|
@@ -968,14 +864,12 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
968
864
|
if (typeof options === "object") {
|
|
969
865
|
const value = options.plugins;
|
|
970
866
|
if (value !== void 0) {
|
|
971
|
-
if (!Array.isArray(value))
|
|
972
|
-
return handleError(new Error(`"plugins" must be an array`), "");
|
|
867
|
+
if (!Array.isArray(value)) return handleError(new Error(`"plugins" must be an array`), "");
|
|
973
868
|
plugins = value;
|
|
974
869
|
}
|
|
975
870
|
}
|
|
976
871
|
if (plugins && plugins.length > 0) {
|
|
977
|
-
if (streamIn.isSync)
|
|
978
|
-
return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
|
872
|
+
if (streamIn.isSync) return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
|
979
873
|
handlePlugins(
|
|
980
874
|
buildKey,
|
|
981
875
|
sendRequest,
|
|
@@ -988,8 +882,7 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
988
882
|
details
|
|
989
883
|
).then(
|
|
990
884
|
(result) => {
|
|
991
|
-
if (!result.ok)
|
|
992
|
-
return handleError(result.error, result.pluginName);
|
|
885
|
+
if (!result.ok) return handleError(result.error, result.pluginName);
|
|
993
886
|
try {
|
|
994
887
|
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
|
|
995
888
|
} catch (e) {
|
|
@@ -1018,8 +911,7 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1018
911
|
nodePaths,
|
|
1019
912
|
mangleCache
|
|
1020
913
|
} = flagsForBuildOptions(callName, options, isTTY2, buildLogLevelDefault, writeDefault);
|
|
1021
|
-
if (write && !streamIn.hasFS)
|
|
1022
|
-
throw new Error(`The "write" option is unavailable in this environment`);
|
|
914
|
+
if (write && !streamIn.hasFS) throw new Error(`The "write" option is unavailable in this environment`);
|
|
1023
915
|
const request = {
|
|
1024
916
|
command: "build",
|
|
1025
917
|
key: buildKey,
|
|
@@ -1032,10 +924,8 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1032
924
|
nodePaths,
|
|
1033
925
|
context: isContext
|
|
1034
926
|
};
|
|
1035
|
-
if (requestPlugins)
|
|
1036
|
-
|
|
1037
|
-
if (mangleCache)
|
|
1038
|
-
request.mangleCache = mangleCache;
|
|
927
|
+
if (requestPlugins) request.plugins = requestPlugins;
|
|
928
|
+
if (mangleCache) request.mangleCache = mangleCache;
|
|
1039
929
|
const buildResponseToResult = (response, callback2) => {
|
|
1040
930
|
const result = {
|
|
1041
931
|
errors: replaceDetailsInMessages(response.errors, details),
|
|
@@ -1046,14 +936,10 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1046
936
|
};
|
|
1047
937
|
const originalErrors = result.errors.slice();
|
|
1048
938
|
const originalWarnings = result.warnings.slice();
|
|
1049
|
-
if (response.outputFiles)
|
|
1050
|
-
|
|
1051
|
-
if (response.
|
|
1052
|
-
|
|
1053
|
-
if (response.mangleCache)
|
|
1054
|
-
result.mangleCache = response.mangleCache;
|
|
1055
|
-
if (response.writeToStdout !== void 0)
|
|
1056
|
-
console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
|
939
|
+
if (response.outputFiles) result.outputFiles = response.outputFiles.map(convertOutputFiles);
|
|
940
|
+
if (response.metafile) result.metafile = JSON.parse(response.metafile);
|
|
941
|
+
if (response.mangleCache) result.mangleCache = response.mangleCache;
|
|
942
|
+
if (response.writeToStdout !== void 0) console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
|
1057
943
|
runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
|
|
1058
944
|
if (originalErrors.length > 0 || onEndErrors.length > 0) {
|
|
1059
945
|
const error = failureErrorWithLog("Build failed", originalErrors.concat(onEndErrors), originalWarnings.concat(onEndWarnings));
|
|
@@ -1071,8 +957,7 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1071
957
|
errors: onEndErrors,
|
|
1072
958
|
warnings: onEndWarnings
|
|
1073
959
|
};
|
|
1074
|
-
if (provideLatestResult)
|
|
1075
|
-
provideLatestResult(err, result);
|
|
960
|
+
if (provideLatestResult) provideLatestResult(err, result);
|
|
1076
961
|
latestResultPromise = void 0;
|
|
1077
962
|
provideLatestResult = void 0;
|
|
1078
963
|
sendResponse(id, response);
|
|
@@ -1080,8 +965,7 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1080
965
|
});
|
|
1081
966
|
});
|
|
1082
967
|
sendRequest(refs, request, (error, response) => {
|
|
1083
|
-
if (error)
|
|
1084
|
-
return callback(new Error(error), null);
|
|
968
|
+
if (error) return callback(new Error(error), null);
|
|
1085
969
|
if (!isContext) {
|
|
1086
970
|
return buildResponseToResult(response, (err, res) => {
|
|
1087
971
|
scheduleOnDisposeCallbacks();
|
|
@@ -1094,35 +978,32 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1094
978
|
let didDispose = false;
|
|
1095
979
|
const result = {
|
|
1096
980
|
rebuild: () => {
|
|
1097
|
-
if (!latestResultPromise)
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
command: "rebuild",
|
|
1107
|
-
key: buildKey
|
|
1108
|
-
};
|
|
1109
|
-
sendRequest(refs, request2, (error2, response2) => {
|
|
1110
|
-
if (error2) {
|
|
1111
|
-
reject(new Error(error2));
|
|
1112
|
-
} else if (settlePromise) {
|
|
1113
|
-
settlePromise();
|
|
1114
|
-
} else {
|
|
1115
|
-
triggerAnotherBuild();
|
|
1116
|
-
}
|
|
1117
|
-
});
|
|
981
|
+
if (!latestResultPromise) latestResultPromise = new Promise((resolve, reject) => {
|
|
982
|
+
let settlePromise;
|
|
983
|
+
provideLatestResult = (err, result2) => {
|
|
984
|
+
if (!settlePromise) settlePromise = () => err ? reject(err) : resolve(result2);
|
|
985
|
+
};
|
|
986
|
+
const triggerAnotherBuild = () => {
|
|
987
|
+
const request2 = {
|
|
988
|
+
command: "rebuild",
|
|
989
|
+
key: buildKey
|
|
1118
990
|
};
|
|
1119
|
-
|
|
1120
|
-
|
|
991
|
+
sendRequest(refs, request2, (error2, response2) => {
|
|
992
|
+
if (error2) {
|
|
993
|
+
reject(new Error(error2));
|
|
994
|
+
} else if (settlePromise) {
|
|
995
|
+
settlePromise();
|
|
996
|
+
} else {
|
|
997
|
+
triggerAnotherBuild();
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
};
|
|
1001
|
+
triggerAnotherBuild();
|
|
1002
|
+
});
|
|
1121
1003
|
return latestResultPromise;
|
|
1122
1004
|
},
|
|
1123
1005
|
watch: (options2 = {}) => new Promise((resolve, reject) => {
|
|
1124
|
-
if (!streamIn.hasFS)
|
|
1125
|
-
throw new Error(`Cannot use the "watch" API in this environment`);
|
|
1006
|
+
if (!streamIn.hasFS) throw new Error(`Cannot use the "watch" API in this environment`);
|
|
1126
1007
|
const keys = {};
|
|
1127
1008
|
checkForInvalidFlags(options2, keys, `in watch() call`);
|
|
1128
1009
|
const request2 = {
|
|
@@ -1130,15 +1011,12 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1130
1011
|
key: buildKey
|
|
1131
1012
|
};
|
|
1132
1013
|
sendRequest(refs, request2, (error2) => {
|
|
1133
|
-
if (error2)
|
|
1134
|
-
|
|
1135
|
-
else
|
|
1136
|
-
resolve(void 0);
|
|
1014
|
+
if (error2) reject(new Error(error2));
|
|
1015
|
+
else resolve(void 0);
|
|
1137
1016
|
});
|
|
1138
1017
|
}),
|
|
1139
1018
|
serve: (options2 = {}) => new Promise((resolve, reject) => {
|
|
1140
|
-
if (!streamIn.hasFS)
|
|
1141
|
-
throw new Error(`Cannot use the "serve" API in this environment`);
|
|
1019
|
+
if (!streamIn.hasFS) throw new Error(`Cannot use the "serve" API in this environment`);
|
|
1142
1020
|
const keys = {};
|
|
1143
1021
|
const port = getFlag(options2, keys, "port", mustBeInteger);
|
|
1144
1022
|
const host = getFlag(options2, keys, "host", mustBeString);
|
|
@@ -1153,21 +1031,14 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1153
1031
|
key: buildKey,
|
|
1154
1032
|
onRequest: !!onRequest
|
|
1155
1033
|
};
|
|
1156
|
-
if (port !== void 0)
|
|
1157
|
-
|
|
1158
|
-
if (
|
|
1159
|
-
|
|
1160
|
-
if (
|
|
1161
|
-
|
|
1162
|
-
if (keyfile !== void 0)
|
|
1163
|
-
request2.keyfile = keyfile;
|
|
1164
|
-
if (certfile !== void 0)
|
|
1165
|
-
request2.certfile = certfile;
|
|
1166
|
-
if (fallback !== void 0)
|
|
1167
|
-
request2.fallback = fallback;
|
|
1034
|
+
if (port !== void 0) request2.port = port;
|
|
1035
|
+
if (host !== void 0) request2.host = host;
|
|
1036
|
+
if (servedir !== void 0) request2.servedir = servedir;
|
|
1037
|
+
if (keyfile !== void 0) request2.keyfile = keyfile;
|
|
1038
|
+
if (certfile !== void 0) request2.certfile = certfile;
|
|
1039
|
+
if (fallback !== void 0) request2.fallback = fallback;
|
|
1168
1040
|
sendRequest(refs, request2, (error2, response2) => {
|
|
1169
|
-
if (error2)
|
|
1170
|
-
return reject(new Error(error2));
|
|
1041
|
+
if (error2) return reject(new Error(error2));
|
|
1171
1042
|
if (onRequest) {
|
|
1172
1043
|
requestCallbacks["serve-request"] = (id, request3) => {
|
|
1173
1044
|
onRequest(request3.args);
|
|
@@ -1178,8 +1049,7 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1178
1049
|
});
|
|
1179
1050
|
}),
|
|
1180
1051
|
cancel: () => new Promise((resolve) => {
|
|
1181
|
-
if (didDispose)
|
|
1182
|
-
return resolve();
|
|
1052
|
+
if (didDispose) return resolve();
|
|
1183
1053
|
const request2 = {
|
|
1184
1054
|
command: "cancel",
|
|
1185
1055
|
key: buildKey
|
|
@@ -1189,8 +1059,7 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
|
|
1189
1059
|
});
|
|
1190
1060
|
}),
|
|
1191
1061
|
dispose: () => new Promise((resolve) => {
|
|
1192
|
-
if (didDispose)
|
|
1193
|
-
return resolve();
|
|
1062
|
+
if (didDispose) return resolve();
|
|
1194
1063
|
didDispose = true;
|
|
1195
1064
|
const request2 = {
|
|
1196
1065
|
command: "dispose",
|
|
@@ -1221,15 +1090,12 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1221
1090
|
plugins = [...plugins];
|
|
1222
1091
|
for (let item of plugins) {
|
|
1223
1092
|
let keys = {};
|
|
1224
|
-
if (typeof item !== "object")
|
|
1225
|
-
throw new Error(`Plugin at index ${i} must be an object`);
|
|
1093
|
+
if (typeof item !== "object") throw new Error(`Plugin at index ${i} must be an object`);
|
|
1226
1094
|
const name = getFlag(item, keys, "name", mustBeString);
|
|
1227
|
-
if (typeof name !== "string" || name === "")
|
|
1228
|
-
throw new Error(`Plugin at index ${i} is missing a name`);
|
|
1095
|
+
if (typeof name !== "string" || name === "") throw new Error(`Plugin at index ${i} is missing a name`);
|
|
1229
1096
|
try {
|
|
1230
1097
|
let setup = getFlag(item, keys, "setup", mustBeFunction);
|
|
1231
|
-
if (typeof setup !== "function")
|
|
1232
|
-
throw new Error(`Plugin is missing a setup function`);
|
|
1098
|
+
if (typeof setup !== "function") throw new Error(`Plugin is missing a setup function`);
|
|
1233
1099
|
checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
|
|
1234
1100
|
let plugin = {
|
|
1235
1101
|
name,
|
|
@@ -1240,10 +1106,8 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1240
1106
|
};
|
|
1241
1107
|
i++;
|
|
1242
1108
|
let resolve = (path3, options = {}) => {
|
|
1243
|
-
if (!isSetupDone)
|
|
1244
|
-
|
|
1245
|
-
if (typeof path3 !== "string")
|
|
1246
|
-
throw new Error(`The path to resolve must be a string`);
|
|
1109
|
+
if (!isSetupDone) throw new Error('Cannot call "resolve" before plugin setup has completed');
|
|
1110
|
+
if (typeof path3 !== "string") throw new Error(`The path to resolve must be a string`);
|
|
1247
1111
|
let keys2 = /* @__PURE__ */ Object.create(null);
|
|
1248
1112
|
let pluginName = getFlag(options, keys2, "pluginName", mustBeString);
|
|
1249
1113
|
let importer = getFlag(options, keys2, "importer", mustBeString);
|
|
@@ -1259,34 +1123,25 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1259
1123
|
key: buildKey,
|
|
1260
1124
|
pluginName: name
|
|
1261
1125
|
};
|
|
1262
|
-
if (pluginName != null)
|
|
1263
|
-
|
|
1264
|
-
if (
|
|
1265
|
-
|
|
1266
|
-
if (
|
|
1267
|
-
|
|
1268
|
-
if (
|
|
1269
|
-
request.resolveDir = resolveDir;
|
|
1270
|
-
if (kind != null)
|
|
1271
|
-
request.kind = kind;
|
|
1272
|
-
else
|
|
1273
|
-
throw new Error(`Must specify "kind" when calling "resolve"`);
|
|
1274
|
-
if (pluginData != null)
|
|
1275
|
-
request.pluginData = details.store(pluginData);
|
|
1126
|
+
if (pluginName != null) request.pluginName = pluginName;
|
|
1127
|
+
if (importer != null) request.importer = importer;
|
|
1128
|
+
if (namespace != null) request.namespace = namespace;
|
|
1129
|
+
if (resolveDir != null) request.resolveDir = resolveDir;
|
|
1130
|
+
if (kind != null) request.kind = kind;
|
|
1131
|
+
else throw new Error(`Must specify "kind" when calling "resolve"`);
|
|
1132
|
+
if (pluginData != null) request.pluginData = details.store(pluginData);
|
|
1276
1133
|
sendRequest(refs, request, (error, response) => {
|
|
1277
|
-
if (error !== null)
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
pluginData: details.load(response.pluginData)
|
|
1289
|
-
});
|
|
1134
|
+
if (error !== null) reject(new Error(error));
|
|
1135
|
+
else resolve2({
|
|
1136
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
1137
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
1138
|
+
path: response.path,
|
|
1139
|
+
external: response.external,
|
|
1140
|
+
sideEffects: response.sideEffects,
|
|
1141
|
+
namespace: response.namespace,
|
|
1142
|
+
suffix: response.suffix,
|
|
1143
|
+
pluginData: details.load(response.pluginData)
|
|
1144
|
+
});
|
|
1290
1145
|
});
|
|
1291
1146
|
});
|
|
1292
1147
|
};
|
|
@@ -1312,8 +1167,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1312
1167
|
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
1313
1168
|
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
1314
1169
|
checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${quote(name)}`);
|
|
1315
|
-
if (filter == null)
|
|
1316
|
-
throw new Error(`onResolve() call is missing a filter`);
|
|
1170
|
+
if (filter == null) throw new Error(`onResolve() call is missing a filter`);
|
|
1317
1171
|
let id = nextCallbackID++;
|
|
1318
1172
|
onResolveCallbacks[id] = { name, callback, note: registeredNote };
|
|
1319
1173
|
plugin.onResolve.push({ id, filter: filter.source, namespace: namespace || "" });
|
|
@@ -1325,8 +1179,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1325
1179
|
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
1326
1180
|
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
1327
1181
|
checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${quote(name)}`);
|
|
1328
|
-
if (filter == null)
|
|
1329
|
-
throw new Error(`onLoad() call is missing a filter`);
|
|
1182
|
+
if (filter == null) throw new Error(`onLoad() call is missing a filter`);
|
|
1330
1183
|
let id = nextCallbackID++;
|
|
1331
1184
|
onLoadCallbacks[id] = { name, callback, note: registeredNote };
|
|
1332
1185
|
plugin.onLoad.push({ id, filter: filter.source, namespace: namespace || "" });
|
|
@@ -1336,8 +1189,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1336
1189
|
},
|
|
1337
1190
|
esbuild: streamIn.esbuild
|
|
1338
1191
|
});
|
|
1339
|
-
if (promise)
|
|
1340
|
-
await promise;
|
|
1192
|
+
if (promise) await promise;
|
|
1341
1193
|
requestPlugins.push(plugin);
|
|
1342
1194
|
} catch (e) {
|
|
1343
1195
|
return { ok: false, error: e, pluginName: name };
|
|
@@ -1349,16 +1201,13 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1349
1201
|
try {
|
|
1350
1202
|
let result = await callback();
|
|
1351
1203
|
if (result != null) {
|
|
1352
|
-
if (typeof result !== "object")
|
|
1353
|
-
throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
|
|
1204
|
+
if (typeof result !== "object") throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
|
|
1354
1205
|
let keys = {};
|
|
1355
1206
|
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
1356
1207
|
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1357
1208
|
checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${quote(name)}`);
|
|
1358
|
-
if (errors != null)
|
|
1359
|
-
|
|
1360
|
-
if (warnings != null)
|
|
1361
|
-
response.warnings.push(...sanitizeMessages(warnings, "warnings", details, name, void 0));
|
|
1209
|
+
if (errors != null) response.errors.push(...sanitizeMessages(errors, "errors", details, name, void 0));
|
|
1210
|
+
if (warnings != null) response.warnings.push(...sanitizeMessages(warnings, "warnings", details, name, void 0));
|
|
1362
1211
|
}
|
|
1363
1212
|
} catch (e) {
|
|
1364
1213
|
response.errors.push(extractErrorMessageV8(e, streamIn, details, note && note(), name));
|
|
@@ -1380,8 +1229,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1380
1229
|
pluginData: details.load(request.pluginData)
|
|
1381
1230
|
});
|
|
1382
1231
|
if (result != null) {
|
|
1383
|
-
if (typeof result !== "object")
|
|
1384
|
-
throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
|
|
1232
|
+
if (typeof result !== "object") throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
|
|
1385
1233
|
let keys = {};
|
|
1386
1234
|
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
1387
1235
|
let path3 = getFlag(result, keys, "path", mustBeString);
|
|
@@ -1396,28 +1244,17 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1396
1244
|
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
|
|
1397
1245
|
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
|
|
1398
1246
|
response.id = id2;
|
|
1399
|
-
if (pluginName != null)
|
|
1400
|
-
|
|
1401
|
-
if (
|
|
1402
|
-
|
|
1403
|
-
if (
|
|
1404
|
-
|
|
1405
|
-
if (
|
|
1406
|
-
|
|
1407
|
-
if (
|
|
1408
|
-
|
|
1409
|
-
if (
|
|
1410
|
-
response.sideEffects = sideEffects;
|
|
1411
|
-
if (pluginData != null)
|
|
1412
|
-
response.pluginData = details.store(pluginData);
|
|
1413
|
-
if (errors != null)
|
|
1414
|
-
response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1415
|
-
if (warnings != null)
|
|
1416
|
-
response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1417
|
-
if (watchFiles != null)
|
|
1418
|
-
response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
1419
|
-
if (watchDirs != null)
|
|
1420
|
-
response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
1247
|
+
if (pluginName != null) response.pluginName = pluginName;
|
|
1248
|
+
if (path3 != null) response.path = path3;
|
|
1249
|
+
if (namespace != null) response.namespace = namespace;
|
|
1250
|
+
if (suffix != null) response.suffix = suffix;
|
|
1251
|
+
if (external != null) response.external = external;
|
|
1252
|
+
if (sideEffects != null) response.sideEffects = sideEffects;
|
|
1253
|
+
if (pluginData != null) response.pluginData = details.store(pluginData);
|
|
1254
|
+
if (errors != null) response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1255
|
+
if (warnings != null) response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1256
|
+
if (watchFiles != null) response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
1257
|
+
if (watchDirs != null) response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
1421
1258
|
break;
|
|
1422
1259
|
}
|
|
1423
1260
|
} catch (e) {
|
|
@@ -1440,8 +1277,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1440
1277
|
with: request.with
|
|
1441
1278
|
});
|
|
1442
1279
|
if (result != null) {
|
|
1443
|
-
if (typeof result !== "object")
|
|
1444
|
-
throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
|
|
1280
|
+
if (typeof result !== "object") throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
|
|
1445
1281
|
let keys = {};
|
|
1446
1282
|
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
1447
1283
|
let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
|
|
@@ -1454,26 +1290,16 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1454
1290
|
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
|
|
1455
1291
|
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
|
|
1456
1292
|
response.id = id2;
|
|
1457
|
-
if (pluginName != null)
|
|
1458
|
-
|
|
1459
|
-
if (contents
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
if (
|
|
1464
|
-
|
|
1465
|
-
if (
|
|
1466
|
-
|
|
1467
|
-
if (loader != null)
|
|
1468
|
-
response.loader = loader;
|
|
1469
|
-
if (errors != null)
|
|
1470
|
-
response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1471
|
-
if (warnings != null)
|
|
1472
|
-
response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1473
|
-
if (watchFiles != null)
|
|
1474
|
-
response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
1475
|
-
if (watchDirs != null)
|
|
1476
|
-
response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
1293
|
+
if (pluginName != null) response.pluginName = pluginName;
|
|
1294
|
+
if (contents instanceof Uint8Array) response.contents = contents;
|
|
1295
|
+
else if (contents != null) response.contents = encodeUTF8(contents);
|
|
1296
|
+
if (resolveDir != null) response.resolveDir = resolveDir;
|
|
1297
|
+
if (pluginData != null) response.pluginData = details.store(pluginData);
|
|
1298
|
+
if (loader != null) response.loader = loader;
|
|
1299
|
+
if (errors != null) response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1300
|
+
if (warnings != null) response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1301
|
+
if (watchFiles != null) response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
1302
|
+
if (watchDirs != null) response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
1477
1303
|
break;
|
|
1478
1304
|
}
|
|
1479
1305
|
} catch (e) {
|
|
@@ -1495,16 +1321,13 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1495
1321
|
try {
|
|
1496
1322
|
const value = await callback(result);
|
|
1497
1323
|
if (value != null) {
|
|
1498
|
-
if (typeof value !== "object")
|
|
1499
|
-
throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
|
|
1324
|
+
if (typeof value !== "object") throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
|
|
1500
1325
|
let keys = {};
|
|
1501
1326
|
let errors = getFlag(value, keys, "errors", mustBeArray);
|
|
1502
1327
|
let warnings = getFlag(value, keys, "warnings", mustBeArray);
|
|
1503
1328
|
checkForInvalidFlags(value, keys, `from onEnd() callback in plugin ${quote(name)}`);
|
|
1504
|
-
if (errors != null)
|
|
1505
|
-
|
|
1506
|
-
if (warnings != null)
|
|
1507
|
-
newWarnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1329
|
+
if (errors != null) newErrors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1330
|
+
if (warnings != null) newWarnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1508
1331
|
}
|
|
1509
1332
|
} catch (e) {
|
|
1510
1333
|
newErrors = [extractErrorMessageV8(e, streamIn, details, note && note(), name)];
|
|
@@ -1549,8 +1372,7 @@ function createObjectStash() {
|
|
|
1549
1372
|
return map.get(id);
|
|
1550
1373
|
},
|
|
1551
1374
|
store(value) {
|
|
1552
|
-
if (value === void 0)
|
|
1553
|
-
return -1;
|
|
1375
|
+
if (value === void 0) return -1;
|
|
1554
1376
|
const id = nextID++;
|
|
1555
1377
|
map.set(id, value);
|
|
1556
1378
|
return id;
|
|
@@ -1561,8 +1383,7 @@ function extractCallerV8(e, streamIn, ident) {
|
|
|
1561
1383
|
let note;
|
|
1562
1384
|
let tried = false;
|
|
1563
1385
|
return () => {
|
|
1564
|
-
if (tried)
|
|
1565
|
-
return note;
|
|
1386
|
+
if (tried) return note;
|
|
1566
1387
|
tried = true;
|
|
1567
1388
|
try {
|
|
1568
1389
|
let lines = (e.stack + "").split("\n");
|
|
@@ -1594,8 +1415,7 @@ function parseStackLinesV8(streamIn, lines, ident) {
|
|
|
1594
1415
|
if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at)) {
|
|
1595
1416
|
for (let i = 1; i < lines.length; i++) {
|
|
1596
1417
|
let line = lines[i];
|
|
1597
|
-
if (!line.startsWith(at))
|
|
1598
|
-
continue;
|
|
1418
|
+
if (!line.startsWith(at)) continue;
|
|
1599
1419
|
line = line.slice(at.length);
|
|
1600
1420
|
while (true) {
|
|
1601
1421
|
let match = /^(?:new |async )?\S+ \((.*)\)$/.exec(line);
|
|
@@ -1638,10 +1458,8 @@ function parseStackLinesV8(streamIn, lines, ident) {
|
|
|
1638
1458
|
function failureErrorWithLog(text, errors, warnings) {
|
|
1639
1459
|
let limit = 5;
|
|
1640
1460
|
text += errors.length < 1 ? "" : ` with ${errors.length} error${errors.length < 2 ? "" : "s"}:` + errors.slice(0, limit + 1).map((e, i) => {
|
|
1641
|
-
if (i === limit)
|
|
1642
|
-
|
|
1643
|
-
if (!e.location)
|
|
1644
|
-
return `
|
|
1461
|
+
if (i === limit) return "\n...";
|
|
1462
|
+
if (!e.location) return `
|
|
1645
1463
|
error: ${e.text}`;
|
|
1646
1464
|
let { file, line, column } = e.location;
|
|
1647
1465
|
let pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : "";
|
|
@@ -1670,8 +1488,7 @@ function replaceDetailsInMessages(messages, stash) {
|
|
|
1670
1488
|
return messages;
|
|
1671
1489
|
}
|
|
1672
1490
|
function sanitizeLocation(location, where, terminalWidth) {
|
|
1673
|
-
if (location == null)
|
|
1674
|
-
return null;
|
|
1491
|
+
if (location == null) return null;
|
|
1675
1492
|
let keys = {};
|
|
1676
1493
|
let file = getFlag(location, keys, "file", mustBeString);
|
|
1677
1494
|
let namespace = getFlag(location, keys, "namespace", mustBeString);
|
|
@@ -1741,8 +1558,7 @@ function sanitizeMessages(messages, property, stash, fallbackPluginName, termina
|
|
|
1741
1558
|
function sanitizeStringArray(values, property) {
|
|
1742
1559
|
const result = [];
|
|
1743
1560
|
for (const value of values) {
|
|
1744
|
-
if (typeof value !== "string")
|
|
1745
|
-
throw new Error(`${quote(property)} must be an array of strings`);
|
|
1561
|
+
if (typeof value !== "string") throw new Error(`${quote(property)} must be an array of strings`);
|
|
1746
1562
|
result.push(value);
|
|
1747
1563
|
}
|
|
1748
1564
|
return result;
|
|
@@ -1828,16 +1644,14 @@ function pkgForSomeOtherPlatform() {
|
|
|
1828
1644
|
for (const unixKey in knownUnixlikePackages) {
|
|
1829
1645
|
try {
|
|
1830
1646
|
const pkg = knownUnixlikePackages[unixKey];
|
|
1831
|
-
if (fs.existsSync(path.join(nodeModulesDirectory, pkg)))
|
|
1832
|
-
return pkg;
|
|
1647
|
+
if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
|
1833
1648
|
} catch {
|
|
1834
1649
|
}
|
|
1835
1650
|
}
|
|
1836
1651
|
for (const windowsKey in knownWindowsPackages) {
|
|
1837
1652
|
try {
|
|
1838
1653
|
const pkg = knownWindowsPackages[windowsKey];
|
|
1839
|
-
if (fs.existsSync(path.join(nodeModulesDirectory, pkg)))
|
|
1840
|
-
return pkg;
|
|
1654
|
+
if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
|
1841
1655
|
} catch {
|
|
1842
1656
|
}
|
|
1843
1657
|
}
|
|
@@ -1941,7 +1755,7 @@ for your current platform.`);
|
|
|
1941
1755
|
"node_modules",
|
|
1942
1756
|
".cache",
|
|
1943
1757
|
"esbuild",
|
|
1944
|
-
`pnpapi-${pkg.replace("/", "-")}-${"0.
|
|
1758
|
+
`pnpapi-${pkg.replace("/", "-")}-${"0.21.0"}-${path.basename(subpath)}`
|
|
1945
1759
|
);
|
|
1946
1760
|
if (!fs.existsSync(binTargetPath)) {
|
|
1947
1761
|
fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
|
|
@@ -1976,7 +1790,7 @@ if (process.env.ESBUILD_WORKER_THREADS !== "0") {
|
|
|
1976
1790
|
}
|
|
1977
1791
|
}
|
|
1978
1792
|
var _a;
|
|
1979
|
-
var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.
|
|
1793
|
+
var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.21.0";
|
|
1980
1794
|
var esbuildCommandAndArgs = () => {
|
|
1981
1795
|
if ((!ESBUILD_BINARY_PATH || false) && (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib")) {
|
|
1982
1796
|
throw new Error(
|
|
@@ -2043,7 +1857,7 @@ var fsAsync = {
|
|
|
2043
1857
|
}
|
|
2044
1858
|
}
|
|
2045
1859
|
};
|
|
2046
|
-
var version = "0.
|
|
1860
|
+
var version = "0.21.0";
|
|
2047
1861
|
var build = (options) => ensureServiceIsRunning().build(options);
|
|
2048
1862
|
var context = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
|
|
2049
1863
|
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
|
@@ -2051,8 +1865,7 @@ var formatMessages = (messages, options) => ensureServiceIsRunning().formatMessa
|
|
|
2051
1865
|
var analyzeMetafile = (messages, options) => ensureServiceIsRunning().analyzeMetafile(messages, options);
|
|
2052
1866
|
var buildSync = (options) => {
|
|
2053
1867
|
if (worker_threads && !isInternalWorkerThread) {
|
|
2054
|
-
if (!workerThreadService)
|
|
2055
|
-
workerThreadService = startWorkerThreadService(worker_threads);
|
|
1868
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
2056
1869
|
return workerThreadService.buildSync(options);
|
|
2057
1870
|
}
|
|
2058
1871
|
let result;
|
|
@@ -2063,8 +1876,7 @@ var buildSync = (options) => {
|
|
|
2063
1876
|
isTTY: isTTY(),
|
|
2064
1877
|
defaultWD,
|
|
2065
1878
|
callback: (err, res) => {
|
|
2066
|
-
if (err)
|
|
2067
|
-
throw err;
|
|
1879
|
+
if (err) throw err;
|
|
2068
1880
|
result = res;
|
|
2069
1881
|
}
|
|
2070
1882
|
}));
|
|
@@ -2072,8 +1884,7 @@ var buildSync = (options) => {
|
|
|
2072
1884
|
};
|
|
2073
1885
|
var transformSync = (input, options) => {
|
|
2074
1886
|
if (worker_threads && !isInternalWorkerThread) {
|
|
2075
|
-
if (!workerThreadService)
|
|
2076
|
-
workerThreadService = startWorkerThreadService(worker_threads);
|
|
1887
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
2077
1888
|
return workerThreadService.transformSync(input, options);
|
|
2078
1889
|
}
|
|
2079
1890
|
let result;
|
|
@@ -2085,8 +1896,7 @@ var transformSync = (input, options) => {
|
|
|
2085
1896
|
isTTY: isTTY(),
|
|
2086
1897
|
fs: fsSync,
|
|
2087
1898
|
callback: (err, res) => {
|
|
2088
|
-
if (err)
|
|
2089
|
-
throw err;
|
|
1899
|
+
if (err) throw err;
|
|
2090
1900
|
result = res;
|
|
2091
1901
|
}
|
|
2092
1902
|
}));
|
|
@@ -2094,8 +1904,7 @@ var transformSync = (input, options) => {
|
|
|
2094
1904
|
};
|
|
2095
1905
|
var formatMessagesSync = (messages, options) => {
|
|
2096
1906
|
if (worker_threads && !isInternalWorkerThread) {
|
|
2097
|
-
if (!workerThreadService)
|
|
2098
|
-
workerThreadService = startWorkerThreadService(worker_threads);
|
|
1907
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
2099
1908
|
return workerThreadService.formatMessagesSync(messages, options);
|
|
2100
1909
|
}
|
|
2101
1910
|
let result;
|
|
@@ -2105,8 +1914,7 @@ var formatMessagesSync = (messages, options) => {
|
|
|
2105
1914
|
messages,
|
|
2106
1915
|
options,
|
|
2107
1916
|
callback: (err, res) => {
|
|
2108
|
-
if (err)
|
|
2109
|
-
throw err;
|
|
1917
|
+
if (err) throw err;
|
|
2110
1918
|
result = res;
|
|
2111
1919
|
}
|
|
2112
1920
|
}));
|
|
@@ -2114,8 +1922,7 @@ var formatMessagesSync = (messages, options) => {
|
|
|
2114
1922
|
};
|
|
2115
1923
|
var analyzeMetafileSync = (metafile, options) => {
|
|
2116
1924
|
if (worker_threads && !isInternalWorkerThread) {
|
|
2117
|
-
if (!workerThreadService)
|
|
2118
|
-
workerThreadService = startWorkerThreadService(worker_threads);
|
|
1925
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
2119
1926
|
return workerThreadService.analyzeMetafileSync(metafile, options);
|
|
2120
1927
|
}
|
|
2121
1928
|
let result;
|
|
@@ -2125,31 +1932,24 @@ var analyzeMetafileSync = (metafile, options) => {
|
|
|
2125
1932
|
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
|
2126
1933
|
options,
|
|
2127
1934
|
callback: (err, res) => {
|
|
2128
|
-
if (err)
|
|
2129
|
-
throw err;
|
|
1935
|
+
if (err) throw err;
|
|
2130
1936
|
result = res;
|
|
2131
1937
|
}
|
|
2132
1938
|
}));
|
|
2133
1939
|
return result;
|
|
2134
1940
|
};
|
|
2135
1941
|
var stop = () => {
|
|
2136
|
-
if (stopService)
|
|
2137
|
-
|
|
2138
|
-
if (workerThreadService)
|
|
2139
|
-
workerThreadService.stop();
|
|
1942
|
+
if (stopService) stopService();
|
|
1943
|
+
if (workerThreadService) workerThreadService.stop();
|
|
2140
1944
|
return Promise.resolve();
|
|
2141
1945
|
};
|
|
2142
1946
|
var initializeWasCalled = false;
|
|
2143
1947
|
var initialize = (options) => {
|
|
2144
1948
|
options = validateInitializeOptions(options || {});
|
|
2145
|
-
if (options.wasmURL)
|
|
2146
|
-
|
|
2147
|
-
if (options.
|
|
2148
|
-
|
|
2149
|
-
if (options.worker)
|
|
2150
|
-
throw new Error(`The "worker" option only works in the browser`);
|
|
2151
|
-
if (initializeWasCalled)
|
|
2152
|
-
throw new Error('Cannot call "initialize" more than once');
|
|
1949
|
+
if (options.wasmURL) throw new Error(`The "wasmURL" option only works in the browser`);
|
|
1950
|
+
if (options.wasmModule) throw new Error(`The "wasmModule" option only works in the browser`);
|
|
1951
|
+
if (options.worker) throw new Error(`The "worker" option only works in the browser`);
|
|
1952
|
+
if (initializeWasCalled) throw new Error('Cannot call "initialize" more than once');
|
|
2153
1953
|
ensureServiceIsRunning();
|
|
2154
1954
|
initializeWasCalled = true;
|
|
2155
1955
|
return Promise.resolve();
|
|
@@ -2158,10 +1958,9 @@ var defaultWD = process.cwd();
|
|
|
2158
1958
|
var longLivedService;
|
|
2159
1959
|
var stopService;
|
|
2160
1960
|
var ensureServiceIsRunning = () => {
|
|
2161
|
-
if (longLivedService)
|
|
2162
|
-
return longLivedService;
|
|
1961
|
+
if (longLivedService) return longLivedService;
|
|
2163
1962
|
let [command, args] = esbuildCommandAndArgs();
|
|
2164
|
-
let child = child_process.spawn(command, args.concat(`--service=${"0.
|
|
1963
|
+
let child = child_process.spawn(command, args.concat(`--service=${"0.21.0"}`, "--ping"), {
|
|
2165
1964
|
windowsHide: true,
|
|
2166
1965
|
stdio: ["pipe", "pipe", "inherit"],
|
|
2167
1966
|
cwd: defaultWD
|
|
@@ -2169,8 +1968,7 @@ var ensureServiceIsRunning = () => {
|
|
|
2169
1968
|
let { readFromStdout, afterClose, service } = createChannel({
|
|
2170
1969
|
writeToStdin(bytes) {
|
|
2171
1970
|
child.stdin.write(bytes, (err) => {
|
|
2172
|
-
if (err)
|
|
2173
|
-
afterClose(err);
|
|
1971
|
+
if (err) afterClose(err);
|
|
2174
1972
|
});
|
|
2175
1973
|
},
|
|
2176
1974
|
readFileSync: fs2.readFileSync,
|
|
@@ -2202,12 +2000,10 @@ var ensureServiceIsRunning = () => {
|
|
|
2202
2000
|
}
|
|
2203
2001
|
const refs = {
|
|
2204
2002
|
ref() {
|
|
2205
|
-
if (++refCount === 1)
|
|
2206
|
-
child.ref();
|
|
2003
|
+
if (++refCount === 1) child.ref();
|
|
2207
2004
|
},
|
|
2208
2005
|
unref() {
|
|
2209
|
-
if (--refCount === 0)
|
|
2210
|
-
child.unref();
|
|
2006
|
+
if (--refCount === 0) child.unref();
|
|
2211
2007
|
}
|
|
2212
2008
|
};
|
|
2213
2009
|
longLivedService = {
|
|
@@ -2260,8 +2056,7 @@ var runServiceSync = (callback) => {
|
|
|
2260
2056
|
let stdin = new Uint8Array();
|
|
2261
2057
|
let { readFromStdout, afterClose, service } = createChannel({
|
|
2262
2058
|
writeToStdin(bytes) {
|
|
2263
|
-
if (stdin.length !== 0)
|
|
2264
|
-
throw new Error("Must run at most one command");
|
|
2059
|
+
if (stdin.length !== 0) throw new Error("Must run at most one command");
|
|
2265
2060
|
stdin = bytes;
|
|
2266
2061
|
},
|
|
2267
2062
|
isSync: true,
|
|
@@ -2269,7 +2064,7 @@ var runServiceSync = (callback) => {
|
|
|
2269
2064
|
esbuild: node_exports
|
|
2270
2065
|
});
|
|
2271
2066
|
callback(service);
|
|
2272
|
-
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.
|
|
2067
|
+
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.21.0"}`), {
|
|
2273
2068
|
cwd: defaultWD,
|
|
2274
2069
|
windowsHide: true,
|
|
2275
2070
|
input: stdin,
|
|
@@ -2289,7 +2084,7 @@ var workerThreadService = null;
|
|
|
2289
2084
|
var startWorkerThreadService = (worker_threads2) => {
|
|
2290
2085
|
let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel();
|
|
2291
2086
|
let worker = new worker_threads2.Worker(__filename, {
|
|
2292
|
-
workerData: { workerPort, defaultWD, esbuildVersion: "0.
|
|
2087
|
+
workerData: { workerPort, defaultWD, esbuildVersion: "0.21.0" },
|
|
2293
2088
|
transferList: [workerPort],
|
|
2294
2089
|
// From node's documentation: https://nodejs.org/api/worker_threads.html
|
|
2295
2090
|
//
|
|
@@ -2312,11 +2107,9 @@ error: ${text}`);
|
|
|
2312
2107
|
return error;
|
|
2313
2108
|
};
|
|
2314
2109
|
let validateBuildSyncOptions = (options) => {
|
|
2315
|
-
if (!options)
|
|
2316
|
-
return;
|
|
2110
|
+
if (!options) return;
|
|
2317
2111
|
let plugins = options.plugins;
|
|
2318
|
-
if (plugins && plugins.length > 0)
|
|
2319
|
-
throw fakeBuildError(`Cannot use plugins in synchronous API calls`);
|
|
2112
|
+
if (plugins && plugins.length > 0) throw fakeBuildError(`Cannot use plugins in synchronous API calls`);
|
|
2320
2113
|
};
|
|
2321
2114
|
let applyProperties = (object, properties) => {
|
|
2322
2115
|
for (let key in properties) {
|
|
@@ -2330,11 +2123,9 @@ error: ${text}`);
|
|
|
2330
2123
|
let msg = { sharedBuffer, id, command, args };
|
|
2331
2124
|
worker.postMessage(msg);
|
|
2332
2125
|
let status = Atomics.wait(sharedBufferView, 0, 0);
|
|
2333
|
-
if (status !== "ok" && status !== "not-equal")
|
|
2334
|
-
throw new Error("Internal error: Atomics.wait() failed: " + status);
|
|
2126
|
+
if (status !== "ok" && status !== "not-equal") throw new Error("Internal error: Atomics.wait() failed: " + status);
|
|
2335
2127
|
let { message: { id: id2, resolve, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
|
|
2336
|
-
if (id !== id2)
|
|
2337
|
-
throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
|
2128
|
+
if (id !== id2) throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
|
2338
2129
|
if (reject) {
|
|
2339
2130
|
applyProperties(reject, properties);
|
|
2340
2131
|
throw reject;
|