@aziontech/bundler 1.1.4 → 1.2.0
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/README.md +31 -0
- package/dist/index-Dx9B4Utx.js +2290 -0
- package/dist/index.js +93 -58
- package/dist/utils-CSEkDVys.js +399 -0
- package/package.json +7 -7
- package/dist/index-CgialJ1S.js +0 -2165
- package/dist/utils-B43tliMf.js +0 -377
package/dist/index-CgialJ1S.js
DELETED
|
@@ -1,2165 +0,0 @@
|
|
|
1
|
-
import { fetchContext as Ne, FirewallEventContext as Ie, FetchEventContext as Be, AsyncHooksContext as de, StorageContext as De, EnvVarsContext as We, NetworkListContext as Me, fsContext as Le, streamContext as He, cryptoContext as Ve, promisesContext as ze, KVContext as Ge } from "@aziontech/builder/polyfills";
|
|
2
|
-
import { load as qe } from "@edge-runtime/primitives/dist/load.js";
|
|
3
|
-
import { D as C, p as Ke, u as Je, d as g, S as pe, B as F, r as Xe, a as Ye, b as _, m as Ze, e as Qe, c as et, w as tt, f as U, T as R, g as oe, h as te, i as Se, j as rt, k as $e } from "./utils-B43tliMf.js";
|
|
4
|
-
import * as O from "@aziontech/utils/node";
|
|
5
|
-
import { getPackageManager as nt, feedback as p } from "@aziontech/utils/node";
|
|
6
|
-
import st from "chokidar";
|
|
7
|
-
import { runPhaseWithTelemetry as x, TelemetryCollector as ot, formatHeader as it, formatBuildConfig as at } from "@aziontech/bundler-telemetry";
|
|
8
|
-
import { validateConfig as re, processConfig as ct, convertJsonConfigToObject as lt } from "@aziontech/config";
|
|
9
|
-
import h, { rm as ie, mkdir as Pe, readFile as ft, stat as ut, writeFile as dt } from "fs/promises";
|
|
10
|
-
import S, { resolve as ae, join as k, relative as ne, basename as V, extname as I, dirname as xe } from "path";
|
|
11
|
-
import X from "os";
|
|
12
|
-
import { executeESBuildBuild as pt, executeWebpackBuild as mt, createAzionWebpackConfig as ht, createAzionESBuildConfig as gt } from "@aziontech/builder";
|
|
13
|
-
import yt from "lodash";
|
|
14
|
-
import me, { existsSync as ke, readFileSync as wt, promises as z } from "fs";
|
|
15
|
-
import { runInContext as ce } from "vm";
|
|
16
|
-
import { pathToFileURL as bt } from "url";
|
|
17
|
-
import D from "node:vm";
|
|
18
|
-
import Et from "net";
|
|
19
|
-
import { runServer as vt } from "edge-runtime";
|
|
20
|
-
import * as J from "@aziontech/presets";
|
|
21
|
-
import { listFrameworks as Tt } from "@netlify/framework-info";
|
|
22
|
-
import * as Ce from "prettier";
|
|
23
|
-
import { cosmiconfig as St } from "cosmiconfig";
|
|
24
|
-
import { TypeScriptLoader as Y } from "cosmiconfig-typescript-loader";
|
|
25
|
-
class $t {
|
|
26
|
-
context;
|
|
27
|
-
constructor(t = {}) {
|
|
28
|
-
const r = D.createContext(
|
|
29
|
-
{},
|
|
30
|
-
{
|
|
31
|
-
name: "Edge Runtime",
|
|
32
|
-
codeGeneration: t.codeGeneration ?? {
|
|
33
|
-
strings: !1,
|
|
34
|
-
wasm: !0
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
this.context = t.extend?.(r) ?? r;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Allows to run arbitrary code within the VM.
|
|
42
|
-
*/
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
-
evaluate(t) {
|
|
45
|
-
return D.runInContext(t, this.context, {
|
|
46
|
-
importModuleDynamically: async (r) => {
|
|
47
|
-
try {
|
|
48
|
-
return await import(bt(ae(r)).href);
|
|
49
|
-
} catch {
|
|
50
|
-
process.env.DEBUG && console.warn(
|
|
51
|
-
">>> [edge-runtime] dynamic import failed, returning empty module:",
|
|
52
|
-
r
|
|
53
|
-
);
|
|
54
|
-
const n = new D.SourceTextModule("export default {}", { context: this.context });
|
|
55
|
-
return await n.link(() => new D.SourceTextModule("export {}", { context: this.context })), await n.evaluate(), n;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
let G, q;
|
|
63
|
-
class Pt extends $t {
|
|
64
|
-
dispatchFetch;
|
|
65
|
-
constructor(t) {
|
|
66
|
-
super({
|
|
67
|
-
...t,
|
|
68
|
-
extend: (r) => t?.extend ? t.extend(he(r)) : he(r)
|
|
69
|
-
}), Object.defineProperty(this.context, "__onUnhandledRejectionHandlers", {
|
|
70
|
-
set: kt,
|
|
71
|
-
configurable: !1,
|
|
72
|
-
enumerable: !1
|
|
73
|
-
}), Object.defineProperty(this, "__rejectionHandlers", {
|
|
74
|
-
get: () => G,
|
|
75
|
-
configurable: !1,
|
|
76
|
-
enumerable: !1
|
|
77
|
-
}), Object.defineProperty(this.context, "__onErrorHandlers", {
|
|
78
|
-
set: Ct,
|
|
79
|
-
configurable: !1,
|
|
80
|
-
enumerable: !1
|
|
81
|
-
}), Object.defineProperty(this, "__errorHandlers", {
|
|
82
|
-
get: () => q,
|
|
83
|
-
configurable: !1,
|
|
84
|
-
enumerable: !1
|
|
85
|
-
}), this.evaluate(Ft()), this.dispatchFetch = this.evaluate(At());
|
|
86
|
-
for (const r of Fe)
|
|
87
|
-
xt(r, this.context);
|
|
88
|
-
t?.initialCode && this.evaluate(t.initialCode);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const Fe = [
|
|
92
|
-
"Object",
|
|
93
|
-
"Array",
|
|
94
|
-
"RegExp",
|
|
95
|
-
"Uint8Array",
|
|
96
|
-
"ArrayBuffer",
|
|
97
|
-
"Error",
|
|
98
|
-
"SyntaxError",
|
|
99
|
-
"TypeError"
|
|
100
|
-
];
|
|
101
|
-
function xt(e, t) {
|
|
102
|
-
const r = eval;
|
|
103
|
-
return t[/* @__PURE__ */ Symbol.for(`node:${e}`)] = r(e), ce(
|
|
104
|
-
`
|
|
105
|
-
globalThis.${e} = new Proxy(${e}, {
|
|
106
|
-
get(target, prop, receiver) {
|
|
107
|
-
if (prop === Symbol.hasInstance && receiver === globalThis.${e}) {
|
|
108
|
-
const nodeTarget = globalThis[Symbol.for('node:${e}')];
|
|
109
|
-
if (nodeTarget) {
|
|
110
|
-
return function(instance) {
|
|
111
|
-
return instance instanceof target || instance instanceof nodeTarget;
|
|
112
|
-
};
|
|
113
|
-
} else {
|
|
114
|
-
throw new Error('node target must exist')
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return Reflect.get(target, prop, receiver);
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
`,
|
|
122
|
-
t
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
function kt(e) {
|
|
126
|
-
G || process.on("unhandledRejection", function(r, n) {
|
|
127
|
-
G.forEach((o) => o({ reason: r, promise: n }));
|
|
128
|
-
}), G = e;
|
|
129
|
-
}
|
|
130
|
-
function Ct(e) {
|
|
131
|
-
q || process.on("uncaughtException", function(r) {
|
|
132
|
-
q.forEach((n) => n(r));
|
|
133
|
-
}), q = e;
|
|
134
|
-
}
|
|
135
|
-
function Ft() {
|
|
136
|
-
return `
|
|
137
|
-
Object.defineProperty(self, '__listeners', {
|
|
138
|
-
configurable: false,
|
|
139
|
-
enumerable: false,
|
|
140
|
-
value: {},
|
|
141
|
-
writable: true,
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
function __conditionallyUpdatesHandlerList(eventType) {
|
|
145
|
-
if (eventType === 'unhandledrejection') {
|
|
146
|
-
self.__onUnhandledRejectionHandlers = self.__listeners[eventType];
|
|
147
|
-
} else if (eventType === 'error') {
|
|
148
|
-
self.__onErrorHandlers = self.__listeners[eventType];
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function addEventListener(type, handler) {
|
|
153
|
-
const eventType = type.toLowerCase();
|
|
154
|
-
if (eventType === 'fetch' && self.__listeners.fetch) {
|
|
155
|
-
throw new TypeError('You can register just one "fetch" event listener');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
self.__listeners[eventType] = self.__listeners[eventType] || [];
|
|
159
|
-
self.__listeners[eventType].push(handler);
|
|
160
|
-
__conditionallyUpdatesHandlerList(eventType);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function removeEventListener(type, handler) {
|
|
164
|
-
const eventType = type.toLowerCase();
|
|
165
|
-
if (self.__listeners[eventType]) {
|
|
166
|
-
self.__listeners[eventType] = self.__listeners[eventType].filter(item => {
|
|
167
|
-
return item !== handler;
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
if (self.__listeners[eventType].length === 0) {
|
|
171
|
-
delete self.__listeners[eventType];
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
__conditionallyUpdatesHandlerList(eventType);
|
|
175
|
-
}
|
|
176
|
-
`;
|
|
177
|
-
}
|
|
178
|
-
function At() {
|
|
179
|
-
return `(async function dispatchFetch(input, init) {
|
|
180
|
-
const request = new Request(input, init);
|
|
181
|
-
const event = new FetchEvent(request);
|
|
182
|
-
if (!self.__listeners.fetch) {
|
|
183
|
-
throw new Error("No fetch event listeners found");
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const getResponse = ({ response, error }) => {
|
|
187
|
-
if (error || !response || !(response instanceof Response)) {
|
|
188
|
-
console.error(error ? error.toString() : 'The event listener did not respond')
|
|
189
|
-
response = new Response(null, {
|
|
190
|
-
statusText: 'Internal Server Error',
|
|
191
|
-
status: 500
|
|
192
|
-
})
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
response.waitUntil = () => Promise.all(event.awaiting);
|
|
196
|
-
|
|
197
|
-
if (response.status < 300 || response.status >= 400 ) {
|
|
198
|
-
response.headers.delete('content-encoding');
|
|
199
|
-
response.headers.delete('transform-encoding');
|
|
200
|
-
response.headers.delete('content-length');
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return response;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
try {
|
|
207
|
-
await self.__listeners.fetch[0].call(event, event)
|
|
208
|
-
} catch (error) {
|
|
209
|
-
return getResponse({ error })
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return Promise.resolve(event.response)
|
|
213
|
-
.then(response => getResponse({ response }))
|
|
214
|
-
.catch(error => getResponse({ error }))
|
|
215
|
-
})`;
|
|
216
|
-
}
|
|
217
|
-
function he(e) {
|
|
218
|
-
A(e, "self", { enumerable: !0, value: e }), A(e, "globalThis", { value: e }), A(e, "Symbol", { value: Symbol }), A(e, "clearInterval", { value: clearInterval }), A(e, "clearTimeout", { value: clearTimeout }), A(e, "queueMicrotask", { value: queueMicrotask }), A(e, "EdgeRuntime", { value: "edge-runtime" });
|
|
219
|
-
const t = _t(e);
|
|
220
|
-
return Ot(e, {
|
|
221
|
-
exports: qe({
|
|
222
|
-
...t,
|
|
223
|
-
WeakRef: ce("WeakRef", e)
|
|
224
|
-
}),
|
|
225
|
-
enumerable: ["crypto"],
|
|
226
|
-
nonenumerable: [
|
|
227
|
-
// Crypto
|
|
228
|
-
"Crypto",
|
|
229
|
-
"CryptoKey",
|
|
230
|
-
"SubtleCrypto",
|
|
231
|
-
// Fetch APIs
|
|
232
|
-
"fetch",
|
|
233
|
-
"File",
|
|
234
|
-
"FormData",
|
|
235
|
-
"Headers",
|
|
236
|
-
"Request",
|
|
237
|
-
"Response",
|
|
238
|
-
"WebSocket",
|
|
239
|
-
// Structured Clone
|
|
240
|
-
"structuredClone",
|
|
241
|
-
// Blob
|
|
242
|
-
"Blob",
|
|
243
|
-
// URL
|
|
244
|
-
"URL",
|
|
245
|
-
"URLSearchParams",
|
|
246
|
-
"URLPattern",
|
|
247
|
-
// AbortController
|
|
248
|
-
"AbortController",
|
|
249
|
-
"AbortSignal",
|
|
250
|
-
"DOMException",
|
|
251
|
-
// Streams
|
|
252
|
-
"ReadableStream",
|
|
253
|
-
"ReadableStreamBYOBReader",
|
|
254
|
-
"ReadableStreamDefaultReader",
|
|
255
|
-
"TextDecoderStream",
|
|
256
|
-
"TextEncoderStream",
|
|
257
|
-
"TransformStream",
|
|
258
|
-
"WritableStream",
|
|
259
|
-
"WritableStreamDefaultWriter",
|
|
260
|
-
// Encoding
|
|
261
|
-
"atob",
|
|
262
|
-
"btoa",
|
|
263
|
-
"TextEncoder",
|
|
264
|
-
"TextDecoder",
|
|
265
|
-
// Events
|
|
266
|
-
"Event",
|
|
267
|
-
"EventTarget",
|
|
268
|
-
"FetchEvent",
|
|
269
|
-
"PromiseRejectionEvent",
|
|
270
|
-
// Console
|
|
271
|
-
"console",
|
|
272
|
-
// Timers
|
|
273
|
-
"setTimeout",
|
|
274
|
-
"setInterval"
|
|
275
|
-
]
|
|
276
|
-
}), e;
|
|
277
|
-
}
|
|
278
|
-
function A(e, t, r) {
|
|
279
|
-
Object.defineProperty(e, t, {
|
|
280
|
-
configurable: r.configurable ?? !1,
|
|
281
|
-
enumerable: r.enumerable ?? !1,
|
|
282
|
-
value: r.value,
|
|
283
|
-
writable: r.writable ?? !0
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
function Ot(e, t) {
|
|
287
|
-
for (const r of t.enumerable ?? []) {
|
|
288
|
-
if (!t.exports[r])
|
|
289
|
-
throw new Error(`Attempt to export a nullable value for "${r}"`);
|
|
290
|
-
A(e, r, {
|
|
291
|
-
enumerable: !0,
|
|
292
|
-
value: t.exports[r]
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
for (const r of t.nonenumerable ?? []) {
|
|
296
|
-
if (!t.exports[r])
|
|
297
|
-
throw new Error(`Attempt to export a nullable value for "${r}"`);
|
|
298
|
-
A(e, r, {
|
|
299
|
-
value: t.exports[r]
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
function _t(e) {
|
|
304
|
-
const r = `({${Fe.join(",")}})`;
|
|
305
|
-
return ce(r, e);
|
|
306
|
-
}
|
|
307
|
-
function jt() {
|
|
308
|
-
const e = k(process.cwd(), C.OUTPUT_ENV_VARS_PATH);
|
|
309
|
-
if (!ke(e)) return { ...process.env };
|
|
310
|
-
const t = wt(e, "utf-8");
|
|
311
|
-
return Object.fromEntries(
|
|
312
|
-
Ke(t).map(({ key: r, value: n }) => [r, Je(n)])
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
function Ae(e, t = !1) {
|
|
316
|
-
const r = /switch \((\w+)\) \{\n(\s+)case Object:/g;
|
|
317
|
-
e = e.replace(r, (s, i, c) => `if (${i} != null && ${i} !== Object && ${i}.name === "Object") ${i} = Object;
|
|
318
|
-
${c}` + s);
|
|
319
|
-
const n = (s) => (s.RESERVED_FETCH = s.fetch.bind(s), s.fetch = async (i, c) => Ne(
|
|
320
|
-
s,
|
|
321
|
-
i,
|
|
322
|
-
c,
|
|
323
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
324
|
-
globalThis?.AZION_BUCKET_NAME,
|
|
325
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
326
|
-
globalThis?.AZION_BUCKET_PREFIX
|
|
327
|
-
), s.FetchEvent = t ? Ie : Be, s.Response = t ? Response : s.Response, s.eval = eval, s.process = { env: jt() }, s.File = void 0, s.WebSocket = void 0, s.ASYNC_LOCAL_STORAGE = de, s.AsyncLocalStorage = de.AsyncLocalStorage, s.STORAGE_CONTEXT = De, s.ENV_VARS_CONTEXT = We, s.NETWORK_LIST_CONTEXT = Me, s.FS_CONTEXT = Le, s.STREAM_CONTEXT = He, s.CRYPTO_CONTEXT = Ve, s.TextDecoderStream = TextDecoderStream, s.TextEncoderStream = TextEncoderStream, s.perfomance = { now: performance.now }, s.CompressionStream = CompressionStream, s.CountQueuingStrategy = CountQueuingStrategy, s.DecompressionStream = DecompressionStream, s.Promise = Promise, s.Promise.withResolvers = ze, s.KV_CONTEXT = Ge, s);
|
|
328
|
-
return new Pt({ extend: n, initialCode: e, codeGeneration: { strings: !0 } });
|
|
329
|
-
}
|
|
330
|
-
class Oe extends Error {
|
|
331
|
-
constructor(t, r) {
|
|
332
|
-
super(t), this.code = r, this.name = "PackageJsonError";
|
|
333
|
-
}
|
|
334
|
-
code;
|
|
335
|
-
}
|
|
336
|
-
class Ut extends Error {
|
|
337
|
-
constructor(t) {
|
|
338
|
-
super(`Please install dependencies using ${t}`), this.name = "DependenciesError";
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
const Rt = async () => {
|
|
342
|
-
const e = k(process.cwd(), "package.json");
|
|
343
|
-
try {
|
|
344
|
-
const t = await ft(e, "utf8");
|
|
345
|
-
return JSON.parse(t);
|
|
346
|
-
} catch (t) {
|
|
347
|
-
throw new Oe("Failed to read package.json", t.code);
|
|
348
|
-
}
|
|
349
|
-
}, Nt = async () => {
|
|
350
|
-
const e = k(process.cwd(), "node_modules");
|
|
351
|
-
try {
|
|
352
|
-
return (await ut(e)).isDirectory();
|
|
353
|
-
} catch {
|
|
354
|
-
return !1;
|
|
355
|
-
}
|
|
356
|
-
}, It = async () => {
|
|
357
|
-
let e;
|
|
358
|
-
try {
|
|
359
|
-
e = await Rt();
|
|
360
|
-
} catch (t) {
|
|
361
|
-
if (t instanceof Oe && t.code === "ENOENT")
|
|
362
|
-
return;
|
|
363
|
-
throw t;
|
|
364
|
-
}
|
|
365
|
-
if (e && (e.dependencies || e.devDependencies)) {
|
|
366
|
-
const t = await nt();
|
|
367
|
-
if (!await Nt())
|
|
368
|
-
throw new Ut(t);
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
function W({
|
|
372
|
-
inputValue: e,
|
|
373
|
-
fileValue: t,
|
|
374
|
-
storeValue: r,
|
|
375
|
-
defaultValue: n
|
|
376
|
-
}) {
|
|
377
|
-
return ((i) => i === "true" ? !0 : i === "false" ? !1 : i)(e ?? t ?? r ?? n);
|
|
378
|
-
}
|
|
379
|
-
const Bt = (e, t) => {
|
|
380
|
-
const r = Object.keys(e).map((s) => {
|
|
381
|
-
const c = (s.endsWith(".js") ? s : `${s}.js`).replace(/\.dev\.js$/, ".js");
|
|
382
|
-
return `./${ne(C.OUTPUT_BASE_PATH, c)}`;
|
|
383
|
-
}), n = (t ?? []).map((s, i) => ({ func: s, index: i })).filter(({ func: s }) => s.path && !r.includes(s.path));
|
|
384
|
-
if (n.length === 0) return;
|
|
385
|
-
const o = n.map(({ func: s, index: i }) => {
|
|
386
|
-
const c = s.path, a = r[i];
|
|
387
|
-
if (a)
|
|
388
|
-
return ` - functions[${i}] ("${s.name}"): configured path "${c}" does not match generated output "${k(C.OUTPUT_BASE_PATH, a)}". Update the path to "${a}" in azion.config`;
|
|
389
|
-
const l = r.map((f) => `"${f}"`).join(", ");
|
|
390
|
-
return ` - functions[${i}] ("${s.name}"): configured path "${c}" does not match any generated output. Update the path in azion.config to one of: ${l}`;
|
|
391
|
-
}).join(`
|
|
392
|
-
`);
|
|
393
|
-
throw new Error(
|
|
394
|
-
`The "path" declared for the following function(s) in azion.config does not match the file(s) generated by the build:
|
|
395
|
-
${o}`
|
|
396
|
-
);
|
|
397
|
-
}, Dt = async (e) => {
|
|
398
|
-
try {
|
|
399
|
-
await Promise.all(
|
|
400
|
-
e.map(async (t) => {
|
|
401
|
-
try {
|
|
402
|
-
await ie(t, { recursive: !0, force: !0 });
|
|
403
|
-
} catch (r) {
|
|
404
|
-
if (r.code !== "ENOENT")
|
|
405
|
-
throw r;
|
|
406
|
-
}
|
|
407
|
-
await Pe(t, { recursive: !0 });
|
|
408
|
-
})
|
|
409
|
-
);
|
|
410
|
-
} catch (t) {
|
|
411
|
-
throw new Error(`Failed to clean directories: ${t}`);
|
|
412
|
-
}
|
|
413
|
-
}, Wt = (e) => `//---
|
|
414
|
-
//storages:
|
|
415
|
-
// - name: assets
|
|
416
|
-
// bucket: ${e.bucket}
|
|
417
|
-
// prefix: ${e.prefix}
|
|
418
|
-
//---
|
|
419
|
-
/* this temporary binding is used to inject the storage name and prefix into the function file */
|
|
420
|
-
globalThis.AZION_BUCKET_NAME = '${e.bucket}';
|
|
421
|
-
globalThis.AZION_BUCKET_PREFIX = '${e.prefix}';`, Mt = async (e) => {
|
|
422
|
-
try {
|
|
423
|
-
return await h.access(e), !0;
|
|
424
|
-
} catch {
|
|
425
|
-
return !1;
|
|
426
|
-
}
|
|
427
|
-
}, Lt = (e) => S.isAbsolute(e) ? e : S.resolve(process.cwd(), C.OUTPUT_BASE_PATH, e), Ht = (e, t) => t.find((r) => r.name === e), Vt = async (e, t, r) => {
|
|
428
|
-
if (!e.path) {
|
|
429
|
-
g.warn(`Function ${e.name} does not have a defined path`);
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
const n = e.bindings?.storage;
|
|
433
|
-
if (!n) {
|
|
434
|
-
g.info(`Function ${e.name} does not have storage bindings`);
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
const o = Lt(
|
|
438
|
-
e.path.replace(/\.js$/, r ? ".js" : ".dev.js")
|
|
439
|
-
);
|
|
440
|
-
if (!await Mt(o)) {
|
|
441
|
-
p.bindings.warn(`Function file not found: ${o}.`), p.bindings.info(`Binding injection skipped for function ${e.name}`);
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
try {
|
|
445
|
-
const s = await h.readFile(o, "utf-8");
|
|
446
|
-
if (s.includes("//storages:") || s.includes("//---")) {
|
|
447
|
-
g.info(`Function ${e.name} already has injected bindings`);
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
const i = String(n.bucket), c = Ht(i, t);
|
|
451
|
-
if (!c) {
|
|
452
|
-
g.warn(`Storage '${i}' not found for function ${e.name}`);
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
const a = n.prefix, l = a || c.prefix;
|
|
456
|
-
a || p.postbuild.info(
|
|
457
|
-
`No prefix provided for binding in function '${e.name}', using storage prefix: ${l}`
|
|
458
|
-
);
|
|
459
|
-
const f = Wt({
|
|
460
|
-
bucket: i,
|
|
461
|
-
prefix: l
|
|
462
|
-
});
|
|
463
|
-
g.info(`Generated binding template for ${e.name}: ${f}`);
|
|
464
|
-
const u = `${f}
|
|
465
|
-
${s}`;
|
|
466
|
-
await h.writeFile(o, u), g.info(`Bindings injected into ${o} for function ${e.name}`);
|
|
467
|
-
} catch (s) {
|
|
468
|
-
throw g.error(`Failed to process bindings for function ${e.name}:`, s), s;
|
|
469
|
-
}
|
|
470
|
-
}, zt = async ({
|
|
471
|
-
config: e,
|
|
472
|
-
storageSetup: t,
|
|
473
|
-
isProduction: r
|
|
474
|
-
}) => {
|
|
475
|
-
try {
|
|
476
|
-
const n = e.functions || [];
|
|
477
|
-
if (n.length === 0) {
|
|
478
|
-
g.info("No functions found to inject bindings");
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
g.info("Injecting bindings into functions..."), await Promise.all(
|
|
482
|
-
n.map((o) => Vt(o, t, r))
|
|
483
|
-
);
|
|
484
|
-
} catch (n) {
|
|
485
|
-
return g.error("Failed to execute bindings setup:", n), Promise.reject(n);
|
|
486
|
-
}
|
|
487
|
-
}, Gt = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10).replace(/-/g, ""), qt = async ({
|
|
488
|
-
entry: e,
|
|
489
|
-
ext: t = "js",
|
|
490
|
-
basePath: r = ".edge/functions",
|
|
491
|
-
production: n = !0,
|
|
492
|
-
bundler: o
|
|
493
|
-
}) => {
|
|
494
|
-
const s = Gt(), i = (c, a) => {
|
|
495
|
-
const l = V(c, I(c)), f = xe(c), u = `azion-${l}-${s}.temp.${t}`, m = ae(f, u), w = o === "webpack" ? ".js" : "", d = n ? "" : ".dev";
|
|
496
|
-
let y;
|
|
497
|
-
if (a) {
|
|
498
|
-
const T = a.replace(/\.[^/.]+$/, "");
|
|
499
|
-
y = k(r, `${T}${d}${w}`);
|
|
500
|
-
} else
|
|
501
|
-
y = k(r, f, `${l}${d}${w}`);
|
|
502
|
-
return { [y]: m };
|
|
503
|
-
};
|
|
504
|
-
if (typeof e == "string") {
|
|
505
|
-
const a = `${V(e, I(e))}${n ? "" : ".dev"}`;
|
|
506
|
-
return { ...i(e, a) };
|
|
507
|
-
}
|
|
508
|
-
return Array.isArray(e) ? e.reduce((c, a) => {
|
|
509
|
-
const f = `${V(a, I(a))}${n ? "" : ".dev"}`;
|
|
510
|
-
return { ...c, ...i(a, f) };
|
|
511
|
-
}, {}) : Object.entries(e).reduce(
|
|
512
|
-
(c, [a, l]) => ({ ...c, ...i(l, a) }),
|
|
513
|
-
{}
|
|
514
|
-
);
|
|
515
|
-
}, Kt = async (e, t, r) => {
|
|
516
|
-
let n = {};
|
|
517
|
-
const o = e.build?.entry, s = async (i) => await qt({
|
|
518
|
-
entry: i,
|
|
519
|
-
ext: t.metadata.ext ?? F.DEFAULT_OUTPUT_EXTENSION,
|
|
520
|
-
production: r,
|
|
521
|
-
bundler: e.build?.bundler ?? t.config.build?.bundler ?? pe.DEFAULT
|
|
522
|
-
});
|
|
523
|
-
if (o ? n = await s(o) : t.config.build?.entry ? n = await s(t.config.build.entry) : t.handler && (n = await s(F.DEFAULT_HANDLER_FILENAME)), Object.keys(n).length === 0) {
|
|
524
|
-
const i = t.config.build?.entry ? `(default is "${t.config.build.entry}")` : "";
|
|
525
|
-
throw new Error(
|
|
526
|
-
`No entry point found ${i}. Please specify one using --entry or create a default entry file in your project.`
|
|
527
|
-
);
|
|
528
|
-
}
|
|
529
|
-
return {
|
|
530
|
-
...e.build,
|
|
531
|
-
entry: n,
|
|
532
|
-
bundler: e.build?.bundler ?? t.config.build?.bundler ?? pe.DEFAULT,
|
|
533
|
-
preset: t,
|
|
534
|
-
setup: {
|
|
535
|
-
contentToInject: void 0,
|
|
536
|
-
defineVars: {}
|
|
537
|
-
},
|
|
538
|
-
polyfills: !!e.build?.polyfills
|
|
539
|
-
};
|
|
540
|
-
}, Jt = (e, t) => gt(e, t), Xt = (e, t) => ht(e, t), Yt = async (e) => pt(e), Zt = async (e) => mt(e), M = {
|
|
541
|
-
createAzionESBuildConfigWrapper: Jt,
|
|
542
|
-
createAzionWebpackConfigWrapper: Xt,
|
|
543
|
-
executeESBuildBuildWrapper: Yt,
|
|
544
|
-
executeWebpackBuildWrapper: Zt
|
|
545
|
-
}, Qt = (e) => {
|
|
546
|
-
const t = /import\s+.*?from\s*['"](.*?)['"];?/g, r = /(const\s+.*?=\s*require\(.*\).*);/g, n = (e.match(t) || []).map((i) => i.trim()), o = (e.match(r) || []).map((i) => i.trim());
|
|
547
|
-
let s = e.replace(t, "").replace(r, "").replace(/\n\s*\n\s*\n/g, `
|
|
548
|
-
|
|
549
|
-
`);
|
|
550
|
-
return (n.length || o.length) && (s = `${[...n, ...o].join(`
|
|
551
|
-
`)}
|
|
552
|
-
|
|
553
|
-
${s.trim()}`), s;
|
|
554
|
-
}, er = (e, t, r) => t.polyfills && r.production ? `import SRC_NODE_FS from "node:fs";
|
|
555
|
-
${e}` : e, L = async (e, t, r, n, o, s) => !e || !t ? s() : x(
|
|
556
|
-
e,
|
|
557
|
-
t,
|
|
558
|
-
r,
|
|
559
|
-
n,
|
|
560
|
-
o,
|
|
561
|
-
s
|
|
562
|
-
), tr = async ({
|
|
563
|
-
buildConfig: e,
|
|
564
|
-
prebuildResult: t,
|
|
565
|
-
ctx: r,
|
|
566
|
-
telemetry: n,
|
|
567
|
-
telemetryEnabled: o,
|
|
568
|
-
telemetryOutputFormat: s
|
|
569
|
-
}) => {
|
|
570
|
-
try {
|
|
571
|
-
const i = typeof e.entry == "string" ? [e.entry] : Array.isArray(e.entry) ? e.entry : Object.values(e.entry);
|
|
572
|
-
if (t.filesToInject.length > 0) {
|
|
573
|
-
const a = await Promise.all(
|
|
574
|
-
t.filesToInject.map((l) => h.readFile(l, "utf-8"))
|
|
575
|
-
).then((l) => l.join(" "));
|
|
576
|
-
await Promise.all(
|
|
577
|
-
i.map(async (l) => {
|
|
578
|
-
const f = await h.readFile(l, "utf-8"), u = `${a} ${f}`, m = Qt(u);
|
|
579
|
-
return h.writeFile(l, m);
|
|
580
|
-
})
|
|
581
|
-
);
|
|
582
|
-
}
|
|
583
|
-
const c = {
|
|
584
|
-
...e,
|
|
585
|
-
setup: {
|
|
586
|
-
contentToInject: t.injection.banner,
|
|
587
|
-
defineVars: Object.fromEntries(
|
|
588
|
-
// Get all entries from defineVars
|
|
589
|
-
Object.entries(t.bundler.defineVars).filter(([a, l]) => l !== void 0).map(([a, l]) => [a, l])
|
|
590
|
-
)
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
return await rr(c, r, n, o, s), Promise.all(
|
|
594
|
-
Object.entries(c.entry).map(async ([a]) => {
|
|
595
|
-
const l = a.endsWith(".js") ? a : `${a}.js`, f = await h.readFile(l, "utf-8");
|
|
596
|
-
if (!r.production) return f;
|
|
597
|
-
const u = er(
|
|
598
|
-
f,
|
|
599
|
-
e,
|
|
600
|
-
r
|
|
601
|
-
);
|
|
602
|
-
return await h.writeFile(l, u), u;
|
|
603
|
-
})
|
|
604
|
-
);
|
|
605
|
-
} catch (i) {
|
|
606
|
-
return Promise.reject(i);
|
|
607
|
-
}
|
|
608
|
-
}, rr = async (e, t, r, n, o) => {
|
|
609
|
-
switch (e.bundler) {
|
|
610
|
-
case "esbuild": {
|
|
611
|
-
F.IS_DEBUG && (p.build.info("=== System Info ==="), p.build.info("CPUs:", X.cpus().length), p.build.info("Total Memory:", X.totalmem() / 1024 / 1024, "MB"), p.build.info("Free Memory:", X.freemem() / 1024 / 1024, "MB"));
|
|
612
|
-
const s = await L(
|
|
613
|
-
r,
|
|
614
|
-
n,
|
|
615
|
-
o,
|
|
616
|
-
"esbuild-config-create",
|
|
617
|
-
"ESBuild Config Create",
|
|
618
|
-
async () => M.createAzionESBuildConfigWrapper(e, t)
|
|
619
|
-
);
|
|
620
|
-
let i, c;
|
|
621
|
-
F.IS_DEBUG && (p.build.info("=== Build Test ==="), i = Date.now(), c = process.memoryUsage());
|
|
622
|
-
const a = await L(
|
|
623
|
-
r,
|
|
624
|
-
n,
|
|
625
|
-
o,
|
|
626
|
-
"esbuild-execution",
|
|
627
|
-
"ESBuild Execution",
|
|
628
|
-
async () => M.executeESBuildBuildWrapper(s)
|
|
629
|
-
);
|
|
630
|
-
if (F.IS_DEBUG) {
|
|
631
|
-
const l = Date.now() - i, f = process.memoryUsage();
|
|
632
|
-
p.build.info("=== Results ==="), p.build.info("Duration:", l, "ms");
|
|
633
|
-
const u = {
|
|
634
|
-
heapUsed: `${(f.heapUsed - c.heapUsed) / 1024 / 1024} MB`,
|
|
635
|
-
rss: `${(f.rss - c.rss) / 1024 / 1024} MB`
|
|
636
|
-
};
|
|
637
|
-
p.build.info("Memory heapUsed:", u.heapUsed), p.build.info("Memory rss:", u.rss);
|
|
638
|
-
}
|
|
639
|
-
return a;
|
|
640
|
-
}
|
|
641
|
-
case "webpack": {
|
|
642
|
-
const s = await L(
|
|
643
|
-
r,
|
|
644
|
-
n,
|
|
645
|
-
o,
|
|
646
|
-
"webpack-config-create",
|
|
647
|
-
"Webpack Config Create",
|
|
648
|
-
async () => M.createAzionWebpackConfigWrapper(e, t)
|
|
649
|
-
);
|
|
650
|
-
return L(
|
|
651
|
-
r,
|
|
652
|
-
n,
|
|
653
|
-
o,
|
|
654
|
-
"webpack-execution",
|
|
655
|
-
"Webpack Execution",
|
|
656
|
-
async () => M.executeWebpackBuildWrapper(s)
|
|
657
|
-
);
|
|
658
|
-
}
|
|
659
|
-
default:
|
|
660
|
-
throw new Error(`Unsupported bundler: ${e.bundler}`);
|
|
661
|
-
}
|
|
662
|
-
}, nr = (e, t) => {
|
|
663
|
-
const r = (n, o) => {
|
|
664
|
-
if (n && !n.build || Array.isArray(n) && !Array.isArray(o))
|
|
665
|
-
return o;
|
|
666
|
-
};
|
|
667
|
-
return yt.mergeWith({}, e, t, r);
|
|
668
|
-
}, sr = { mergeConfigWithUserOverrides: nr }, ge = async ({
|
|
669
|
-
config: e,
|
|
670
|
-
preset: t
|
|
671
|
-
}) => {
|
|
672
|
-
try {
|
|
673
|
-
const { config: r } = t;
|
|
674
|
-
e.firewall && (delete r.applications, delete r.workloads, delete r.connectors, delete r.functions);
|
|
675
|
-
const n = sr.mergeConfigWithUserOverrides(
|
|
676
|
-
r,
|
|
677
|
-
e
|
|
678
|
-
);
|
|
679
|
-
return n.build?.preset || (n.build = {
|
|
680
|
-
...n.build,
|
|
681
|
-
preset: t.metadata.name,
|
|
682
|
-
...!t.handler && e.build?.entry && {
|
|
683
|
-
entry: e.build?.entry
|
|
684
|
-
}
|
|
685
|
-
}), await Ee.readAzionConfig() || await Ee.writeUserConfig(n), n;
|
|
686
|
-
} catch (r) {
|
|
687
|
-
throw new Error(`Failed to set environment: ${r.message}`);
|
|
688
|
-
}
|
|
689
|
-
}, ye = (e) => e ? typeof e == "string" ? [e] : Array.isArray(e) ? e : Object.values(e) : [], or = async ({
|
|
690
|
-
entrypoint: e,
|
|
691
|
-
preset: t
|
|
692
|
-
}) => {
|
|
693
|
-
if (e && !t.handler) {
|
|
694
|
-
const r = ye(e), n = r.map((o) => S.resolve(o));
|
|
695
|
-
return await Promise.all(
|
|
696
|
-
n.map(async (o) => {
|
|
697
|
-
try {
|
|
698
|
-
await h.access(o);
|
|
699
|
-
} catch (s) {
|
|
700
|
-
throw g.error(s), new Error(
|
|
701
|
-
`Entry point "${ne(process.cwd(), o)}" was not found.
|
|
702
|
-
- Fix the "build.entry" property in your azion.config, or
|
|
703
|
-
- Pass the correct file via the --entry flag.
|
|
704
|
-
If not specified, the entry defaults to index.ts or index.js" in the project root.`
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
})
|
|
708
|
-
), O.feedback.build.info(
|
|
709
|
-
`Using entry point(s): ${r.map((o) => ne(process.cwd(), o)).join(", ")}`
|
|
710
|
-
), n;
|
|
711
|
-
}
|
|
712
|
-
if (t.handler) {
|
|
713
|
-
const r = globalThis.bundler.root.includes("node_modules") ? S.resolve(globalThis.bundler.root, "../../") : S.resolve(globalThis.bundler.root, "node_modules"), n = S.resolve(
|
|
714
|
-
r,
|
|
715
|
-
"@aziontech/presets/dist/presets",
|
|
716
|
-
t.metadata.name,
|
|
717
|
-
"handler.js"
|
|
718
|
-
);
|
|
719
|
-
try {
|
|
720
|
-
await h.access(n);
|
|
721
|
-
} catch (o) {
|
|
722
|
-
throw g.error(o), new Error(
|
|
723
|
-
`Missing handler "${n}" (default for "${t.metadata.name}" preset). Either create this file or specify a custom entry point using --entry.`
|
|
724
|
-
);
|
|
725
|
-
}
|
|
726
|
-
return O.feedback.build.info(`Using built-in handler from "${t.metadata.name}" preset.`), [n];
|
|
727
|
-
}
|
|
728
|
-
if (t.config.build?.entry) {
|
|
729
|
-
const r = ye(t.config.build.entry), n = r.map((o) => S.resolve(o));
|
|
730
|
-
return await Promise.all(
|
|
731
|
-
n.map(async (o) => {
|
|
732
|
-
try {
|
|
733
|
-
await h.access(o);
|
|
734
|
-
} catch (s) {
|
|
735
|
-
throw g.error(s), new Error(
|
|
736
|
-
`Missing default entry point "${o}" for "${t.metadata.name}" preset. Either create this file or specify a custom entry point using --entry.`
|
|
737
|
-
);
|
|
738
|
-
}
|
|
739
|
-
})
|
|
740
|
-
), O.feedback.build.info(`Using preset default entry: ${r.join(", ")}`), n;
|
|
741
|
-
}
|
|
742
|
-
throw new Error(
|
|
743
|
-
"Cannot determine entry point. Please specify one using --entry or in your configuration."
|
|
744
|
-
);
|
|
745
|
-
}, ir = async ({ buildConfig: e, ctx: t }) => {
|
|
746
|
-
const { postbuild: r } = e.preset;
|
|
747
|
-
r && await r(e, { ...t });
|
|
748
|
-
}, ar = async ({
|
|
749
|
-
namespace: e,
|
|
750
|
-
property: t,
|
|
751
|
-
dirs: r
|
|
752
|
-
}) => {
|
|
753
|
-
const n = {}, o = async (s) => {
|
|
754
|
-
await Promise.all(
|
|
755
|
-
s.map(async (i) => {
|
|
756
|
-
const c = await h.readdir(i);
|
|
757
|
-
await Promise.all(
|
|
758
|
-
c.map(async (a) => {
|
|
759
|
-
const l = k(i, a), f = await h.stat(l);
|
|
760
|
-
if (f.isDirectory())
|
|
761
|
-
await o([l]);
|
|
762
|
-
else if (f.isFile()) {
|
|
763
|
-
const u = await h.readFile(l);
|
|
764
|
-
let m = l;
|
|
765
|
-
l.startsWith("/") || (m = `/${l}`), n[m] = { content: u.toString("base64") };
|
|
766
|
-
}
|
|
767
|
-
})
|
|
768
|
-
);
|
|
769
|
-
})
|
|
770
|
-
);
|
|
771
|
-
};
|
|
772
|
-
return await o(r), `globalThis.${e}.${t}=${JSON.stringify(n)};`;
|
|
773
|
-
}, cr = async ({ dirs: e, prefix: t, outputPath: r }) => {
|
|
774
|
-
await Promise.all(
|
|
775
|
-
e.map(async (n) => {
|
|
776
|
-
const o = t ? n.replace(t, "") : n, s = k(r, o);
|
|
777
|
-
await h.access(s).then(() => !0).catch(() => !1) || await h.mkdir(s, { recursive: !0 }), await h.cp(n, s, { recursive: !0 });
|
|
778
|
-
})
|
|
779
|
-
);
|
|
780
|
-
}, lr = ({ namespace: e, property: t, vars: r }) => Object.entries(r).reduce(
|
|
781
|
-
(n, [o, s]) => {
|
|
782
|
-
const i = t ? `${e}.${t}` : e;
|
|
783
|
-
return `${n} globalThis.${i}.${o}=${s};`;
|
|
784
|
-
},
|
|
785
|
-
t ? `globalThis.${e}.${t}={};` : `globalThis.${e}={};`
|
|
786
|
-
), fr = async (e, t) => {
|
|
787
|
-
const r = Xe(t);
|
|
788
|
-
if (!r) return {};
|
|
789
|
-
const n = await Ye(e, !0);
|
|
790
|
-
return n.length === 0 ? {} : Object.fromEntries(
|
|
791
|
-
n.map(({ key: o }) => [`process.env.${o}`, `process.env.${r}${o}`])
|
|
792
|
-
);
|
|
793
|
-
}, ur = async ({
|
|
794
|
-
namespace: e,
|
|
795
|
-
property: t,
|
|
796
|
-
prefix: r
|
|
797
|
-
}) => `globalThis.${e} = { ...globalThis.${e}, ${t}: '${r && typeof r == "string" && r !== "" ? r : '""'}'};`, N = {
|
|
798
|
-
injectWorkerMemoryFiles: ar,
|
|
799
|
-
copyFilesToLocalEdgeStorage: cr,
|
|
800
|
-
injectWorkerGlobals: lr,
|
|
801
|
-
injectWorkerPathPrefix: ur,
|
|
802
|
-
buildEnvAliasDefineVars: fr
|
|
803
|
-
}, dr = {
|
|
804
|
-
filesToInject: [],
|
|
805
|
-
injection: {
|
|
806
|
-
globals: {}
|
|
807
|
-
},
|
|
808
|
-
bundler: {
|
|
809
|
-
defineVars: {},
|
|
810
|
-
plugins: []
|
|
811
|
-
}
|
|
812
|
-
}, pr = async ({
|
|
813
|
-
buildConfig: e,
|
|
814
|
-
ctx: t,
|
|
815
|
-
applicationName: r
|
|
816
|
-
}) => {
|
|
817
|
-
const n = await e.preset.prebuild?.(e, t) || dr, o = N.injectWorkerGlobals({
|
|
818
|
-
namespace: F.NAMESPACE,
|
|
819
|
-
// Transform globals object:
|
|
820
|
-
// 1. Convert object to entries
|
|
821
|
-
// 2. Remove any entries with undefined values
|
|
822
|
-
// 3. Ensure remaining values are typed as string
|
|
823
|
-
vars: Object.fromEntries(
|
|
824
|
-
Object.entries(n.injection?.globals || {}).filter(([l, f]) => f !== void 0).map(([l, f]) => [l, f])
|
|
825
|
-
)
|
|
826
|
-
}), s = await N.injectWorkerMemoryFiles({
|
|
827
|
-
namespace: F.NAMESPACE,
|
|
828
|
-
property: "__FILES__",
|
|
829
|
-
dirs: e.memoryFS?.injectionDirs || []
|
|
830
|
-
});
|
|
831
|
-
e.memoryFS && N.copyFilesToLocalEdgeStorage({
|
|
832
|
-
dirs: e.memoryFS?.injectionDirs,
|
|
833
|
-
prefix: e.memoryFS?.removePathPrefix,
|
|
834
|
-
outputPath: C.OUTPUT_STORAGE_PATH
|
|
835
|
-
});
|
|
836
|
-
const i = await N.injectWorkerPathPrefix({
|
|
837
|
-
namespace: F.NAMESPACE,
|
|
838
|
-
property: "FS_PATH_PREFIX_TO_REMOVE",
|
|
839
|
-
prefix: e.memoryFS?.removePathPrefix || ""
|
|
840
|
-
}), c = `${o}${i}
|
|
841
|
-
${s}`, a = t.production ? await N.buildEnvAliasDefineVars(process.cwd(), r) : {};
|
|
842
|
-
return {
|
|
843
|
-
filesToInject: n.filesToInject || [],
|
|
844
|
-
injection: {
|
|
845
|
-
globals: n.injection?.globals || {},
|
|
846
|
-
entry: "",
|
|
847
|
-
banner: c
|
|
848
|
-
},
|
|
849
|
-
bundler: {
|
|
850
|
-
defineVars: { ...n.bundler?.defineVars, ...a },
|
|
851
|
-
plugins: n.bundler?.plugins || []
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
}, mr = ({ projectDir: e = process.cwd() }) => Tt({
|
|
855
|
-
projectDir: e
|
|
856
|
-
}), hr = { listFrameworks: mr };
|
|
857
|
-
async function gr() {
|
|
858
|
-
try {
|
|
859
|
-
const e = await hr.listFrameworks({
|
|
860
|
-
projectDir: process.cwd()
|
|
861
|
-
});
|
|
862
|
-
if (e[0]?.id && Object.values(J).some(
|
|
863
|
-
(i) => i.metadata?.name === e[0].id
|
|
864
|
-
))
|
|
865
|
-
return e[0].id;
|
|
866
|
-
const t = k(process.cwd(), "tsconfig.json");
|
|
867
|
-
return me.existsSync(t) || me.readdirSync(process.cwd()).some((s) => [".ts", ".tsx"].includes(I(s))) ? "typescript" : "javascript";
|
|
868
|
-
} catch {
|
|
869
|
-
return "javascript";
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
const yr = { inferPreset: gr }, wr = (e) => Object.values(J).find((t) => t.metadata?.name === e), br = async (e) => {
|
|
873
|
-
if (e) {
|
|
874
|
-
const t = typeof e == "string" ? e : e.metadata?.name;
|
|
875
|
-
O.feedback.build.info(`Using preset: ${t}`);
|
|
876
|
-
}
|
|
877
|
-
if (e || (O.feedback.build.info("No preset specified, using automatic detection..."), e = await yr.inferPreset(), O.feedback.build.info(`Detected preset: ${e}`)), typeof e == "string") {
|
|
878
|
-
const t = wr(e);
|
|
879
|
-
if (!t)
|
|
880
|
-
throw new Error(`Invalid build preset name: '${e}'`);
|
|
881
|
-
return t;
|
|
882
|
-
}
|
|
883
|
-
return e;
|
|
884
|
-
}, Er = () => `${Date.now()}`, vr = async (e) => {
|
|
885
|
-
try {
|
|
886
|
-
return await h.access(e), (await h.stat(e)).isDirectory();
|
|
887
|
-
} catch {
|
|
888
|
-
return !1;
|
|
889
|
-
}
|
|
890
|
-
}, Tr = async (e, t) => {
|
|
891
|
-
try {
|
|
892
|
-
const r = C.OUTPUT_STORAGE_METADATA_PATH;
|
|
893
|
-
let n = [];
|
|
894
|
-
try {
|
|
895
|
-
const s = await h.readFile(r, "utf-8");
|
|
896
|
-
n = JSON.parse(s);
|
|
897
|
-
} catch {
|
|
898
|
-
g.info("Creating new storage metadata file");
|
|
899
|
-
}
|
|
900
|
-
const o = {
|
|
901
|
-
...t,
|
|
902
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
903
|
-
};
|
|
904
|
-
n = n.filter((s) => s.name !== e), n.push(o), await h.writeFile(r, JSON.stringify(n, null, 2), "utf-8"), g.info(`Storage metadata saved for: ${e}`);
|
|
905
|
-
} catch (r) {
|
|
906
|
-
throw g.error(`Failed to save storage metadata for ${e}:`, r), r;
|
|
907
|
-
}
|
|
908
|
-
}, Sr = async (e, t, r, n) => {
|
|
909
|
-
const o = e.name;
|
|
910
|
-
try {
|
|
911
|
-
const s = S.join(r, o, n);
|
|
912
|
-
await h.mkdir(S.join(r, o), { recursive: !0 });
|
|
913
|
-
try {
|
|
914
|
-
const i = await h.readdir(S.join(r, o));
|
|
915
|
-
await Promise.all(
|
|
916
|
-
i.filter((c) => c !== n).map(async (c) => {
|
|
917
|
-
const a = S.join(r, o, c);
|
|
918
|
-
try {
|
|
919
|
-
const l = await h.lstat(a);
|
|
920
|
-
l.isSymbolicLink() ? await h.unlink(a) : l.isDirectory() ? await h.rm(a, { recursive: !0, force: !0 }) : await h.unlink(a);
|
|
921
|
-
} catch (l) {
|
|
922
|
-
g.warn(`Failed to remove ${a}:`, l);
|
|
923
|
-
}
|
|
924
|
-
})
|
|
925
|
-
), g.info(`Cleaned up existing storage items in: ${S.join(r, o)}`);
|
|
926
|
-
} catch {
|
|
927
|
-
g.warn(`Storage directory not found or empty: ${S.join(r, o)}`);
|
|
928
|
-
}
|
|
929
|
-
try {
|
|
930
|
-
const i = await h.lstat(s);
|
|
931
|
-
i.isSymbolicLink() ? (await h.unlink(s), g.info(`Removed existing symlink: ${s}`)) : i.isDirectory() && (await h.rm(s, { recursive: !0, force: !0 }), g.info(`Removed existing directory: ${s}`));
|
|
932
|
-
} catch {
|
|
933
|
-
}
|
|
934
|
-
await h.symlink(t, s, "dir"), g.info(`Storage link created: ${o} -> ${t}`), await Tr(o, {
|
|
935
|
-
name: o,
|
|
936
|
-
workloadsAccess: e.workloadsAccess || "read_only",
|
|
937
|
-
sourceDir: t,
|
|
938
|
-
targetDir: s,
|
|
939
|
-
prefix: n
|
|
940
|
-
});
|
|
941
|
-
} catch (s) {
|
|
942
|
-
throw g.error(`Failed to create storage link for ${o}:`, s), s;
|
|
943
|
-
}
|
|
944
|
-
}, $r = (e) => !e.name || !e.dir ? (g.warn("Storage configuration is missing required fields (name or dir)"), !1) : !0, Pr = async ({ config: e }) => {
|
|
945
|
-
try {
|
|
946
|
-
const t = e.storage || [], r = [];
|
|
947
|
-
if (t.length === 0)
|
|
948
|
-
return g.info("No storages found to setup"), r;
|
|
949
|
-
await h.mkdir(C.OUTPUT_STORAGE_PATH, { recursive: !0 });
|
|
950
|
-
for (const n of t) {
|
|
951
|
-
if (!$r(n))
|
|
952
|
-
continue;
|
|
953
|
-
const o = S.resolve(process.cwd(), n.dir);
|
|
954
|
-
if (!await vr(o))
|
|
955
|
-
throw new Error(
|
|
956
|
-
`Storage directory not found: ${o}.
|
|
957
|
-
- Please check the path provided in the azion.config file on storage[].dir`
|
|
958
|
-
);
|
|
959
|
-
const s = n.prefix, i = s || Er();
|
|
960
|
-
s || p.storage.info(
|
|
961
|
-
`No prefix provided for storage '${n.name}', generating version prefix: ${i}`
|
|
962
|
-
), s && p.storage.info(`Using provided prefix for storage '${n.name}': ${i}`), await Sr(n, o, C.OUTPUT_STORAGE_PATH, i), r.push({
|
|
963
|
-
...n,
|
|
964
|
-
prefix: i
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
return g.info("Storage setup completed successfully"), r;
|
|
968
|
-
} catch (t) {
|
|
969
|
-
throw g.error("Failed to setup storages:", t), t;
|
|
970
|
-
}
|
|
971
|
-
}, Z = {
|
|
972
|
-
LEGACY_DEPRECATION: "DEPRECATED: Migrate handler to → export default { fetch: (request, env, ctx) => {...} }",
|
|
973
|
-
UNSUPPORTED_PATTERN_DETECTED: "Unsupported handler pattern detected. Generating Service Worker wrapper as fallback.",
|
|
974
|
-
UNSUPPORTED_PATTERN_SUGGESTIONS: "Consider updating your handler to use ES Modules pattern."
|
|
975
|
-
}, H = `
|
|
976
|
-
const request = event.request;
|
|
977
|
-
const env = process.env; // or any other environment variables you want to pass
|
|
978
|
-
const ctx = { waitUntil: event.waitUntil?.bind(event) };`, Q = {
|
|
979
|
-
baseImport: (e) => `
|
|
980
|
-
import module from '${e}';
|
|
981
|
-
|
|
982
|
-
// Object export pattern: export default { fetch, firewall }
|
|
983
|
-
const handlers = module.default || module;`,
|
|
984
|
-
contextSetup: H,
|
|
985
|
-
firewallHandler: `
|
|
986
|
-
const firewallHandler = handlers.firewall;
|
|
987
|
-
addEventListener('firewall', (event) => {
|
|
988
|
-
(async () => {${H}
|
|
989
|
-
|
|
990
|
-
await firewallHandler(request, env, ctx);
|
|
991
|
-
})().catch(console.error);
|
|
992
|
-
});`,
|
|
993
|
-
fetchHandler: (e) => `
|
|
994
|
-
${e ? "export default module;" : `
|
|
995
|
-
const fetchHandler = handlers.fetch;
|
|
996
|
-
addEventListener('fetch', (event) => {${H}
|
|
997
|
-
event.respondWith((async () => {
|
|
998
|
-
return fetchHandler(request, env, ctx);
|
|
999
|
-
})());
|
|
1000
|
-
});`}
|
|
1001
|
-
`,
|
|
1002
|
-
fallbackHandler: (e) => `${`
|
|
1003
|
-
import module from '${e}';
|
|
1004
|
-
|
|
1005
|
-
// Object export pattern: export default { fetch, firewall }
|
|
1006
|
-
const handlers = module.default || module;`}
|
|
1007
|
-
const fetchHandler = handlers.fetch;
|
|
1008
|
-
|
|
1009
|
-
if (fetchHandler) {
|
|
1010
|
-
addEventListener('fetch', (event) => {${H}
|
|
1011
|
-
|
|
1012
|
-
event.respondWith((async () => {
|
|
1013
|
-
return fetchHandler(request, env, ctx);
|
|
1014
|
-
})());
|
|
1015
|
-
});
|
|
1016
|
-
} else {
|
|
1017
|
-
throw new Error("No fetch handler found in default export object.");
|
|
1018
|
-
}`
|
|
1019
|
-
}, _e = (e) => {
|
|
1020
|
-
const t = e.split(`
|
|
1021
|
-
`), r = /addEventListener\s*\(\s*['"`](fetch|firewall)['"`]\s*,/;
|
|
1022
|
-
return t.some((n) => {
|
|
1023
|
-
const o = n.trim();
|
|
1024
|
-
return o.startsWith("//") || o.startsWith("/*") ? !1 : r.test(n);
|
|
1025
|
-
});
|
|
1026
|
-
}, xr = async (e) => {
|
|
1027
|
-
try {
|
|
1028
|
-
const t = await import(e), r = t.default || t;
|
|
1029
|
-
return {
|
|
1030
|
-
hasFirewall: !!r.firewall,
|
|
1031
|
-
hasFetch: !!r.fetch
|
|
1032
|
-
};
|
|
1033
|
-
} catch {
|
|
1034
|
-
return {
|
|
1035
|
-
hasFirewall: !1,
|
|
1036
|
-
hasFetch: !0
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
}, kr = async (e, t) => {
|
|
1040
|
-
const { hasFirewall: r, hasFetch: n } = await xr(e);
|
|
1041
|
-
if (!r && !n)
|
|
1042
|
-
return `// No fetch or firewall handlers found in: ${e}
|
|
1043
|
-
// The original file will be used as-is in production mode.
|
|
1044
|
-
// Consider adding: export default { fetch: (request, env, ctx) => { ... } }
|
|
1045
|
-
|
|
1046
|
-
console.warn('No Edge Function handlers found. File will run as-is.');`;
|
|
1047
|
-
const o = [Q.baseImport(e)];
|
|
1048
|
-
return r && o.push(Q.firewallHandler), n && o.push(Q.fetchHandler(t)), o.join(`
|
|
1049
|
-
`);
|
|
1050
|
-
}, Cr = (e) => `
|
|
1051
|
-
import handler from '${e}';
|
|
1052
|
-
|
|
1053
|
-
// Legacy pattern wrapper: export default function → addEventListener
|
|
1054
|
-
addEventListener('fetch', (event) => {
|
|
1055
|
-
event.respondWith((async () => {
|
|
1056
|
-
return await handler(event);
|
|
1057
|
-
})());
|
|
1058
|
-
});
|
|
1059
|
-
`, le = (e) => /export\s+default\s*\{[\s\S]*fetch[\s\S]*\}/.test(e), je = (e) => !(!/export\s+default\s+/.test(e) || le(e)), Fr = async (e) => {
|
|
1060
|
-
try {
|
|
1061
|
-
const t = await import(e);
|
|
1062
|
-
return typeof t.default > "u" && !t.fetch && !t.firewall ? "serviceWorker" : t.default && typeof t.default == "object" && (t.default.fetch || t.default.firewall) ? "ESModules" : t.default ? "legacy" : "unsupported";
|
|
1063
|
-
} catch {
|
|
1064
|
-
const r = await (await import("fs/promises")).readFile(e, "utf-8");
|
|
1065
|
-
return _e(r) ? "serviceWorker" : le(r) ? "ESModules" : je(r) ? "legacy" : "unsupported";
|
|
1066
|
-
}
|
|
1067
|
-
}, Ar = (e) => typeof e == "string" ? [e] : Array.isArray(e) ? e : Object.values(e), Or = (e) => _e(e) ? "serviceWorker" : le(e) ? "ESModules" : je(e) ? "legacy" : "unsupported", _r = async (e, t, r) => {
|
|
1068
|
-
let n;
|
|
1069
|
-
try {
|
|
1070
|
-
n = await Fr(t);
|
|
1071
|
-
} catch {
|
|
1072
|
-
n = Or(e);
|
|
1073
|
-
}
|
|
1074
|
-
switch (n) {
|
|
1075
|
-
case "serviceWorker":
|
|
1076
|
-
return e;
|
|
1077
|
-
case "ESModules":
|
|
1078
|
-
return await kr(t, r);
|
|
1079
|
-
case "legacy":
|
|
1080
|
-
return p.build.warn(Z.LEGACY_DEPRECATION), Cr(t);
|
|
1081
|
-
default:
|
|
1082
|
-
return p.build.warn(Z.UNSUPPORTED_PATTERN_DETECTED), p.build.info(Z.UNSUPPORTED_PATTERN_SUGGESTIONS), e;
|
|
1083
|
-
}
|
|
1084
|
-
}, jr = async (e, t) => {
|
|
1085
|
-
try {
|
|
1086
|
-
const r = Ar(t.handler), n = e.entry || {}, o = await Promise.all(
|
|
1087
|
-
r.map(async (s, i) => {
|
|
1088
|
-
const c = Object.values(n)[i], a = await h.readFile(s, "utf-8"), l = await _r(a, s, t.production);
|
|
1089
|
-
return [c, l];
|
|
1090
|
-
})
|
|
1091
|
-
);
|
|
1092
|
-
return Object.fromEntries(o);
|
|
1093
|
-
} catch (r) {
|
|
1094
|
-
throw new Error(
|
|
1095
|
-
`Failed to setup worker code: ${r instanceof Error ? r.message : String(r)}`
|
|
1096
|
-
);
|
|
1097
|
-
}
|
|
1098
|
-
}, Ur = (e) => e === !0 ? !0 : process.env[R.ENV_ENABLED] === "true", Rr = () => {
|
|
1099
|
-
const e = process.env[R.ENV_FORMAT];
|
|
1100
|
-
return e === "console" || e === "json" || e === "html" || e === "both" ? e : R.DEFAULT_FORMAT;
|
|
1101
|
-
}, Nr = () => process.env[R.ENV_OUTPUT] || R.DEFAULT_OUTPUT_PATH, Ir = () => R.DEFAULT_HTML_OUTPUT_PATH, Br = async (e) => {
|
|
1102
|
-
const { config: t, options: r } = e, n = !!r.production, o = Ur(r.telemetry), s = t.build?.bundler || "esbuild", i = {
|
|
1103
|
-
enabled: o,
|
|
1104
|
-
outputFormat: Rr(),
|
|
1105
|
-
outputPath: Nr(),
|
|
1106
|
-
htmlOutputPath: Ir()
|
|
1107
|
-
}, c = {
|
|
1108
|
-
bundlerVersion: F.VERSION,
|
|
1109
|
-
preset: t.build?.preset?.toString() || "javascript",
|
|
1110
|
-
bundler: s,
|
|
1111
|
-
production: n,
|
|
1112
|
-
entry: typeof t.build?.entry == "string" || Array.isArray(t.build?.entry) ? t.build.entry : t.build?.entry ? Object.values(t.build.entry) : ["./main.js"]
|
|
1113
|
-
}, a = new ot(i, c);
|
|
1114
|
-
try {
|
|
1115
|
-
const l = a.startSpan("build", {
|
|
1116
|
-
preset: c.preset,
|
|
1117
|
-
bundler: c.bundler,
|
|
1118
|
-
production: c.production
|
|
1119
|
-
});
|
|
1120
|
-
o && i.outputFormat !== "json" && (console.log(it(F.VERSION)), console.log(at(c)), console.log(`
|
|
1121
|
-
⚙️ Starting build pipeline...
|
|
1122
|
-
`)), r.skipFrameworkBuild && p.build.warn("Skipping framework build"), await x(
|
|
1123
|
-
a,
|
|
1124
|
-
o,
|
|
1125
|
-
i.outputFormat,
|
|
1126
|
-
"dependencies-check",
|
|
1127
|
-
"Dependencies Check",
|
|
1128
|
-
async () => It()
|
|
1129
|
-
);
|
|
1130
|
-
const f = await x(
|
|
1131
|
-
a,
|
|
1132
|
-
o,
|
|
1133
|
-
i.outputFormat,
|
|
1134
|
-
"preset-resolution",
|
|
1135
|
-
"Preset Resolution",
|
|
1136
|
-
async () => br(t.build?.preset)
|
|
1137
|
-
), u = await x(
|
|
1138
|
-
a,
|
|
1139
|
-
o,
|
|
1140
|
-
i.outputFormat,
|
|
1141
|
-
"build-config-setup",
|
|
1142
|
-
"Build Config Setup",
|
|
1143
|
-
async () => Kt(t, f, n)
|
|
1144
|
-
);
|
|
1145
|
-
if (r.onlyGenerateConfig) {
|
|
1146
|
-
const E = await ge({
|
|
1147
|
-
config: t,
|
|
1148
|
-
preset: f,
|
|
1149
|
-
ctx: {
|
|
1150
|
-
production: n ?? _.PRODUCTION,
|
|
1151
|
-
skipFrameworkBuild: !!r.skipFrameworkBuild,
|
|
1152
|
-
handler: ""
|
|
1153
|
-
}
|
|
1154
|
-
});
|
|
1155
|
-
return p.build.success("Build completed successfully with only azion.config"), re(E), a.endSpan(l), a.printToConsole(), await a.saveReport(), {
|
|
1156
|
-
config: E,
|
|
1157
|
-
ctx: {
|
|
1158
|
-
production: n ?? _.PRODUCTION,
|
|
1159
|
-
skipFrameworkBuild: !!r.skipFrameworkBuild,
|
|
1160
|
-
handler: ""
|
|
1161
|
-
},
|
|
1162
|
-
setup: u
|
|
1163
|
-
};
|
|
1164
|
-
}
|
|
1165
|
-
let m = {
|
|
1166
|
-
production: n ?? _.PRODUCTION,
|
|
1167
|
-
skipFrameworkBuild: !!r.skipFrameworkBuild,
|
|
1168
|
-
handler: ""
|
|
1169
|
-
};
|
|
1170
|
-
const w = await x(
|
|
1171
|
-
a,
|
|
1172
|
-
o,
|
|
1173
|
-
i.outputFormat,
|
|
1174
|
-
"environment-setup",
|
|
1175
|
-
"Environment Setup",
|
|
1176
|
-
async () => {
|
|
1177
|
-
const E = await ge({
|
|
1178
|
-
config: t,
|
|
1179
|
-
preset: f,
|
|
1180
|
-
ctx: m
|
|
1181
|
-
});
|
|
1182
|
-
return re(E), E;
|
|
1183
|
-
}
|
|
1184
|
-
);
|
|
1185
|
-
p.prebuild.info("Starting pre-build...");
|
|
1186
|
-
const d = await x(
|
|
1187
|
-
a,
|
|
1188
|
-
o,
|
|
1189
|
-
i.outputFormat,
|
|
1190
|
-
"prebuild",
|
|
1191
|
-
"Prebuild",
|
|
1192
|
-
async () => pr({
|
|
1193
|
-
buildConfig: u,
|
|
1194
|
-
ctx: m,
|
|
1195
|
-
applicationName: w.applications?.[0]?.name
|
|
1196
|
-
})
|
|
1197
|
-
);
|
|
1198
|
-
p.prebuild.info("Pre-build completed successfully");
|
|
1199
|
-
const y = await x(
|
|
1200
|
-
a,
|
|
1201
|
-
o,
|
|
1202
|
-
i.outputFormat,
|
|
1203
|
-
"handler-resolution",
|
|
1204
|
-
"Handler Resolution",
|
|
1205
|
-
async () => or({
|
|
1206
|
-
entrypoint: t.build?.entry,
|
|
1207
|
-
preset: f
|
|
1208
|
-
})
|
|
1209
|
-
);
|
|
1210
|
-
m = {
|
|
1211
|
-
production: n ?? _.PRODUCTION,
|
|
1212
|
-
handler: y,
|
|
1213
|
-
skipFrameworkBuild: !!r.skipFrameworkBuild
|
|
1214
|
-
}, await x(
|
|
1215
|
-
a,
|
|
1216
|
-
o,
|
|
1217
|
-
i.outputFormat,
|
|
1218
|
-
"worker-setup",
|
|
1219
|
-
"Worker Setup",
|
|
1220
|
-
async () => {
|
|
1221
|
-
const E = await jr(u, m), b = [];
|
|
1222
|
-
await Promise.all(
|
|
1223
|
-
Object.entries(E).map(async ([v, j]) => {
|
|
1224
|
-
await Pe(xe(v), { recursive: !0 }), await dt(v, j, "utf-8"), b.push(v);
|
|
1225
|
-
})
|
|
1226
|
-
);
|
|
1227
|
-
for (const v of b)
|
|
1228
|
-
await Ze(v);
|
|
1229
|
-
return E;
|
|
1230
|
-
}
|
|
1231
|
-
), p.build.info("Starting build..."), await x(
|
|
1232
|
-
a,
|
|
1233
|
-
o,
|
|
1234
|
-
i.outputFormat,
|
|
1235
|
-
"core-build",
|
|
1236
|
-
"Core Build",
|
|
1237
|
-
async () => tr({
|
|
1238
|
-
buildConfig: u,
|
|
1239
|
-
prebuildResult: d,
|
|
1240
|
-
ctx: m,
|
|
1241
|
-
telemetry: a,
|
|
1242
|
-
telemetryEnabled: o,
|
|
1243
|
-
telemetryOutputFormat: i.outputFormat
|
|
1244
|
-
})
|
|
1245
|
-
), p.build.success("Build completed successfully"), await Qe(), Bt(u.entry, w.functions), p.postbuild.info("Starting post-build..."), await x(
|
|
1246
|
-
a,
|
|
1247
|
-
o,
|
|
1248
|
-
i.outputFormat,
|
|
1249
|
-
"postbuild",
|
|
1250
|
-
"Postbuild",
|
|
1251
|
-
async () => {
|
|
1252
|
-
await ir({ buildConfig: u, ctx: m });
|
|
1253
|
-
}
|
|
1254
|
-
), p.postbuild.success("Post-build completed successfully");
|
|
1255
|
-
const T = await x(
|
|
1256
|
-
a,
|
|
1257
|
-
o,
|
|
1258
|
-
i.outputFormat,
|
|
1259
|
-
"storage-setup",
|
|
1260
|
-
"Storage Setup",
|
|
1261
|
-
async () => Pr({ config: w })
|
|
1262
|
-
);
|
|
1263
|
-
return await x(
|
|
1264
|
-
a,
|
|
1265
|
-
o,
|
|
1266
|
-
i.outputFormat,
|
|
1267
|
-
"bindings-setup",
|
|
1268
|
-
"Bindings Setup",
|
|
1269
|
-
async () => {
|
|
1270
|
-
await zt({ config: w, storageSetup: T, isProduction: n });
|
|
1271
|
-
}
|
|
1272
|
-
), await x(
|
|
1273
|
-
a,
|
|
1274
|
-
o,
|
|
1275
|
-
i.outputFormat,
|
|
1276
|
-
"env-vars-copy",
|
|
1277
|
-
"Copy Env Vars",
|
|
1278
|
-
async () => {
|
|
1279
|
-
await et(m.production), await tt(w.applications?.[0]?.name, m.production);
|
|
1280
|
-
}
|
|
1281
|
-
), a.endSpan(l), o && (a.printToConsole(), await a.saveReport()), {
|
|
1282
|
-
config: w,
|
|
1283
|
-
ctx: m,
|
|
1284
|
-
setup: u
|
|
1285
|
-
};
|
|
1286
|
-
} catch (l) {
|
|
1287
|
-
g.error("Build process failed:", l), p.build.error(
|
|
1288
|
-
`${l instanceof Error ? l.message : String(l)}${U}`
|
|
1289
|
-
), a.markFailed(l instanceof Error ? l.message : String(l)), o && (a.printToConsole(), await a.saveReport()), process.exit(1);
|
|
1290
|
-
}
|
|
1291
|
-
};
|
|
1292
|
-
async function Dr(e) {
|
|
1293
|
-
const t = await oe() || {}, { build: r } = t, n = {
|
|
1294
|
-
preset: W({
|
|
1295
|
-
inputValue: e.preset,
|
|
1296
|
-
fileValue: r?.preset,
|
|
1297
|
-
defaultValue: _.PRESET
|
|
1298
|
-
}),
|
|
1299
|
-
entry: W({
|
|
1300
|
-
inputValue: e.entry,
|
|
1301
|
-
fileValue: r?.entry,
|
|
1302
|
-
defaultValue: _.ENTRY
|
|
1303
|
-
}),
|
|
1304
|
-
bundler: W({
|
|
1305
|
-
inputValue: void 0,
|
|
1306
|
-
fileValue: r?.bundler,
|
|
1307
|
-
defaultValue: _.BUNDLER
|
|
1308
|
-
}),
|
|
1309
|
-
polyfills: W({
|
|
1310
|
-
inputValue: r?.polyfills,
|
|
1311
|
-
fileValue: e.polyfills,
|
|
1312
|
-
defaultValue: _.POLYFILLS
|
|
1313
|
-
})
|
|
1314
|
-
}, o = {
|
|
1315
|
-
...t,
|
|
1316
|
-
build: {
|
|
1317
|
-
...n,
|
|
1318
|
-
memoryFS: t?.build?.memoryFS,
|
|
1319
|
-
extend: t?.build?.extend
|
|
1320
|
-
}
|
|
1321
|
-
};
|
|
1322
|
-
return e.production && await Dt([C.OUTPUT_BASE_PATH]), Br({
|
|
1323
|
-
config: o,
|
|
1324
|
-
options: {
|
|
1325
|
-
production: e.production,
|
|
1326
|
-
skipFrameworkBuild: e.skipFrameworkBuild,
|
|
1327
|
-
onlyGenerateConfig: e.onlyGenerateConfig,
|
|
1328
|
-
telemetry: e.telemetry
|
|
1329
|
-
}
|
|
1330
|
-
});
|
|
1331
|
-
}
|
|
1332
|
-
let ee, K = !1;
|
|
1333
|
-
const Wr = (e, t, r, n = !0) => {
|
|
1334
|
-
let o = r;
|
|
1335
|
-
const s = new RegExp(`addEventListener\\((['"]?)${e}\\1,`, "g"), i = /firewall:\s*\(event\)\s*=>\s*{/g, c = !!r.match(i), a = /eventType\s*=\s*['"]firewall['"];/g, l = !!r.match(s);
|
|
1336
|
-
return (n && l || c) && (o = r.replace(s, `addEventListener("${t}",`), c && (o = o.replace(a, "eventType = 'fetch';"))), { matchEvent: l || c, codeChanged: o };
|
|
1337
|
-
};
|
|
1338
|
-
function Mr(e) {
|
|
1339
|
-
return new Promise((t) => {
|
|
1340
|
-
const r = new Et.Socket();
|
|
1341
|
-
r.setTimeout(1e3), r.on("connect", () => {
|
|
1342
|
-
r.destroy(), t(!0);
|
|
1343
|
-
}), r.on("timeout", () => {
|
|
1344
|
-
r.destroy(), t(!1);
|
|
1345
|
-
}), r.on("error", (n) => {
|
|
1346
|
-
r.destroy(), n.message.includes("ECONNREFUSED") ? t(!1) : t(!0);
|
|
1347
|
-
}), r.connect(e, "127.0.0.1");
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
async function Lr(e) {
|
|
1351
|
-
try {
|
|
1352
|
-
return await h.access(e), await h.readFile(e, "utf8");
|
|
1353
|
-
} catch (t) {
|
|
1354
|
-
if (t.message.includes("ENOENT")) {
|
|
1355
|
-
const r = V(e);
|
|
1356
|
-
throw new Error(
|
|
1357
|
-
`Server entry file "${r}" not found. Please specify your entry point using "azion dev <path>" or create the default handler file.${U}`
|
|
1358
|
-
);
|
|
1359
|
-
}
|
|
1360
|
-
throw new Error(`Error reading file ${e}: ${t.message}${U}`);
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
async function Hr(e, t) {
|
|
1364
|
-
const { matchEvent: r, codeChanged: n } = (
|
|
1365
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1366
|
-
Wr("firewall", "fetch", t)
|
|
1367
|
-
), s = Ae(r ? n : t, r);
|
|
1368
|
-
return vt({ port: e, host: "0.0.0.0", runtime: s });
|
|
1369
|
-
}
|
|
1370
|
-
function we(e, t) {
|
|
1371
|
-
const r = e?.bindings?.storage?.bucket || t?.storage?.[0].name || "", n = e?.bindings?.storage?.prefix || t?.storage?.[0].prefix || "";
|
|
1372
|
-
return { bucketName: r, prefix: n };
|
|
1373
|
-
}
|
|
1374
|
-
function Vr(e, t, r) {
|
|
1375
|
-
const n = Object.keys(e).find((o) => {
|
|
1376
|
-
const s = o.replace(/\.dev$/, "").replace(/\.edge\//, "");
|
|
1377
|
-
return r.replace(/\.js$/, "").endsWith(s);
|
|
1378
|
-
});
|
|
1379
|
-
if (!n)
|
|
1380
|
-
throw new Error(`Entry path not found for function "${t}"`);
|
|
1381
|
-
return n;
|
|
1382
|
-
}
|
|
1383
|
-
function be(e) {
|
|
1384
|
-
return e.endsWith(".js") ? e : `${e}.js`;
|
|
1385
|
-
}
|
|
1386
|
-
function zr(e, t, r) {
|
|
1387
|
-
if (!e || Object.keys(e).length === 0)
|
|
1388
|
-
throw new Error("No entries provided");
|
|
1389
|
-
if (r) {
|
|
1390
|
-
const i = t.functions?.find((l) => l.name === r);
|
|
1391
|
-
if (!i)
|
|
1392
|
-
throw new Error(`Function "${r}" not found in edge functions configuration`);
|
|
1393
|
-
const c = Vr(e, r, i.path), a = we(i, t);
|
|
1394
|
-
return {
|
|
1395
|
-
name: i.name,
|
|
1396
|
-
bucket: a.bucketName,
|
|
1397
|
-
prefix: a.prefix,
|
|
1398
|
-
path: be(c)
|
|
1399
|
-
};
|
|
1400
|
-
}
|
|
1401
|
-
const n = Object.keys(e)[0], o = t.functions?.[0], s = we(o, t);
|
|
1402
|
-
return {
|
|
1403
|
-
name: o?.name,
|
|
1404
|
-
bucket: s.bucketName,
|
|
1405
|
-
prefix: s.prefix,
|
|
1406
|
-
path: be(n)
|
|
1407
|
-
};
|
|
1408
|
-
}
|
|
1409
|
-
async function fe(e, t, r = !1, n) {
|
|
1410
|
-
try {
|
|
1411
|
-
ee && await ee.close();
|
|
1412
|
-
const {
|
|
1413
|
-
setup: { entry: o },
|
|
1414
|
-
config: { functions: s, storage: i }
|
|
1415
|
-
} = await Dr({ production: !1, skipFrameworkBuild: r });
|
|
1416
|
-
let c;
|
|
1417
|
-
try {
|
|
1418
|
-
const {
|
|
1419
|
-
path: a,
|
|
1420
|
-
bucket: l,
|
|
1421
|
-
prefix: f
|
|
1422
|
-
} = zr(o, { functions: s, storage: i }, n);
|
|
1423
|
-
globalThis.AZION_BUCKET_NAME = l, globalThis.AZION_BUCKET_PREFIX = f, c = await Lr(a);
|
|
1424
|
-
} catch (a) {
|
|
1425
|
-
p.server.error(a.message), g.error(`Error reading worker file: ${a}`), process.exit(1);
|
|
1426
|
-
}
|
|
1427
|
-
try {
|
|
1428
|
-
ee = await Hr(t, c), p.server.success(
|
|
1429
|
-
`Function running on port 0.0.0.0:${t}, url: http://localhost:${t}`
|
|
1430
|
-
);
|
|
1431
|
-
} catch (a) {
|
|
1432
|
-
if (a.message.includes("EADDRINUSE"))
|
|
1433
|
-
await fe(e, t + 1);
|
|
1434
|
-
else
|
|
1435
|
-
throw a;
|
|
1436
|
-
}
|
|
1437
|
-
} catch (o) {
|
|
1438
|
-
p.server.error(
|
|
1439
|
-
`${o instanceof Error ? o.message : String(o)}${U}`
|
|
1440
|
-
), g.error(`Server management error: ${o}`), process.exit(1);
|
|
1441
|
-
} finally {
|
|
1442
|
-
K = !1;
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
async function Gr(e, t, r) {
|
|
1446
|
-
if (!K && !(e.startsWith(".azion-bundler") || e.startsWith("azion") && e.includes(".temp") || e.startsWith(".edge") || e.startsWith("node_modules") || e.startsWith(".vercel"))) {
|
|
1447
|
-
K = !0;
|
|
1448
|
-
try {
|
|
1449
|
-
p.build.info("Rebuilding with the new changes..."), await fe(t, r);
|
|
1450
|
-
} catch (n) {
|
|
1451
|
-
g.error(`Build or server restart failed: ${n}`);
|
|
1452
|
-
} finally {
|
|
1453
|
-
K = !1;
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
async function Ue(e, t, r = !1, n) {
|
|
1458
|
-
await Mr(t) && (p.server.error(`Port ${t} is in use. Please choose another port.`), process.exit(1)), await fe(e, t, r, n);
|
|
1459
|
-
const s = st.watch("./", {
|
|
1460
|
-
persistent: !0,
|
|
1461
|
-
ignoreInitial: !0,
|
|
1462
|
-
// Ignore the initial add events
|
|
1463
|
-
depth: 99,
|
|
1464
|
-
ignored: [".git", ".vscode", ".idea", ".sublime-text", ".history"]
|
|
1465
|
-
// Added common IDE-related folders
|
|
1466
|
-
}), i = async (c) => {
|
|
1467
|
-
await Gr(c, e, t);
|
|
1468
|
-
};
|
|
1469
|
-
s.on("add", i).on("change", i).on("unlink", i).on("addDir", i).on("unlinkDir", i).on("error", (c) => g.error(`Watcher error: ${c}`)).on("ready", () => p.server.info("Initial scan complete. Ready for changes."));
|
|
1470
|
-
}
|
|
1471
|
-
const Ee = {
|
|
1472
|
-
runtime: Ae,
|
|
1473
|
-
server: Ue,
|
|
1474
|
-
readStore: rt,
|
|
1475
|
-
readAzionConfig: oe,
|
|
1476
|
-
writeStore: Se,
|
|
1477
|
-
writeUserConfig: te
|
|
1478
|
-
};
|
|
1479
|
-
async function jn({
|
|
1480
|
-
entry: e,
|
|
1481
|
-
port: t,
|
|
1482
|
-
skipFrameworkBuild: r = !1,
|
|
1483
|
-
functionName: n
|
|
1484
|
-
}) {
|
|
1485
|
-
const o = parseInt(t, 10);
|
|
1486
|
-
Ue(e || null, o, r, n);
|
|
1487
|
-
}
|
|
1488
|
-
function ve() {
|
|
1489
|
-
return Object.values(J).filter((t) => t.metadata?.name).map((t) => t.metadata.name);
|
|
1490
|
-
}
|
|
1491
|
-
function qr(e) {
|
|
1492
|
-
const t = J[e];
|
|
1493
|
-
if (!t)
|
|
1494
|
-
throw new Error(
|
|
1495
|
-
`Preset '${e}' not found. Run 'ef presets ls' to see available presets.`
|
|
1496
|
-
);
|
|
1497
|
-
return t.config;
|
|
1498
|
-
}
|
|
1499
|
-
async function Un(e, t = {}) {
|
|
1500
|
-
const r = process.env.CLEAN_OUTPUT_MODE === "true";
|
|
1501
|
-
switch (e) {
|
|
1502
|
-
case "ls":
|
|
1503
|
-
r && ve().forEach((n) => console.log(n?.toLowerCase())), r || ve().forEach((n) => p.option(n));
|
|
1504
|
-
break;
|
|
1505
|
-
case "config":
|
|
1506
|
-
if (!t.preset) {
|
|
1507
|
-
p.error("Preset name is required. Use: ef presets config <preset-name>");
|
|
1508
|
-
return;
|
|
1509
|
-
}
|
|
1510
|
-
try {
|
|
1511
|
-
const n = qr(t.preset);
|
|
1512
|
-
console.log(JSON.stringify(n, null, 2));
|
|
1513
|
-
} catch (n) {
|
|
1514
|
-
p.error(n instanceof Error ? n.message : "Unknown error occurred");
|
|
1515
|
-
}
|
|
1516
|
-
break;
|
|
1517
|
-
default:
|
|
1518
|
-
p.error("Invalid argument provided. Available commands: ls, config");
|
|
1519
|
-
break;
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
function Kr(e) {
|
|
1523
|
-
return ct(e);
|
|
1524
|
-
}
|
|
1525
|
-
const Jr = { processConfigWrapper: Kr }, Xr = ".edge/manifest.json", Yr = "azion.config", Zr = async (e, t = k(process.cwd(), ".edge")) => {
|
|
1526
|
-
try {
|
|
1527
|
-
await z.access(t);
|
|
1528
|
-
} catch {
|
|
1529
|
-
await z.mkdir(t, { recursive: !0 });
|
|
1530
|
-
}
|
|
1531
|
-
let r;
|
|
1532
|
-
if (typeof e == "object")
|
|
1533
|
-
r = e;
|
|
1534
|
-
else {
|
|
1535
|
-
const s = await $e.readAzionConfig(e);
|
|
1536
|
-
if (!s)
|
|
1537
|
-
throw new Error(
|
|
1538
|
-
e ? `Failed to load config from ${e}` : "No configuration found. Please provide a config file or object."
|
|
1539
|
-
);
|
|
1540
|
-
r = s;
|
|
1541
|
-
}
|
|
1542
|
-
re(r);
|
|
1543
|
-
const n = Jr.processConfigWrapper(r), o = k(t, "manifest.json");
|
|
1544
|
-
await z.writeFile(o, JSON.stringify(n, null, 2)), O.feedback.manifest.success(`Manifest generated successfully at ${o}`);
|
|
1545
|
-
}, Qr = async (e, t = Yr) => {
|
|
1546
|
-
const n = await (async (o) => {
|
|
1547
|
-
const s = ae(process.cwd(), o);
|
|
1548
|
-
if (I(s) !== ".json")
|
|
1549
|
-
throw new Error("Input file must be .json");
|
|
1550
|
-
const i = await z.readFile(s, "utf8");
|
|
1551
|
-
return lt(i);
|
|
1552
|
-
})(e || Xr);
|
|
1553
|
-
await $e.writeUserConfig(n, t), O.feedback.manifest.success(`Config file generated successfully at ${t}`);
|
|
1554
|
-
};
|
|
1555
|
-
async function Rn(e) {
|
|
1556
|
-
try {
|
|
1557
|
-
const t = e.action || "generate", n = {
|
|
1558
|
-
generate: async () => {
|
|
1559
|
-
const o = e.entry || e.config;
|
|
1560
|
-
await Zr(o, e.output);
|
|
1561
|
-
},
|
|
1562
|
-
transform: async () => {
|
|
1563
|
-
await Qr(e.entry, e.output);
|
|
1564
|
-
}
|
|
1565
|
-
}[t];
|
|
1566
|
-
n && await n(), n || (p.manifest.error(
|
|
1567
|
-
"Only transform and generate actions are supported"
|
|
1568
|
-
), process.exit(1));
|
|
1569
|
-
} catch (t) {
|
|
1570
|
-
g.error(t), p.error(`${t instanceof Error ? t.message : String(t)}${U}`), await ie(C.OUTPUT_BASE_PATH, { recursive: !0, force: !0 }), process.exit(1);
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
async function Nn({ command: e, options: t }) {
|
|
1574
|
-
const r = JSON.parse(
|
|
1575
|
-
typeof t.config == "string" ? t.config : "{}"
|
|
1576
|
-
), n = t.scope || "global";
|
|
1577
|
-
try {
|
|
1578
|
-
switch (e) {
|
|
1579
|
-
case "init": {
|
|
1580
|
-
const o = { ...r };
|
|
1581
|
-
await Se(o, n), p.info(`Store file initialized with scope: ${n}`);
|
|
1582
|
-
break;
|
|
1583
|
-
}
|
|
1584
|
-
case "destroy":
|
|
1585
|
-
await ie(globalThis.bundler.tempPath, { recursive: !0, force: !0 }), p.info("Temporary store directory removed");
|
|
1586
|
-
break;
|
|
1587
|
-
default:
|
|
1588
|
-
throw new Error(`Invalid command: ${e}`);
|
|
1589
|
-
}
|
|
1590
|
-
} catch (o) {
|
|
1591
|
-
p.error(`${o instanceof Error ? o.message : String(o)}${U}`), process.exit(1);
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
function se(e) {
|
|
1595
|
-
if (typeof e != "string")
|
|
1596
|
-
return e;
|
|
1597
|
-
const t = e.trim();
|
|
1598
|
-
if (!t.startsWith("{") && !t.startsWith("["))
|
|
1599
|
-
return e;
|
|
1600
|
-
try {
|
|
1601
|
-
return JSON.parse(e);
|
|
1602
|
-
} catch {
|
|
1603
|
-
return e;
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
async function en() {
|
|
1607
|
-
const t = await St("azion", {
|
|
1608
|
-
searchPlaces: [
|
|
1609
|
-
"azion.config.ts",
|
|
1610
|
-
"azion.config.mts",
|
|
1611
|
-
"azion.config.cts",
|
|
1612
|
-
"azion.config.js",
|
|
1613
|
-
"azion.config.mjs",
|
|
1614
|
-
"azion.config.cjs",
|
|
1615
|
-
"azion.config.json"
|
|
1616
|
-
],
|
|
1617
|
-
loaders: {
|
|
1618
|
-
".ts": Y(),
|
|
1619
|
-
".mts": Y(),
|
|
1620
|
-
".cts": Y()
|
|
1621
|
-
}
|
|
1622
|
-
}).search();
|
|
1623
|
-
if (!t)
|
|
1624
|
-
throw new Error("No azion config file found");
|
|
1625
|
-
const r = t.filepath, n = await h.readFile(r, "utf8");
|
|
1626
|
-
return { configPath: r, fileContent: n };
|
|
1627
|
-
}
|
|
1628
|
-
const Re = {
|
|
1629
|
-
findAndReadConfigFile: en,
|
|
1630
|
-
tryParseJSON: se
|
|
1631
|
-
};
|
|
1632
|
-
function tn(e) {
|
|
1633
|
-
const t = {}, r = e.key.split(".");
|
|
1634
|
-
let n = t;
|
|
1635
|
-
for (let o = 0; o < r.length; o++) {
|
|
1636
|
-
const s = r[o], i = s.match(/^(.+)\[(\d+)\]$/);
|
|
1637
|
-
if (i) {
|
|
1638
|
-
const c = i[1], a = parseInt(i[2]);
|
|
1639
|
-
o === r.length - 1 ? (n[c] || (n[c] = []), n[c][a] = se(e.value)) : (n[c] || (n[c] = []), n[c][a] || (n[c][a] = {}), n = n[c][a]);
|
|
1640
|
-
} else
|
|
1641
|
-
o === r.length - 1 ? n[s] = se(e.value) : (n[s] || (n[s] = {}), n = n[s]);
|
|
1642
|
-
}
|
|
1643
|
-
return t;
|
|
1644
|
-
}
|
|
1645
|
-
function rn(e) {
|
|
1646
|
-
if (!e.config)
|
|
1647
|
-
throw new Error("Config is required for read");
|
|
1648
|
-
const t = e.config, r = e.key.split(".").flatMap((o) => {
|
|
1649
|
-
const s = o.match(/^(.+)\[(\d+)\]$/);
|
|
1650
|
-
return s ? [s[1], parseInt(s[2])] : [o];
|
|
1651
|
-
});
|
|
1652
|
-
let n = t;
|
|
1653
|
-
for (let o = 0; o < r.length; o++) {
|
|
1654
|
-
const s = r[o], i = r[o + 1];
|
|
1655
|
-
if (typeof s == "number") {
|
|
1656
|
-
if (!Array.isArray(n))
|
|
1657
|
-
throw new Error("Property is not an array");
|
|
1658
|
-
if (!n[s])
|
|
1659
|
-
throw new Error(`Array index ${s} does not exist`);
|
|
1660
|
-
n = n[s];
|
|
1661
|
-
} else {
|
|
1662
|
-
if (!(s in n))
|
|
1663
|
-
throw new Error(`Property '${s}' does not exist`);
|
|
1664
|
-
if (typeof i == "number") {
|
|
1665
|
-
if (!Array.isArray(n[s]))
|
|
1666
|
-
throw new Error(`Property '${s}' is not an array`);
|
|
1667
|
-
if (!n[s][i])
|
|
1668
|
-
throw new Error(`Array index ${i} does not exist in '${s}'`);
|
|
1669
|
-
n = n[s][i], o++;
|
|
1670
|
-
} else
|
|
1671
|
-
n = n[s];
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
return n;
|
|
1675
|
-
}
|
|
1676
|
-
function nn(e) {
|
|
1677
|
-
if (!e.config)
|
|
1678
|
-
throw new Error("Config is required for delete");
|
|
1679
|
-
const t = { ...e.config }, r = e.key.split(".");
|
|
1680
|
-
let n = t;
|
|
1681
|
-
for (let i = 0; i < r.length - 1; i++) {
|
|
1682
|
-
const c = r[i], a = c.match(/^(.+)\[(\d+)\]$/);
|
|
1683
|
-
if (a) {
|
|
1684
|
-
const l = a[1], f = parseInt(a[2]);
|
|
1685
|
-
if (!n[l])
|
|
1686
|
-
throw new Error(`Property '${l}' does not exist`);
|
|
1687
|
-
if (!Array.isArray(n[l]))
|
|
1688
|
-
throw new Error(`Property '${l}' is not an array`);
|
|
1689
|
-
if (f >= n[l].length)
|
|
1690
|
-
throw new Error(`Array index ${f} does not exist in '${l}'`);
|
|
1691
|
-
n = n[l][f];
|
|
1692
|
-
} else {
|
|
1693
|
-
if (!n[c])
|
|
1694
|
-
throw new Error(`Property '${c}' does not exist`);
|
|
1695
|
-
n = n[c];
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
const o = r[r.length - 1], s = o.match(/^(.+)\[(\d+)\]$/);
|
|
1699
|
-
if (s) {
|
|
1700
|
-
const i = s[1], c = parseInt(s[2]);
|
|
1701
|
-
if (!n[i])
|
|
1702
|
-
throw new Error(`Property '${i}' does not exist`);
|
|
1703
|
-
if (!Array.isArray(n[i]))
|
|
1704
|
-
throw new Error(`Property '${i}' is not an array`);
|
|
1705
|
-
if (c >= n[i].length)
|
|
1706
|
-
throw new Error(`Array index ${c} does not exist in '${i}'`);
|
|
1707
|
-
n[i].splice(c, 1);
|
|
1708
|
-
} else {
|
|
1709
|
-
if (!(o in n))
|
|
1710
|
-
throw new Error(`Property '${o}' does not exist`);
|
|
1711
|
-
delete n[o];
|
|
1712
|
-
}
|
|
1713
|
-
return t;
|
|
1714
|
-
}
|
|
1715
|
-
function sn(e) {
|
|
1716
|
-
const t = e.match(
|
|
1717
|
-
/^\s*export\s+default\s+defineConfig\s*\(\s*/m
|
|
1718
|
-
), r = e.match(
|
|
1719
|
-
/^\s*module\.exports\s*=\s*defineConfig\s*\(\s*/m
|
|
1720
|
-
), n = e.match(/^\s*export\s+default\s+/m), o = e.match(/^\s*module\.exports\s*=\s*/m);
|
|
1721
|
-
let s = -1;
|
|
1722
|
-
if (t)
|
|
1723
|
-
s = t.index + t[0].length;
|
|
1724
|
-
else if (r)
|
|
1725
|
-
s = r.index + r[0].length;
|
|
1726
|
-
else if (n) {
|
|
1727
|
-
const w = n.index + n[0].length;
|
|
1728
|
-
let d = w;
|
|
1729
|
-
for (; d < e.length && e[d].match(/\s/); )
|
|
1730
|
-
d++;
|
|
1731
|
-
const y = e.slice(d).match(/^defineConfig\s*\(\s*/);
|
|
1732
|
-
y ? s = d + y[0].length : s = w;
|
|
1733
|
-
} else if (o) {
|
|
1734
|
-
const w = o.index + o[0].length;
|
|
1735
|
-
let d = w;
|
|
1736
|
-
for (; d < e.length && e[d].match(/\s/); )
|
|
1737
|
-
d++;
|
|
1738
|
-
const y = e.slice(d).match(/^defineConfig\s*\(\s*/);
|
|
1739
|
-
y ? s = d + y[0].length : s = w;
|
|
1740
|
-
}
|
|
1741
|
-
if (s === -1)
|
|
1742
|
-
throw new Error("Could not find module.exports or export default in config file");
|
|
1743
|
-
let i = s;
|
|
1744
|
-
for (; i < e.length && e[i].match(/\s/); )
|
|
1745
|
-
i++;
|
|
1746
|
-
if (i >= e.length)
|
|
1747
|
-
throw new Error("Could not find opening brace or parenthesis for config object");
|
|
1748
|
-
const c = e[i], a = c === "{" ? "}" : c === "(" ? ")" : null;
|
|
1749
|
-
if (!a)
|
|
1750
|
-
throw new Error("Config object must start with { or (");
|
|
1751
|
-
let l = 1, f = !1, u = "", m = e.length;
|
|
1752
|
-
for (let w = i + 1; w < e.length; w++) {
|
|
1753
|
-
const d = e[w], y = w > 0 ? e[w - 1] : "";
|
|
1754
|
-
if ((d === '"' || d === "'" || d === "`") && y !== "\\") {
|
|
1755
|
-
f ? d === u && (f = !1, u = "") : (f = !0, u = d);
|
|
1756
|
-
continue;
|
|
1757
|
-
}
|
|
1758
|
-
if (!f && (d === c ? l++ : d === a && l--, l === 0)) {
|
|
1759
|
-
m = w + 1;
|
|
1760
|
-
break;
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
return { start: s, end: m };
|
|
1764
|
-
}
|
|
1765
|
-
async function on(e, t) {
|
|
1766
|
-
try {
|
|
1767
|
-
const r = Array.isArray(e) ? e : [{ placeholder: e, value: t }];
|
|
1768
|
-
for (const { placeholder: d, value: y } of r)
|
|
1769
|
-
if (typeof d != "string" || typeof y != "string")
|
|
1770
|
-
throw new Error("Placeholder and value must be strings");
|
|
1771
|
-
const { configPath: n, fileContent: o } = await Re.findAndReadConfigFile(), { start: s, end: i } = sn(o), c = o.slice(0, s);
|
|
1772
|
-
let a = o.slice(s, i);
|
|
1773
|
-
const l = o.slice(i), f = /* @__PURE__ */ new Map();
|
|
1774
|
-
for (const { placeholder: d, value: y } of r) {
|
|
1775
|
-
let T = 0, E = 0;
|
|
1776
|
-
for (; E < a.length; ) {
|
|
1777
|
-
const b = a.indexOf(d, E);
|
|
1778
|
-
if (b === -1) break;
|
|
1779
|
-
const v = b > 0 ? a[b - 1] : "", j = b + d.length < a.length ? a[b + d.length] : "";
|
|
1780
|
-
let B = !0;
|
|
1781
|
-
if (typeof d == "string" && d.match(/[A-Za-z0-9_$]/)) {
|
|
1782
|
-
const P = v && v.match(/[A-Za-z0-9_$]/), $ = j && j.match(/[A-Za-z0-9_]/);
|
|
1783
|
-
(P || $) && (B = !1);
|
|
1784
|
-
}
|
|
1785
|
-
B ? (a = a.slice(0, b) + y + a.slice(b + d.length), E = b + y.length, T++) : E = b + 1;
|
|
1786
|
-
}
|
|
1787
|
-
T > 0 && f.set(d, T);
|
|
1788
|
-
}
|
|
1789
|
-
const u = c + a + l;
|
|
1790
|
-
let m;
|
|
1791
|
-
try {
|
|
1792
|
-
m = await Ce.format(u, {
|
|
1793
|
-
parser: "babel",
|
|
1794
|
-
semi: !1,
|
|
1795
|
-
singleQuote: !0,
|
|
1796
|
-
trailingComma: "none"
|
|
1797
|
-
});
|
|
1798
|
-
} catch {
|
|
1799
|
-
m = u;
|
|
1800
|
-
}
|
|
1801
|
-
await h.writeFile(n, m, "utf8");
|
|
1802
|
-
const w = Array.from(f.values()).reduce((d, y) => d + y, 0);
|
|
1803
|
-
if (w === 0)
|
|
1804
|
-
p.info(`No placeholders found to replace in ${S.basename(n)}`);
|
|
1805
|
-
else if (f.size === 1) {
|
|
1806
|
-
const [d, y] = Array.from(f.entries())[0], T = r.find((E) => E.placeholder === d);
|
|
1807
|
-
p.info(
|
|
1808
|
-
`Successfully replaced "${d}" with "${T?.value}" (${y} occurrence${y > 1 ? "s" : ""}) in ${S.basename(n)}`
|
|
1809
|
-
);
|
|
1810
|
-
} else {
|
|
1811
|
-
const d = Array.from(f.entries()).map(([y, T]) => {
|
|
1812
|
-
const E = r.find((b) => b.placeholder === y);
|
|
1813
|
-
return `"${y}" -> "${E?.value}" (${T})`;
|
|
1814
|
-
}).join(", ");
|
|
1815
|
-
p.info(
|
|
1816
|
-
`Successfully replaced ${w} occurrences of ${f.size} placeholders (${d}) in ${S.basename(n)}`
|
|
1817
|
-
);
|
|
1818
|
-
}
|
|
1819
|
-
} catch (r) {
|
|
1820
|
-
throw new Error(
|
|
1821
|
-
`Failed to replace in config file: ${r instanceof Error ? r.message : String(r)}`
|
|
1822
|
-
);
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
async function an(e, t) {
|
|
1826
|
-
try {
|
|
1827
|
-
const { configPath: r, fileContent: n } = await Re.findAndReadConfigFile(), o = cn(n, e, t);
|
|
1828
|
-
let s;
|
|
1829
|
-
try {
|
|
1830
|
-
s = await Ce.format(o, {
|
|
1831
|
-
parser: "babel",
|
|
1832
|
-
semi: !1,
|
|
1833
|
-
singleQuote: !0,
|
|
1834
|
-
trailingComma: "none"
|
|
1835
|
-
});
|
|
1836
|
-
} catch {
|
|
1837
|
-
s = o;
|
|
1838
|
-
}
|
|
1839
|
-
await h.writeFile(r, s, "utf8"), O.feedback.info(
|
|
1840
|
-
`Successfully updated "${e}" to "${t}" in ${S.basename(r)}`
|
|
1841
|
-
);
|
|
1842
|
-
} catch (r) {
|
|
1843
|
-
throw new Error(
|
|
1844
|
-
`Failed to update config file: ${r instanceof Error ? r.message : String(r)}`
|
|
1845
|
-
);
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
function cn(e, t, r) {
|
|
1849
|
-
return ln(e, t, r);
|
|
1850
|
-
}
|
|
1851
|
-
function ln(e, t, r) {
|
|
1852
|
-
const n = un(r), o = e.replace(/\n\s*/g, " ").replace(/\s+/g, " "), s = o.match(
|
|
1853
|
-
/(.*(?:module\.exports\s*=(?:\s+\w+\()?|export default(?:\s+\w+\()?)\s*)\{/
|
|
1854
|
-
);
|
|
1855
|
-
if (!s)
|
|
1856
|
-
return e;
|
|
1857
|
-
const i = s[0].length;
|
|
1858
|
-
let c = 1, a = i, l = !1, f = "";
|
|
1859
|
-
for (let P = i; P < o.length && c > 0; P++) {
|
|
1860
|
-
const $ = o[P];
|
|
1861
|
-
if (l ? $ === f && o[P - 1] !== "\\" && (l = !1) : $ === '"' || $ === "'" ? (l = !0, f = $) : $ === "{" ? c++ : $ === "}" && c--, c === 0) {
|
|
1862
|
-
a = P;
|
|
1863
|
-
break;
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
if (c !== 0)
|
|
1867
|
-
return e;
|
|
1868
|
-
const u = o.substring(i, a), m = fn(t), w = ue(u, m, n), d = e.match(
|
|
1869
|
-
/(.*(?:module\.exports\s*=(?:\s+\w+\()?|export default(?:\s+\w+\()?)\s*)\{/s
|
|
1870
|
-
);
|
|
1871
|
-
if (!d)
|
|
1872
|
-
return e;
|
|
1873
|
-
const y = d[1] + "{", T = d[0].length;
|
|
1874
|
-
let E = 1, b = T, v = !1, j = "";
|
|
1875
|
-
for (let P = T; P < e.length && E > 0; P++) {
|
|
1876
|
-
const $ = e[P];
|
|
1877
|
-
if (v ? $ === j && e[P - 1] !== "\\" && (v = !1) : $ === '"' || $ === "'" ? (v = !0, j = $) : $ === "{" ? E++ : $ === "}" && E--, E === 0) {
|
|
1878
|
-
b = P;
|
|
1879
|
-
break;
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
const B = "}" + e.substring(b + 1);
|
|
1883
|
-
return y + w + B;
|
|
1884
|
-
}
|
|
1885
|
-
function fn(e) {
|
|
1886
|
-
const t = [];
|
|
1887
|
-
let r = "", n = 0;
|
|
1888
|
-
for (; n < e.length; ) {
|
|
1889
|
-
const o = e[n];
|
|
1890
|
-
if (o === ".")
|
|
1891
|
-
r && (t.push(r), r = "");
|
|
1892
|
-
else if (o === "[") {
|
|
1893
|
-
r && (t.push(r), r = ""), n++;
|
|
1894
|
-
let s = "";
|
|
1895
|
-
for (; n < e.length && e[n] !== "]"; )
|
|
1896
|
-
s += e[n], n++;
|
|
1897
|
-
t.push(parseInt(s));
|
|
1898
|
-
} else
|
|
1899
|
-
r += o;
|
|
1900
|
-
n++;
|
|
1901
|
-
}
|
|
1902
|
-
return r && t.push(r), t;
|
|
1903
|
-
}
|
|
1904
|
-
function ue(e, t, r) {
|
|
1905
|
-
if (t.length === 0) return e;
|
|
1906
|
-
const [n, ...o] = t;
|
|
1907
|
-
if (typeof n == "string") {
|
|
1908
|
-
const s = n.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
1909
|
-
if (o.length === 0) {
|
|
1910
|
-
const i = new RegExp(`(${s}\\s*:\\s*)([^,}]+)`);
|
|
1911
|
-
return e.replace(i, `$1${r}`);
|
|
1912
|
-
} else {
|
|
1913
|
-
const i = e.match(
|
|
1914
|
-
new RegExp(`(.*${s}\\s*:\\s*)([^,}]+)(.*)`)
|
|
1915
|
-
);
|
|
1916
|
-
if (i) {
|
|
1917
|
-
const [, , c] = i;
|
|
1918
|
-
if (c.trim().startsWith("{")) {
|
|
1919
|
-
const a = e.indexOf(c.trim());
|
|
1920
|
-
if (a === -1)
|
|
1921
|
-
return e;
|
|
1922
|
-
let l = 0, f = !1, u = "", m = -1;
|
|
1923
|
-
for (let b = a; b < e.length; b++) {
|
|
1924
|
-
const v = e[b];
|
|
1925
|
-
if (f)
|
|
1926
|
-
v === u && e[b - 1] !== "\\" && (f = !1);
|
|
1927
|
-
else if (v === '"' || v === "'")
|
|
1928
|
-
f = !0, u = v;
|
|
1929
|
-
else if (v === "{")
|
|
1930
|
-
l++;
|
|
1931
|
-
else if (v === "}" && (l--, l === 0)) {
|
|
1932
|
-
m = b;
|
|
1933
|
-
break;
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
if (m === -1)
|
|
1937
|
-
return e;
|
|
1938
|
-
const d = e.substring(a, m + 1).slice(1, -1), y = ue(d, o, r), T = e.substring(0, a), E = e.substring(m + 1);
|
|
1939
|
-
return T + `{ ${y} }` + E;
|
|
1940
|
-
} else if (c.trim().startsWith("[")) {
|
|
1941
|
-
const a = e.indexOf(c.trim());
|
|
1942
|
-
if (a === -1)
|
|
1943
|
-
return e;
|
|
1944
|
-
let l = 0, f = !1, u = "", m = -1;
|
|
1945
|
-
for (let b = a; b < e.length; b++) {
|
|
1946
|
-
const v = e[b];
|
|
1947
|
-
if (f)
|
|
1948
|
-
v === u && e[b - 1] !== "\\" && (f = !1);
|
|
1949
|
-
else if (v === '"' || v === "'")
|
|
1950
|
-
f = !0, u = v;
|
|
1951
|
-
else if (v === "[")
|
|
1952
|
-
l++;
|
|
1953
|
-
else if (v === "]" && (l--, l === 0)) {
|
|
1954
|
-
m = b;
|
|
1955
|
-
break;
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
if (m === -1)
|
|
1959
|
-
return e;
|
|
1960
|
-
const d = e.substring(a, m + 1).slice(1, -1), y = Te(d, o, r), T = e.substring(0, a), E = e.substring(m + 1);
|
|
1961
|
-
return T + `[ ${y} ]` + E;
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
} else if (typeof n == "number")
|
|
1966
|
-
return Te(e, t, r);
|
|
1967
|
-
return e;
|
|
1968
|
-
}
|
|
1969
|
-
function Te(e, t, r) {
|
|
1970
|
-
if (t.length === 0) return e;
|
|
1971
|
-
const [n, ...o] = t;
|
|
1972
|
-
if (typeof n != "number") return e;
|
|
1973
|
-
const s = [];
|
|
1974
|
-
let i = 0;
|
|
1975
|
-
for (; i < e.length; ) {
|
|
1976
|
-
for (; i < e.length && /\s/.test(e[i]); )
|
|
1977
|
-
i++;
|
|
1978
|
-
if (i >= e.length) break;
|
|
1979
|
-
if (e[i] === "{") {
|
|
1980
|
-
let c = 0, a = !1, l = "";
|
|
1981
|
-
const f = i;
|
|
1982
|
-
for (; i < e.length; ) {
|
|
1983
|
-
const u = e[i];
|
|
1984
|
-
if (a)
|
|
1985
|
-
u === l && e[i - 1] !== "\\" && (a = !1);
|
|
1986
|
-
else if (u === '"' || u === "'")
|
|
1987
|
-
a = !0, l = u;
|
|
1988
|
-
else if (u === "{")
|
|
1989
|
-
c++;
|
|
1990
|
-
else if (u === "}" && (c--, c === 0)) {
|
|
1991
|
-
const m = e.substring(f, i + 1);
|
|
1992
|
-
for (s.push(m.trim()), i++; i < e.length && /[\s,]/.test(e[i]); )
|
|
1993
|
-
i++;
|
|
1994
|
-
break;
|
|
1995
|
-
}
|
|
1996
|
-
i++;
|
|
1997
|
-
}
|
|
1998
|
-
} else {
|
|
1999
|
-
const c = i;
|
|
2000
|
-
let a = !1, l = "";
|
|
2001
|
-
for (; i < e.length; ) {
|
|
2002
|
-
const f = e[i];
|
|
2003
|
-
if (a)
|
|
2004
|
-
f === l && e[i - 1] !== "\\" && (a = !1);
|
|
2005
|
-
else if (f === '"' || f === "'")
|
|
2006
|
-
a = !0, l = f;
|
|
2007
|
-
else if (f === ",") {
|
|
2008
|
-
const u = e.substring(c, i);
|
|
2009
|
-
for (s.push(u.trim()), i++; i < e.length && /\s/.test(e[i]); )
|
|
2010
|
-
i++;
|
|
2011
|
-
break;
|
|
2012
|
-
}
|
|
2013
|
-
i++;
|
|
2014
|
-
}
|
|
2015
|
-
if (i >= e.length && c < e.length) {
|
|
2016
|
-
const f = e.substring(c);
|
|
2017
|
-
f.trim() && s.push(f.trim());
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
if (n < s.length)
|
|
2022
|
-
if (o.length === 0)
|
|
2023
|
-
s[n] = r;
|
|
2024
|
-
else {
|
|
2025
|
-
const c = s[n];
|
|
2026
|
-
if (c.startsWith("{") && c.endsWith("}")) {
|
|
2027
|
-
const a = c.slice(1, -1), l = ue(a, o, r);
|
|
2028
|
-
s[n] = `{ ${l} }`;
|
|
2029
|
-
}
|
|
2030
|
-
}
|
|
2031
|
-
return s.join(", ");
|
|
2032
|
-
}
|
|
2033
|
-
function un(e) {
|
|
2034
|
-
if (typeof e == "string") {
|
|
2035
|
-
if (e.startsWith('"') && e.endsWith('"') || e.startsWith("'") && e.endsWith("'"))
|
|
2036
|
-
return e;
|
|
2037
|
-
const t = e.trim();
|
|
2038
|
-
return t.startsWith("{") && t.endsWith("}") || t.startsWith("[") && t.endsWith("]") || e.includes("=>") || e.trim().startsWith("function") ? e : `'${e}'`;
|
|
2039
|
-
}
|
|
2040
|
-
return String(e);
|
|
2041
|
-
}
|
|
2042
|
-
async function In({ command: e, options: t }) {
|
|
2043
|
-
try {
|
|
2044
|
-
const r = await oe();
|
|
2045
|
-
if (t.all) {
|
|
2046
|
-
let l;
|
|
2047
|
-
switch (e) {
|
|
2048
|
-
case "read":
|
|
2049
|
-
return l = r || {}, console.log(JSON.stringify(l, null, 2)), l;
|
|
2050
|
-
case "delete":
|
|
2051
|
-
return await te({}), {};
|
|
2052
|
-
default:
|
|
2053
|
-
throw new Error("--all flag is only supported for read and delete commands");
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
const n = Array.isArray(t.key) ? t.key : t.key ? [t.key] : [], o = Array.isArray(t.value) ? t.value : t.value !== void 0 ? [t.value] : [];
|
|
2057
|
-
if (n.length === 0 && e !== "replace")
|
|
2058
|
-
throw new Error("Key is required when --all is not used");
|
|
2059
|
-
const s = n[0], i = o[0];
|
|
2060
|
-
let c, a;
|
|
2061
|
-
switch (e) {
|
|
2062
|
-
case "create":
|
|
2063
|
-
if (r)
|
|
2064
|
-
throw new Error("Configuration already exists. Use update command instead.");
|
|
2065
|
-
if (i === void 0)
|
|
2066
|
-
throw new Error("Value is required for create command");
|
|
2067
|
-
c = tn({
|
|
2068
|
-
key: s,
|
|
2069
|
-
value: i
|
|
2070
|
-
});
|
|
2071
|
-
break;
|
|
2072
|
-
case "update":
|
|
2073
|
-
if (!r)
|
|
2074
|
-
throw new Error("No configuration found. Use create command first.");
|
|
2075
|
-
if (i === void 0)
|
|
2076
|
-
throw new Error("Value is required for update command");
|
|
2077
|
-
return await an(s, i), {};
|
|
2078
|
-
case "read":
|
|
2079
|
-
if (!r)
|
|
2080
|
-
throw new Error("No configuration found");
|
|
2081
|
-
return a = rn({
|
|
2082
|
-
key: s,
|
|
2083
|
-
config: r
|
|
2084
|
-
}), a;
|
|
2085
|
-
case "delete":
|
|
2086
|
-
if (!r)
|
|
2087
|
-
throw new Error("No configuration found");
|
|
2088
|
-
c = nn({
|
|
2089
|
-
key: s,
|
|
2090
|
-
config: r
|
|
2091
|
-
});
|
|
2092
|
-
break;
|
|
2093
|
-
case "replace": {
|
|
2094
|
-
const l = [];
|
|
2095
|
-
if (t.replacements) {
|
|
2096
|
-
let f;
|
|
2097
|
-
if (typeof t.replacements == "string")
|
|
2098
|
-
try {
|
|
2099
|
-
f = JSON.parse(t.replacements);
|
|
2100
|
-
} catch {
|
|
2101
|
-
try {
|
|
2102
|
-
const u = t.replacements.replace(/\\"/g, '"');
|
|
2103
|
-
f = JSON.parse(u);
|
|
2104
|
-
} catch (u) {
|
|
2105
|
-
const m = u instanceof Error ? u.message : String(u);
|
|
2106
|
-
throw new Error(
|
|
2107
|
-
`Invalid JSON format for --replacements option: ${m}. Received: ${t.replacements}`
|
|
2108
|
-
);
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
2111
|
-
else if (typeof t.replacements == "object")
|
|
2112
|
-
f = t.replacements;
|
|
2113
|
-
else
|
|
2114
|
-
throw new Error("Invalid format for --replacements option");
|
|
2115
|
-
for (const [u, m] of Object.entries(f))
|
|
2116
|
-
l.push({ placeholder: u, value: String(m) });
|
|
2117
|
-
} else if (n.length > 0 && o.length > 0)
|
|
2118
|
-
for (let f = 0; f < Math.min(n.length, o.length); f++)
|
|
2119
|
-
l.push({ placeholder: n[f], value: String(o[f]) });
|
|
2120
|
-
if (l.length === 0)
|
|
2121
|
-
throw new Error(
|
|
2122
|
-
"Replacements are required for replace command. Use -k/-v pairs or --replacements JSON"
|
|
2123
|
-
);
|
|
2124
|
-
return await on(l), {};
|
|
2125
|
-
}
|
|
2126
|
-
default:
|
|
2127
|
-
throw new Error(`Unknown command: ${e}`);
|
|
2128
|
-
}
|
|
2129
|
-
return await te(c), c;
|
|
2130
|
-
} catch (r) {
|
|
2131
|
-
g.error(r), p.error(`${r instanceof Error ? r.message : String(r)}`), process.exit(1);
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
async function Bn(e = {}) {
|
|
2135
|
-
const t = e.path || k(C.OUTPUT_BASE_PATH, "telemetry-report.html");
|
|
2136
|
-
ke(t) || (p.error(
|
|
2137
|
-
`Telemetry report not found at: ${t}
|
|
2138
|
-
|
|
2139
|
-
Make sure you have run a build with the --telemetry flag first.
|
|
2140
|
-
Example: ef build --telemetry html
|
|
2141
|
-
Or: ef build --telemetry`
|
|
2142
|
-
), process.exit(1));
|
|
2143
|
-
try {
|
|
2144
|
-
const r = process.platform;
|
|
2145
|
-
let n;
|
|
2146
|
-
r === "darwin" ? n = `open "${t}"` : r === "win32" ? n = `start "" "${t}"` : n = `xdg-open "${t}"`;
|
|
2147
|
-
const { exec: o } = await import("child_process");
|
|
2148
|
-
o(n, (s) => {
|
|
2149
|
-
s && (p.error(`Failed to open telemetry report: ${s.message}`), process.exit(1)), p.success(`Opened telemetry report: ${t}`);
|
|
2150
|
-
});
|
|
2151
|
-
} catch (r) {
|
|
2152
|
-
p.error(
|
|
2153
|
-
`Failed to open telemetry report: ${r instanceof Error ? r.message : "Unknown error"}`
|
|
2154
|
-
), process.exit(1);
|
|
2155
|
-
}
|
|
2156
|
-
}
|
|
2157
|
-
export {
|
|
2158
|
-
Dr as buildCommand,
|
|
2159
|
-
In as configCommand,
|
|
2160
|
-
jn as devCommand,
|
|
2161
|
-
Rn as manifestCommand,
|
|
2162
|
-
Un as presetsCommand,
|
|
2163
|
-
Nn as storeCommand,
|
|
2164
|
-
Bn as telemetryCommand
|
|
2165
|
-
};
|