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