jiek 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- package/{tests/fixtures/node_modules/.pnpm/@jiek+loader-esbuild@1.0.0_esbuild@0.20.2/node_modules/@jiek/loader-esbuild/LICENSE → LICENSE} +1 -1
- package/package.json +13 -8
- package/src/commands/build.ts +0 -91
- package/src/commands/publish.ts +0 -79
- package/src/index.ts +0 -6
- package/src/inner.ts +0 -11
- package/src/merge-package-json.ts +0 -19
- package/src/rollup/index.ts +0 -162
- package/src/rollup/plugins/globals.ts +0 -34
- package/src/rollup/plugins/skip.ts +0 -23
- package/src/rollup/utils/commonOptions.ts +0 -9
- package/src/rollup/utils/externalResolver.ts +0 -11
- package/src/rollup/utils/globalResolver.ts +0 -24
- package/src/rollup/utils/withMinify.ts +0 -16
- package/tests/build.spec.ts +0 -28
- package/tests/fixtures/node_modules/.bin/jiek +0 -17
- package/tests/fixtures/node_modules/.jiek/jiek+test-foo.rollup.config.js +0 -31
- package/tests/fixtures/node_modules/.modules.yaml +0 -95
- package/tests/fixtures/node_modules/.pnpm/@esbuild+darwin-arm64@0.20.2/node_modules/@esbuild/darwin-arm64/README.md +0 -3
- package/tests/fixtures/node_modules/.pnpm/@esbuild+darwin-arm64@0.20.2/node_modules/@esbuild/darwin-arm64/bin/esbuild +0 -0
- package/tests/fixtures/node_modules/.pnpm/@esbuild+darwin-arm64@0.20.2/node_modules/@esbuild/darwin-arm64/package.json +0 -20
- package/tests/fixtures/node_modules/.pnpm/@jiek+loader-esbuild@1.0.0_esbuild@0.20.2/node_modules/@jiek/loader-esbuild/loader.js +0 -3
- package/tests/fixtures/node_modules/.pnpm/@jiek+loader-esbuild@1.0.0_esbuild@0.20.2/node_modules/@jiek/loader-esbuild/package.json +0 -8
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/LICENSE +0 -20
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/README.md +0 -481
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/package.json +0 -59
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/browser.js +0 -269
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/common.js +0 -274
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/index.js +0 -10
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/node.js +0 -263
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/LICENSE +0 -21
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/README.md +0 -50
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/loader.d.ts +0 -3
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/loader.js +0 -15
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/node.d.ts +0 -23
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/node.js +0 -4926
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/loader.js +0 -1
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/node_modules/.bin/esbuild +0 -14
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/package.json +0 -46
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/register.js +0 -3
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/LICENSE.md +0 -21
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/README.md +0 -3
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/bin/esbuild +0 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/install.js +0 -288
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.d.ts +0 -703
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js +0 -2436
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/node_modules/.bin/esbuild +0 -14
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/package.json +0 -46
- package/tests/fixtures/node_modules/.pnpm/lock.yaml +0 -291
- package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/index.js +0 -162
- package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/license.md +0 -21
- package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/package.json +0 -37
- package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/readme.md +0 -60
- package/tests/fixtures/node_modules/.pnpm/node_modules/.bin/esbuild +0 -14
- package/tests/fixtures/package.json +0 -8
- package/tests/fixtures/packages/bar/package.json +0 -4
- package/tests/fixtures/packages/foo/dist/index.d.ts +0 -3
- package/tests/fixtures/packages/foo/dist/index.esm.d.ts +0 -3
- package/tests/fixtures/packages/foo/dist/index.esm.js +0 -6
- package/tests/fixtures/packages/foo/dist/index.esm.js.map +0 -1
- package/tests/fixtures/packages/foo/dist/index.esm.min.js +0 -2
- package/tests/fixtures/packages/foo/dist/index.esm.min.js.map +0 -1
- package/tests/fixtures/packages/foo/dist/index.iife.js +0 -15
- package/tests/fixtures/packages/foo/dist/index.iife.js.map +0 -1
- package/tests/fixtures/packages/foo/dist/index.iife.min.js +0 -2
- package/tests/fixtures/packages/foo/dist/index.iife.min.js.map +0 -1
- package/tests/fixtures/packages/foo/dist/index.umd.js +0 -16
- package/tests/fixtures/packages/foo/dist/index.umd.js.map +0 -1
- package/tests/fixtures/packages/foo/dist/index.umd.min.js +0 -2
- package/tests/fixtures/packages/foo/dist/index.umd.min.js.map +0 -1
- package/tests/fixtures/packages/foo/package.json +0 -7
- package/tests/fixtures/packages/foo/src/index.ts +0 -3
- package/tests/fixtures/pnpm-workspace.yaml +0 -2
- package/tests/publish.spec.ts +0 -31
@@ -1,2436 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
|
30
|
-
// lib/npm/node.ts
|
31
|
-
var node_exports = {};
|
32
|
-
__export(node_exports, {
|
33
|
-
analyzeMetafile: () => analyzeMetafile,
|
34
|
-
analyzeMetafileSync: () => analyzeMetafileSync,
|
35
|
-
build: () => build,
|
36
|
-
buildSync: () => buildSync,
|
37
|
-
context: () => context,
|
38
|
-
default: () => node_default,
|
39
|
-
formatMessages: () => formatMessages,
|
40
|
-
formatMessagesSync: () => formatMessagesSync,
|
41
|
-
initialize: () => initialize,
|
42
|
-
stop: () => stop,
|
43
|
-
transform: () => transform,
|
44
|
-
transformSync: () => transformSync,
|
45
|
-
version: () => version
|
46
|
-
});
|
47
|
-
module.exports = __toCommonJS(node_exports);
|
48
|
-
|
49
|
-
// lib/shared/stdio_protocol.ts
|
50
|
-
function encodePacket(packet) {
|
51
|
-
let visit = (value) => {
|
52
|
-
if (value === null) {
|
53
|
-
bb.write8(0);
|
54
|
-
} else if (typeof value === "boolean") {
|
55
|
-
bb.write8(1);
|
56
|
-
bb.write8(+value);
|
57
|
-
} else if (typeof value === "number") {
|
58
|
-
bb.write8(2);
|
59
|
-
bb.write32(value | 0);
|
60
|
-
} else if (typeof value === "string") {
|
61
|
-
bb.write8(3);
|
62
|
-
bb.write(encodeUTF8(value));
|
63
|
-
} else if (value instanceof Uint8Array) {
|
64
|
-
bb.write8(4);
|
65
|
-
bb.write(value);
|
66
|
-
} else if (value instanceof Array) {
|
67
|
-
bb.write8(5);
|
68
|
-
bb.write32(value.length);
|
69
|
-
for (let item of value) {
|
70
|
-
visit(item);
|
71
|
-
}
|
72
|
-
} else {
|
73
|
-
let keys = Object.keys(value);
|
74
|
-
bb.write8(6);
|
75
|
-
bb.write32(keys.length);
|
76
|
-
for (let key of keys) {
|
77
|
-
bb.write(encodeUTF8(key));
|
78
|
-
visit(value[key]);
|
79
|
-
}
|
80
|
-
}
|
81
|
-
};
|
82
|
-
let bb = new ByteBuffer();
|
83
|
-
bb.write32(0);
|
84
|
-
bb.write32(packet.id << 1 | +!packet.isRequest);
|
85
|
-
visit(packet.value);
|
86
|
-
writeUInt32LE(bb.buf, bb.len - 4, 0);
|
87
|
-
return 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();
|
104
|
-
let value2 = [];
|
105
|
-
for (let i = 0; i < count; i++) {
|
106
|
-
value2.push(visit());
|
107
|
-
}
|
108
|
-
return value2;
|
109
|
-
}
|
110
|
-
case 6: {
|
111
|
-
let count = bb.read32();
|
112
|
-
let value2 = {};
|
113
|
-
for (let i = 0; i < count; i++) {
|
114
|
-
value2[decodeUTF8(bb.read())] = visit();
|
115
|
-
}
|
116
|
-
return value2;
|
117
|
-
}
|
118
|
-
default:
|
119
|
-
throw new Error("Invalid packet");
|
120
|
-
}
|
121
|
-
};
|
122
|
-
let bb = new ByteBuffer(bytes);
|
123
|
-
let id = bb.read32();
|
124
|
-
let isRequest = (id & 1) === 0;
|
125
|
-
id >>>= 1;
|
126
|
-
let value = visit();
|
127
|
-
if (bb.ptr !== bytes.length) {
|
128
|
-
throw new Error("Invalid packet");
|
129
|
-
}
|
130
|
-
return { id, isRequest, value };
|
131
|
-
}
|
132
|
-
var ByteBuffer = class {
|
133
|
-
constructor(buf = new Uint8Array(1024)) {
|
134
|
-
this.buf = buf;
|
135
|
-
this.len = 0;
|
136
|
-
this.ptr = 0;
|
137
|
-
}
|
138
|
-
_write(delta) {
|
139
|
-
if (this.len + delta > this.buf.length) {
|
140
|
-
let clone = new Uint8Array((this.len + delta) * 2);
|
141
|
-
clone.set(this.buf);
|
142
|
-
this.buf = clone;
|
143
|
-
}
|
144
|
-
this.len += delta;
|
145
|
-
return this.len - delta;
|
146
|
-
}
|
147
|
-
write8(value) {
|
148
|
-
let offset = this._write(1);
|
149
|
-
this.buf[offset] = value;
|
150
|
-
}
|
151
|
-
write32(value) {
|
152
|
-
let offset = this._write(4);
|
153
|
-
writeUInt32LE(this.buf, value, offset);
|
154
|
-
}
|
155
|
-
write(bytes) {
|
156
|
-
let offset = this._write(4 + bytes.length);
|
157
|
-
writeUInt32LE(this.buf, bytes.length, offset);
|
158
|
-
this.buf.set(bytes, offset + 4);
|
159
|
-
}
|
160
|
-
_read(delta) {
|
161
|
-
if (this.ptr + delta > this.buf.length) {
|
162
|
-
throw new Error("Invalid packet");
|
163
|
-
}
|
164
|
-
this.ptr += delta;
|
165
|
-
return this.ptr - delta;
|
166
|
-
}
|
167
|
-
read8() {
|
168
|
-
return this.buf[this._read(1)];
|
169
|
-
}
|
170
|
-
read32() {
|
171
|
-
return readUInt32LE(this.buf, this._read(4));
|
172
|
-
}
|
173
|
-
read() {
|
174
|
-
let length = this.read32();
|
175
|
-
let bytes = new Uint8Array(length);
|
176
|
-
let ptr = this._read(bytes.length);
|
177
|
-
bytes.set(this.buf.subarray(ptr, ptr + length));
|
178
|
-
return bytes;
|
179
|
-
}
|
180
|
-
};
|
181
|
-
var encodeUTF8;
|
182
|
-
var decodeUTF8;
|
183
|
-
var encodeInvariant;
|
184
|
-
if (typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined") {
|
185
|
-
let encoder = new TextEncoder();
|
186
|
-
let decoder = new TextDecoder();
|
187
|
-
encodeUTF8 = (text) => encoder.encode(text);
|
188
|
-
decodeUTF8 = (bytes) => decoder.decode(bytes);
|
189
|
-
encodeInvariant = 'new TextEncoder().encode("")';
|
190
|
-
} else if (typeof Buffer !== "undefined") {
|
191
|
-
encodeUTF8 = (text) => Buffer.from(text);
|
192
|
-
decodeUTF8 = (bytes) => {
|
193
|
-
let { buffer, byteOffset, byteLength } = bytes;
|
194
|
-
return Buffer.from(buffer, byteOffset, byteLength).toString();
|
195
|
-
};
|
196
|
-
encodeInvariant = 'Buffer.from("")';
|
197
|
-
} else {
|
198
|
-
throw new Error("No UTF-8 codec found");
|
199
|
-
}
|
200
|
-
if (!(encodeUTF8("") instanceof Uint8Array))
|
201
|
-
throw new Error(`Invariant violation: "${encodeInvariant} instanceof Uint8Array" is incorrectly false
|
202
|
-
|
203
|
-
This indicates that your JavaScript environment is broken. You cannot use
|
204
|
-
esbuild in this environment because esbuild relies on this invariant. This
|
205
|
-
is not a problem with esbuild. You need to fix your environment instead.
|
206
|
-
`);
|
207
|
-
function readUInt32LE(buffer, offset) {
|
208
|
-
return buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24;
|
209
|
-
}
|
210
|
-
function writeUInt32LE(buffer, value, offset) {
|
211
|
-
buffer[offset++] = value;
|
212
|
-
buffer[offset++] = value >> 8;
|
213
|
-
buffer[offset++] = value >> 16;
|
214
|
-
buffer[offset++] = value >> 24;
|
215
|
-
}
|
216
|
-
|
217
|
-
// lib/shared/common.ts
|
218
|
-
var quote = JSON.stringify;
|
219
|
-
var buildLogLevelDefault = "warning";
|
220
|
-
var transformLogLevelDefault = "silent";
|
221
|
-
function validateTarget(target) {
|
222
|
-
validateStringValue(target, "target");
|
223
|
-
if (target.indexOf(",") >= 0)
|
224
|
-
throw new Error(`Invalid target: ${target}`);
|
225
|
-
return target;
|
226
|
-
}
|
227
|
-
var canBeAnything = () => null;
|
228
|
-
var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
|
229
|
-
var mustBeString = (value) => typeof value === "string" ? null : "a string";
|
230
|
-
var mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object";
|
231
|
-
var mustBeInteger = (value) => typeof value === "number" && value === (value | 0) ? null : "an integer";
|
232
|
-
var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
|
233
|
-
var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
|
234
|
-
var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
|
235
|
-
var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
236
|
-
var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
|
237
|
-
var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
|
238
|
-
var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
|
239
|
-
var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
|
240
|
-
var mustBeStringOrArray = (value) => typeof value === "string" || Array.isArray(value) ? null : "a string or an array";
|
241
|
-
var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array";
|
242
|
-
var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof URL ? null : "a string or a URL";
|
243
|
-
function getFlag(object, keys, key, mustBeFn) {
|
244
|
-
let value = object[key];
|
245
|
-
keys[key + ""] = true;
|
246
|
-
if (value === void 0)
|
247
|
-
return void 0;
|
248
|
-
let mustBe = mustBeFn(value);
|
249
|
-
if (mustBe !== null)
|
250
|
-
throw new Error(`${quote(key)} must be ${mustBe}`);
|
251
|
-
return value;
|
252
|
-
}
|
253
|
-
function checkForInvalidFlags(object, keys, where) {
|
254
|
-
for (let key in object) {
|
255
|
-
if (!(key in keys)) {
|
256
|
-
throw new Error(`Invalid option ${where}: ${quote(key)}`);
|
257
|
-
}
|
258
|
-
}
|
259
|
-
}
|
260
|
-
function validateInitializeOptions(options) {
|
261
|
-
let keys = /* @__PURE__ */ Object.create(null);
|
262
|
-
let wasmURL = getFlag(options, keys, "wasmURL", mustBeStringOrURL);
|
263
|
-
let wasmModule = getFlag(options, keys, "wasmModule", mustBeWebAssemblyModule);
|
264
|
-
let worker = getFlag(options, keys, "worker", mustBeBoolean);
|
265
|
-
checkForInvalidFlags(options, keys, "in initialize() call");
|
266
|
-
return {
|
267
|
-
wasmURL,
|
268
|
-
wasmModule,
|
269
|
-
worker
|
270
|
-
};
|
271
|
-
}
|
272
|
-
function validateMangleCache(mangleCache) {
|
273
|
-
let validated;
|
274
|
-
if (mangleCache !== void 0) {
|
275
|
-
validated = /* @__PURE__ */ Object.create(null);
|
276
|
-
for (let key in mangleCache) {
|
277
|
-
let value = mangleCache[key];
|
278
|
-
if (typeof value === "string" || value === false) {
|
279
|
-
validated[key] = value;
|
280
|
-
} else {
|
281
|
-
throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`);
|
282
|
-
}
|
283
|
-
}
|
284
|
-
}
|
285
|
-
return validated;
|
286
|
-
}
|
287
|
-
function pushLogFlags(flags, options, keys, isTTY2, logLevelDefault) {
|
288
|
-
let color = getFlag(options, keys, "color", mustBeBoolean);
|
289
|
-
let logLevel = getFlag(options, keys, "logLevel", mustBeString);
|
290
|
-
let logLimit = getFlag(options, keys, "logLimit", mustBeInteger);
|
291
|
-
if (color !== void 0)
|
292
|
-
flags.push(`--color=${color}`);
|
293
|
-
else if (isTTY2)
|
294
|
-
flags.push(`--color=true`);
|
295
|
-
flags.push(`--log-level=${logLevel || logLevelDefault}`);
|
296
|
-
flags.push(`--log-limit=${logLimit || 0}`);
|
297
|
-
}
|
298
|
-
function validateStringValue(value, what, key) {
|
299
|
-
if (typeof value !== "string") {
|
300
|
-
throw new Error(`Expected value for ${what}${key !== void 0 ? " " + quote(key) : ""} to be a string, got ${typeof value} instead`);
|
301
|
-
}
|
302
|
-
return value;
|
303
|
-
}
|
304
|
-
function pushCommonFlags(flags, options, keys) {
|
305
|
-
let legalComments = getFlag(options, keys, "legalComments", mustBeString);
|
306
|
-
let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
|
307
|
-
let sourcesContent = getFlag(options, keys, "sourcesContent", mustBeBoolean);
|
308
|
-
let target = getFlag(options, keys, "target", mustBeStringOrArray);
|
309
|
-
let format = getFlag(options, keys, "format", mustBeString);
|
310
|
-
let globalName = getFlag(options, keys, "globalName", mustBeString);
|
311
|
-
let mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp);
|
312
|
-
let reserveProps = getFlag(options, keys, "reserveProps", mustBeRegExp);
|
313
|
-
let mangleQuoted = getFlag(options, keys, "mangleQuoted", mustBeBoolean);
|
314
|
-
let minify = getFlag(options, keys, "minify", mustBeBoolean);
|
315
|
-
let minifySyntax = getFlag(options, keys, "minifySyntax", mustBeBoolean);
|
316
|
-
let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
|
317
|
-
let minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean);
|
318
|
-
let lineLimit = getFlag(options, keys, "lineLimit", mustBeInteger);
|
319
|
-
let drop = getFlag(options, keys, "drop", mustBeArray);
|
320
|
-
let dropLabels = getFlag(options, keys, "dropLabels", mustBeArray);
|
321
|
-
let charset = getFlag(options, keys, "charset", mustBeString);
|
322
|
-
let treeShaking = getFlag(options, keys, "treeShaking", mustBeBoolean);
|
323
|
-
let ignoreAnnotations = getFlag(options, keys, "ignoreAnnotations", mustBeBoolean);
|
324
|
-
let jsx = getFlag(options, keys, "jsx", mustBeString);
|
325
|
-
let jsxFactory = getFlag(options, keys, "jsxFactory", mustBeString);
|
326
|
-
let jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString);
|
327
|
-
let jsxImportSource = getFlag(options, keys, "jsxImportSource", mustBeString);
|
328
|
-
let jsxDev = getFlag(options, keys, "jsxDev", mustBeBoolean);
|
329
|
-
let jsxSideEffects = getFlag(options, keys, "jsxSideEffects", mustBeBoolean);
|
330
|
-
let define = getFlag(options, keys, "define", mustBeObject);
|
331
|
-
let logOverride = getFlag(options, keys, "logOverride", mustBeObject);
|
332
|
-
let supported = getFlag(options, keys, "supported", mustBeObject);
|
333
|
-
let pure = getFlag(options, keys, "pure", mustBeArray);
|
334
|
-
let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
|
335
|
-
let platform = getFlag(options, keys, "platform", mustBeString);
|
336
|
-
let tsconfigRaw = getFlag(options, keys, "tsconfigRaw", mustBeStringOrObject);
|
337
|
-
if (legalComments)
|
338
|
-
flags.push(`--legal-comments=${legalComments}`);
|
339
|
-
if (sourceRoot !== void 0)
|
340
|
-
flags.push(`--source-root=${sourceRoot}`);
|
341
|
-
if (sourcesContent !== void 0)
|
342
|
-
flags.push(`--sources-content=${sourcesContent}`);
|
343
|
-
if (target) {
|
344
|
-
if (Array.isArray(target))
|
345
|
-
flags.push(`--target=${Array.from(target).map(validateTarget).join(",")}`);
|
346
|
-
else
|
347
|
-
flags.push(`--target=${validateTarget(target)}`);
|
348
|
-
}
|
349
|
-
if (format)
|
350
|
-
flags.push(`--format=${format}`);
|
351
|
-
if (globalName)
|
352
|
-
flags.push(`--global-name=${globalName}`);
|
353
|
-
if (platform)
|
354
|
-
flags.push(`--platform=${platform}`);
|
355
|
-
if (tsconfigRaw)
|
356
|
-
flags.push(`--tsconfig-raw=${typeof tsconfigRaw === "string" ? tsconfigRaw : JSON.stringify(tsconfigRaw)}`);
|
357
|
-
if (minify)
|
358
|
-
flags.push("--minify");
|
359
|
-
if (minifySyntax)
|
360
|
-
flags.push("--minify-syntax");
|
361
|
-
if (minifyWhitespace)
|
362
|
-
flags.push("--minify-whitespace");
|
363
|
-
if (minifyIdentifiers)
|
364
|
-
flags.push("--minify-identifiers");
|
365
|
-
if (lineLimit)
|
366
|
-
flags.push(`--line-limit=${lineLimit}`);
|
367
|
-
if (charset)
|
368
|
-
flags.push(`--charset=${charset}`);
|
369
|
-
if (treeShaking !== void 0)
|
370
|
-
flags.push(`--tree-shaking=${treeShaking}`);
|
371
|
-
if (ignoreAnnotations)
|
372
|
-
flags.push(`--ignore-annotations`);
|
373
|
-
if (drop)
|
374
|
-
for (let what of drop)
|
375
|
-
flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
376
|
-
if (dropLabels)
|
377
|
-
flags.push(`--drop-labels=${Array.from(dropLabels).map((what) => validateStringValue(what, "dropLabels")).join(",")}`);
|
378
|
-
if (mangleProps)
|
379
|
-
flags.push(`--mangle-props=${mangleProps.source}`);
|
380
|
-
if (reserveProps)
|
381
|
-
flags.push(`--reserve-props=${reserveProps.source}`);
|
382
|
-
if (mangleQuoted !== void 0)
|
383
|
-
flags.push(`--mangle-quoted=${mangleQuoted}`);
|
384
|
-
if (jsx)
|
385
|
-
flags.push(`--jsx=${jsx}`);
|
386
|
-
if (jsxFactory)
|
387
|
-
flags.push(`--jsx-factory=${jsxFactory}`);
|
388
|
-
if (jsxFragment)
|
389
|
-
flags.push(`--jsx-fragment=${jsxFragment}`);
|
390
|
-
if (jsxImportSource)
|
391
|
-
flags.push(`--jsx-import-source=${jsxImportSource}`);
|
392
|
-
if (jsxDev)
|
393
|
-
flags.push(`--jsx-dev`);
|
394
|
-
if (jsxSideEffects)
|
395
|
-
flags.push(`--jsx-side-effects`);
|
396
|
-
if (define) {
|
397
|
-
for (let key in define) {
|
398
|
-
if (key.indexOf("=") >= 0)
|
399
|
-
throw new Error(`Invalid define: ${key}`);
|
400
|
-
flags.push(`--define:${key}=${validateStringValue(define[key], "define", key)}`);
|
401
|
-
}
|
402
|
-
}
|
403
|
-
if (logOverride) {
|
404
|
-
for (let key in logOverride) {
|
405
|
-
if (key.indexOf("=") >= 0)
|
406
|
-
throw new Error(`Invalid log override: ${key}`);
|
407
|
-
flags.push(`--log-override:${key}=${validateStringValue(logOverride[key], "log override", key)}`);
|
408
|
-
}
|
409
|
-
}
|
410
|
-
if (supported) {
|
411
|
-
for (let key in supported) {
|
412
|
-
if (key.indexOf("=") >= 0)
|
413
|
-
throw new Error(`Invalid supported: ${key}`);
|
414
|
-
const value = supported[key];
|
415
|
-
if (typeof value !== "boolean")
|
416
|
-
throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
|
417
|
-
flags.push(`--supported:${key}=${value}`);
|
418
|
-
}
|
419
|
-
}
|
420
|
-
if (pure)
|
421
|
-
for (let fn of pure)
|
422
|
-
flags.push(`--pure:${validateStringValue(fn, "pure")}`);
|
423
|
-
if (keepNames)
|
424
|
-
flags.push(`--keep-names`);
|
425
|
-
}
|
426
|
-
function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeDefault) {
|
427
|
-
var _a2;
|
428
|
-
let flags = [];
|
429
|
-
let entries = [];
|
430
|
-
let keys = /* @__PURE__ */ Object.create(null);
|
431
|
-
let stdinContents = null;
|
432
|
-
let stdinResolveDir = null;
|
433
|
-
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
434
|
-
pushCommonFlags(flags, options, keys);
|
435
|
-
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
436
|
-
let bundle = getFlag(options, keys, "bundle", mustBeBoolean);
|
437
|
-
let splitting = getFlag(options, keys, "splitting", mustBeBoolean);
|
438
|
-
let preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean);
|
439
|
-
let metafile = getFlag(options, keys, "metafile", mustBeBoolean);
|
440
|
-
let outfile = getFlag(options, keys, "outfile", mustBeString);
|
441
|
-
let outdir = getFlag(options, keys, "outdir", mustBeString);
|
442
|
-
let outbase = getFlag(options, keys, "outbase", mustBeString);
|
443
|
-
let tsconfig = getFlag(options, keys, "tsconfig", mustBeString);
|
444
|
-
let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArray);
|
445
|
-
let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArray);
|
446
|
-
let mainFields = getFlag(options, keys, "mainFields", mustBeArray);
|
447
|
-
let conditions = getFlag(options, keys, "conditions", mustBeArray);
|
448
|
-
let external = getFlag(options, keys, "external", mustBeArray);
|
449
|
-
let packages = getFlag(options, keys, "packages", mustBeString);
|
450
|
-
let alias = getFlag(options, keys, "alias", mustBeObject);
|
451
|
-
let loader = getFlag(options, keys, "loader", mustBeObject);
|
452
|
-
let outExtension = getFlag(options, keys, "outExtension", mustBeObject);
|
453
|
-
let publicPath = getFlag(options, keys, "publicPath", mustBeString);
|
454
|
-
let entryNames = getFlag(options, keys, "entryNames", mustBeString);
|
455
|
-
let chunkNames = getFlag(options, keys, "chunkNames", mustBeString);
|
456
|
-
let assetNames = getFlag(options, keys, "assetNames", mustBeString);
|
457
|
-
let inject = getFlag(options, keys, "inject", mustBeArray);
|
458
|
-
let banner = getFlag(options, keys, "banner", mustBeObject);
|
459
|
-
let footer = getFlag(options, keys, "footer", mustBeObject);
|
460
|
-
let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
|
461
|
-
let absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString);
|
462
|
-
let stdin = getFlag(options, keys, "stdin", mustBeObject);
|
463
|
-
let write = (_a2 = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a2 : writeDefault;
|
464
|
-
let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean);
|
465
|
-
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
466
|
-
keys.plugins = true;
|
467
|
-
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
468
|
-
if (sourcemap)
|
469
|
-
flags.push(`--sourcemap${sourcemap === true ? "" : `=${sourcemap}`}`);
|
470
|
-
if (bundle)
|
471
|
-
flags.push("--bundle");
|
472
|
-
if (allowOverwrite)
|
473
|
-
flags.push("--allow-overwrite");
|
474
|
-
if (splitting)
|
475
|
-
flags.push("--splitting");
|
476
|
-
if (preserveSymlinks)
|
477
|
-
flags.push("--preserve-symlinks");
|
478
|
-
if (metafile)
|
479
|
-
flags.push(`--metafile`);
|
480
|
-
if (outfile)
|
481
|
-
flags.push(`--outfile=${outfile}`);
|
482
|
-
if (outdir)
|
483
|
-
flags.push(`--outdir=${outdir}`);
|
484
|
-
if (outbase)
|
485
|
-
flags.push(`--outbase=${outbase}`);
|
486
|
-
if (tsconfig)
|
487
|
-
flags.push(`--tsconfig=${tsconfig}`);
|
488
|
-
if (packages)
|
489
|
-
flags.push(`--packages=${packages}`);
|
490
|
-
if (resolveExtensions) {
|
491
|
-
let values = [];
|
492
|
-
for (let value of resolveExtensions) {
|
493
|
-
validateStringValue(value, "resolve extension");
|
494
|
-
if (value.indexOf(",") >= 0)
|
495
|
-
throw new Error(`Invalid resolve extension: ${value}`);
|
496
|
-
values.push(value);
|
497
|
-
}
|
498
|
-
flags.push(`--resolve-extensions=${values.join(",")}`);
|
499
|
-
}
|
500
|
-
if (publicPath)
|
501
|
-
flags.push(`--public-path=${publicPath}`);
|
502
|
-
if (entryNames)
|
503
|
-
flags.push(`--entry-names=${entryNames}`);
|
504
|
-
if (chunkNames)
|
505
|
-
flags.push(`--chunk-names=${chunkNames}`);
|
506
|
-
if (assetNames)
|
507
|
-
flags.push(`--asset-names=${assetNames}`);
|
508
|
-
if (mainFields) {
|
509
|
-
let values = [];
|
510
|
-
for (let value of mainFields) {
|
511
|
-
validateStringValue(value, "main field");
|
512
|
-
if (value.indexOf(",") >= 0)
|
513
|
-
throw new Error(`Invalid main field: ${value}`);
|
514
|
-
values.push(value);
|
515
|
-
}
|
516
|
-
flags.push(`--main-fields=${values.join(",")}`);
|
517
|
-
}
|
518
|
-
if (conditions) {
|
519
|
-
let values = [];
|
520
|
-
for (let value of conditions) {
|
521
|
-
validateStringValue(value, "condition");
|
522
|
-
if (value.indexOf(",") >= 0)
|
523
|
-
throw new Error(`Invalid condition: ${value}`);
|
524
|
-
values.push(value);
|
525
|
-
}
|
526
|
-
flags.push(`--conditions=${values.join(",")}`);
|
527
|
-
}
|
528
|
-
if (external)
|
529
|
-
for (let name of external)
|
530
|
-
flags.push(`--external:${validateStringValue(name, "external")}`);
|
531
|
-
if (alias) {
|
532
|
-
for (let old in alias) {
|
533
|
-
if (old.indexOf("=") >= 0)
|
534
|
-
throw new Error(`Invalid package name in alias: ${old}`);
|
535
|
-
flags.push(`--alias:${old}=${validateStringValue(alias[old], "alias", old)}`);
|
536
|
-
}
|
537
|
-
}
|
538
|
-
if (banner) {
|
539
|
-
for (let type in banner) {
|
540
|
-
if (type.indexOf("=") >= 0)
|
541
|
-
throw new Error(`Invalid banner file type: ${type}`);
|
542
|
-
flags.push(`--banner:${type}=${validateStringValue(banner[type], "banner", type)}`);
|
543
|
-
}
|
544
|
-
}
|
545
|
-
if (footer) {
|
546
|
-
for (let type in footer) {
|
547
|
-
if (type.indexOf("=") >= 0)
|
548
|
-
throw new Error(`Invalid footer file type: ${type}`);
|
549
|
-
flags.push(`--footer:${type}=${validateStringValue(footer[type], "footer", type)}`);
|
550
|
-
}
|
551
|
-
}
|
552
|
-
if (inject)
|
553
|
-
for (let path3 of inject)
|
554
|
-
flags.push(`--inject:${validateStringValue(path3, "inject")}`);
|
555
|
-
if (loader) {
|
556
|
-
for (let ext in loader) {
|
557
|
-
if (ext.indexOf("=") >= 0)
|
558
|
-
throw new Error(`Invalid loader extension: ${ext}`);
|
559
|
-
flags.push(`--loader:${ext}=${validateStringValue(loader[ext], "loader", ext)}`);
|
560
|
-
}
|
561
|
-
}
|
562
|
-
if (outExtension) {
|
563
|
-
for (let ext in outExtension) {
|
564
|
-
if (ext.indexOf("=") >= 0)
|
565
|
-
throw new Error(`Invalid out extension: ${ext}`);
|
566
|
-
flags.push(`--out-extension:${ext}=${validateStringValue(outExtension[ext], "out extension", ext)}`);
|
567
|
-
}
|
568
|
-
}
|
569
|
-
if (entryPoints) {
|
570
|
-
if (Array.isArray(entryPoints)) {
|
571
|
-
for (let i = 0, n = entryPoints.length; i < n; i++) {
|
572
|
-
let entryPoint = entryPoints[i];
|
573
|
-
if (typeof entryPoint === "object" && entryPoint !== null) {
|
574
|
-
let entryPointKeys = /* @__PURE__ */ Object.create(null);
|
575
|
-
let input = getFlag(entryPoint, entryPointKeys, "in", mustBeString);
|
576
|
-
let output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
|
577
|
-
checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i);
|
578
|
-
if (input === void 0)
|
579
|
-
throw new Error('Missing property "in" for entry point at index ' + i);
|
580
|
-
if (output === void 0)
|
581
|
-
throw new Error('Missing property "out" for entry point at index ' + i);
|
582
|
-
entries.push([output, input]);
|
583
|
-
} else {
|
584
|
-
entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
|
585
|
-
}
|
586
|
-
}
|
587
|
-
} else {
|
588
|
-
for (let key in entryPoints) {
|
589
|
-
entries.push([key, validateStringValue(entryPoints[key], "entry point", key)]);
|
590
|
-
}
|
591
|
-
}
|
592
|
-
}
|
593
|
-
if (stdin) {
|
594
|
-
let stdinKeys = /* @__PURE__ */ Object.create(null);
|
595
|
-
let contents = getFlag(stdin, stdinKeys, "contents", mustBeStringOrUint8Array);
|
596
|
-
let resolveDir = getFlag(stdin, stdinKeys, "resolveDir", mustBeString);
|
597
|
-
let sourcefile = getFlag(stdin, stdinKeys, "sourcefile", mustBeString);
|
598
|
-
let loader2 = getFlag(stdin, stdinKeys, "loader", mustBeString);
|
599
|
-
checkForInvalidFlags(stdin, stdinKeys, 'in "stdin" object');
|
600
|
-
if (sourcefile)
|
601
|
-
flags.push(`--sourcefile=${sourcefile}`);
|
602
|
-
if (loader2)
|
603
|
-
flags.push(`--loader=${loader2}`);
|
604
|
-
if (resolveDir)
|
605
|
-
stdinResolveDir = resolveDir;
|
606
|
-
if (typeof contents === "string")
|
607
|
-
stdinContents = encodeUTF8(contents);
|
608
|
-
else if (contents instanceof Uint8Array)
|
609
|
-
stdinContents = contents;
|
610
|
-
}
|
611
|
-
let nodePaths = [];
|
612
|
-
if (nodePathsInput) {
|
613
|
-
for (let value of nodePathsInput) {
|
614
|
-
value += "";
|
615
|
-
nodePaths.push(value);
|
616
|
-
}
|
617
|
-
}
|
618
|
-
return {
|
619
|
-
entries,
|
620
|
-
flags,
|
621
|
-
write,
|
622
|
-
stdinContents,
|
623
|
-
stdinResolveDir,
|
624
|
-
absWorkingDir,
|
625
|
-
nodePaths,
|
626
|
-
mangleCache: validateMangleCache(mangleCache)
|
627
|
-
};
|
628
|
-
}
|
629
|
-
function flagsForTransformOptions(callName, options, isTTY2, logLevelDefault) {
|
630
|
-
let flags = [];
|
631
|
-
let keys = /* @__PURE__ */ Object.create(null);
|
632
|
-
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
633
|
-
pushCommonFlags(flags, options, keys);
|
634
|
-
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
635
|
-
let sourcefile = getFlag(options, keys, "sourcefile", mustBeString);
|
636
|
-
let loader = getFlag(options, keys, "loader", mustBeString);
|
637
|
-
let banner = getFlag(options, keys, "banner", mustBeString);
|
638
|
-
let footer = getFlag(options, keys, "footer", mustBeString);
|
639
|
-
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
640
|
-
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
641
|
-
if (sourcemap)
|
642
|
-
flags.push(`--sourcemap=${sourcemap === true ? "external" : sourcemap}`);
|
643
|
-
if (sourcefile)
|
644
|
-
flags.push(`--sourcefile=${sourcefile}`);
|
645
|
-
if (loader)
|
646
|
-
flags.push(`--loader=${loader}`);
|
647
|
-
if (banner)
|
648
|
-
flags.push(`--banner=${banner}`);
|
649
|
-
if (footer)
|
650
|
-
flags.push(`--footer=${footer}`);
|
651
|
-
return {
|
652
|
-
flags,
|
653
|
-
mangleCache: validateMangleCache(mangleCache)
|
654
|
-
};
|
655
|
-
}
|
656
|
-
function createChannel(streamIn) {
|
657
|
-
const requestCallbacksByKey = {};
|
658
|
-
const closeData = { didClose: false, reason: "" };
|
659
|
-
let responseCallbacks = {};
|
660
|
-
let nextRequestID = 0;
|
661
|
-
let nextBuildKey = 0;
|
662
|
-
let stdout = new Uint8Array(16 * 1024);
|
663
|
-
let stdoutUsed = 0;
|
664
|
-
let readFromStdout = (chunk) => {
|
665
|
-
let limit = stdoutUsed + chunk.length;
|
666
|
-
if (limit > stdout.length) {
|
667
|
-
let swap = new Uint8Array(limit * 2);
|
668
|
-
swap.set(stdout);
|
669
|
-
stdout = swap;
|
670
|
-
}
|
671
|
-
stdout.set(chunk, stdoutUsed);
|
672
|
-
stdoutUsed += chunk.length;
|
673
|
-
let offset = 0;
|
674
|
-
while (offset + 4 <= stdoutUsed) {
|
675
|
-
let length = readUInt32LE(stdout, offset);
|
676
|
-
if (offset + 4 + length > stdoutUsed) {
|
677
|
-
break;
|
678
|
-
}
|
679
|
-
offset += 4;
|
680
|
-
handleIncomingPacket(stdout.subarray(offset, offset + length));
|
681
|
-
offset += length;
|
682
|
-
}
|
683
|
-
if (offset > 0) {
|
684
|
-
stdout.copyWithin(0, offset, stdoutUsed);
|
685
|
-
stdoutUsed -= offset;
|
686
|
-
}
|
687
|
-
};
|
688
|
-
let afterClose = (error) => {
|
689
|
-
closeData.didClose = true;
|
690
|
-
if (error)
|
691
|
-
closeData.reason = ": " + (error.message || error);
|
692
|
-
const text = "The service was stopped" + closeData.reason;
|
693
|
-
for (let id in responseCallbacks) {
|
694
|
-
responseCallbacks[id](text, null);
|
695
|
-
}
|
696
|
-
responseCallbacks = {};
|
697
|
-
};
|
698
|
-
let sendRequest = (refs, value, callback) => {
|
699
|
-
if (closeData.didClose)
|
700
|
-
return callback("The service is no longer running" + closeData.reason, null);
|
701
|
-
let id = nextRequestID++;
|
702
|
-
responseCallbacks[id] = (error, response) => {
|
703
|
-
try {
|
704
|
-
callback(error, response);
|
705
|
-
} finally {
|
706
|
-
if (refs)
|
707
|
-
refs.unref();
|
708
|
-
}
|
709
|
-
};
|
710
|
-
if (refs)
|
711
|
-
refs.ref();
|
712
|
-
streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
|
713
|
-
};
|
714
|
-
let sendResponse = (id, value) => {
|
715
|
-
if (closeData.didClose)
|
716
|
-
throw new Error("The service is no longer running" + closeData.reason);
|
717
|
-
streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
|
718
|
-
};
|
719
|
-
let handleRequest = async (id, request) => {
|
720
|
-
try {
|
721
|
-
if (request.command === "ping") {
|
722
|
-
sendResponse(id, {});
|
723
|
-
return;
|
724
|
-
}
|
725
|
-
if (typeof request.key === "number") {
|
726
|
-
const requestCallbacks = requestCallbacksByKey[request.key];
|
727
|
-
if (!requestCallbacks) {
|
728
|
-
return;
|
729
|
-
}
|
730
|
-
const callback = requestCallbacks[request.command];
|
731
|
-
if (callback) {
|
732
|
-
await callback(id, request);
|
733
|
-
return;
|
734
|
-
}
|
735
|
-
}
|
736
|
-
throw new Error(`Invalid command: ` + request.command);
|
737
|
-
} catch (e) {
|
738
|
-
const errors = [extractErrorMessageV8(e, streamIn, null, void 0, "")];
|
739
|
-
try {
|
740
|
-
sendResponse(id, { errors });
|
741
|
-
} catch {
|
742
|
-
}
|
743
|
-
}
|
744
|
-
};
|
745
|
-
let isFirstPacket = true;
|
746
|
-
let handleIncomingPacket = (bytes) => {
|
747
|
-
if (isFirstPacket) {
|
748
|
-
isFirstPacket = false;
|
749
|
-
let binaryVersion = String.fromCharCode(...bytes);
|
750
|
-
if (binaryVersion !== "0.20.2") {
|
751
|
-
throw new Error(`Cannot start service: Host version "${"0.20.2"}" does not match binary version ${quote(binaryVersion)}`);
|
752
|
-
}
|
753
|
-
return;
|
754
|
-
}
|
755
|
-
let packet = decodePacket(bytes);
|
756
|
-
if (packet.isRequest) {
|
757
|
-
handleRequest(packet.id, packet.value);
|
758
|
-
} else {
|
759
|
-
let callback = responseCallbacks[packet.id];
|
760
|
-
delete responseCallbacks[packet.id];
|
761
|
-
if (packet.value.error)
|
762
|
-
callback(packet.value.error, {});
|
763
|
-
else
|
764
|
-
callback(null, packet.value);
|
765
|
-
}
|
766
|
-
};
|
767
|
-
let buildOrContext = ({ callName, refs, options, isTTY: isTTY2, defaultWD: defaultWD2, callback }) => {
|
768
|
-
let refCount = 0;
|
769
|
-
const buildKey = nextBuildKey++;
|
770
|
-
const requestCallbacks = {};
|
771
|
-
const buildRefs = {
|
772
|
-
ref() {
|
773
|
-
if (++refCount === 1) {
|
774
|
-
if (refs)
|
775
|
-
refs.ref();
|
776
|
-
}
|
777
|
-
},
|
778
|
-
unref() {
|
779
|
-
if (--refCount === 0) {
|
780
|
-
delete requestCallbacksByKey[buildKey];
|
781
|
-
if (refs)
|
782
|
-
refs.unref();
|
783
|
-
}
|
784
|
-
}
|
785
|
-
};
|
786
|
-
requestCallbacksByKey[buildKey] = requestCallbacks;
|
787
|
-
buildRefs.ref();
|
788
|
-
buildOrContextImpl(
|
789
|
-
callName,
|
790
|
-
buildKey,
|
791
|
-
sendRequest,
|
792
|
-
sendResponse,
|
793
|
-
buildRefs,
|
794
|
-
streamIn,
|
795
|
-
requestCallbacks,
|
796
|
-
options,
|
797
|
-
isTTY2,
|
798
|
-
defaultWD2,
|
799
|
-
(err, res) => {
|
800
|
-
try {
|
801
|
-
callback(err, res);
|
802
|
-
} finally {
|
803
|
-
buildRefs.unref();
|
804
|
-
}
|
805
|
-
}
|
806
|
-
);
|
807
|
-
};
|
808
|
-
let transform2 = ({ callName, refs, input, options, isTTY: isTTY2, fs: fs3, callback }) => {
|
809
|
-
const details = createObjectStash();
|
810
|
-
let start = (inputPath) => {
|
811
|
-
try {
|
812
|
-
if (typeof input !== "string" && !(input instanceof Uint8Array))
|
813
|
-
throw new Error('The input to "transform" must be a string or a Uint8Array');
|
814
|
-
let {
|
815
|
-
flags,
|
816
|
-
mangleCache
|
817
|
-
} = flagsForTransformOptions(callName, options, isTTY2, transformLogLevelDefault);
|
818
|
-
let request = {
|
819
|
-
command: "transform",
|
820
|
-
flags,
|
821
|
-
inputFS: inputPath !== null,
|
822
|
-
input: inputPath !== null ? encodeUTF8(inputPath) : typeof input === "string" ? encodeUTF8(input) : input
|
823
|
-
};
|
824
|
-
if (mangleCache)
|
825
|
-
request.mangleCache = mangleCache;
|
826
|
-
sendRequest(refs, request, (error, response) => {
|
827
|
-
if (error)
|
828
|
-
return callback(new Error(error), null);
|
829
|
-
let errors = replaceDetailsInMessages(response.errors, details);
|
830
|
-
let warnings = replaceDetailsInMessages(response.warnings, details);
|
831
|
-
let outstanding = 1;
|
832
|
-
let next = () => {
|
833
|
-
if (--outstanding === 0) {
|
834
|
-
let result = {
|
835
|
-
warnings,
|
836
|
-
code: response.code,
|
837
|
-
map: response.map,
|
838
|
-
mangleCache: void 0,
|
839
|
-
legalComments: void 0
|
840
|
-
};
|
841
|
-
if ("legalComments" in response)
|
842
|
-
result.legalComments = response == null ? void 0 : response.legalComments;
|
843
|
-
if (response.mangleCache)
|
844
|
-
result.mangleCache = response == null ? void 0 : response.mangleCache;
|
845
|
-
callback(null, result);
|
846
|
-
}
|
847
|
-
};
|
848
|
-
if (errors.length > 0)
|
849
|
-
return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
|
850
|
-
if (response.codeFS) {
|
851
|
-
outstanding++;
|
852
|
-
fs3.readFile(response.code, (err, contents) => {
|
853
|
-
if (err !== null) {
|
854
|
-
callback(err, null);
|
855
|
-
} else {
|
856
|
-
response.code = contents;
|
857
|
-
next();
|
858
|
-
}
|
859
|
-
});
|
860
|
-
}
|
861
|
-
if (response.mapFS) {
|
862
|
-
outstanding++;
|
863
|
-
fs3.readFile(response.map, (err, contents) => {
|
864
|
-
if (err !== null) {
|
865
|
-
callback(err, null);
|
866
|
-
} else {
|
867
|
-
response.map = contents;
|
868
|
-
next();
|
869
|
-
}
|
870
|
-
});
|
871
|
-
}
|
872
|
-
next();
|
873
|
-
});
|
874
|
-
} catch (e) {
|
875
|
-
let flags = [];
|
876
|
-
try {
|
877
|
-
pushLogFlags(flags, options, {}, isTTY2, transformLogLevelDefault);
|
878
|
-
} catch {
|
879
|
-
}
|
880
|
-
const error = extractErrorMessageV8(e, streamIn, details, void 0, "");
|
881
|
-
sendRequest(refs, { command: "error", flags, error }, () => {
|
882
|
-
error.detail = details.load(error.detail);
|
883
|
-
callback(failureErrorWithLog("Transform failed", [error], []), null);
|
884
|
-
});
|
885
|
-
}
|
886
|
-
};
|
887
|
-
if ((typeof input === "string" || input instanceof Uint8Array) && input.length > 1024 * 1024) {
|
888
|
-
let next = start;
|
889
|
-
start = () => fs3.writeFile(input, next);
|
890
|
-
}
|
891
|
-
start(null);
|
892
|
-
};
|
893
|
-
let formatMessages2 = ({ callName, refs, messages, options, callback }) => {
|
894
|
-
if (!options)
|
895
|
-
throw new Error(`Missing second argument in ${callName}() call`);
|
896
|
-
let keys = {};
|
897
|
-
let kind = getFlag(options, keys, "kind", mustBeString);
|
898
|
-
let color = getFlag(options, keys, "color", mustBeBoolean);
|
899
|
-
let terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger);
|
900
|
-
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
901
|
-
if (kind === void 0)
|
902
|
-
throw new Error(`Missing "kind" in ${callName}() call`);
|
903
|
-
if (kind !== "error" && kind !== "warning")
|
904
|
-
throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
|
905
|
-
let request = {
|
906
|
-
command: "format-msgs",
|
907
|
-
messages: sanitizeMessages(messages, "messages", null, "", terminalWidth),
|
908
|
-
isWarning: kind === "warning"
|
909
|
-
};
|
910
|
-
if (color !== void 0)
|
911
|
-
request.color = color;
|
912
|
-
if (terminalWidth !== void 0)
|
913
|
-
request.terminalWidth = terminalWidth;
|
914
|
-
sendRequest(refs, request, (error, response) => {
|
915
|
-
if (error)
|
916
|
-
return callback(new Error(error), null);
|
917
|
-
callback(null, response.messages);
|
918
|
-
});
|
919
|
-
};
|
920
|
-
let analyzeMetafile2 = ({ callName, refs, metafile, options, callback }) => {
|
921
|
-
if (options === void 0)
|
922
|
-
options = {};
|
923
|
-
let keys = {};
|
924
|
-
let color = getFlag(options, keys, "color", mustBeBoolean);
|
925
|
-
let verbose = getFlag(options, keys, "verbose", mustBeBoolean);
|
926
|
-
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
927
|
-
let request = {
|
928
|
-
command: "analyze-metafile",
|
929
|
-
metafile
|
930
|
-
};
|
931
|
-
if (color !== void 0)
|
932
|
-
request.color = color;
|
933
|
-
if (verbose !== void 0)
|
934
|
-
request.verbose = verbose;
|
935
|
-
sendRequest(refs, request, (error, response) => {
|
936
|
-
if (error)
|
937
|
-
return callback(new Error(error), null);
|
938
|
-
callback(null, response.result);
|
939
|
-
});
|
940
|
-
};
|
941
|
-
return {
|
942
|
-
readFromStdout,
|
943
|
-
afterClose,
|
944
|
-
service: {
|
945
|
-
buildOrContext,
|
946
|
-
transform: transform2,
|
947
|
-
formatMessages: formatMessages2,
|
948
|
-
analyzeMetafile: analyzeMetafile2
|
949
|
-
}
|
950
|
-
};
|
951
|
-
}
|
952
|
-
function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, isTTY2, defaultWD2, callback) {
|
953
|
-
const details = createObjectStash();
|
954
|
-
const isContext = callName === "context";
|
955
|
-
const handleError = (e, pluginName) => {
|
956
|
-
const flags = [];
|
957
|
-
try {
|
958
|
-
pushLogFlags(flags, options, {}, isTTY2, buildLogLevelDefault);
|
959
|
-
} catch {
|
960
|
-
}
|
961
|
-
const message = extractErrorMessageV8(e, streamIn, details, void 0, pluginName);
|
962
|
-
sendRequest(refs, { command: "error", flags, error: message }, () => {
|
963
|
-
message.detail = details.load(message.detail);
|
964
|
-
callback(failureErrorWithLog(isContext ? "Context failed" : "Build failed", [message], []), null);
|
965
|
-
});
|
966
|
-
};
|
967
|
-
let plugins;
|
968
|
-
if (typeof options === "object") {
|
969
|
-
const value = options.plugins;
|
970
|
-
if (value !== void 0) {
|
971
|
-
if (!Array.isArray(value))
|
972
|
-
return handleError(new Error(`"plugins" must be an array`), "");
|
973
|
-
plugins = value;
|
974
|
-
}
|
975
|
-
}
|
976
|
-
if (plugins && plugins.length > 0) {
|
977
|
-
if (streamIn.isSync)
|
978
|
-
return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
979
|
-
handlePlugins(
|
980
|
-
buildKey,
|
981
|
-
sendRequest,
|
982
|
-
sendResponse,
|
983
|
-
refs,
|
984
|
-
streamIn,
|
985
|
-
requestCallbacks,
|
986
|
-
options,
|
987
|
-
plugins,
|
988
|
-
details
|
989
|
-
).then(
|
990
|
-
(result) => {
|
991
|
-
if (!result.ok)
|
992
|
-
return handleError(result.error, result.pluginName);
|
993
|
-
try {
|
994
|
-
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
|
995
|
-
} catch (e) {
|
996
|
-
handleError(e, "");
|
997
|
-
}
|
998
|
-
},
|
999
|
-
(e) => handleError(e, "")
|
1000
|
-
);
|
1001
|
-
return;
|
1002
|
-
}
|
1003
|
-
try {
|
1004
|
-
buildOrContextContinue(null, (result, done) => done([], []), () => {
|
1005
|
-
});
|
1006
|
-
} catch (e) {
|
1007
|
-
handleError(e, "");
|
1008
|
-
}
|
1009
|
-
function buildOrContextContinue(requestPlugins, runOnEndCallbacks, scheduleOnDisposeCallbacks) {
|
1010
|
-
const writeDefault = streamIn.hasFS;
|
1011
|
-
const {
|
1012
|
-
entries,
|
1013
|
-
flags,
|
1014
|
-
write,
|
1015
|
-
stdinContents,
|
1016
|
-
stdinResolveDir,
|
1017
|
-
absWorkingDir,
|
1018
|
-
nodePaths,
|
1019
|
-
mangleCache
|
1020
|
-
} = flagsForBuildOptions(callName, options, isTTY2, buildLogLevelDefault, writeDefault);
|
1021
|
-
if (write && !streamIn.hasFS)
|
1022
|
-
throw new Error(`The "write" option is unavailable in this environment`);
|
1023
|
-
const request = {
|
1024
|
-
command: "build",
|
1025
|
-
key: buildKey,
|
1026
|
-
entries,
|
1027
|
-
flags,
|
1028
|
-
write,
|
1029
|
-
stdinContents,
|
1030
|
-
stdinResolveDir,
|
1031
|
-
absWorkingDir: absWorkingDir || defaultWD2,
|
1032
|
-
nodePaths,
|
1033
|
-
context: isContext
|
1034
|
-
};
|
1035
|
-
if (requestPlugins)
|
1036
|
-
request.plugins = requestPlugins;
|
1037
|
-
if (mangleCache)
|
1038
|
-
request.mangleCache = mangleCache;
|
1039
|
-
const buildResponseToResult = (response, callback2) => {
|
1040
|
-
const result = {
|
1041
|
-
errors: replaceDetailsInMessages(response.errors, details),
|
1042
|
-
warnings: replaceDetailsInMessages(response.warnings, details),
|
1043
|
-
outputFiles: void 0,
|
1044
|
-
metafile: void 0,
|
1045
|
-
mangleCache: void 0
|
1046
|
-
};
|
1047
|
-
const originalErrors = result.errors.slice();
|
1048
|
-
const originalWarnings = result.warnings.slice();
|
1049
|
-
if (response.outputFiles)
|
1050
|
-
result.outputFiles = response.outputFiles.map(convertOutputFiles);
|
1051
|
-
if (response.metafile)
|
1052
|
-
result.metafile = JSON.parse(response.metafile);
|
1053
|
-
if (response.mangleCache)
|
1054
|
-
result.mangleCache = response.mangleCache;
|
1055
|
-
if (response.writeToStdout !== void 0)
|
1056
|
-
console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
1057
|
-
runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
|
1058
|
-
if (originalErrors.length > 0 || onEndErrors.length > 0) {
|
1059
|
-
const error = failureErrorWithLog("Build failed", originalErrors.concat(onEndErrors), originalWarnings.concat(onEndWarnings));
|
1060
|
-
return callback2(error, null, onEndErrors, onEndWarnings);
|
1061
|
-
}
|
1062
|
-
callback2(null, result, onEndErrors, onEndWarnings);
|
1063
|
-
});
|
1064
|
-
};
|
1065
|
-
let latestResultPromise;
|
1066
|
-
let provideLatestResult;
|
1067
|
-
if (isContext)
|
1068
|
-
requestCallbacks["on-end"] = (id, request2) => new Promise((resolve) => {
|
1069
|
-
buildResponseToResult(request2, (err, result, onEndErrors, onEndWarnings) => {
|
1070
|
-
const response = {
|
1071
|
-
errors: onEndErrors,
|
1072
|
-
warnings: onEndWarnings
|
1073
|
-
};
|
1074
|
-
if (provideLatestResult)
|
1075
|
-
provideLatestResult(err, result);
|
1076
|
-
latestResultPromise = void 0;
|
1077
|
-
provideLatestResult = void 0;
|
1078
|
-
sendResponse(id, response);
|
1079
|
-
resolve();
|
1080
|
-
});
|
1081
|
-
});
|
1082
|
-
sendRequest(refs, request, (error, response) => {
|
1083
|
-
if (error)
|
1084
|
-
return callback(new Error(error), null);
|
1085
|
-
if (!isContext) {
|
1086
|
-
return buildResponseToResult(response, (err, res) => {
|
1087
|
-
scheduleOnDisposeCallbacks();
|
1088
|
-
return callback(err, res);
|
1089
|
-
});
|
1090
|
-
}
|
1091
|
-
if (response.errors.length > 0) {
|
1092
|
-
return callback(failureErrorWithLog("Context failed", response.errors, response.warnings), null);
|
1093
|
-
}
|
1094
|
-
let didDispose = false;
|
1095
|
-
const result = {
|
1096
|
-
rebuild: () => {
|
1097
|
-
if (!latestResultPromise)
|
1098
|
-
latestResultPromise = new Promise((resolve, reject) => {
|
1099
|
-
let settlePromise;
|
1100
|
-
provideLatestResult = (err, result2) => {
|
1101
|
-
if (!settlePromise)
|
1102
|
-
settlePromise = () => err ? reject(err) : resolve(result2);
|
1103
|
-
};
|
1104
|
-
const triggerAnotherBuild = () => {
|
1105
|
-
const request2 = {
|
1106
|
-
command: "rebuild",
|
1107
|
-
key: buildKey
|
1108
|
-
};
|
1109
|
-
sendRequest(refs, request2, (error2, response2) => {
|
1110
|
-
if (error2) {
|
1111
|
-
reject(new Error(error2));
|
1112
|
-
} else if (settlePromise) {
|
1113
|
-
settlePromise();
|
1114
|
-
} else {
|
1115
|
-
triggerAnotherBuild();
|
1116
|
-
}
|
1117
|
-
});
|
1118
|
-
};
|
1119
|
-
triggerAnotherBuild();
|
1120
|
-
});
|
1121
|
-
return latestResultPromise;
|
1122
|
-
},
|
1123
|
-
watch: (options2 = {}) => new Promise((resolve, reject) => {
|
1124
|
-
if (!streamIn.hasFS)
|
1125
|
-
throw new Error(`Cannot use the "watch" API in this environment`);
|
1126
|
-
const keys = {};
|
1127
|
-
checkForInvalidFlags(options2, keys, `in watch() call`);
|
1128
|
-
const request2 = {
|
1129
|
-
command: "watch",
|
1130
|
-
key: buildKey
|
1131
|
-
};
|
1132
|
-
sendRequest(refs, request2, (error2) => {
|
1133
|
-
if (error2)
|
1134
|
-
reject(new Error(error2));
|
1135
|
-
else
|
1136
|
-
resolve(void 0);
|
1137
|
-
});
|
1138
|
-
}),
|
1139
|
-
serve: (options2 = {}) => new Promise((resolve, reject) => {
|
1140
|
-
if (!streamIn.hasFS)
|
1141
|
-
throw new Error(`Cannot use the "serve" API in this environment`);
|
1142
|
-
const keys = {};
|
1143
|
-
const port = getFlag(options2, keys, "port", mustBeInteger);
|
1144
|
-
const host = getFlag(options2, keys, "host", mustBeString);
|
1145
|
-
const servedir = getFlag(options2, keys, "servedir", mustBeString);
|
1146
|
-
const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
|
1147
|
-
const certfile = getFlag(options2, keys, "certfile", mustBeString);
|
1148
|
-
const fallback = getFlag(options2, keys, "fallback", mustBeString);
|
1149
|
-
const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
|
1150
|
-
checkForInvalidFlags(options2, keys, `in serve() call`);
|
1151
|
-
const request2 = {
|
1152
|
-
command: "serve",
|
1153
|
-
key: buildKey,
|
1154
|
-
onRequest: !!onRequest
|
1155
|
-
};
|
1156
|
-
if (port !== void 0)
|
1157
|
-
request2.port = port;
|
1158
|
-
if (host !== void 0)
|
1159
|
-
request2.host = host;
|
1160
|
-
if (servedir !== void 0)
|
1161
|
-
request2.servedir = servedir;
|
1162
|
-
if (keyfile !== void 0)
|
1163
|
-
request2.keyfile = keyfile;
|
1164
|
-
if (certfile !== void 0)
|
1165
|
-
request2.certfile = certfile;
|
1166
|
-
if (fallback !== void 0)
|
1167
|
-
request2.fallback = fallback;
|
1168
|
-
sendRequest(refs, request2, (error2, response2) => {
|
1169
|
-
if (error2)
|
1170
|
-
return reject(new Error(error2));
|
1171
|
-
if (onRequest) {
|
1172
|
-
requestCallbacks["serve-request"] = (id, request3) => {
|
1173
|
-
onRequest(request3.args);
|
1174
|
-
sendResponse(id, {});
|
1175
|
-
};
|
1176
|
-
}
|
1177
|
-
resolve(response2);
|
1178
|
-
});
|
1179
|
-
}),
|
1180
|
-
cancel: () => new Promise((resolve) => {
|
1181
|
-
if (didDispose)
|
1182
|
-
return resolve();
|
1183
|
-
const request2 = {
|
1184
|
-
command: "cancel",
|
1185
|
-
key: buildKey
|
1186
|
-
};
|
1187
|
-
sendRequest(refs, request2, () => {
|
1188
|
-
resolve();
|
1189
|
-
});
|
1190
|
-
}),
|
1191
|
-
dispose: () => new Promise((resolve) => {
|
1192
|
-
if (didDispose)
|
1193
|
-
return resolve();
|
1194
|
-
didDispose = true;
|
1195
|
-
const request2 = {
|
1196
|
-
command: "dispose",
|
1197
|
-
key: buildKey
|
1198
|
-
};
|
1199
|
-
sendRequest(refs, request2, () => {
|
1200
|
-
resolve();
|
1201
|
-
scheduleOnDisposeCallbacks();
|
1202
|
-
refs.unref();
|
1203
|
-
});
|
1204
|
-
})
|
1205
|
-
};
|
1206
|
-
refs.ref();
|
1207
|
-
callback(null, result);
|
1208
|
-
});
|
1209
|
-
}
|
1210
|
-
}
|
1211
|
-
var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, initialOptions, plugins, details) => {
|
1212
|
-
let onStartCallbacks = [];
|
1213
|
-
let onEndCallbacks = [];
|
1214
|
-
let onResolveCallbacks = {};
|
1215
|
-
let onLoadCallbacks = {};
|
1216
|
-
let onDisposeCallbacks = [];
|
1217
|
-
let nextCallbackID = 0;
|
1218
|
-
let i = 0;
|
1219
|
-
let requestPlugins = [];
|
1220
|
-
let isSetupDone = false;
|
1221
|
-
plugins = [...plugins];
|
1222
|
-
for (let item of plugins) {
|
1223
|
-
let keys = {};
|
1224
|
-
if (typeof item !== "object")
|
1225
|
-
throw new Error(`Plugin at index ${i} must be an object`);
|
1226
|
-
const name = getFlag(item, keys, "name", mustBeString);
|
1227
|
-
if (typeof name !== "string" || name === "")
|
1228
|
-
throw new Error(`Plugin at index ${i} is missing a name`);
|
1229
|
-
try {
|
1230
|
-
let setup = getFlag(item, keys, "setup", mustBeFunction);
|
1231
|
-
if (typeof setup !== "function")
|
1232
|
-
throw new Error(`Plugin is missing a setup function`);
|
1233
|
-
checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
|
1234
|
-
let plugin = {
|
1235
|
-
name,
|
1236
|
-
onStart: false,
|
1237
|
-
onEnd: false,
|
1238
|
-
onResolve: [],
|
1239
|
-
onLoad: []
|
1240
|
-
};
|
1241
|
-
i++;
|
1242
|
-
let resolve = (path3, options = {}) => {
|
1243
|
-
if (!isSetupDone)
|
1244
|
-
throw new Error('Cannot call "resolve" before plugin setup has completed');
|
1245
|
-
if (typeof path3 !== "string")
|
1246
|
-
throw new Error(`The path to resolve must be a string`);
|
1247
|
-
let keys2 = /* @__PURE__ */ Object.create(null);
|
1248
|
-
let pluginName = getFlag(options, keys2, "pluginName", mustBeString);
|
1249
|
-
let importer = getFlag(options, keys2, "importer", mustBeString);
|
1250
|
-
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
1251
|
-
let resolveDir = getFlag(options, keys2, "resolveDir", mustBeString);
|
1252
|
-
let kind = getFlag(options, keys2, "kind", mustBeString);
|
1253
|
-
let pluginData = getFlag(options, keys2, "pluginData", canBeAnything);
|
1254
|
-
checkForInvalidFlags(options, keys2, "in resolve() call");
|
1255
|
-
return new Promise((resolve2, reject) => {
|
1256
|
-
const request = {
|
1257
|
-
command: "resolve",
|
1258
|
-
path: path3,
|
1259
|
-
key: buildKey,
|
1260
|
-
pluginName: name
|
1261
|
-
};
|
1262
|
-
if (pluginName != null)
|
1263
|
-
request.pluginName = pluginName;
|
1264
|
-
if (importer != null)
|
1265
|
-
request.importer = importer;
|
1266
|
-
if (namespace != null)
|
1267
|
-
request.namespace = namespace;
|
1268
|
-
if (resolveDir != null)
|
1269
|
-
request.resolveDir = resolveDir;
|
1270
|
-
if (kind != null)
|
1271
|
-
request.kind = kind;
|
1272
|
-
else
|
1273
|
-
throw new Error(`Must specify "kind" when calling "resolve"`);
|
1274
|
-
if (pluginData != null)
|
1275
|
-
request.pluginData = details.store(pluginData);
|
1276
|
-
sendRequest(refs, request, (error, response) => {
|
1277
|
-
if (error !== null)
|
1278
|
-
reject(new Error(error));
|
1279
|
-
else
|
1280
|
-
resolve2({
|
1281
|
-
errors: replaceDetailsInMessages(response.errors, details),
|
1282
|
-
warnings: replaceDetailsInMessages(response.warnings, details),
|
1283
|
-
path: response.path,
|
1284
|
-
external: response.external,
|
1285
|
-
sideEffects: response.sideEffects,
|
1286
|
-
namespace: response.namespace,
|
1287
|
-
suffix: response.suffix,
|
1288
|
-
pluginData: details.load(response.pluginData)
|
1289
|
-
});
|
1290
|
-
});
|
1291
|
-
});
|
1292
|
-
};
|
1293
|
-
let promise = setup({
|
1294
|
-
initialOptions,
|
1295
|
-
resolve,
|
1296
|
-
onStart(callback) {
|
1297
|
-
let registeredText = `This error came from the "onStart" callback registered here:`;
|
1298
|
-
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
|
1299
|
-
onStartCallbacks.push({ name, callback, note: registeredNote });
|
1300
|
-
plugin.onStart = true;
|
1301
|
-
},
|
1302
|
-
onEnd(callback) {
|
1303
|
-
let registeredText = `This error came from the "onEnd" callback registered here:`;
|
1304
|
-
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
|
1305
|
-
onEndCallbacks.push({ name, callback, note: registeredNote });
|
1306
|
-
plugin.onEnd = true;
|
1307
|
-
},
|
1308
|
-
onResolve(options, callback) {
|
1309
|
-
let registeredText = `This error came from the "onResolve" callback registered here:`;
|
1310
|
-
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve");
|
1311
|
-
let keys2 = {};
|
1312
|
-
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
1313
|
-
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
1314
|
-
checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${quote(name)}`);
|
1315
|
-
if (filter == null)
|
1316
|
-
throw new Error(`onResolve() call is missing a filter`);
|
1317
|
-
let id = nextCallbackID++;
|
1318
|
-
onResolveCallbacks[id] = { name, callback, note: registeredNote };
|
1319
|
-
plugin.onResolve.push({ id, filter: filter.source, namespace: namespace || "" });
|
1320
|
-
},
|
1321
|
-
onLoad(options, callback) {
|
1322
|
-
let registeredText = `This error came from the "onLoad" callback registered here:`;
|
1323
|
-
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad");
|
1324
|
-
let keys2 = {};
|
1325
|
-
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
1326
|
-
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
1327
|
-
checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${quote(name)}`);
|
1328
|
-
if (filter == null)
|
1329
|
-
throw new Error(`onLoad() call is missing a filter`);
|
1330
|
-
let id = nextCallbackID++;
|
1331
|
-
onLoadCallbacks[id] = { name, callback, note: registeredNote };
|
1332
|
-
plugin.onLoad.push({ id, filter: filter.source, namespace: namespace || "" });
|
1333
|
-
},
|
1334
|
-
onDispose(callback) {
|
1335
|
-
onDisposeCallbacks.push(callback);
|
1336
|
-
},
|
1337
|
-
esbuild: streamIn.esbuild
|
1338
|
-
});
|
1339
|
-
if (promise)
|
1340
|
-
await promise;
|
1341
|
-
requestPlugins.push(plugin);
|
1342
|
-
} catch (e) {
|
1343
|
-
return { ok: false, error: e, pluginName: name };
|
1344
|
-
}
|
1345
|
-
}
|
1346
|
-
requestCallbacks["on-start"] = async (id, request) => {
|
1347
|
-
let response = { errors: [], warnings: [] };
|
1348
|
-
await Promise.all(onStartCallbacks.map(async ({ name, callback, note }) => {
|
1349
|
-
try {
|
1350
|
-
let result = await callback();
|
1351
|
-
if (result != null) {
|
1352
|
-
if (typeof result !== "object")
|
1353
|
-
throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
|
1354
|
-
let keys = {};
|
1355
|
-
let errors = getFlag(result, keys, "errors", mustBeArray);
|
1356
|
-
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
1357
|
-
checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${quote(name)}`);
|
1358
|
-
if (errors != null)
|
1359
|
-
response.errors.push(...sanitizeMessages(errors, "errors", details, name, void 0));
|
1360
|
-
if (warnings != null)
|
1361
|
-
response.warnings.push(...sanitizeMessages(warnings, "warnings", details, name, void 0));
|
1362
|
-
}
|
1363
|
-
} catch (e) {
|
1364
|
-
response.errors.push(extractErrorMessageV8(e, streamIn, details, note && note(), name));
|
1365
|
-
}
|
1366
|
-
}));
|
1367
|
-
sendResponse(id, response);
|
1368
|
-
};
|
1369
|
-
requestCallbacks["on-resolve"] = async (id, request) => {
|
1370
|
-
let response = {}, name = "", callback, note;
|
1371
|
-
for (let id2 of request.ids) {
|
1372
|
-
try {
|
1373
|
-
({ name, callback, note } = onResolveCallbacks[id2]);
|
1374
|
-
let result = await callback({
|
1375
|
-
path: request.path,
|
1376
|
-
importer: request.importer,
|
1377
|
-
namespace: request.namespace,
|
1378
|
-
resolveDir: request.resolveDir,
|
1379
|
-
kind: request.kind,
|
1380
|
-
pluginData: details.load(request.pluginData)
|
1381
|
-
});
|
1382
|
-
if (result != null) {
|
1383
|
-
if (typeof result !== "object")
|
1384
|
-
throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
|
1385
|
-
let keys = {};
|
1386
|
-
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
1387
|
-
let path3 = getFlag(result, keys, "path", mustBeString);
|
1388
|
-
let namespace = getFlag(result, keys, "namespace", mustBeString);
|
1389
|
-
let suffix = getFlag(result, keys, "suffix", mustBeString);
|
1390
|
-
let external = getFlag(result, keys, "external", mustBeBoolean);
|
1391
|
-
let sideEffects = getFlag(result, keys, "sideEffects", mustBeBoolean);
|
1392
|
-
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
1393
|
-
let errors = getFlag(result, keys, "errors", mustBeArray);
|
1394
|
-
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
1395
|
-
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
|
1396
|
-
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
|
1397
|
-
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
|
1398
|
-
response.id = id2;
|
1399
|
-
if (pluginName != null)
|
1400
|
-
response.pluginName = pluginName;
|
1401
|
-
if (path3 != null)
|
1402
|
-
response.path = path3;
|
1403
|
-
if (namespace != null)
|
1404
|
-
response.namespace = namespace;
|
1405
|
-
if (suffix != null)
|
1406
|
-
response.suffix = suffix;
|
1407
|
-
if (external != null)
|
1408
|
-
response.external = external;
|
1409
|
-
if (sideEffects != null)
|
1410
|
-
response.sideEffects = sideEffects;
|
1411
|
-
if (pluginData != null)
|
1412
|
-
response.pluginData = details.store(pluginData);
|
1413
|
-
if (errors != null)
|
1414
|
-
response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
1415
|
-
if (warnings != null)
|
1416
|
-
response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
1417
|
-
if (watchFiles != null)
|
1418
|
-
response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
1419
|
-
if (watchDirs != null)
|
1420
|
-
response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
1421
|
-
break;
|
1422
|
-
}
|
1423
|
-
} catch (e) {
|
1424
|
-
response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
|
1425
|
-
break;
|
1426
|
-
}
|
1427
|
-
}
|
1428
|
-
sendResponse(id, response);
|
1429
|
-
};
|
1430
|
-
requestCallbacks["on-load"] = async (id, request) => {
|
1431
|
-
let response = {}, name = "", callback, note;
|
1432
|
-
for (let id2 of request.ids) {
|
1433
|
-
try {
|
1434
|
-
({ name, callback, note } = onLoadCallbacks[id2]);
|
1435
|
-
let result = await callback({
|
1436
|
-
path: request.path,
|
1437
|
-
namespace: request.namespace,
|
1438
|
-
suffix: request.suffix,
|
1439
|
-
pluginData: details.load(request.pluginData),
|
1440
|
-
with: request.with
|
1441
|
-
});
|
1442
|
-
if (result != null) {
|
1443
|
-
if (typeof result !== "object")
|
1444
|
-
throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
|
1445
|
-
let keys = {};
|
1446
|
-
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
1447
|
-
let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
|
1448
|
-
let resolveDir = getFlag(result, keys, "resolveDir", mustBeString);
|
1449
|
-
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
1450
|
-
let loader = getFlag(result, keys, "loader", mustBeString);
|
1451
|
-
let errors = getFlag(result, keys, "errors", mustBeArray);
|
1452
|
-
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
1453
|
-
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
|
1454
|
-
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
|
1455
|
-
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
|
1456
|
-
response.id = id2;
|
1457
|
-
if (pluginName != null)
|
1458
|
-
response.pluginName = pluginName;
|
1459
|
-
if (contents instanceof Uint8Array)
|
1460
|
-
response.contents = contents;
|
1461
|
-
else if (contents != null)
|
1462
|
-
response.contents = encodeUTF8(contents);
|
1463
|
-
if (resolveDir != null)
|
1464
|
-
response.resolveDir = resolveDir;
|
1465
|
-
if (pluginData != null)
|
1466
|
-
response.pluginData = details.store(pluginData);
|
1467
|
-
if (loader != null)
|
1468
|
-
response.loader = loader;
|
1469
|
-
if (errors != null)
|
1470
|
-
response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
1471
|
-
if (warnings != null)
|
1472
|
-
response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
1473
|
-
if (watchFiles != null)
|
1474
|
-
response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
1475
|
-
if (watchDirs != null)
|
1476
|
-
response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
1477
|
-
break;
|
1478
|
-
}
|
1479
|
-
} catch (e) {
|
1480
|
-
response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
|
1481
|
-
break;
|
1482
|
-
}
|
1483
|
-
}
|
1484
|
-
sendResponse(id, response);
|
1485
|
-
};
|
1486
|
-
let runOnEndCallbacks = (result, done) => done([], []);
|
1487
|
-
if (onEndCallbacks.length > 0) {
|
1488
|
-
runOnEndCallbacks = (result, done) => {
|
1489
|
-
(async () => {
|
1490
|
-
const onEndErrors = [];
|
1491
|
-
const onEndWarnings = [];
|
1492
|
-
for (const { name, callback, note } of onEndCallbacks) {
|
1493
|
-
let newErrors;
|
1494
|
-
let newWarnings;
|
1495
|
-
try {
|
1496
|
-
const value = await callback(result);
|
1497
|
-
if (value != null) {
|
1498
|
-
if (typeof value !== "object")
|
1499
|
-
throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
|
1500
|
-
let keys = {};
|
1501
|
-
let errors = getFlag(value, keys, "errors", mustBeArray);
|
1502
|
-
let warnings = getFlag(value, keys, "warnings", mustBeArray);
|
1503
|
-
checkForInvalidFlags(value, keys, `from onEnd() callback in plugin ${quote(name)}`);
|
1504
|
-
if (errors != null)
|
1505
|
-
newErrors = sanitizeMessages(errors, "errors", details, name, void 0);
|
1506
|
-
if (warnings != null)
|
1507
|
-
newWarnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
1508
|
-
}
|
1509
|
-
} catch (e) {
|
1510
|
-
newErrors = [extractErrorMessageV8(e, streamIn, details, note && note(), name)];
|
1511
|
-
}
|
1512
|
-
if (newErrors) {
|
1513
|
-
onEndErrors.push(...newErrors);
|
1514
|
-
try {
|
1515
|
-
result.errors.push(...newErrors);
|
1516
|
-
} catch {
|
1517
|
-
}
|
1518
|
-
}
|
1519
|
-
if (newWarnings) {
|
1520
|
-
onEndWarnings.push(...newWarnings);
|
1521
|
-
try {
|
1522
|
-
result.warnings.push(...newWarnings);
|
1523
|
-
} catch {
|
1524
|
-
}
|
1525
|
-
}
|
1526
|
-
}
|
1527
|
-
done(onEndErrors, onEndWarnings);
|
1528
|
-
})();
|
1529
|
-
};
|
1530
|
-
}
|
1531
|
-
let scheduleOnDisposeCallbacks = () => {
|
1532
|
-
for (const cb of onDisposeCallbacks) {
|
1533
|
-
setTimeout(() => cb(), 0);
|
1534
|
-
}
|
1535
|
-
};
|
1536
|
-
isSetupDone = true;
|
1537
|
-
return {
|
1538
|
-
ok: true,
|
1539
|
-
requestPlugins,
|
1540
|
-
runOnEndCallbacks,
|
1541
|
-
scheduleOnDisposeCallbacks
|
1542
|
-
};
|
1543
|
-
};
|
1544
|
-
function createObjectStash() {
|
1545
|
-
const map = /* @__PURE__ */ new Map();
|
1546
|
-
let nextID = 0;
|
1547
|
-
return {
|
1548
|
-
load(id) {
|
1549
|
-
return map.get(id);
|
1550
|
-
},
|
1551
|
-
store(value) {
|
1552
|
-
if (value === void 0)
|
1553
|
-
return -1;
|
1554
|
-
const id = nextID++;
|
1555
|
-
map.set(id, value);
|
1556
|
-
return id;
|
1557
|
-
}
|
1558
|
-
};
|
1559
|
-
}
|
1560
|
-
function extractCallerV8(e, streamIn, ident) {
|
1561
|
-
let note;
|
1562
|
-
let tried = false;
|
1563
|
-
return () => {
|
1564
|
-
if (tried)
|
1565
|
-
return note;
|
1566
|
-
tried = true;
|
1567
|
-
try {
|
1568
|
-
let lines = (e.stack + "").split("\n");
|
1569
|
-
lines.splice(1, 1);
|
1570
|
-
let location = parseStackLinesV8(streamIn, lines, ident);
|
1571
|
-
if (location) {
|
1572
|
-
note = { text: e.message, location };
|
1573
|
-
return note;
|
1574
|
-
}
|
1575
|
-
} catch {
|
1576
|
-
}
|
1577
|
-
};
|
1578
|
-
}
|
1579
|
-
function extractErrorMessageV8(e, streamIn, stash, note, pluginName) {
|
1580
|
-
let text = "Internal error";
|
1581
|
-
let location = null;
|
1582
|
-
try {
|
1583
|
-
text = (e && e.message || e) + "";
|
1584
|
-
} catch {
|
1585
|
-
}
|
1586
|
-
try {
|
1587
|
-
location = parseStackLinesV8(streamIn, (e.stack + "").split("\n"), "");
|
1588
|
-
} catch {
|
1589
|
-
}
|
1590
|
-
return { id: "", pluginName, text, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1 };
|
1591
|
-
}
|
1592
|
-
function parseStackLinesV8(streamIn, lines, ident) {
|
1593
|
-
let at = " at ";
|
1594
|
-
if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at)) {
|
1595
|
-
for (let i = 1; i < lines.length; i++) {
|
1596
|
-
let line = lines[i];
|
1597
|
-
if (!line.startsWith(at))
|
1598
|
-
continue;
|
1599
|
-
line = line.slice(at.length);
|
1600
|
-
while (true) {
|
1601
|
-
let match = /^(?:new |async )?\S+ \((.*)\)$/.exec(line);
|
1602
|
-
if (match) {
|
1603
|
-
line = match[1];
|
1604
|
-
continue;
|
1605
|
-
}
|
1606
|
-
match = /^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(line);
|
1607
|
-
if (match) {
|
1608
|
-
line = match[1];
|
1609
|
-
continue;
|
1610
|
-
}
|
1611
|
-
match = /^(\S+):(\d+):(\d+)$/.exec(line);
|
1612
|
-
if (match) {
|
1613
|
-
let contents;
|
1614
|
-
try {
|
1615
|
-
contents = streamIn.readFileSync(match[1], "utf8");
|
1616
|
-
} catch {
|
1617
|
-
break;
|
1618
|
-
}
|
1619
|
-
let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || "";
|
1620
|
-
let column = +match[3] - 1;
|
1621
|
-
let length = lineText.slice(column, column + ident.length) === ident ? ident.length : 0;
|
1622
|
-
return {
|
1623
|
-
file: match[1],
|
1624
|
-
namespace: "file",
|
1625
|
-
line: +match[2],
|
1626
|
-
column: encodeUTF8(lineText.slice(0, column)).length,
|
1627
|
-
length: encodeUTF8(lineText.slice(column, column + length)).length,
|
1628
|
-
lineText: lineText + "\n" + lines.slice(1).join("\n"),
|
1629
|
-
suggestion: ""
|
1630
|
-
};
|
1631
|
-
}
|
1632
|
-
break;
|
1633
|
-
}
|
1634
|
-
}
|
1635
|
-
}
|
1636
|
-
return null;
|
1637
|
-
}
|
1638
|
-
function failureErrorWithLog(text, errors, warnings) {
|
1639
|
-
let limit = 5;
|
1640
|
-
text += errors.length < 1 ? "" : ` with ${errors.length} error${errors.length < 2 ? "" : "s"}:` + errors.slice(0, limit + 1).map((e, i) => {
|
1641
|
-
if (i === limit)
|
1642
|
-
return "\n...";
|
1643
|
-
if (!e.location)
|
1644
|
-
return `
|
1645
|
-
error: ${e.text}`;
|
1646
|
-
let { file, line, column } = e.location;
|
1647
|
-
let pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : "";
|
1648
|
-
return `
|
1649
|
-
${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`;
|
1650
|
-
}).join("");
|
1651
|
-
let error = new Error(text);
|
1652
|
-
for (const [key, value] of [["errors", errors], ["warnings", warnings]]) {
|
1653
|
-
Object.defineProperty(error, key, {
|
1654
|
-
configurable: true,
|
1655
|
-
enumerable: true,
|
1656
|
-
get: () => value,
|
1657
|
-
set: (value2) => Object.defineProperty(error, key, {
|
1658
|
-
configurable: true,
|
1659
|
-
enumerable: true,
|
1660
|
-
value: value2
|
1661
|
-
})
|
1662
|
-
});
|
1663
|
-
}
|
1664
|
-
return error;
|
1665
|
-
}
|
1666
|
-
function replaceDetailsInMessages(messages, stash) {
|
1667
|
-
for (const message of messages) {
|
1668
|
-
message.detail = stash.load(message.detail);
|
1669
|
-
}
|
1670
|
-
return messages;
|
1671
|
-
}
|
1672
|
-
function sanitizeLocation(location, where, terminalWidth) {
|
1673
|
-
if (location == null)
|
1674
|
-
return null;
|
1675
|
-
let keys = {};
|
1676
|
-
let file = getFlag(location, keys, "file", mustBeString);
|
1677
|
-
let namespace = getFlag(location, keys, "namespace", mustBeString);
|
1678
|
-
let line = getFlag(location, keys, "line", mustBeInteger);
|
1679
|
-
let column = getFlag(location, keys, "column", mustBeInteger);
|
1680
|
-
let length = getFlag(location, keys, "length", mustBeInteger);
|
1681
|
-
let lineText = getFlag(location, keys, "lineText", mustBeString);
|
1682
|
-
let suggestion = getFlag(location, keys, "suggestion", mustBeString);
|
1683
|
-
checkForInvalidFlags(location, keys, where);
|
1684
|
-
if (lineText) {
|
1685
|
-
const relevantASCII = lineText.slice(
|
1686
|
-
0,
|
1687
|
-
(column && column > 0 ? column : 0) + (length && length > 0 ? length : 0) + (terminalWidth && terminalWidth > 0 ? terminalWidth : 80)
|
1688
|
-
);
|
1689
|
-
if (!/[\x7F-\uFFFF]/.test(relevantASCII) && !/\n/.test(lineText)) {
|
1690
|
-
lineText = relevantASCII;
|
1691
|
-
}
|
1692
|
-
}
|
1693
|
-
return {
|
1694
|
-
file: file || "",
|
1695
|
-
namespace: namespace || "",
|
1696
|
-
line: line || 0,
|
1697
|
-
column: column || 0,
|
1698
|
-
length: length || 0,
|
1699
|
-
lineText: lineText || "",
|
1700
|
-
suggestion: suggestion || ""
|
1701
|
-
};
|
1702
|
-
}
|
1703
|
-
function sanitizeMessages(messages, property, stash, fallbackPluginName, terminalWidth) {
|
1704
|
-
let messagesClone = [];
|
1705
|
-
let index = 0;
|
1706
|
-
for (const message of messages) {
|
1707
|
-
let keys = {};
|
1708
|
-
let id = getFlag(message, keys, "id", mustBeString);
|
1709
|
-
let pluginName = getFlag(message, keys, "pluginName", mustBeString);
|
1710
|
-
let text = getFlag(message, keys, "text", mustBeString);
|
1711
|
-
let location = getFlag(message, keys, "location", mustBeObjectOrNull);
|
1712
|
-
let notes = getFlag(message, keys, "notes", mustBeArray);
|
1713
|
-
let detail = getFlag(message, keys, "detail", canBeAnything);
|
1714
|
-
let where = `in element ${index} of "${property}"`;
|
1715
|
-
checkForInvalidFlags(message, keys, where);
|
1716
|
-
let notesClone = [];
|
1717
|
-
if (notes) {
|
1718
|
-
for (const note of notes) {
|
1719
|
-
let noteKeys = {};
|
1720
|
-
let noteText = getFlag(note, noteKeys, "text", mustBeString);
|
1721
|
-
let noteLocation = getFlag(note, noteKeys, "location", mustBeObjectOrNull);
|
1722
|
-
checkForInvalidFlags(note, noteKeys, where);
|
1723
|
-
notesClone.push({
|
1724
|
-
text: noteText || "",
|
1725
|
-
location: sanitizeLocation(noteLocation, where, terminalWidth)
|
1726
|
-
});
|
1727
|
-
}
|
1728
|
-
}
|
1729
|
-
messagesClone.push({
|
1730
|
-
id: id || "",
|
1731
|
-
pluginName: pluginName || fallbackPluginName,
|
1732
|
-
text: text || "",
|
1733
|
-
location: sanitizeLocation(location, where, terminalWidth),
|
1734
|
-
notes: notesClone,
|
1735
|
-
detail: stash ? stash.store(detail) : -1
|
1736
|
-
});
|
1737
|
-
index++;
|
1738
|
-
}
|
1739
|
-
return messagesClone;
|
1740
|
-
}
|
1741
|
-
function sanitizeStringArray(values, property) {
|
1742
|
-
const result = [];
|
1743
|
-
for (const value of values) {
|
1744
|
-
if (typeof value !== "string")
|
1745
|
-
throw new Error(`${quote(property)} must be an array of strings`);
|
1746
|
-
result.push(value);
|
1747
|
-
}
|
1748
|
-
return result;
|
1749
|
-
}
|
1750
|
-
function convertOutputFiles({ path: path3, contents, hash }) {
|
1751
|
-
let text = null;
|
1752
|
-
return {
|
1753
|
-
path: path3,
|
1754
|
-
contents,
|
1755
|
-
hash,
|
1756
|
-
get text() {
|
1757
|
-
const binary = this.contents;
|
1758
|
-
if (text === null || binary !== contents) {
|
1759
|
-
contents = binary;
|
1760
|
-
text = decodeUTF8(binary);
|
1761
|
-
}
|
1762
|
-
return text;
|
1763
|
-
}
|
1764
|
-
};
|
1765
|
-
}
|
1766
|
-
|
1767
|
-
// lib/npm/node-platform.ts
|
1768
|
-
var fs = require("fs");
|
1769
|
-
var os = require("os");
|
1770
|
-
var path = require("path");
|
1771
|
-
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
1772
|
-
var isValidBinaryPath = (x) => !!x && x !== "/usr/bin/esbuild";
|
1773
|
-
var packageDarwin_arm64 = "@esbuild/darwin-arm64";
|
1774
|
-
var packageDarwin_x64 = "@esbuild/darwin-x64";
|
1775
|
-
var knownWindowsPackages = {
|
1776
|
-
"win32 arm64 LE": "@esbuild/win32-arm64",
|
1777
|
-
"win32 ia32 LE": "@esbuild/win32-ia32",
|
1778
|
-
"win32 x64 LE": "@esbuild/win32-x64"
|
1779
|
-
};
|
1780
|
-
var knownUnixlikePackages = {
|
1781
|
-
"aix ppc64 BE": "@esbuild/aix-ppc64",
|
1782
|
-
"android arm64 LE": "@esbuild/android-arm64",
|
1783
|
-
"darwin arm64 LE": "@esbuild/darwin-arm64",
|
1784
|
-
"darwin x64 LE": "@esbuild/darwin-x64",
|
1785
|
-
"freebsd arm64 LE": "@esbuild/freebsd-arm64",
|
1786
|
-
"freebsd x64 LE": "@esbuild/freebsd-x64",
|
1787
|
-
"linux arm LE": "@esbuild/linux-arm",
|
1788
|
-
"linux arm64 LE": "@esbuild/linux-arm64",
|
1789
|
-
"linux ia32 LE": "@esbuild/linux-ia32",
|
1790
|
-
"linux mips64el LE": "@esbuild/linux-mips64el",
|
1791
|
-
"linux ppc64 LE": "@esbuild/linux-ppc64",
|
1792
|
-
"linux riscv64 LE": "@esbuild/linux-riscv64",
|
1793
|
-
"linux s390x BE": "@esbuild/linux-s390x",
|
1794
|
-
"linux x64 LE": "@esbuild/linux-x64",
|
1795
|
-
"linux loong64 LE": "@esbuild/linux-loong64",
|
1796
|
-
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
1797
|
-
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
1798
|
-
"sunos x64 LE": "@esbuild/sunos-x64"
|
1799
|
-
};
|
1800
|
-
var knownWebAssemblyFallbackPackages = {
|
1801
|
-
"android arm LE": "@esbuild/android-arm",
|
1802
|
-
"android x64 LE": "@esbuild/android-x64"
|
1803
|
-
};
|
1804
|
-
function pkgAndSubpathForCurrentPlatform() {
|
1805
|
-
let pkg;
|
1806
|
-
let subpath;
|
1807
|
-
let isWASM = false;
|
1808
|
-
let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
1809
|
-
if (platformKey in knownWindowsPackages) {
|
1810
|
-
pkg = knownWindowsPackages[platformKey];
|
1811
|
-
subpath = "esbuild.exe";
|
1812
|
-
} else if (platformKey in knownUnixlikePackages) {
|
1813
|
-
pkg = knownUnixlikePackages[platformKey];
|
1814
|
-
subpath = "bin/esbuild";
|
1815
|
-
} else if (platformKey in knownWebAssemblyFallbackPackages) {
|
1816
|
-
pkg = knownWebAssemblyFallbackPackages[platformKey];
|
1817
|
-
subpath = "bin/esbuild";
|
1818
|
-
isWASM = true;
|
1819
|
-
} else {
|
1820
|
-
throw new Error(`Unsupported platform: ${platformKey}`);
|
1821
|
-
}
|
1822
|
-
return { pkg, subpath, isWASM };
|
1823
|
-
}
|
1824
|
-
function pkgForSomeOtherPlatform() {
|
1825
|
-
const libMainJS = require.resolve("esbuild");
|
1826
|
-
const nodeModulesDirectory = path.dirname(path.dirname(path.dirname(libMainJS)));
|
1827
|
-
if (path.basename(nodeModulesDirectory) === "node_modules") {
|
1828
|
-
for (const unixKey in knownUnixlikePackages) {
|
1829
|
-
try {
|
1830
|
-
const pkg = knownUnixlikePackages[unixKey];
|
1831
|
-
if (fs.existsSync(path.join(nodeModulesDirectory, pkg)))
|
1832
|
-
return pkg;
|
1833
|
-
} catch {
|
1834
|
-
}
|
1835
|
-
}
|
1836
|
-
for (const windowsKey in knownWindowsPackages) {
|
1837
|
-
try {
|
1838
|
-
const pkg = knownWindowsPackages[windowsKey];
|
1839
|
-
if (fs.existsSync(path.join(nodeModulesDirectory, pkg)))
|
1840
|
-
return pkg;
|
1841
|
-
} catch {
|
1842
|
-
}
|
1843
|
-
}
|
1844
|
-
}
|
1845
|
-
return null;
|
1846
|
-
}
|
1847
|
-
function downloadedBinPath(pkg, subpath) {
|
1848
|
-
const esbuildLibDir = path.dirname(require.resolve("esbuild"));
|
1849
|
-
return path.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
1850
|
-
}
|
1851
|
-
function generateBinPath() {
|
1852
|
-
if (isValidBinaryPath(ESBUILD_BINARY_PATH)) {
|
1853
|
-
if (!fs.existsSync(ESBUILD_BINARY_PATH)) {
|
1854
|
-
console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
|
1855
|
-
} else {
|
1856
|
-
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
|
1857
|
-
}
|
1858
|
-
}
|
1859
|
-
const { pkg, subpath, isWASM } = pkgAndSubpathForCurrentPlatform();
|
1860
|
-
let binPath;
|
1861
|
-
try {
|
1862
|
-
binPath = require.resolve(`${pkg}/${subpath}`);
|
1863
|
-
} catch (e) {
|
1864
|
-
binPath = downloadedBinPath(pkg, subpath);
|
1865
|
-
if (!fs.existsSync(binPath)) {
|
1866
|
-
try {
|
1867
|
-
require.resolve(pkg);
|
1868
|
-
} catch {
|
1869
|
-
const otherPkg = pkgForSomeOtherPlatform();
|
1870
|
-
if (otherPkg) {
|
1871
|
-
let suggestions = `
|
1872
|
-
Specifically the "${otherPkg}" package is present but this platform
|
1873
|
-
needs the "${pkg}" package instead. People often get into this
|
1874
|
-
situation by installing esbuild on Windows or macOS and copying "node_modules"
|
1875
|
-
into a Docker image that runs Linux, or by copying "node_modules" between
|
1876
|
-
Windows and WSL environments.
|
1877
|
-
|
1878
|
-
If you are installing with npm, you can try not copying the "node_modules"
|
1879
|
-
directory when you copy the files over, and running "npm ci" or "npm install"
|
1880
|
-
on the destination platform after the copy. Or you could consider using yarn
|
1881
|
-
instead of npm which has built-in support for installing a package on multiple
|
1882
|
-
platforms simultaneously.
|
1883
|
-
|
1884
|
-
If you are installing with yarn, you can try listing both this platform and the
|
1885
|
-
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
1886
|
-
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
1887
|
-
Keep in mind that this means multiple copies of esbuild will be present.
|
1888
|
-
`;
|
1889
|
-
if (pkg === packageDarwin_x64 && otherPkg === packageDarwin_arm64 || pkg === packageDarwin_arm64 && otherPkg === packageDarwin_x64) {
|
1890
|
-
suggestions = `
|
1891
|
-
Specifically the "${otherPkg}" package is present but this platform
|
1892
|
-
needs the "${pkg}" package instead. People often get into this
|
1893
|
-
situation by installing esbuild with npm running inside of Rosetta 2 and then
|
1894
|
-
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
|
1895
|
-
2 is Apple's on-the-fly x86_64-to-arm64 translation service).
|
1896
|
-
|
1897
|
-
If you are installing with npm, you can try ensuring that both npm and node are
|
1898
|
-
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
|
1899
|
-
changing how you installed npm and/or node. For example, installing node with
|
1900
|
-
the universal installer here should work: https://nodejs.org/en/download/. Or
|
1901
|
-
you could consider using yarn instead of npm which has built-in support for
|
1902
|
-
installing a package on multiple platforms simultaneously.
|
1903
|
-
|
1904
|
-
If you are installing with yarn, you can try listing both "arm64" and "x64"
|
1905
|
-
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
|
1906
|
-
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
1907
|
-
Keep in mind that this means multiple copies of esbuild will be present.
|
1908
|
-
`;
|
1909
|
-
}
|
1910
|
-
throw new Error(`
|
1911
|
-
You installed esbuild for another platform than the one you're currently using.
|
1912
|
-
This won't work because esbuild is written with native code and needs to
|
1913
|
-
install a platform-specific binary executable.
|
1914
|
-
${suggestions}
|
1915
|
-
Another alternative is to use the "esbuild-wasm" package instead, which works
|
1916
|
-
the same way on all platforms. But it comes with a heavy performance cost and
|
1917
|
-
can sometimes be 10x slower than the "esbuild" package, so you may also not
|
1918
|
-
want to do that.
|
1919
|
-
`);
|
1920
|
-
}
|
1921
|
-
throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
|
1922
|
-
|
1923
|
-
If you are installing esbuild with npm, make sure that you don't specify the
|
1924
|
-
"--no-optional" or "--omit=optional" flags. The "optionalDependencies" feature
|
1925
|
-
of "package.json" is used by esbuild to install the correct binary executable
|
1926
|
-
for your current platform.`);
|
1927
|
-
}
|
1928
|
-
throw e;
|
1929
|
-
}
|
1930
|
-
}
|
1931
|
-
if (/\.zip\//.test(binPath)) {
|
1932
|
-
let pnpapi;
|
1933
|
-
try {
|
1934
|
-
pnpapi = require("pnpapi");
|
1935
|
-
} catch (e) {
|
1936
|
-
}
|
1937
|
-
if (pnpapi) {
|
1938
|
-
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
|
1939
|
-
const binTargetPath = path.join(
|
1940
|
-
root,
|
1941
|
-
"node_modules",
|
1942
|
-
".cache",
|
1943
|
-
"esbuild",
|
1944
|
-
`pnpapi-${pkg.replace("/", "-")}-${"0.20.2"}-${path.basename(subpath)}`
|
1945
|
-
);
|
1946
|
-
if (!fs.existsSync(binTargetPath)) {
|
1947
|
-
fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
|
1948
|
-
fs.copyFileSync(binPath, binTargetPath);
|
1949
|
-
fs.chmodSync(binTargetPath, 493);
|
1950
|
-
}
|
1951
|
-
return { binPath: binTargetPath, isWASM };
|
1952
|
-
}
|
1953
|
-
}
|
1954
|
-
return { binPath, isWASM };
|
1955
|
-
}
|
1956
|
-
|
1957
|
-
// lib/npm/node.ts
|
1958
|
-
var child_process = require("child_process");
|
1959
|
-
var crypto = require("crypto");
|
1960
|
-
var path2 = require("path");
|
1961
|
-
var fs2 = require("fs");
|
1962
|
-
var os2 = require("os");
|
1963
|
-
var tty = require("tty");
|
1964
|
-
var worker_threads;
|
1965
|
-
if (process.env.ESBUILD_WORKER_THREADS !== "0") {
|
1966
|
-
try {
|
1967
|
-
worker_threads = require("worker_threads");
|
1968
|
-
} catch {
|
1969
|
-
}
|
1970
|
-
let [major, minor] = process.versions.node.split(".");
|
1971
|
-
if (
|
1972
|
-
// <v12.17.0 does not work
|
1973
|
-
+major < 12 || +major === 12 && +minor < 17 || +major === 13 && +minor < 13
|
1974
|
-
) {
|
1975
|
-
worker_threads = void 0;
|
1976
|
-
}
|
1977
|
-
}
|
1978
|
-
var _a;
|
1979
|
-
var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.20.2";
|
1980
|
-
var esbuildCommandAndArgs = () => {
|
1981
|
-
if ((!ESBUILD_BINARY_PATH || false) && (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib")) {
|
1982
|
-
throw new Error(
|
1983
|
-
`The esbuild JavaScript API cannot be bundled. Please mark the "esbuild" package as external so it's not included in the bundle.
|
1984
|
-
|
1985
|
-
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.`
|
1986
|
-
);
|
1987
|
-
}
|
1988
|
-
if (false) {
|
1989
|
-
return ["node", [path2.join(__dirname, "..", "bin", "esbuild")]];
|
1990
|
-
} else {
|
1991
|
-
const { binPath, isWASM } = generateBinPath();
|
1992
|
-
if (isWASM) {
|
1993
|
-
return ["node", [binPath]];
|
1994
|
-
} else {
|
1995
|
-
return [binPath, []];
|
1996
|
-
}
|
1997
|
-
}
|
1998
|
-
};
|
1999
|
-
var isTTY = () => tty.isatty(2);
|
2000
|
-
var fsSync = {
|
2001
|
-
readFile(tempFile, callback) {
|
2002
|
-
try {
|
2003
|
-
let contents = fs2.readFileSync(tempFile, "utf8");
|
2004
|
-
try {
|
2005
|
-
fs2.unlinkSync(tempFile);
|
2006
|
-
} catch {
|
2007
|
-
}
|
2008
|
-
callback(null, contents);
|
2009
|
-
} catch (err) {
|
2010
|
-
callback(err, null);
|
2011
|
-
}
|
2012
|
-
},
|
2013
|
-
writeFile(contents, callback) {
|
2014
|
-
try {
|
2015
|
-
let tempFile = randomFileName();
|
2016
|
-
fs2.writeFileSync(tempFile, contents);
|
2017
|
-
callback(tempFile);
|
2018
|
-
} catch {
|
2019
|
-
callback(null);
|
2020
|
-
}
|
2021
|
-
}
|
2022
|
-
};
|
2023
|
-
var fsAsync = {
|
2024
|
-
readFile(tempFile, callback) {
|
2025
|
-
try {
|
2026
|
-
fs2.readFile(tempFile, "utf8", (err, contents) => {
|
2027
|
-
try {
|
2028
|
-
fs2.unlink(tempFile, () => callback(err, contents));
|
2029
|
-
} catch {
|
2030
|
-
callback(err, contents);
|
2031
|
-
}
|
2032
|
-
});
|
2033
|
-
} catch (err) {
|
2034
|
-
callback(err, null);
|
2035
|
-
}
|
2036
|
-
},
|
2037
|
-
writeFile(contents, callback) {
|
2038
|
-
try {
|
2039
|
-
let tempFile = randomFileName();
|
2040
|
-
fs2.writeFile(tempFile, contents, (err) => err !== null ? callback(null) : callback(tempFile));
|
2041
|
-
} catch {
|
2042
|
-
callback(null);
|
2043
|
-
}
|
2044
|
-
}
|
2045
|
-
};
|
2046
|
-
var version = "0.20.2";
|
2047
|
-
var build = (options) => ensureServiceIsRunning().build(options);
|
2048
|
-
var context = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
|
2049
|
-
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
2050
|
-
var formatMessages = (messages, options) => ensureServiceIsRunning().formatMessages(messages, options);
|
2051
|
-
var analyzeMetafile = (messages, options) => ensureServiceIsRunning().analyzeMetafile(messages, options);
|
2052
|
-
var buildSync = (options) => {
|
2053
|
-
if (worker_threads && !isInternalWorkerThread) {
|
2054
|
-
if (!workerThreadService)
|
2055
|
-
workerThreadService = startWorkerThreadService(worker_threads);
|
2056
|
-
return workerThreadService.buildSync(options);
|
2057
|
-
}
|
2058
|
-
let result;
|
2059
|
-
runServiceSync((service) => service.buildOrContext({
|
2060
|
-
callName: "buildSync",
|
2061
|
-
refs: null,
|
2062
|
-
options,
|
2063
|
-
isTTY: isTTY(),
|
2064
|
-
defaultWD,
|
2065
|
-
callback: (err, res) => {
|
2066
|
-
if (err)
|
2067
|
-
throw err;
|
2068
|
-
result = res;
|
2069
|
-
}
|
2070
|
-
}));
|
2071
|
-
return result;
|
2072
|
-
};
|
2073
|
-
var transformSync = (input, options) => {
|
2074
|
-
if (worker_threads && !isInternalWorkerThread) {
|
2075
|
-
if (!workerThreadService)
|
2076
|
-
workerThreadService = startWorkerThreadService(worker_threads);
|
2077
|
-
return workerThreadService.transformSync(input, options);
|
2078
|
-
}
|
2079
|
-
let result;
|
2080
|
-
runServiceSync((service) => service.transform({
|
2081
|
-
callName: "transformSync",
|
2082
|
-
refs: null,
|
2083
|
-
input,
|
2084
|
-
options: options || {},
|
2085
|
-
isTTY: isTTY(),
|
2086
|
-
fs: fsSync,
|
2087
|
-
callback: (err, res) => {
|
2088
|
-
if (err)
|
2089
|
-
throw err;
|
2090
|
-
result = res;
|
2091
|
-
}
|
2092
|
-
}));
|
2093
|
-
return result;
|
2094
|
-
};
|
2095
|
-
var formatMessagesSync = (messages, options) => {
|
2096
|
-
if (worker_threads && !isInternalWorkerThread) {
|
2097
|
-
if (!workerThreadService)
|
2098
|
-
workerThreadService = startWorkerThreadService(worker_threads);
|
2099
|
-
return workerThreadService.formatMessagesSync(messages, options);
|
2100
|
-
}
|
2101
|
-
let result;
|
2102
|
-
runServiceSync((service) => service.formatMessages({
|
2103
|
-
callName: "formatMessagesSync",
|
2104
|
-
refs: null,
|
2105
|
-
messages,
|
2106
|
-
options,
|
2107
|
-
callback: (err, res) => {
|
2108
|
-
if (err)
|
2109
|
-
throw err;
|
2110
|
-
result = res;
|
2111
|
-
}
|
2112
|
-
}));
|
2113
|
-
return result;
|
2114
|
-
};
|
2115
|
-
var analyzeMetafileSync = (metafile, options) => {
|
2116
|
-
if (worker_threads && !isInternalWorkerThread) {
|
2117
|
-
if (!workerThreadService)
|
2118
|
-
workerThreadService = startWorkerThreadService(worker_threads);
|
2119
|
-
return workerThreadService.analyzeMetafileSync(metafile, options);
|
2120
|
-
}
|
2121
|
-
let result;
|
2122
|
-
runServiceSync((service) => service.analyzeMetafile({
|
2123
|
-
callName: "analyzeMetafileSync",
|
2124
|
-
refs: null,
|
2125
|
-
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
2126
|
-
options,
|
2127
|
-
callback: (err, res) => {
|
2128
|
-
if (err)
|
2129
|
-
throw err;
|
2130
|
-
result = res;
|
2131
|
-
}
|
2132
|
-
}));
|
2133
|
-
return result;
|
2134
|
-
};
|
2135
|
-
var stop = () => {
|
2136
|
-
if (stopService)
|
2137
|
-
stopService();
|
2138
|
-
if (workerThreadService)
|
2139
|
-
workerThreadService.stop();
|
2140
|
-
return Promise.resolve();
|
2141
|
-
};
|
2142
|
-
var initializeWasCalled = false;
|
2143
|
-
var initialize = (options) => {
|
2144
|
-
options = validateInitializeOptions(options || {});
|
2145
|
-
if (options.wasmURL)
|
2146
|
-
throw new Error(`The "wasmURL" option only works in the browser`);
|
2147
|
-
if (options.wasmModule)
|
2148
|
-
throw new Error(`The "wasmModule" option only works in the browser`);
|
2149
|
-
if (options.worker)
|
2150
|
-
throw new Error(`The "worker" option only works in the browser`);
|
2151
|
-
if (initializeWasCalled)
|
2152
|
-
throw new Error('Cannot call "initialize" more than once');
|
2153
|
-
ensureServiceIsRunning();
|
2154
|
-
initializeWasCalled = true;
|
2155
|
-
return Promise.resolve();
|
2156
|
-
};
|
2157
|
-
var defaultWD = process.cwd();
|
2158
|
-
var longLivedService;
|
2159
|
-
var stopService;
|
2160
|
-
var ensureServiceIsRunning = () => {
|
2161
|
-
if (longLivedService)
|
2162
|
-
return longLivedService;
|
2163
|
-
let [command, args] = esbuildCommandAndArgs();
|
2164
|
-
let child = child_process.spawn(command, args.concat(`--service=${"0.20.2"}`, "--ping"), {
|
2165
|
-
windowsHide: true,
|
2166
|
-
stdio: ["pipe", "pipe", "inherit"],
|
2167
|
-
cwd: defaultWD
|
2168
|
-
});
|
2169
|
-
let { readFromStdout, afterClose, service } = createChannel({
|
2170
|
-
writeToStdin(bytes) {
|
2171
|
-
child.stdin.write(bytes, (err) => {
|
2172
|
-
if (err)
|
2173
|
-
afterClose(err);
|
2174
|
-
});
|
2175
|
-
},
|
2176
|
-
readFileSync: fs2.readFileSync,
|
2177
|
-
isSync: false,
|
2178
|
-
hasFS: true,
|
2179
|
-
esbuild: node_exports
|
2180
|
-
});
|
2181
|
-
child.stdin.on("error", afterClose);
|
2182
|
-
child.on("error", afterClose);
|
2183
|
-
const stdin = child.stdin;
|
2184
|
-
const stdout = child.stdout;
|
2185
|
-
stdout.on("data", readFromStdout);
|
2186
|
-
stdout.on("end", afterClose);
|
2187
|
-
stopService = () => {
|
2188
|
-
stdin.destroy();
|
2189
|
-
stdout.destroy();
|
2190
|
-
child.kill();
|
2191
|
-
initializeWasCalled = false;
|
2192
|
-
longLivedService = void 0;
|
2193
|
-
stopService = void 0;
|
2194
|
-
};
|
2195
|
-
let refCount = 0;
|
2196
|
-
child.unref();
|
2197
|
-
if (stdin.unref) {
|
2198
|
-
stdin.unref();
|
2199
|
-
}
|
2200
|
-
if (stdout.unref) {
|
2201
|
-
stdout.unref();
|
2202
|
-
}
|
2203
|
-
const refs = {
|
2204
|
-
ref() {
|
2205
|
-
if (++refCount === 1)
|
2206
|
-
child.ref();
|
2207
|
-
},
|
2208
|
-
unref() {
|
2209
|
-
if (--refCount === 0)
|
2210
|
-
child.unref();
|
2211
|
-
}
|
2212
|
-
};
|
2213
|
-
longLivedService = {
|
2214
|
-
build: (options) => new Promise((resolve, reject) => {
|
2215
|
-
service.buildOrContext({
|
2216
|
-
callName: "build",
|
2217
|
-
refs,
|
2218
|
-
options,
|
2219
|
-
isTTY: isTTY(),
|
2220
|
-
defaultWD,
|
2221
|
-
callback: (err, res) => err ? reject(err) : resolve(res)
|
2222
|
-
});
|
2223
|
-
}),
|
2224
|
-
context: (options) => new Promise((resolve, reject) => service.buildOrContext({
|
2225
|
-
callName: "context",
|
2226
|
-
refs,
|
2227
|
-
options,
|
2228
|
-
isTTY: isTTY(),
|
2229
|
-
defaultWD,
|
2230
|
-
callback: (err, res) => err ? reject(err) : resolve(res)
|
2231
|
-
})),
|
2232
|
-
transform: (input, options) => new Promise((resolve, reject) => service.transform({
|
2233
|
-
callName: "transform",
|
2234
|
-
refs,
|
2235
|
-
input,
|
2236
|
-
options: options || {},
|
2237
|
-
isTTY: isTTY(),
|
2238
|
-
fs: fsAsync,
|
2239
|
-
callback: (err, res) => err ? reject(err) : resolve(res)
|
2240
|
-
})),
|
2241
|
-
formatMessages: (messages, options) => new Promise((resolve, reject) => service.formatMessages({
|
2242
|
-
callName: "formatMessages",
|
2243
|
-
refs,
|
2244
|
-
messages,
|
2245
|
-
options,
|
2246
|
-
callback: (err, res) => err ? reject(err) : resolve(res)
|
2247
|
-
})),
|
2248
|
-
analyzeMetafile: (metafile, options) => new Promise((resolve, reject) => service.analyzeMetafile({
|
2249
|
-
callName: "analyzeMetafile",
|
2250
|
-
refs,
|
2251
|
-
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
2252
|
-
options,
|
2253
|
-
callback: (err, res) => err ? reject(err) : resolve(res)
|
2254
|
-
}))
|
2255
|
-
};
|
2256
|
-
return longLivedService;
|
2257
|
-
};
|
2258
|
-
var runServiceSync = (callback) => {
|
2259
|
-
let [command, args] = esbuildCommandAndArgs();
|
2260
|
-
let stdin = new Uint8Array();
|
2261
|
-
let { readFromStdout, afterClose, service } = createChannel({
|
2262
|
-
writeToStdin(bytes) {
|
2263
|
-
if (stdin.length !== 0)
|
2264
|
-
throw new Error("Must run at most one command");
|
2265
|
-
stdin = bytes;
|
2266
|
-
},
|
2267
|
-
isSync: true,
|
2268
|
-
hasFS: true,
|
2269
|
-
esbuild: node_exports
|
2270
|
-
});
|
2271
|
-
callback(service);
|
2272
|
-
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.20.2"}`), {
|
2273
|
-
cwd: defaultWD,
|
2274
|
-
windowsHide: true,
|
2275
|
-
input: stdin,
|
2276
|
-
// We don't know how large the output could be. If it's too large, the
|
2277
|
-
// command will fail with ENOBUFS. Reserve 16mb for now since that feels
|
2278
|
-
// like it should be enough. Also allow overriding this with an environment
|
2279
|
-
// variable.
|
2280
|
-
maxBuffer: +process.env.ESBUILD_MAX_BUFFER || 16 * 1024 * 1024
|
2281
|
-
});
|
2282
|
-
readFromStdout(stdout);
|
2283
|
-
afterClose(null);
|
2284
|
-
};
|
2285
|
-
var randomFileName = () => {
|
2286
|
-
return path2.join(os2.tmpdir(), `esbuild-${crypto.randomBytes(32).toString("hex")}`);
|
2287
|
-
};
|
2288
|
-
var workerThreadService = null;
|
2289
|
-
var startWorkerThreadService = (worker_threads2) => {
|
2290
|
-
let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel();
|
2291
|
-
let worker = new worker_threads2.Worker(__filename, {
|
2292
|
-
workerData: { workerPort, defaultWD, esbuildVersion: "0.20.2" },
|
2293
|
-
transferList: [workerPort],
|
2294
|
-
// From node's documentation: https://nodejs.org/api/worker_threads.html
|
2295
|
-
//
|
2296
|
-
// Take care when launching worker threads from preload scripts (scripts loaded
|
2297
|
-
// and run using the `-r` command line flag). Unless the `execArgv` option is
|
2298
|
-
// explicitly set, new Worker threads automatically inherit the command line flags
|
2299
|
-
// from the running process and will preload the same preload scripts as the main
|
2300
|
-
// thread. If the preload script unconditionally launches a worker thread, every
|
2301
|
-
// thread spawned will spawn another until the application crashes.
|
2302
|
-
//
|
2303
|
-
execArgv: []
|
2304
|
-
});
|
2305
|
-
let nextID = 0;
|
2306
|
-
let fakeBuildError = (text) => {
|
2307
|
-
let error = new Error(`Build failed with 1 error:
|
2308
|
-
error: ${text}`);
|
2309
|
-
let errors = [{ id: "", pluginName: "", text, location: null, notes: [], detail: void 0 }];
|
2310
|
-
error.errors = errors;
|
2311
|
-
error.warnings = [];
|
2312
|
-
return error;
|
2313
|
-
};
|
2314
|
-
let validateBuildSyncOptions = (options) => {
|
2315
|
-
if (!options)
|
2316
|
-
return;
|
2317
|
-
let plugins = options.plugins;
|
2318
|
-
if (plugins && plugins.length > 0)
|
2319
|
-
throw fakeBuildError(`Cannot use plugins in synchronous API calls`);
|
2320
|
-
};
|
2321
|
-
let applyProperties = (object, properties) => {
|
2322
|
-
for (let key in properties) {
|
2323
|
-
object[key] = properties[key];
|
2324
|
-
}
|
2325
|
-
};
|
2326
|
-
let runCallSync = (command, args) => {
|
2327
|
-
let id = nextID++;
|
2328
|
-
let sharedBuffer = new SharedArrayBuffer(8);
|
2329
|
-
let sharedBufferView = new Int32Array(sharedBuffer);
|
2330
|
-
let msg = { sharedBuffer, id, command, args };
|
2331
|
-
worker.postMessage(msg);
|
2332
|
-
let status = Atomics.wait(sharedBufferView, 0, 0);
|
2333
|
-
if (status !== "ok" && status !== "not-equal")
|
2334
|
-
throw new Error("Internal error: Atomics.wait() failed: " + status);
|
2335
|
-
let { message: { id: id2, resolve, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
|
2336
|
-
if (id !== id2)
|
2337
|
-
throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
2338
|
-
if (reject) {
|
2339
|
-
applyProperties(reject, properties);
|
2340
|
-
throw reject;
|
2341
|
-
}
|
2342
|
-
return resolve;
|
2343
|
-
};
|
2344
|
-
worker.unref();
|
2345
|
-
return {
|
2346
|
-
buildSync(options) {
|
2347
|
-
validateBuildSyncOptions(options);
|
2348
|
-
return runCallSync("build", [options]);
|
2349
|
-
},
|
2350
|
-
transformSync(input, options) {
|
2351
|
-
return runCallSync("transform", [input, options]);
|
2352
|
-
},
|
2353
|
-
formatMessagesSync(messages, options) {
|
2354
|
-
return runCallSync("formatMessages", [messages, options]);
|
2355
|
-
},
|
2356
|
-
analyzeMetafileSync(metafile, options) {
|
2357
|
-
return runCallSync("analyzeMetafile", [metafile, options]);
|
2358
|
-
},
|
2359
|
-
stop() {
|
2360
|
-
worker.terminate();
|
2361
|
-
workerThreadService = null;
|
2362
|
-
}
|
2363
|
-
};
|
2364
|
-
};
|
2365
|
-
var startSyncServiceWorker = () => {
|
2366
|
-
let workerPort = worker_threads.workerData.workerPort;
|
2367
|
-
let parentPort = worker_threads.parentPort;
|
2368
|
-
let extractProperties = (object) => {
|
2369
|
-
let properties = {};
|
2370
|
-
if (object && typeof object === "object") {
|
2371
|
-
for (let key in object) {
|
2372
|
-
properties[key] = object[key];
|
2373
|
-
}
|
2374
|
-
}
|
2375
|
-
return properties;
|
2376
|
-
};
|
2377
|
-
try {
|
2378
|
-
let service = ensureServiceIsRunning();
|
2379
|
-
defaultWD = worker_threads.workerData.defaultWD;
|
2380
|
-
parentPort.on("message", (msg) => {
|
2381
|
-
(async () => {
|
2382
|
-
let { sharedBuffer, id, command, args } = msg;
|
2383
|
-
let sharedBufferView = new Int32Array(sharedBuffer);
|
2384
|
-
try {
|
2385
|
-
switch (command) {
|
2386
|
-
case "build":
|
2387
|
-
workerPort.postMessage({ id, resolve: await service.build(args[0]) });
|
2388
|
-
break;
|
2389
|
-
case "transform":
|
2390
|
-
workerPort.postMessage({ id, resolve: await service.transform(args[0], args[1]) });
|
2391
|
-
break;
|
2392
|
-
case "formatMessages":
|
2393
|
-
workerPort.postMessage({ id, resolve: await service.formatMessages(args[0], args[1]) });
|
2394
|
-
break;
|
2395
|
-
case "analyzeMetafile":
|
2396
|
-
workerPort.postMessage({ id, resolve: await service.analyzeMetafile(args[0], args[1]) });
|
2397
|
-
break;
|
2398
|
-
default:
|
2399
|
-
throw new Error(`Invalid command: ${command}`);
|
2400
|
-
}
|
2401
|
-
} catch (reject) {
|
2402
|
-
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
2403
|
-
}
|
2404
|
-
Atomics.add(sharedBufferView, 0, 1);
|
2405
|
-
Atomics.notify(sharedBufferView, 0, Infinity);
|
2406
|
-
})();
|
2407
|
-
});
|
2408
|
-
} catch (reject) {
|
2409
|
-
parentPort.on("message", (msg) => {
|
2410
|
-
let { sharedBuffer, id } = msg;
|
2411
|
-
let sharedBufferView = new Int32Array(sharedBuffer);
|
2412
|
-
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
2413
|
-
Atomics.add(sharedBufferView, 0, 1);
|
2414
|
-
Atomics.notify(sharedBufferView, 0, Infinity);
|
2415
|
-
});
|
2416
|
-
}
|
2417
|
-
};
|
2418
|
-
if (isInternalWorkerThread) {
|
2419
|
-
startSyncServiceWorker();
|
2420
|
-
}
|
2421
|
-
var node_default = node_exports;
|
2422
|
-
// Annotate the CommonJS export names for ESM import in node:
|
2423
|
-
0 && (module.exports = {
|
2424
|
-
analyzeMetafile,
|
2425
|
-
analyzeMetafileSync,
|
2426
|
-
build,
|
2427
|
-
buildSync,
|
2428
|
-
context,
|
2429
|
-
formatMessages,
|
2430
|
-
formatMessagesSync,
|
2431
|
-
initialize,
|
2432
|
-
stop,
|
2433
|
-
transform,
|
2434
|
-
transformSync,
|
2435
|
-
version
|
2436
|
-
});
|