@edgeone/opennextjs-pages 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/functions/middleware/compat/globals.js +119 -0
- package/dist/build/functions/middleware/compat/index.js +27 -0
- package/dist/build/functions/middleware/compat/turbopack-runtime.js +662 -0
- package/dist/build/functions/middleware/compat/webpack-runtime.js +266 -0
- package/dist/build/functions/middleware/compiler.js +3580 -0
- package/dist/build/functions/middleware/middleware.js +58 -0
- package/dist/build/functions/middleware/polyfills/async-local-storage.js +100 -0
- package/dist/build/functions/middleware/polyfills/buffer.js +214 -0
- package/dist/build/functions/middleware/polyfills/crypto.js +117 -0
- package/dist/build/functions/middleware/polyfills/index.js +200 -0
- package/dist/build/functions/middleware/polyfills/process.js +101 -0
- package/dist/build/functions/middleware/wrapper.js +353 -0
- package/dist/index.js +2 -0
- package/dist/run/handlers/tags-handler.cjs +1 -1
- package/dist/types.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,3580 @@
|
|
|
1
|
+
|
|
2
|
+
var require = await (async () => {
|
|
3
|
+
var { createRequire } = await import("node:module");
|
|
4
|
+
return createRequire(import.meta.url);
|
|
5
|
+
})();
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
__commonJS,
|
|
9
|
+
__require,
|
|
10
|
+
__toESM
|
|
11
|
+
} from "../../../esm-chunks/chunk-6BT4RYQJ.js";
|
|
12
|
+
|
|
13
|
+
// node_modules/esbuild/lib/main.js
|
|
14
|
+
var require_main = __commonJS({
|
|
15
|
+
"node_modules/esbuild/lib/main.js"(exports, module) {
|
|
16
|
+
"use strict";
|
|
17
|
+
var __defProp = Object.defineProperty;
|
|
18
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
19
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
20
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
21
|
+
var __export = (target, all) => {
|
|
22
|
+
for (var name in all)
|
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
+
};
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
+
for (let key of __getOwnPropNames(from))
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
+
var node_exports = {};
|
|
35
|
+
__export(node_exports, {
|
|
36
|
+
analyzeMetafile: () => analyzeMetafile,
|
|
37
|
+
analyzeMetafileSync: () => analyzeMetafileSync,
|
|
38
|
+
build: () => build2,
|
|
39
|
+
buildSync: () => buildSync,
|
|
40
|
+
context: () => context,
|
|
41
|
+
default: () => node_default,
|
|
42
|
+
formatMessages: () => formatMessages,
|
|
43
|
+
formatMessagesSync: () => formatMessagesSync,
|
|
44
|
+
initialize: () => initialize,
|
|
45
|
+
stop: () => stop,
|
|
46
|
+
transform: () => transform,
|
|
47
|
+
transformSync: () => transformSync,
|
|
48
|
+
version: () => version
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(node_exports);
|
|
51
|
+
function encodePacket(packet) {
|
|
52
|
+
let visit = (value) => {
|
|
53
|
+
if (value === null) {
|
|
54
|
+
bb.write8(0);
|
|
55
|
+
} else if (typeof value === "boolean") {
|
|
56
|
+
bb.write8(1);
|
|
57
|
+
bb.write8(+value);
|
|
58
|
+
} else if (typeof value === "number") {
|
|
59
|
+
bb.write8(2);
|
|
60
|
+
bb.write32(value | 0);
|
|
61
|
+
} else if (typeof value === "string") {
|
|
62
|
+
bb.write8(3);
|
|
63
|
+
bb.write(encodeUTF8(value));
|
|
64
|
+
} else if (value instanceof Uint8Array) {
|
|
65
|
+
bb.write8(4);
|
|
66
|
+
bb.write(value);
|
|
67
|
+
} else if (value instanceof Array) {
|
|
68
|
+
bb.write8(5);
|
|
69
|
+
bb.write32(value.length);
|
|
70
|
+
for (let item of value) {
|
|
71
|
+
visit(item);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
let keys = Object.keys(value);
|
|
75
|
+
bb.write8(6);
|
|
76
|
+
bb.write32(keys.length);
|
|
77
|
+
for (let key of keys) {
|
|
78
|
+
bb.write(encodeUTF8(key));
|
|
79
|
+
visit(value[key]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
let bb = new ByteBuffer();
|
|
84
|
+
bb.write32(0);
|
|
85
|
+
bb.write32(packet.id << 1 | +!packet.isRequest);
|
|
86
|
+
visit(packet.value);
|
|
87
|
+
writeUInt32LE(bb.buf, bb.len - 4, 0);
|
|
88
|
+
return bb.buf.subarray(0, bb.len);
|
|
89
|
+
}
|
|
90
|
+
function decodePacket(bytes) {
|
|
91
|
+
let visit = () => {
|
|
92
|
+
switch (bb.read8()) {
|
|
93
|
+
case 0:
|
|
94
|
+
return null;
|
|
95
|
+
case 1:
|
|
96
|
+
return !!bb.read8();
|
|
97
|
+
case 2:
|
|
98
|
+
return bb.read32();
|
|
99
|
+
case 3:
|
|
100
|
+
return decodeUTF8(bb.read());
|
|
101
|
+
case 4:
|
|
102
|
+
return bb.read();
|
|
103
|
+
case 5: {
|
|
104
|
+
let count = bb.read32();
|
|
105
|
+
let value2 = [];
|
|
106
|
+
for (let i = 0; i < count; i++) {
|
|
107
|
+
value2.push(visit());
|
|
108
|
+
}
|
|
109
|
+
return value2;
|
|
110
|
+
}
|
|
111
|
+
case 6: {
|
|
112
|
+
let count = bb.read32();
|
|
113
|
+
let value2 = {};
|
|
114
|
+
for (let i = 0; i < count; i++) {
|
|
115
|
+
value2[decodeUTF8(bb.read())] = visit();
|
|
116
|
+
}
|
|
117
|
+
return value2;
|
|
118
|
+
}
|
|
119
|
+
default:
|
|
120
|
+
throw new Error("Invalid packet");
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
let bb = new ByteBuffer(bytes);
|
|
124
|
+
let id = bb.read32();
|
|
125
|
+
let isRequest = (id & 1) === 0;
|
|
126
|
+
id >>>= 1;
|
|
127
|
+
let value = visit();
|
|
128
|
+
if (bb.ptr !== bytes.length) {
|
|
129
|
+
throw new Error("Invalid packet");
|
|
130
|
+
}
|
|
131
|
+
return { id, isRequest, value };
|
|
132
|
+
}
|
|
133
|
+
var ByteBuffer = class {
|
|
134
|
+
constructor(buf = new Uint8Array(1024)) {
|
|
135
|
+
this.buf = buf;
|
|
136
|
+
this.len = 0;
|
|
137
|
+
this.ptr = 0;
|
|
138
|
+
}
|
|
139
|
+
_write(delta) {
|
|
140
|
+
if (this.len + delta > this.buf.length) {
|
|
141
|
+
let clone = new Uint8Array((this.len + delta) * 2);
|
|
142
|
+
clone.set(this.buf);
|
|
143
|
+
this.buf = clone;
|
|
144
|
+
}
|
|
145
|
+
this.len += delta;
|
|
146
|
+
return this.len - delta;
|
|
147
|
+
}
|
|
148
|
+
write8(value) {
|
|
149
|
+
let offset = this._write(1);
|
|
150
|
+
this.buf[offset] = value;
|
|
151
|
+
}
|
|
152
|
+
write32(value) {
|
|
153
|
+
let offset = this._write(4);
|
|
154
|
+
writeUInt32LE(this.buf, value, offset);
|
|
155
|
+
}
|
|
156
|
+
write(bytes) {
|
|
157
|
+
let offset = this._write(4 + bytes.length);
|
|
158
|
+
writeUInt32LE(this.buf, bytes.length, offset);
|
|
159
|
+
this.buf.set(bytes, offset + 4);
|
|
160
|
+
}
|
|
161
|
+
_read(delta) {
|
|
162
|
+
if (this.ptr + delta > this.buf.length) {
|
|
163
|
+
throw new Error("Invalid packet");
|
|
164
|
+
}
|
|
165
|
+
this.ptr += delta;
|
|
166
|
+
return this.ptr - delta;
|
|
167
|
+
}
|
|
168
|
+
read8() {
|
|
169
|
+
return this.buf[this._read(1)];
|
|
170
|
+
}
|
|
171
|
+
read32() {
|
|
172
|
+
return readUInt32LE(this.buf, this._read(4));
|
|
173
|
+
}
|
|
174
|
+
read() {
|
|
175
|
+
let length = this.read32();
|
|
176
|
+
let bytes = new Uint8Array(length);
|
|
177
|
+
let ptr = this._read(bytes.length);
|
|
178
|
+
bytes.set(this.buf.subarray(ptr, ptr + length));
|
|
179
|
+
return bytes;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
var encodeUTF8;
|
|
183
|
+
var decodeUTF8;
|
|
184
|
+
var encodeInvariant;
|
|
185
|
+
if (typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined") {
|
|
186
|
+
let encoder = new TextEncoder();
|
|
187
|
+
let decoder = new TextDecoder();
|
|
188
|
+
encodeUTF8 = (text) => encoder.encode(text);
|
|
189
|
+
decodeUTF8 = (bytes) => decoder.decode(bytes);
|
|
190
|
+
encodeInvariant = 'new TextEncoder().encode("")';
|
|
191
|
+
} else if (typeof Buffer !== "undefined") {
|
|
192
|
+
encodeUTF8 = (text) => Buffer.from(text);
|
|
193
|
+
decodeUTF8 = (bytes) => {
|
|
194
|
+
let { buffer, byteOffset, byteLength } = bytes;
|
|
195
|
+
return Buffer.from(buffer, byteOffset, byteLength).toString();
|
|
196
|
+
};
|
|
197
|
+
encodeInvariant = 'Buffer.from("")';
|
|
198
|
+
} else {
|
|
199
|
+
throw new Error("No UTF-8 codec found");
|
|
200
|
+
}
|
|
201
|
+
if (!(encodeUTF8("") instanceof Uint8Array))
|
|
202
|
+
throw new Error(`Invariant violation: "${encodeInvariant} instanceof Uint8Array" is incorrectly false
|
|
203
|
+
|
|
204
|
+
This indicates that your JavaScript environment is broken. You cannot use
|
|
205
|
+
esbuild in this environment because esbuild relies on this invariant. This
|
|
206
|
+
is not a problem with esbuild. You need to fix your environment instead.
|
|
207
|
+
`);
|
|
208
|
+
function readUInt32LE(buffer, offset) {
|
|
209
|
+
return buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24;
|
|
210
|
+
}
|
|
211
|
+
function writeUInt32LE(buffer, value, offset) {
|
|
212
|
+
buffer[offset++] = value;
|
|
213
|
+
buffer[offset++] = value >> 8;
|
|
214
|
+
buffer[offset++] = value >> 16;
|
|
215
|
+
buffer[offset++] = value >> 24;
|
|
216
|
+
}
|
|
217
|
+
var quote = JSON.stringify;
|
|
218
|
+
var buildLogLevelDefault = "warning";
|
|
219
|
+
var transformLogLevelDefault = "silent";
|
|
220
|
+
function validateAndJoinStringArray(values, what) {
|
|
221
|
+
const toJoin = [];
|
|
222
|
+
for (const value of values) {
|
|
223
|
+
validateStringValue(value, what);
|
|
224
|
+
if (value.indexOf(",") >= 0) throw new Error(`Invalid ${what}: ${value}`);
|
|
225
|
+
toJoin.push(value);
|
|
226
|
+
}
|
|
227
|
+
return toJoin.join(",");
|
|
228
|
+
}
|
|
229
|
+
var canBeAnything = () => null;
|
|
230
|
+
var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
|
|
231
|
+
var mustBeString = (value) => typeof value === "string" ? null : "a string";
|
|
232
|
+
var mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object";
|
|
233
|
+
var mustBeInteger = (value) => typeof value === "number" && value === (value | 0) ? null : "an integer";
|
|
234
|
+
var mustBeValidPortNumber = (value) => typeof value === "number" && value === (value | 0) && value >= 0 && value <= 65535 ? null : "a valid port number";
|
|
235
|
+
var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
|
|
236
|
+
var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
|
|
237
|
+
var mustBeArrayOfStrings = (value) => Array.isArray(value) && value.every((x) => typeof x === "string") ? null : "an array of strings";
|
|
238
|
+
var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
|
|
239
|
+
var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
|
240
|
+
var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
|
|
241
|
+
var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
|
|
242
|
+
var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
|
|
243
|
+
var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
|
|
244
|
+
var mustBeStringOrArrayOfStrings = (value) => typeof value === "string" || Array.isArray(value) && value.every((x) => typeof x === "string") ? null : "a string or an array of strings";
|
|
245
|
+
var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array";
|
|
246
|
+
var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof URL ? null : "a string or a URL";
|
|
247
|
+
function getFlag(object, keys, key, mustBeFn) {
|
|
248
|
+
let value = object[key];
|
|
249
|
+
keys[key + ""] = true;
|
|
250
|
+
if (value === void 0) return void 0;
|
|
251
|
+
let mustBe = mustBeFn(value);
|
|
252
|
+
if (mustBe !== null) throw new Error(`${quote(key)} must be ${mustBe}`);
|
|
253
|
+
return value;
|
|
254
|
+
}
|
|
255
|
+
function checkForInvalidFlags(object, keys, where) {
|
|
256
|
+
for (let key in object) {
|
|
257
|
+
if (!(key in keys)) {
|
|
258
|
+
throw new Error(`Invalid option ${where}: ${quote(key)}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function validateInitializeOptions(options) {
|
|
263
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
264
|
+
let wasmURL = getFlag(options, keys, "wasmURL", mustBeStringOrURL);
|
|
265
|
+
let wasmModule = getFlag(options, keys, "wasmModule", mustBeWebAssemblyModule);
|
|
266
|
+
let worker = getFlag(options, keys, "worker", mustBeBoolean);
|
|
267
|
+
checkForInvalidFlags(options, keys, "in initialize() call");
|
|
268
|
+
return {
|
|
269
|
+
wasmURL,
|
|
270
|
+
wasmModule,
|
|
271
|
+
worker
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function validateMangleCache(mangleCache) {
|
|
275
|
+
let validated;
|
|
276
|
+
if (mangleCache !== void 0) {
|
|
277
|
+
validated = /* @__PURE__ */ Object.create(null);
|
|
278
|
+
for (let key in mangleCache) {
|
|
279
|
+
let value = mangleCache[key];
|
|
280
|
+
if (typeof value === "string" || value === false) {
|
|
281
|
+
validated[key] = value;
|
|
282
|
+
} else {
|
|
283
|
+
throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return validated;
|
|
288
|
+
}
|
|
289
|
+
function pushLogFlags(flags, options, keys, isTTY2, logLevelDefault) {
|
|
290
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
291
|
+
let logLevel = getFlag(options, keys, "logLevel", mustBeString);
|
|
292
|
+
let logLimit = getFlag(options, keys, "logLimit", mustBeInteger);
|
|
293
|
+
if (color !== void 0) flags.push(`--color=${color}`);
|
|
294
|
+
else if (isTTY2) 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", mustBeStringOrArrayOfStrings);
|
|
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", mustBeArrayOfStrings);
|
|
320
|
+
let dropLabels = getFlag(options, keys, "dropLabels", mustBeArrayOfStrings);
|
|
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", mustBeArrayOfStrings);
|
|
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) flags.push(`--legal-comments=${legalComments}`);
|
|
338
|
+
if (sourceRoot !== void 0) flags.push(`--source-root=${sourceRoot}`);
|
|
339
|
+
if (sourcesContent !== void 0) flags.push(`--sources-content=${sourcesContent}`);
|
|
340
|
+
if (target) flags.push(`--target=${validateAndJoinStringArray(Array.isArray(target) ? target : [target], "target")}`);
|
|
341
|
+
if (format) flags.push(`--format=${format}`);
|
|
342
|
+
if (globalName) flags.push(`--global-name=${globalName}`);
|
|
343
|
+
if (platform) flags.push(`--platform=${platform}`);
|
|
344
|
+
if (tsconfigRaw) flags.push(`--tsconfig-raw=${typeof tsconfigRaw === "string" ? tsconfigRaw : JSON.stringify(tsconfigRaw)}`);
|
|
345
|
+
if (minify) flags.push("--minify");
|
|
346
|
+
if (minifySyntax) flags.push("--minify-syntax");
|
|
347
|
+
if (minifyWhitespace) flags.push("--minify-whitespace");
|
|
348
|
+
if (minifyIdentifiers) flags.push("--minify-identifiers");
|
|
349
|
+
if (lineLimit) flags.push(`--line-limit=${lineLimit}`);
|
|
350
|
+
if (charset) flags.push(`--charset=${charset}`);
|
|
351
|
+
if (treeShaking !== void 0) flags.push(`--tree-shaking=${treeShaking}`);
|
|
352
|
+
if (ignoreAnnotations) flags.push(`--ignore-annotations`);
|
|
353
|
+
if (drop) for (let what of drop) flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
|
354
|
+
if (dropLabels) flags.push(`--drop-labels=${validateAndJoinStringArray(dropLabels, "drop label")}`);
|
|
355
|
+
if (mangleProps) flags.push(`--mangle-props=${jsRegExpToGoRegExp(mangleProps)}`);
|
|
356
|
+
if (reserveProps) flags.push(`--reserve-props=${jsRegExpToGoRegExp(reserveProps)}`);
|
|
357
|
+
if (mangleQuoted !== void 0) flags.push(`--mangle-quoted=${mangleQuoted}`);
|
|
358
|
+
if (jsx) flags.push(`--jsx=${jsx}`);
|
|
359
|
+
if (jsxFactory) flags.push(`--jsx-factory=${jsxFactory}`);
|
|
360
|
+
if (jsxFragment) flags.push(`--jsx-fragment=${jsxFragment}`);
|
|
361
|
+
if (jsxImportSource) flags.push(`--jsx-import-source=${jsxImportSource}`);
|
|
362
|
+
if (jsxDev) flags.push(`--jsx-dev`);
|
|
363
|
+
if (jsxSideEffects) flags.push(`--jsx-side-effects`);
|
|
364
|
+
if (define) {
|
|
365
|
+
for (let key in define) {
|
|
366
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid define: ${key}`);
|
|
367
|
+
flags.push(`--define:${key}=${validateStringValue(define[key], "define", key)}`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (logOverride) {
|
|
371
|
+
for (let key in logOverride) {
|
|
372
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid log override: ${key}`);
|
|
373
|
+
flags.push(`--log-override:${key}=${validateStringValue(logOverride[key], "log override", key)}`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (supported) {
|
|
377
|
+
for (let key in supported) {
|
|
378
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid supported: ${key}`);
|
|
379
|
+
const value = supported[key];
|
|
380
|
+
if (typeof value !== "boolean") throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
|
|
381
|
+
flags.push(`--supported:${key}=${value}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (pure) for (let fn of pure) flags.push(`--pure:${validateStringValue(fn, "pure")}`);
|
|
385
|
+
if (keepNames) flags.push(`--keep-names`);
|
|
386
|
+
}
|
|
387
|
+
function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeDefault) {
|
|
388
|
+
var _a2;
|
|
389
|
+
let flags = [];
|
|
390
|
+
let entries = [];
|
|
391
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
392
|
+
let stdinContents = null;
|
|
393
|
+
let stdinResolveDir = null;
|
|
394
|
+
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
|
395
|
+
pushCommonFlags(flags, options, keys);
|
|
396
|
+
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
|
397
|
+
let bundle = getFlag(options, keys, "bundle", mustBeBoolean);
|
|
398
|
+
let splitting = getFlag(options, keys, "splitting", mustBeBoolean);
|
|
399
|
+
let preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean);
|
|
400
|
+
let metafile = getFlag(options, keys, "metafile", mustBeBoolean);
|
|
401
|
+
let outfile = getFlag(options, keys, "outfile", mustBeString);
|
|
402
|
+
let outdir = getFlag(options, keys, "outdir", mustBeString);
|
|
403
|
+
let outbase = getFlag(options, keys, "outbase", mustBeString);
|
|
404
|
+
let tsconfig = getFlag(options, keys, "tsconfig", mustBeString);
|
|
405
|
+
let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArrayOfStrings);
|
|
406
|
+
let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArrayOfStrings);
|
|
407
|
+
let mainFields = getFlag(options, keys, "mainFields", mustBeArrayOfStrings);
|
|
408
|
+
let conditions = getFlag(options, keys, "conditions", mustBeArrayOfStrings);
|
|
409
|
+
let external = getFlag(options, keys, "external", mustBeArrayOfStrings);
|
|
410
|
+
let packages = getFlag(options, keys, "packages", mustBeString);
|
|
411
|
+
let alias = getFlag(options, keys, "alias", mustBeObject);
|
|
412
|
+
let loader = getFlag(options, keys, "loader", mustBeObject);
|
|
413
|
+
let outExtension = getFlag(options, keys, "outExtension", mustBeObject);
|
|
414
|
+
let publicPath = getFlag(options, keys, "publicPath", mustBeString);
|
|
415
|
+
let entryNames = getFlag(options, keys, "entryNames", mustBeString);
|
|
416
|
+
let chunkNames = getFlag(options, keys, "chunkNames", mustBeString);
|
|
417
|
+
let assetNames = getFlag(options, keys, "assetNames", mustBeString);
|
|
418
|
+
let inject = getFlag(options, keys, "inject", mustBeArrayOfStrings);
|
|
419
|
+
let banner = getFlag(options, keys, "banner", mustBeObject);
|
|
420
|
+
let footer = getFlag(options, keys, "footer", mustBeObject);
|
|
421
|
+
let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
|
|
422
|
+
let absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString);
|
|
423
|
+
let stdin = getFlag(options, keys, "stdin", mustBeObject);
|
|
424
|
+
let write = (_a2 = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a2 : writeDefault;
|
|
425
|
+
let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean);
|
|
426
|
+
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
427
|
+
keys.plugins = true;
|
|
428
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
429
|
+
if (sourcemap) flags.push(`--sourcemap${sourcemap === true ? "" : `=${sourcemap}`}`);
|
|
430
|
+
if (bundle) flags.push("--bundle");
|
|
431
|
+
if (allowOverwrite) flags.push("--allow-overwrite");
|
|
432
|
+
if (splitting) flags.push("--splitting");
|
|
433
|
+
if (preserveSymlinks) flags.push("--preserve-symlinks");
|
|
434
|
+
if (metafile) flags.push(`--metafile`);
|
|
435
|
+
if (outfile) flags.push(`--outfile=${outfile}`);
|
|
436
|
+
if (outdir) flags.push(`--outdir=${outdir}`);
|
|
437
|
+
if (outbase) flags.push(`--outbase=${outbase}`);
|
|
438
|
+
if (tsconfig) flags.push(`--tsconfig=${tsconfig}`);
|
|
439
|
+
if (packages) flags.push(`--packages=${packages}`);
|
|
440
|
+
if (resolveExtensions) flags.push(`--resolve-extensions=${validateAndJoinStringArray(resolveExtensions, "resolve extension")}`);
|
|
441
|
+
if (publicPath) flags.push(`--public-path=${publicPath}`);
|
|
442
|
+
if (entryNames) flags.push(`--entry-names=${entryNames}`);
|
|
443
|
+
if (chunkNames) flags.push(`--chunk-names=${chunkNames}`);
|
|
444
|
+
if (assetNames) flags.push(`--asset-names=${assetNames}`);
|
|
445
|
+
if (mainFields) flags.push(`--main-fields=${validateAndJoinStringArray(mainFields, "main field")}`);
|
|
446
|
+
if (conditions) flags.push(`--conditions=${validateAndJoinStringArray(conditions, "condition")}`);
|
|
447
|
+
if (external) for (let name of external) flags.push(`--external:${validateStringValue(name, "external")}`);
|
|
448
|
+
if (alias) {
|
|
449
|
+
for (let old in alias) {
|
|
450
|
+
if (old.indexOf("=") >= 0) throw new Error(`Invalid package name in alias: ${old}`);
|
|
451
|
+
flags.push(`--alias:${old}=${validateStringValue(alias[old], "alias", old)}`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (banner) {
|
|
455
|
+
for (let type in banner) {
|
|
456
|
+
if (type.indexOf("=") >= 0) throw new Error(`Invalid banner file type: ${type}`);
|
|
457
|
+
flags.push(`--banner:${type}=${validateStringValue(banner[type], "banner", type)}`);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (footer) {
|
|
461
|
+
for (let type in footer) {
|
|
462
|
+
if (type.indexOf("=") >= 0) throw new Error(`Invalid footer file type: ${type}`);
|
|
463
|
+
flags.push(`--footer:${type}=${validateStringValue(footer[type], "footer", type)}`);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if (inject) for (let path3 of inject) flags.push(`--inject:${validateStringValue(path3, "inject")}`);
|
|
467
|
+
if (loader) {
|
|
468
|
+
for (let ext in loader) {
|
|
469
|
+
if (ext.indexOf("=") >= 0) throw new Error(`Invalid loader extension: ${ext}`);
|
|
470
|
+
flags.push(`--loader:${ext}=${validateStringValue(loader[ext], "loader", ext)}`);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
if (outExtension) {
|
|
474
|
+
for (let ext in outExtension) {
|
|
475
|
+
if (ext.indexOf("=") >= 0) throw new Error(`Invalid out extension: ${ext}`);
|
|
476
|
+
flags.push(`--out-extension:${ext}=${validateStringValue(outExtension[ext], "out extension", ext)}`);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (entryPoints) {
|
|
480
|
+
if (Array.isArray(entryPoints)) {
|
|
481
|
+
for (let i = 0, n = entryPoints.length; i < n; i++) {
|
|
482
|
+
let entryPoint = entryPoints[i];
|
|
483
|
+
if (typeof entryPoint === "object" && entryPoint !== null) {
|
|
484
|
+
let entryPointKeys = /* @__PURE__ */ Object.create(null);
|
|
485
|
+
let input = getFlag(entryPoint, entryPointKeys, "in", mustBeString);
|
|
486
|
+
let output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
|
|
487
|
+
checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i);
|
|
488
|
+
if (input === void 0) throw new Error('Missing property "in" for entry point at index ' + i);
|
|
489
|
+
if (output === void 0) throw new Error('Missing property "out" for entry point at index ' + i);
|
|
490
|
+
entries.push([output, input]);
|
|
491
|
+
} else {
|
|
492
|
+
entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
} else {
|
|
496
|
+
for (let key in entryPoints) {
|
|
497
|
+
entries.push([key, validateStringValue(entryPoints[key], "entry point", key)]);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (stdin) {
|
|
502
|
+
let stdinKeys = /* @__PURE__ */ Object.create(null);
|
|
503
|
+
let contents = getFlag(stdin, stdinKeys, "contents", mustBeStringOrUint8Array);
|
|
504
|
+
let resolveDir = getFlag(stdin, stdinKeys, "resolveDir", mustBeString);
|
|
505
|
+
let sourcefile = getFlag(stdin, stdinKeys, "sourcefile", mustBeString);
|
|
506
|
+
let loader2 = getFlag(stdin, stdinKeys, "loader", mustBeString);
|
|
507
|
+
checkForInvalidFlags(stdin, stdinKeys, 'in "stdin" object');
|
|
508
|
+
if (sourcefile) flags.push(`--sourcefile=${sourcefile}`);
|
|
509
|
+
if (loader2) flags.push(`--loader=${loader2}`);
|
|
510
|
+
if (resolveDir) stdinResolveDir = resolveDir;
|
|
511
|
+
if (typeof contents === "string") stdinContents = encodeUTF8(contents);
|
|
512
|
+
else if (contents instanceof Uint8Array) stdinContents = contents;
|
|
513
|
+
}
|
|
514
|
+
let nodePaths = [];
|
|
515
|
+
if (nodePathsInput) {
|
|
516
|
+
for (let value of nodePathsInput) {
|
|
517
|
+
value += "";
|
|
518
|
+
nodePaths.push(value);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return {
|
|
522
|
+
entries,
|
|
523
|
+
flags,
|
|
524
|
+
write,
|
|
525
|
+
stdinContents,
|
|
526
|
+
stdinResolveDir,
|
|
527
|
+
absWorkingDir,
|
|
528
|
+
nodePaths,
|
|
529
|
+
mangleCache: validateMangleCache(mangleCache)
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
function flagsForTransformOptions(callName, options, isTTY2, logLevelDefault) {
|
|
533
|
+
let flags = [];
|
|
534
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
535
|
+
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
|
536
|
+
pushCommonFlags(flags, options, keys);
|
|
537
|
+
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
|
538
|
+
let sourcefile = getFlag(options, keys, "sourcefile", mustBeString);
|
|
539
|
+
let loader = getFlag(options, keys, "loader", mustBeString);
|
|
540
|
+
let banner = getFlag(options, keys, "banner", mustBeString);
|
|
541
|
+
let footer = getFlag(options, keys, "footer", mustBeString);
|
|
542
|
+
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
543
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
544
|
+
if (sourcemap) flags.push(`--sourcemap=${sourcemap === true ? "external" : sourcemap}`);
|
|
545
|
+
if (sourcefile) flags.push(`--sourcefile=${sourcefile}`);
|
|
546
|
+
if (loader) flags.push(`--loader=${loader}`);
|
|
547
|
+
if (banner) flags.push(`--banner=${banner}`);
|
|
548
|
+
if (footer) flags.push(`--footer=${footer}`);
|
|
549
|
+
return {
|
|
550
|
+
flags,
|
|
551
|
+
mangleCache: validateMangleCache(mangleCache)
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
function createChannel(streamIn) {
|
|
555
|
+
const requestCallbacksByKey = {};
|
|
556
|
+
const closeData = { didClose: false, reason: "" };
|
|
557
|
+
let responseCallbacks = {};
|
|
558
|
+
let nextRequestID = 0;
|
|
559
|
+
let nextBuildKey = 0;
|
|
560
|
+
let stdout = new Uint8Array(16 * 1024);
|
|
561
|
+
let stdoutUsed = 0;
|
|
562
|
+
let readFromStdout = (chunk) => {
|
|
563
|
+
let limit = stdoutUsed + chunk.length;
|
|
564
|
+
if (limit > stdout.length) {
|
|
565
|
+
let swap = new Uint8Array(limit * 2);
|
|
566
|
+
swap.set(stdout);
|
|
567
|
+
stdout = swap;
|
|
568
|
+
}
|
|
569
|
+
stdout.set(chunk, stdoutUsed);
|
|
570
|
+
stdoutUsed += chunk.length;
|
|
571
|
+
let offset = 0;
|
|
572
|
+
while (offset + 4 <= stdoutUsed) {
|
|
573
|
+
let length = readUInt32LE(stdout, offset);
|
|
574
|
+
if (offset + 4 + length > stdoutUsed) {
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
offset += 4;
|
|
578
|
+
handleIncomingPacket(stdout.subarray(offset, offset + length));
|
|
579
|
+
offset += length;
|
|
580
|
+
}
|
|
581
|
+
if (offset > 0) {
|
|
582
|
+
stdout.copyWithin(0, offset, stdoutUsed);
|
|
583
|
+
stdoutUsed -= offset;
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
let afterClose = (error) => {
|
|
587
|
+
closeData.didClose = true;
|
|
588
|
+
if (error) closeData.reason = ": " + (error.message || error);
|
|
589
|
+
const text = "The service was stopped" + closeData.reason;
|
|
590
|
+
for (let id in responseCallbacks) {
|
|
591
|
+
responseCallbacks[id](text, null);
|
|
592
|
+
}
|
|
593
|
+
responseCallbacks = {};
|
|
594
|
+
};
|
|
595
|
+
let sendRequest = (refs, value, callback) => {
|
|
596
|
+
if (closeData.didClose) return callback("The service is no longer running" + closeData.reason, null);
|
|
597
|
+
let id = nextRequestID++;
|
|
598
|
+
responseCallbacks[id] = (error, response) => {
|
|
599
|
+
try {
|
|
600
|
+
callback(error, response);
|
|
601
|
+
} finally {
|
|
602
|
+
if (refs) refs.unref();
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
if (refs) refs.ref();
|
|
606
|
+
streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
|
|
607
|
+
};
|
|
608
|
+
let sendResponse = (id, value) => {
|
|
609
|
+
if (closeData.didClose) throw new Error("The service is no longer running" + closeData.reason);
|
|
610
|
+
streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
|
|
611
|
+
};
|
|
612
|
+
let handleRequest = async (id, request) => {
|
|
613
|
+
try {
|
|
614
|
+
if (request.command === "ping") {
|
|
615
|
+
sendResponse(id, {});
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
if (typeof request.key === "number") {
|
|
619
|
+
const requestCallbacks = requestCallbacksByKey[request.key];
|
|
620
|
+
if (!requestCallbacks) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const callback = requestCallbacks[request.command];
|
|
624
|
+
if (callback) {
|
|
625
|
+
await callback(id, request);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
throw new Error(`Invalid command: ` + request.command);
|
|
630
|
+
} catch (e) {
|
|
631
|
+
const errors = [extractErrorMessageV8(e, streamIn, null, void 0, "")];
|
|
632
|
+
try {
|
|
633
|
+
sendResponse(id, { errors });
|
|
634
|
+
} catch {
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
let isFirstPacket = true;
|
|
639
|
+
let handleIncomingPacket = (bytes) => {
|
|
640
|
+
if (isFirstPacket) {
|
|
641
|
+
isFirstPacket = false;
|
|
642
|
+
let binaryVersion = String.fromCharCode(...bytes);
|
|
643
|
+
if (binaryVersion !== "0.25.5") {
|
|
644
|
+
throw new Error(`Cannot start service: Host version "${"0.25.5"}" does not match binary version ${quote(binaryVersion)}`);
|
|
645
|
+
}
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
let packet = decodePacket(bytes);
|
|
649
|
+
if (packet.isRequest) {
|
|
650
|
+
handleRequest(packet.id, packet.value);
|
|
651
|
+
} else {
|
|
652
|
+
let callback = responseCallbacks[packet.id];
|
|
653
|
+
delete responseCallbacks[packet.id];
|
|
654
|
+
if (packet.value.error) callback(packet.value.error, {});
|
|
655
|
+
else callback(null, packet.value);
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
let buildOrContext = ({ callName, refs, options, isTTY: isTTY2, defaultWD: defaultWD2, callback }) => {
|
|
659
|
+
let refCount = 0;
|
|
660
|
+
const buildKey = nextBuildKey++;
|
|
661
|
+
const requestCallbacks = {};
|
|
662
|
+
const buildRefs = {
|
|
663
|
+
ref() {
|
|
664
|
+
if (++refCount === 1) {
|
|
665
|
+
if (refs) refs.ref();
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
unref() {
|
|
669
|
+
if (--refCount === 0) {
|
|
670
|
+
delete requestCallbacksByKey[buildKey];
|
|
671
|
+
if (refs) refs.unref();
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
requestCallbacksByKey[buildKey] = requestCallbacks;
|
|
676
|
+
buildRefs.ref();
|
|
677
|
+
buildOrContextImpl(
|
|
678
|
+
callName,
|
|
679
|
+
buildKey,
|
|
680
|
+
sendRequest,
|
|
681
|
+
sendResponse,
|
|
682
|
+
buildRefs,
|
|
683
|
+
streamIn,
|
|
684
|
+
requestCallbacks,
|
|
685
|
+
options,
|
|
686
|
+
isTTY2,
|
|
687
|
+
defaultWD2,
|
|
688
|
+
(err, res) => {
|
|
689
|
+
try {
|
|
690
|
+
callback(err, res);
|
|
691
|
+
} finally {
|
|
692
|
+
buildRefs.unref();
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
);
|
|
696
|
+
};
|
|
697
|
+
let transform2 = ({ callName, refs, input, options, isTTY: isTTY2, fs: fs3, callback }) => {
|
|
698
|
+
const details = createObjectStash();
|
|
699
|
+
let start = (inputPath) => {
|
|
700
|
+
try {
|
|
701
|
+
if (typeof input !== "string" && !(input instanceof Uint8Array))
|
|
702
|
+
throw new Error('The input to "transform" must be a string or a Uint8Array');
|
|
703
|
+
let {
|
|
704
|
+
flags,
|
|
705
|
+
mangleCache
|
|
706
|
+
} = flagsForTransformOptions(callName, options, isTTY2, transformLogLevelDefault);
|
|
707
|
+
let request = {
|
|
708
|
+
command: "transform",
|
|
709
|
+
flags,
|
|
710
|
+
inputFS: inputPath !== null,
|
|
711
|
+
input: inputPath !== null ? encodeUTF8(inputPath) : typeof input === "string" ? encodeUTF8(input) : input
|
|
712
|
+
};
|
|
713
|
+
if (mangleCache) request.mangleCache = mangleCache;
|
|
714
|
+
sendRequest(refs, request, (error, response) => {
|
|
715
|
+
if (error) return callback(new Error(error), null);
|
|
716
|
+
let errors = replaceDetailsInMessages(response.errors, details);
|
|
717
|
+
let warnings = replaceDetailsInMessages(response.warnings, details);
|
|
718
|
+
let outstanding = 1;
|
|
719
|
+
let next = () => {
|
|
720
|
+
if (--outstanding === 0) {
|
|
721
|
+
let result = {
|
|
722
|
+
warnings,
|
|
723
|
+
code: response.code,
|
|
724
|
+
map: response.map,
|
|
725
|
+
mangleCache: void 0,
|
|
726
|
+
legalComments: void 0
|
|
727
|
+
};
|
|
728
|
+
if ("legalComments" in response) result.legalComments = response == null ? void 0 : response.legalComments;
|
|
729
|
+
if (response.mangleCache) result.mangleCache = response == null ? void 0 : response.mangleCache;
|
|
730
|
+
callback(null, result);
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
if (errors.length > 0) return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
|
|
734
|
+
if (response.codeFS) {
|
|
735
|
+
outstanding++;
|
|
736
|
+
fs3.readFile(response.code, (err, contents) => {
|
|
737
|
+
if (err !== null) {
|
|
738
|
+
callback(err, null);
|
|
739
|
+
} else {
|
|
740
|
+
response.code = contents;
|
|
741
|
+
next();
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
if (response.mapFS) {
|
|
746
|
+
outstanding++;
|
|
747
|
+
fs3.readFile(response.map, (err, contents) => {
|
|
748
|
+
if (err !== null) {
|
|
749
|
+
callback(err, null);
|
|
750
|
+
} else {
|
|
751
|
+
response.map = contents;
|
|
752
|
+
next();
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
next();
|
|
757
|
+
});
|
|
758
|
+
} catch (e) {
|
|
759
|
+
let flags = [];
|
|
760
|
+
try {
|
|
761
|
+
pushLogFlags(flags, options, {}, isTTY2, transformLogLevelDefault);
|
|
762
|
+
} catch {
|
|
763
|
+
}
|
|
764
|
+
const error = extractErrorMessageV8(e, streamIn, details, void 0, "");
|
|
765
|
+
sendRequest(refs, { command: "error", flags, error }, () => {
|
|
766
|
+
error.detail = details.load(error.detail);
|
|
767
|
+
callback(failureErrorWithLog("Transform failed", [error], []), null);
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
if ((typeof input === "string" || input instanceof Uint8Array) && input.length > 1024 * 1024) {
|
|
772
|
+
let next = start;
|
|
773
|
+
start = () => fs3.writeFile(input, next);
|
|
774
|
+
}
|
|
775
|
+
start(null);
|
|
776
|
+
};
|
|
777
|
+
let formatMessages2 = ({ callName, refs, messages, options, callback }) => {
|
|
778
|
+
if (!options) throw new Error(`Missing second argument in ${callName}() call`);
|
|
779
|
+
let keys = {};
|
|
780
|
+
let kind = getFlag(options, keys, "kind", mustBeString);
|
|
781
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
782
|
+
let terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger);
|
|
783
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
784
|
+
if (kind === void 0) throw new Error(`Missing "kind" in ${callName}() call`);
|
|
785
|
+
if (kind !== "error" && kind !== "warning") throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
|
|
786
|
+
let request = {
|
|
787
|
+
command: "format-msgs",
|
|
788
|
+
messages: sanitizeMessages(messages, "messages", null, "", terminalWidth),
|
|
789
|
+
isWarning: kind === "warning"
|
|
790
|
+
};
|
|
791
|
+
if (color !== void 0) request.color = color;
|
|
792
|
+
if (terminalWidth !== void 0) request.terminalWidth = terminalWidth;
|
|
793
|
+
sendRequest(refs, request, (error, response) => {
|
|
794
|
+
if (error) return callback(new Error(error), null);
|
|
795
|
+
callback(null, response.messages);
|
|
796
|
+
});
|
|
797
|
+
};
|
|
798
|
+
let analyzeMetafile2 = ({ callName, refs, metafile, options, callback }) => {
|
|
799
|
+
if (options === void 0) options = {};
|
|
800
|
+
let keys = {};
|
|
801
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
802
|
+
let verbose = getFlag(options, keys, "verbose", mustBeBoolean);
|
|
803
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
804
|
+
let request = {
|
|
805
|
+
command: "analyze-metafile",
|
|
806
|
+
metafile
|
|
807
|
+
};
|
|
808
|
+
if (color !== void 0) request.color = color;
|
|
809
|
+
if (verbose !== void 0) request.verbose = verbose;
|
|
810
|
+
sendRequest(refs, request, (error, response) => {
|
|
811
|
+
if (error) return callback(new Error(error), null);
|
|
812
|
+
callback(null, response.result);
|
|
813
|
+
});
|
|
814
|
+
};
|
|
815
|
+
return {
|
|
816
|
+
readFromStdout,
|
|
817
|
+
afterClose,
|
|
818
|
+
service: {
|
|
819
|
+
buildOrContext,
|
|
820
|
+
transform: transform2,
|
|
821
|
+
formatMessages: formatMessages2,
|
|
822
|
+
analyzeMetafile: analyzeMetafile2
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, isTTY2, defaultWD2, callback) {
|
|
827
|
+
const details = createObjectStash();
|
|
828
|
+
const isContext = callName === "context";
|
|
829
|
+
const handleError = (e, pluginName) => {
|
|
830
|
+
const flags = [];
|
|
831
|
+
try {
|
|
832
|
+
pushLogFlags(flags, options, {}, isTTY2, buildLogLevelDefault);
|
|
833
|
+
} catch {
|
|
834
|
+
}
|
|
835
|
+
const message = extractErrorMessageV8(e, streamIn, details, void 0, pluginName);
|
|
836
|
+
sendRequest(refs, { command: "error", flags, error: message }, () => {
|
|
837
|
+
message.detail = details.load(message.detail);
|
|
838
|
+
callback(failureErrorWithLog(isContext ? "Context failed" : "Build failed", [message], []), null);
|
|
839
|
+
});
|
|
840
|
+
};
|
|
841
|
+
let plugins;
|
|
842
|
+
if (typeof options === "object") {
|
|
843
|
+
const value = options.plugins;
|
|
844
|
+
if (value !== void 0) {
|
|
845
|
+
if (!Array.isArray(value)) return handleError(new Error(`"plugins" must be an array`), "");
|
|
846
|
+
plugins = value;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
if (plugins && plugins.length > 0) {
|
|
850
|
+
if (streamIn.isSync) return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
|
851
|
+
handlePlugins(
|
|
852
|
+
buildKey,
|
|
853
|
+
sendRequest,
|
|
854
|
+
sendResponse,
|
|
855
|
+
refs,
|
|
856
|
+
streamIn,
|
|
857
|
+
requestCallbacks,
|
|
858
|
+
options,
|
|
859
|
+
plugins,
|
|
860
|
+
details
|
|
861
|
+
).then(
|
|
862
|
+
(result) => {
|
|
863
|
+
if (!result.ok) return handleError(result.error, result.pluginName);
|
|
864
|
+
try {
|
|
865
|
+
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
|
|
866
|
+
} catch (e) {
|
|
867
|
+
handleError(e, "");
|
|
868
|
+
}
|
|
869
|
+
},
|
|
870
|
+
(e) => handleError(e, "")
|
|
871
|
+
);
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
try {
|
|
875
|
+
buildOrContextContinue(null, (result, done) => done([], []), () => {
|
|
876
|
+
});
|
|
877
|
+
} catch (e) {
|
|
878
|
+
handleError(e, "");
|
|
879
|
+
}
|
|
880
|
+
function buildOrContextContinue(requestPlugins, runOnEndCallbacks, scheduleOnDisposeCallbacks) {
|
|
881
|
+
const writeDefault = streamIn.hasFS;
|
|
882
|
+
const {
|
|
883
|
+
entries,
|
|
884
|
+
flags,
|
|
885
|
+
write,
|
|
886
|
+
stdinContents,
|
|
887
|
+
stdinResolveDir,
|
|
888
|
+
absWorkingDir,
|
|
889
|
+
nodePaths,
|
|
890
|
+
mangleCache
|
|
891
|
+
} = flagsForBuildOptions(callName, options, isTTY2, buildLogLevelDefault, writeDefault);
|
|
892
|
+
if (write && !streamIn.hasFS) throw new Error(`The "write" option is unavailable in this environment`);
|
|
893
|
+
const request = {
|
|
894
|
+
command: "build",
|
|
895
|
+
key: buildKey,
|
|
896
|
+
entries,
|
|
897
|
+
flags,
|
|
898
|
+
write,
|
|
899
|
+
stdinContents,
|
|
900
|
+
stdinResolveDir,
|
|
901
|
+
absWorkingDir: absWorkingDir || defaultWD2,
|
|
902
|
+
nodePaths,
|
|
903
|
+
context: isContext
|
|
904
|
+
};
|
|
905
|
+
if (requestPlugins) request.plugins = requestPlugins;
|
|
906
|
+
if (mangleCache) request.mangleCache = mangleCache;
|
|
907
|
+
const buildResponseToResult = (response, callback2) => {
|
|
908
|
+
const result = {
|
|
909
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
910
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
911
|
+
outputFiles: void 0,
|
|
912
|
+
metafile: void 0,
|
|
913
|
+
mangleCache: void 0
|
|
914
|
+
};
|
|
915
|
+
const originalErrors = result.errors.slice();
|
|
916
|
+
const originalWarnings = result.warnings.slice();
|
|
917
|
+
if (response.outputFiles) result.outputFiles = response.outputFiles.map(convertOutputFiles);
|
|
918
|
+
if (response.metafile) result.metafile = JSON.parse(response.metafile);
|
|
919
|
+
if (response.mangleCache) result.mangleCache = response.mangleCache;
|
|
920
|
+
if (response.writeToStdout !== void 0) console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
|
921
|
+
runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
|
|
922
|
+
if (originalErrors.length > 0 || onEndErrors.length > 0) {
|
|
923
|
+
const error = failureErrorWithLog("Build failed", originalErrors.concat(onEndErrors), originalWarnings.concat(onEndWarnings));
|
|
924
|
+
return callback2(error, null, onEndErrors, onEndWarnings);
|
|
925
|
+
}
|
|
926
|
+
callback2(null, result, onEndErrors, onEndWarnings);
|
|
927
|
+
});
|
|
928
|
+
};
|
|
929
|
+
let latestResultPromise;
|
|
930
|
+
let provideLatestResult;
|
|
931
|
+
if (isContext)
|
|
932
|
+
requestCallbacks["on-end"] = (id, request2) => new Promise((resolve2) => {
|
|
933
|
+
buildResponseToResult(request2, (err, result, onEndErrors, onEndWarnings) => {
|
|
934
|
+
const response = {
|
|
935
|
+
errors: onEndErrors,
|
|
936
|
+
warnings: onEndWarnings
|
|
937
|
+
};
|
|
938
|
+
if (provideLatestResult) provideLatestResult(err, result);
|
|
939
|
+
latestResultPromise = void 0;
|
|
940
|
+
provideLatestResult = void 0;
|
|
941
|
+
sendResponse(id, response);
|
|
942
|
+
resolve2();
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
sendRequest(refs, request, (error, response) => {
|
|
946
|
+
if (error) return callback(new Error(error), null);
|
|
947
|
+
if (!isContext) {
|
|
948
|
+
return buildResponseToResult(response, (err, res) => {
|
|
949
|
+
scheduleOnDisposeCallbacks();
|
|
950
|
+
return callback(err, res);
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
if (response.errors.length > 0) {
|
|
954
|
+
return callback(failureErrorWithLog("Context failed", response.errors, response.warnings), null);
|
|
955
|
+
}
|
|
956
|
+
let didDispose = false;
|
|
957
|
+
const result = {
|
|
958
|
+
rebuild: () => {
|
|
959
|
+
if (!latestResultPromise) latestResultPromise = new Promise((resolve2, reject) => {
|
|
960
|
+
let settlePromise;
|
|
961
|
+
provideLatestResult = (err, result2) => {
|
|
962
|
+
if (!settlePromise) settlePromise = () => err ? reject(err) : resolve2(result2);
|
|
963
|
+
};
|
|
964
|
+
const triggerAnotherBuild = () => {
|
|
965
|
+
const request2 = {
|
|
966
|
+
command: "rebuild",
|
|
967
|
+
key: buildKey
|
|
968
|
+
};
|
|
969
|
+
sendRequest(refs, request2, (error2, response2) => {
|
|
970
|
+
if (error2) {
|
|
971
|
+
reject(new Error(error2));
|
|
972
|
+
} else if (settlePromise) {
|
|
973
|
+
settlePromise();
|
|
974
|
+
} else {
|
|
975
|
+
triggerAnotherBuild();
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
};
|
|
979
|
+
triggerAnotherBuild();
|
|
980
|
+
});
|
|
981
|
+
return latestResultPromise;
|
|
982
|
+
},
|
|
983
|
+
watch: (options2 = {}) => new Promise((resolve2, reject) => {
|
|
984
|
+
if (!streamIn.hasFS) throw new Error(`Cannot use the "watch" API in this environment`);
|
|
985
|
+
const keys = {};
|
|
986
|
+
checkForInvalidFlags(options2, keys, `in watch() call`);
|
|
987
|
+
const request2 = {
|
|
988
|
+
command: "watch",
|
|
989
|
+
key: buildKey
|
|
990
|
+
};
|
|
991
|
+
sendRequest(refs, request2, (error2) => {
|
|
992
|
+
if (error2) reject(new Error(error2));
|
|
993
|
+
else resolve2(void 0);
|
|
994
|
+
});
|
|
995
|
+
}),
|
|
996
|
+
serve: (options2 = {}) => new Promise((resolve2, reject) => {
|
|
997
|
+
if (!streamIn.hasFS) throw new Error(`Cannot use the "serve" API in this environment`);
|
|
998
|
+
const keys = {};
|
|
999
|
+
const port = getFlag(options2, keys, "port", mustBeValidPortNumber);
|
|
1000
|
+
const host = getFlag(options2, keys, "host", mustBeString);
|
|
1001
|
+
const servedir = getFlag(options2, keys, "servedir", mustBeString);
|
|
1002
|
+
const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
|
|
1003
|
+
const certfile = getFlag(options2, keys, "certfile", mustBeString);
|
|
1004
|
+
const fallback = getFlag(options2, keys, "fallback", mustBeString);
|
|
1005
|
+
const cors = getFlag(options2, keys, "cors", mustBeObject);
|
|
1006
|
+
const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
|
|
1007
|
+
checkForInvalidFlags(options2, keys, `in serve() call`);
|
|
1008
|
+
const request2 = {
|
|
1009
|
+
command: "serve",
|
|
1010
|
+
key: buildKey,
|
|
1011
|
+
onRequest: !!onRequest
|
|
1012
|
+
};
|
|
1013
|
+
if (port !== void 0) request2.port = port;
|
|
1014
|
+
if (host !== void 0) request2.host = host;
|
|
1015
|
+
if (servedir !== void 0) request2.servedir = servedir;
|
|
1016
|
+
if (keyfile !== void 0) request2.keyfile = keyfile;
|
|
1017
|
+
if (certfile !== void 0) request2.certfile = certfile;
|
|
1018
|
+
if (fallback !== void 0) request2.fallback = fallback;
|
|
1019
|
+
if (cors) {
|
|
1020
|
+
const corsKeys = {};
|
|
1021
|
+
const origin = getFlag(cors, corsKeys, "origin", mustBeStringOrArrayOfStrings);
|
|
1022
|
+
checkForInvalidFlags(cors, corsKeys, `on "cors" object`);
|
|
1023
|
+
if (Array.isArray(origin)) request2.corsOrigin = origin;
|
|
1024
|
+
else if (origin !== void 0) request2.corsOrigin = [origin];
|
|
1025
|
+
}
|
|
1026
|
+
sendRequest(refs, request2, (error2, response2) => {
|
|
1027
|
+
if (error2) return reject(new Error(error2));
|
|
1028
|
+
if (onRequest) {
|
|
1029
|
+
requestCallbacks["serve-request"] = (id, request3) => {
|
|
1030
|
+
onRequest(request3.args);
|
|
1031
|
+
sendResponse(id, {});
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
resolve2(response2);
|
|
1035
|
+
});
|
|
1036
|
+
}),
|
|
1037
|
+
cancel: () => new Promise((resolve2) => {
|
|
1038
|
+
if (didDispose) return resolve2();
|
|
1039
|
+
const request2 = {
|
|
1040
|
+
command: "cancel",
|
|
1041
|
+
key: buildKey
|
|
1042
|
+
};
|
|
1043
|
+
sendRequest(refs, request2, () => {
|
|
1044
|
+
resolve2();
|
|
1045
|
+
});
|
|
1046
|
+
}),
|
|
1047
|
+
dispose: () => new Promise((resolve2) => {
|
|
1048
|
+
if (didDispose) return resolve2();
|
|
1049
|
+
didDispose = true;
|
|
1050
|
+
const request2 = {
|
|
1051
|
+
command: "dispose",
|
|
1052
|
+
key: buildKey
|
|
1053
|
+
};
|
|
1054
|
+
sendRequest(refs, request2, () => {
|
|
1055
|
+
resolve2();
|
|
1056
|
+
scheduleOnDisposeCallbacks();
|
|
1057
|
+
refs.unref();
|
|
1058
|
+
});
|
|
1059
|
+
})
|
|
1060
|
+
};
|
|
1061
|
+
refs.ref();
|
|
1062
|
+
callback(null, result);
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, initialOptions, plugins, details) => {
|
|
1067
|
+
let onStartCallbacks = [];
|
|
1068
|
+
let onEndCallbacks = [];
|
|
1069
|
+
let onResolveCallbacks = {};
|
|
1070
|
+
let onLoadCallbacks = {};
|
|
1071
|
+
let onDisposeCallbacks = [];
|
|
1072
|
+
let nextCallbackID = 0;
|
|
1073
|
+
let i = 0;
|
|
1074
|
+
let requestPlugins = [];
|
|
1075
|
+
let isSetupDone = false;
|
|
1076
|
+
plugins = [...plugins];
|
|
1077
|
+
for (let item of plugins) {
|
|
1078
|
+
let keys = {};
|
|
1079
|
+
if (typeof item !== "object") throw new Error(`Plugin at index ${i} must be an object`);
|
|
1080
|
+
const name = getFlag(item, keys, "name", mustBeString);
|
|
1081
|
+
if (typeof name !== "string" || name === "") throw new Error(`Plugin at index ${i} is missing a name`);
|
|
1082
|
+
try {
|
|
1083
|
+
let setup = getFlag(item, keys, "setup", mustBeFunction);
|
|
1084
|
+
if (typeof setup !== "function") throw new Error(`Plugin is missing a setup function`);
|
|
1085
|
+
checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
|
|
1086
|
+
let plugin = {
|
|
1087
|
+
name,
|
|
1088
|
+
onStart: false,
|
|
1089
|
+
onEnd: false,
|
|
1090
|
+
onResolve: [],
|
|
1091
|
+
onLoad: []
|
|
1092
|
+
};
|
|
1093
|
+
i++;
|
|
1094
|
+
let resolve2 = (path3, options = {}) => {
|
|
1095
|
+
if (!isSetupDone) throw new Error('Cannot call "resolve" before plugin setup has completed');
|
|
1096
|
+
if (typeof path3 !== "string") throw new Error(`The path to resolve must be a string`);
|
|
1097
|
+
let keys2 = /* @__PURE__ */ Object.create(null);
|
|
1098
|
+
let pluginName = getFlag(options, keys2, "pluginName", mustBeString);
|
|
1099
|
+
let importer = getFlag(options, keys2, "importer", mustBeString);
|
|
1100
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
1101
|
+
let resolveDir = getFlag(options, keys2, "resolveDir", mustBeString);
|
|
1102
|
+
let kind = getFlag(options, keys2, "kind", mustBeString);
|
|
1103
|
+
let pluginData = getFlag(options, keys2, "pluginData", canBeAnything);
|
|
1104
|
+
let importAttributes = getFlag(options, keys2, "with", mustBeObject);
|
|
1105
|
+
checkForInvalidFlags(options, keys2, "in resolve() call");
|
|
1106
|
+
return new Promise((resolve22, reject) => {
|
|
1107
|
+
const request = {
|
|
1108
|
+
command: "resolve",
|
|
1109
|
+
path: path3,
|
|
1110
|
+
key: buildKey,
|
|
1111
|
+
pluginName: name
|
|
1112
|
+
};
|
|
1113
|
+
if (pluginName != null) request.pluginName = pluginName;
|
|
1114
|
+
if (importer != null) request.importer = importer;
|
|
1115
|
+
if (namespace != null) request.namespace = namespace;
|
|
1116
|
+
if (resolveDir != null) request.resolveDir = resolveDir;
|
|
1117
|
+
if (kind != null) request.kind = kind;
|
|
1118
|
+
else throw new Error(`Must specify "kind" when calling "resolve"`);
|
|
1119
|
+
if (pluginData != null) request.pluginData = details.store(pluginData);
|
|
1120
|
+
if (importAttributes != null) request.with = sanitizeStringMap(importAttributes, "with");
|
|
1121
|
+
sendRequest(refs, request, (error, response) => {
|
|
1122
|
+
if (error !== null) reject(new Error(error));
|
|
1123
|
+
else resolve22({
|
|
1124
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
1125
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
1126
|
+
path: response.path,
|
|
1127
|
+
external: response.external,
|
|
1128
|
+
sideEffects: response.sideEffects,
|
|
1129
|
+
namespace: response.namespace,
|
|
1130
|
+
suffix: response.suffix,
|
|
1131
|
+
pluginData: details.load(response.pluginData)
|
|
1132
|
+
});
|
|
1133
|
+
});
|
|
1134
|
+
});
|
|
1135
|
+
};
|
|
1136
|
+
let promise = setup({
|
|
1137
|
+
initialOptions,
|
|
1138
|
+
resolve: resolve2,
|
|
1139
|
+
onStart(callback) {
|
|
1140
|
+
let registeredText = `This error came from the "onStart" callback registered here:`;
|
|
1141
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
|
|
1142
|
+
onStartCallbacks.push({ name, callback, note: registeredNote });
|
|
1143
|
+
plugin.onStart = true;
|
|
1144
|
+
},
|
|
1145
|
+
onEnd(callback) {
|
|
1146
|
+
let registeredText = `This error came from the "onEnd" callback registered here:`;
|
|
1147
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
|
|
1148
|
+
onEndCallbacks.push({ name, callback, note: registeredNote });
|
|
1149
|
+
plugin.onEnd = true;
|
|
1150
|
+
},
|
|
1151
|
+
onResolve(options, callback) {
|
|
1152
|
+
let registeredText = `This error came from the "onResolve" callback registered here:`;
|
|
1153
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve");
|
|
1154
|
+
let keys2 = {};
|
|
1155
|
+
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
1156
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
1157
|
+
checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${quote(name)}`);
|
|
1158
|
+
if (filter == null) throw new Error(`onResolve() call is missing a filter`);
|
|
1159
|
+
let id = nextCallbackID++;
|
|
1160
|
+
onResolveCallbacks[id] = { name, callback, note: registeredNote };
|
|
1161
|
+
plugin.onResolve.push({ id, filter: jsRegExpToGoRegExp(filter), namespace: namespace || "" });
|
|
1162
|
+
},
|
|
1163
|
+
onLoad(options, callback) {
|
|
1164
|
+
let registeredText = `This error came from the "onLoad" callback registered here:`;
|
|
1165
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad");
|
|
1166
|
+
let keys2 = {};
|
|
1167
|
+
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
1168
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
1169
|
+
checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${quote(name)}`);
|
|
1170
|
+
if (filter == null) throw new Error(`onLoad() call is missing a filter`);
|
|
1171
|
+
let id = nextCallbackID++;
|
|
1172
|
+
onLoadCallbacks[id] = { name, callback, note: registeredNote };
|
|
1173
|
+
plugin.onLoad.push({ id, filter: jsRegExpToGoRegExp(filter), namespace: namespace || "" });
|
|
1174
|
+
},
|
|
1175
|
+
onDispose(callback) {
|
|
1176
|
+
onDisposeCallbacks.push(callback);
|
|
1177
|
+
},
|
|
1178
|
+
esbuild: streamIn.esbuild
|
|
1179
|
+
});
|
|
1180
|
+
if (promise) await promise;
|
|
1181
|
+
requestPlugins.push(plugin);
|
|
1182
|
+
} catch (e) {
|
|
1183
|
+
return { ok: false, error: e, pluginName: name };
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
requestCallbacks["on-start"] = async (id, request) => {
|
|
1187
|
+
details.clear();
|
|
1188
|
+
let response = { errors: [], warnings: [] };
|
|
1189
|
+
await Promise.all(onStartCallbacks.map(async ({ name, callback, note }) => {
|
|
1190
|
+
try {
|
|
1191
|
+
let result = await callback();
|
|
1192
|
+
if (result != null) {
|
|
1193
|
+
if (typeof result !== "object") throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
|
|
1194
|
+
let keys = {};
|
|
1195
|
+
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
1196
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1197
|
+
checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${quote(name)}`);
|
|
1198
|
+
if (errors != null) response.errors.push(...sanitizeMessages(errors, "errors", details, name, void 0));
|
|
1199
|
+
if (warnings != null) response.warnings.push(...sanitizeMessages(warnings, "warnings", details, name, void 0));
|
|
1200
|
+
}
|
|
1201
|
+
} catch (e) {
|
|
1202
|
+
response.errors.push(extractErrorMessageV8(e, streamIn, details, note && note(), name));
|
|
1203
|
+
}
|
|
1204
|
+
}));
|
|
1205
|
+
sendResponse(id, response);
|
|
1206
|
+
};
|
|
1207
|
+
requestCallbacks["on-resolve"] = async (id, request) => {
|
|
1208
|
+
let response = {}, name = "", callback, note;
|
|
1209
|
+
for (let id2 of request.ids) {
|
|
1210
|
+
try {
|
|
1211
|
+
({ name, callback, note } = onResolveCallbacks[id2]);
|
|
1212
|
+
let result = await callback({
|
|
1213
|
+
path: request.path,
|
|
1214
|
+
importer: request.importer,
|
|
1215
|
+
namespace: request.namespace,
|
|
1216
|
+
resolveDir: request.resolveDir,
|
|
1217
|
+
kind: request.kind,
|
|
1218
|
+
pluginData: details.load(request.pluginData),
|
|
1219
|
+
with: request.with
|
|
1220
|
+
});
|
|
1221
|
+
if (result != null) {
|
|
1222
|
+
if (typeof result !== "object") throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
|
|
1223
|
+
let keys = {};
|
|
1224
|
+
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
1225
|
+
let path3 = getFlag(result, keys, "path", mustBeString);
|
|
1226
|
+
let namespace = getFlag(result, keys, "namespace", mustBeString);
|
|
1227
|
+
let suffix = getFlag(result, keys, "suffix", mustBeString);
|
|
1228
|
+
let external = getFlag(result, keys, "external", mustBeBoolean);
|
|
1229
|
+
let sideEffects = getFlag(result, keys, "sideEffects", mustBeBoolean);
|
|
1230
|
+
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
|
1231
|
+
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
1232
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1233
|
+
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
|
|
1234
|
+
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
|
1235
|
+
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
|
|
1236
|
+
response.id = id2;
|
|
1237
|
+
if (pluginName != null) response.pluginName = pluginName;
|
|
1238
|
+
if (path3 != null) response.path = path3;
|
|
1239
|
+
if (namespace != null) response.namespace = namespace;
|
|
1240
|
+
if (suffix != null) response.suffix = suffix;
|
|
1241
|
+
if (external != null) response.external = external;
|
|
1242
|
+
if (sideEffects != null) response.sideEffects = sideEffects;
|
|
1243
|
+
if (pluginData != null) response.pluginData = details.store(pluginData);
|
|
1244
|
+
if (errors != null) response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1245
|
+
if (warnings != null) response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1246
|
+
if (watchFiles != null) response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
1247
|
+
if (watchDirs != null) response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1250
|
+
} catch (e) {
|
|
1251
|
+
response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
|
|
1252
|
+
break;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
sendResponse(id, response);
|
|
1256
|
+
};
|
|
1257
|
+
requestCallbacks["on-load"] = async (id, request) => {
|
|
1258
|
+
let response = {}, name = "", callback, note;
|
|
1259
|
+
for (let id2 of request.ids) {
|
|
1260
|
+
try {
|
|
1261
|
+
({ name, callback, note } = onLoadCallbacks[id2]);
|
|
1262
|
+
let result = await callback({
|
|
1263
|
+
path: request.path,
|
|
1264
|
+
namespace: request.namespace,
|
|
1265
|
+
suffix: request.suffix,
|
|
1266
|
+
pluginData: details.load(request.pluginData),
|
|
1267
|
+
with: request.with
|
|
1268
|
+
});
|
|
1269
|
+
if (result != null) {
|
|
1270
|
+
if (typeof result !== "object") throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
|
|
1271
|
+
let keys = {};
|
|
1272
|
+
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
1273
|
+
let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
|
|
1274
|
+
let resolveDir = getFlag(result, keys, "resolveDir", mustBeString);
|
|
1275
|
+
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
|
1276
|
+
let loader = getFlag(result, keys, "loader", mustBeString);
|
|
1277
|
+
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
1278
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1279
|
+
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
|
|
1280
|
+
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
|
1281
|
+
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
|
|
1282
|
+
response.id = id2;
|
|
1283
|
+
if (pluginName != null) response.pluginName = pluginName;
|
|
1284
|
+
if (contents instanceof Uint8Array) response.contents = contents;
|
|
1285
|
+
else if (contents != null) response.contents = encodeUTF8(contents);
|
|
1286
|
+
if (resolveDir != null) response.resolveDir = resolveDir;
|
|
1287
|
+
if (pluginData != null) response.pluginData = details.store(pluginData);
|
|
1288
|
+
if (loader != null) response.loader = loader;
|
|
1289
|
+
if (errors != null) response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1290
|
+
if (warnings != null) response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1291
|
+
if (watchFiles != null) response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
1292
|
+
if (watchDirs != null) response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
1293
|
+
break;
|
|
1294
|
+
}
|
|
1295
|
+
} catch (e) {
|
|
1296
|
+
response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
|
|
1297
|
+
break;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
sendResponse(id, response);
|
|
1301
|
+
};
|
|
1302
|
+
let runOnEndCallbacks = (result, done) => done([], []);
|
|
1303
|
+
if (onEndCallbacks.length > 0) {
|
|
1304
|
+
runOnEndCallbacks = (result, done) => {
|
|
1305
|
+
(async () => {
|
|
1306
|
+
const onEndErrors = [];
|
|
1307
|
+
const onEndWarnings = [];
|
|
1308
|
+
for (const { name, callback, note } of onEndCallbacks) {
|
|
1309
|
+
let newErrors;
|
|
1310
|
+
let newWarnings;
|
|
1311
|
+
try {
|
|
1312
|
+
const value = await callback(result);
|
|
1313
|
+
if (value != null) {
|
|
1314
|
+
if (typeof value !== "object") throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
|
|
1315
|
+
let keys = {};
|
|
1316
|
+
let errors = getFlag(value, keys, "errors", mustBeArray);
|
|
1317
|
+
let warnings = getFlag(value, keys, "warnings", mustBeArray);
|
|
1318
|
+
checkForInvalidFlags(value, keys, `from onEnd() callback in plugin ${quote(name)}`);
|
|
1319
|
+
if (errors != null) newErrors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1320
|
+
if (warnings != null) newWarnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1321
|
+
}
|
|
1322
|
+
} catch (e) {
|
|
1323
|
+
newErrors = [extractErrorMessageV8(e, streamIn, details, note && note(), name)];
|
|
1324
|
+
}
|
|
1325
|
+
if (newErrors) {
|
|
1326
|
+
onEndErrors.push(...newErrors);
|
|
1327
|
+
try {
|
|
1328
|
+
result.errors.push(...newErrors);
|
|
1329
|
+
} catch {
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
if (newWarnings) {
|
|
1333
|
+
onEndWarnings.push(...newWarnings);
|
|
1334
|
+
try {
|
|
1335
|
+
result.warnings.push(...newWarnings);
|
|
1336
|
+
} catch {
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
done(onEndErrors, onEndWarnings);
|
|
1341
|
+
})();
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
let scheduleOnDisposeCallbacks = () => {
|
|
1345
|
+
for (const cb of onDisposeCallbacks) {
|
|
1346
|
+
setTimeout(() => cb(), 0);
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
isSetupDone = true;
|
|
1350
|
+
return {
|
|
1351
|
+
ok: true,
|
|
1352
|
+
requestPlugins,
|
|
1353
|
+
runOnEndCallbacks,
|
|
1354
|
+
scheduleOnDisposeCallbacks
|
|
1355
|
+
};
|
|
1356
|
+
};
|
|
1357
|
+
function createObjectStash() {
|
|
1358
|
+
const map = /* @__PURE__ */ new Map();
|
|
1359
|
+
let nextID = 0;
|
|
1360
|
+
return {
|
|
1361
|
+
clear() {
|
|
1362
|
+
map.clear();
|
|
1363
|
+
},
|
|
1364
|
+
load(id) {
|
|
1365
|
+
return map.get(id);
|
|
1366
|
+
},
|
|
1367
|
+
store(value) {
|
|
1368
|
+
if (value === void 0) return -1;
|
|
1369
|
+
const id = nextID++;
|
|
1370
|
+
map.set(id, value);
|
|
1371
|
+
return id;
|
|
1372
|
+
}
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
function extractCallerV8(e, streamIn, ident) {
|
|
1376
|
+
let note;
|
|
1377
|
+
let tried = false;
|
|
1378
|
+
return () => {
|
|
1379
|
+
if (tried) return note;
|
|
1380
|
+
tried = true;
|
|
1381
|
+
try {
|
|
1382
|
+
let lines = (e.stack + "").split("\n");
|
|
1383
|
+
lines.splice(1, 1);
|
|
1384
|
+
let location = parseStackLinesV8(streamIn, lines, ident);
|
|
1385
|
+
if (location) {
|
|
1386
|
+
note = { text: e.message, location };
|
|
1387
|
+
return note;
|
|
1388
|
+
}
|
|
1389
|
+
} catch {
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
function extractErrorMessageV8(e, streamIn, stash, note, pluginName) {
|
|
1394
|
+
let text = "Internal error";
|
|
1395
|
+
let location = null;
|
|
1396
|
+
try {
|
|
1397
|
+
text = (e && e.message || e) + "";
|
|
1398
|
+
} catch {
|
|
1399
|
+
}
|
|
1400
|
+
try {
|
|
1401
|
+
location = parseStackLinesV8(streamIn, (e.stack + "").split("\n"), "");
|
|
1402
|
+
} catch {
|
|
1403
|
+
}
|
|
1404
|
+
return { id: "", pluginName, text, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1 };
|
|
1405
|
+
}
|
|
1406
|
+
function parseStackLinesV8(streamIn, lines, ident) {
|
|
1407
|
+
let at = " at ";
|
|
1408
|
+
if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at)) {
|
|
1409
|
+
for (let i = 1; i < lines.length; i++) {
|
|
1410
|
+
let line = lines[i];
|
|
1411
|
+
if (!line.startsWith(at)) continue;
|
|
1412
|
+
line = line.slice(at.length);
|
|
1413
|
+
while (true) {
|
|
1414
|
+
let match = /^(?:new |async )?\S+ \((.*)\)$/.exec(line);
|
|
1415
|
+
if (match) {
|
|
1416
|
+
line = match[1];
|
|
1417
|
+
continue;
|
|
1418
|
+
}
|
|
1419
|
+
match = /^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(line);
|
|
1420
|
+
if (match) {
|
|
1421
|
+
line = match[1];
|
|
1422
|
+
continue;
|
|
1423
|
+
}
|
|
1424
|
+
match = /^(\S+):(\d+):(\d+)$/.exec(line);
|
|
1425
|
+
if (match) {
|
|
1426
|
+
let contents;
|
|
1427
|
+
try {
|
|
1428
|
+
contents = streamIn.readFileSync(match[1], "utf8");
|
|
1429
|
+
} catch {
|
|
1430
|
+
break;
|
|
1431
|
+
}
|
|
1432
|
+
let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || "";
|
|
1433
|
+
let column = +match[3] - 1;
|
|
1434
|
+
let length = lineText.slice(column, column + ident.length) === ident ? ident.length : 0;
|
|
1435
|
+
return {
|
|
1436
|
+
file: match[1],
|
|
1437
|
+
namespace: "file",
|
|
1438
|
+
line: +match[2],
|
|
1439
|
+
column: encodeUTF8(lineText.slice(0, column)).length,
|
|
1440
|
+
length: encodeUTF8(lineText.slice(column, column + length)).length,
|
|
1441
|
+
lineText: lineText + "\n" + lines.slice(1).join("\n"),
|
|
1442
|
+
suggestion: ""
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
break;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
return null;
|
|
1450
|
+
}
|
|
1451
|
+
function failureErrorWithLog(text, errors, warnings) {
|
|
1452
|
+
let limit = 5;
|
|
1453
|
+
text += errors.length < 1 ? "" : ` with ${errors.length} error${errors.length < 2 ? "" : "s"}:` + errors.slice(0, limit + 1).map((e, i) => {
|
|
1454
|
+
if (i === limit) return "\n...";
|
|
1455
|
+
if (!e.location) return `
|
|
1456
|
+
error: ${e.text}`;
|
|
1457
|
+
let { file, line, column } = e.location;
|
|
1458
|
+
let pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : "";
|
|
1459
|
+
return `
|
|
1460
|
+
${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`;
|
|
1461
|
+
}).join("");
|
|
1462
|
+
let error = new Error(text);
|
|
1463
|
+
for (const [key, value] of [["errors", errors], ["warnings", warnings]]) {
|
|
1464
|
+
Object.defineProperty(error, key, {
|
|
1465
|
+
configurable: true,
|
|
1466
|
+
enumerable: true,
|
|
1467
|
+
get: () => value,
|
|
1468
|
+
set: (value2) => Object.defineProperty(error, key, {
|
|
1469
|
+
configurable: true,
|
|
1470
|
+
enumerable: true,
|
|
1471
|
+
value: value2
|
|
1472
|
+
})
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
return error;
|
|
1476
|
+
}
|
|
1477
|
+
function replaceDetailsInMessages(messages, stash) {
|
|
1478
|
+
for (const message of messages) {
|
|
1479
|
+
message.detail = stash.load(message.detail);
|
|
1480
|
+
}
|
|
1481
|
+
return messages;
|
|
1482
|
+
}
|
|
1483
|
+
function sanitizeLocation(location, where, terminalWidth) {
|
|
1484
|
+
if (location == null) return null;
|
|
1485
|
+
let keys = {};
|
|
1486
|
+
let file = getFlag(location, keys, "file", mustBeString);
|
|
1487
|
+
let namespace = getFlag(location, keys, "namespace", mustBeString);
|
|
1488
|
+
let line = getFlag(location, keys, "line", mustBeInteger);
|
|
1489
|
+
let column = getFlag(location, keys, "column", mustBeInteger);
|
|
1490
|
+
let length = getFlag(location, keys, "length", mustBeInteger);
|
|
1491
|
+
let lineText = getFlag(location, keys, "lineText", mustBeString);
|
|
1492
|
+
let suggestion = getFlag(location, keys, "suggestion", mustBeString);
|
|
1493
|
+
checkForInvalidFlags(location, keys, where);
|
|
1494
|
+
if (lineText) {
|
|
1495
|
+
const relevantASCII = lineText.slice(
|
|
1496
|
+
0,
|
|
1497
|
+
(column && column > 0 ? column : 0) + (length && length > 0 ? length : 0) + (terminalWidth && terminalWidth > 0 ? terminalWidth : 80)
|
|
1498
|
+
);
|
|
1499
|
+
if (!/[\x7F-\uFFFF]/.test(relevantASCII) && !/\n/.test(lineText)) {
|
|
1500
|
+
lineText = relevantASCII;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
return {
|
|
1504
|
+
file: file || "",
|
|
1505
|
+
namespace: namespace || "",
|
|
1506
|
+
line: line || 0,
|
|
1507
|
+
column: column || 0,
|
|
1508
|
+
length: length || 0,
|
|
1509
|
+
lineText: lineText || "",
|
|
1510
|
+
suggestion: suggestion || ""
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
function sanitizeMessages(messages, property, stash, fallbackPluginName, terminalWidth) {
|
|
1514
|
+
let messagesClone = [];
|
|
1515
|
+
let index = 0;
|
|
1516
|
+
for (const message of messages) {
|
|
1517
|
+
let keys = {};
|
|
1518
|
+
let id = getFlag(message, keys, "id", mustBeString);
|
|
1519
|
+
let pluginName = getFlag(message, keys, "pluginName", mustBeString);
|
|
1520
|
+
let text = getFlag(message, keys, "text", mustBeString);
|
|
1521
|
+
let location = getFlag(message, keys, "location", mustBeObjectOrNull);
|
|
1522
|
+
let notes = getFlag(message, keys, "notes", mustBeArray);
|
|
1523
|
+
let detail = getFlag(message, keys, "detail", canBeAnything);
|
|
1524
|
+
let where = `in element ${index} of "${property}"`;
|
|
1525
|
+
checkForInvalidFlags(message, keys, where);
|
|
1526
|
+
let notesClone = [];
|
|
1527
|
+
if (notes) {
|
|
1528
|
+
for (const note of notes) {
|
|
1529
|
+
let noteKeys = {};
|
|
1530
|
+
let noteText = getFlag(note, noteKeys, "text", mustBeString);
|
|
1531
|
+
let noteLocation = getFlag(note, noteKeys, "location", mustBeObjectOrNull);
|
|
1532
|
+
checkForInvalidFlags(note, noteKeys, where);
|
|
1533
|
+
notesClone.push({
|
|
1534
|
+
text: noteText || "",
|
|
1535
|
+
location: sanitizeLocation(noteLocation, where, terminalWidth)
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
messagesClone.push({
|
|
1540
|
+
id: id || "",
|
|
1541
|
+
pluginName: pluginName || fallbackPluginName,
|
|
1542
|
+
text: text || "",
|
|
1543
|
+
location: sanitizeLocation(location, where, terminalWidth),
|
|
1544
|
+
notes: notesClone,
|
|
1545
|
+
detail: stash ? stash.store(detail) : -1
|
|
1546
|
+
});
|
|
1547
|
+
index++;
|
|
1548
|
+
}
|
|
1549
|
+
return messagesClone;
|
|
1550
|
+
}
|
|
1551
|
+
function sanitizeStringArray(values, property) {
|
|
1552
|
+
const result = [];
|
|
1553
|
+
for (const value of values) {
|
|
1554
|
+
if (typeof value !== "string") throw new Error(`${quote(property)} must be an array of strings`);
|
|
1555
|
+
result.push(value);
|
|
1556
|
+
}
|
|
1557
|
+
return result;
|
|
1558
|
+
}
|
|
1559
|
+
function sanitizeStringMap(map, property) {
|
|
1560
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
1561
|
+
for (const key in map) {
|
|
1562
|
+
const value = map[key];
|
|
1563
|
+
if (typeof value !== "string") throw new Error(`key ${quote(key)} in object ${quote(property)} must be a string`);
|
|
1564
|
+
result[key] = value;
|
|
1565
|
+
}
|
|
1566
|
+
return result;
|
|
1567
|
+
}
|
|
1568
|
+
function convertOutputFiles({ path: path3, contents, hash }) {
|
|
1569
|
+
let text = null;
|
|
1570
|
+
return {
|
|
1571
|
+
path: path3,
|
|
1572
|
+
contents,
|
|
1573
|
+
hash,
|
|
1574
|
+
get text() {
|
|
1575
|
+
const binary = this.contents;
|
|
1576
|
+
if (text === null || binary !== contents) {
|
|
1577
|
+
contents = binary;
|
|
1578
|
+
text = decodeUTF8(binary);
|
|
1579
|
+
}
|
|
1580
|
+
return text;
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
function jsRegExpToGoRegExp(regexp) {
|
|
1585
|
+
let result = regexp.source;
|
|
1586
|
+
if (regexp.flags) result = `(?${regexp.flags})${result}`;
|
|
1587
|
+
return result;
|
|
1588
|
+
}
|
|
1589
|
+
var fs = __require("fs");
|
|
1590
|
+
var os = __require("os");
|
|
1591
|
+
var path = __require("path");
|
|
1592
|
+
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
|
1593
|
+
var isValidBinaryPath = (x) => !!x && x !== "/usr/bin/esbuild";
|
|
1594
|
+
var packageDarwin_arm64 = "@esbuild/darwin-arm64";
|
|
1595
|
+
var packageDarwin_x64 = "@esbuild/darwin-x64";
|
|
1596
|
+
var knownWindowsPackages = {
|
|
1597
|
+
"win32 arm64 LE": "@esbuild/win32-arm64",
|
|
1598
|
+
"win32 ia32 LE": "@esbuild/win32-ia32",
|
|
1599
|
+
"win32 x64 LE": "@esbuild/win32-x64"
|
|
1600
|
+
};
|
|
1601
|
+
var knownUnixlikePackages = {
|
|
1602
|
+
"aix ppc64 BE": "@esbuild/aix-ppc64",
|
|
1603
|
+
"android arm64 LE": "@esbuild/android-arm64",
|
|
1604
|
+
"darwin arm64 LE": "@esbuild/darwin-arm64",
|
|
1605
|
+
"darwin x64 LE": "@esbuild/darwin-x64",
|
|
1606
|
+
"freebsd arm64 LE": "@esbuild/freebsd-arm64",
|
|
1607
|
+
"freebsd x64 LE": "@esbuild/freebsd-x64",
|
|
1608
|
+
"linux arm LE": "@esbuild/linux-arm",
|
|
1609
|
+
"linux arm64 LE": "@esbuild/linux-arm64",
|
|
1610
|
+
"linux ia32 LE": "@esbuild/linux-ia32",
|
|
1611
|
+
"linux mips64el LE": "@esbuild/linux-mips64el",
|
|
1612
|
+
"linux ppc64 LE": "@esbuild/linux-ppc64",
|
|
1613
|
+
"linux riscv64 LE": "@esbuild/linux-riscv64",
|
|
1614
|
+
"linux s390x BE": "@esbuild/linux-s390x",
|
|
1615
|
+
"linux x64 LE": "@esbuild/linux-x64",
|
|
1616
|
+
"linux loong64 LE": "@esbuild/linux-loong64",
|
|
1617
|
+
"netbsd arm64 LE": "@esbuild/netbsd-arm64",
|
|
1618
|
+
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
|
1619
|
+
"openbsd arm64 LE": "@esbuild/openbsd-arm64",
|
|
1620
|
+
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
|
1621
|
+
"sunos x64 LE": "@esbuild/sunos-x64"
|
|
1622
|
+
};
|
|
1623
|
+
var knownWebAssemblyFallbackPackages = {
|
|
1624
|
+
"android arm LE": "@esbuild/android-arm",
|
|
1625
|
+
"android x64 LE": "@esbuild/android-x64"
|
|
1626
|
+
};
|
|
1627
|
+
function pkgAndSubpathForCurrentPlatform() {
|
|
1628
|
+
let pkg;
|
|
1629
|
+
let subpath;
|
|
1630
|
+
let isWASM = false;
|
|
1631
|
+
let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
|
1632
|
+
if (platformKey in knownWindowsPackages) {
|
|
1633
|
+
pkg = knownWindowsPackages[platformKey];
|
|
1634
|
+
subpath = "esbuild.exe";
|
|
1635
|
+
} else if (platformKey in knownUnixlikePackages) {
|
|
1636
|
+
pkg = knownUnixlikePackages[platformKey];
|
|
1637
|
+
subpath = "bin/esbuild";
|
|
1638
|
+
} else if (platformKey in knownWebAssemblyFallbackPackages) {
|
|
1639
|
+
pkg = knownWebAssemblyFallbackPackages[platformKey];
|
|
1640
|
+
subpath = "bin/esbuild";
|
|
1641
|
+
isWASM = true;
|
|
1642
|
+
} else {
|
|
1643
|
+
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
1644
|
+
}
|
|
1645
|
+
return { pkg, subpath, isWASM };
|
|
1646
|
+
}
|
|
1647
|
+
function pkgForSomeOtherPlatform() {
|
|
1648
|
+
const libMainJS = __require.resolve("esbuild");
|
|
1649
|
+
const nodeModulesDirectory = path.dirname(path.dirname(path.dirname(libMainJS)));
|
|
1650
|
+
if (path.basename(nodeModulesDirectory) === "node_modules") {
|
|
1651
|
+
for (const unixKey in knownUnixlikePackages) {
|
|
1652
|
+
try {
|
|
1653
|
+
const pkg = knownUnixlikePackages[unixKey];
|
|
1654
|
+
if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
|
1655
|
+
} catch {
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
for (const windowsKey in knownWindowsPackages) {
|
|
1659
|
+
try {
|
|
1660
|
+
const pkg = knownWindowsPackages[windowsKey];
|
|
1661
|
+
if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
|
1662
|
+
} catch {
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
return null;
|
|
1667
|
+
}
|
|
1668
|
+
function downloadedBinPath(pkg, subpath) {
|
|
1669
|
+
const esbuildLibDir = path.dirname(__require.resolve("esbuild"));
|
|
1670
|
+
return path.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
|
1671
|
+
}
|
|
1672
|
+
function generateBinPath() {
|
|
1673
|
+
if (isValidBinaryPath(ESBUILD_BINARY_PATH)) {
|
|
1674
|
+
if (!fs.existsSync(ESBUILD_BINARY_PATH)) {
|
|
1675
|
+
console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
|
|
1676
|
+
} else {
|
|
1677
|
+
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
const { pkg, subpath, isWASM } = pkgAndSubpathForCurrentPlatform();
|
|
1681
|
+
let binPath;
|
|
1682
|
+
try {
|
|
1683
|
+
binPath = __require.resolve(`${pkg}/${subpath}`);
|
|
1684
|
+
} catch (e) {
|
|
1685
|
+
binPath = downloadedBinPath(pkg, subpath);
|
|
1686
|
+
if (!fs.existsSync(binPath)) {
|
|
1687
|
+
try {
|
|
1688
|
+
__require.resolve(pkg);
|
|
1689
|
+
} catch {
|
|
1690
|
+
const otherPkg = pkgForSomeOtherPlatform();
|
|
1691
|
+
if (otherPkg) {
|
|
1692
|
+
let suggestions = `
|
|
1693
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
1694
|
+
needs the "${pkg}" package instead. People often get into this
|
|
1695
|
+
situation by installing esbuild on Windows or macOS and copying "node_modules"
|
|
1696
|
+
into a Docker image that runs Linux, or by copying "node_modules" between
|
|
1697
|
+
Windows and WSL environments.
|
|
1698
|
+
|
|
1699
|
+
If you are installing with npm, you can try not copying the "node_modules"
|
|
1700
|
+
directory when you copy the files over, and running "npm ci" or "npm install"
|
|
1701
|
+
on the destination platform after the copy. Or you could consider using yarn
|
|
1702
|
+
instead of npm which has built-in support for installing a package on multiple
|
|
1703
|
+
platforms simultaneously.
|
|
1704
|
+
|
|
1705
|
+
If you are installing with yarn, you can try listing both this platform and the
|
|
1706
|
+
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
|
1707
|
+
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
1708
|
+
Keep in mind that this means multiple copies of esbuild will be present.
|
|
1709
|
+
`;
|
|
1710
|
+
if (pkg === packageDarwin_x64 && otherPkg === packageDarwin_arm64 || pkg === packageDarwin_arm64 && otherPkg === packageDarwin_x64) {
|
|
1711
|
+
suggestions = `
|
|
1712
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
1713
|
+
needs the "${pkg}" package instead. People often get into this
|
|
1714
|
+
situation by installing esbuild with npm running inside of Rosetta 2 and then
|
|
1715
|
+
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
|
|
1716
|
+
2 is Apple's on-the-fly x86_64-to-arm64 translation service).
|
|
1717
|
+
|
|
1718
|
+
If you are installing with npm, you can try ensuring that both npm and node are
|
|
1719
|
+
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
|
|
1720
|
+
changing how you installed npm and/or node. For example, installing node with
|
|
1721
|
+
the universal installer here should work: https://nodejs.org/en/download/. Or
|
|
1722
|
+
you could consider using yarn instead of npm which has built-in support for
|
|
1723
|
+
installing a package on multiple platforms simultaneously.
|
|
1724
|
+
|
|
1725
|
+
If you are installing with yarn, you can try listing both "arm64" and "x64"
|
|
1726
|
+
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
|
|
1727
|
+
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
1728
|
+
Keep in mind that this means multiple copies of esbuild will be present.
|
|
1729
|
+
`;
|
|
1730
|
+
}
|
|
1731
|
+
throw new Error(`
|
|
1732
|
+
You installed esbuild for another platform than the one you're currently using.
|
|
1733
|
+
This won't work because esbuild is written with native code and needs to
|
|
1734
|
+
install a platform-specific binary executable.
|
|
1735
|
+
${suggestions}
|
|
1736
|
+
Another alternative is to use the "esbuild-wasm" package instead, which works
|
|
1737
|
+
the same way on all platforms. But it comes with a heavy performance cost and
|
|
1738
|
+
can sometimes be 10x slower than the "esbuild" package, so you may also not
|
|
1739
|
+
want to do that.
|
|
1740
|
+
`);
|
|
1741
|
+
}
|
|
1742
|
+
throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
|
|
1743
|
+
|
|
1744
|
+
If you are installing esbuild with npm, make sure that you don't specify the
|
|
1745
|
+
"--no-optional" or "--omit=optional" flags. The "optionalDependencies" feature
|
|
1746
|
+
of "package.json" is used by esbuild to install the correct binary executable
|
|
1747
|
+
for your current platform.`);
|
|
1748
|
+
}
|
|
1749
|
+
throw e;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
if (/\.zip\//.test(binPath)) {
|
|
1753
|
+
let pnpapi;
|
|
1754
|
+
try {
|
|
1755
|
+
pnpapi = __require("pnpapi");
|
|
1756
|
+
} catch (e) {
|
|
1757
|
+
}
|
|
1758
|
+
if (pnpapi) {
|
|
1759
|
+
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
|
|
1760
|
+
const binTargetPath = path.join(
|
|
1761
|
+
root,
|
|
1762
|
+
"node_modules",
|
|
1763
|
+
".cache",
|
|
1764
|
+
"esbuild",
|
|
1765
|
+
`pnpapi-${pkg.replace("/", "-")}-${"0.25.5"}-${path.basename(subpath)}`
|
|
1766
|
+
);
|
|
1767
|
+
if (!fs.existsSync(binTargetPath)) {
|
|
1768
|
+
fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
|
|
1769
|
+
fs.copyFileSync(binPath, binTargetPath);
|
|
1770
|
+
fs.chmodSync(binTargetPath, 493);
|
|
1771
|
+
}
|
|
1772
|
+
return { binPath: binTargetPath, isWASM };
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
return { binPath, isWASM };
|
|
1776
|
+
}
|
|
1777
|
+
var child_process = __require("child_process");
|
|
1778
|
+
var crypto = __require("crypto");
|
|
1779
|
+
var path2 = __require("path");
|
|
1780
|
+
var fs2 = __require("fs");
|
|
1781
|
+
var os2 = __require("os");
|
|
1782
|
+
var tty = __require("tty");
|
|
1783
|
+
var worker_threads;
|
|
1784
|
+
if (process.env.ESBUILD_WORKER_THREADS !== "0") {
|
|
1785
|
+
try {
|
|
1786
|
+
worker_threads = __require("worker_threads");
|
|
1787
|
+
} catch {
|
|
1788
|
+
}
|
|
1789
|
+
let [major, minor] = process.versions.node.split(".");
|
|
1790
|
+
if (
|
|
1791
|
+
// <v12.17.0 does not work
|
|
1792
|
+
+major < 12 || +major === 12 && +minor < 17 || +major === 13 && +minor < 13
|
|
1793
|
+
) {
|
|
1794
|
+
worker_threads = void 0;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
var _a;
|
|
1798
|
+
var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.25.5";
|
|
1799
|
+
var esbuildCommandAndArgs = () => {
|
|
1800
|
+
if ((!ESBUILD_BINARY_PATH || false) && (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib")) {
|
|
1801
|
+
throw new Error(
|
|
1802
|
+
`The esbuild JavaScript API cannot be bundled. Please mark the "esbuild" package as external so it's not included in the bundle.
|
|
1803
|
+
|
|
1804
|
+
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.`
|
|
1805
|
+
);
|
|
1806
|
+
}
|
|
1807
|
+
if (false) {
|
|
1808
|
+
return ["node", [path2.join(__dirname, "..", "bin", "esbuild")]];
|
|
1809
|
+
} else {
|
|
1810
|
+
const { binPath, isWASM } = generateBinPath();
|
|
1811
|
+
if (isWASM) {
|
|
1812
|
+
return ["node", [binPath]];
|
|
1813
|
+
} else {
|
|
1814
|
+
return [binPath, []];
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
};
|
|
1818
|
+
var isTTY = () => tty.isatty(2);
|
|
1819
|
+
var fsSync = {
|
|
1820
|
+
readFile(tempFile, callback) {
|
|
1821
|
+
try {
|
|
1822
|
+
let contents = fs2.readFileSync(tempFile, "utf8");
|
|
1823
|
+
try {
|
|
1824
|
+
fs2.unlinkSync(tempFile);
|
|
1825
|
+
} catch {
|
|
1826
|
+
}
|
|
1827
|
+
callback(null, contents);
|
|
1828
|
+
} catch (err) {
|
|
1829
|
+
callback(err, null);
|
|
1830
|
+
}
|
|
1831
|
+
},
|
|
1832
|
+
writeFile(contents, callback) {
|
|
1833
|
+
try {
|
|
1834
|
+
let tempFile = randomFileName();
|
|
1835
|
+
fs2.writeFileSync(tempFile, contents);
|
|
1836
|
+
callback(tempFile);
|
|
1837
|
+
} catch {
|
|
1838
|
+
callback(null);
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
};
|
|
1842
|
+
var fsAsync = {
|
|
1843
|
+
readFile(tempFile, callback) {
|
|
1844
|
+
try {
|
|
1845
|
+
fs2.readFile(tempFile, "utf8", (err, contents) => {
|
|
1846
|
+
try {
|
|
1847
|
+
fs2.unlink(tempFile, () => callback(err, contents));
|
|
1848
|
+
} catch {
|
|
1849
|
+
callback(err, contents);
|
|
1850
|
+
}
|
|
1851
|
+
});
|
|
1852
|
+
} catch (err) {
|
|
1853
|
+
callback(err, null);
|
|
1854
|
+
}
|
|
1855
|
+
},
|
|
1856
|
+
writeFile(contents, callback) {
|
|
1857
|
+
try {
|
|
1858
|
+
let tempFile = randomFileName();
|
|
1859
|
+
fs2.writeFile(tempFile, contents, (err) => err !== null ? callback(null) : callback(tempFile));
|
|
1860
|
+
} catch {
|
|
1861
|
+
callback(null);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
};
|
|
1865
|
+
var version = "0.25.5";
|
|
1866
|
+
var build2 = (options) => ensureServiceIsRunning().build(options);
|
|
1867
|
+
var context = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
|
|
1868
|
+
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
|
1869
|
+
var formatMessages = (messages, options) => ensureServiceIsRunning().formatMessages(messages, options);
|
|
1870
|
+
var analyzeMetafile = (messages, options) => ensureServiceIsRunning().analyzeMetafile(messages, options);
|
|
1871
|
+
var buildSync = (options) => {
|
|
1872
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
1873
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
1874
|
+
return workerThreadService.buildSync(options);
|
|
1875
|
+
}
|
|
1876
|
+
let result;
|
|
1877
|
+
runServiceSync((service) => service.buildOrContext({
|
|
1878
|
+
callName: "buildSync",
|
|
1879
|
+
refs: null,
|
|
1880
|
+
options,
|
|
1881
|
+
isTTY: isTTY(),
|
|
1882
|
+
defaultWD,
|
|
1883
|
+
callback: (err, res) => {
|
|
1884
|
+
if (err) throw err;
|
|
1885
|
+
result = res;
|
|
1886
|
+
}
|
|
1887
|
+
}));
|
|
1888
|
+
return result;
|
|
1889
|
+
};
|
|
1890
|
+
var transformSync = (input, options) => {
|
|
1891
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
1892
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
1893
|
+
return workerThreadService.transformSync(input, options);
|
|
1894
|
+
}
|
|
1895
|
+
let result;
|
|
1896
|
+
runServiceSync((service) => service.transform({
|
|
1897
|
+
callName: "transformSync",
|
|
1898
|
+
refs: null,
|
|
1899
|
+
input,
|
|
1900
|
+
options: options || {},
|
|
1901
|
+
isTTY: isTTY(),
|
|
1902
|
+
fs: fsSync,
|
|
1903
|
+
callback: (err, res) => {
|
|
1904
|
+
if (err) throw err;
|
|
1905
|
+
result = res;
|
|
1906
|
+
}
|
|
1907
|
+
}));
|
|
1908
|
+
return result;
|
|
1909
|
+
};
|
|
1910
|
+
var formatMessagesSync = (messages, options) => {
|
|
1911
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
1912
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
1913
|
+
return workerThreadService.formatMessagesSync(messages, options);
|
|
1914
|
+
}
|
|
1915
|
+
let result;
|
|
1916
|
+
runServiceSync((service) => service.formatMessages({
|
|
1917
|
+
callName: "formatMessagesSync",
|
|
1918
|
+
refs: null,
|
|
1919
|
+
messages,
|
|
1920
|
+
options,
|
|
1921
|
+
callback: (err, res) => {
|
|
1922
|
+
if (err) throw err;
|
|
1923
|
+
result = res;
|
|
1924
|
+
}
|
|
1925
|
+
}));
|
|
1926
|
+
return result;
|
|
1927
|
+
};
|
|
1928
|
+
var analyzeMetafileSync = (metafile, options) => {
|
|
1929
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
1930
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
1931
|
+
return workerThreadService.analyzeMetafileSync(metafile, options);
|
|
1932
|
+
}
|
|
1933
|
+
let result;
|
|
1934
|
+
runServiceSync((service) => service.analyzeMetafile({
|
|
1935
|
+
callName: "analyzeMetafileSync",
|
|
1936
|
+
refs: null,
|
|
1937
|
+
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
|
1938
|
+
options,
|
|
1939
|
+
callback: (err, res) => {
|
|
1940
|
+
if (err) throw err;
|
|
1941
|
+
result = res;
|
|
1942
|
+
}
|
|
1943
|
+
}));
|
|
1944
|
+
return result;
|
|
1945
|
+
};
|
|
1946
|
+
var stop = () => {
|
|
1947
|
+
if (stopService) stopService();
|
|
1948
|
+
if (workerThreadService) workerThreadService.stop();
|
|
1949
|
+
return Promise.resolve();
|
|
1950
|
+
};
|
|
1951
|
+
var initializeWasCalled = false;
|
|
1952
|
+
var initialize = (options) => {
|
|
1953
|
+
options = validateInitializeOptions(options || {});
|
|
1954
|
+
if (options.wasmURL) throw new Error(`The "wasmURL" option only works in the browser`);
|
|
1955
|
+
if (options.wasmModule) throw new Error(`The "wasmModule" option only works in the browser`);
|
|
1956
|
+
if (options.worker) throw new Error(`The "worker" option only works in the browser`);
|
|
1957
|
+
if (initializeWasCalled) throw new Error('Cannot call "initialize" more than once');
|
|
1958
|
+
ensureServiceIsRunning();
|
|
1959
|
+
initializeWasCalled = true;
|
|
1960
|
+
return Promise.resolve();
|
|
1961
|
+
};
|
|
1962
|
+
var defaultWD = process.cwd();
|
|
1963
|
+
var longLivedService;
|
|
1964
|
+
var stopService;
|
|
1965
|
+
var ensureServiceIsRunning = () => {
|
|
1966
|
+
if (longLivedService) return longLivedService;
|
|
1967
|
+
let [command, args] = esbuildCommandAndArgs();
|
|
1968
|
+
let child = child_process.spawn(command, args.concat(`--service=${"0.25.5"}`, "--ping"), {
|
|
1969
|
+
windowsHide: true,
|
|
1970
|
+
stdio: ["pipe", "pipe", "inherit"],
|
|
1971
|
+
cwd: defaultWD
|
|
1972
|
+
});
|
|
1973
|
+
let { readFromStdout, afterClose, service } = createChannel({
|
|
1974
|
+
writeToStdin(bytes) {
|
|
1975
|
+
child.stdin.write(bytes, (err) => {
|
|
1976
|
+
if (err) afterClose(err);
|
|
1977
|
+
});
|
|
1978
|
+
},
|
|
1979
|
+
readFileSync: fs2.readFileSync,
|
|
1980
|
+
isSync: false,
|
|
1981
|
+
hasFS: true,
|
|
1982
|
+
esbuild: node_exports
|
|
1983
|
+
});
|
|
1984
|
+
child.stdin.on("error", afterClose);
|
|
1985
|
+
child.on("error", afterClose);
|
|
1986
|
+
const stdin = child.stdin;
|
|
1987
|
+
const stdout = child.stdout;
|
|
1988
|
+
stdout.on("data", readFromStdout);
|
|
1989
|
+
stdout.on("end", afterClose);
|
|
1990
|
+
stopService = () => {
|
|
1991
|
+
stdin.destroy();
|
|
1992
|
+
stdout.destroy();
|
|
1993
|
+
child.kill();
|
|
1994
|
+
initializeWasCalled = false;
|
|
1995
|
+
longLivedService = void 0;
|
|
1996
|
+
stopService = void 0;
|
|
1997
|
+
};
|
|
1998
|
+
let refCount = 0;
|
|
1999
|
+
child.unref();
|
|
2000
|
+
if (stdin.unref) {
|
|
2001
|
+
stdin.unref();
|
|
2002
|
+
}
|
|
2003
|
+
if (stdout.unref) {
|
|
2004
|
+
stdout.unref();
|
|
2005
|
+
}
|
|
2006
|
+
const refs = {
|
|
2007
|
+
ref() {
|
|
2008
|
+
if (++refCount === 1) child.ref();
|
|
2009
|
+
},
|
|
2010
|
+
unref() {
|
|
2011
|
+
if (--refCount === 0) child.unref();
|
|
2012
|
+
}
|
|
2013
|
+
};
|
|
2014
|
+
longLivedService = {
|
|
2015
|
+
build: (options) => new Promise((resolve2, reject) => {
|
|
2016
|
+
service.buildOrContext({
|
|
2017
|
+
callName: "build",
|
|
2018
|
+
refs,
|
|
2019
|
+
options,
|
|
2020
|
+
isTTY: isTTY(),
|
|
2021
|
+
defaultWD,
|
|
2022
|
+
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
2023
|
+
});
|
|
2024
|
+
}),
|
|
2025
|
+
context: (options) => new Promise((resolve2, reject) => service.buildOrContext({
|
|
2026
|
+
callName: "context",
|
|
2027
|
+
refs,
|
|
2028
|
+
options,
|
|
2029
|
+
isTTY: isTTY(),
|
|
2030
|
+
defaultWD,
|
|
2031
|
+
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
2032
|
+
})),
|
|
2033
|
+
transform: (input, options) => new Promise((resolve2, reject) => service.transform({
|
|
2034
|
+
callName: "transform",
|
|
2035
|
+
refs,
|
|
2036
|
+
input,
|
|
2037
|
+
options: options || {},
|
|
2038
|
+
isTTY: isTTY(),
|
|
2039
|
+
fs: fsAsync,
|
|
2040
|
+
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
2041
|
+
})),
|
|
2042
|
+
formatMessages: (messages, options) => new Promise((resolve2, reject) => service.formatMessages({
|
|
2043
|
+
callName: "formatMessages",
|
|
2044
|
+
refs,
|
|
2045
|
+
messages,
|
|
2046
|
+
options,
|
|
2047
|
+
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
2048
|
+
})),
|
|
2049
|
+
analyzeMetafile: (metafile, options) => new Promise((resolve2, reject) => service.analyzeMetafile({
|
|
2050
|
+
callName: "analyzeMetafile",
|
|
2051
|
+
refs,
|
|
2052
|
+
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
|
2053
|
+
options,
|
|
2054
|
+
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
2055
|
+
}))
|
|
2056
|
+
};
|
|
2057
|
+
return longLivedService;
|
|
2058
|
+
};
|
|
2059
|
+
var runServiceSync = (callback) => {
|
|
2060
|
+
let [command, args] = esbuildCommandAndArgs();
|
|
2061
|
+
let stdin = new Uint8Array();
|
|
2062
|
+
let { readFromStdout, afterClose, service } = createChannel({
|
|
2063
|
+
writeToStdin(bytes) {
|
|
2064
|
+
if (stdin.length !== 0) throw new Error("Must run at most one command");
|
|
2065
|
+
stdin = bytes;
|
|
2066
|
+
},
|
|
2067
|
+
isSync: true,
|
|
2068
|
+
hasFS: true,
|
|
2069
|
+
esbuild: node_exports
|
|
2070
|
+
});
|
|
2071
|
+
callback(service);
|
|
2072
|
+
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.25.5"}`), {
|
|
2073
|
+
cwd: defaultWD,
|
|
2074
|
+
windowsHide: true,
|
|
2075
|
+
input: stdin,
|
|
2076
|
+
// We don't know how large the output could be. If it's too large, the
|
|
2077
|
+
// command will fail with ENOBUFS. Reserve 16mb for now since that feels
|
|
2078
|
+
// like it should be enough. Also allow overriding this with an environment
|
|
2079
|
+
// variable.
|
|
2080
|
+
maxBuffer: +process.env.ESBUILD_MAX_BUFFER || 16 * 1024 * 1024
|
|
2081
|
+
});
|
|
2082
|
+
readFromStdout(stdout);
|
|
2083
|
+
afterClose(null);
|
|
2084
|
+
};
|
|
2085
|
+
var randomFileName = () => {
|
|
2086
|
+
return path2.join(os2.tmpdir(), `esbuild-${crypto.randomBytes(32).toString("hex")}`);
|
|
2087
|
+
};
|
|
2088
|
+
var workerThreadService = null;
|
|
2089
|
+
var startWorkerThreadService = (worker_threads2) => {
|
|
2090
|
+
let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel();
|
|
2091
|
+
let worker = new worker_threads2.Worker(__filename, {
|
|
2092
|
+
workerData: { workerPort, defaultWD, esbuildVersion: "0.25.5" },
|
|
2093
|
+
transferList: [workerPort],
|
|
2094
|
+
// From node's documentation: https://nodejs.org/api/worker_threads.html
|
|
2095
|
+
//
|
|
2096
|
+
// Take care when launching worker threads from preload scripts (scripts loaded
|
|
2097
|
+
// and run using the `-r` command line flag). Unless the `execArgv` option is
|
|
2098
|
+
// explicitly set, new Worker threads automatically inherit the command line flags
|
|
2099
|
+
// from the running process and will preload the same preload scripts as the main
|
|
2100
|
+
// thread. If the preload script unconditionally launches a worker thread, every
|
|
2101
|
+
// thread spawned will spawn another until the application crashes.
|
|
2102
|
+
//
|
|
2103
|
+
execArgv: []
|
|
2104
|
+
});
|
|
2105
|
+
let nextID = 0;
|
|
2106
|
+
let fakeBuildError = (text) => {
|
|
2107
|
+
let error = new Error(`Build failed with 1 error:
|
|
2108
|
+
error: ${text}`);
|
|
2109
|
+
let errors = [{ id: "", pluginName: "", text, location: null, notes: [], detail: void 0 }];
|
|
2110
|
+
error.errors = errors;
|
|
2111
|
+
error.warnings = [];
|
|
2112
|
+
return error;
|
|
2113
|
+
};
|
|
2114
|
+
let validateBuildSyncOptions = (options) => {
|
|
2115
|
+
if (!options) return;
|
|
2116
|
+
let plugins = options.plugins;
|
|
2117
|
+
if (plugins && plugins.length > 0) throw fakeBuildError(`Cannot use plugins in synchronous API calls`);
|
|
2118
|
+
};
|
|
2119
|
+
let applyProperties = (object, properties) => {
|
|
2120
|
+
for (let key in properties) {
|
|
2121
|
+
object[key] = properties[key];
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2124
|
+
let runCallSync = (command, args) => {
|
|
2125
|
+
let id = nextID++;
|
|
2126
|
+
let sharedBuffer = new SharedArrayBuffer(8);
|
|
2127
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
2128
|
+
let msg = { sharedBuffer, id, command, args };
|
|
2129
|
+
worker.postMessage(msg);
|
|
2130
|
+
let status = Atomics.wait(sharedBufferView, 0, 0);
|
|
2131
|
+
if (status !== "ok" && status !== "not-equal") throw new Error("Internal error: Atomics.wait() failed: " + status);
|
|
2132
|
+
let { message: { id: id2, resolve: resolve2, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
|
|
2133
|
+
if (id !== id2) throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
|
2134
|
+
if (reject) {
|
|
2135
|
+
applyProperties(reject, properties);
|
|
2136
|
+
throw reject;
|
|
2137
|
+
}
|
|
2138
|
+
return resolve2;
|
|
2139
|
+
};
|
|
2140
|
+
worker.unref();
|
|
2141
|
+
return {
|
|
2142
|
+
buildSync(options) {
|
|
2143
|
+
validateBuildSyncOptions(options);
|
|
2144
|
+
return runCallSync("build", [options]);
|
|
2145
|
+
},
|
|
2146
|
+
transformSync(input, options) {
|
|
2147
|
+
return runCallSync("transform", [input, options]);
|
|
2148
|
+
},
|
|
2149
|
+
formatMessagesSync(messages, options) {
|
|
2150
|
+
return runCallSync("formatMessages", [messages, options]);
|
|
2151
|
+
},
|
|
2152
|
+
analyzeMetafileSync(metafile, options) {
|
|
2153
|
+
return runCallSync("analyzeMetafile", [metafile, options]);
|
|
2154
|
+
},
|
|
2155
|
+
stop() {
|
|
2156
|
+
worker.terminate();
|
|
2157
|
+
workerThreadService = null;
|
|
2158
|
+
}
|
|
2159
|
+
};
|
|
2160
|
+
};
|
|
2161
|
+
var startSyncServiceWorker = () => {
|
|
2162
|
+
let workerPort = worker_threads.workerData.workerPort;
|
|
2163
|
+
let parentPort = worker_threads.parentPort;
|
|
2164
|
+
let extractProperties = (object) => {
|
|
2165
|
+
let properties = {};
|
|
2166
|
+
if (object && typeof object === "object") {
|
|
2167
|
+
for (let key in object) {
|
|
2168
|
+
properties[key] = object[key];
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
return properties;
|
|
2172
|
+
};
|
|
2173
|
+
try {
|
|
2174
|
+
let service = ensureServiceIsRunning();
|
|
2175
|
+
defaultWD = worker_threads.workerData.defaultWD;
|
|
2176
|
+
parentPort.on("message", (msg) => {
|
|
2177
|
+
(async () => {
|
|
2178
|
+
let { sharedBuffer, id, command, args } = msg;
|
|
2179
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
2180
|
+
try {
|
|
2181
|
+
switch (command) {
|
|
2182
|
+
case "build":
|
|
2183
|
+
workerPort.postMessage({ id, resolve: await service.build(args[0]) });
|
|
2184
|
+
break;
|
|
2185
|
+
case "transform":
|
|
2186
|
+
workerPort.postMessage({ id, resolve: await service.transform(args[0], args[1]) });
|
|
2187
|
+
break;
|
|
2188
|
+
case "formatMessages":
|
|
2189
|
+
workerPort.postMessage({ id, resolve: await service.formatMessages(args[0], args[1]) });
|
|
2190
|
+
break;
|
|
2191
|
+
case "analyzeMetafile":
|
|
2192
|
+
workerPort.postMessage({ id, resolve: await service.analyzeMetafile(args[0], args[1]) });
|
|
2193
|
+
break;
|
|
2194
|
+
default:
|
|
2195
|
+
throw new Error(`Invalid command: ${command}`);
|
|
2196
|
+
}
|
|
2197
|
+
} catch (reject) {
|
|
2198
|
+
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
|
2199
|
+
}
|
|
2200
|
+
Atomics.add(sharedBufferView, 0, 1);
|
|
2201
|
+
Atomics.notify(sharedBufferView, 0, Infinity);
|
|
2202
|
+
})();
|
|
2203
|
+
});
|
|
2204
|
+
} catch (reject) {
|
|
2205
|
+
parentPort.on("message", (msg) => {
|
|
2206
|
+
let { sharedBuffer, id } = msg;
|
|
2207
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
2208
|
+
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
|
2209
|
+
Atomics.add(sharedBufferView, 0, 1);
|
|
2210
|
+
Atomics.notify(sharedBufferView, 0, Infinity);
|
|
2211
|
+
});
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
if (isInternalWorkerThread) {
|
|
2215
|
+
startSyncServiceWorker();
|
|
2216
|
+
}
|
|
2217
|
+
var node_default = node_exports;
|
|
2218
|
+
}
|
|
2219
|
+
});
|
|
2220
|
+
|
|
2221
|
+
// src/build/functions/middleware/compiler.ts
|
|
2222
|
+
var esbuild = __toESM(require_main(), 1);
|
|
2223
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
2224
|
+
import { resolve, dirname, join } from "path";
|
|
2225
|
+
import { getPolyfillsCode } from "./polyfills/index.js";
|
|
2226
|
+
import { getCompatCode } from "./compat/index.js";
|
|
2227
|
+
import { getEdgeOneWrapperCode } from "./wrapper.js";
|
|
2228
|
+
function detectBuildType(code) {
|
|
2229
|
+
if (code.includes("webpackChunk_N_E")) {
|
|
2230
|
+
return "webpack";
|
|
2231
|
+
}
|
|
2232
|
+
if (code.includes("[turbopack]_runtime.js") || code.includes("R.c(") && code.includes("server/chunks/")) {
|
|
2233
|
+
return "turbopack";
|
|
2234
|
+
}
|
|
2235
|
+
if (code.includes("export function") || code.includes("export const") || code.includes("export async function") || /:\s*(string|number|boolean|any)\s*[=\)\{,]/.test(code)) {
|
|
2236
|
+
return "raw";
|
|
2237
|
+
}
|
|
2238
|
+
return "webpack";
|
|
2239
|
+
}
|
|
2240
|
+
async function transformSourceCode(code, filePath) {
|
|
2241
|
+
const absolutePath = resolve(filePath);
|
|
2242
|
+
const fileDir = dirname(absolutePath);
|
|
2243
|
+
const result = await esbuild.build({
|
|
2244
|
+
stdin: {
|
|
2245
|
+
contents: code,
|
|
2246
|
+
resolveDir: fileDir,
|
|
2247
|
+
// 用于解析相对路径 import
|
|
2248
|
+
sourcefile: absolutePath,
|
|
2249
|
+
loader: filePath.endsWith(".ts") || filePath.endsWith(".tsx") ? "ts" : "js"
|
|
2250
|
+
},
|
|
2251
|
+
bundle: true,
|
|
2252
|
+
// 打包所有依赖
|
|
2253
|
+
format: "iife",
|
|
2254
|
+
// 立即执行函数
|
|
2255
|
+
globalName: "__MIDDLEWARE_EXPORTS__",
|
|
2256
|
+
// 将导出暴露到全局变量
|
|
2257
|
+
target: "es2020",
|
|
2258
|
+
minify: false,
|
|
2259
|
+
keepNames: true,
|
|
2260
|
+
write: false,
|
|
2261
|
+
// 不写入文件,返回结果
|
|
2262
|
+
platform: "browser",
|
|
2263
|
+
// 边缘运行时类似浏览器环境
|
|
2264
|
+
// 外部化 Node.js 内置模块(我们会用 polyfill 处理)
|
|
2265
|
+
external: ["node:*"],
|
|
2266
|
+
// 定义全局变量
|
|
2267
|
+
define: {
|
|
2268
|
+
"process.env.NODE_ENV": '"production"'
|
|
2269
|
+
}
|
|
2270
|
+
});
|
|
2271
|
+
if (result.errors.length > 0) {
|
|
2272
|
+
throw new Error(`esbuild errors: ${result.errors.map((e) => e.text).join(", ")}`);
|
|
2273
|
+
}
|
|
2274
|
+
let transformed = result.outputFiles[0].text;
|
|
2275
|
+
transformed += `
|
|
2276
|
+
// === Expose middleware exports to global scope ===
|
|
2277
|
+
if (typeof __MIDDLEWARE_EXPORTS__ !== 'undefined') {
|
|
2278
|
+
if (typeof __MIDDLEWARE_EXPORTS__.middleware === 'function') {
|
|
2279
|
+
globalThis.middleware = __MIDDLEWARE_EXPORTS__.middleware;
|
|
2280
|
+
}
|
|
2281
|
+
if (typeof __MIDDLEWARE_EXPORTS__.default === 'function') {
|
|
2282
|
+
globalThis.middleware = __MIDDLEWARE_EXPORTS__.default;
|
|
2283
|
+
}
|
|
2284
|
+
if (typeof __MIDDLEWARE_EXPORTS__.config === 'object') {
|
|
2285
|
+
globalThis.config = __MIDDLEWARE_EXPORTS__.config;
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
`;
|
|
2289
|
+
return transformed;
|
|
2290
|
+
}
|
|
2291
|
+
function detectMiddlewareEntry(code) {
|
|
2292
|
+
const bracketPattern = /_ENTRIES\s*\[\s*["']((?:middleware|proxy)[_\/a-zA-Z0-9]+)["']\s*\]/g;
|
|
2293
|
+
const bracketMatches = [...code.matchAll(bracketPattern)];
|
|
2294
|
+
for (const match of bracketMatches) {
|
|
2295
|
+
const entry = match[1];
|
|
2296
|
+
if (entry && /^(middleware|proxy)[_\/a-zA-Z0-9]+$/.test(entry)) {
|
|
2297
|
+
return entry;
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
const dotPattern = /_ENTRIES\s*\)?\.((middleware|proxy)[_a-zA-Z0-9]+)\s*=/g;
|
|
2301
|
+
const dotMatches = [...code.matchAll(dotPattern)];
|
|
2302
|
+
for (const match of dotMatches) {
|
|
2303
|
+
const entry = match[1];
|
|
2304
|
+
if (entry && /^(middleware|proxy)[_a-zA-Z0-9]+$/.test(entry)) {
|
|
2305
|
+
return entry;
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
const stringPattern = /["'](middleware_[a-zA-Z0-9_\/]+|proxy_[a-zA-Z0-9_\/]+)["']/g;
|
|
2309
|
+
const stringMatches = [...code.matchAll(stringPattern)];
|
|
2310
|
+
if (stringMatches.length > 0) {
|
|
2311
|
+
return stringMatches[0][1];
|
|
2312
|
+
}
|
|
2313
|
+
return "middleware_src/middleware";
|
|
2314
|
+
}
|
|
2315
|
+
function extractMiddlewareConfig(code) {
|
|
2316
|
+
const matcherPattern = /matcher\s*:\s*\[([^\]]+)\]/;
|
|
2317
|
+
const match = code.match(matcherPattern);
|
|
2318
|
+
if (match) {
|
|
2319
|
+
try {
|
|
2320
|
+
const matcherStr = match[1];
|
|
2321
|
+
const matchers = matcherStr.split(",").map((s) => s.trim().replace(/^["']|["']$/g, "")).filter((s) => s.length > 0);
|
|
2322
|
+
return { matcher: matchers };
|
|
2323
|
+
} catch {
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
return {};
|
|
2327
|
+
}
|
|
2328
|
+
function transformRequires(code) {
|
|
2329
|
+
code = code.replace(/require\s*\(\s*["']node:buffer["']\s*\)/g, "nodeBuffer");
|
|
2330
|
+
code = code.replace(/require\s*\(\s*["']node:async_hooks["']\s*\)/g, "nodeAsyncHooks");
|
|
2331
|
+
code = code.replace(/require\s*\(\s*["']buffer["']\s*\)/g, "nodeBuffer");
|
|
2332
|
+
code = code.replace(/require\s*\(\s*["']async_hooks["']\s*\)/g, "nodeAsyncHooks");
|
|
2333
|
+
return code;
|
|
2334
|
+
}
|
|
2335
|
+
function fixEdgeOneCompatibility(code) {
|
|
2336
|
+
return code;
|
|
2337
|
+
}
|
|
2338
|
+
function transformForEdgeOneRuntime(code) {
|
|
2339
|
+
let transformed = code;
|
|
2340
|
+
let transformCount = 0;
|
|
2341
|
+
const requestSymbolPattern = /(?:let|var|const|,)\s*([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*Symbol\s*\(\s*["']internal request["']\s*\)/g;
|
|
2342
|
+
transformed = transformed.replace(requestSymbolPattern, (match, varName) => {
|
|
2343
|
+
transformCount++;
|
|
2344
|
+
const prefix = match.match(/^(let|var|const|,)\s*/)?.[1] || "let";
|
|
2345
|
+
return `${prefix} ${varName}="__edgeone_nextInternal"`;
|
|
2346
|
+
});
|
|
2347
|
+
const responseSymbolPattern = /(?:let|var|const|,)\s*([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*Symbol\s*\(\s*["']internal response["']\s*\)/g;
|
|
2348
|
+
transformed = transformed.replace(responseSymbolPattern, (match, varName) => {
|
|
2349
|
+
transformCount++;
|
|
2350
|
+
const prefix = match.match(/^(let|var|const|,)\s*/)?.[1] || "let";
|
|
2351
|
+
return `${prefix} ${varName}="__edgeone_nextResponseInternal"`;
|
|
2352
|
+
});
|
|
2353
|
+
const nextRequestSubclassPattern = /class\s+(\w+)\s+extends\s+(\w+)\s*\{\s*constructor\s*\(\s*(\w+)\s*\)\s*\{\s*super\s*\(\s*\3\.input\s*,\s*\3\.init\s*\)\s*,\s*this\.sourcePage\s*=\s*\3\.page\s*;?\s*\}/g;
|
|
2354
|
+
transformed = transformed.replace(nextRequestSubclassPattern, (_match, className, parentClass, paramName) => {
|
|
2355
|
+
transformCount++;
|
|
2356
|
+
const patchedConstructor = `class ${className} extends ${parentClass}{constructor(${paramName}){super(${paramName}.input,${paramName}.init),this.sourcePage=${paramName}.page;var __k="__edgeone_nextInternal",__self=this;if(this[__k]){Object.defineProperty(this,"nextUrl",{get:function(){return __self[__k]?__self[__k].nextUrl:undefined},enumerable:true,configurable:true});Object.defineProperty(this,"cookies",{get:function(){return __self[__k]?__self[__k].cookies:undefined},enumerable:true,configurable:true})}}`;
|
|
2357
|
+
return patchedConstructor;
|
|
2358
|
+
});
|
|
2359
|
+
const baseClassInternalAssignPattern = /this\[(\w+)\]\s*=\s*\{\s*cookies\s*:\s*new\s+\w+\.RequestCookies\s*\(\s*this\.headers\s*\)\s*,\s*nextUrl\s*:\s*(\w+)\s*,\s*url\s*:\s*\2\.toString\s*\(\s*\)\s*\}/g;
|
|
2360
|
+
transformed = transformed.replace(baseClassInternalAssignPattern, (match, internalVar, _nextUrlVar) => {
|
|
2361
|
+
transformCount++;
|
|
2362
|
+
const patchedAssignment = match + `;var __self=this;Object.defineProperty(this,"nextUrl",{get:function(){return __self[${internalVar}]?__self[${internalVar}].nextUrl:undefined},enumerable:true,configurable:true});Object.defineProperty(this,"cookies",{get:function(){return __self[${internalVar}]?__self[${internalVar}].cookies:undefined},enumerable:true,configurable:true})`;
|
|
2363
|
+
return patchedAssignment;
|
|
2364
|
+
});
|
|
2365
|
+
const responseInternalAssignPattern = /this\[(\w+)\]\s*=\s*\{\s*cookies\s*:\s*(\w+)\s*,\s*url\s*:\s*([^}]+)\}/g;
|
|
2366
|
+
if (transformed.includes("ResponseCookies")) {
|
|
2367
|
+
transformed = transformed.replace(responseInternalAssignPattern, (match, internalVar, _cookiesVar, _urlExpr) => {
|
|
2368
|
+
if (match.includes("Proxy") || match.includes("ResponseCookies")) {
|
|
2369
|
+
transformCount++;
|
|
2370
|
+
const patchedAssignment = match + `;var __respSelf=this;Object.defineProperty(this,"cookies",{get:function(){return __respSelf[${internalVar}]?__respSelf[${internalVar}].cookies:undefined},enumerable:true,configurable:true})`;
|
|
2371
|
+
return patchedAssignment;
|
|
2372
|
+
}
|
|
2373
|
+
return match;
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
return transformed;
|
|
2377
|
+
}
|
|
2378
|
+
function fixWebpackConfigExport(code) {
|
|
2379
|
+
let transformed = code;
|
|
2380
|
+
const configDefPatterns = [
|
|
2381
|
+
// 字符串 matcher: let be={matcher:"/normal/test"}
|
|
2382
|
+
/(?:let|var|const)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*\{\s*matcher\s*:\s*"([^"]+)"\s*\}/,
|
|
2383
|
+
// 压缩格式: ;be={matcher:"/normal/test"} 或 ,be={matcher:"..."}
|
|
2384
|
+
/[;,]([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*\{\s*matcher\s*:\s*"([^"]+)"\s*\}/,
|
|
2385
|
+
// 数组 matcher: let be={matcher:["/api/:path*", "/dashboard/:path*"]}
|
|
2386
|
+
/(?:let|var|const)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*\{\s*matcher\s*:\s*(\[[^\]]+\])\s*\}/,
|
|
2387
|
+
// 压缩格式数组: ;be={matcher:[...]}
|
|
2388
|
+
/[;,]([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*\{\s*matcher\s*:\s*(\[[^\]]+\])\s*\}/
|
|
2389
|
+
];
|
|
2390
|
+
let configVarName = null;
|
|
2391
|
+
let configValue = null;
|
|
2392
|
+
for (const pattern of configDefPatterns) {
|
|
2393
|
+
const match = pattern.exec(code);
|
|
2394
|
+
if (match) {
|
|
2395
|
+
configVarName = match[1];
|
|
2396
|
+
if (match[2].startsWith("[")) {
|
|
2397
|
+
configValue = `{matcher:${match[2]}}`;
|
|
2398
|
+
} else {
|
|
2399
|
+
configValue = `{matcher:"${match[2]}"}`;
|
|
2400
|
+
}
|
|
2401
|
+
break;
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
if (!configVarName) {
|
|
2405
|
+
const exportPattern = /c\.d\s*\(\s*\w+\s*,\s*\{[^}]*config\s*:\s*\(\s*\)\s*=>\s*([a-zA-Z_$][a-zA-Z0-9_$]*)[^}]*\}/;
|
|
2406
|
+
const exportMatch = code.match(exportPattern);
|
|
2407
|
+
if (exportMatch) {
|
|
2408
|
+
configVarName = exportMatch[1];
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
if (configVarName && configValue) {
|
|
2412
|
+
const entriesPatterns = [
|
|
2413
|
+
// 带条件判断的格式: _ENTRIES)["middleware_src/middleware"]=b
|
|
2414
|
+
/(_ENTRIES\s*\)\s*\[\s*["'][^"']+["']\s*\]\s*=\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(?=\s*[}\];,)])/g,
|
|
2415
|
+
// 简单方括号访问: _ENTRIES["middleware_src/middleware"]=b
|
|
2416
|
+
/(_ENTRIES\s*\[\s*["'][^"']+["']\s*\]\s*=\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(?=\s*[}\];,)])/g,
|
|
2417
|
+
// 点号访问 (带括号): _ENTRIES).middleware_middleware=b
|
|
2418
|
+
/(_ENTRIES\s*\)?\.(?:middleware|proxy)[_a-zA-Z0-9]*\s*=\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(?=\s*[}\];,)])/g
|
|
2419
|
+
];
|
|
2420
|
+
for (const pattern of entriesPatterns) {
|
|
2421
|
+
transformed = transformed.replace(pattern, (match, prefix, varName) => {
|
|
2422
|
+
if (match.includes("config:")) {
|
|
2423
|
+
return match;
|
|
2424
|
+
}
|
|
2425
|
+
const configRef = configValue;
|
|
2426
|
+
const replacement = `${prefix}Object.assign({},${varName},{config:${configRef}})`;
|
|
2427
|
+
return replacement;
|
|
2428
|
+
});
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
return transformed;
|
|
2432
|
+
}
|
|
2433
|
+
async function compileTurbopack(inputPath, middlewareCode, options = {}) {
|
|
2434
|
+
const warnings = [];
|
|
2435
|
+
const errors = [];
|
|
2436
|
+
const middlewareDir = dirname(inputPath);
|
|
2437
|
+
const chunksDir = join(middlewareDir, "chunks");
|
|
2438
|
+
const chunkPattern = /R\.c\s*\(\s*["']([^"']+)["']\s*\)/g;
|
|
2439
|
+
const modulePattern = /R\.m\s*\(\s*(\d+)\s*\)/g;
|
|
2440
|
+
const chunkPaths = [];
|
|
2441
|
+
let match;
|
|
2442
|
+
while ((match = chunkPattern.exec(middlewareCode)) !== null) {
|
|
2443
|
+
chunkPaths.push(match[1]);
|
|
2444
|
+
}
|
|
2445
|
+
let entryModuleId = "";
|
|
2446
|
+
while ((match = modulePattern.exec(middlewareCode)) !== null) {
|
|
2447
|
+
entryModuleId = match[1];
|
|
2448
|
+
}
|
|
2449
|
+
const externalChunks = [];
|
|
2450
|
+
const middlewareChunks = [];
|
|
2451
|
+
for (const chunkPath of chunkPaths) {
|
|
2452
|
+
if (chunkPath.includes("[externals]")) {
|
|
2453
|
+
externalChunks.push(chunkPath);
|
|
2454
|
+
} else if (chunkPath.includes("[root-of-the-server]")) {
|
|
2455
|
+
middlewareChunks.push(chunkPath);
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
const chunksCode = [];
|
|
2459
|
+
for (const chunkPath of externalChunks) {
|
|
2460
|
+
const relativePath = chunkPath.replace(/^server\//, "");
|
|
2461
|
+
const fullPath = join(middlewareDir, relativePath);
|
|
2462
|
+
if (existsSync(fullPath)) {
|
|
2463
|
+
let code = readFileSync(fullPath, "utf-8");
|
|
2464
|
+
code = transformForEdgeOneRuntime(code);
|
|
2465
|
+
chunksCode.push(code);
|
|
2466
|
+
} else {
|
|
2467
|
+
warnings.push(`External chunk not found: ${fullPath}`);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
for (const chunkPath of middlewareChunks) {
|
|
2471
|
+
const relativePath = chunkPath.replace(/^server\//, "");
|
|
2472
|
+
const fullPath = join(middlewareDir, relativePath);
|
|
2473
|
+
if (existsSync(fullPath)) {
|
|
2474
|
+
let code = readFileSync(fullPath, "utf-8");
|
|
2475
|
+
code = transformForEdgeOneRuntime(code);
|
|
2476
|
+
chunksCode.push(code);
|
|
2477
|
+
} else {
|
|
2478
|
+
warnings.push(`Chunk not found: ${fullPath}`);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
if (chunksCode.length === 0) {
|
|
2482
|
+
errors.push("No middleware chunk found");
|
|
2483
|
+
return { code: "", warnings, errors };
|
|
2484
|
+
}
|
|
2485
|
+
const polyfillsCode = getPolyfillsCode();
|
|
2486
|
+
const turbopackCompatCode = getSimplifiedTurbopackCompat(entryModuleId);
|
|
2487
|
+
const outputCode = `
|
|
2488
|
+
// ============================================================
|
|
2489
|
+
// Next.js Middleware compiled for EdgeOne Pages
|
|
2490
|
+
// Build type: Turbopack (Next.js 16+)
|
|
2491
|
+
// Generated at: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
2492
|
+
// ============================================================
|
|
2493
|
+
|
|
2494
|
+
${polyfillsCode}
|
|
2495
|
+
|
|
2496
|
+
${turbopackCompatCode}
|
|
2497
|
+
|
|
2498
|
+
// ============================================================
|
|
2499
|
+
// Turbopack Middleware Chunks
|
|
2500
|
+
// ============================================================
|
|
2501
|
+
|
|
2502
|
+
${chunksCode.map((code, i) => `
|
|
2503
|
+
// --- Chunk ${i + 1} ---
|
|
2504
|
+
${code}
|
|
2505
|
+
`).join("\n")}
|
|
2506
|
+
`;
|
|
2507
|
+
return {
|
|
2508
|
+
code: outputCode,
|
|
2509
|
+
warnings,
|
|
2510
|
+
errors
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
function getSimplifiedTurbopackCompat(entryModuleId) {
|
|
2514
|
+
return `
|
|
2515
|
+
// ============================================================
|
|
2516
|
+
// Turbopack Runtime Compatibility Layer (\u57FA\u4E8E Next.js \u5B98\u65B9\u5B9E\u73B0)
|
|
2517
|
+
// ============================================================
|
|
2518
|
+
|
|
2519
|
+
// Edge \u73AF\u5883\u4E2D require \u4E0D\u5B58\u5728\uFF0C\u9700\u8981 mock
|
|
2520
|
+
if (typeof require === 'undefined') {
|
|
2521
|
+
globalThis.require = function(id) {
|
|
2522
|
+
throw new Error('require is not available in Edge environment: ' + id);
|
|
2523
|
+
};
|
|
2524
|
+
globalThis.require.resolve = function(id) { return id; };
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
const REEXPORTED_OBJECTS = new WeakMap();
|
|
2528
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2529
|
+
const toStringTag = typeof Symbol !== 'undefined' && Symbol.toStringTag;
|
|
2530
|
+
|
|
2531
|
+
// \u6A21\u5757\u5DE5\u5382\u548C\u7F13\u5B58
|
|
2532
|
+
const moduleFactories = new Map();
|
|
2533
|
+
const moduleCache = Object.create(null);
|
|
2534
|
+
|
|
2535
|
+
// \u8F85\u52A9\u51FD\u6570
|
|
2536
|
+
function defineProp(obj, name, options) {
|
|
2537
|
+
if (!hasOwnProperty.call(obj, name)) Object.defineProperty(obj, name, options);
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
function createModuleObject(id) {
|
|
2541
|
+
return {
|
|
2542
|
+
exports: {},
|
|
2543
|
+
error: undefined,
|
|
2544
|
+
id,
|
|
2545
|
+
loaded: false,
|
|
2546
|
+
namespaceObject: undefined
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
function getOverwrittenModule(id) {
|
|
2551
|
+
let module = moduleCache[id];
|
|
2552
|
+
if (!module) {
|
|
2553
|
+
module = createModuleObject(id);
|
|
2554
|
+
moduleCache[id] = module;
|
|
2555
|
+
}
|
|
2556
|
+
return module;
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
const BindingTag_Value = 0;
|
|
2560
|
+
|
|
2561
|
+
// esm() - \u6DFB\u52A0 getters \u5230 exports \u5BF9\u8C61
|
|
2562
|
+
function esm(exports, bindings) {
|
|
2563
|
+
defineProp(exports, '__esModule', { value: true });
|
|
2564
|
+
if (toStringTag) defineProp(exports, toStringTag, { value: 'Module' });
|
|
2565
|
+
|
|
2566
|
+
let i = 0;
|
|
2567
|
+
while (i < bindings.length) {
|
|
2568
|
+
const propName = bindings[i++];
|
|
2569
|
+
const tagOrFunction = bindings[i++];
|
|
2570
|
+
if (typeof tagOrFunction === 'number') {
|
|
2571
|
+
if (tagOrFunction === BindingTag_Value) {
|
|
2572
|
+
defineProp(exports, propName, {
|
|
2573
|
+
value: bindings[i++],
|
|
2574
|
+
enumerable: true,
|
|
2575
|
+
writable: false
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
} else {
|
|
2579
|
+
const getterFn = tagOrFunction;
|
|
2580
|
+
if (typeof bindings[i] === 'function') {
|
|
2581
|
+
const setterFn = bindings[i++];
|
|
2582
|
+
defineProp(exports, propName, {
|
|
2583
|
+
get: getterFn,
|
|
2584
|
+
set: setterFn,
|
|
2585
|
+
enumerable: true
|
|
2586
|
+
});
|
|
2587
|
+
} else {
|
|
2588
|
+
defineProp(exports, propName, {
|
|
2589
|
+
get: getterFn,
|
|
2590
|
+
enumerable: true
|
|
2591
|
+
});
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
Object.seal(exports);
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2598
|
+
// interopEsm - \u5904\u7406 ESM/CJS \u4E92\u64CD\u4F5C
|
|
2599
|
+
const getProto = Object.getPrototypeOf ? (obj) => Object.getPrototypeOf(obj) : (obj) => obj.__proto__;
|
|
2600
|
+
const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)];
|
|
2601
|
+
|
|
2602
|
+
function createGetter(obj, key) {
|
|
2603
|
+
return () => obj[key];
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
function createNS(raw) {
|
|
2607
|
+
if (typeof raw === 'function') {
|
|
2608
|
+
return function(...args) { return raw.apply(this, args); };
|
|
2609
|
+
} else {
|
|
2610
|
+
return Object.create(null);
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
function interopEsm(raw, ns, allowExportDefault) {
|
|
2615
|
+
const bindings = [];
|
|
2616
|
+
let defaultLocation = -1;
|
|
2617
|
+
for (let current = raw; (typeof current === 'object' || typeof current === 'function') && !LEAF_PROTOTYPES.includes(current); current = getProto(current)) {
|
|
2618
|
+
for (const key of Object.getOwnPropertyNames(current)) {
|
|
2619
|
+
bindings.push(key, createGetter(raw, key));
|
|
2620
|
+
if (defaultLocation === -1 && key === 'default') {
|
|
2621
|
+
defaultLocation = bindings.length - 1;
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
if (!(allowExportDefault && defaultLocation >= 0)) {
|
|
2626
|
+
if (defaultLocation >= 0) {
|
|
2627
|
+
bindings.splice(defaultLocation, 1, BindingTag_Value, raw);
|
|
2628
|
+
} else {
|
|
2629
|
+
bindings.push('default', BindingTag_Value, raw);
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
esm(ns, bindings);
|
|
2633
|
+
return ns;
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
// Context \u6784\u9020\u51FD\u6570
|
|
2637
|
+
function Context(module, exports) {
|
|
2638
|
+
this.m = module;
|
|
2639
|
+
this.e = exports;
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
const contextPrototype = Context.prototype;
|
|
2643
|
+
|
|
2644
|
+
// e.c - \u6A21\u5757\u7F13\u5B58
|
|
2645
|
+
contextPrototype.c = moduleCache;
|
|
2646
|
+
|
|
2647
|
+
// e.M - \u6A21\u5757\u5DE5\u5382
|
|
2648
|
+
contextPrototype.M = moduleFactories;
|
|
2649
|
+
|
|
2650
|
+
// e.g - globalThis
|
|
2651
|
+
contextPrototype.g = globalThis;
|
|
2652
|
+
|
|
2653
|
+
// e.s() - ESM export
|
|
2654
|
+
contextPrototype.s = function esmExport(bindings, id) {
|
|
2655
|
+
let module, exports;
|
|
2656
|
+
if (id != null) {
|
|
2657
|
+
module = getOverwrittenModule(id);
|
|
2658
|
+
exports = module.exports;
|
|
2659
|
+
} else {
|
|
2660
|
+
module = this.m;
|
|
2661
|
+
exports = this.e;
|
|
2662
|
+
}
|
|
2663
|
+
module.namespaceObject = exports;
|
|
2664
|
+
esm(exports, bindings);
|
|
2665
|
+
};
|
|
2666
|
+
|
|
2667
|
+
// e.j() - \u52A8\u6001\u5BFC\u51FA
|
|
2668
|
+
function ensureDynamicExports(module, exports) {
|
|
2669
|
+
let reexportedObjects = REEXPORTED_OBJECTS.get(module);
|
|
2670
|
+
if (!reexportedObjects) {
|
|
2671
|
+
REEXPORTED_OBJECTS.set(module, reexportedObjects = []);
|
|
2672
|
+
module.exports = module.namespaceObject = new Proxy(exports, {
|
|
2673
|
+
get(target, prop) {
|
|
2674
|
+
if (hasOwnProperty.call(target, prop) || prop === 'default' || prop === '__esModule') {
|
|
2675
|
+
return Reflect.get(target, prop);
|
|
2676
|
+
}
|
|
2677
|
+
for (const obj of reexportedObjects) {
|
|
2678
|
+
const value = Reflect.get(obj, prop);
|
|
2679
|
+
if (value !== undefined) return value;
|
|
2680
|
+
}
|
|
2681
|
+
return undefined;
|
|
2682
|
+
},
|
|
2683
|
+
ownKeys(target) {
|
|
2684
|
+
const keys = Reflect.ownKeys(target);
|
|
2685
|
+
for (const obj of reexportedObjects) {
|
|
2686
|
+
for (const key of Reflect.ownKeys(obj)) {
|
|
2687
|
+
if (key !== 'default' && !keys.includes(key)) keys.push(key);
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
return keys;
|
|
2691
|
+
}
|
|
2692
|
+
});
|
|
2693
|
+
}
|
|
2694
|
+
return reexportedObjects;
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
contextPrototype.j = function dynamicExport(object, id) {
|
|
2698
|
+
let module, exports;
|
|
2699
|
+
if (id != null) {
|
|
2700
|
+
module = getOverwrittenModule(id);
|
|
2701
|
+
exports = module.exports;
|
|
2702
|
+
} else {
|
|
2703
|
+
module = this.m;
|
|
2704
|
+
exports = this.e;
|
|
2705
|
+
}
|
|
2706
|
+
const reexportedObjects = ensureDynamicExports(module, exports);
|
|
2707
|
+
if (typeof object === 'object' && object !== null) {
|
|
2708
|
+
reexportedObjects.push(object);
|
|
2709
|
+
}
|
|
2710
|
+
};
|
|
2711
|
+
|
|
2712
|
+
// e.v() - \u5BFC\u51FA\u503C
|
|
2713
|
+
contextPrototype.v = function exportValue(value, id) {
|
|
2714
|
+
let module;
|
|
2715
|
+
if (id != null) {
|
|
2716
|
+
module = getOverwrittenModule(id);
|
|
2717
|
+
} else {
|
|
2718
|
+
module = this.m;
|
|
2719
|
+
}
|
|
2720
|
+
module.exports = value;
|
|
2721
|
+
};
|
|
2722
|
+
|
|
2723
|
+
// e.n() - \u5BFC\u51FA\u547D\u540D\u7A7A\u95F4
|
|
2724
|
+
contextPrototype.n = function exportNamespace(namespace, id) {
|
|
2725
|
+
let module;
|
|
2726
|
+
if (id != null) {
|
|
2727
|
+
module = getOverwrittenModule(id);
|
|
2728
|
+
} else {
|
|
2729
|
+
module = this.m;
|
|
2730
|
+
}
|
|
2731
|
+
module.exports = module.namespaceObject = namespace;
|
|
2732
|
+
};
|
|
2733
|
+
|
|
2734
|
+
// e.i() - ESM import
|
|
2735
|
+
contextPrototype.i = function esmImport(id) {
|
|
2736
|
+
const module = getOrInstantiateModuleFromParent(id, this.m);
|
|
2737
|
+
if (module.namespaceObject) return module.namespaceObject;
|
|
2738
|
+
const raw = module.exports;
|
|
2739
|
+
return module.namespaceObject = interopEsm(raw, createNS(raw), raw && raw.__esModule);
|
|
2740
|
+
};
|
|
2741
|
+
|
|
2742
|
+
// e.r() - CommonJS require (\u5173\u952E\uFF01\u4E0D\u662F ESM \u6807\u8BB0)
|
|
2743
|
+
contextPrototype.r = function commonJsRequire(id) {
|
|
2744
|
+
return getOrInstantiateModuleFromParent(id, this.m).exports;
|
|
2745
|
+
};
|
|
2746
|
+
|
|
2747
|
+
// e.t() - runtime require
|
|
2748
|
+
contextPrototype.t = typeof require === 'function' ? require : function() {
|
|
2749
|
+
throw new Error('Unexpected use of runtime require');
|
|
2750
|
+
};
|
|
2751
|
+
|
|
2752
|
+
// e.z() - require stub
|
|
2753
|
+
contextPrototype.z = function requireStub(_moduleId) {
|
|
2754
|
+
throw new Error('dynamic usage of require is not supported');
|
|
2755
|
+
};
|
|
2756
|
+
|
|
2757
|
+
// e.x() - external require (Edge \u73AF\u5883 mock)
|
|
2758
|
+
function externalRequire(id, thunk, esmFlag) {
|
|
2759
|
+
let raw;
|
|
2760
|
+
try {
|
|
2761
|
+
if (thunk) {
|
|
2762
|
+
raw = thunk();
|
|
2763
|
+
} else {
|
|
2764
|
+
raw = getExternalMock(id);
|
|
2765
|
+
}
|
|
2766
|
+
} catch (err) {
|
|
2767
|
+
raw = getExternalMock(id);
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2770
|
+
if (!esmFlag || (raw && raw.__esModule)) {
|
|
2771
|
+
return raw;
|
|
2772
|
+
}
|
|
2773
|
+
return interopEsm(raw, createNS(raw), true);
|
|
2774
|
+
}
|
|
2775
|
+
externalRequire.resolve = (id, options) => id;
|
|
2776
|
+
contextPrototype.x = externalRequire;
|
|
2777
|
+
|
|
2778
|
+
// e.y() - external import (async)
|
|
2779
|
+
contextPrototype.y = async function externalImport(id) {
|
|
2780
|
+
return getExternalMock(id);
|
|
2781
|
+
};
|
|
2782
|
+
|
|
2783
|
+
// \u5916\u90E8\u6A21\u5757 mock
|
|
2784
|
+
function getExternalMock(id) {
|
|
2785
|
+
// Work unit storage mock - \u8FD9\u4E9B\u662F Next.js \u5185\u90E8\u4F7F\u7528\u7684 AsyncLocalStorage
|
|
2786
|
+
// \u6CE8\u610F\uFF1A\u5FC5\u987B\u5728\u901A\u7528 async-storage \u4E4B\u524D\u5339\u914D
|
|
2787
|
+
if (id.includes('work-unit-async-storage') || id.includes('work-async-storage') || id.includes('workUnitAsyncStorage') || id.includes('workAsyncStorage')) {
|
|
2788
|
+
// \u521B\u5EFA AsyncLocalStorage mock
|
|
2789
|
+
const createAsyncLocalStorage = () => ({
|
|
2790
|
+
getStore: () => undefined,
|
|
2791
|
+
run: (store, fn, ...args) => {
|
|
2792
|
+
if (typeof fn === 'function') {
|
|
2793
|
+
return fn(...args);
|
|
2794
|
+
}
|
|
2795
|
+
return undefined;
|
|
2796
|
+
},
|
|
2797
|
+
enterWith: () => {},
|
|
2798
|
+
disable: () => {},
|
|
2799
|
+
exit: (fn) => fn ? fn() : undefined
|
|
2800
|
+
});
|
|
2801
|
+
|
|
2802
|
+
const result = {
|
|
2803
|
+
workAsyncStorage: createAsyncLocalStorage(),
|
|
2804
|
+
workUnitAsyncStorage: createAsyncLocalStorage(),
|
|
2805
|
+
getStore: () => undefined,
|
|
2806
|
+
run: (store, fn, ...args) => {
|
|
2807
|
+
if (typeof fn === 'function') {
|
|
2808
|
+
return fn(...args);
|
|
2809
|
+
}
|
|
2810
|
+
return undefined;
|
|
2811
|
+
}
|
|
2812
|
+
};
|
|
2813
|
+
Object.defineProperty(result, '__esModule', { value: true });
|
|
2814
|
+
return result;
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
// after-task-async-storage mock
|
|
2818
|
+
if (id.includes('after-task-async-storage')) {
|
|
2819
|
+
const createAsyncLocalStorage = () => ({
|
|
2820
|
+
getStore: () => undefined,
|
|
2821
|
+
run: (store, fn, ...args) => {
|
|
2822
|
+
if (typeof fn === 'function') {
|
|
2823
|
+
return fn(...args);
|
|
2824
|
+
}
|
|
2825
|
+
return undefined;
|
|
2826
|
+
},
|
|
2827
|
+
enterWith: () => {},
|
|
2828
|
+
disable: () => {},
|
|
2829
|
+
exit: (fn) => fn ? fn() : undefined
|
|
2830
|
+
});
|
|
2831
|
+
|
|
2832
|
+
const result = {
|
|
2833
|
+
afterTaskAsyncStorage: createAsyncLocalStorage(),
|
|
2834
|
+
getStore: () => undefined,
|
|
2835
|
+
run: (store, fn, ...args) => {
|
|
2836
|
+
if (typeof fn === 'function') {
|
|
2837
|
+
return fn(...args);
|
|
2838
|
+
}
|
|
2839
|
+
return undefined;
|
|
2840
|
+
}
|
|
2841
|
+
};
|
|
2842
|
+
Object.defineProperty(result, '__esModule', { value: true });
|
|
2843
|
+
return result;
|
|
2844
|
+
}
|
|
2845
|
+
|
|
2846
|
+
// AsyncLocalStorage mock (\u901A\u7528)
|
|
2847
|
+
if (id.includes('async_hooks') || id.includes('AsyncLocalStorage')) {
|
|
2848
|
+
const AsyncLocalStorageMock = function() {};
|
|
2849
|
+
AsyncLocalStorageMock.prototype.getStore = function() { return undefined; };
|
|
2850
|
+
AsyncLocalStorageMock.prototype.run = function(store, fn, ...args) { return typeof fn === 'function' ? fn(...args) : undefined; };
|
|
2851
|
+
AsyncLocalStorageMock.prototype.enterWith = function() {};
|
|
2852
|
+
AsyncLocalStorageMock.prototype.disable = function() {};
|
|
2853
|
+
AsyncLocalStorageMock.prototype.exit = function(fn) { return fn ? fn() : undefined; };
|
|
2854
|
+
const result = { AsyncLocalStorage: AsyncLocalStorageMock };
|
|
2855
|
+
Object.defineProperty(result, '__esModule', { value: true });
|
|
2856
|
+
return result;
|
|
2857
|
+
}
|
|
2858
|
+
|
|
2859
|
+
// app-page-turbo.runtime.prod.js mock (\u5305\u542B vendored React)
|
|
2860
|
+
if (id.includes('app-page-turbo.runtime') || id.includes('app-page.runtime')) {
|
|
2861
|
+
// \u521B\u5EFA React mock
|
|
2862
|
+
const ReactMock = {
|
|
2863
|
+
createElement: function(type, props, ...children) { return { type, props, children }; },
|
|
2864
|
+
Fragment: Symbol.for('react.fragment'),
|
|
2865
|
+
useState: function(init) { return [init, function() {}]; },
|
|
2866
|
+
useEffect: function() {},
|
|
2867
|
+
useCallback: function(fn) { return fn; },
|
|
2868
|
+
useMemo: function(fn) { return fn(); },
|
|
2869
|
+
useRef: function(init) { return { current: init }; },
|
|
2870
|
+
useContext: function() { return undefined; },
|
|
2871
|
+
createContext: function(def) { return { Provider: function() {}, Consumer: function() {}, _currentValue: def }; },
|
|
2872
|
+
forwardRef: function(render) { return render; },
|
|
2873
|
+
memo: function(component) { return component; },
|
|
2874
|
+
lazy: function(factory) { return factory; },
|
|
2875
|
+
Suspense: function() {},
|
|
2876
|
+
Component: function() {},
|
|
2877
|
+
PureComponent: function() {},
|
|
2878
|
+
Children: { map: function(c, fn) { return Array.isArray(c) ? c.map(fn) : fn ? [fn(c)] : []; }, forEach: function() {}, count: function(c) { return Array.isArray(c) ? c.length : 1; }, only: function(c) { return c; }, toArray: function(c) { return Array.isArray(c) ? c : [c]; } },
|
|
2879
|
+
isValidElement: function() { return false; },
|
|
2880
|
+
cloneElement: function(el) { return el; },
|
|
2881
|
+
version: '18.0.0',
|
|
2882
|
+
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {}
|
|
2883
|
+
};
|
|
2884
|
+
|
|
2885
|
+
// \u521B\u5EFA ReactDOM mock
|
|
2886
|
+
const ReactDOMMock = {
|
|
2887
|
+
render: function() {},
|
|
2888
|
+
hydrate: function() {},
|
|
2889
|
+
createRoot: function() { return { render: function() {}, unmount: function() {} }; },
|
|
2890
|
+
hydrateRoot: function() { return { render: function() {}, unmount: function() {} }; },
|
|
2891
|
+
flushSync: function(fn) { return fn(); },
|
|
2892
|
+
createPortal: function(children) { return children; },
|
|
2893
|
+
findDOMNode: function() { return null; },
|
|
2894
|
+
unmountComponentAtNode: function() { return false; }
|
|
2895
|
+
};
|
|
2896
|
+
|
|
2897
|
+
// \u521B\u5EFA vendored \u7ED3\u6784
|
|
2898
|
+
const result = {
|
|
2899
|
+
vendored: {
|
|
2900
|
+
'react-rsc': {
|
|
2901
|
+
React: ReactMock,
|
|
2902
|
+
ReactDOM: ReactDOMMock,
|
|
2903
|
+
ReactJsxRuntime: {
|
|
2904
|
+
jsx: ReactMock.createElement,
|
|
2905
|
+
jsxs: ReactMock.createElement,
|
|
2906
|
+
Fragment: ReactMock.Fragment
|
|
2907
|
+
}
|
|
2908
|
+
},
|
|
2909
|
+
react: ReactMock,
|
|
2910
|
+
'react-dom': ReactDOMMock
|
|
2911
|
+
}
|
|
2912
|
+
};
|
|
2913
|
+
Object.defineProperty(result, '__esModule', { value: true });
|
|
2914
|
+
return result;
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
// incremental-cache/tags-manifest mock
|
|
2918
|
+
if (id.includes('incremental-cache') || id.includes('tags-manifest')) {
|
|
2919
|
+
const result = {
|
|
2920
|
+
getTagsManifest: function() { return {}; },
|
|
2921
|
+
saveTagsManifest: function() {},
|
|
2922
|
+
default: {}
|
|
2923
|
+
};
|
|
2924
|
+
Object.defineProperty(result, '__esModule', { value: true });
|
|
2925
|
+
return result;
|
|
2926
|
+
}
|
|
2927
|
+
|
|
2928
|
+
// path mock
|
|
2929
|
+
if (id === 'path') {
|
|
2930
|
+
return {
|
|
2931
|
+
join: (...args) => args.join('/').replace(/\\/\\/+/g, '/'),
|
|
2932
|
+
resolve: (...args) => args.join('/').replace(/\\/\\/+/g, '/'),
|
|
2933
|
+
dirname: (p) => p.split('/').slice(0, -1).join('/') || '/',
|
|
2934
|
+
basename: (p) => p.split('/').pop() || '',
|
|
2935
|
+
extname: (p) => { const m = p.match(/\\.[^.]+$/); return m ? m[0] : ''; },
|
|
2936
|
+
relative: (from, to) => to,
|
|
2937
|
+
sep: '/',
|
|
2938
|
+
default: null
|
|
2939
|
+
};
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
// os mock
|
|
2943
|
+
if (id === 'os') {
|
|
2944
|
+
return {
|
|
2945
|
+
platform: () => 'linux',
|
|
2946
|
+
homedir: () => '/home/user',
|
|
2947
|
+
tmpdir: () => '/tmp',
|
|
2948
|
+
default: null
|
|
2949
|
+
};
|
|
2950
|
+
}
|
|
2951
|
+
|
|
2952
|
+
// fs mock
|
|
2953
|
+
if (id === 'fs') {
|
|
2954
|
+
return {
|
|
2955
|
+
existsSync: () => false,
|
|
2956
|
+
readFileSync: () => '',
|
|
2957
|
+
writeFileSync: () => {},
|
|
2958
|
+
mkdirSync: () => {},
|
|
2959
|
+
chmodSync: () => {},
|
|
2960
|
+
default: null
|
|
2961
|
+
};
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
// \u901A\u7528 mock
|
|
2965
|
+
const result = {};
|
|
2966
|
+
Object.defineProperty(result, '__esModule', { value: true });
|
|
2967
|
+
return result;
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
// e.A() - async loader
|
|
2971
|
+
contextPrototype.A = function asyncLoader(moduleId) {
|
|
2972
|
+
const loader = this.r(moduleId);
|
|
2973
|
+
return loader(contextPrototype.i.bind(this));
|
|
2974
|
+
};
|
|
2975
|
+
|
|
2976
|
+
// e.l() - load chunk async
|
|
2977
|
+
contextPrototype.l = function loadChunkAsync(chunkData) {
|
|
2978
|
+
return Promise.resolve(undefined);
|
|
2979
|
+
};
|
|
2980
|
+
|
|
2981
|
+
// e.L() - load chunk by URL
|
|
2982
|
+
contextPrototype.L = function loadChunkAsyncByUrl(chunkUrl) {
|
|
2983
|
+
return Promise.resolve(undefined);
|
|
2984
|
+
};
|
|
2985
|
+
|
|
2986
|
+
// e.f() - module context
|
|
2987
|
+
contextPrototype.f = function moduleContext(map) {
|
|
2988
|
+
function ctx(id) {
|
|
2989
|
+
if (hasOwnProperty.call(map, id)) {
|
|
2990
|
+
return map[id].module();
|
|
2991
|
+
}
|
|
2992
|
+
const e = new Error("Cannot find module '" + id + "'");
|
|
2993
|
+
e.code = 'MODULE_NOT_FOUND';
|
|
2994
|
+
throw e;
|
|
2995
|
+
}
|
|
2996
|
+
ctx.keys = () => Object.keys(map);
|
|
2997
|
+
ctx.resolve = (id) => {
|
|
2998
|
+
if (hasOwnProperty.call(map, id)) return map[id].id();
|
|
2999
|
+
const e = new Error("Cannot find module '" + id + "'");
|
|
3000
|
+
e.code = 'MODULE_NOT_FOUND';
|
|
3001
|
+
throw e;
|
|
3002
|
+
};
|
|
3003
|
+
ctx.import = async (id) => await ctx(id);
|
|
3004
|
+
return ctx;
|
|
3005
|
+
};
|
|
3006
|
+
|
|
3007
|
+
// e.P() - resolve absolute path
|
|
3008
|
+
contextPrototype.P = function resolveAbsolutePath(modulePath) {
|
|
3009
|
+
return modulePath || '/';
|
|
3010
|
+
};
|
|
3011
|
+
|
|
3012
|
+
// e.R() - resolve path from module
|
|
3013
|
+
contextPrototype.R = function resolvePathFromModule(moduleId) {
|
|
3014
|
+
const exported = this.r(moduleId);
|
|
3015
|
+
return exported?.default ?? exported;
|
|
3016
|
+
};
|
|
3017
|
+
|
|
3018
|
+
// e.U() - relative URL
|
|
3019
|
+
const relativeURL = function relativeURL(inputUrl) {
|
|
3020
|
+
const realUrl = new URL(inputUrl, 'x:/');
|
|
3021
|
+
const values = {};
|
|
3022
|
+
for (const key in realUrl) values[key] = realUrl[key];
|
|
3023
|
+
values.href = inputUrl;
|
|
3024
|
+
values.pathname = inputUrl.replace(/[?#].*/, '');
|
|
3025
|
+
values.origin = values.protocol = '';
|
|
3026
|
+
values.toString = values.toJSON = () => inputUrl;
|
|
3027
|
+
for (const key in values) Object.defineProperty(this, key, {
|
|
3028
|
+
enumerable: true,
|
|
3029
|
+
configurable: true,
|
|
3030
|
+
value: values[key]
|
|
3031
|
+
});
|
|
3032
|
+
};
|
|
3033
|
+
relativeURL.prototype = URL.prototype;
|
|
3034
|
+
contextPrototype.U = relativeURL;
|
|
3035
|
+
|
|
3036
|
+
// e.w() - load WebAssembly
|
|
3037
|
+
contextPrototype.w = function loadWebAssembly() {
|
|
3038
|
+
throw new Error('WebAssembly loading not supported in Edge environment');
|
|
3039
|
+
};
|
|
3040
|
+
|
|
3041
|
+
// e.u() - load WebAssembly module
|
|
3042
|
+
contextPrototype.u = function loadWebAssemblyModule() {
|
|
3043
|
+
throw new Error('WebAssembly module loading not supported in Edge environment');
|
|
3044
|
+
};
|
|
3045
|
+
|
|
3046
|
+
// e.a() - async module (\u7B80\u5316\u7248)
|
|
3047
|
+
const turbopackQueues = Symbol('turbopack queues');
|
|
3048
|
+
const turbopackExports = Symbol('turbopack exports');
|
|
3049
|
+
const turbopackError = Symbol('turbopack error');
|
|
3050
|
+
|
|
3051
|
+
function resolveQueue(queue) {
|
|
3052
|
+
if (queue && queue.status !== 1) {
|
|
3053
|
+
queue.status = 1;
|
|
3054
|
+
queue.forEach((fn) => fn.queueCount--);
|
|
3055
|
+
queue.forEach((fn) => fn.queueCount-- ? fn.queueCount++ : fn());
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
|
|
3059
|
+
function createPromise() {
|
|
3060
|
+
let resolve, reject;
|
|
3061
|
+
const promise = new Promise((res, rej) => {
|
|
3062
|
+
reject = rej;
|
|
3063
|
+
resolve = res;
|
|
3064
|
+
});
|
|
3065
|
+
return { promise, resolve, reject };
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
function isPromise(maybePromise) {
|
|
3069
|
+
return maybePromise != null && typeof maybePromise === 'object' && 'then' in maybePromise && typeof maybePromise.then === 'function';
|
|
3070
|
+
}
|
|
3071
|
+
|
|
3072
|
+
function isAsyncModuleExt(obj) {
|
|
3073
|
+
return turbopackQueues in obj;
|
|
3074
|
+
}
|
|
3075
|
+
|
|
3076
|
+
function wrapDeps(deps) {
|
|
3077
|
+
return deps.map((dep) => {
|
|
3078
|
+
if (dep !== null && typeof dep === 'object') {
|
|
3079
|
+
if (isAsyncModuleExt(dep)) return dep;
|
|
3080
|
+
if (isPromise(dep)) {
|
|
3081
|
+
const queue = Object.assign([], { status: 0 });
|
|
3082
|
+
const obj = {
|
|
3083
|
+
[turbopackExports]: {},
|
|
3084
|
+
[turbopackQueues]: (fn) => fn(queue)
|
|
3085
|
+
};
|
|
3086
|
+
dep.then((res) => {
|
|
3087
|
+
obj[turbopackExports] = res;
|
|
3088
|
+
resolveQueue(queue);
|
|
3089
|
+
}, (err) => {
|
|
3090
|
+
obj[turbopackError] = err;
|
|
3091
|
+
resolveQueue(queue);
|
|
3092
|
+
});
|
|
3093
|
+
return obj;
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
return {
|
|
3097
|
+
[turbopackExports]: dep,
|
|
3098
|
+
[turbopackQueues]: () => {}
|
|
3099
|
+
};
|
|
3100
|
+
});
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
contextPrototype.a = function asyncModule(body, hasAwait) {
|
|
3104
|
+
const module = this.m;
|
|
3105
|
+
const queue = hasAwait ? Object.assign([], { status: -1 }) : undefined;
|
|
3106
|
+
const depQueues = new Set();
|
|
3107
|
+
const { resolve, reject, promise: rawPromise } = createPromise();
|
|
3108
|
+
const promise = Object.assign(rawPromise, {
|
|
3109
|
+
[turbopackExports]: module.exports,
|
|
3110
|
+
[turbopackQueues]: (fn) => {
|
|
3111
|
+
queue && fn(queue);
|
|
3112
|
+
depQueues.forEach(fn);
|
|
3113
|
+
promise['catch'](() => {});
|
|
3114
|
+
}
|
|
3115
|
+
});
|
|
3116
|
+
const attributes = {
|
|
3117
|
+
get() { return promise; },
|
|
3118
|
+
set(v) {
|
|
3119
|
+
if (v !== promise) {
|
|
3120
|
+
promise[turbopackExports] = v;
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
};
|
|
3124
|
+
Object.defineProperty(module, 'exports', attributes);
|
|
3125
|
+
Object.defineProperty(module, 'namespaceObject', attributes);
|
|
3126
|
+
|
|
3127
|
+
function handleAsyncDependencies(deps) {
|
|
3128
|
+
const currentDeps = wrapDeps(deps);
|
|
3129
|
+
const getResult = () => currentDeps.map((d) => {
|
|
3130
|
+
if (d[turbopackError]) throw d[turbopackError];
|
|
3131
|
+
return d[turbopackExports];
|
|
3132
|
+
});
|
|
3133
|
+
const { promise, resolve } = createPromise();
|
|
3134
|
+
const fn = Object.assign(() => resolve(getResult), { queueCount: 0 });
|
|
3135
|
+
function fnQueue(q) {
|
|
3136
|
+
if (q !== queue && !depQueues.has(q)) {
|
|
3137
|
+
depQueues.add(q);
|
|
3138
|
+
if (q && q.status === 0) {
|
|
3139
|
+
fn.queueCount++;
|
|
3140
|
+
q.push(fn);
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
currentDeps.map((dep) => dep[turbopackQueues](fnQueue));
|
|
3145
|
+
return fn.queueCount ? promise : getResult();
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
function asyncResult(err) {
|
|
3149
|
+
if (err) {
|
|
3150
|
+
reject(promise[turbopackError] = err);
|
|
3151
|
+
} else {
|
|
3152
|
+
resolve(promise[turbopackExports]);
|
|
3153
|
+
}
|
|
3154
|
+
resolveQueue(queue);
|
|
3155
|
+
}
|
|
3156
|
+
|
|
3157
|
+
body(handleAsyncDependencies, asyncResult);
|
|
3158
|
+
if (queue && queue.status === -1) {
|
|
3159
|
+
queue.status = 0;
|
|
3160
|
+
}
|
|
3161
|
+
};
|
|
3162
|
+
|
|
3163
|
+
// ============================================================
|
|
3164
|
+
// \u6A21\u5757\u5B9E\u4F8B\u5316
|
|
3165
|
+
// ============================================================
|
|
3166
|
+
|
|
3167
|
+
function instantiateModule(id, sourceType, sourceData) {
|
|
3168
|
+
const moduleFactory = moduleFactories.get(id);
|
|
3169
|
+
if (typeof moduleFactory !== 'function') {
|
|
3170
|
+
let reason = sourceType === 0
|
|
3171
|
+
? 'as a runtime entry of chunk ' + sourceData
|
|
3172
|
+
: 'because it was required from module ' + sourceData;
|
|
3173
|
+
throw new Error('Module ' + id + ' was instantiated ' + reason + ', but the module factory is not available. Available: ' + Array.from(moduleFactories.keys()).join(', '));
|
|
3174
|
+
}
|
|
3175
|
+
|
|
3176
|
+
const module = createModuleObject(id);
|
|
3177
|
+
const exports = module.exports;
|
|
3178
|
+
moduleCache[id] = module;
|
|
3179
|
+
|
|
3180
|
+
const context = new Context(module, exports);
|
|
3181
|
+
|
|
3182
|
+
try {
|
|
3183
|
+
moduleFactory(context, module, exports);
|
|
3184
|
+
} catch (error) {
|
|
3185
|
+
module.error = error;
|
|
3186
|
+
throw error;
|
|
3187
|
+
}
|
|
3188
|
+
|
|
3189
|
+
module.loaded = true;
|
|
3190
|
+
if (module.namespaceObject && module.exports !== module.namespaceObject) {
|
|
3191
|
+
interopEsm(module.exports, module.namespaceObject);
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
return module;
|
|
3195
|
+
}
|
|
3196
|
+
|
|
3197
|
+
function getOrInstantiateModuleFromParent(id, sourceModule) {
|
|
3198
|
+
const module = moduleCache[id];
|
|
3199
|
+
if (module) {
|
|
3200
|
+
if (module.error) {
|
|
3201
|
+
throw module.error;
|
|
3202
|
+
}
|
|
3203
|
+
return module;
|
|
3204
|
+
}
|
|
3205
|
+
return instantiateModule(id, 1, sourceModule.id);
|
|
3206
|
+
}
|
|
3207
|
+
|
|
3208
|
+
function getOrInstantiateRuntimeModule(chunkPath, moduleId) {
|
|
3209
|
+
const module = moduleCache[moduleId];
|
|
3210
|
+
if (module) {
|
|
3211
|
+
if (module.error) {
|
|
3212
|
+
throw module.error;
|
|
3213
|
+
}
|
|
3214
|
+
return module;
|
|
3215
|
+
}
|
|
3216
|
+
return instantiateModule(moduleId, 0, chunkPath);
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
// ============================================================
|
|
3220
|
+
// Chunk \u52A0\u8F7D
|
|
3221
|
+
// ============================================================
|
|
3222
|
+
|
|
3223
|
+
// \u5B89\u88C5\u538B\u7F29\u683C\u5F0F\u7684\u6A21\u5757\u5DE5\u5382
|
|
3224
|
+
// Chunk \u683C\u5F0F: [moduleId1, factory1, moduleId2, factory2, ...]
|
|
3225
|
+
function installCompressedModuleFactories(chunkModules, offset) {
|
|
3226
|
+
let i = offset || 0;
|
|
3227
|
+
while (i < chunkModules.length) {
|
|
3228
|
+
let moduleId = chunkModules[i];
|
|
3229
|
+
let end = i + 1;
|
|
3230
|
+
// \u627E\u5230\u5DE5\u5382\u51FD\u6570
|
|
3231
|
+
while (end < chunkModules.length && typeof chunkModules[end] !== 'function') {
|
|
3232
|
+
end++;
|
|
3233
|
+
}
|
|
3234
|
+
if (end === chunkModules.length) {
|
|
3235
|
+
break;
|
|
3236
|
+
}
|
|
3237
|
+
if (!moduleFactories.has(moduleId)) {
|
|
3238
|
+
const moduleFactoryFn = chunkModules[end];
|
|
3239
|
+
for (; i < end; i++) {
|
|
3240
|
+
moduleId = chunkModules[i];
|
|
3241
|
+
moduleFactories.set(moduleId, moduleFactoryFn);
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
i = end + 1;
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
|
|
3248
|
+
// \u5168\u5C40 _ENTRIES \u5BF9\u8C61
|
|
3249
|
+
globalThis._ENTRIES = globalThis._ENTRIES || {};
|
|
3250
|
+
|
|
3251
|
+
// \u4E3A chunk \u6587\u4EF6\u521B\u5EFA module \u5BF9\u8C61
|
|
3252
|
+
var module = (function() {
|
|
3253
|
+
let _exports = {};
|
|
3254
|
+
return {
|
|
3255
|
+
get exports() { return _exports; },
|
|
3256
|
+
set exports(value) {
|
|
3257
|
+
if (Array.isArray(value)) {
|
|
3258
|
+
installCompressedModuleFactories(value, 0);
|
|
3259
|
+
}
|
|
3260
|
+
_exports = value;
|
|
3261
|
+
}
|
|
3262
|
+
};
|
|
3263
|
+
})();
|
|
3264
|
+
|
|
3265
|
+
// ============================================================
|
|
3266
|
+
// Middleware \u8BF7\u6C42\u5904\u7406
|
|
3267
|
+
// ============================================================
|
|
3268
|
+
|
|
3269
|
+
// \u5B58\u50A8 middleware \u51FD\u6570
|
|
3270
|
+
let __middleware_fn__ = null;
|
|
3271
|
+
|
|
3272
|
+
/**
|
|
3273
|
+
* \u8FD0\u884C\u4E2D\u95F4\u4EF6\u7684\u4E3B\u51FD\u6570
|
|
3274
|
+
* @param {Request} request - \u539F\u59CB\u8BF7\u6C42\u5BF9\u8C61
|
|
3275
|
+
* @returns {Promise<Response|null|{__rewrite: string}>} - \u4E2D\u95F4\u4EF6\u5904\u7406\u540E\u7684\u54CD\u5E94\uFF0Cnull \u8868\u793A\u4E0D\u5904\u7406
|
|
3276
|
+
*/
|
|
3277
|
+
async function executeMiddleware({request}) {
|
|
3278
|
+
try {
|
|
3279
|
+
const url = new URL(request.url);
|
|
3280
|
+
|
|
3281
|
+
// \u5982\u679C\u8FD8\u6CA1\u6709\u52A0\u8F7D middleware\uFF0C\u5C1D\u8BD5\u52A0\u8F7D
|
|
3282
|
+
if (!__middleware_fn__) {
|
|
3283
|
+
// \u5C1D\u8BD5\u4ECE\u5165\u53E3\u6A21\u5757\u83B7\u53D6
|
|
3284
|
+
const entryModule = getOrInstantiateRuntimeModule('edge', ${entryModuleId || "86311"});
|
|
3285
|
+
|
|
3286
|
+
if (entryModule && entryModule.exports) {
|
|
3287
|
+
// Turbopack \u5BFC\u51FA\u7684 default \u53EF\u80FD\u662F\u4E00\u4E2A\u5305\u88C5\u51FD\u6570
|
|
3288
|
+
let exportedFn = entryModule.exports.default || entryModule.exports.middleware || entryModule.exports.proxy;
|
|
3289
|
+
|
|
3290
|
+
// \u5982\u679C\u5BFC\u51FA\u7684\u662F\u4E00\u4E2A\u5BF9\u8C61\uFF0C\u5C1D\u8BD5\u83B7\u53D6\u5176\u4E2D\u7684 handler \u6216 default
|
|
3291
|
+
if (exportedFn && typeof exportedFn === 'object') {
|
|
3292
|
+
exportedFn = exportedFn.handler || exportedFn.default || exportedFn.middleware || exportedFn.proxy;
|
|
3293
|
+
}
|
|
3294
|
+
|
|
3295
|
+
// \u5982\u679C\u662F\u51FD\u6570\uFF0C\u68C0\u67E5\u5B83\u662F\u5426\u662F middleware \u5305\u88C5\u5668
|
|
3296
|
+
if (typeof exportedFn === 'function') {
|
|
3297
|
+
__middleware_fn__ = exportedFn;
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3302
|
+
if (!__middleware_fn__ || typeof __middleware_fn__ !== 'function') {
|
|
3303
|
+
console.error('[Middleware] No middleware function found');
|
|
3304
|
+
return fetch(request);
|
|
3305
|
+
}
|
|
3306
|
+
|
|
3307
|
+
// \u5C1D\u8BD5\u83B7\u53D6 NextRequest \u7C7B\uFF08\u4ECE\u5DF2\u52A0\u8F7D\u7684\u6A21\u5757\u4E2D\uFF09
|
|
3308
|
+
let NextRequestClass = null;
|
|
3309
|
+
let NextResponseClass = null;
|
|
3310
|
+
|
|
3311
|
+
// \u67E5\u627E NextRequest \u548C NextResponse \u6A21\u5757
|
|
3312
|
+
for (const [moduleId, factory] of moduleFactories) {
|
|
3313
|
+
try {
|
|
3314
|
+
const mod = moduleCache[moduleId];
|
|
3315
|
+
if (mod && mod.exports) {
|
|
3316
|
+
if (mod.exports.NextRequest) {
|
|
3317
|
+
NextRequestClass = mod.exports.NextRequest;
|
|
3318
|
+
}
|
|
3319
|
+
if (mod.exports.NextResponse) {
|
|
3320
|
+
NextResponseClass = mod.exports.NextResponse;
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
} catch (e) {}
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3326
|
+
// \u5982\u679C\u6CA1\u6709\u627E\u5230 NextRequest\uFF0C\u5C1D\u8BD5\u5B9E\u4F8B\u5316\u53EF\u80FD\u5305\u542B\u5B83\u7684\u6A21\u5757
|
|
3327
|
+
if (!NextRequestClass) {
|
|
3328
|
+
// \u6A21\u5757 49779 \u901A\u5E38\u662F next/server \u7684\u5165\u53E3
|
|
3329
|
+
try {
|
|
3330
|
+
const nextServerModule = getOrInstantiateRuntimeModule('edge', 49779);
|
|
3331
|
+
if (nextServerModule && nextServerModule.exports) {
|
|
3332
|
+
NextRequestClass = nextServerModule.exports.NextRequest;
|
|
3333
|
+
NextResponseClass = nextServerModule.exports.NextResponse;
|
|
3334
|
+
}
|
|
3335
|
+
} catch (e) {}
|
|
3336
|
+
}
|
|
3337
|
+
|
|
3338
|
+
// \u6784\u9020\u8BF7\u6C42\u5BF9\u8C61
|
|
3339
|
+
let nextRequest;
|
|
3340
|
+
|
|
3341
|
+
if (NextRequestClass) {
|
|
3342
|
+
try {
|
|
3343
|
+
// NextRequest \u6784\u9020\u51FD\u6570\u7B7E\u540D: new NextRequest(input, init?)
|
|
3344
|
+
// input \u53EF\u4EE5\u662F URL \u5B57\u7B26\u4E32\u6216 Request \u5BF9\u8C61
|
|
3345
|
+
nextRequest = new NextRequestClass(request, {
|
|
3346
|
+
nextConfig: {}
|
|
3347
|
+
});
|
|
3348
|
+
} catch (e) {
|
|
3349
|
+
nextRequest = null;
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
// \u5982\u679C\u65E0\u6CD5\u521B\u5EFA NextRequest\uFF0C\u4F7F\u7528\u589E\u5F3A\u7684 Request
|
|
3354
|
+
if (!nextRequest) {
|
|
3355
|
+
nextRequest = new Request(request.url, {
|
|
3356
|
+
method: request.method,
|
|
3357
|
+
headers: request.headers,
|
|
3358
|
+
body: request.body,
|
|
3359
|
+
});
|
|
3360
|
+
|
|
3361
|
+
// \u6DFB\u52A0 nextUrl (\u6A21\u62DF NextURL)
|
|
3362
|
+
const parsedUrl = new URL(request.url);
|
|
3363
|
+
nextRequest.nextUrl = {
|
|
3364
|
+
href: parsedUrl.href,
|
|
3365
|
+
origin: parsedUrl.origin,
|
|
3366
|
+
protocol: parsedUrl.protocol,
|
|
3367
|
+
host: parsedUrl.host,
|
|
3368
|
+
hostname: parsedUrl.hostname,
|
|
3369
|
+
port: parsedUrl.port,
|
|
3370
|
+
pathname: parsedUrl.pathname,
|
|
3371
|
+
search: parsedUrl.search,
|
|
3372
|
+
searchParams: parsedUrl.searchParams,
|
|
3373
|
+
hash: parsedUrl.hash,
|
|
3374
|
+
toString: () => parsedUrl.href,
|
|
3375
|
+
clone: () => new URL(parsedUrl.href)
|
|
3376
|
+
};
|
|
3377
|
+
|
|
3378
|
+
// \u6DFB\u52A0 cookies API
|
|
3379
|
+
nextRequest.cookies = {
|
|
3380
|
+
get: (name) => {
|
|
3381
|
+
const cookies = request.headers.get('cookie') || '';
|
|
3382
|
+
const match = cookies.match(new RegExp('(^|;\\\\s*)' + name + '=([^;]*)'));
|
|
3383
|
+
return match ? { name, value: decodeURIComponent(match[2]) } : undefined;
|
|
3384
|
+
},
|
|
3385
|
+
getAll: () => {
|
|
3386
|
+
const cookies = request.headers.get('cookie') || '';
|
|
3387
|
+
return cookies.split(';').filter(c => c.trim()).map(c => {
|
|
3388
|
+
const [name, ...rest] = c.trim().split('=');
|
|
3389
|
+
return { name, value: decodeURIComponent(rest.join('=')) };
|
|
3390
|
+
});
|
|
3391
|
+
},
|
|
3392
|
+
has: (name) => {
|
|
3393
|
+
const cookies = request.headers.get('cookie') || '';
|
|
3394
|
+
return cookies.includes(name + '=');
|
|
3395
|
+
},
|
|
3396
|
+
set: () => {},
|
|
3397
|
+
delete: () => {}
|
|
3398
|
+
};
|
|
3399
|
+
|
|
3400
|
+
// \u6DFB\u52A0 geo \u548C ip
|
|
3401
|
+
nextRequest.geo = {};
|
|
3402
|
+
nextRequest.ip = request.headers.get('x-forwarded-for') || '';
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
// \u8BBE\u7F6E\u5168\u5C40 NextResponse\uFF08\u5982\u679C\u53EF\u7528\uFF09
|
|
3406
|
+
if (NextResponseClass) {
|
|
3407
|
+
globalThis.NextResponse = NextResponseClass;
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3410
|
+
// \u8C03\u7528 middleware
|
|
3411
|
+
// Turbopack \u7684 middleware \u5305\u88C5\u5668\u671F\u671B\u4E00\u4E2A\u7279\u6B8A\u7684\u53C2\u6570\u5BF9\u8C61
|
|
3412
|
+
|
|
3413
|
+
// \u6784\u9020 Turbopack \u671F\u671B\u7684\u8BF7\u6C42\u53C2\u6570
|
|
3414
|
+
// \u5173\u952E\uFF1ATurbopack \u7684 to \u51FD\u6570\u671F\u671B\uFF1A
|
|
3415
|
+
// 1. request.url \u662F\u53EF\u5199\u7684\uFF08\u4F1A\u6267\u884C t.request.url = t.request.url.replace(...)\uFF09
|
|
3416
|
+
// 2. request.headers \u662F\u666E\u901A\u5BF9\u8C61\uFF08\u4F1A\u6267\u884C Object.entries(t.request.headers)\uFF09
|
|
3417
|
+
// 3. request.nextConfig \u5B58\u5728\uFF08\u7528\u4E8E\u521B\u5EFA NextURL\uFF09
|
|
3418
|
+
|
|
3419
|
+
// \u5C06 Headers \u8F6C\u6362\u4E3A\u666E\u901A\u5BF9\u8C61
|
|
3420
|
+
const headersObj = {};
|
|
3421
|
+
request.headers.forEach((value, key) => {
|
|
3422
|
+
headersObj[key] = value;
|
|
3423
|
+
});
|
|
3424
|
+
|
|
3425
|
+
// \u521B\u5EFA\u4E00\u4E2A\u53EF\u5199\u7684 request \u5305\u88C5\u5BF9\u8C61
|
|
3426
|
+
const requestWrapper = {
|
|
3427
|
+
url: request.url,
|
|
3428
|
+
method: request.method,
|
|
3429
|
+
headers: headersObj, // \u5FC5\u987B\u662F\u666E\u901A\u5BF9\u8C61\uFF0Cto \u51FD\u6570\u4F1A\u7528 Object.entries() \u904D\u5386
|
|
3430
|
+
body: request.body,
|
|
3431
|
+
bodyUsed: request.bodyUsed,
|
|
3432
|
+
signal: request.signal,
|
|
3433
|
+
nextConfig: {}, // NextURL \u6784\u9020\u51FD\u6570\u9700\u8981\u8FD9\u4E2A
|
|
3434
|
+
// \u4FDD\u6301\u539F\u59CB Request \u7684\u65B9\u6CD5\u53EF\u7528
|
|
3435
|
+
clone: () => request.clone(),
|
|
3436
|
+
arrayBuffer: () => request.arrayBuffer(),
|
|
3437
|
+
blob: () => request.blob(),
|
|
3438
|
+
formData: () => request.formData(),
|
|
3439
|
+
json: () => request.json(),
|
|
3440
|
+
text: () => request.text(),
|
|
3441
|
+
};
|
|
3442
|
+
|
|
3443
|
+
const turbopackParams = {
|
|
3444
|
+
request: requestWrapper,
|
|
3445
|
+
page: '/',
|
|
3446
|
+
waitUntil: (promise) => {},
|
|
3447
|
+
bypassNextUrl: false
|
|
3448
|
+
};
|
|
3449
|
+
|
|
3450
|
+
let result;
|
|
3451
|
+
try {
|
|
3452
|
+
result = await __middleware_fn__(turbopackParams);
|
|
3453
|
+
} catch (e) {
|
|
3454
|
+
console.error('[Middleware] Turbopack call failed:', e.message, e.stack);
|
|
3455
|
+
throw e;
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
// Turbopack \u6A21\u5F0F\u8FD4\u56DE\u7684\u662F { response: Response, waitUntil: {} } \u683C\u5F0F
|
|
3459
|
+
// \u9700\u8981\u63D0\u53D6\u5B9E\u9645\u7684 Response \u5BF9\u8C61
|
|
3460
|
+
let finalResponse = result;
|
|
3461
|
+
if (result && typeof result === 'object' && !(result instanceof Response)) {
|
|
3462
|
+
if (result.response && result.response instanceof Response) {
|
|
3463
|
+
finalResponse = result.response;
|
|
3464
|
+
} else if (result.cookies && typeof result.cookies === 'object') {
|
|
3465
|
+
// \u53E6\u4E00\u79CD\u53EF\u80FD\u7684\u683C\u5F0F\uFF1A{ cookies: {...}, ... }
|
|
3466
|
+
// \u5C1D\u8BD5\u4ECE response \u5C5E\u6027\u83B7\u53D6
|
|
3467
|
+
if (result.response) {
|
|
3468
|
+
finalResponse = result.response;
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
|
|
3473
|
+
return finalResponse;
|
|
3474
|
+
|
|
3475
|
+
} catch (error) {
|
|
3476
|
+
console.error('[Middleware Error]', error);
|
|
3477
|
+
return new Response(
|
|
3478
|
+
JSON.stringify({ error: 'Middleware execution failed', message: error.message }),
|
|
3479
|
+
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
|
3480
|
+
);
|
|
3481
|
+
}
|
|
3482
|
+
}`;
|
|
3483
|
+
}
|
|
3484
|
+
async function compile(inputPath, options = {}) {
|
|
3485
|
+
const warnings = [];
|
|
3486
|
+
const errors = [];
|
|
3487
|
+
const absoluteInputPath = resolve(inputPath);
|
|
3488
|
+
if (!existsSync(absoluteInputPath)) {
|
|
3489
|
+
errors.push(`Input file not found: ${absoluteInputPath}`);
|
|
3490
|
+
return { code: "", warnings, errors };
|
|
3491
|
+
}
|
|
3492
|
+
let middlewareCode;
|
|
3493
|
+
try {
|
|
3494
|
+
middlewareCode = readFileSync(absoluteInputPath, "utf-8");
|
|
3495
|
+
} catch (err) {
|
|
3496
|
+
errors.push(`Failed to read input file: ${err}`);
|
|
3497
|
+
return { code: "", warnings, errors };
|
|
3498
|
+
}
|
|
3499
|
+
const buildType = detectBuildType(middlewareCode);
|
|
3500
|
+
if (buildType === "turbopack") {
|
|
3501
|
+
return compileTurbopack(absoluteInputPath, middlewareCode, options);
|
|
3502
|
+
}
|
|
3503
|
+
const isRawSource = buildType === "raw";
|
|
3504
|
+
if (isRawSource) {
|
|
3505
|
+
try {
|
|
3506
|
+
middlewareCode = await transformSourceCode(middlewareCode, absoluteInputPath);
|
|
3507
|
+
} catch (err) {
|
|
3508
|
+
errors.push(`Failed to transform source code: ${err}`);
|
|
3509
|
+
return { code: "", warnings, errors };
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
const middlewareEntry = detectMiddlewareEntry(middlewareCode);
|
|
3513
|
+
const config = extractMiddlewareConfig(middlewareCode);
|
|
3514
|
+
middlewareCode = transformRequires(middlewareCode);
|
|
3515
|
+
middlewareCode = fixEdgeOneCompatibility(middlewareCode);
|
|
3516
|
+
middlewareCode = transformForEdgeOneRuntime(middlewareCode);
|
|
3517
|
+
middlewareCode = fixWebpackConfigExport(middlewareCode);
|
|
3518
|
+
const polyfillsCode = getPolyfillsCode();
|
|
3519
|
+
const compatCode = isRawSource ? "" : getCompatCode();
|
|
3520
|
+
const wrapperCode = getEdgeOneWrapperCode({
|
|
3521
|
+
middlewareEntry,
|
|
3522
|
+
debug: options.env?.DEBUG === "true",
|
|
3523
|
+
isRawSource
|
|
3524
|
+
});
|
|
3525
|
+
let envCode = "";
|
|
3526
|
+
if (options.env) {
|
|
3527
|
+
const envEntries = Object.entries(options.env).map(([key, value]) => `process.env[${JSON.stringify(key)}] = ${JSON.stringify(value)};`).join("\n");
|
|
3528
|
+
envCode = `
|
|
3529
|
+
// === Environment Variables ===
|
|
3530
|
+
${envEntries}
|
|
3531
|
+
`;
|
|
3532
|
+
}
|
|
3533
|
+
const outputCode = `
|
|
3534
|
+
// ============================================================
|
|
3535
|
+
// Next.js Middleware compiled for EdgeOne Pages Edge Function
|
|
3536
|
+
// Generated at: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
3537
|
+
// ============================================================
|
|
3538
|
+
|
|
3539
|
+
${polyfillsCode}
|
|
3540
|
+
|
|
3541
|
+
${compatCode}
|
|
3542
|
+
|
|
3543
|
+
${envCode}
|
|
3544
|
+
|
|
3545
|
+
// ============================================================
|
|
3546
|
+
// Original Next.js Middleware Code
|
|
3547
|
+
// ============================================================
|
|
3548
|
+
|
|
3549
|
+
${middlewareCode}
|
|
3550
|
+
|
|
3551
|
+
${wrapperCode}
|
|
3552
|
+
`;
|
|
3553
|
+
let finalCode = outputCode;
|
|
3554
|
+
if (options.minify) {
|
|
3555
|
+
warnings.push("Minification is not implemented yet, outputting unminified code");
|
|
3556
|
+
}
|
|
3557
|
+
return {
|
|
3558
|
+
code: finalCode,
|
|
3559
|
+
warnings,
|
|
3560
|
+
errors
|
|
3561
|
+
};
|
|
3562
|
+
}
|
|
3563
|
+
async function compileToFile(inputPath, outputPath, options = {}) {
|
|
3564
|
+
const result = await compile(inputPath, options);
|
|
3565
|
+
if (result.errors.length > 0) {
|
|
3566
|
+
return result;
|
|
3567
|
+
}
|
|
3568
|
+
try {
|
|
3569
|
+
writeFileSync(outputPath, result.code, "utf-8");
|
|
3570
|
+
} catch (err) {
|
|
3571
|
+
result.errors.push(`Failed to write output file: ${err}`);
|
|
3572
|
+
}
|
|
3573
|
+
return result;
|
|
3574
|
+
}
|
|
3575
|
+
var compiler_default = { compile, compileToFile };
|
|
3576
|
+
export {
|
|
3577
|
+
compile,
|
|
3578
|
+
compileToFile,
|
|
3579
|
+
compiler_default as default
|
|
3580
|
+
};
|