bakit 2.0.0-alpha.18 → 2.0.0-alpha.19
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/dist/index.js +2 -3
- package/dist/loader/hooks.js +2 -1563
- package/dist/loader/register.js +1 -3
- package/package.json +1 -1
package/dist/loader/hooks.js
CHANGED
|
@@ -4,1571 +4,10 @@ import { Module } from 'module';
|
|
|
4
4
|
import { dirname, resolve as resolve$1, basename } from 'path';
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __require = /* @__PURE__ */ ((x) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(x, {
|
|
13
|
-
get: (a, b) => (typeof require < "u" ? require : a)[b]
|
|
14
|
-
}) : x)(function(x) {
|
|
15
|
-
if (typeof require < "u") return require.apply(this, arguments);
|
|
16
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
17
|
-
});
|
|
18
|
-
var __commonJS = (cb, mod) => function() {
|
|
19
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
20
|
-
};
|
|
21
|
-
var __copyProps = (to, from, except, desc) => {
|
|
22
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
23
|
-
for (let key of __getOwnPropNames(from))
|
|
24
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
28
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
32
|
-
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
33
|
-
mod
|
|
34
|
-
));
|
|
35
|
-
|
|
36
|
-
// ../../node_modules/.pnpm/esbuild@0.27.1/node_modules/esbuild/lib/main.js
|
|
37
|
-
var require_main = __commonJS({
|
|
38
|
-
"../../node_modules/.pnpm/esbuild@0.27.1/node_modules/esbuild/lib/main.js"(exports, module) {
|
|
39
|
-
var __defProp2 = Object.defineProperty, __getOwnPropDesc2 = Object.getOwnPropertyDescriptor, __getOwnPropNames2 = Object.getOwnPropertyNames, __hasOwnProp2 = Object.prototype.hasOwnProperty, __export = (target, all) => {
|
|
40
|
-
for (var name in all)
|
|
41
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
42
|
-
}, __copyProps2 = (to, from, except, desc) => {
|
|
43
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
44
|
-
for (let key of __getOwnPropNames2(from))
|
|
45
|
-
!__hasOwnProp2.call(to, key) && key !== except && __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
46
|
-
return to;
|
|
47
|
-
}, __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod), node_exports = {};
|
|
48
|
-
__export(node_exports, {
|
|
49
|
-
analyzeMetafile: () => analyzeMetafile,
|
|
50
|
-
analyzeMetafileSync: () => analyzeMetafileSync,
|
|
51
|
-
build: () => build,
|
|
52
|
-
buildSync: () => buildSync,
|
|
53
|
-
context: () => context,
|
|
54
|
-
default: () => node_default,
|
|
55
|
-
formatMessages: () => formatMessages,
|
|
56
|
-
formatMessagesSync: () => formatMessagesSync,
|
|
57
|
-
initialize: () => initialize2,
|
|
58
|
-
stop: () => stop,
|
|
59
|
-
transform: () => transform,
|
|
60
|
-
transformSync: () => transformSync,
|
|
61
|
-
version: () => version
|
|
62
|
-
});
|
|
63
|
-
module.exports = __toCommonJS(node_exports);
|
|
64
|
-
function encodePacket(packet) {
|
|
65
|
-
let visit = (value) => {
|
|
66
|
-
if (value === null)
|
|
67
|
-
bb.write8(0);
|
|
68
|
-
else if (typeof value == "boolean")
|
|
69
|
-
bb.write8(1), bb.write8(+value);
|
|
70
|
-
else if (typeof value == "number")
|
|
71
|
-
bb.write8(2), bb.write32(value | 0);
|
|
72
|
-
else if (typeof value == "string")
|
|
73
|
-
bb.write8(3), bb.write(encodeUTF8(value));
|
|
74
|
-
else if (value instanceof Uint8Array)
|
|
75
|
-
bb.write8(4), bb.write(value);
|
|
76
|
-
else if (value instanceof Array) {
|
|
77
|
-
bb.write8(5), bb.write32(value.length);
|
|
78
|
-
for (let item of value)
|
|
79
|
-
visit(item);
|
|
80
|
-
} else {
|
|
81
|
-
let keys = Object.keys(value);
|
|
82
|
-
bb.write8(6), bb.write32(keys.length);
|
|
83
|
-
for (let key of keys)
|
|
84
|
-
bb.write(encodeUTF8(key)), visit(value[key]);
|
|
85
|
-
}
|
|
86
|
-
}, bb = new ByteBuffer();
|
|
87
|
-
return bb.write32(0), bb.write32(packet.id << 1 | +!packet.isRequest), visit(packet.value), writeUInt32LE(bb.buf, bb.len - 4, 0), bb.buf.subarray(0, bb.len);
|
|
88
|
-
}
|
|
89
|
-
function decodePacket(bytes) {
|
|
90
|
-
let visit = () => {
|
|
91
|
-
switch (bb.read8()) {
|
|
92
|
-
case 0:
|
|
93
|
-
return null;
|
|
94
|
-
case 1:
|
|
95
|
-
return !!bb.read8();
|
|
96
|
-
case 2:
|
|
97
|
-
return bb.read32();
|
|
98
|
-
case 3:
|
|
99
|
-
return decodeUTF8(bb.read());
|
|
100
|
-
case 4:
|
|
101
|
-
return bb.read();
|
|
102
|
-
case 5: {
|
|
103
|
-
let count = bb.read32(), value2 = [];
|
|
104
|
-
for (let i = 0; i < count; i++)
|
|
105
|
-
value2.push(visit());
|
|
106
|
-
return value2;
|
|
107
|
-
}
|
|
108
|
-
case 6: {
|
|
109
|
-
let count = bb.read32(), value2 = {};
|
|
110
|
-
for (let i = 0; i < count; i++)
|
|
111
|
-
value2[decodeUTF8(bb.read())] = visit();
|
|
112
|
-
return value2;
|
|
113
|
-
}
|
|
114
|
-
default:
|
|
115
|
-
throw new Error("Invalid packet");
|
|
116
|
-
}
|
|
117
|
-
}, bb = new ByteBuffer(bytes), id = bb.read32(), isRequest = (id & 1) === 0;
|
|
118
|
-
id >>>= 1;
|
|
119
|
-
let value = visit();
|
|
120
|
-
if (bb.ptr !== bytes.length)
|
|
121
|
-
throw new Error("Invalid packet");
|
|
122
|
-
return { id, isRequest, value };
|
|
123
|
-
}
|
|
124
|
-
var ByteBuffer = class {
|
|
125
|
-
constructor(buf = new Uint8Array(1024)) {
|
|
126
|
-
this.buf = buf, this.len = 0, this.ptr = 0;
|
|
127
|
-
}
|
|
128
|
-
_write(delta) {
|
|
129
|
-
if (this.len + delta > this.buf.length) {
|
|
130
|
-
let clone = new Uint8Array((this.len + delta) * 2);
|
|
131
|
-
clone.set(this.buf), this.buf = clone;
|
|
132
|
-
}
|
|
133
|
-
return this.len += delta, this.len - delta;
|
|
134
|
-
}
|
|
135
|
-
write8(value) {
|
|
136
|
-
let offset = this._write(1);
|
|
137
|
-
this.buf[offset] = value;
|
|
138
|
-
}
|
|
139
|
-
write32(value) {
|
|
140
|
-
let offset = this._write(4);
|
|
141
|
-
writeUInt32LE(this.buf, value, offset);
|
|
142
|
-
}
|
|
143
|
-
write(bytes) {
|
|
144
|
-
let offset = this._write(4 + bytes.length);
|
|
145
|
-
writeUInt32LE(this.buf, bytes.length, offset), this.buf.set(bytes, offset + 4);
|
|
146
|
-
}
|
|
147
|
-
_read(delta) {
|
|
148
|
-
if (this.ptr + delta > this.buf.length)
|
|
149
|
-
throw new Error("Invalid packet");
|
|
150
|
-
return this.ptr += delta, this.ptr - delta;
|
|
151
|
-
}
|
|
152
|
-
read8() {
|
|
153
|
-
return this.buf[this._read(1)];
|
|
154
|
-
}
|
|
155
|
-
read32() {
|
|
156
|
-
return readUInt32LE(this.buf, this._read(4));
|
|
157
|
-
}
|
|
158
|
-
read() {
|
|
159
|
-
let length = this.read32(), bytes = new Uint8Array(length), ptr = this._read(bytes.length);
|
|
160
|
-
return bytes.set(this.buf.subarray(ptr, ptr + length)), bytes;
|
|
161
|
-
}
|
|
162
|
-
}, encodeUTF8, decodeUTF8, encodeInvariant;
|
|
163
|
-
if (typeof TextEncoder < "u" && typeof TextDecoder < "u") {
|
|
164
|
-
let encoder = new TextEncoder(), decoder = new TextDecoder();
|
|
165
|
-
encodeUTF8 = (text) => encoder.encode(text), decodeUTF8 = (bytes) => decoder.decode(bytes), encodeInvariant = 'new TextEncoder().encode("")';
|
|
166
|
-
} else if (typeof Buffer < "u")
|
|
167
|
-
encodeUTF8 = (text) => Buffer.from(text), decodeUTF8 = (bytes) => {
|
|
168
|
-
let { buffer, byteOffset, byteLength } = bytes;
|
|
169
|
-
return Buffer.from(buffer, byteOffset, byteLength).toString();
|
|
170
|
-
}, encodeInvariant = 'Buffer.from("")';
|
|
171
|
-
else
|
|
172
|
-
throw new Error("No UTF-8 codec found");
|
|
173
|
-
if (!(encodeUTF8("") instanceof Uint8Array))
|
|
174
|
-
throw new Error(`Invariant violation: "${encodeInvariant} instanceof Uint8Array" is incorrectly false
|
|
175
|
-
|
|
176
|
-
This indicates that your JavaScript environment is broken. You cannot use
|
|
177
|
-
esbuild in this environment because esbuild relies on this invariant. This
|
|
178
|
-
is not a problem with esbuild. You need to fix your environment instead.
|
|
179
|
-
`);
|
|
180
|
-
function readUInt32LE(buffer, offset) {
|
|
181
|
-
return buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24;
|
|
182
|
-
}
|
|
183
|
-
function writeUInt32LE(buffer, value, offset) {
|
|
184
|
-
buffer[offset++] = value, buffer[offset++] = value >> 8, buffer[offset++] = value >> 16, buffer[offset++] = value >> 24;
|
|
185
|
-
}
|
|
186
|
-
var quote = JSON.stringify, buildLogLevelDefault = "warning", transformLogLevelDefault = "silent";
|
|
187
|
-
function validateAndJoinStringArray(values, what) {
|
|
188
|
-
let toJoin = [];
|
|
189
|
-
for (let value of values) {
|
|
190
|
-
if (validateStringValue(value, what), value.indexOf(",") >= 0) throw new Error(`Invalid ${what}: ${value}`);
|
|
191
|
-
toJoin.push(value);
|
|
192
|
-
}
|
|
193
|
-
return toJoin.join(",");
|
|
194
|
-
}
|
|
195
|
-
var canBeAnything = () => null, mustBeBoolean = (value) => typeof value == "boolean" ? null : "a boolean", mustBeString = (value) => typeof value == "string" ? null : "a string", mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object", mustBeInteger = (value) => typeof value == "number" && value === (value | 0) ? null : "an integer", mustBeValidPortNumber = (value) => typeof value == "number" && value === (value | 0) && value >= 0 && value <= 65535 ? null : "a valid port number", mustBeFunction = (value) => typeof value == "function" ? null : "a function", mustBeArray = (value) => Array.isArray(value) ? null : "an array", mustBeArrayOfStrings = (value) => Array.isArray(value) && value.every((x) => typeof x == "string") ? null : "an array of strings", mustBeObject = (value) => typeof value == "object" && value !== null && !Array.isArray(value) ? null : "an object", mustBeEntryPoints = (value) => typeof value == "object" && value !== null ? null : "an array or an object", mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module", mustBeObjectOrNull = (value) => typeof value == "object" && !Array.isArray(value) ? null : "an object or null", mustBeStringOrBoolean = (value) => typeof value == "string" || typeof value == "boolean" ? null : "a string or a boolean", mustBeStringOrObject = (value) => typeof value == "string" || typeof value == "object" && value !== null && !Array.isArray(value) ? null : "a string or an object", mustBeStringOrArrayOfStrings = (value) => typeof value == "string" || Array.isArray(value) && value.every((x) => typeof x == "string") ? null : "a string or an array of strings", mustBeStringOrUint8Array = (value) => typeof value == "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array", mustBeStringOrURL = (value) => typeof value == "string" || value instanceof URL ? null : "a string or a URL";
|
|
196
|
-
function getFlag(object, keys, key, mustBeFn) {
|
|
197
|
-
let value = object[key];
|
|
198
|
-
if (keys[key + ""] = true, value === void 0) return;
|
|
199
|
-
let mustBe = mustBeFn(value);
|
|
200
|
-
if (mustBe !== null) throw new Error(`${quote(key)} must be ${mustBe}`);
|
|
201
|
-
return value;
|
|
202
|
-
}
|
|
203
|
-
function checkForInvalidFlags(object, keys, where) {
|
|
204
|
-
for (let key in object)
|
|
205
|
-
if (!(key in keys))
|
|
206
|
-
throw new Error(`Invalid option ${where}: ${quote(key)}`);
|
|
207
|
-
}
|
|
208
|
-
function validateInitializeOptions(options) {
|
|
209
|
-
let keys = /* @__PURE__ */ Object.create(null), wasmURL = getFlag(options, keys, "wasmURL", mustBeStringOrURL), wasmModule = getFlag(options, keys, "wasmModule", mustBeWebAssemblyModule), worker = getFlag(options, keys, "worker", mustBeBoolean);
|
|
210
|
-
return checkForInvalidFlags(options, keys, "in initialize() call"), {
|
|
211
|
-
wasmURL,
|
|
212
|
-
wasmModule,
|
|
213
|
-
worker
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
function validateMangleCache(mangleCache) {
|
|
217
|
-
let validated;
|
|
218
|
-
if (mangleCache !== void 0) {
|
|
219
|
-
validated = /* @__PURE__ */ Object.create(null);
|
|
220
|
-
for (let key in mangleCache) {
|
|
221
|
-
let value = mangleCache[key];
|
|
222
|
-
if (typeof value == "string" || value === false)
|
|
223
|
-
validated[key] = value;
|
|
224
|
-
else
|
|
225
|
-
throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return validated;
|
|
229
|
-
}
|
|
230
|
-
function pushLogFlags(flags, options, keys, isTTY2, logLevelDefault) {
|
|
231
|
-
let color = getFlag(options, keys, "color", mustBeBoolean), logLevel = getFlag(options, keys, "logLevel", mustBeString), logLimit = getFlag(options, keys, "logLimit", mustBeInteger);
|
|
232
|
-
color !== void 0 ? flags.push(`--color=${color}`) : isTTY2 && flags.push("--color=true"), flags.push(`--log-level=${logLevel || logLevelDefault}`), flags.push(`--log-limit=${logLimit || 0}`);
|
|
233
|
-
}
|
|
234
|
-
function validateStringValue(value, what, key) {
|
|
235
|
-
if (typeof value != "string")
|
|
236
|
-
throw new Error(`Expected value for ${what}${key !== void 0 ? " " + quote(key) : ""} to be a string, got ${typeof value} instead`);
|
|
237
|
-
return value;
|
|
238
|
-
}
|
|
239
|
-
function pushCommonFlags(flags, options, keys) {
|
|
240
|
-
let legalComments = getFlag(options, keys, "legalComments", mustBeString), sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString), sourcesContent = getFlag(options, keys, "sourcesContent", mustBeBoolean), target = getFlag(options, keys, "target", mustBeStringOrArrayOfStrings), format = getFlag(options, keys, "format", mustBeString), globalName = getFlag(options, keys, "globalName", mustBeString), mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp), reserveProps = getFlag(options, keys, "reserveProps", mustBeRegExp), mangleQuoted = getFlag(options, keys, "mangleQuoted", mustBeBoolean), minify = getFlag(options, keys, "minify", mustBeBoolean), minifySyntax = getFlag(options, keys, "minifySyntax", mustBeBoolean), minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean), minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean), lineLimit = getFlag(options, keys, "lineLimit", mustBeInteger), drop = getFlag(options, keys, "drop", mustBeArrayOfStrings), dropLabels = getFlag(options, keys, "dropLabels", mustBeArrayOfStrings), charset = getFlag(options, keys, "charset", mustBeString), treeShaking = getFlag(options, keys, "treeShaking", mustBeBoolean), ignoreAnnotations = getFlag(options, keys, "ignoreAnnotations", mustBeBoolean), jsx = getFlag(options, keys, "jsx", mustBeString), jsxFactory = getFlag(options, keys, "jsxFactory", mustBeString), jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString), jsxImportSource = getFlag(options, keys, "jsxImportSource", mustBeString), jsxDev = getFlag(options, keys, "jsxDev", mustBeBoolean), jsxSideEffects = getFlag(options, keys, "jsxSideEffects", mustBeBoolean), define = getFlag(options, keys, "define", mustBeObject), logOverride = getFlag(options, keys, "logOverride", mustBeObject), supported = getFlag(options, keys, "supported", mustBeObject), pure = getFlag(options, keys, "pure", mustBeArrayOfStrings), keepNames = getFlag(options, keys, "keepNames", mustBeBoolean), platform = getFlag(options, keys, "platform", mustBeString), tsconfigRaw = getFlag(options, keys, "tsconfigRaw", mustBeStringOrObject), absPaths = getFlag(options, keys, "absPaths", mustBeArrayOfStrings);
|
|
241
|
-
if (legalComments && flags.push(`--legal-comments=${legalComments}`), sourceRoot !== void 0 && flags.push(`--source-root=${sourceRoot}`), sourcesContent !== void 0 && flags.push(`--sources-content=${sourcesContent}`), target && flags.push(`--target=${validateAndJoinStringArray(Array.isArray(target) ? target : [target], "target")}`), format && flags.push(`--format=${format}`), globalName && flags.push(`--global-name=${globalName}`), platform && flags.push(`--platform=${platform}`), tsconfigRaw && flags.push(`--tsconfig-raw=${typeof tsconfigRaw == "string" ? tsconfigRaw : JSON.stringify(tsconfigRaw)}`), minify && flags.push("--minify"), minifySyntax && flags.push("--minify-syntax"), minifyWhitespace && flags.push("--minify-whitespace"), minifyIdentifiers && flags.push("--minify-identifiers"), lineLimit && flags.push(`--line-limit=${lineLimit}`), charset && flags.push(`--charset=${charset}`), treeShaking !== void 0 && flags.push(`--tree-shaking=${treeShaking}`), ignoreAnnotations && flags.push("--ignore-annotations"), drop) for (let what of drop) flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
|
242
|
-
if (dropLabels && flags.push(`--drop-labels=${validateAndJoinStringArray(dropLabels, "drop label")}`), absPaths && flags.push(`--abs-paths=${validateAndJoinStringArray(absPaths, "abs paths")}`), mangleProps && flags.push(`--mangle-props=${jsRegExpToGoRegExp(mangleProps)}`), reserveProps && flags.push(`--reserve-props=${jsRegExpToGoRegExp(reserveProps)}`), mangleQuoted !== void 0 && flags.push(`--mangle-quoted=${mangleQuoted}`), jsx && flags.push(`--jsx=${jsx}`), jsxFactory && flags.push(`--jsx-factory=${jsxFactory}`), jsxFragment && flags.push(`--jsx-fragment=${jsxFragment}`), jsxImportSource && flags.push(`--jsx-import-source=${jsxImportSource}`), jsxDev && flags.push("--jsx-dev"), jsxSideEffects && flags.push("--jsx-side-effects"), define)
|
|
243
|
-
for (let key in define) {
|
|
244
|
-
if (key.indexOf("=") >= 0) throw new Error(`Invalid define: ${key}`);
|
|
245
|
-
flags.push(`--define:${key}=${validateStringValue(define[key], "define", key)}`);
|
|
246
|
-
}
|
|
247
|
-
if (logOverride)
|
|
248
|
-
for (let key in logOverride) {
|
|
249
|
-
if (key.indexOf("=") >= 0) throw new Error(`Invalid log override: ${key}`);
|
|
250
|
-
flags.push(`--log-override:${key}=${validateStringValue(logOverride[key], "log override", key)}`);
|
|
251
|
-
}
|
|
252
|
-
if (supported)
|
|
253
|
-
for (let key in supported) {
|
|
254
|
-
if (key.indexOf("=") >= 0) throw new Error(`Invalid supported: ${key}`);
|
|
255
|
-
let value = supported[key];
|
|
256
|
-
if (typeof value != "boolean") throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
|
|
257
|
-
flags.push(`--supported:${key}=${value}`);
|
|
258
|
-
}
|
|
259
|
-
if (pure) for (let fn of pure) flags.push(`--pure:${validateStringValue(fn, "pure")}`);
|
|
260
|
-
keepNames && flags.push("--keep-names");
|
|
261
|
-
}
|
|
262
|
-
function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeDefault) {
|
|
263
|
-
var _a2;
|
|
264
|
-
let flags = [], entries = [], keys = /* @__PURE__ */ Object.create(null), stdinContents = null, stdinResolveDir = null;
|
|
265
|
-
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault), pushCommonFlags(flags, options, keys);
|
|
266
|
-
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean), bundle = getFlag(options, keys, "bundle", mustBeBoolean), splitting = getFlag(options, keys, "splitting", mustBeBoolean), preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean), metafile = getFlag(options, keys, "metafile", mustBeBoolean), outfile = getFlag(options, keys, "outfile", mustBeString), outdir = getFlag(options, keys, "outdir", mustBeString), outbase = getFlag(options, keys, "outbase", mustBeString), tsconfig = getFlag(options, keys, "tsconfig", mustBeString), resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArrayOfStrings), nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArrayOfStrings), mainFields = getFlag(options, keys, "mainFields", mustBeArrayOfStrings), conditions = getFlag(options, keys, "conditions", mustBeArrayOfStrings), external = getFlag(options, keys, "external", mustBeArrayOfStrings), packages = getFlag(options, keys, "packages", mustBeString), alias = getFlag(options, keys, "alias", mustBeObject), loader = getFlag(options, keys, "loader", mustBeObject), outExtension = getFlag(options, keys, "outExtension", mustBeObject), publicPath = getFlag(options, keys, "publicPath", mustBeString), entryNames = getFlag(options, keys, "entryNames", mustBeString), chunkNames = getFlag(options, keys, "chunkNames", mustBeString), assetNames = getFlag(options, keys, "assetNames", mustBeString), inject = getFlag(options, keys, "inject", mustBeArrayOfStrings), banner = getFlag(options, keys, "banner", mustBeObject), footer = getFlag(options, keys, "footer", mustBeObject), entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints), absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString), stdin = getFlag(options, keys, "stdin", mustBeObject), write = (_a2 = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a2 : writeDefault, allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean), mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
267
|
-
if (keys.plugins = true, checkForInvalidFlags(options, keys, `in ${callName}() call`), sourcemap && flags.push(`--sourcemap${sourcemap === true ? "" : `=${sourcemap}`}`), bundle && flags.push("--bundle"), allowOverwrite && flags.push("--allow-overwrite"), splitting && flags.push("--splitting"), preserveSymlinks && flags.push("--preserve-symlinks"), metafile && flags.push("--metafile"), outfile && flags.push(`--outfile=${outfile}`), outdir && flags.push(`--outdir=${outdir}`), outbase && flags.push(`--outbase=${outbase}`), tsconfig && flags.push(`--tsconfig=${tsconfig}`), packages && flags.push(`--packages=${packages}`), resolveExtensions && flags.push(`--resolve-extensions=${validateAndJoinStringArray(resolveExtensions, "resolve extension")}`), publicPath && flags.push(`--public-path=${publicPath}`), entryNames && flags.push(`--entry-names=${entryNames}`), chunkNames && flags.push(`--chunk-names=${chunkNames}`), assetNames && flags.push(`--asset-names=${assetNames}`), mainFields && flags.push(`--main-fields=${validateAndJoinStringArray(mainFields, "main field")}`), conditions && flags.push(`--conditions=${validateAndJoinStringArray(conditions, "condition")}`), external) for (let name of external) flags.push(`--external:${validateStringValue(name, "external")}`);
|
|
268
|
-
if (alias)
|
|
269
|
-
for (let old in alias) {
|
|
270
|
-
if (old.indexOf("=") >= 0) throw new Error(`Invalid package name in alias: ${old}`);
|
|
271
|
-
flags.push(`--alias:${old}=${validateStringValue(alias[old], "alias", old)}`);
|
|
272
|
-
}
|
|
273
|
-
if (banner)
|
|
274
|
-
for (let type in banner) {
|
|
275
|
-
if (type.indexOf("=") >= 0) throw new Error(`Invalid banner file type: ${type}`);
|
|
276
|
-
flags.push(`--banner:${type}=${validateStringValue(banner[type], "banner", type)}`);
|
|
277
|
-
}
|
|
278
|
-
if (footer)
|
|
279
|
-
for (let type in footer) {
|
|
280
|
-
if (type.indexOf("=") >= 0) throw new Error(`Invalid footer file type: ${type}`);
|
|
281
|
-
flags.push(`--footer:${type}=${validateStringValue(footer[type], "footer", type)}`);
|
|
282
|
-
}
|
|
283
|
-
if (inject) for (let path3 of inject) flags.push(`--inject:${validateStringValue(path3, "inject")}`);
|
|
284
|
-
if (loader)
|
|
285
|
-
for (let ext in loader) {
|
|
286
|
-
if (ext.indexOf("=") >= 0) throw new Error(`Invalid loader extension: ${ext}`);
|
|
287
|
-
flags.push(`--loader:${ext}=${validateStringValue(loader[ext], "loader", ext)}`);
|
|
288
|
-
}
|
|
289
|
-
if (outExtension)
|
|
290
|
-
for (let ext in outExtension) {
|
|
291
|
-
if (ext.indexOf("=") >= 0) throw new Error(`Invalid out extension: ${ext}`);
|
|
292
|
-
flags.push(`--out-extension:${ext}=${validateStringValue(outExtension[ext], "out extension", ext)}`);
|
|
293
|
-
}
|
|
294
|
-
if (entryPoints)
|
|
295
|
-
if (Array.isArray(entryPoints))
|
|
296
|
-
for (let i = 0, n = entryPoints.length; i < n; i++) {
|
|
297
|
-
let entryPoint = entryPoints[i];
|
|
298
|
-
if (typeof entryPoint == "object" && entryPoint !== null) {
|
|
299
|
-
let entryPointKeys = /* @__PURE__ */ Object.create(null), input = getFlag(entryPoint, entryPointKeys, "in", mustBeString), output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
|
|
300
|
-
if (checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i), input === void 0) throw new Error('Missing property "in" for entry point at index ' + i);
|
|
301
|
-
if (output === void 0) throw new Error('Missing property "out" for entry point at index ' + i);
|
|
302
|
-
entries.push([output, input]);
|
|
303
|
-
} else
|
|
304
|
-
entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
|
|
305
|
-
}
|
|
306
|
-
else
|
|
307
|
-
for (let key in entryPoints)
|
|
308
|
-
entries.push([key, validateStringValue(entryPoints[key], "entry point", key)]);
|
|
309
|
-
if (stdin) {
|
|
310
|
-
let stdinKeys = /* @__PURE__ */ Object.create(null), contents = getFlag(stdin, stdinKeys, "contents", mustBeStringOrUint8Array), resolveDir = getFlag(stdin, stdinKeys, "resolveDir", mustBeString), sourcefile = getFlag(stdin, stdinKeys, "sourcefile", mustBeString), loader2 = getFlag(stdin, stdinKeys, "loader", mustBeString);
|
|
311
|
-
checkForInvalidFlags(stdin, stdinKeys, 'in "stdin" object'), sourcefile && flags.push(`--sourcefile=${sourcefile}`), loader2 && flags.push(`--loader=${loader2}`), resolveDir && (stdinResolveDir = resolveDir), typeof contents == "string" ? stdinContents = encodeUTF8(contents) : contents instanceof Uint8Array && (stdinContents = contents);
|
|
312
|
-
}
|
|
313
|
-
let nodePaths = [];
|
|
314
|
-
if (nodePathsInput)
|
|
315
|
-
for (let value of nodePathsInput)
|
|
316
|
-
value += "", nodePaths.push(value);
|
|
317
|
-
return {
|
|
318
|
-
entries,
|
|
319
|
-
flags,
|
|
320
|
-
write,
|
|
321
|
-
stdinContents,
|
|
322
|
-
stdinResolveDir,
|
|
323
|
-
absWorkingDir,
|
|
324
|
-
nodePaths,
|
|
325
|
-
mangleCache: validateMangleCache(mangleCache)
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
function flagsForTransformOptions(callName, options, isTTY2, logLevelDefault) {
|
|
329
|
-
let flags = [], keys = /* @__PURE__ */ Object.create(null);
|
|
330
|
-
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault), pushCommonFlags(flags, options, keys);
|
|
331
|
-
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean), sourcefile = getFlag(options, keys, "sourcefile", mustBeString), loader = getFlag(options, keys, "loader", mustBeString), banner = getFlag(options, keys, "banner", mustBeString), footer = getFlag(options, keys, "footer", mustBeString), mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
332
|
-
return checkForInvalidFlags(options, keys, `in ${callName}() call`), sourcemap && flags.push(`--sourcemap=${sourcemap === true ? "external" : sourcemap}`), sourcefile && flags.push(`--sourcefile=${sourcefile}`), loader && flags.push(`--loader=${loader}`), banner && flags.push(`--banner=${banner}`), footer && flags.push(`--footer=${footer}`), {
|
|
333
|
-
flags,
|
|
334
|
-
mangleCache: validateMangleCache(mangleCache)
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
function createChannel(streamIn) {
|
|
338
|
-
let requestCallbacksByKey = {}, closeData = { didClose: false, reason: "" }, responseCallbacks = {}, nextRequestID = 0, nextBuildKey = 0, stdout = new Uint8Array(16 * 1024), stdoutUsed = 0, readFromStdout = (chunk) => {
|
|
339
|
-
let limit = stdoutUsed + chunk.length;
|
|
340
|
-
if (limit > stdout.length) {
|
|
341
|
-
let swap = new Uint8Array(limit * 2);
|
|
342
|
-
swap.set(stdout), stdout = swap;
|
|
343
|
-
}
|
|
344
|
-
stdout.set(chunk, stdoutUsed), stdoutUsed += chunk.length;
|
|
345
|
-
let offset = 0;
|
|
346
|
-
for (; offset + 4 <= stdoutUsed; ) {
|
|
347
|
-
let length = readUInt32LE(stdout, offset);
|
|
348
|
-
if (offset + 4 + length > stdoutUsed)
|
|
349
|
-
break;
|
|
350
|
-
offset += 4, handleIncomingPacket(stdout.subarray(offset, offset + length)), offset += length;
|
|
351
|
-
}
|
|
352
|
-
offset > 0 && (stdout.copyWithin(0, offset, stdoutUsed), stdoutUsed -= offset);
|
|
353
|
-
}, afterClose = (error) => {
|
|
354
|
-
closeData.didClose = true, error && (closeData.reason = ": " + (error.message || error));
|
|
355
|
-
let text = "The service was stopped" + closeData.reason;
|
|
356
|
-
for (let id in responseCallbacks)
|
|
357
|
-
responseCallbacks[id](text, null);
|
|
358
|
-
responseCallbacks = {};
|
|
359
|
-
}, sendRequest = (refs, value, callback) => {
|
|
360
|
-
if (closeData.didClose) return callback("The service is no longer running" + closeData.reason, null);
|
|
361
|
-
let id = nextRequestID++;
|
|
362
|
-
responseCallbacks[id] = (error, response) => {
|
|
363
|
-
try {
|
|
364
|
-
callback(error, response);
|
|
365
|
-
} finally {
|
|
366
|
-
refs && refs.unref();
|
|
367
|
-
}
|
|
368
|
-
}, refs && refs.ref(), streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
|
|
369
|
-
}, sendResponse = (id, value) => {
|
|
370
|
-
if (closeData.didClose) throw new Error("The service is no longer running" + closeData.reason);
|
|
371
|
-
streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
|
|
372
|
-
}, handleRequest = async (id, request) => {
|
|
373
|
-
try {
|
|
374
|
-
if (request.command === "ping") {
|
|
375
|
-
sendResponse(id, {});
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
if (typeof request.key == "number") {
|
|
379
|
-
let requestCallbacks = requestCallbacksByKey[request.key];
|
|
380
|
-
if (!requestCallbacks)
|
|
381
|
-
return;
|
|
382
|
-
let callback = requestCallbacks[request.command];
|
|
383
|
-
if (callback) {
|
|
384
|
-
await callback(id, request);
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
throw new Error("Invalid command: " + request.command);
|
|
389
|
-
} catch (e) {
|
|
390
|
-
let errors = [extractErrorMessageV8(e, streamIn, null, void 0, "")];
|
|
391
|
-
try {
|
|
392
|
-
sendResponse(id, { errors });
|
|
393
|
-
} catch {
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}, isFirstPacket = true, handleIncomingPacket = (bytes) => {
|
|
397
|
-
if (isFirstPacket) {
|
|
398
|
-
isFirstPacket = false;
|
|
399
|
-
let binaryVersion = String.fromCharCode(...bytes);
|
|
400
|
-
if (binaryVersion !== "0.27.1")
|
|
401
|
-
throw new Error(`Cannot start service: Host version "0.27.1" does not match binary version ${quote(binaryVersion)}`);
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
let packet = decodePacket(bytes);
|
|
405
|
-
if (packet.isRequest)
|
|
406
|
-
handleRequest(packet.id, packet.value);
|
|
407
|
-
else {
|
|
408
|
-
let callback = responseCallbacks[packet.id];
|
|
409
|
-
delete responseCallbacks[packet.id], packet.value.error ? callback(packet.value.error, {}) : callback(null, packet.value);
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
return {
|
|
413
|
-
readFromStdout,
|
|
414
|
-
afterClose,
|
|
415
|
-
service: {
|
|
416
|
-
buildOrContext: ({ callName, refs, options, isTTY: isTTY2, defaultWD: defaultWD2, callback }) => {
|
|
417
|
-
let refCount = 0, buildKey = nextBuildKey++, requestCallbacks = {}, buildRefs = {
|
|
418
|
-
ref() {
|
|
419
|
-
++refCount === 1 && refs && refs.ref();
|
|
420
|
-
},
|
|
421
|
-
unref() {
|
|
422
|
-
--refCount === 0 && (delete requestCallbacksByKey[buildKey], refs && refs.unref());
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
requestCallbacksByKey[buildKey] = requestCallbacks, buildRefs.ref(), buildOrContextImpl(
|
|
426
|
-
callName,
|
|
427
|
-
buildKey,
|
|
428
|
-
sendRequest,
|
|
429
|
-
sendResponse,
|
|
430
|
-
buildRefs,
|
|
431
|
-
streamIn,
|
|
432
|
-
requestCallbacks,
|
|
433
|
-
options,
|
|
434
|
-
isTTY2,
|
|
435
|
-
defaultWD2,
|
|
436
|
-
(err, res) => {
|
|
437
|
-
try {
|
|
438
|
-
callback(err, res);
|
|
439
|
-
} finally {
|
|
440
|
-
buildRefs.unref();
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
);
|
|
444
|
-
},
|
|
445
|
-
transform: ({ callName, refs, input, options, isTTY: isTTY2, fs: fs3, callback }) => {
|
|
446
|
-
let details = createObjectStash(), start = (inputPath) => {
|
|
447
|
-
try {
|
|
448
|
-
if (typeof input != "string" && !(input instanceof Uint8Array))
|
|
449
|
-
throw new Error('The input to "transform" must be a string or a Uint8Array');
|
|
450
|
-
let {
|
|
451
|
-
flags,
|
|
452
|
-
mangleCache
|
|
453
|
-
} = flagsForTransformOptions(callName, options, isTTY2, transformLogLevelDefault), request = {
|
|
454
|
-
command: "transform",
|
|
455
|
-
flags,
|
|
456
|
-
inputFS: inputPath !== null,
|
|
457
|
-
input: inputPath !== null ? encodeUTF8(inputPath) : typeof input == "string" ? encodeUTF8(input) : input
|
|
458
|
-
};
|
|
459
|
-
mangleCache && (request.mangleCache = mangleCache), sendRequest(refs, request, (error, response) => {
|
|
460
|
-
if (error) return callback(new Error(error), null);
|
|
461
|
-
let errors = replaceDetailsInMessages(response.errors, details), warnings = replaceDetailsInMessages(response.warnings, details), outstanding = 1, next = () => {
|
|
462
|
-
if (--outstanding === 0) {
|
|
463
|
-
let result = {
|
|
464
|
-
warnings,
|
|
465
|
-
code: response.code,
|
|
466
|
-
map: response.map,
|
|
467
|
-
mangleCache: void 0,
|
|
468
|
-
legalComments: void 0
|
|
469
|
-
};
|
|
470
|
-
"legalComments" in response && (result.legalComments = response?.legalComments), response.mangleCache && (result.mangleCache = response?.mangleCache), callback(null, result);
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
if (errors.length > 0) return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
|
|
474
|
-
response.codeFS && (outstanding++, fs3.readFile(response.code, (err, contents) => {
|
|
475
|
-
err !== null ? callback(err, null) : (response.code = contents, next());
|
|
476
|
-
})), response.mapFS && (outstanding++, fs3.readFile(response.map, (err, contents) => {
|
|
477
|
-
err !== null ? callback(err, null) : (response.map = contents, next());
|
|
478
|
-
})), next();
|
|
479
|
-
});
|
|
480
|
-
} catch (e) {
|
|
481
|
-
let flags = [];
|
|
482
|
-
try {
|
|
483
|
-
pushLogFlags(flags, options, {}, isTTY2, transformLogLevelDefault);
|
|
484
|
-
} catch {
|
|
485
|
-
}
|
|
486
|
-
let error = extractErrorMessageV8(e, streamIn, details, void 0, "");
|
|
487
|
-
sendRequest(refs, { command: "error", flags, error }, () => {
|
|
488
|
-
error.detail = details.load(error.detail), callback(failureErrorWithLog("Transform failed", [error], []), null);
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
if ((typeof input == "string" || input instanceof Uint8Array) && input.length > 1024 * 1024) {
|
|
493
|
-
let next = start;
|
|
494
|
-
start = () => fs3.writeFile(input, next);
|
|
495
|
-
}
|
|
496
|
-
start(null);
|
|
497
|
-
},
|
|
498
|
-
formatMessages: ({ callName, refs, messages, options, callback }) => {
|
|
499
|
-
if (!options) throw new Error(`Missing second argument in ${callName}() call`);
|
|
500
|
-
let keys = {}, kind = getFlag(options, keys, "kind", mustBeString), color = getFlag(options, keys, "color", mustBeBoolean), terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger);
|
|
501
|
-
if (checkForInvalidFlags(options, keys, `in ${callName}() call`), kind === void 0) throw new Error(`Missing "kind" in ${callName}() call`);
|
|
502
|
-
if (kind !== "error" && kind !== "warning") throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
|
|
503
|
-
let request = {
|
|
504
|
-
command: "format-msgs",
|
|
505
|
-
messages: sanitizeMessages(messages, "messages", null, "", terminalWidth),
|
|
506
|
-
isWarning: kind === "warning"
|
|
507
|
-
};
|
|
508
|
-
color !== void 0 && (request.color = color), terminalWidth !== void 0 && (request.terminalWidth = terminalWidth), sendRequest(refs, request, (error, response) => {
|
|
509
|
-
if (error) return callback(new Error(error), null);
|
|
510
|
-
callback(null, response.messages);
|
|
511
|
-
});
|
|
512
|
-
},
|
|
513
|
-
analyzeMetafile: ({ callName, refs, metafile, options, callback }) => {
|
|
514
|
-
options === void 0 && (options = {});
|
|
515
|
-
let keys = {}, color = getFlag(options, keys, "color", mustBeBoolean), verbose = getFlag(options, keys, "verbose", mustBeBoolean);
|
|
516
|
-
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
517
|
-
let request = {
|
|
518
|
-
command: "analyze-metafile",
|
|
519
|
-
metafile
|
|
520
|
-
};
|
|
521
|
-
color !== void 0 && (request.color = color), verbose !== void 0 && (request.verbose = verbose), sendRequest(refs, request, (error, response) => {
|
|
522
|
-
if (error) return callback(new Error(error), null);
|
|
523
|
-
callback(null, response.result);
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, isTTY2, defaultWD2, callback) {
|
|
530
|
-
let details = createObjectStash(), isContext = callName === "context", handleError = (e, pluginName) => {
|
|
531
|
-
let flags = [];
|
|
532
|
-
try {
|
|
533
|
-
pushLogFlags(flags, options, {}, isTTY2, buildLogLevelDefault);
|
|
534
|
-
} catch {
|
|
535
|
-
}
|
|
536
|
-
let message = extractErrorMessageV8(e, streamIn, details, void 0, pluginName);
|
|
537
|
-
sendRequest(refs, { command: "error", flags, error: message }, () => {
|
|
538
|
-
message.detail = details.load(message.detail), callback(failureErrorWithLog(isContext ? "Context failed" : "Build failed", [message], []), null);
|
|
539
|
-
});
|
|
540
|
-
}, plugins;
|
|
541
|
-
if (typeof options == "object") {
|
|
542
|
-
let value = options.plugins;
|
|
543
|
-
if (value !== void 0) {
|
|
544
|
-
if (!Array.isArray(value)) return handleError(new Error('"plugins" must be an array'), "");
|
|
545
|
-
plugins = value;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
if (plugins && plugins.length > 0) {
|
|
549
|
-
if (streamIn.isSync) return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
|
550
|
-
handlePlugins(
|
|
551
|
-
buildKey,
|
|
552
|
-
sendRequest,
|
|
553
|
-
sendResponse,
|
|
554
|
-
refs,
|
|
555
|
-
streamIn,
|
|
556
|
-
requestCallbacks,
|
|
557
|
-
options,
|
|
558
|
-
plugins,
|
|
559
|
-
details
|
|
560
|
-
).then(
|
|
561
|
-
(result) => {
|
|
562
|
-
if (!result.ok) return handleError(result.error, result.pluginName);
|
|
563
|
-
try {
|
|
564
|
-
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
|
|
565
|
-
} catch (e) {
|
|
566
|
-
handleError(e, "");
|
|
567
|
-
}
|
|
568
|
-
},
|
|
569
|
-
(e) => handleError(e, "")
|
|
570
|
-
);
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
try {
|
|
574
|
-
buildOrContextContinue(null, (result, done) => done([], []), () => {
|
|
575
|
-
});
|
|
576
|
-
} catch (e) {
|
|
577
|
-
handleError(e, "");
|
|
578
|
-
}
|
|
579
|
-
function buildOrContextContinue(requestPlugins, runOnEndCallbacks, scheduleOnDisposeCallbacks) {
|
|
580
|
-
let writeDefault = streamIn.hasFS, {
|
|
581
|
-
entries,
|
|
582
|
-
flags,
|
|
583
|
-
write,
|
|
584
|
-
stdinContents,
|
|
585
|
-
stdinResolveDir,
|
|
586
|
-
absWorkingDir,
|
|
587
|
-
nodePaths,
|
|
588
|
-
mangleCache
|
|
589
|
-
} = flagsForBuildOptions(callName, options, isTTY2, buildLogLevelDefault, writeDefault);
|
|
590
|
-
if (write && !streamIn.hasFS) throw new Error('The "write" option is unavailable in this environment');
|
|
591
|
-
let request = {
|
|
592
|
-
command: "build",
|
|
593
|
-
key: buildKey,
|
|
594
|
-
entries,
|
|
595
|
-
flags,
|
|
596
|
-
write,
|
|
597
|
-
stdinContents,
|
|
598
|
-
stdinResolveDir,
|
|
599
|
-
absWorkingDir: absWorkingDir || defaultWD2,
|
|
600
|
-
nodePaths,
|
|
601
|
-
context: isContext
|
|
602
|
-
};
|
|
603
|
-
requestPlugins && (request.plugins = requestPlugins), mangleCache && (request.mangleCache = mangleCache);
|
|
604
|
-
let buildResponseToResult = (response, callback2) => {
|
|
605
|
-
let result = {
|
|
606
|
-
errors: replaceDetailsInMessages(response.errors, details),
|
|
607
|
-
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
608
|
-
outputFiles: void 0,
|
|
609
|
-
metafile: void 0,
|
|
610
|
-
mangleCache: void 0
|
|
611
|
-
}, originalErrors = result.errors.slice(), originalWarnings = result.warnings.slice();
|
|
612
|
-
response.outputFiles && (result.outputFiles = response.outputFiles.map(convertOutputFiles)), response.metafile && (result.metafile = JSON.parse(response.metafile)), response.mangleCache && (result.mangleCache = response.mangleCache), response.writeToStdout !== void 0 && console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, "")), runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
|
|
613
|
-
if (originalErrors.length > 0 || onEndErrors.length > 0) {
|
|
614
|
-
let error = failureErrorWithLog("Build failed", originalErrors.concat(onEndErrors), originalWarnings.concat(onEndWarnings));
|
|
615
|
-
return callback2(error, null, onEndErrors, onEndWarnings);
|
|
616
|
-
}
|
|
617
|
-
callback2(null, result, onEndErrors, onEndWarnings);
|
|
618
|
-
});
|
|
619
|
-
}, latestResultPromise, provideLatestResult;
|
|
620
|
-
isContext && (requestCallbacks["on-end"] = (id, request2) => new Promise((resolve2) => {
|
|
621
|
-
buildResponseToResult(request2, (err, result, onEndErrors, onEndWarnings) => {
|
|
622
|
-
let response = {
|
|
623
|
-
errors: onEndErrors,
|
|
624
|
-
warnings: onEndWarnings
|
|
625
|
-
};
|
|
626
|
-
provideLatestResult && provideLatestResult(err, result), latestResultPromise = void 0, provideLatestResult = void 0, sendResponse(id, response), resolve2();
|
|
627
|
-
});
|
|
628
|
-
})), sendRequest(refs, request, (error, response) => {
|
|
629
|
-
if (error) return callback(new Error(error), null);
|
|
630
|
-
if (!isContext)
|
|
631
|
-
return buildResponseToResult(response, (err, res) => (scheduleOnDisposeCallbacks(), callback(err, res)));
|
|
632
|
-
if (response.errors.length > 0)
|
|
633
|
-
return callback(failureErrorWithLog("Context failed", response.errors, response.warnings), null);
|
|
634
|
-
let didDispose = false, result = {
|
|
635
|
-
rebuild: () => (latestResultPromise || (latestResultPromise = new Promise((resolve2, reject) => {
|
|
636
|
-
let settlePromise;
|
|
637
|
-
provideLatestResult = (err, result2) => {
|
|
638
|
-
settlePromise || (settlePromise = () => err ? reject(err) : resolve2(result2));
|
|
639
|
-
};
|
|
640
|
-
let triggerAnotherBuild = () => {
|
|
641
|
-
sendRequest(refs, {
|
|
642
|
-
command: "rebuild",
|
|
643
|
-
key: buildKey
|
|
644
|
-
}, (error2, response2) => {
|
|
645
|
-
error2 ? reject(new Error(error2)) : settlePromise ? settlePromise() : triggerAnotherBuild();
|
|
646
|
-
});
|
|
647
|
-
};
|
|
648
|
-
triggerAnotherBuild();
|
|
649
|
-
})), latestResultPromise),
|
|
650
|
-
watch: (options2 = {}) => new Promise((resolve2, reject) => {
|
|
651
|
-
if (!streamIn.hasFS) throw new Error('Cannot use the "watch" API in this environment');
|
|
652
|
-
let keys = {}, delay = getFlag(options2, keys, "delay", mustBeInteger);
|
|
653
|
-
checkForInvalidFlags(options2, keys, "in watch() call");
|
|
654
|
-
let request2 = {
|
|
655
|
-
command: "watch",
|
|
656
|
-
key: buildKey
|
|
657
|
-
};
|
|
658
|
-
delay && (request2.delay = delay), sendRequest(refs, request2, (error2) => {
|
|
659
|
-
error2 ? reject(new Error(error2)) : resolve2(void 0);
|
|
660
|
-
});
|
|
661
|
-
}),
|
|
662
|
-
serve: (options2 = {}) => new Promise((resolve2, reject) => {
|
|
663
|
-
if (!streamIn.hasFS) throw new Error('Cannot use the "serve" API in this environment');
|
|
664
|
-
let keys = {}, port = getFlag(options2, keys, "port", mustBeValidPortNumber), host = getFlag(options2, keys, "host", mustBeString), servedir = getFlag(options2, keys, "servedir", mustBeString), keyfile = getFlag(options2, keys, "keyfile", mustBeString), certfile = getFlag(options2, keys, "certfile", mustBeString), fallback = getFlag(options2, keys, "fallback", mustBeString), cors = getFlag(options2, keys, "cors", mustBeObject), onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
|
|
665
|
-
checkForInvalidFlags(options2, keys, "in serve() call");
|
|
666
|
-
let request2 = {
|
|
667
|
-
command: "serve",
|
|
668
|
-
key: buildKey,
|
|
669
|
-
onRequest: !!onRequest
|
|
670
|
-
};
|
|
671
|
-
if (port !== void 0 && (request2.port = port), host !== void 0 && (request2.host = host), servedir !== void 0 && (request2.servedir = servedir), keyfile !== void 0 && (request2.keyfile = keyfile), certfile !== void 0 && (request2.certfile = certfile), fallback !== void 0 && (request2.fallback = fallback), cors) {
|
|
672
|
-
let corsKeys = {}, origin = getFlag(cors, corsKeys, "origin", mustBeStringOrArrayOfStrings);
|
|
673
|
-
checkForInvalidFlags(cors, corsKeys, 'on "cors" object'), Array.isArray(origin) ? request2.corsOrigin = origin : origin !== void 0 && (request2.corsOrigin = [origin]);
|
|
674
|
-
}
|
|
675
|
-
sendRequest(refs, request2, (error2, response2) => {
|
|
676
|
-
if (error2) return reject(new Error(error2));
|
|
677
|
-
onRequest && (requestCallbacks["serve-request"] = (id, request3) => {
|
|
678
|
-
onRequest(request3.args), sendResponse(id, {});
|
|
679
|
-
}), resolve2(response2);
|
|
680
|
-
});
|
|
681
|
-
}),
|
|
682
|
-
cancel: () => new Promise((resolve2) => {
|
|
683
|
-
if (didDispose) return resolve2();
|
|
684
|
-
sendRequest(refs, {
|
|
685
|
-
command: "cancel",
|
|
686
|
-
key: buildKey
|
|
687
|
-
}, () => {
|
|
688
|
-
resolve2();
|
|
689
|
-
});
|
|
690
|
-
}),
|
|
691
|
-
dispose: () => new Promise((resolve2) => {
|
|
692
|
-
if (didDispose) return resolve2();
|
|
693
|
-
didDispose = true, sendRequest(refs, {
|
|
694
|
-
command: "dispose",
|
|
695
|
-
key: buildKey
|
|
696
|
-
}, () => {
|
|
697
|
-
resolve2(), scheduleOnDisposeCallbacks(), refs.unref();
|
|
698
|
-
});
|
|
699
|
-
})
|
|
700
|
-
};
|
|
701
|
-
refs.ref(), callback(null, result);
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, initialOptions, plugins, details) => {
|
|
706
|
-
let onStartCallbacks = [], onEndCallbacks = [], onResolveCallbacks = {}, onLoadCallbacks = {}, onDisposeCallbacks = [], nextCallbackID = 0, i = 0, requestPlugins = [], isSetupDone = false;
|
|
707
|
-
plugins = [...plugins];
|
|
708
|
-
for (let item of plugins) {
|
|
709
|
-
let keys = {};
|
|
710
|
-
if (typeof item != "object") throw new Error(`Plugin at index ${i} must be an object`);
|
|
711
|
-
let name = getFlag(item, keys, "name", mustBeString);
|
|
712
|
-
if (typeof name != "string" || name === "") throw new Error(`Plugin at index ${i} is missing a name`);
|
|
713
|
-
try {
|
|
714
|
-
let setup = getFlag(item, keys, "setup", mustBeFunction);
|
|
715
|
-
if (typeof setup != "function") throw new Error("Plugin is missing a setup function");
|
|
716
|
-
checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
|
|
717
|
-
let plugin = {
|
|
718
|
-
name,
|
|
719
|
-
onStart: !1,
|
|
720
|
-
onEnd: !1,
|
|
721
|
-
onResolve: [],
|
|
722
|
-
onLoad: []
|
|
723
|
-
};
|
|
724
|
-
i++;
|
|
725
|
-
let promise = setup({
|
|
726
|
-
initialOptions,
|
|
727
|
-
resolve: (path3, options = {}) => {
|
|
728
|
-
if (!isSetupDone) throw new Error('Cannot call "resolve" before plugin setup has completed');
|
|
729
|
-
if (typeof path3 != "string") throw new Error("The path to resolve must be a string");
|
|
730
|
-
let keys2 = /* @__PURE__ */ Object.create(null), pluginName = getFlag(options, keys2, "pluginName", mustBeString), importer = getFlag(options, keys2, "importer", mustBeString), namespace = getFlag(options, keys2, "namespace", mustBeString), resolveDir = getFlag(options, keys2, "resolveDir", mustBeString), kind = getFlag(options, keys2, "kind", mustBeString), pluginData = getFlag(options, keys2, "pluginData", canBeAnything), importAttributes = getFlag(options, keys2, "with", mustBeObject);
|
|
731
|
-
return checkForInvalidFlags(options, keys2, "in resolve() call"), new Promise((resolve22, reject) => {
|
|
732
|
-
let request = {
|
|
733
|
-
command: "resolve",
|
|
734
|
-
path: path3,
|
|
735
|
-
key: buildKey,
|
|
736
|
-
pluginName: name
|
|
737
|
-
};
|
|
738
|
-
if (pluginName != null && (request.pluginName = pluginName), importer != null && (request.importer = importer), namespace != null && (request.namespace = namespace), resolveDir != null && (request.resolveDir = resolveDir), kind != null) request.kind = kind;
|
|
739
|
-
else throw new Error('Must specify "kind" when calling "resolve"');
|
|
740
|
-
pluginData != null && (request.pluginData = details.store(pluginData)), importAttributes != null && (request.with = sanitizeStringMap(importAttributes, "with")), sendRequest(refs, request, (error, response) => {
|
|
741
|
-
error !== null ? reject(new Error(error)) : resolve22({
|
|
742
|
-
errors: replaceDetailsInMessages(response.errors, details),
|
|
743
|
-
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
744
|
-
path: response.path,
|
|
745
|
-
external: response.external,
|
|
746
|
-
sideEffects: response.sideEffects,
|
|
747
|
-
namespace: response.namespace,
|
|
748
|
-
suffix: response.suffix,
|
|
749
|
-
pluginData: details.load(response.pluginData)
|
|
750
|
-
});
|
|
751
|
-
});
|
|
752
|
-
});
|
|
753
|
-
},
|
|
754
|
-
onStart(callback) {
|
|
755
|
-
let registeredText = 'This error came from the "onStart" callback registered here:', registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
|
|
756
|
-
onStartCallbacks.push({ name, callback, note: registeredNote }), plugin.onStart = !0;
|
|
757
|
-
},
|
|
758
|
-
onEnd(callback) {
|
|
759
|
-
let registeredText = 'This error came from the "onEnd" callback registered here:', registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
|
|
760
|
-
onEndCallbacks.push({ name, callback, note: registeredNote }), plugin.onEnd = !0;
|
|
761
|
-
},
|
|
762
|
-
onResolve(options, callback) {
|
|
763
|
-
let registeredText = 'This error came from the "onResolve" callback registered here:', registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve"), keys2 = {}, filter = getFlag(options, keys2, "filter", mustBeRegExp), namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
764
|
-
if (checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${quote(name)}`), filter == null) throw new Error("onResolve() call is missing a filter");
|
|
765
|
-
let id = nextCallbackID++;
|
|
766
|
-
onResolveCallbacks[id] = { name, callback, note: registeredNote }, plugin.onResolve.push({ id, filter: jsRegExpToGoRegExp(filter), namespace: namespace || "" });
|
|
767
|
-
},
|
|
768
|
-
onLoad(options, callback) {
|
|
769
|
-
let registeredText = 'This error came from the "onLoad" callback registered here:', registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad"), keys2 = {}, filter = getFlag(options, keys2, "filter", mustBeRegExp), namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
770
|
-
if (checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${quote(name)}`), filter == null) throw new Error("onLoad() call is missing a filter");
|
|
771
|
-
let id = nextCallbackID++;
|
|
772
|
-
onLoadCallbacks[id] = { name, callback, note: registeredNote }, plugin.onLoad.push({ id, filter: jsRegExpToGoRegExp(filter), namespace: namespace || "" });
|
|
773
|
-
},
|
|
774
|
-
onDispose(callback) {
|
|
775
|
-
onDisposeCallbacks.push(callback);
|
|
776
|
-
},
|
|
777
|
-
esbuild: streamIn.esbuild
|
|
778
|
-
});
|
|
779
|
-
promise && await promise, requestPlugins.push(plugin);
|
|
780
|
-
} catch (e) {
|
|
781
|
-
return { ok: false, error: e, pluginName: name };
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
requestCallbacks["on-start"] = async (id, request) => {
|
|
785
|
-
details.clear();
|
|
786
|
-
let response = { errors: [], warnings: [] };
|
|
787
|
-
await Promise.all(onStartCallbacks.map(async ({ name, callback, note }) => {
|
|
788
|
-
try {
|
|
789
|
-
let result = await callback();
|
|
790
|
-
if (result != null) {
|
|
791
|
-
if (typeof result != "object") throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
|
|
792
|
-
let keys = {}, errors = getFlag(result, keys, "errors", mustBeArray), warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
793
|
-
checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${quote(name)}`), errors != null && response.errors.push(...sanitizeMessages(errors, "errors", details, name, void 0)), warnings != null && response.warnings.push(...sanitizeMessages(warnings, "warnings", details, name, void 0));
|
|
794
|
-
}
|
|
795
|
-
} catch (e) {
|
|
796
|
-
response.errors.push(extractErrorMessageV8(e, streamIn, details, note && note(), name));
|
|
797
|
-
}
|
|
798
|
-
})), sendResponse(id, response);
|
|
799
|
-
}, requestCallbacks["on-resolve"] = async (id, request) => {
|
|
800
|
-
let response = {}, name = "", callback, note;
|
|
801
|
-
for (let id2 of request.ids)
|
|
802
|
-
try {
|
|
803
|
-
({ name, callback, note } = onResolveCallbacks[id2]);
|
|
804
|
-
let result = await callback({
|
|
805
|
-
path: request.path,
|
|
806
|
-
importer: request.importer,
|
|
807
|
-
namespace: request.namespace,
|
|
808
|
-
resolveDir: request.resolveDir,
|
|
809
|
-
kind: request.kind,
|
|
810
|
-
pluginData: details.load(request.pluginData),
|
|
811
|
-
with: request.with
|
|
812
|
-
});
|
|
813
|
-
if (result != null) {
|
|
814
|
-
if (typeof result != "object") throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
|
|
815
|
-
let keys = {}, pluginName = getFlag(result, keys, "pluginName", mustBeString), path3 = getFlag(result, keys, "path", mustBeString), namespace = getFlag(result, keys, "namespace", mustBeString), suffix = getFlag(result, keys, "suffix", mustBeString), external = getFlag(result, keys, "external", mustBeBoolean), sideEffects = getFlag(result, keys, "sideEffects", mustBeBoolean), pluginData = getFlag(result, keys, "pluginData", canBeAnything), errors = getFlag(result, keys, "errors", mustBeArray), warnings = getFlag(result, keys, "warnings", mustBeArray), watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings), watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
|
816
|
-
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`), response.id = id2, pluginName != null && (response.pluginName = pluginName), path3 != null && (response.path = path3), namespace != null && (response.namespace = namespace), suffix != null && (response.suffix = suffix), external != null && (response.external = external), sideEffects != null && (response.sideEffects = sideEffects), pluginData != null && (response.pluginData = details.store(pluginData)), errors != null && (response.errors = sanitizeMessages(errors, "errors", details, name, void 0)), warnings != null && (response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0)), watchFiles != null && (response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles")), watchDirs != null && (response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs"));
|
|
817
|
-
break;
|
|
818
|
-
}
|
|
819
|
-
} catch (e) {
|
|
820
|
-
response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
|
|
821
|
-
break;
|
|
822
|
-
}
|
|
823
|
-
sendResponse(id, response);
|
|
824
|
-
}, requestCallbacks["on-load"] = async (id, request) => {
|
|
825
|
-
let response = {}, name = "", callback, note;
|
|
826
|
-
for (let id2 of request.ids)
|
|
827
|
-
try {
|
|
828
|
-
({ name, callback, note } = onLoadCallbacks[id2]);
|
|
829
|
-
let result = await callback({
|
|
830
|
-
path: request.path,
|
|
831
|
-
namespace: request.namespace,
|
|
832
|
-
suffix: request.suffix,
|
|
833
|
-
pluginData: details.load(request.pluginData),
|
|
834
|
-
with: request.with
|
|
835
|
-
});
|
|
836
|
-
if (result != null) {
|
|
837
|
-
if (typeof result != "object") throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
|
|
838
|
-
let keys = {}, pluginName = getFlag(result, keys, "pluginName", mustBeString), contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array), resolveDir = getFlag(result, keys, "resolveDir", mustBeString), pluginData = getFlag(result, keys, "pluginData", canBeAnything), loader = getFlag(result, keys, "loader", mustBeString), errors = getFlag(result, keys, "errors", mustBeArray), warnings = getFlag(result, keys, "warnings", mustBeArray), watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings), watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
|
839
|
-
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`), response.id = id2, pluginName != null && (response.pluginName = pluginName), contents instanceof Uint8Array ? response.contents = contents : contents != null && (response.contents = encodeUTF8(contents)), resolveDir != null && (response.resolveDir = resolveDir), pluginData != null && (response.pluginData = details.store(pluginData)), loader != null && (response.loader = loader), errors != null && (response.errors = sanitizeMessages(errors, "errors", details, name, void 0)), warnings != null && (response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0)), watchFiles != null && (response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles")), watchDirs != null && (response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs"));
|
|
840
|
-
break;
|
|
841
|
-
}
|
|
842
|
-
} catch (e) {
|
|
843
|
-
response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
|
|
844
|
-
break;
|
|
845
|
-
}
|
|
846
|
-
sendResponse(id, response);
|
|
847
|
-
};
|
|
848
|
-
let runOnEndCallbacks = (result, done) => done([], []);
|
|
849
|
-
onEndCallbacks.length > 0 && (runOnEndCallbacks = (result, done) => {
|
|
850
|
-
(async () => {
|
|
851
|
-
let onEndErrors = [], onEndWarnings = [];
|
|
852
|
-
for (let { name, callback, note } of onEndCallbacks) {
|
|
853
|
-
let newErrors, newWarnings;
|
|
854
|
-
try {
|
|
855
|
-
let value = await callback(result);
|
|
856
|
-
if (value != null) {
|
|
857
|
-
if (typeof value != "object") throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
|
|
858
|
-
let keys = {}, errors = getFlag(value, keys, "errors", mustBeArray), warnings = getFlag(value, keys, "warnings", mustBeArray);
|
|
859
|
-
checkForInvalidFlags(value, keys, `from onEnd() callback in plugin ${quote(name)}`), errors != null && (newErrors = sanitizeMessages(errors, "errors", details, name, void 0)), warnings != null && (newWarnings = sanitizeMessages(warnings, "warnings", details, name, void 0));
|
|
860
|
-
}
|
|
861
|
-
} catch (e) {
|
|
862
|
-
newErrors = [extractErrorMessageV8(e, streamIn, details, note && note(), name)];
|
|
863
|
-
}
|
|
864
|
-
if (newErrors) {
|
|
865
|
-
onEndErrors.push(...newErrors);
|
|
866
|
-
try {
|
|
867
|
-
result.errors.push(...newErrors);
|
|
868
|
-
} catch {
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
if (newWarnings) {
|
|
872
|
-
onEndWarnings.push(...newWarnings);
|
|
873
|
-
try {
|
|
874
|
-
result.warnings.push(...newWarnings);
|
|
875
|
-
} catch {
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
done(onEndErrors, onEndWarnings);
|
|
880
|
-
})();
|
|
881
|
-
});
|
|
882
|
-
let scheduleOnDisposeCallbacks = () => {
|
|
883
|
-
for (let cb of onDisposeCallbacks)
|
|
884
|
-
setTimeout(() => cb(), 0);
|
|
885
|
-
};
|
|
886
|
-
return isSetupDone = true, {
|
|
887
|
-
ok: true,
|
|
888
|
-
requestPlugins,
|
|
889
|
-
runOnEndCallbacks,
|
|
890
|
-
scheduleOnDisposeCallbacks
|
|
891
|
-
};
|
|
892
|
-
};
|
|
893
|
-
function createObjectStash() {
|
|
894
|
-
let map = /* @__PURE__ */ new Map(), nextID = 0;
|
|
895
|
-
return {
|
|
896
|
-
clear() {
|
|
897
|
-
map.clear();
|
|
898
|
-
},
|
|
899
|
-
load(id) {
|
|
900
|
-
return map.get(id);
|
|
901
|
-
},
|
|
902
|
-
store(value) {
|
|
903
|
-
if (value === void 0) return -1;
|
|
904
|
-
let id = nextID++;
|
|
905
|
-
return map.set(id, value), id;
|
|
906
|
-
}
|
|
907
|
-
};
|
|
908
|
-
}
|
|
909
|
-
function extractCallerV8(e, streamIn, ident) {
|
|
910
|
-
let note, tried = false;
|
|
911
|
-
return () => {
|
|
912
|
-
if (tried) return note;
|
|
913
|
-
tried = true;
|
|
914
|
-
try {
|
|
915
|
-
let lines = (e.stack + "").split(`
|
|
916
|
-
`);
|
|
917
|
-
lines.splice(1, 1);
|
|
918
|
-
let location = parseStackLinesV8(streamIn, lines, ident);
|
|
919
|
-
if (location)
|
|
920
|
-
return note = { text: e.message, location }, note;
|
|
921
|
-
} catch {
|
|
922
|
-
}
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
|
-
function extractErrorMessageV8(e, streamIn, stash, note, pluginName) {
|
|
926
|
-
let text = "Internal error", location = null;
|
|
927
|
-
try {
|
|
928
|
-
text = (e && e.message || e) + "";
|
|
929
|
-
} catch {
|
|
930
|
-
}
|
|
931
|
-
try {
|
|
932
|
-
location = parseStackLinesV8(streamIn, (e.stack + "").split(`
|
|
933
|
-
`), "");
|
|
934
|
-
} catch {
|
|
935
|
-
}
|
|
936
|
-
return { id: "", pluginName, text, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1 };
|
|
937
|
-
}
|
|
938
|
-
function parseStackLinesV8(streamIn, lines, ident) {
|
|
939
|
-
let at = " at ";
|
|
940
|
-
if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at))
|
|
941
|
-
for (let i = 1; i < lines.length; i++) {
|
|
942
|
-
let line = lines[i];
|
|
943
|
-
if (line.startsWith(at))
|
|
944
|
-
for (line = line.slice(at.length); ; ) {
|
|
945
|
-
let match = /^(?:new |async )?\S+ \((.*)\)$/.exec(line);
|
|
946
|
-
if (match) {
|
|
947
|
-
line = match[1];
|
|
948
|
-
continue;
|
|
949
|
-
}
|
|
950
|
-
if (match = /^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(line), match) {
|
|
951
|
-
line = match[1];
|
|
952
|
-
continue;
|
|
953
|
-
}
|
|
954
|
-
if (match = /^(\S+):(\d+):(\d+)$/.exec(line), match) {
|
|
955
|
-
let contents;
|
|
956
|
-
try {
|
|
957
|
-
contents = streamIn.readFileSync(match[1], "utf8");
|
|
958
|
-
} catch {
|
|
959
|
-
break;
|
|
960
|
-
}
|
|
961
|
-
let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || "", column = +match[3] - 1, length = lineText.slice(column, column + ident.length) === ident ? ident.length : 0;
|
|
962
|
-
return {
|
|
963
|
-
file: match[1],
|
|
964
|
-
namespace: "file",
|
|
965
|
-
line: +match[2],
|
|
966
|
-
column: encodeUTF8(lineText.slice(0, column)).length,
|
|
967
|
-
length: encodeUTF8(lineText.slice(column, column + length)).length,
|
|
968
|
-
lineText: lineText + `
|
|
969
|
-
` + lines.slice(1).join(`
|
|
970
|
-
`),
|
|
971
|
-
suggestion: ""
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
break;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
return null;
|
|
978
|
-
}
|
|
979
|
-
function failureErrorWithLog(text, errors, warnings) {
|
|
980
|
-
let limit = 5;
|
|
981
|
-
text += errors.length < 1 ? "" : ` with ${errors.length} error${errors.length < 2 ? "" : "s"}:` + errors.slice(0, limit + 1).map((e, i) => {
|
|
982
|
-
if (i === limit) return `
|
|
983
|
-
...`;
|
|
984
|
-
if (!e.location) return `
|
|
985
|
-
error: ${e.text}`;
|
|
986
|
-
let { file, line, column } = e.location, pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : "";
|
|
987
|
-
return `
|
|
988
|
-
${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`;
|
|
989
|
-
}).join("");
|
|
990
|
-
let error = new Error(text);
|
|
991
|
-
for (let [key, value] of [["errors", errors], ["warnings", warnings]])
|
|
992
|
-
Object.defineProperty(error, key, {
|
|
993
|
-
configurable: true,
|
|
994
|
-
enumerable: true,
|
|
995
|
-
get: () => value,
|
|
996
|
-
set: (value2) => Object.defineProperty(error, key, {
|
|
997
|
-
configurable: true,
|
|
998
|
-
enumerable: true,
|
|
999
|
-
value: value2
|
|
1000
|
-
})
|
|
1001
|
-
});
|
|
1002
|
-
return error;
|
|
1003
|
-
}
|
|
1004
|
-
function replaceDetailsInMessages(messages, stash) {
|
|
1005
|
-
for (let message of messages)
|
|
1006
|
-
message.detail = stash.load(message.detail);
|
|
1007
|
-
return messages;
|
|
1008
|
-
}
|
|
1009
|
-
function sanitizeLocation(location, where, terminalWidth) {
|
|
1010
|
-
if (location == null) return null;
|
|
1011
|
-
let keys = {}, file = getFlag(location, keys, "file", mustBeString), namespace = getFlag(location, keys, "namespace", mustBeString), line = getFlag(location, keys, "line", mustBeInteger), column = getFlag(location, keys, "column", mustBeInteger), length = getFlag(location, keys, "length", mustBeInteger), lineText = getFlag(location, keys, "lineText", mustBeString), suggestion = getFlag(location, keys, "suggestion", mustBeString);
|
|
1012
|
-
if (checkForInvalidFlags(location, keys, where), lineText) {
|
|
1013
|
-
let relevantASCII = lineText.slice(
|
|
1014
|
-
0,
|
|
1015
|
-
(column && column > 0 ? column : 0) + (length && length > 0 ? length : 0) + (terminalWidth && terminalWidth > 0 ? terminalWidth : 80)
|
|
1016
|
-
);
|
|
1017
|
-
!/[\x7F-\uFFFF]/.test(relevantASCII) && !/\n/.test(lineText) && (lineText = relevantASCII);
|
|
1018
|
-
}
|
|
1019
|
-
return {
|
|
1020
|
-
file: file || "",
|
|
1021
|
-
namespace: namespace || "",
|
|
1022
|
-
line: line || 0,
|
|
1023
|
-
column: column || 0,
|
|
1024
|
-
length: length || 0,
|
|
1025
|
-
lineText: lineText || "",
|
|
1026
|
-
suggestion: suggestion || ""
|
|
1027
|
-
};
|
|
1028
|
-
}
|
|
1029
|
-
function sanitizeMessages(messages, property, stash, fallbackPluginName, terminalWidth) {
|
|
1030
|
-
let messagesClone = [], index = 0;
|
|
1031
|
-
for (let message of messages) {
|
|
1032
|
-
let keys = {}, id = getFlag(message, keys, "id", mustBeString), pluginName = getFlag(message, keys, "pluginName", mustBeString), text = getFlag(message, keys, "text", mustBeString), location = getFlag(message, keys, "location", mustBeObjectOrNull), notes = getFlag(message, keys, "notes", mustBeArray), detail = getFlag(message, keys, "detail", canBeAnything), where = `in element ${index} of "${property}"`;
|
|
1033
|
-
checkForInvalidFlags(message, keys, where);
|
|
1034
|
-
let notesClone = [];
|
|
1035
|
-
if (notes)
|
|
1036
|
-
for (let note of notes) {
|
|
1037
|
-
let noteKeys = {}, noteText = getFlag(note, noteKeys, "text", mustBeString), noteLocation = getFlag(note, noteKeys, "location", mustBeObjectOrNull);
|
|
1038
|
-
checkForInvalidFlags(note, noteKeys, where), notesClone.push({
|
|
1039
|
-
text: noteText || "",
|
|
1040
|
-
location: sanitizeLocation(noteLocation, where, terminalWidth)
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
|
-
messagesClone.push({
|
|
1044
|
-
id: id || "",
|
|
1045
|
-
pluginName: pluginName || fallbackPluginName,
|
|
1046
|
-
text: text || "",
|
|
1047
|
-
location: sanitizeLocation(location, where, terminalWidth),
|
|
1048
|
-
notes: notesClone,
|
|
1049
|
-
detail: stash ? stash.store(detail) : -1
|
|
1050
|
-
}), index++;
|
|
1051
|
-
}
|
|
1052
|
-
return messagesClone;
|
|
1053
|
-
}
|
|
1054
|
-
function sanitizeStringArray(values, property) {
|
|
1055
|
-
let result = [];
|
|
1056
|
-
for (let value of values) {
|
|
1057
|
-
if (typeof value != "string") throw new Error(`${quote(property)} must be an array of strings`);
|
|
1058
|
-
result.push(value);
|
|
1059
|
-
}
|
|
1060
|
-
return result;
|
|
1061
|
-
}
|
|
1062
|
-
function sanitizeStringMap(map, property) {
|
|
1063
|
-
let result = /* @__PURE__ */ Object.create(null);
|
|
1064
|
-
for (let key in map) {
|
|
1065
|
-
let value = map[key];
|
|
1066
|
-
if (typeof value != "string") throw new Error(`key ${quote(key)} in object ${quote(property)} must be a string`);
|
|
1067
|
-
result[key] = value;
|
|
1068
|
-
}
|
|
1069
|
-
return result;
|
|
1070
|
-
}
|
|
1071
|
-
function convertOutputFiles({ path: path3, contents, hash }) {
|
|
1072
|
-
let text = null;
|
|
1073
|
-
return {
|
|
1074
|
-
path: path3,
|
|
1075
|
-
contents,
|
|
1076
|
-
hash,
|
|
1077
|
-
get text() {
|
|
1078
|
-
let binary = this.contents;
|
|
1079
|
-
return (text === null || binary !== contents) && (contents = binary, text = decodeUTF8(binary)), text;
|
|
1080
|
-
}
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
function jsRegExpToGoRegExp(regexp) {
|
|
1084
|
-
let result = regexp.source;
|
|
1085
|
-
return regexp.flags && (result = `(?${regexp.flags})${result}`), result;
|
|
1086
|
-
}
|
|
1087
|
-
var fs = __require("fs"), os = __require("os"), path = __require("path"), ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH, isValidBinaryPath = (x) => !!x && x !== "/usr/bin/esbuild", packageDarwin_arm64 = "@esbuild/darwin-arm64", packageDarwin_x64 = "@esbuild/darwin-x64", knownWindowsPackages = {
|
|
1088
|
-
"win32 arm64 LE": "@esbuild/win32-arm64",
|
|
1089
|
-
"win32 ia32 LE": "@esbuild/win32-ia32",
|
|
1090
|
-
"win32 x64 LE": "@esbuild/win32-x64"
|
|
1091
|
-
}, knownUnixlikePackages = {
|
|
1092
|
-
"aix ppc64 BE": "@esbuild/aix-ppc64",
|
|
1093
|
-
"android arm64 LE": "@esbuild/android-arm64",
|
|
1094
|
-
"darwin arm64 LE": "@esbuild/darwin-arm64",
|
|
1095
|
-
"darwin x64 LE": "@esbuild/darwin-x64",
|
|
1096
|
-
"freebsd arm64 LE": "@esbuild/freebsd-arm64",
|
|
1097
|
-
"freebsd x64 LE": "@esbuild/freebsd-x64",
|
|
1098
|
-
"linux arm LE": "@esbuild/linux-arm",
|
|
1099
|
-
"linux arm64 LE": "@esbuild/linux-arm64",
|
|
1100
|
-
"linux ia32 LE": "@esbuild/linux-ia32",
|
|
1101
|
-
"linux mips64el LE": "@esbuild/linux-mips64el",
|
|
1102
|
-
"linux ppc64 LE": "@esbuild/linux-ppc64",
|
|
1103
|
-
"linux riscv64 LE": "@esbuild/linux-riscv64",
|
|
1104
|
-
"linux s390x BE": "@esbuild/linux-s390x",
|
|
1105
|
-
"linux x64 LE": "@esbuild/linux-x64",
|
|
1106
|
-
"linux loong64 LE": "@esbuild/linux-loong64",
|
|
1107
|
-
"netbsd arm64 LE": "@esbuild/netbsd-arm64",
|
|
1108
|
-
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
|
1109
|
-
"openbsd arm64 LE": "@esbuild/openbsd-arm64",
|
|
1110
|
-
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
|
1111
|
-
"sunos x64 LE": "@esbuild/sunos-x64"
|
|
1112
|
-
}, knownWebAssemblyFallbackPackages = {
|
|
1113
|
-
"android arm LE": "@esbuild/android-arm",
|
|
1114
|
-
"android x64 LE": "@esbuild/android-x64",
|
|
1115
|
-
"openharmony arm64 LE": "@esbuild/openharmony-arm64"
|
|
1116
|
-
};
|
|
1117
|
-
function pkgAndSubpathForCurrentPlatform() {
|
|
1118
|
-
let pkg, subpath, isWASM = false, platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
|
1119
|
-
if (platformKey in knownWindowsPackages)
|
|
1120
|
-
pkg = knownWindowsPackages[platformKey], subpath = "esbuild.exe";
|
|
1121
|
-
else if (platformKey in knownUnixlikePackages)
|
|
1122
|
-
pkg = knownUnixlikePackages[platformKey], subpath = "bin/esbuild";
|
|
1123
|
-
else if (platformKey in knownWebAssemblyFallbackPackages)
|
|
1124
|
-
pkg = knownWebAssemblyFallbackPackages[platformKey], subpath = "bin/esbuild", isWASM = true;
|
|
1125
|
-
else
|
|
1126
|
-
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
1127
|
-
return { pkg, subpath, isWASM };
|
|
1128
|
-
}
|
|
1129
|
-
function pkgForSomeOtherPlatform() {
|
|
1130
|
-
let libMainJS = __require.resolve("esbuild"), nodeModulesDirectory = path.dirname(path.dirname(path.dirname(libMainJS)));
|
|
1131
|
-
if (path.basename(nodeModulesDirectory) === "node_modules") {
|
|
1132
|
-
for (let unixKey in knownUnixlikePackages)
|
|
1133
|
-
try {
|
|
1134
|
-
let pkg = knownUnixlikePackages[unixKey];
|
|
1135
|
-
if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
|
1136
|
-
} catch {
|
|
1137
|
-
}
|
|
1138
|
-
for (let windowsKey in knownWindowsPackages)
|
|
1139
|
-
try {
|
|
1140
|
-
let pkg = knownWindowsPackages[windowsKey];
|
|
1141
|
-
if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
|
1142
|
-
} catch {
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
return null;
|
|
1146
|
-
}
|
|
1147
|
-
function downloadedBinPath(pkg, subpath) {
|
|
1148
|
-
let esbuildLibDir = path.dirname(__require.resolve("esbuild"));
|
|
1149
|
-
return path.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
|
1150
|
-
}
|
|
1151
|
-
function generateBinPath() {
|
|
1152
|
-
if (isValidBinaryPath(ESBUILD_BINARY_PATH))
|
|
1153
|
-
if (!fs.existsSync(ESBUILD_BINARY_PATH))
|
|
1154
|
-
console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
|
|
1155
|
-
else
|
|
1156
|
-
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
|
|
1157
|
-
let { pkg, subpath, isWASM } = pkgAndSubpathForCurrentPlatform(), binPath;
|
|
1158
|
-
try {
|
|
1159
|
-
binPath = __require.resolve(`${pkg}/${subpath}`);
|
|
1160
|
-
} catch (e) {
|
|
1161
|
-
if (binPath = downloadedBinPath(pkg, subpath), !fs.existsSync(binPath)) {
|
|
1162
|
-
try {
|
|
1163
|
-
__require.resolve(pkg);
|
|
1164
|
-
} catch {
|
|
1165
|
-
let otherPkg = pkgForSomeOtherPlatform();
|
|
1166
|
-
if (otherPkg) {
|
|
1167
|
-
let suggestions = `
|
|
1168
|
-
Specifically the "${otherPkg}" package is present but this platform
|
|
1169
|
-
needs the "${pkg}" package instead. People often get into this
|
|
1170
|
-
situation by installing esbuild on Windows or macOS and copying "node_modules"
|
|
1171
|
-
into a Docker image that runs Linux, or by copying "node_modules" between
|
|
1172
|
-
Windows and WSL environments.
|
|
1173
|
-
|
|
1174
|
-
If you are installing with npm, you can try not copying the "node_modules"
|
|
1175
|
-
directory when you copy the files over, and running "npm ci" or "npm install"
|
|
1176
|
-
on the destination platform after the copy. Or you could consider using yarn
|
|
1177
|
-
instead of npm which has built-in support for installing a package on multiple
|
|
1178
|
-
platforms simultaneously.
|
|
1179
|
-
|
|
1180
|
-
If you are installing with yarn, you can try listing both this platform and the
|
|
1181
|
-
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
|
1182
|
-
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
1183
|
-
Keep in mind that this means multiple copies of esbuild will be present.
|
|
1184
|
-
`;
|
|
1185
|
-
throw (pkg === packageDarwin_x64 && otherPkg === packageDarwin_arm64 || pkg === packageDarwin_arm64 && otherPkg === packageDarwin_x64) && (suggestions = `
|
|
1186
|
-
Specifically the "${otherPkg}" package is present but this platform
|
|
1187
|
-
needs the "${pkg}" package instead. People often get into this
|
|
1188
|
-
situation by installing esbuild with npm running inside of Rosetta 2 and then
|
|
1189
|
-
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
|
|
1190
|
-
2 is Apple's on-the-fly x86_64-to-arm64 translation service).
|
|
1191
|
-
|
|
1192
|
-
If you are installing with npm, you can try ensuring that both npm and node are
|
|
1193
|
-
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
|
|
1194
|
-
changing how you installed npm and/or node. For example, installing node with
|
|
1195
|
-
the universal installer here should work: https://nodejs.org/en/download/. Or
|
|
1196
|
-
you could consider using yarn instead of npm which has built-in support for
|
|
1197
|
-
installing a package on multiple platforms simultaneously.
|
|
1198
|
-
|
|
1199
|
-
If you are installing with yarn, you can try listing both "arm64" and "x64"
|
|
1200
|
-
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
|
|
1201
|
-
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
1202
|
-
Keep in mind that this means multiple copies of esbuild will be present.
|
|
1203
|
-
`), new Error(`
|
|
1204
|
-
You installed esbuild for another platform than the one you're currently using.
|
|
1205
|
-
This won't work because esbuild is written with native code and needs to
|
|
1206
|
-
install a platform-specific binary executable.
|
|
1207
|
-
${suggestions}
|
|
1208
|
-
Another alternative is to use the "esbuild-wasm" package instead, which works
|
|
1209
|
-
the same way on all platforms. But it comes with a heavy performance cost and
|
|
1210
|
-
can sometimes be 10x slower than the "esbuild" package, so you may also not
|
|
1211
|
-
want to do that.
|
|
1212
|
-
`);
|
|
1213
|
-
}
|
|
1214
|
-
throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
|
|
1215
|
-
|
|
1216
|
-
If you are installing esbuild with npm, make sure that you don't specify the
|
|
1217
|
-
"--no-optional" or "--omit=optional" flags. The "optionalDependencies" feature
|
|
1218
|
-
of "package.json" is used by esbuild to install the correct binary executable
|
|
1219
|
-
for your current platform.`);
|
|
1220
|
-
}
|
|
1221
|
-
throw e;
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
if (/\.zip\//.test(binPath)) {
|
|
1225
|
-
let pnpapi;
|
|
1226
|
-
try {
|
|
1227
|
-
pnpapi = __require("pnpapi");
|
|
1228
|
-
} catch {
|
|
1229
|
-
}
|
|
1230
|
-
if (pnpapi) {
|
|
1231
|
-
let root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation, binTargetPath = path.join(
|
|
1232
|
-
root,
|
|
1233
|
-
"node_modules",
|
|
1234
|
-
".cache",
|
|
1235
|
-
"esbuild",
|
|
1236
|
-
`pnpapi-${pkg.replace("/", "-")}-0.27.1-${path.basename(subpath)}`
|
|
1237
|
-
);
|
|
1238
|
-
return fs.existsSync(binTargetPath) || (fs.mkdirSync(path.dirname(binTargetPath), { recursive: true }), fs.copyFileSync(binPath, binTargetPath), fs.chmodSync(binTargetPath, 493)), { binPath: binTargetPath, isWASM };
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
return { binPath, isWASM };
|
|
1242
|
-
}
|
|
1243
|
-
var child_process = __require("child_process"), crypto = __require("crypto"), path2 = __require("path"), fs2 = __require("fs"), os2 = __require("os"), tty = __require("tty"), worker_threads;
|
|
1244
|
-
if (process.env.ESBUILD_WORKER_THREADS !== "0") {
|
|
1245
|
-
try {
|
|
1246
|
-
worker_threads = __require("worker_threads");
|
|
1247
|
-
} catch {
|
|
1248
|
-
}
|
|
1249
|
-
let [major, minor] = process.versions.node.split(".");
|
|
1250
|
-
// <v12.17.0 does not work
|
|
1251
|
-
(+major < 12 || +major == 12 && +minor < 17 || +major == 13 && +minor < 13) && (worker_threads = void 0);
|
|
1252
|
-
}
|
|
1253
|
-
var _a, isInternalWorkerThread = ((_a = worker_threads?.workerData) == null ? void 0 : _a.esbuildVersion) === "0.27.1", esbuildCommandAndArgs = () => {
|
|
1254
|
-
if (!ESBUILD_BINARY_PATH && (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib"))
|
|
1255
|
-
throw new Error(
|
|
1256
|
-
`The esbuild JavaScript API cannot be bundled. Please mark the "esbuild" package as external so it's not included in the bundle.
|
|
1257
|
-
|
|
1258
|
-
More information: The file containing the code for esbuild's JavaScript API (${__filename}) does not appear to be inside the esbuild package on the file system, which usually means that the esbuild package was bundled into another file. This is problematic because the API needs to run a binary executable inside the esbuild package which is located using a relative path from the API code to the executable. If the esbuild package is bundled, the relative path will be incorrect and the executable won't be found.`
|
|
1259
|
-
);
|
|
1260
|
-
{
|
|
1261
|
-
let { binPath, isWASM } = generateBinPath();
|
|
1262
|
-
return isWASM ? ["node", [binPath]] : [binPath, []];
|
|
1263
|
-
}
|
|
1264
|
-
}, isTTY = () => tty.isatty(2), fsSync = {
|
|
1265
|
-
readFile(tempFile, callback) {
|
|
1266
|
-
try {
|
|
1267
|
-
let contents = fs2.readFileSync(tempFile, "utf8");
|
|
1268
|
-
try {
|
|
1269
|
-
fs2.unlinkSync(tempFile);
|
|
1270
|
-
} catch {
|
|
1271
|
-
}
|
|
1272
|
-
callback(null, contents);
|
|
1273
|
-
} catch (err) {
|
|
1274
|
-
callback(err, null);
|
|
1275
|
-
}
|
|
1276
|
-
},
|
|
1277
|
-
writeFile(contents, callback) {
|
|
1278
|
-
try {
|
|
1279
|
-
let tempFile = randomFileName();
|
|
1280
|
-
fs2.writeFileSync(tempFile, contents), callback(tempFile);
|
|
1281
|
-
} catch {
|
|
1282
|
-
callback(null);
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
}, fsAsync = {
|
|
1286
|
-
readFile(tempFile, callback) {
|
|
1287
|
-
try {
|
|
1288
|
-
fs2.readFile(tempFile, "utf8", (err, contents) => {
|
|
1289
|
-
try {
|
|
1290
|
-
fs2.unlink(tempFile, () => callback(err, contents));
|
|
1291
|
-
} catch {
|
|
1292
|
-
callback(err, contents);
|
|
1293
|
-
}
|
|
1294
|
-
});
|
|
1295
|
-
} catch (err) {
|
|
1296
|
-
callback(err, null);
|
|
1297
|
-
}
|
|
1298
|
-
},
|
|
1299
|
-
writeFile(contents, callback) {
|
|
1300
|
-
try {
|
|
1301
|
-
let tempFile = randomFileName();
|
|
1302
|
-
fs2.writeFile(tempFile, contents, (err) => callback(err !== null ? null : tempFile));
|
|
1303
|
-
} catch {
|
|
1304
|
-
callback(null);
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
}, version = "0.27.1", build = (options) => ensureServiceIsRunning().build(options), context = (buildOptions) => ensureServiceIsRunning().context(buildOptions), transform = (input, options) => ensureServiceIsRunning().transform(input, options), formatMessages = (messages, options) => ensureServiceIsRunning().formatMessages(messages, options), analyzeMetafile = (messages, options) => ensureServiceIsRunning().analyzeMetafile(messages, options), buildSync = (options) => {
|
|
1308
|
-
if (worker_threads && !isInternalWorkerThread)
|
|
1309
|
-
return workerThreadService || (workerThreadService = startWorkerThreadService(worker_threads)), workerThreadService.buildSync(options);
|
|
1310
|
-
let result;
|
|
1311
|
-
return runServiceSync((service) => service.buildOrContext({
|
|
1312
|
-
callName: "buildSync",
|
|
1313
|
-
refs: null,
|
|
1314
|
-
options,
|
|
1315
|
-
isTTY: isTTY(),
|
|
1316
|
-
defaultWD,
|
|
1317
|
-
callback: (err, res) => {
|
|
1318
|
-
if (err) throw err;
|
|
1319
|
-
result = res;
|
|
1320
|
-
}
|
|
1321
|
-
})), result;
|
|
1322
|
-
}, transformSync = (input, options) => {
|
|
1323
|
-
if (worker_threads && !isInternalWorkerThread)
|
|
1324
|
-
return workerThreadService || (workerThreadService = startWorkerThreadService(worker_threads)), workerThreadService.transformSync(input, options);
|
|
1325
|
-
let result;
|
|
1326
|
-
return runServiceSync((service) => service.transform({
|
|
1327
|
-
callName: "transformSync",
|
|
1328
|
-
refs: null,
|
|
1329
|
-
input,
|
|
1330
|
-
options: options || {},
|
|
1331
|
-
isTTY: isTTY(),
|
|
1332
|
-
fs: fsSync,
|
|
1333
|
-
callback: (err, res) => {
|
|
1334
|
-
if (err) throw err;
|
|
1335
|
-
result = res;
|
|
1336
|
-
}
|
|
1337
|
-
})), result;
|
|
1338
|
-
}, formatMessagesSync = (messages, options) => {
|
|
1339
|
-
if (worker_threads && !isInternalWorkerThread)
|
|
1340
|
-
return workerThreadService || (workerThreadService = startWorkerThreadService(worker_threads)), workerThreadService.formatMessagesSync(messages, options);
|
|
1341
|
-
let result;
|
|
1342
|
-
return runServiceSync((service) => service.formatMessages({
|
|
1343
|
-
callName: "formatMessagesSync",
|
|
1344
|
-
refs: null,
|
|
1345
|
-
messages,
|
|
1346
|
-
options,
|
|
1347
|
-
callback: (err, res) => {
|
|
1348
|
-
if (err) throw err;
|
|
1349
|
-
result = res;
|
|
1350
|
-
}
|
|
1351
|
-
})), result;
|
|
1352
|
-
}, analyzeMetafileSync = (metafile, options) => {
|
|
1353
|
-
if (worker_threads && !isInternalWorkerThread)
|
|
1354
|
-
return workerThreadService || (workerThreadService = startWorkerThreadService(worker_threads)), workerThreadService.analyzeMetafileSync(metafile, options);
|
|
1355
|
-
let result;
|
|
1356
|
-
return runServiceSync((service) => service.analyzeMetafile({
|
|
1357
|
-
callName: "analyzeMetafileSync",
|
|
1358
|
-
refs: null,
|
|
1359
|
-
metafile: typeof metafile == "string" ? metafile : JSON.stringify(metafile),
|
|
1360
|
-
options,
|
|
1361
|
-
callback: (err, res) => {
|
|
1362
|
-
if (err) throw err;
|
|
1363
|
-
result = res;
|
|
1364
|
-
}
|
|
1365
|
-
})), result;
|
|
1366
|
-
}, stop = () => (stopService && stopService(), workerThreadService && workerThreadService.stop(), Promise.resolve()), initializeWasCalled = false, initialize2 = (options) => {
|
|
1367
|
-
if (options = validateInitializeOptions(options || {}), options.wasmURL) throw new Error('The "wasmURL" option only works in the browser');
|
|
1368
|
-
if (options.wasmModule) throw new Error('The "wasmModule" option only works in the browser');
|
|
1369
|
-
if (options.worker) throw new Error('The "worker" option only works in the browser');
|
|
1370
|
-
if (initializeWasCalled) throw new Error('Cannot call "initialize" more than once');
|
|
1371
|
-
return ensureServiceIsRunning(), initializeWasCalled = true, Promise.resolve();
|
|
1372
|
-
}, defaultWD = process.cwd(), longLivedService, stopService, ensureServiceIsRunning = () => {
|
|
1373
|
-
if (longLivedService) return longLivedService;
|
|
1374
|
-
let [command, args] = esbuildCommandAndArgs(), child = child_process.spawn(command, args.concat("--service=0.27.1", "--ping"), {
|
|
1375
|
-
windowsHide: true,
|
|
1376
|
-
stdio: ["pipe", "pipe", "inherit"],
|
|
1377
|
-
cwd: defaultWD
|
|
1378
|
-
}), { readFromStdout, afterClose, service } = createChannel({
|
|
1379
|
-
writeToStdin(bytes) {
|
|
1380
|
-
child.stdin.write(bytes, (err) => {
|
|
1381
|
-
err && afterClose(err);
|
|
1382
|
-
});
|
|
1383
|
-
},
|
|
1384
|
-
readFileSync: fs2.readFileSync,
|
|
1385
|
-
isSync: false,
|
|
1386
|
-
hasFS: true,
|
|
1387
|
-
esbuild: node_exports
|
|
1388
|
-
});
|
|
1389
|
-
child.stdin.on("error", afterClose), child.on("error", afterClose);
|
|
1390
|
-
let stdin = child.stdin, stdout = child.stdout;
|
|
1391
|
-
stdout.on("data", readFromStdout), stdout.on("end", afterClose), stopService = () => {
|
|
1392
|
-
stdin.destroy(), stdout.destroy(), child.kill(), initializeWasCalled = false, longLivedService = void 0, stopService = void 0;
|
|
1393
|
-
};
|
|
1394
|
-
let refCount = 0;
|
|
1395
|
-
child.unref(), stdin.unref && stdin.unref(), stdout.unref && stdout.unref();
|
|
1396
|
-
let refs = {
|
|
1397
|
-
ref() {
|
|
1398
|
-
++refCount === 1 && child.ref();
|
|
1399
|
-
},
|
|
1400
|
-
unref() {
|
|
1401
|
-
--refCount === 0 && child.unref();
|
|
1402
|
-
}
|
|
1403
|
-
};
|
|
1404
|
-
return longLivedService = {
|
|
1405
|
-
build: (options) => new Promise((resolve2, reject) => {
|
|
1406
|
-
service.buildOrContext({
|
|
1407
|
-
callName: "build",
|
|
1408
|
-
refs,
|
|
1409
|
-
options,
|
|
1410
|
-
isTTY: isTTY(),
|
|
1411
|
-
defaultWD,
|
|
1412
|
-
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
1413
|
-
});
|
|
1414
|
-
}),
|
|
1415
|
-
context: (options) => new Promise((resolve2, reject) => service.buildOrContext({
|
|
1416
|
-
callName: "context",
|
|
1417
|
-
refs,
|
|
1418
|
-
options,
|
|
1419
|
-
isTTY: isTTY(),
|
|
1420
|
-
defaultWD,
|
|
1421
|
-
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
1422
|
-
})),
|
|
1423
|
-
transform: (input, options) => new Promise((resolve2, reject) => service.transform({
|
|
1424
|
-
callName: "transform",
|
|
1425
|
-
refs,
|
|
1426
|
-
input,
|
|
1427
|
-
options: options || {},
|
|
1428
|
-
isTTY: isTTY(),
|
|
1429
|
-
fs: fsAsync,
|
|
1430
|
-
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
1431
|
-
})),
|
|
1432
|
-
formatMessages: (messages, options) => new Promise((resolve2, reject) => service.formatMessages({
|
|
1433
|
-
callName: "formatMessages",
|
|
1434
|
-
refs,
|
|
1435
|
-
messages,
|
|
1436
|
-
options,
|
|
1437
|
-
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
1438
|
-
})),
|
|
1439
|
-
analyzeMetafile: (metafile, options) => new Promise((resolve2, reject) => service.analyzeMetafile({
|
|
1440
|
-
callName: "analyzeMetafile",
|
|
1441
|
-
refs,
|
|
1442
|
-
metafile: typeof metafile == "string" ? metafile : JSON.stringify(metafile),
|
|
1443
|
-
options,
|
|
1444
|
-
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
1445
|
-
}))
|
|
1446
|
-
}, longLivedService;
|
|
1447
|
-
}, runServiceSync = (callback) => {
|
|
1448
|
-
let [command, args] = esbuildCommandAndArgs(), stdin = new Uint8Array(), { readFromStdout, afterClose, service } = createChannel({
|
|
1449
|
-
writeToStdin(bytes) {
|
|
1450
|
-
if (stdin.length !== 0) throw new Error("Must run at most one command");
|
|
1451
|
-
stdin = bytes;
|
|
1452
|
-
},
|
|
1453
|
-
isSync: true,
|
|
1454
|
-
hasFS: true,
|
|
1455
|
-
esbuild: node_exports
|
|
1456
|
-
});
|
|
1457
|
-
callback(service);
|
|
1458
|
-
let stdout = child_process.execFileSync(command, args.concat("--service=0.27.1"), {
|
|
1459
|
-
cwd: defaultWD,
|
|
1460
|
-
windowsHide: true,
|
|
1461
|
-
input: stdin,
|
|
1462
|
-
// We don't know how large the output could be. If it's too large, the
|
|
1463
|
-
// command will fail with ENOBUFS. Reserve 16mb for now since that feels
|
|
1464
|
-
// like it should be enough. Also allow overriding this with an environment
|
|
1465
|
-
// variable.
|
|
1466
|
-
maxBuffer: +process.env.ESBUILD_MAX_BUFFER || 16 * 1024 * 1024
|
|
1467
|
-
});
|
|
1468
|
-
readFromStdout(stdout), afterClose(null);
|
|
1469
|
-
}, randomFileName = () => path2.join(os2.tmpdir(), `esbuild-${crypto.randomBytes(32).toString("hex")}`), workerThreadService = null, startWorkerThreadService = (worker_threads2) => {
|
|
1470
|
-
let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel(), worker = new worker_threads2.Worker(__filename, {
|
|
1471
|
-
workerData: { workerPort, defaultWD, esbuildVersion: "0.27.1" },
|
|
1472
|
-
transferList: [workerPort],
|
|
1473
|
-
// From node's documentation: https://nodejs.org/api/worker_threads.html
|
|
1474
|
-
//
|
|
1475
|
-
// Take care when launching worker threads from preload scripts (scripts loaded
|
|
1476
|
-
// and run using the `-r` command line flag). Unless the `execArgv` option is
|
|
1477
|
-
// explicitly set, new Worker threads automatically inherit the command line flags
|
|
1478
|
-
// from the running process and will preload the same preload scripts as the main
|
|
1479
|
-
// thread. If the preload script unconditionally launches a worker thread, every
|
|
1480
|
-
// thread spawned will spawn another until the application crashes.
|
|
1481
|
-
//
|
|
1482
|
-
execArgv: []
|
|
1483
|
-
}), nextID = 0, fakeBuildError = (text) => {
|
|
1484
|
-
let error = new Error(`Build failed with 1 error:
|
|
1485
|
-
error: ${text}`), errors = [{ id: "", pluginName: "", text, location: null, notes: [], detail: void 0 }];
|
|
1486
|
-
return error.errors = errors, error.warnings = [], error;
|
|
1487
|
-
}, validateBuildSyncOptions = (options) => {
|
|
1488
|
-
if (!options) return;
|
|
1489
|
-
let plugins = options.plugins;
|
|
1490
|
-
if (plugins && plugins.length > 0) throw fakeBuildError("Cannot use plugins in synchronous API calls");
|
|
1491
|
-
}, applyProperties = (object, properties) => {
|
|
1492
|
-
for (let key in properties)
|
|
1493
|
-
object[key] = properties[key];
|
|
1494
|
-
}, runCallSync = (command, args) => {
|
|
1495
|
-
let id = nextID++, sharedBuffer = new SharedArrayBuffer(8), sharedBufferView = new Int32Array(sharedBuffer), msg = { sharedBuffer, id, command, args };
|
|
1496
|
-
worker.postMessage(msg);
|
|
1497
|
-
let status = Atomics.wait(sharedBufferView, 0, 0);
|
|
1498
|
-
if (status !== "ok" && status !== "not-equal") throw new Error("Internal error: Atomics.wait() failed: " + status);
|
|
1499
|
-
let { message: { id: id2, resolve: resolve2, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
|
|
1500
|
-
if (id !== id2) throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
|
1501
|
-
if (reject)
|
|
1502
|
-
throw applyProperties(reject, properties), reject;
|
|
1503
|
-
return resolve2;
|
|
1504
|
-
};
|
|
1505
|
-
return worker.unref(), {
|
|
1506
|
-
buildSync(options) {
|
|
1507
|
-
return validateBuildSyncOptions(options), runCallSync("build", [options]);
|
|
1508
|
-
},
|
|
1509
|
-
transformSync(input, options) {
|
|
1510
|
-
return runCallSync("transform", [input, options]);
|
|
1511
|
-
},
|
|
1512
|
-
formatMessagesSync(messages, options) {
|
|
1513
|
-
return runCallSync("formatMessages", [messages, options]);
|
|
1514
|
-
},
|
|
1515
|
-
analyzeMetafileSync(metafile, options) {
|
|
1516
|
-
return runCallSync("analyzeMetafile", [metafile, options]);
|
|
1517
|
-
},
|
|
1518
|
-
stop() {
|
|
1519
|
-
worker.terminate(), workerThreadService = null;
|
|
1520
|
-
}
|
|
1521
|
-
};
|
|
1522
|
-
}, startSyncServiceWorker = () => {
|
|
1523
|
-
let workerPort = worker_threads.workerData.workerPort, parentPort2 = worker_threads.parentPort, extractProperties = (object) => {
|
|
1524
|
-
let properties = {};
|
|
1525
|
-
if (object && typeof object == "object")
|
|
1526
|
-
for (let key in object)
|
|
1527
|
-
properties[key] = object[key];
|
|
1528
|
-
return properties;
|
|
1529
|
-
};
|
|
1530
|
-
try {
|
|
1531
|
-
let service = ensureServiceIsRunning();
|
|
1532
|
-
defaultWD = worker_threads.workerData.defaultWD, parentPort2.on("message", (msg) => {
|
|
1533
|
-
(async () => {
|
|
1534
|
-
let { sharedBuffer, id, command, args } = msg, sharedBufferView = new Int32Array(sharedBuffer);
|
|
1535
|
-
try {
|
|
1536
|
-
switch (command) {
|
|
1537
|
-
case "build":
|
|
1538
|
-
workerPort.postMessage({ id, resolve: await service.build(args[0]) });
|
|
1539
|
-
break;
|
|
1540
|
-
case "transform":
|
|
1541
|
-
workerPort.postMessage({ id, resolve: await service.transform(args[0], args[1]) });
|
|
1542
|
-
break;
|
|
1543
|
-
case "formatMessages":
|
|
1544
|
-
workerPort.postMessage({ id, resolve: await service.formatMessages(args[0], args[1]) });
|
|
1545
|
-
break;
|
|
1546
|
-
case "analyzeMetafile":
|
|
1547
|
-
workerPort.postMessage({ id, resolve: await service.analyzeMetafile(args[0], args[1]) });
|
|
1548
|
-
break;
|
|
1549
|
-
default:
|
|
1550
|
-
throw new Error(`Invalid command: ${command}`);
|
|
1551
|
-
}
|
|
1552
|
-
} catch (reject) {
|
|
1553
|
-
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
|
1554
|
-
}
|
|
1555
|
-
Atomics.add(sharedBufferView, 0, 1), Atomics.notify(sharedBufferView, 0, 1 / 0);
|
|
1556
|
-
})();
|
|
1557
|
-
});
|
|
1558
|
-
} catch (reject) {
|
|
1559
|
-
parentPort2.on("message", (msg) => {
|
|
1560
|
-
let { sharedBuffer, id } = msg, sharedBufferView = new Int32Array(sharedBuffer);
|
|
1561
|
-
workerPort.postMessage({ id, reject, properties: extractProperties(reject) }), Atomics.add(sharedBufferView, 0, 1), Atomics.notify(sharedBufferView, 0, 1 / 0);
|
|
1562
|
-
});
|
|
1563
|
-
}
|
|
1564
|
-
};
|
|
1565
|
-
isInternalWorkerThread && startSyncServiceWorker();
|
|
1566
|
-
var node_default = node_exports;
|
|
1567
|
-
}
|
|
1568
|
-
});
|
|
7
|
+
// src/loader/hooks.ts
|
|
1569
8
|
var EXTENSIONS = [".js", ".ts"], inDev = false, parentPort, versions, esbuild;
|
|
1570
9
|
async function initialize({ port }) {
|
|
1571
|
-
inDev = process.env.NODE_ENV === "development", inDev && (parentPort = port, parentPort.on("message", onMessage), versions = /* @__PURE__ */ new Map(), esbuild = await
|
|
10
|
+
inDev = process.env.NODE_ENV === "development", inDev && (parentPort = port, parentPort.on("message", onMessage), versions = /* @__PURE__ */ new Map(), esbuild = await import('esbuild'));
|
|
1572
11
|
}
|
|
1573
12
|
async function resolve(specifier, context, nextResolve) {
|
|
1574
13
|
if (shouldSkip(specifier))
|