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