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