esbuild 0.15.18 → 0.17.2
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 +33 -25
- package/install.js +70 -30
- package/lib/main.d.ts +274 -243
- package/lib/main.js +410 -350
- package/package.json +23 -23
package/lib/main.js
CHANGED
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -30,11 +34,11 @@ __export(node_exports, {
|
|
|
30
34
|
analyzeMetafileSync: () => analyzeMetafileSync,
|
|
31
35
|
build: () => build,
|
|
32
36
|
buildSync: () => buildSync,
|
|
37
|
+
context: () => context,
|
|
33
38
|
default: () => node_default,
|
|
34
39
|
formatMessages: () => formatMessages,
|
|
35
40
|
formatMessagesSync: () => formatMessagesSync,
|
|
36
41
|
initialize: () => initialize,
|
|
37
|
-
serve: () => serve,
|
|
38
42
|
transform: () => transform,
|
|
39
43
|
transformSync: () => transformSync,
|
|
40
44
|
version: () => version
|
|
@@ -175,26 +179,30 @@ var ByteBuffer = class {
|
|
|
175
179
|
};
|
|
176
180
|
var encodeUTF8;
|
|
177
181
|
var decodeUTF8;
|
|
182
|
+
var encodeInvariant;
|
|
178
183
|
if (typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined") {
|
|
179
184
|
let encoder = new TextEncoder();
|
|
180
185
|
let decoder = new TextDecoder();
|
|
181
186
|
encodeUTF8 = (text) => encoder.encode(text);
|
|
182
187
|
decodeUTF8 = (bytes) => decoder.decode(bytes);
|
|
188
|
+
encodeInvariant = 'new TextEncoder().encode("")';
|
|
183
189
|
} else if (typeof Buffer !== "undefined") {
|
|
184
|
-
encodeUTF8 = (text) =>
|
|
185
|
-
let buffer = Buffer.from(text);
|
|
186
|
-
if (!(buffer instanceof Uint8Array)) {
|
|
187
|
-
buffer = new Uint8Array(buffer);
|
|
188
|
-
}
|
|
189
|
-
return buffer;
|
|
190
|
-
};
|
|
190
|
+
encodeUTF8 = (text) => Buffer.from(text);
|
|
191
191
|
decodeUTF8 = (bytes) => {
|
|
192
192
|
let { buffer, byteOffset, byteLength } = bytes;
|
|
193
193
|
return Buffer.from(buffer, byteOffset, byteLength).toString();
|
|
194
194
|
};
|
|
195
|
+
encodeInvariant = 'Buffer.from("")';
|
|
195
196
|
} else {
|
|
196
197
|
throw new Error("No UTF-8 codec found");
|
|
197
198
|
}
|
|
199
|
+
if (!(encodeUTF8("") instanceof Uint8Array))
|
|
200
|
+
throw new Error(`Invariant violation: "${encodeInvariant} instanceof Uint8Array" is incorrectly false
|
|
201
|
+
|
|
202
|
+
This indicates that your JavaScript environment is broken. You cannot use
|
|
203
|
+
esbuild in this environment because esbuild relies on this invariant. This
|
|
204
|
+
is not a problem with esbuild. You need to fix your environment instead.
|
|
205
|
+
`);
|
|
198
206
|
function readUInt32LE(buffer, offset) {
|
|
199
207
|
return buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24;
|
|
200
208
|
}
|
|
@@ -206,25 +214,25 @@ function writeUInt32LE(buffer, value, offset) {
|
|
|
206
214
|
}
|
|
207
215
|
|
|
208
216
|
// lib/shared/common.ts
|
|
217
|
+
var quote = JSON.stringify;
|
|
209
218
|
var buildLogLevelDefault = "warning";
|
|
210
219
|
var transformLogLevelDefault = "silent";
|
|
211
220
|
function validateTarget(target) {
|
|
212
|
-
target
|
|
221
|
+
validateStringValue(target, "target");
|
|
213
222
|
if (target.indexOf(",") >= 0)
|
|
214
223
|
throw new Error(`Invalid target: ${target}`);
|
|
215
224
|
return target;
|
|
216
225
|
}
|
|
217
226
|
var canBeAnything = () => null;
|
|
218
227
|
var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
|
|
219
|
-
var mustBeBooleanOrObject = (value) => typeof value === "boolean" || typeof value === "object" && !Array.isArray(value) ? null : "a boolean or an object";
|
|
220
228
|
var mustBeString = (value) => typeof value === "string" ? null : "a string";
|
|
221
229
|
var mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object";
|
|
222
230
|
var mustBeInteger = (value) => typeof value === "number" && value === (value | 0) ? null : "an integer";
|
|
223
231
|
var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
|
|
224
232
|
var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
|
|
225
233
|
var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
|
|
234
|
+
var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
|
226
235
|
var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
|
|
227
|
-
var mustBeArrayOrRecord = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
|
228
236
|
var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
|
|
229
237
|
var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
|
|
230
238
|
var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
|
|
@@ -238,13 +246,13 @@ function getFlag(object, keys, key, mustBeFn) {
|
|
|
238
246
|
return void 0;
|
|
239
247
|
let mustBe = mustBeFn(value);
|
|
240
248
|
if (mustBe !== null)
|
|
241
|
-
throw new Error(
|
|
249
|
+
throw new Error(`${quote(key)} must be ${mustBe}`);
|
|
242
250
|
return value;
|
|
243
251
|
}
|
|
244
252
|
function checkForInvalidFlags(object, keys, where) {
|
|
245
253
|
for (let key in object) {
|
|
246
254
|
if (!(key in keys)) {
|
|
247
|
-
throw new Error(`Invalid option ${where}:
|
|
255
|
+
throw new Error(`Invalid option ${where}: ${quote(key)}`);
|
|
248
256
|
}
|
|
249
257
|
}
|
|
250
258
|
}
|
|
@@ -264,12 +272,12 @@ function validateMangleCache(mangleCache) {
|
|
|
264
272
|
let validated;
|
|
265
273
|
if (mangleCache !== void 0) {
|
|
266
274
|
validated = /* @__PURE__ */ Object.create(null);
|
|
267
|
-
for (let key
|
|
275
|
+
for (let key in mangleCache) {
|
|
268
276
|
let value = mangleCache[key];
|
|
269
277
|
if (typeof value === "string" || value === false) {
|
|
270
278
|
validated[key] = value;
|
|
271
279
|
} else {
|
|
272
|
-
throw new Error(`Expected ${
|
|
280
|
+
throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`);
|
|
273
281
|
}
|
|
274
282
|
}
|
|
275
283
|
}
|
|
@@ -286,6 +294,12 @@ function pushLogFlags(flags, options, keys, isTTY2, logLevelDefault) {
|
|
|
286
294
|
flags.push(`--log-level=${logLevel || logLevelDefault}`);
|
|
287
295
|
flags.push(`--log-limit=${logLimit || 0}`);
|
|
288
296
|
}
|
|
297
|
+
function validateStringValue(value, what, key) {
|
|
298
|
+
if (typeof value !== "string") {
|
|
299
|
+
throw new Error(`Expected value for ${what}${key !== void 0 ? " " + quote(key) : ""} to be a string, got ${typeof value} instead`);
|
|
300
|
+
}
|
|
301
|
+
return value;
|
|
302
|
+
}
|
|
289
303
|
function pushCommonFlags(flags, options, keys) {
|
|
290
304
|
let legalComments = getFlag(options, keys, "legalComments", mustBeString);
|
|
291
305
|
let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
|
|
@@ -350,7 +364,7 @@ function pushCommonFlags(flags, options, keys) {
|
|
|
350
364
|
flags.push(`--ignore-annotations`);
|
|
351
365
|
if (drop)
|
|
352
366
|
for (let what of drop)
|
|
353
|
-
flags.push(`--drop:${what}`);
|
|
367
|
+
flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
|
354
368
|
if (mangleProps)
|
|
355
369
|
flags.push(`--mangle-props=${mangleProps.source}`);
|
|
356
370
|
if (reserveProps)
|
|
@@ -373,26 +387,29 @@ function pushCommonFlags(flags, options, keys) {
|
|
|
373
387
|
for (let key in define) {
|
|
374
388
|
if (key.indexOf("=") >= 0)
|
|
375
389
|
throw new Error(`Invalid define: ${key}`);
|
|
376
|
-
flags.push(`--define:${key}=${define[key]}`);
|
|
390
|
+
flags.push(`--define:${key}=${validateStringValue(define[key], "define", key)}`);
|
|
377
391
|
}
|
|
378
392
|
}
|
|
379
393
|
if (logOverride) {
|
|
380
394
|
for (let key in logOverride) {
|
|
381
395
|
if (key.indexOf("=") >= 0)
|
|
382
396
|
throw new Error(`Invalid log override: ${key}`);
|
|
383
|
-
flags.push(`--log-override:${key}=${logOverride[key]}`);
|
|
397
|
+
flags.push(`--log-override:${key}=${validateStringValue(logOverride[key], "log override", key)}`);
|
|
384
398
|
}
|
|
385
399
|
}
|
|
386
400
|
if (supported) {
|
|
387
401
|
for (let key in supported) {
|
|
388
402
|
if (key.indexOf("=") >= 0)
|
|
389
403
|
throw new Error(`Invalid supported: ${key}`);
|
|
390
|
-
|
|
404
|
+
const value = supported[key];
|
|
405
|
+
if (typeof value !== "boolean")
|
|
406
|
+
throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
|
|
407
|
+
flags.push(`--supported:${key}=${value}`);
|
|
391
408
|
}
|
|
392
409
|
}
|
|
393
410
|
if (pure)
|
|
394
411
|
for (let fn of pure)
|
|
395
|
-
flags.push(`--pure:${fn}`);
|
|
412
|
+
flags.push(`--pure:${validateStringValue(fn, "pure")}`);
|
|
396
413
|
if (keepNames)
|
|
397
414
|
flags.push(`--keep-names`);
|
|
398
415
|
}
|
|
@@ -403,12 +420,10 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
403
420
|
let keys = /* @__PURE__ */ Object.create(null);
|
|
404
421
|
let stdinContents = null;
|
|
405
422
|
let stdinResolveDir = null;
|
|
406
|
-
let watchMode = null;
|
|
407
423
|
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
|
408
424
|
pushCommonFlags(flags, options, keys);
|
|
409
425
|
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
|
410
426
|
let bundle = getFlag(options, keys, "bundle", mustBeBoolean);
|
|
411
|
-
let watch = getFlag(options, keys, "watch", mustBeBooleanOrObject);
|
|
412
427
|
let splitting = getFlag(options, keys, "splitting", mustBeBoolean);
|
|
413
428
|
let preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean);
|
|
414
429
|
let metafile = getFlag(options, keys, "metafile", mustBeBoolean);
|
|
@@ -421,6 +436,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
421
436
|
let mainFields = getFlag(options, keys, "mainFields", mustBeArray);
|
|
422
437
|
let conditions = getFlag(options, keys, "conditions", mustBeArray);
|
|
423
438
|
let external = getFlag(options, keys, "external", mustBeArray);
|
|
439
|
+
let packages = getFlag(options, keys, "packages", mustBeString);
|
|
424
440
|
let alias = getFlag(options, keys, "alias", mustBeObject);
|
|
425
441
|
let loader = getFlag(options, keys, "loader", mustBeObject);
|
|
426
442
|
let outExtension = getFlag(options, keys, "outExtension", mustBeObject);
|
|
@@ -431,12 +447,11 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
431
447
|
let inject = getFlag(options, keys, "inject", mustBeArray);
|
|
432
448
|
let banner = getFlag(options, keys, "banner", mustBeObject);
|
|
433
449
|
let footer = getFlag(options, keys, "footer", mustBeObject);
|
|
434
|
-
let entryPoints = getFlag(options, keys, "entryPoints",
|
|
450
|
+
let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
|
|
435
451
|
let absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString);
|
|
436
452
|
let stdin = getFlag(options, keys, "stdin", mustBeObject);
|
|
437
453
|
let write = (_a2 = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a2 : writeDefault;
|
|
438
454
|
let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean);
|
|
439
|
-
let incremental = getFlag(options, keys, "incremental", mustBeBoolean) === true;
|
|
440
455
|
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
441
456
|
keys.plugins = true;
|
|
442
457
|
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
@@ -446,17 +461,6 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
446
461
|
flags.push("--bundle");
|
|
447
462
|
if (allowOverwrite)
|
|
448
463
|
flags.push("--allow-overwrite");
|
|
449
|
-
if (watch) {
|
|
450
|
-
flags.push("--watch");
|
|
451
|
-
if (typeof watch === "boolean") {
|
|
452
|
-
watchMode = {};
|
|
453
|
-
} else {
|
|
454
|
-
let watchKeys = /* @__PURE__ */ Object.create(null);
|
|
455
|
-
let onRebuild = getFlag(watch, watchKeys, "onRebuild", mustBeFunction);
|
|
456
|
-
checkForInvalidFlags(watch, watchKeys, `on "watch" in ${callName}() call`);
|
|
457
|
-
watchMode = { onRebuild };
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
464
|
if (splitting)
|
|
461
465
|
flags.push("--splitting");
|
|
462
466
|
if (preserveSymlinks)
|
|
@@ -471,10 +475,12 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
471
475
|
flags.push(`--outbase=${outbase}`);
|
|
472
476
|
if (tsconfig)
|
|
473
477
|
flags.push(`--tsconfig=${tsconfig}`);
|
|
478
|
+
if (packages)
|
|
479
|
+
flags.push(`--packages=${packages}`);
|
|
474
480
|
if (resolveExtensions) {
|
|
475
481
|
let values = [];
|
|
476
482
|
for (let value of resolveExtensions) {
|
|
477
|
-
value
|
|
483
|
+
validateStringValue(value, "resolve extension");
|
|
478
484
|
if (value.indexOf(",") >= 0)
|
|
479
485
|
throw new Error(`Invalid resolve extension: ${value}`);
|
|
480
486
|
values.push(value);
|
|
@@ -492,7 +498,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
492
498
|
if (mainFields) {
|
|
493
499
|
let values = [];
|
|
494
500
|
for (let value of mainFields) {
|
|
495
|
-
value
|
|
501
|
+
validateStringValue(value, "main field");
|
|
496
502
|
if (value.indexOf(",") >= 0)
|
|
497
503
|
throw new Error(`Invalid main field: ${value}`);
|
|
498
504
|
values.push(value);
|
|
@@ -502,7 +508,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
502
508
|
if (conditions) {
|
|
503
509
|
let values = [];
|
|
504
510
|
for (let value of conditions) {
|
|
505
|
-
value
|
|
511
|
+
validateStringValue(value, "condition");
|
|
506
512
|
if (value.indexOf(",") >= 0)
|
|
507
513
|
throw new Error(`Invalid condition: ${value}`);
|
|
508
514
|
values.push(value);
|
|
@@ -511,53 +517,66 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
511
517
|
}
|
|
512
518
|
if (external)
|
|
513
519
|
for (let name of external)
|
|
514
|
-
flags.push(`--external:${name}`);
|
|
520
|
+
flags.push(`--external:${validateStringValue(name, "external")}`);
|
|
515
521
|
if (alias) {
|
|
516
522
|
for (let old in alias) {
|
|
517
523
|
if (old.indexOf("=") >= 0)
|
|
518
524
|
throw new Error(`Invalid package name in alias: ${old}`);
|
|
519
|
-
flags.push(`--alias:${old}=${alias[old]}`);
|
|
525
|
+
flags.push(`--alias:${old}=${validateStringValue(alias[old], "alias", old)}`);
|
|
520
526
|
}
|
|
521
527
|
}
|
|
522
528
|
if (banner) {
|
|
523
529
|
for (let type in banner) {
|
|
524
530
|
if (type.indexOf("=") >= 0)
|
|
525
531
|
throw new Error(`Invalid banner file type: ${type}`);
|
|
526
|
-
flags.push(`--banner:${type}=${banner[type]}`);
|
|
532
|
+
flags.push(`--banner:${type}=${validateStringValue(banner[type], "banner", type)}`);
|
|
527
533
|
}
|
|
528
534
|
}
|
|
529
535
|
if (footer) {
|
|
530
536
|
for (let type in footer) {
|
|
531
537
|
if (type.indexOf("=") >= 0)
|
|
532
538
|
throw new Error(`Invalid footer file type: ${type}`);
|
|
533
|
-
flags.push(`--footer:${type}=${footer[type]}`);
|
|
539
|
+
flags.push(`--footer:${type}=${validateStringValue(footer[type], "footer", type)}`);
|
|
534
540
|
}
|
|
535
541
|
}
|
|
536
542
|
if (inject)
|
|
537
543
|
for (let path3 of inject)
|
|
538
|
-
flags.push(`--inject:${path3}`);
|
|
544
|
+
flags.push(`--inject:${validateStringValue(path3, "inject")}`);
|
|
539
545
|
if (loader) {
|
|
540
546
|
for (let ext in loader) {
|
|
541
547
|
if (ext.indexOf("=") >= 0)
|
|
542
548
|
throw new Error(`Invalid loader extension: ${ext}`);
|
|
543
|
-
flags.push(`--loader:${ext}=${loader[ext]}`);
|
|
549
|
+
flags.push(`--loader:${ext}=${validateStringValue(loader[ext], "loader", ext)}`);
|
|
544
550
|
}
|
|
545
551
|
}
|
|
546
552
|
if (outExtension) {
|
|
547
553
|
for (let ext in outExtension) {
|
|
548
554
|
if (ext.indexOf("=") >= 0)
|
|
549
555
|
throw new Error(`Invalid out extension: ${ext}`);
|
|
550
|
-
flags.push(`--out-extension:${ext}=${outExtension[ext]}`);
|
|
556
|
+
flags.push(`--out-extension:${ext}=${validateStringValue(outExtension[ext], "out extension", ext)}`);
|
|
551
557
|
}
|
|
552
558
|
}
|
|
553
559
|
if (entryPoints) {
|
|
554
560
|
if (Array.isArray(entryPoints)) {
|
|
555
|
-
for (let
|
|
556
|
-
|
|
561
|
+
for (let i = 0, n = entryPoints.length; i < n; i++) {
|
|
562
|
+
let entryPoint = entryPoints[i];
|
|
563
|
+
if (typeof entryPoint === "object" && entryPoint !== null) {
|
|
564
|
+
let entryPointKeys = /* @__PURE__ */ Object.create(null);
|
|
565
|
+
let input = getFlag(entryPoint, entryPointKeys, "in", mustBeString);
|
|
566
|
+
let output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
|
|
567
|
+
checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i);
|
|
568
|
+
if (input === void 0)
|
|
569
|
+
throw new Error('Missing property "in" for entry point at index ' + i);
|
|
570
|
+
if (output === void 0)
|
|
571
|
+
throw new Error('Missing property "out" for entry point at index ' + i);
|
|
572
|
+
entries.push([output, input]);
|
|
573
|
+
} else {
|
|
574
|
+
entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
|
|
575
|
+
}
|
|
557
576
|
}
|
|
558
577
|
} else {
|
|
559
|
-
for (let
|
|
560
|
-
entries.push([key
|
|
578
|
+
for (let key in entryPoints) {
|
|
579
|
+
entries.push([key, validateStringValue(entryPoints[key], "entry point", key)]);
|
|
561
580
|
}
|
|
562
581
|
}
|
|
563
582
|
}
|
|
@@ -573,7 +592,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
573
592
|
if (loader2)
|
|
574
593
|
flags.push(`--loader=${loader2}`);
|
|
575
594
|
if (resolveDir)
|
|
576
|
-
stdinResolveDir = resolveDir
|
|
595
|
+
stdinResolveDir = resolveDir;
|
|
577
596
|
if (typeof contents === "string")
|
|
578
597
|
stdinContents = encodeUTF8(contents);
|
|
579
598
|
else if (contents instanceof Uint8Array)
|
|
@@ -593,9 +612,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
593
612
|
stdinContents,
|
|
594
613
|
stdinResolveDir,
|
|
595
614
|
absWorkingDir,
|
|
596
|
-
incremental,
|
|
597
615
|
nodePaths,
|
|
598
|
-
watch: watchMode,
|
|
599
616
|
mangleCache: validateMangleCache(mangleCache)
|
|
600
617
|
};
|
|
601
618
|
}
|
|
@@ -718,8 +735,8 @@ function createChannel(streamIn) {
|
|
|
718
735
|
if (isFirstPacket) {
|
|
719
736
|
isFirstPacket = false;
|
|
720
737
|
let binaryVersion = String.fromCharCode(...bytes);
|
|
721
|
-
if (binaryVersion !== "0.
|
|
722
|
-
throw new Error(`Cannot start service: Host version "${"0.
|
|
738
|
+
if (binaryVersion !== "0.17.2") {
|
|
739
|
+
throw new Error(`Cannot start service: Host version "${"0.17.2"}" does not match binary version ${quote(binaryVersion)}`);
|
|
723
740
|
}
|
|
724
741
|
return;
|
|
725
742
|
}
|
|
@@ -735,7 +752,7 @@ function createChannel(streamIn) {
|
|
|
735
752
|
callback(null, packet.value);
|
|
736
753
|
}
|
|
737
754
|
};
|
|
738
|
-
let
|
|
755
|
+
let buildOrContext = ({ callName, refs, options, isTTY: isTTY2, defaultWD: defaultWD2, callback }) => {
|
|
739
756
|
let refCount = 0;
|
|
740
757
|
const buildKey = nextBuildKey++;
|
|
741
758
|
const requestCallbacks = {};
|
|
@@ -756,7 +773,7 @@ function createChannel(streamIn) {
|
|
|
756
773
|
};
|
|
757
774
|
requestCallbacksByKey[buildKey] = requestCallbacks;
|
|
758
775
|
buildRefs.ref();
|
|
759
|
-
|
|
776
|
+
buildOrContextImpl(
|
|
760
777
|
callName,
|
|
761
778
|
buildKey,
|
|
762
779
|
sendRequest,
|
|
@@ -765,10 +782,8 @@ function createChannel(streamIn) {
|
|
|
765
782
|
streamIn,
|
|
766
783
|
requestCallbacks,
|
|
767
784
|
options,
|
|
768
|
-
serveOptions,
|
|
769
785
|
isTTY2,
|
|
770
786
|
defaultWD2,
|
|
771
|
-
closeData,
|
|
772
787
|
(err, res) => {
|
|
773
788
|
try {
|
|
774
789
|
callback(err, res);
|
|
@@ -804,7 +819,15 @@ function createChannel(streamIn) {
|
|
|
804
819
|
let outstanding = 1;
|
|
805
820
|
let next = () => {
|
|
806
821
|
if (--outstanding === 0) {
|
|
807
|
-
let result = {
|
|
822
|
+
let result = {
|
|
823
|
+
warnings,
|
|
824
|
+
code: response.code,
|
|
825
|
+
map: response.map,
|
|
826
|
+
mangleCache: void 0,
|
|
827
|
+
legalComments: void 0
|
|
828
|
+
};
|
|
829
|
+
if ("legalComments" in response)
|
|
830
|
+
result.legalComments = response == null ? void 0 : response.legalComments;
|
|
808
831
|
if (response.mangleCache)
|
|
809
832
|
result.mangleCache = response == null ? void 0 : response.mangleCache;
|
|
810
833
|
callback(null, result);
|
|
@@ -908,30 +931,26 @@ function createChannel(streamIn) {
|
|
|
908
931
|
readFromStdout,
|
|
909
932
|
afterClose,
|
|
910
933
|
service: {
|
|
911
|
-
|
|
934
|
+
buildOrContext,
|
|
912
935
|
transform: transform2,
|
|
913
936
|
formatMessages: formatMessages2,
|
|
914
937
|
analyzeMetafile: analyzeMetafile2
|
|
915
938
|
}
|
|
916
939
|
};
|
|
917
940
|
}
|
|
918
|
-
function
|
|
941
|
+
function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, isTTY2, defaultWD2, callback) {
|
|
919
942
|
const details = createObjectStash();
|
|
920
|
-
const
|
|
943
|
+
const isContext = callName === "context";
|
|
944
|
+
const handleError = (e, pluginName) => {
|
|
921
945
|
const flags = [];
|
|
922
946
|
try {
|
|
923
947
|
pushLogFlags(flags, options, {}, isTTY2, buildLogLevelDefault);
|
|
924
948
|
} catch {
|
|
925
949
|
}
|
|
926
|
-
const message = extractErrorMessageV8(e, streamIn, details,
|
|
950
|
+
const message = extractErrorMessageV8(e, streamIn, details, void 0, pluginName);
|
|
927
951
|
sendRequest(refs, { command: "error", flags, error: message }, () => {
|
|
928
952
|
message.detail = details.load(message.detail);
|
|
929
|
-
|
|
930
|
-
});
|
|
931
|
-
};
|
|
932
|
-
const handleError = (e, pluginName) => {
|
|
933
|
-
logPluginError(e, pluginName, void 0, (error) => {
|
|
934
|
-
callback(failureErrorWithLog("Build failed", [error], []), null);
|
|
953
|
+
callback(failureErrorWithLog(isContext ? "Context failed" : "Build failed", [message], []), null);
|
|
935
954
|
});
|
|
936
955
|
};
|
|
937
956
|
let plugins;
|
|
@@ -939,15 +958,13 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
|
|
|
939
958
|
const value = options.plugins;
|
|
940
959
|
if (value !== void 0) {
|
|
941
960
|
if (!Array.isArray(value))
|
|
942
|
-
|
|
961
|
+
return handleError(new Error(`"plugins" must be an array`), "");
|
|
943
962
|
plugins = value;
|
|
944
963
|
}
|
|
945
964
|
}
|
|
946
965
|
if (plugins && plugins.length > 0) {
|
|
947
|
-
if (streamIn.isSync)
|
|
948
|
-
handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
|
949
|
-
return;
|
|
950
|
-
}
|
|
966
|
+
if (streamIn.isSync)
|
|
967
|
+
return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
|
951
968
|
handlePlugins(
|
|
952
969
|
buildKey,
|
|
953
970
|
sendRequest,
|
|
@@ -960,12 +977,10 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
|
|
|
960
977
|
details
|
|
961
978
|
).then(
|
|
962
979
|
(result) => {
|
|
963
|
-
if (!result.ok)
|
|
964
|
-
handleError(result.error, result.pluginName);
|
|
965
|
-
return;
|
|
966
|
-
}
|
|
980
|
+
if (!result.ok)
|
|
981
|
+
return handleError(result.error, result.pluginName);
|
|
967
982
|
try {
|
|
968
|
-
|
|
983
|
+
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
|
|
969
984
|
} catch (e) {
|
|
970
985
|
handleError(e, "");
|
|
971
986
|
}
|
|
@@ -975,25 +990,26 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
|
|
|
975
990
|
return;
|
|
976
991
|
}
|
|
977
992
|
try {
|
|
978
|
-
|
|
993
|
+
buildOrContextContinue(null, (result, done) => done([], []), () => {
|
|
994
|
+
});
|
|
979
995
|
} catch (e) {
|
|
980
996
|
handleError(e, "");
|
|
981
997
|
}
|
|
982
|
-
function
|
|
983
|
-
|
|
984
|
-
|
|
998
|
+
function buildOrContextContinue(requestPlugins, runOnEndCallbacks, scheduleOnDisposeCallbacks) {
|
|
999
|
+
const writeDefault = streamIn.hasFS;
|
|
1000
|
+
const {
|
|
985
1001
|
entries,
|
|
986
1002
|
flags,
|
|
987
1003
|
write,
|
|
988
1004
|
stdinContents,
|
|
989
1005
|
stdinResolveDir,
|
|
990
1006
|
absWorkingDir,
|
|
991
|
-
incremental,
|
|
992
1007
|
nodePaths,
|
|
993
|
-
watch,
|
|
994
1008
|
mangleCache
|
|
995
1009
|
} = flagsForBuildOptions(callName, options, isTTY2, buildLogLevelDefault, writeDefault);
|
|
996
|
-
|
|
1010
|
+
if (write && !streamIn.hasFS)
|
|
1011
|
+
throw new Error(`The "write" option is unavailable in this environment`);
|
|
1012
|
+
const request = {
|
|
997
1013
|
command: "build",
|
|
998
1014
|
key: buildKey,
|
|
999
1015
|
entries,
|
|
@@ -1002,17 +1018,23 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
|
|
|
1002
1018
|
stdinContents,
|
|
1003
1019
|
stdinResolveDir,
|
|
1004
1020
|
absWorkingDir: absWorkingDir || defaultWD2,
|
|
1005
|
-
|
|
1006
|
-
|
|
1021
|
+
nodePaths,
|
|
1022
|
+
context: isContext
|
|
1007
1023
|
};
|
|
1008
1024
|
if (requestPlugins)
|
|
1009
1025
|
request.plugins = requestPlugins;
|
|
1010
1026
|
if (mangleCache)
|
|
1011
1027
|
request.mangleCache = mangleCache;
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1028
|
+
const buildResponseToResult = (response, callback2) => {
|
|
1029
|
+
const result = {
|
|
1030
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
1031
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
1032
|
+
outputFiles: void 0,
|
|
1033
|
+
metafile: void 0,
|
|
1034
|
+
mangleCache: void 0
|
|
1035
|
+
};
|
|
1036
|
+
const originalErrors = result.errors.slice();
|
|
1037
|
+
const originalWarnings = result.warnings.slice();
|
|
1016
1038
|
if (response.outputFiles)
|
|
1017
1039
|
result.outputFiles = response.outputFiles.map(convertOutputFiles);
|
|
1018
1040
|
if (response.metafile)
|
|
@@ -1021,170 +1043,163 @@ function buildOrServeImpl(callName, buildKey, sendRequest, sendResponse, refs, s
|
|
|
1021
1043
|
result.mangleCache = response.mangleCache;
|
|
1022
1044
|
if (response.writeToStdout !== void 0)
|
|
1023
1045
|
console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
warnings: replaceDetailsInMessages(response.warnings, details)
|
|
1029
|
-
};
|
|
1030
|
-
copyResponseToResult(response, result);
|
|
1031
|
-
runOnEndCallbacks(result, logPluginError, () => {
|
|
1032
|
-
if (result.errors.length > 0) {
|
|
1033
|
-
return callback2(failureErrorWithLog("Build failed", result.errors, result.warnings), null);
|
|
1046
|
+
runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
|
|
1047
|
+
if (originalErrors.length > 0 || onEndErrors.length > 0) {
|
|
1048
|
+
const error = failureErrorWithLog("Build failed", originalErrors.concat(onEndErrors), originalWarnings.concat(onEndWarnings));
|
|
1049
|
+
return callback2(error, null, onEndErrors, onEndWarnings);
|
|
1034
1050
|
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1051
|
+
callback2(null, result, onEndErrors, onEndWarnings);
|
|
1052
|
+
});
|
|
1053
|
+
};
|
|
1054
|
+
let latestResultPromise;
|
|
1055
|
+
let provideLatestResult;
|
|
1056
|
+
if (isContext)
|
|
1057
|
+
requestCallbacks["on-end"] = (id, request2) => new Promise((resolve) => {
|
|
1058
|
+
buildResponseToResult(request2, (err, result, onEndErrors, onEndWarnings) => {
|
|
1059
|
+
const response = {
|
|
1060
|
+
errors: onEndErrors,
|
|
1061
|
+
warnings: onEndWarnings
|
|
1062
|
+
};
|
|
1063
|
+
if (provideLatestResult)
|
|
1064
|
+
provideLatestResult(err, result);
|
|
1065
|
+
latestResultPromise = void 0;
|
|
1066
|
+
provideLatestResult = void 0;
|
|
1067
|
+
sendResponse(id, response);
|
|
1068
|
+
resolve();
|
|
1069
|
+
});
|
|
1070
|
+
});
|
|
1071
|
+
sendRequest(refs, request, (error, response) => {
|
|
1072
|
+
if (error)
|
|
1073
|
+
return callback(new Error(error), null);
|
|
1074
|
+
if (!isContext) {
|
|
1075
|
+
return buildResponseToResult(response, (err, res) => {
|
|
1076
|
+
scheduleOnDisposeCallbacks();
|
|
1077
|
+
return callback(err, res);
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
if (response.errors.length > 0) {
|
|
1081
|
+
return callback(failureErrorWithLog("Context failed", response.errors, response.warnings), null);
|
|
1082
|
+
}
|
|
1083
|
+
let didDispose = false;
|
|
1084
|
+
const result = {
|
|
1085
|
+
rebuild: () => {
|
|
1086
|
+
if (!latestResultPromise)
|
|
1087
|
+
latestResultPromise = new Promise((resolve, reject) => {
|
|
1088
|
+
let settlePromise;
|
|
1089
|
+
provideLatestResult = (err, result2) => {
|
|
1090
|
+
if (!settlePromise)
|
|
1091
|
+
settlePromise = () => err ? reject(err) : resolve(result2);
|
|
1092
|
+
};
|
|
1093
|
+
const triggerAnotherBuild = () => {
|
|
1094
|
+
const request2 = {
|
|
1095
|
+
command: "rebuild",
|
|
1096
|
+
key: buildKey
|
|
1097
|
+
};
|
|
1098
|
+
sendRequest(refs, request2, (error2, response2) => {
|
|
1045
1099
|
if (error2) {
|
|
1046
|
-
|
|
1047
|
-
|
|
1100
|
+
reject(new Error(error2));
|
|
1101
|
+
} else if (settlePromise) {
|
|
1102
|
+
settlePromise();
|
|
1103
|
+
} else {
|
|
1104
|
+
triggerAnotherBuild();
|
|
1048
1105
|
}
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
else
|
|
1053
|
-
resolve(result3);
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
);
|
|
1106
|
+
});
|
|
1107
|
+
};
|
|
1108
|
+
triggerAnotherBuild();
|
|
1057
1109
|
});
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1110
|
+
return latestResultPromise;
|
|
1111
|
+
},
|
|
1112
|
+
watch: (options2 = {}) => new Promise((resolve, reject) => {
|
|
1113
|
+
if (!streamIn.hasFS)
|
|
1114
|
+
throw new Error(`Cannot use the "watch" API in this environment`);
|
|
1115
|
+
const keys = {};
|
|
1116
|
+
checkForInvalidFlags(options2, keys, `in watch() call`);
|
|
1117
|
+
const request2 = {
|
|
1118
|
+
command: "watch",
|
|
1119
|
+
key: buildKey
|
|
1120
|
+
};
|
|
1121
|
+
sendRequest(refs, request2, (error2) => {
|
|
1122
|
+
if (error2)
|
|
1123
|
+
reject(new Error(error2));
|
|
1124
|
+
else
|
|
1125
|
+
resolve(void 0);
|
|
1126
|
+
});
|
|
1127
|
+
}),
|
|
1128
|
+
serve: (options2 = {}) => new Promise((resolve, reject) => {
|
|
1129
|
+
if (!streamIn.hasFS)
|
|
1130
|
+
throw new Error(`Cannot use the "serve" API in this environment`);
|
|
1131
|
+
const keys = {};
|
|
1132
|
+
const port = getFlag(options2, keys, "port", mustBeInteger);
|
|
1133
|
+
const host = getFlag(options2, keys, "host", mustBeString);
|
|
1134
|
+
const servedir = getFlag(options2, keys, "servedir", mustBeString);
|
|
1135
|
+
const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
|
|
1136
|
+
const certfile = getFlag(options2, keys, "certfile", mustBeString);
|
|
1137
|
+
const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
|
|
1138
|
+
checkForInvalidFlags(options2, keys, `in serve() call`);
|
|
1139
|
+
const request2 = {
|
|
1140
|
+
command: "serve",
|
|
1141
|
+
key: buildKey,
|
|
1142
|
+
onRequest: !!onRequest
|
|
1143
|
+
};
|
|
1144
|
+
if (port !== void 0)
|
|
1145
|
+
request2.port = port;
|
|
1146
|
+
if (host !== void 0)
|
|
1147
|
+
request2.host = host;
|
|
1148
|
+
if (servedir !== void 0)
|
|
1149
|
+
request2.servedir = servedir;
|
|
1150
|
+
if (keyfile !== void 0)
|
|
1151
|
+
request2.keyfile = keyfile;
|
|
1152
|
+
if (certfile !== void 0)
|
|
1153
|
+
request2.certfile = certfile;
|
|
1154
|
+
sendRequest(refs, request2, (error2, response2) => {
|
|
1155
|
+
if (error2)
|
|
1156
|
+
return reject(new Error(error2));
|
|
1157
|
+
if (onRequest) {
|
|
1158
|
+
requestCallbacks["serve-request"] = (id, request3) => {
|
|
1159
|
+
onRequest(request3.args);
|
|
1105
1160
|
sendResponse(id, {});
|
|
1106
1161
|
};
|
|
1107
1162
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
return;
|
|
1134
|
-
isStopped = true;
|
|
1135
|
-
serve2.stop();
|
|
1163
|
+
resolve(response2);
|
|
1164
|
+
});
|
|
1165
|
+
}),
|
|
1166
|
+
cancel: () => new Promise((resolve) => {
|
|
1167
|
+
if (didDispose)
|
|
1168
|
+
return resolve();
|
|
1169
|
+
const request2 = {
|
|
1170
|
+
command: "cancel",
|
|
1171
|
+
key: buildKey
|
|
1172
|
+
};
|
|
1173
|
+
sendRequest(refs, request2, () => {
|
|
1174
|
+
resolve();
|
|
1175
|
+
});
|
|
1176
|
+
}),
|
|
1177
|
+
dispose: () => new Promise((resolve) => {
|
|
1178
|
+
if (didDispose)
|
|
1179
|
+
return resolve();
|
|
1180
|
+
didDispose = true;
|
|
1181
|
+
const request2 = {
|
|
1182
|
+
command: "dispose",
|
|
1183
|
+
key: buildKey
|
|
1184
|
+
};
|
|
1185
|
+
sendRequest(refs, request2, () => {
|
|
1186
|
+
resolve();
|
|
1187
|
+
scheduleOnDisposeCallbacks();
|
|
1136
1188
|
refs.unref();
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
}
|
|
1143
|
-
return buildResponseToResult(response, callback);
|
|
1189
|
+
});
|
|
1190
|
+
})
|
|
1191
|
+
};
|
|
1192
|
+
refs.ref();
|
|
1193
|
+
callback(null, result);
|
|
1144
1194
|
});
|
|
1145
1195
|
}
|
|
1146
1196
|
}
|
|
1147
|
-
var buildServeData = (buildKey, sendRequest, sendResponse, refs, requestCallbacks, options, request) => {
|
|
1148
|
-
let keys = {};
|
|
1149
|
-
let port = getFlag(options, keys, "port", mustBeInteger);
|
|
1150
|
-
let host = getFlag(options, keys, "host", mustBeString);
|
|
1151
|
-
let servedir = getFlag(options, keys, "servedir", mustBeString);
|
|
1152
|
-
let onRequest = getFlag(options, keys, "onRequest", mustBeFunction);
|
|
1153
|
-
let wait = new Promise((resolve, reject) => {
|
|
1154
|
-
requestCallbacks["serve-wait"] = (id, request2) => {
|
|
1155
|
-
if (request2.error !== null)
|
|
1156
|
-
reject(new Error(request2.error));
|
|
1157
|
-
else
|
|
1158
|
-
resolve();
|
|
1159
|
-
sendResponse(id, {});
|
|
1160
|
-
};
|
|
1161
|
-
});
|
|
1162
|
-
request.serve = {};
|
|
1163
|
-
checkForInvalidFlags(options, keys, `in serve() call`);
|
|
1164
|
-
if (port !== void 0)
|
|
1165
|
-
request.serve.port = port;
|
|
1166
|
-
if (host !== void 0)
|
|
1167
|
-
request.serve.host = host;
|
|
1168
|
-
if (servedir !== void 0)
|
|
1169
|
-
request.serve.servedir = servedir;
|
|
1170
|
-
requestCallbacks["serve-request"] = (id, request2) => {
|
|
1171
|
-
if (onRequest)
|
|
1172
|
-
onRequest(request2.args);
|
|
1173
|
-
sendResponse(id, {});
|
|
1174
|
-
};
|
|
1175
|
-
return {
|
|
1176
|
-
wait,
|
|
1177
|
-
stop() {
|
|
1178
|
-
sendRequest(refs, { command: "serve-stop", key: buildKey }, () => {
|
|
1179
|
-
});
|
|
1180
|
-
}
|
|
1181
|
-
};
|
|
1182
|
-
};
|
|
1183
1197
|
var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, initialOptions, plugins, details) => {
|
|
1184
1198
|
let onStartCallbacks = [];
|
|
1185
1199
|
let onEndCallbacks = [];
|
|
1186
1200
|
let onResolveCallbacks = {};
|
|
1187
1201
|
let onLoadCallbacks = {};
|
|
1202
|
+
let onDisposeCallbacks = [];
|
|
1188
1203
|
let nextCallbackID = 0;
|
|
1189
1204
|
let i = 0;
|
|
1190
1205
|
let requestPlugins = [];
|
|
@@ -1201,9 +1216,11 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1201
1216
|
let setup = getFlag(item, keys, "setup", mustBeFunction);
|
|
1202
1217
|
if (typeof setup !== "function")
|
|
1203
1218
|
throw new Error(`Plugin is missing a setup function`);
|
|
1204
|
-
checkForInvalidFlags(item, keys, `on plugin ${
|
|
1219
|
+
checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
|
|
1205
1220
|
let plugin = {
|
|
1206
1221
|
name,
|
|
1222
|
+
onStart: false,
|
|
1223
|
+
onEnd: false,
|
|
1207
1224
|
onResolve: [],
|
|
1208
1225
|
onLoad: []
|
|
1209
1226
|
};
|
|
@@ -1238,6 +1255,8 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1238
1255
|
request.resolveDir = resolveDir;
|
|
1239
1256
|
if (kind != null)
|
|
1240
1257
|
request.kind = kind;
|
|
1258
|
+
else
|
|
1259
|
+
throw new Error(`Must specify "kind" when calling "resolve"`);
|
|
1241
1260
|
if (pluginData != null)
|
|
1242
1261
|
request.pluginData = details.store(pluginData);
|
|
1243
1262
|
sendRequest(refs, request, (error, response) => {
|
|
@@ -1264,11 +1283,13 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1264
1283
|
let registeredText = `This error came from the "onStart" callback registered here:`;
|
|
1265
1284
|
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
|
|
1266
1285
|
onStartCallbacks.push({ name, callback, note: registeredNote });
|
|
1286
|
+
plugin.onStart = true;
|
|
1267
1287
|
},
|
|
1268
1288
|
onEnd(callback) {
|
|
1269
1289
|
let registeredText = `This error came from the "onEnd" callback registered here:`;
|
|
1270
1290
|
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
|
|
1271
1291
|
onEndCallbacks.push({ name, callback, note: registeredNote });
|
|
1292
|
+
plugin.onEnd = true;
|
|
1272
1293
|
},
|
|
1273
1294
|
onResolve(options, callback) {
|
|
1274
1295
|
let registeredText = `This error came from the "onResolve" callback registered here:`;
|
|
@@ -1276,7 +1297,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1276
1297
|
let keys2 = {};
|
|
1277
1298
|
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
1278
1299
|
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
1279
|
-
checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${
|
|
1300
|
+
checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${quote(name)}`);
|
|
1280
1301
|
if (filter == null)
|
|
1281
1302
|
throw new Error(`onResolve() call is missing a filter`);
|
|
1282
1303
|
let id = nextCallbackID++;
|
|
@@ -1289,13 +1310,16 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1289
1310
|
let keys2 = {};
|
|
1290
1311
|
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
1291
1312
|
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
1292
|
-
checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${
|
|
1313
|
+
checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${quote(name)}`);
|
|
1293
1314
|
if (filter == null)
|
|
1294
1315
|
throw new Error(`onLoad() call is missing a filter`);
|
|
1295
1316
|
let id = nextCallbackID++;
|
|
1296
1317
|
onLoadCallbacks[id] = { name, callback, note: registeredNote };
|
|
1297
1318
|
plugin.onLoad.push({ id, filter: filter.source, namespace: namespace || "" });
|
|
1298
1319
|
},
|
|
1320
|
+
onDispose(callback) {
|
|
1321
|
+
onDisposeCallbacks.push(callback);
|
|
1322
|
+
},
|
|
1299
1323
|
esbuild: streamIn.esbuild
|
|
1300
1324
|
});
|
|
1301
1325
|
if (promise)
|
|
@@ -1312,11 +1336,11 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1312
1336
|
let result = await callback();
|
|
1313
1337
|
if (result != null) {
|
|
1314
1338
|
if (typeof result !== "object")
|
|
1315
|
-
throw new Error(`Expected onStart() callback in plugin ${
|
|
1339
|
+
throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
|
|
1316
1340
|
let keys = {};
|
|
1317
1341
|
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
1318
1342
|
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1319
|
-
checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${
|
|
1343
|
+
checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${quote(name)}`);
|
|
1320
1344
|
if (errors != null)
|
|
1321
1345
|
response.errors.push(...sanitizeMessages(errors, "errors", details, name));
|
|
1322
1346
|
if (warnings != null)
|
|
@@ -1343,7 +1367,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1343
1367
|
});
|
|
1344
1368
|
if (result != null) {
|
|
1345
1369
|
if (typeof result !== "object")
|
|
1346
|
-
throw new Error(`Expected onResolve() callback in plugin ${
|
|
1370
|
+
throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
|
|
1347
1371
|
let keys = {};
|
|
1348
1372
|
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
1349
1373
|
let path3 = getFlag(result, keys, "path", mustBeString);
|
|
@@ -1356,7 +1380,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1356
1380
|
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1357
1381
|
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
|
|
1358
1382
|
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
|
|
1359
|
-
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${
|
|
1383
|
+
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
|
|
1360
1384
|
response.id = id2;
|
|
1361
1385
|
if (pluginName != null)
|
|
1362
1386
|
response.pluginName = pluginName;
|
|
@@ -1402,7 +1426,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1402
1426
|
});
|
|
1403
1427
|
if (result != null) {
|
|
1404
1428
|
if (typeof result !== "object")
|
|
1405
|
-
throw new Error(`Expected onLoad() callback in plugin ${
|
|
1429
|
+
throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
|
|
1406
1430
|
let keys = {};
|
|
1407
1431
|
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
1408
1432
|
let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
|
|
@@ -1413,7 +1437,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1413
1437
|
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1414
1438
|
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
|
|
1415
1439
|
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
|
|
1416
|
-
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${
|
|
1440
|
+
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
|
|
1417
1441
|
response.id = id2;
|
|
1418
1442
|
if (pluginName != null)
|
|
1419
1443
|
response.pluginName = pluginName;
|
|
@@ -1444,25 +1468,62 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
|
|
1444
1468
|
}
|
|
1445
1469
|
sendResponse(id, response);
|
|
1446
1470
|
};
|
|
1447
|
-
let runOnEndCallbacks = (result,
|
|
1471
|
+
let runOnEndCallbacks = (result, done) => done([], []);
|
|
1448
1472
|
if (onEndCallbacks.length > 0) {
|
|
1449
|
-
runOnEndCallbacks = (result,
|
|
1473
|
+
runOnEndCallbacks = (result, done) => {
|
|
1450
1474
|
(async () => {
|
|
1475
|
+
const onEndErrors = [];
|
|
1476
|
+
const onEndWarnings = [];
|
|
1451
1477
|
for (const { name, callback, note } of onEndCallbacks) {
|
|
1478
|
+
let newErrors;
|
|
1479
|
+
let newWarnings;
|
|
1452
1480
|
try {
|
|
1453
|
-
await callback(result);
|
|
1481
|
+
const value = await callback(result);
|
|
1482
|
+
if (value != null) {
|
|
1483
|
+
if (typeof value !== "object")
|
|
1484
|
+
throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
|
|
1485
|
+
let keys = {};
|
|
1486
|
+
let errors = getFlag(value, keys, "errors", mustBeArray);
|
|
1487
|
+
let warnings = getFlag(value, keys, "warnings", mustBeArray);
|
|
1488
|
+
checkForInvalidFlags(value, keys, `from onEnd() callback in plugin ${quote(name)}`);
|
|
1489
|
+
if (errors != null)
|
|
1490
|
+
newErrors = sanitizeMessages(errors, "errors", details, name);
|
|
1491
|
+
if (warnings != null)
|
|
1492
|
+
newWarnings = sanitizeMessages(warnings, "warnings", details, name);
|
|
1493
|
+
}
|
|
1454
1494
|
} catch (e) {
|
|
1455
|
-
|
|
1495
|
+
newErrors = [extractErrorMessageV8(e, streamIn, details, note && note(), name)];
|
|
1496
|
+
}
|
|
1497
|
+
if (newErrors) {
|
|
1498
|
+
onEndErrors.push(...newErrors);
|
|
1499
|
+
try {
|
|
1500
|
+
result.errors.push(...newErrors);
|
|
1501
|
+
} catch {
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
if (newWarnings) {
|
|
1505
|
+
onEndWarnings.push(...newWarnings);
|
|
1506
|
+
try {
|
|
1507
|
+
result.warnings.push(...newWarnings);
|
|
1508
|
+
} catch {
|
|
1509
|
+
}
|
|
1456
1510
|
}
|
|
1457
1511
|
}
|
|
1458
|
-
|
|
1512
|
+
done(onEndErrors, onEndWarnings);
|
|
1513
|
+
})();
|
|
1459
1514
|
};
|
|
1460
1515
|
}
|
|
1516
|
+
let scheduleOnDisposeCallbacks = () => {
|
|
1517
|
+
for (const cb of onDisposeCallbacks) {
|
|
1518
|
+
setTimeout(() => cb(), 0);
|
|
1519
|
+
}
|
|
1520
|
+
};
|
|
1461
1521
|
isSetupDone = true;
|
|
1462
1522
|
return {
|
|
1463
1523
|
ok: true,
|
|
1464
1524
|
requestPlugins,
|
|
1465
|
-
runOnEndCallbacks
|
|
1525
|
+
runOnEndCallbacks,
|
|
1526
|
+
scheduleOnDisposeCallbacks
|
|
1466
1527
|
};
|
|
1467
1528
|
};
|
|
1468
1529
|
function createObjectStash() {
|
|
@@ -1647,7 +1708,7 @@ function sanitizeStringArray(values, property) {
|
|
|
1647
1708
|
const result = [];
|
|
1648
1709
|
for (const value of values) {
|
|
1649
1710
|
if (typeof value !== "string")
|
|
1650
|
-
throw new Error(`${
|
|
1711
|
+
throw new Error(`${quote(property)} must be an array of strings`);
|
|
1651
1712
|
result.push(value);
|
|
1652
1713
|
}
|
|
1653
1714
|
return result;
|
|
@@ -1673,35 +1734,35 @@ var fs = require("fs");
|
|
|
1673
1734
|
var os = require("os");
|
|
1674
1735
|
var path = require("path");
|
|
1675
1736
|
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
|
1676
|
-
var packageDarwin_arm64 = "esbuild
|
|
1677
|
-
var packageDarwin_x64 = "esbuild
|
|
1737
|
+
var packageDarwin_arm64 = "@esbuild/darwin-arm64";
|
|
1738
|
+
var packageDarwin_x64 = "@esbuild/darwin-x64";
|
|
1678
1739
|
var knownWindowsPackages = {
|
|
1679
|
-
"win32 arm64 LE": "esbuild-
|
|
1680
|
-
"win32 ia32 LE": "esbuild-
|
|
1681
|
-
"win32 x64 LE": "esbuild-
|
|
1740
|
+
"win32 arm64 LE": "@esbuild/win32-arm64",
|
|
1741
|
+
"win32 ia32 LE": "@esbuild/win32-ia32",
|
|
1742
|
+
"win32 x64 LE": "@esbuild/win32-x64"
|
|
1682
1743
|
};
|
|
1683
1744
|
var knownUnixlikePackages = {
|
|
1684
|
-
"android arm64 LE": "esbuild
|
|
1685
|
-
"darwin arm64 LE": "esbuild
|
|
1686
|
-
"darwin x64 LE": "esbuild
|
|
1687
|
-
"freebsd arm64 LE": "esbuild
|
|
1688
|
-
"freebsd x64 LE": "esbuild
|
|
1689
|
-
"linux arm LE": "esbuild
|
|
1690
|
-
"linux arm64 LE": "esbuild
|
|
1691
|
-
"linux ia32 LE": "esbuild
|
|
1692
|
-
"linux mips64el LE": "esbuild
|
|
1693
|
-
"linux ppc64 LE": "esbuild
|
|
1694
|
-
"linux riscv64 LE": "esbuild
|
|
1695
|
-
"linux s390x BE": "esbuild
|
|
1696
|
-
"linux x64 LE": "esbuild
|
|
1745
|
+
"android arm64 LE": "@esbuild/android-arm64",
|
|
1746
|
+
"darwin arm64 LE": "@esbuild/darwin-arm64",
|
|
1747
|
+
"darwin x64 LE": "@esbuild/darwin-x64",
|
|
1748
|
+
"freebsd arm64 LE": "@esbuild/freebsd-arm64",
|
|
1749
|
+
"freebsd x64 LE": "@esbuild/freebsd-x64",
|
|
1750
|
+
"linux arm LE": "@esbuild/linux-arm",
|
|
1751
|
+
"linux arm64 LE": "@esbuild/linux-arm64",
|
|
1752
|
+
"linux ia32 LE": "@esbuild/linux-ia32",
|
|
1753
|
+
"linux mips64el LE": "@esbuild/linux-mips64el",
|
|
1754
|
+
"linux ppc64 LE": "@esbuild/linux-ppc64",
|
|
1755
|
+
"linux riscv64 LE": "@esbuild/linux-riscv64",
|
|
1756
|
+
"linux s390x BE": "@esbuild/linux-s390x",
|
|
1757
|
+
"linux x64 LE": "@esbuild/linux-x64",
|
|
1697
1758
|
"linux loong64 LE": "@esbuild/linux-loong64",
|
|
1698
|
-
"netbsd x64 LE": "esbuild
|
|
1699
|
-
"openbsd x64 LE": "esbuild
|
|
1700
|
-
"sunos x64 LE": "esbuild
|
|
1759
|
+
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
|
1760
|
+
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
|
1761
|
+
"sunos x64 LE": "@esbuild/sunos-x64"
|
|
1701
1762
|
};
|
|
1702
1763
|
var knownWebAssemblyFallbackPackages = {
|
|
1703
1764
|
"android arm LE": "@esbuild/android-arm",
|
|
1704
|
-
"android x64 LE": "esbuild
|
|
1765
|
+
"android x64 LE": "@esbuild/android-x64"
|
|
1705
1766
|
};
|
|
1706
1767
|
function pkgAndSubpathForCurrentPlatform() {
|
|
1707
1768
|
let pkg;
|
|
@@ -1748,11 +1809,15 @@ function pkgForSomeOtherPlatform() {
|
|
|
1748
1809
|
}
|
|
1749
1810
|
function downloadedBinPath(pkg, subpath) {
|
|
1750
1811
|
const esbuildLibDir = path.dirname(require.resolve("esbuild"));
|
|
1751
|
-
return path.join(esbuildLibDir, `downloaded-${pkg}-${path.basename(subpath)}`);
|
|
1812
|
+
return path.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
|
1752
1813
|
}
|
|
1753
1814
|
function generateBinPath() {
|
|
1754
1815
|
if (ESBUILD_BINARY_PATH) {
|
|
1755
|
-
|
|
1816
|
+
if (!fs.existsSync(ESBUILD_BINARY_PATH)) {
|
|
1817
|
+
console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
|
|
1818
|
+
} else {
|
|
1819
|
+
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
|
|
1820
|
+
}
|
|
1756
1821
|
}
|
|
1757
1822
|
const { pkg, subpath, isWASM } = pkgAndSubpathForCurrentPlatform();
|
|
1758
1823
|
let binPath;
|
|
@@ -1839,7 +1904,7 @@ for your current platform.`);
|
|
|
1839
1904
|
"node_modules",
|
|
1840
1905
|
".cache",
|
|
1841
1906
|
"esbuild",
|
|
1842
|
-
`pnpapi-${pkg}-${"0.
|
|
1907
|
+
`pnpapi-${pkg.replace("/", "-")}-${"0.17.2"}-${path.basename(subpath)}`
|
|
1843
1908
|
);
|
|
1844
1909
|
if (!fs.existsSync(binTargetPath)) {
|
|
1845
1910
|
fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
|
|
@@ -1866,12 +1931,15 @@ if (process.env.ESBUILD_WORKER_THREADS !== "0") {
|
|
|
1866
1931
|
} catch {
|
|
1867
1932
|
}
|
|
1868
1933
|
let [major, minor] = process.versions.node.split(".");
|
|
1869
|
-
if (
|
|
1934
|
+
if (
|
|
1935
|
+
// <v12.17.0 does not work
|
|
1936
|
+
+major < 12 || +major === 12 && +minor < 17 || +major === 13 && +minor < 13
|
|
1937
|
+
) {
|
|
1870
1938
|
worker_threads = void 0;
|
|
1871
1939
|
}
|
|
1872
1940
|
}
|
|
1873
1941
|
var _a;
|
|
1874
|
-
var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.
|
|
1942
|
+
var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.17.2";
|
|
1875
1943
|
var esbuildCommandAndArgs = () => {
|
|
1876
1944
|
if ((!ESBUILD_BINARY_PATH || false) && (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib")) {
|
|
1877
1945
|
throw new Error(
|
|
@@ -1938,9 +2006,9 @@ var fsAsync = {
|
|
|
1938
2006
|
}
|
|
1939
2007
|
}
|
|
1940
2008
|
};
|
|
1941
|
-
var version = "0.
|
|
2009
|
+
var version = "0.17.2";
|
|
1942
2010
|
var build = (options) => ensureServiceIsRunning().build(options);
|
|
1943
|
-
var
|
|
2011
|
+
var context = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
|
|
1944
2012
|
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
|
1945
2013
|
var formatMessages = (messages, options) => ensureServiceIsRunning().formatMessages(messages, options);
|
|
1946
2014
|
var analyzeMetafile = (messages, options) => ensureServiceIsRunning().analyzeMetafile(messages, options);
|
|
@@ -1951,10 +2019,9 @@ var buildSync = (options) => {
|
|
|
1951
2019
|
return workerThreadService.buildSync(options);
|
|
1952
2020
|
}
|
|
1953
2021
|
let result;
|
|
1954
|
-
runServiceSync((service) => service.
|
|
2022
|
+
runServiceSync((service) => service.buildOrContext({
|
|
1955
2023
|
callName: "buildSync",
|
|
1956
2024
|
refs: null,
|
|
1957
|
-
serveOptions: null,
|
|
1958
2025
|
options,
|
|
1959
2026
|
isTTY: isTTY(),
|
|
1960
2027
|
defaultWD,
|
|
@@ -2049,7 +2116,7 @@ var ensureServiceIsRunning = () => {
|
|
|
2049
2116
|
if (longLivedService)
|
|
2050
2117
|
return longLivedService;
|
|
2051
2118
|
let [command, args] = esbuildCommandAndArgs();
|
|
2052
|
-
let child = child_process.spawn(command, args.concat(`--service=${"0.
|
|
2119
|
+
let child = child_process.spawn(command, args.concat(`--service=${"0.17.2"}`, "--ping"), {
|
|
2053
2120
|
windowsHide: true,
|
|
2054
2121
|
stdio: ["pipe", "pipe", "inherit"],
|
|
2055
2122
|
cwd: defaultWD
|
|
@@ -2063,7 +2130,7 @@ var ensureServiceIsRunning = () => {
|
|
|
2063
2130
|
},
|
|
2064
2131
|
readFileSync: fs2.readFileSync,
|
|
2065
2132
|
isSync: false,
|
|
2066
|
-
|
|
2133
|
+
hasFS: true,
|
|
2067
2134
|
esbuild: node_exports
|
|
2068
2135
|
});
|
|
2069
2136
|
child.stdin.on("error", afterClose);
|
|
@@ -2091,61 +2158,47 @@ var ensureServiceIsRunning = () => {
|
|
|
2091
2158
|
}
|
|
2092
2159
|
};
|
|
2093
2160
|
longLivedService = {
|
|
2094
|
-
build: (options) => {
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
callName: "build",
|
|
2098
|
-
refs,
|
|
2099
|
-
serveOptions: null,
|
|
2100
|
-
options,
|
|
2101
|
-
isTTY: isTTY(),
|
|
2102
|
-
defaultWD,
|
|
2103
|
-
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2104
|
-
});
|
|
2105
|
-
});
|
|
2106
|
-
},
|
|
2107
|
-
serve: (serveOptions, buildOptions) => {
|
|
2108
|
-
if (serveOptions === null || typeof serveOptions !== "object")
|
|
2109
|
-
throw new Error("The first argument must be an object");
|
|
2110
|
-
return new Promise((resolve, reject) => service.buildOrServe({
|
|
2111
|
-
callName: "serve",
|
|
2161
|
+
build: (options) => new Promise((resolve, reject) => {
|
|
2162
|
+
service.buildOrContext({
|
|
2163
|
+
callName: "build",
|
|
2112
2164
|
refs,
|
|
2113
|
-
|
|
2114
|
-
options: buildOptions,
|
|
2165
|
+
options,
|
|
2115
2166
|
isTTY: isTTY(),
|
|
2116
2167
|
defaultWD,
|
|
2117
2168
|
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2118
|
-
})
|
|
2119
|
-
},
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2169
|
+
});
|
|
2170
|
+
}),
|
|
2171
|
+
context: (options) => new Promise((resolve, reject) => service.buildOrContext({
|
|
2172
|
+
callName: "context",
|
|
2173
|
+
refs,
|
|
2174
|
+
options,
|
|
2175
|
+
isTTY: isTTY(),
|
|
2176
|
+
defaultWD,
|
|
2177
|
+
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2178
|
+
})),
|
|
2179
|
+
transform: (input, options) => new Promise((resolve, reject) => service.transform({
|
|
2180
|
+
callName: "transform",
|
|
2181
|
+
refs,
|
|
2182
|
+
input,
|
|
2183
|
+
options: options || {},
|
|
2184
|
+
isTTY: isTTY(),
|
|
2185
|
+
fs: fsAsync,
|
|
2186
|
+
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2187
|
+
})),
|
|
2188
|
+
formatMessages: (messages, options) => new Promise((resolve, reject) => service.formatMessages({
|
|
2189
|
+
callName: "formatMessages",
|
|
2190
|
+
refs,
|
|
2191
|
+
messages,
|
|
2192
|
+
options,
|
|
2193
|
+
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2194
|
+
})),
|
|
2195
|
+
analyzeMetafile: (metafile, options) => new Promise((resolve, reject) => service.analyzeMetafile({
|
|
2196
|
+
callName: "analyzeMetafile",
|
|
2197
|
+
refs,
|
|
2198
|
+
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
|
2199
|
+
options,
|
|
2200
|
+
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2201
|
+
}))
|
|
2149
2202
|
};
|
|
2150
2203
|
return longLivedService;
|
|
2151
2204
|
};
|
|
@@ -2159,14 +2212,18 @@ var runServiceSync = (callback) => {
|
|
|
2159
2212
|
stdin = bytes;
|
|
2160
2213
|
},
|
|
2161
2214
|
isSync: true,
|
|
2162
|
-
|
|
2215
|
+
hasFS: true,
|
|
2163
2216
|
esbuild: node_exports
|
|
2164
2217
|
});
|
|
2165
2218
|
callback(service);
|
|
2166
|
-
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.
|
|
2219
|
+
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.17.2"}`), {
|
|
2167
2220
|
cwd: defaultWD,
|
|
2168
2221
|
windowsHide: true,
|
|
2169
2222
|
input: stdin,
|
|
2223
|
+
// We don't know how large the output could be. If it's too large, the
|
|
2224
|
+
// command will fail with ENOBUFS. Reserve 16mb for now since that feels
|
|
2225
|
+
// like it should be enough. Also allow overriding this with an environment
|
|
2226
|
+
// variable.
|
|
2170
2227
|
maxBuffer: +process.env.ESBUILD_MAX_BUFFER || 16 * 1024 * 1024
|
|
2171
2228
|
});
|
|
2172
2229
|
readFromStdout(stdout);
|
|
@@ -2179,8 +2236,17 @@ var workerThreadService = null;
|
|
|
2179
2236
|
var startWorkerThreadService = (worker_threads2) => {
|
|
2180
2237
|
let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel();
|
|
2181
2238
|
let worker = new worker_threads2.Worker(__filename, {
|
|
2182
|
-
workerData: { workerPort, defaultWD, esbuildVersion: "0.
|
|
2239
|
+
workerData: { workerPort, defaultWD, esbuildVersion: "0.17.2" },
|
|
2183
2240
|
transferList: [workerPort],
|
|
2241
|
+
// From node's documentation: https://nodejs.org/api/worker_threads.html
|
|
2242
|
+
//
|
|
2243
|
+
// Take care when launching worker threads from preload scripts (scripts loaded
|
|
2244
|
+
// and run using the `-r` command line flag). Unless the `execArgv` option is
|
|
2245
|
+
// explicitly set, new Worker threads automatically inherit the command line flags
|
|
2246
|
+
// from the running process and will preload the same preload scripts as the main
|
|
2247
|
+
// thread. If the preload script unconditionally launches a worker thread, every
|
|
2248
|
+
// thread spawned will spawn another until the application crashes.
|
|
2249
|
+
//
|
|
2184
2250
|
execArgv: []
|
|
2185
2251
|
});
|
|
2186
2252
|
let nextID = 0;
|
|
@@ -2196,14 +2262,8 @@ error: ${text}`);
|
|
|
2196
2262
|
if (!options)
|
|
2197
2263
|
return;
|
|
2198
2264
|
let plugins = options.plugins;
|
|
2199
|
-
let incremental = options.incremental;
|
|
2200
|
-
let watch = options.watch;
|
|
2201
2265
|
if (plugins && plugins.length > 0)
|
|
2202
2266
|
throw fakeBuildError(`Cannot use plugins in synchronous API calls`);
|
|
2203
|
-
if (incremental)
|
|
2204
|
-
throw fakeBuildError(`Cannot use "incremental" with a synchronous build`);
|
|
2205
|
-
if (watch)
|
|
2206
|
-
throw fakeBuildError(`Cannot use "watch" with a synchronous build`);
|
|
2207
2267
|
};
|
|
2208
2268
|
let applyProperties = (object, properties) => {
|
|
2209
2269
|
for (let key in properties) {
|
|
@@ -2308,10 +2368,10 @@ var node_default = node_exports;
|
|
|
2308
2368
|
analyzeMetafileSync,
|
|
2309
2369
|
build,
|
|
2310
2370
|
buildSync,
|
|
2371
|
+
context,
|
|
2311
2372
|
formatMessages,
|
|
2312
2373
|
formatMessagesSync,
|
|
2313
2374
|
initialize,
|
|
2314
|
-
serve,
|
|
2315
2375
|
transform,
|
|
2316
2376
|
transformSync,
|
|
2317
2377
|
version
|