esbuild 0.9.3 → 0.9.7
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/install.js +21 -4
- package/lib/main.d.ts +2 -0
- package/lib/main.js +188 -49
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
var
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
6
|
+
var __assign = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
2
17
|
const fs = require("fs");
|
|
3
18
|
const os = require("os");
|
|
4
19
|
const path = require("path");
|
|
5
20
|
const zlib = require("zlib");
|
|
6
21
|
const https = require("https");
|
|
7
22
|
const child_process = require("child_process");
|
|
8
|
-
const version = "0.9.
|
|
23
|
+
const version = "0.9.7";
|
|
9
24
|
const binPath = path.join(__dirname, "bin", "esbuild");
|
|
10
25
|
async function installBinaryFromPackage(name, fromPath, toPath) {
|
|
11
26
|
const cachePath = getCachePath(name);
|
|
@@ -175,7 +190,8 @@ function installDirectly(name) {
|
|
|
175
190
|
fs.copyFileSync(process.env.ESBUILD_BINARY_PATH, binPath);
|
|
176
191
|
validateBinaryVersion(binPath);
|
|
177
192
|
} else {
|
|
178
|
-
|
|
193
|
+
const tempBinPath = binPath + "__";
|
|
194
|
+
installBinaryFromPackage(name, "bin/esbuild", tempBinPath).then(() => fs.renameSync(tempBinPath, binPath)).catch((e) => setImmediate(() => {
|
|
179
195
|
throw e;
|
|
180
196
|
}));
|
|
181
197
|
}
|
|
@@ -214,8 +230,9 @@ const knownWindowsPackages = {
|
|
|
214
230
|
"win32 x64 LE": "esbuild-windows-64"
|
|
215
231
|
};
|
|
216
232
|
const knownUnixlikePackages = {
|
|
217
|
-
"
|
|
233
|
+
"android arm64 LE": "esbuild-android-arm64",
|
|
218
234
|
"darwin arm64 LE": "esbuild-darwin-arm64",
|
|
235
|
+
"darwin x64 LE": "esbuild-darwin-64",
|
|
219
236
|
"freebsd arm64 LE": "esbuild-freebsd-arm64",
|
|
220
237
|
"freebsd x64 LE": "esbuild-freebsd-64",
|
|
221
238
|
"linux arm LE": "esbuild-linux-arm",
|
package/lib/main.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export interface BuildOptions extends CommonOptions {
|
|
|
49
49
|
tsconfig?: string;
|
|
50
50
|
outExtension?: { [ext: string]: string };
|
|
51
51
|
publicPath?: string;
|
|
52
|
+
entryNames?: string;
|
|
52
53
|
chunkNames?: string;
|
|
53
54
|
assetNames?: string;
|
|
54
55
|
inject?: string[];
|
|
@@ -181,6 +182,7 @@ export interface Plugin {
|
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
export interface PluginBuild {
|
|
185
|
+
initialOptions: BuildOptions;
|
|
184
186
|
onResolve(options: OnResolveOptions, callback: (args: OnResolveArgs) =>
|
|
185
187
|
(OnResolveResult | null | undefined | Promise<OnResolveResult | null | undefined>)): void;
|
|
186
188
|
onLoad(options: OnLoadOptions, callback: (args: OnLoadArgs) =>
|
package/lib/main.js
CHANGED
|
@@ -322,6 +322,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
322
322
|
let loader = getFlag(options, keys, "loader", mustBeObject);
|
|
323
323
|
let outExtension = getFlag(options, keys, "outExtension", mustBeObject);
|
|
324
324
|
let publicPath = getFlag(options, keys, "publicPath", mustBeString);
|
|
325
|
+
let entryNames = getFlag(options, keys, "entryNames", mustBeString);
|
|
325
326
|
let chunkNames = getFlag(options, keys, "chunkNames", mustBeString);
|
|
326
327
|
let assetNames = getFlag(options, keys, "assetNames", mustBeString);
|
|
327
328
|
let inject = getFlag(options, keys, "inject", mustBeArray);
|
|
@@ -332,7 +333,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
332
333
|
let stdin = getFlag(options, keys, "stdin", mustBeObject);
|
|
333
334
|
let write = (_a = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a : writeDefault;
|
|
334
335
|
let incremental = getFlag(options, keys, "incremental", mustBeBoolean) === true;
|
|
335
|
-
|
|
336
|
+
keys.plugins = true;
|
|
336
337
|
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
337
338
|
if (sourcemap)
|
|
338
339
|
flags.push(`--sourcemap${sourcemap === true ? "" : `=${sourcemap}`}`);
|
|
@@ -377,6 +378,8 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
377
378
|
}
|
|
378
379
|
if (publicPath)
|
|
379
380
|
flags.push(`--public-path=${publicPath}`);
|
|
381
|
+
if (entryNames)
|
|
382
|
+
flags.push(`--entry-names=${entryNames}`);
|
|
380
383
|
if (chunkNames)
|
|
381
384
|
flags.push(`--chunk-names=${chunkNames}`);
|
|
382
385
|
if (assetNames)
|
|
@@ -468,7 +471,6 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
|
|
468
471
|
return {
|
|
469
472
|
flags,
|
|
470
473
|
write,
|
|
471
|
-
plugins,
|
|
472
474
|
stdinContents,
|
|
473
475
|
stdinResolveDir,
|
|
474
476
|
absWorkingDir,
|
|
@@ -638,8 +640,8 @@ function createChannel(streamIn) {
|
|
|
638
640
|
if (isFirstPacket) {
|
|
639
641
|
isFirstPacket = false;
|
|
640
642
|
let binaryVersion = String.fromCharCode(...bytes);
|
|
641
|
-
if (binaryVersion !== "0.9.
|
|
642
|
-
throw new Error(`Cannot start service: Host version "${"0.9.
|
|
643
|
+
if (binaryVersion !== "0.9.7") {
|
|
644
|
+
throw new Error(`Cannot start service: Host version "${"0.9.7"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
|
|
643
645
|
}
|
|
644
646
|
return;
|
|
645
647
|
}
|
|
@@ -655,14 +657,15 @@ function createChannel(streamIn) {
|
|
|
655
657
|
callback(null, packet.value);
|
|
656
658
|
}
|
|
657
659
|
};
|
|
658
|
-
let handlePlugins = (
|
|
660
|
+
let handlePlugins = (initialOptions, plugins, buildKey, stash) => {
|
|
659
661
|
if (streamIn.isSync)
|
|
660
662
|
throw new Error("Cannot use plugins in synchronous API calls");
|
|
661
663
|
let onResolveCallbacks = {};
|
|
662
664
|
let onLoadCallbacks = {};
|
|
663
665
|
let nextCallbackID = 0;
|
|
664
666
|
let i = 0;
|
|
665
|
-
|
|
667
|
+
let requestPlugins = [];
|
|
668
|
+
plugins = [...plugins];
|
|
666
669
|
for (let item of plugins) {
|
|
667
670
|
let keys = {};
|
|
668
671
|
if (typeof item !== "object")
|
|
@@ -681,6 +684,7 @@ function createChannel(streamIn) {
|
|
|
681
684
|
};
|
|
682
685
|
i++;
|
|
683
686
|
setup({
|
|
687
|
+
initialOptions,
|
|
684
688
|
onResolve(options, callback2) {
|
|
685
689
|
let registeredText = `This error came from the "onResolve" callback registered here`;
|
|
686
690
|
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve");
|
|
@@ -708,22 +712,22 @@ function createChannel(streamIn) {
|
|
|
708
712
|
plugin.onLoad.push({id, filter: filter.source, namespace: namespace || ""});
|
|
709
713
|
}
|
|
710
714
|
});
|
|
711
|
-
|
|
715
|
+
requestPlugins.push(plugin);
|
|
712
716
|
}
|
|
713
|
-
const callback = async (
|
|
714
|
-
switch (
|
|
717
|
+
const callback = async (request) => {
|
|
718
|
+
switch (request.command) {
|
|
715
719
|
case "resolve": {
|
|
716
720
|
let response = {}, name, callback2, note;
|
|
717
|
-
for (let id of
|
|
721
|
+
for (let id of request.ids) {
|
|
718
722
|
try {
|
|
719
723
|
({name, callback: callback2, note} = onResolveCallbacks[id]);
|
|
720
724
|
let result = await callback2({
|
|
721
|
-
path:
|
|
722
|
-
importer:
|
|
723
|
-
namespace:
|
|
724
|
-
resolveDir:
|
|
725
|
-
kind:
|
|
726
|
-
pluginData: stash.load(
|
|
725
|
+
path: request.path,
|
|
726
|
+
importer: request.importer,
|
|
727
|
+
namespace: request.namespace,
|
|
728
|
+
resolveDir: request.resolveDir,
|
|
729
|
+
kind: request.kind,
|
|
730
|
+
pluginData: stash.load(request.pluginData)
|
|
727
731
|
});
|
|
728
732
|
if (result != null) {
|
|
729
733
|
if (typeof result !== "object")
|
|
@@ -755,20 +759,20 @@ function createChannel(streamIn) {
|
|
|
755
759
|
break;
|
|
756
760
|
}
|
|
757
761
|
} catch (e) {
|
|
758
|
-
return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note)]};
|
|
762
|
+
return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note && note())]};
|
|
759
763
|
}
|
|
760
764
|
}
|
|
761
765
|
return response;
|
|
762
766
|
}
|
|
763
767
|
case "load": {
|
|
764
768
|
let response = {}, name, callback2, note;
|
|
765
|
-
for (let id of
|
|
769
|
+
for (let id of request.ids) {
|
|
766
770
|
try {
|
|
767
771
|
({name, callback: callback2, note} = onLoadCallbacks[id]);
|
|
768
772
|
let result = await callback2({
|
|
769
|
-
path:
|
|
770
|
-
namespace:
|
|
771
|
-
pluginData: stash.load(
|
|
773
|
+
path: request.path,
|
|
774
|
+
namespace: request.namespace,
|
|
775
|
+
pluginData: stash.load(request.pluginData)
|
|
772
776
|
});
|
|
773
777
|
if (result != null) {
|
|
774
778
|
if (typeof result !== "object")
|
|
@@ -802,17 +806,17 @@ function createChannel(streamIn) {
|
|
|
802
806
|
break;
|
|
803
807
|
}
|
|
804
808
|
} catch (e) {
|
|
805
|
-
return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note)]};
|
|
809
|
+
return {id, errors: [extractErrorMessageV8(e, streamIn, stash, note && note())]};
|
|
806
810
|
}
|
|
807
811
|
}
|
|
808
812
|
return response;
|
|
809
813
|
}
|
|
810
814
|
default:
|
|
811
|
-
throw new Error(`Invalid command: ` +
|
|
815
|
+
throw new Error(`Invalid command: ` + request.command);
|
|
812
816
|
}
|
|
813
817
|
};
|
|
814
818
|
let refCount = 0;
|
|
815
|
-
return {
|
|
819
|
+
return [requestPlugins, {
|
|
816
820
|
ref() {
|
|
817
821
|
if (++refCount === 1)
|
|
818
822
|
pluginCallbacks.set(buildKey, callback);
|
|
@@ -821,7 +825,7 @@ function createChannel(streamIn) {
|
|
|
821
825
|
if (--refCount === 0)
|
|
822
826
|
pluginCallbacks.delete(buildKey);
|
|
823
827
|
}
|
|
824
|
-
};
|
|
828
|
+
}];
|
|
825
829
|
};
|
|
826
830
|
let buildServeData = (refs, options, request) => {
|
|
827
831
|
let keys = {};
|
|
@@ -885,10 +889,22 @@ function createChannel(streamIn) {
|
|
|
885
889
|
try {
|
|
886
890
|
let key = nextBuildKey++;
|
|
887
891
|
let writeDefault = !streamIn.isBrowser;
|
|
892
|
+
let plugins;
|
|
893
|
+
let requestPlugins;
|
|
894
|
+
if (typeof options === "object") {
|
|
895
|
+
let value = options.plugins;
|
|
896
|
+
if (value !== void 0) {
|
|
897
|
+
if (!Array.isArray(value))
|
|
898
|
+
throw new Error(`"plugins" must be an array`);
|
|
899
|
+
plugins = value;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
if (plugins && plugins.length > 0) {
|
|
903
|
+
[requestPlugins, pluginRefs] = handlePlugins(options, plugins, key, details);
|
|
904
|
+
}
|
|
888
905
|
let {
|
|
889
906
|
flags,
|
|
890
907
|
write,
|
|
891
|
-
plugins,
|
|
892
908
|
stdinContents,
|
|
893
909
|
stdinResolveDir,
|
|
894
910
|
absWorkingDir,
|
|
@@ -908,9 +924,9 @@ function createChannel(streamIn) {
|
|
|
908
924
|
nodePaths,
|
|
909
925
|
hasOnRebuild: !!(watch && watch.onRebuild)
|
|
910
926
|
};
|
|
927
|
+
if (requestPlugins)
|
|
928
|
+
request.plugins = requestPlugins;
|
|
911
929
|
let serve2 = serveOptions && buildServeData(refs, serveOptions, request);
|
|
912
|
-
if (plugins && plugins.length > 0)
|
|
913
|
-
pluginRefs = handlePlugins(plugins, request, key, details);
|
|
914
930
|
let rebuild;
|
|
915
931
|
let stop;
|
|
916
932
|
let buildResponseToResult = (response, callback2) => {
|
|
@@ -1117,15 +1133,23 @@ function createObjectStash() {
|
|
|
1117
1133
|
};
|
|
1118
1134
|
}
|
|
1119
1135
|
function extractCallerV8(e, streamIn, ident) {
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1136
|
+
let note;
|
|
1137
|
+
let tried = false;
|
|
1138
|
+
return () => {
|
|
1139
|
+
if (tried)
|
|
1140
|
+
return note;
|
|
1141
|
+
tried = true;
|
|
1142
|
+
try {
|
|
1143
|
+
let lines = (e.stack + "").split("\n");
|
|
1144
|
+
lines.splice(1, 1);
|
|
1145
|
+
let location = parseStackLinesV8(streamIn, lines, ident);
|
|
1146
|
+
if (location) {
|
|
1147
|
+
note = {text: e.message, location};
|
|
1148
|
+
return note;
|
|
1149
|
+
}
|
|
1150
|
+
} catch (e2) {
|
|
1126
1151
|
}
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1152
|
+
};
|
|
1129
1153
|
}
|
|
1130
1154
|
function extractErrorMessageV8(e, streamIn, stash, note) {
|
|
1131
1155
|
let text = "Internal error";
|
|
@@ -1161,7 +1185,12 @@ function parseStackLinesV8(streamIn, lines, ident) {
|
|
|
1161
1185
|
}
|
|
1162
1186
|
match = /^(\S+):(\d+):(\d+)$/.exec(line);
|
|
1163
1187
|
if (match) {
|
|
1164
|
-
let contents
|
|
1188
|
+
let contents;
|
|
1189
|
+
try {
|
|
1190
|
+
contents = streamIn.readFileSync(match[1], "utf8");
|
|
1191
|
+
} catch (e) {
|
|
1192
|
+
break;
|
|
1193
|
+
}
|
|
1165
1194
|
let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || "";
|
|
1166
1195
|
let column = +match[3] - 1;
|
|
1167
1196
|
let length = lineText.slice(column, column + ident.length) === ident ? ident.length : 0;
|
|
@@ -1277,6 +1306,13 @@ var path = require("path");
|
|
|
1277
1306
|
var fs = require("fs");
|
|
1278
1307
|
var os = require("os");
|
|
1279
1308
|
var tty = require("tty");
|
|
1309
|
+
var worker_threads;
|
|
1310
|
+
if (process.env.ESBUILD_WORKER_THREADS) {
|
|
1311
|
+
try {
|
|
1312
|
+
worker_threads = require("worker_threads");
|
|
1313
|
+
} catch (e) {
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1280
1316
|
var esbuildCommandAndArgs = () => {
|
|
1281
1317
|
if (process.env.ESBUILD_BINARY_PATH) {
|
|
1282
1318
|
return [path.resolve(process.env.ESBUILD_BINARY_PATH), []];
|
|
@@ -1294,13 +1330,18 @@ var esbuildCommandAndArgs = () => {
|
|
|
1294
1330
|
return [path.join(__dirname, "..", "bin", "esbuild"), []];
|
|
1295
1331
|
};
|
|
1296
1332
|
var isTTY = () => tty.isatty(2);
|
|
1297
|
-
var version = "0.9.
|
|
1333
|
+
var version = "0.9.7";
|
|
1298
1334
|
var build = (options) => ensureServiceIsRunning().build(options);
|
|
1299
1335
|
var serve = (serveOptions, buildOptions) => ensureServiceIsRunning().serve(serveOptions, buildOptions);
|
|
1300
1336
|
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
|
1301
1337
|
var buildSync = (options) => {
|
|
1338
|
+
if (worker_threads) {
|
|
1339
|
+
if (!workerThreadService)
|
|
1340
|
+
workerThreadService = startWorkerThreadService(worker_threads);
|
|
1341
|
+
return workerThreadService.buildSync(options);
|
|
1342
|
+
}
|
|
1302
1343
|
let result;
|
|
1303
|
-
runServiceSync((service) => service.buildOrServe("buildSync", null, null, options, isTTY(),
|
|
1344
|
+
runServiceSync((service) => service.buildOrServe("buildSync", null, null, options, isTTY(), defaultWD, (err, res) => {
|
|
1304
1345
|
if (err)
|
|
1305
1346
|
throw err;
|
|
1306
1347
|
result = res;
|
|
@@ -1308,6 +1349,11 @@ var buildSync = (options) => {
|
|
|
1308
1349
|
return result;
|
|
1309
1350
|
};
|
|
1310
1351
|
var transformSync = (input, options) => {
|
|
1352
|
+
if (worker_threads) {
|
|
1353
|
+
if (!workerThreadService)
|
|
1354
|
+
workerThreadService = startWorkerThreadService(worker_threads);
|
|
1355
|
+
return workerThreadService.transformSync(input, options);
|
|
1356
|
+
}
|
|
1311
1357
|
let result;
|
|
1312
1358
|
runServiceSync((service) => service.transform("transformSync", null, input, options || {}, isTTY(), {
|
|
1313
1359
|
readFile(tempFile, callback) {
|
|
@@ -1347,21 +1393,20 @@ var initialize = (options) => {
|
|
|
1347
1393
|
throw new Error(`The "worker" option only works in the browser`);
|
|
1348
1394
|
if (initializeWasCalled)
|
|
1349
1395
|
throw new Error('Cannot call "initialize" more than once');
|
|
1396
|
+
ensureServiceIsRunning();
|
|
1350
1397
|
initializeWasCalled = true;
|
|
1351
1398
|
return Promise.resolve();
|
|
1352
1399
|
};
|
|
1353
1400
|
var defaultWD = process.cwd();
|
|
1354
1401
|
var longLivedService;
|
|
1355
1402
|
var ensureServiceIsRunning = () => {
|
|
1356
|
-
if (
|
|
1357
|
-
longLivedService
|
|
1358
|
-
return longLivedService;
|
|
1359
|
-
};
|
|
1360
|
-
var startRunningService = () => {
|
|
1403
|
+
if (longLivedService)
|
|
1404
|
+
return longLivedService;
|
|
1361
1405
|
let [command, args] = esbuildCommandAndArgs();
|
|
1362
|
-
let child = child_process.spawn(command, args.concat(`--service=${"0.9.
|
|
1406
|
+
let child = child_process.spawn(command, args.concat(`--service=${"0.9.7"}`, "--ping"), {
|
|
1363
1407
|
windowsHide: true,
|
|
1364
|
-
stdio: ["pipe", "pipe", "inherit"]
|
|
1408
|
+
stdio: ["pipe", "pipe", "inherit"],
|
|
1409
|
+
cwd: defaultWD
|
|
1365
1410
|
});
|
|
1366
1411
|
let {readFromStdout, afterClose, service} = createChannel({
|
|
1367
1412
|
writeToStdin(bytes) {
|
|
@@ -1393,7 +1438,7 @@ var startRunningService = () => {
|
|
|
1393
1438
|
child.unref();
|
|
1394
1439
|
}
|
|
1395
1440
|
};
|
|
1396
|
-
|
|
1441
|
+
longLivedService = {
|
|
1397
1442
|
build: (options) => {
|
|
1398
1443
|
return new Promise((resolve, reject) => {
|
|
1399
1444
|
service.buildOrServe("build", refs, null, options, isTTY(), defaultWD, (err, res) => {
|
|
@@ -1442,6 +1487,7 @@ var startRunningService = () => {
|
|
|
1442
1487
|
}, (err, res) => err ? reject(err) : resolve(res)));
|
|
1443
1488
|
}
|
|
1444
1489
|
};
|
|
1490
|
+
return longLivedService;
|
|
1445
1491
|
};
|
|
1446
1492
|
var runServiceSync = (callback) => {
|
|
1447
1493
|
let [command, args] = esbuildCommandAndArgs();
|
|
@@ -1456,8 +1502,8 @@ var runServiceSync = (callback) => {
|
|
|
1456
1502
|
isBrowser: false
|
|
1457
1503
|
});
|
|
1458
1504
|
callback(service);
|
|
1459
|
-
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.9.
|
|
1460
|
-
cwd:
|
|
1505
|
+
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.9.7"}`), {
|
|
1506
|
+
cwd: defaultWD,
|
|
1461
1507
|
windowsHide: true,
|
|
1462
1508
|
input: stdin,
|
|
1463
1509
|
maxBuffer: +process.env.ESBUILD_MAX_BUFFER || 16 * 1024 * 1024
|
|
@@ -1468,6 +1514,99 @@ var runServiceSync = (callback) => {
|
|
|
1468
1514
|
var randomFileName = () => {
|
|
1469
1515
|
return path.join(os.tmpdir(), `esbuild-${crypto.randomBytes(32).toString("hex")}`);
|
|
1470
1516
|
};
|
|
1517
|
+
var workerThreadService = null;
|
|
1518
|
+
var startWorkerThreadService = (worker_threads2) => {
|
|
1519
|
+
let {port1: mainPort, port2: workerPort} = new worker_threads2.MessageChannel();
|
|
1520
|
+
let worker = new worker_threads2.Worker(__filename, {
|
|
1521
|
+
workerData: {workerPort, defaultWD},
|
|
1522
|
+
transferList: [workerPort],
|
|
1523
|
+
execArgv: []
|
|
1524
|
+
});
|
|
1525
|
+
let nextID = 0;
|
|
1526
|
+
let wasStopped = false;
|
|
1527
|
+
let validateBuildSyncOptions = (options) => {
|
|
1528
|
+
if (!options)
|
|
1529
|
+
return;
|
|
1530
|
+
let plugins = options.plugins;
|
|
1531
|
+
let incremental = options.incremental;
|
|
1532
|
+
if (plugins && plugins.length > 0)
|
|
1533
|
+
throw new Error(`Cannot use plugins in synchronous API calls`);
|
|
1534
|
+
if (incremental)
|
|
1535
|
+
throw new Error(`Cannot use "incremental" with a synchronous build`);
|
|
1536
|
+
};
|
|
1537
|
+
let applyProperties = (object, properties) => {
|
|
1538
|
+
for (let key in properties) {
|
|
1539
|
+
object[key] = properties[key];
|
|
1540
|
+
}
|
|
1541
|
+
};
|
|
1542
|
+
let runCallSync = (command, args) => {
|
|
1543
|
+
if (wasStopped)
|
|
1544
|
+
throw new Error("The service was stopped");
|
|
1545
|
+
let id = nextID++;
|
|
1546
|
+
let sharedBuffer = new SharedArrayBuffer(8);
|
|
1547
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
1548
|
+
let msg = {sharedBuffer, id, command, args};
|
|
1549
|
+
worker.postMessage(msg);
|
|
1550
|
+
let status = Atomics.wait(sharedBufferView, 0, 0);
|
|
1551
|
+
if (status !== "ok" && status !== "not-equal")
|
|
1552
|
+
throw new Error("Internal error: Atomics.wait() failed: " + status);
|
|
1553
|
+
let {message: {id: id2, resolve, reject, properties}} = worker_threads2.receiveMessageOnPort(mainPort);
|
|
1554
|
+
if (id !== id2)
|
|
1555
|
+
throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
|
1556
|
+
if (reject) {
|
|
1557
|
+
applyProperties(reject, properties);
|
|
1558
|
+
throw reject;
|
|
1559
|
+
}
|
|
1560
|
+
return resolve;
|
|
1561
|
+
};
|
|
1562
|
+
worker.unref();
|
|
1563
|
+
return {
|
|
1564
|
+
buildSync(options) {
|
|
1565
|
+
validateBuildSyncOptions(options);
|
|
1566
|
+
return runCallSync("build", [options]);
|
|
1567
|
+
},
|
|
1568
|
+
transformSync(input, options) {
|
|
1569
|
+
return runCallSync("transform", [input, options]);
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
};
|
|
1573
|
+
var startSyncServiceWorker = () => {
|
|
1574
|
+
let workerPort = worker_threads.workerData.workerPort;
|
|
1575
|
+
let parentPort = worker_threads.parentPort;
|
|
1576
|
+
let service = ensureServiceIsRunning();
|
|
1577
|
+
defaultWD = worker_threads.workerData.defaultWD;
|
|
1578
|
+
let extractProperties = (object) => {
|
|
1579
|
+
let properties = {};
|
|
1580
|
+
if (object && typeof object === "object") {
|
|
1581
|
+
for (let key in object) {
|
|
1582
|
+
properties[key] = object[key];
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
return properties;
|
|
1586
|
+
};
|
|
1587
|
+
parentPort.on("message", (msg) => {
|
|
1588
|
+
(async () => {
|
|
1589
|
+
let {sharedBuffer, id, command, args} = msg;
|
|
1590
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
1591
|
+
try {
|
|
1592
|
+
if (command === "build") {
|
|
1593
|
+
workerPort.postMessage({id, resolve: await service.build(args[0])});
|
|
1594
|
+
} else if (command === "transform") {
|
|
1595
|
+
workerPort.postMessage({id, resolve: await service.transform(args[0], args[1])});
|
|
1596
|
+
} else {
|
|
1597
|
+
throw new Error(`Invalid command: ${command}`);
|
|
1598
|
+
}
|
|
1599
|
+
} catch (reject) {
|
|
1600
|
+
workerPort.postMessage({id, reject, properties: extractProperties(reject)});
|
|
1601
|
+
}
|
|
1602
|
+
Atomics.add(sharedBufferView, 0, 1);
|
|
1603
|
+
Atomics.notify(sharedBufferView, 0, Infinity);
|
|
1604
|
+
})();
|
|
1605
|
+
});
|
|
1606
|
+
};
|
|
1607
|
+
if (worker_threads && !worker_threads.isMainThread) {
|
|
1608
|
+
startSyncServiceWorker();
|
|
1609
|
+
}
|
|
1471
1610
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1472
1611
|
0 && (module.exports = {
|
|
1473
1612
|
build,
|