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