edge-functions 7.1.0 → 7.1.1-stage.1
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-Ceyfl122.js → index-Duj5i8yE.js} +491 -489
- package/dist/index.js +6 -6
- package/package.json +2 -2
|
@@ -10,44 +10,44 @@ import u, { rm as Q, mkdir as ye, readFile as Je, stat as Xe, writeFile as Ze }
|
|
|
10
10
|
import { validateConfig as oe, processConfig as Ye, convertJsonConfigToObject as Qe } from "azion/config";
|
|
11
11
|
import * as j from "azion/presets";
|
|
12
12
|
import ae, { promises as D } from "fs";
|
|
13
|
-
import { listFrameworks as
|
|
14
|
-
import { createAzionWebpackConfig as
|
|
15
|
-
import
|
|
13
|
+
import { listFrameworks as et } from "@netlify/framework-info";
|
|
14
|
+
import { createAzionWebpackConfig as tt, executeWebpackBuild as rt, executeESBuildBuild as nt, createAzionESBuildConfig as st } from "azion/bundler";
|
|
15
|
+
import it from "lodash";
|
|
16
16
|
import { runInContext as ee } from "vm";
|
|
17
17
|
import R from "node:vm";
|
|
18
|
-
import
|
|
19
|
-
import { runServer as
|
|
18
|
+
import ot from "net";
|
|
19
|
+
import { runServer as at } from "edge-runtime";
|
|
20
20
|
import * as be from "prettier";
|
|
21
|
-
import { cosmiconfig as
|
|
21
|
+
import { cosmiconfig as ct } from "cosmiconfig";
|
|
22
22
|
import { TypeScriptLoader as V } from "cosmiconfig-typescript-loader";
|
|
23
|
-
class
|
|
23
|
+
class lt {
|
|
24
24
|
context;
|
|
25
|
-
constructor(
|
|
26
|
-
const
|
|
25
|
+
constructor(t = {}) {
|
|
26
|
+
const r = R.createContext(
|
|
27
27
|
{},
|
|
28
28
|
{
|
|
29
29
|
name: "Edge Runtime",
|
|
30
|
-
codeGeneration:
|
|
30
|
+
codeGeneration: t.codeGeneration ?? {
|
|
31
31
|
strings: !1,
|
|
32
32
|
wasm: !0
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
);
|
|
36
|
-
this.context =
|
|
36
|
+
this.context = t.extend?.(r) ?? r;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Allows to run arbitrary code within the VM.
|
|
40
40
|
*/
|
|
41
41
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
-
evaluate(
|
|
43
|
-
return R.runInContext(
|
|
44
|
-
importModuleDynamically: async (
|
|
42
|
+
evaluate(t) {
|
|
43
|
+
return R.runInContext(t, this.context, {
|
|
44
|
+
importModuleDynamically: async (r) => {
|
|
45
45
|
try {
|
|
46
|
-
return await import(Me(Y(
|
|
46
|
+
return await import(Me(Y(r)).href);
|
|
47
47
|
} catch {
|
|
48
48
|
process.env.DEBUG && console.warn(
|
|
49
49
|
">>> [edge-runtime] dynamic import failed, returning empty module:",
|
|
50
|
-
|
|
50
|
+
r
|
|
51
51
|
);
|
|
52
52
|
const s = new R.SourceTextModule("export default {}", { context: this.context });
|
|
53
53
|
return await s.link(() => new R.SourceTextModule("export {}", { context: this.context })), await s.evaluate(), s;
|
|
@@ -58,14 +58,14 @@ class lr {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
let B, M;
|
|
61
|
-
class
|
|
61
|
+
class ft extends lt {
|
|
62
62
|
dispatchFetch;
|
|
63
|
-
constructor(
|
|
63
|
+
constructor(t) {
|
|
64
64
|
super({
|
|
65
|
-
...
|
|
66
|
-
extend: (
|
|
65
|
+
...t,
|
|
66
|
+
extend: (r) => t?.extend ? t.extend(ce(r)) : ce(r)
|
|
67
67
|
}), Object.defineProperty(this.context, "__onUnhandledRejectionHandlers", {
|
|
68
|
-
set:
|
|
68
|
+
set: dt,
|
|
69
69
|
configurable: !1,
|
|
70
70
|
enumerable: !1
|
|
71
71
|
}), Object.defineProperty(this, "__rejectionHandlers", {
|
|
@@ -73,17 +73,17 @@ class fr extends lr {
|
|
|
73
73
|
configurable: !1,
|
|
74
74
|
enumerable: !1
|
|
75
75
|
}), Object.defineProperty(this.context, "__onErrorHandlers", {
|
|
76
|
-
set:
|
|
76
|
+
set: pt,
|
|
77
77
|
configurable: !1,
|
|
78
78
|
enumerable: !1
|
|
79
79
|
}), Object.defineProperty(this, "__errorHandlers", {
|
|
80
80
|
get: () => M,
|
|
81
81
|
configurable: !1,
|
|
82
82
|
enumerable: !1
|
|
83
|
-
}), this.evaluate(
|
|
84
|
-
for (const
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
}), this.evaluate(ht()), this.dispatchFetch = this.evaluate(gt());
|
|
84
|
+
for (const r of Ee)
|
|
85
|
+
ut(r, this.context);
|
|
86
|
+
t?.initialCode && this.evaluate(t.initialCode);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
const Ee = [
|
|
@@ -96,9 +96,9 @@ const Ee = [
|
|
|
96
96
|
"SyntaxError",
|
|
97
97
|
"TypeError"
|
|
98
98
|
];
|
|
99
|
-
function
|
|
100
|
-
const
|
|
101
|
-
return
|
|
99
|
+
function ut(e, t) {
|
|
100
|
+
const r = eval;
|
|
101
|
+
return t[/* @__PURE__ */ Symbol.for(`node:${e}`)] = r(e), ee(
|
|
102
102
|
`
|
|
103
103
|
globalThis.${e} = new Proxy(${e}, {
|
|
104
104
|
get(target, prop, receiver) {
|
|
@@ -117,20 +117,20 @@ function ur(e, r) {
|
|
|
117
117
|
}
|
|
118
118
|
})
|
|
119
119
|
`,
|
|
120
|
-
|
|
120
|
+
t
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
|
-
function
|
|
124
|
-
B || process.on("unhandledRejection", function(
|
|
125
|
-
B.forEach((s) => s({ reason:
|
|
123
|
+
function dt(e) {
|
|
124
|
+
B || process.on("unhandledRejection", function(r, n) {
|
|
125
|
+
B.forEach((s) => s({ reason: r, promise: n }));
|
|
126
126
|
}), B = e;
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
M || process.on("uncaughtException", function(
|
|
130
|
-
M.forEach((n) => n(
|
|
128
|
+
function pt(e) {
|
|
129
|
+
M || process.on("uncaughtException", function(r) {
|
|
130
|
+
M.forEach((n) => n(r));
|
|
131
131
|
}), M = e;
|
|
132
132
|
}
|
|
133
|
-
function
|
|
133
|
+
function ht() {
|
|
134
134
|
return `
|
|
135
135
|
Object.defineProperty(self, '__listeners', {
|
|
136
136
|
configurable: false,
|
|
@@ -173,7 +173,7 @@ function hr() {
|
|
|
173
173
|
}
|
|
174
174
|
`;
|
|
175
175
|
}
|
|
176
|
-
function
|
|
176
|
+
function gt() {
|
|
177
177
|
return `(async function dispatchFetch(input, init) {
|
|
178
178
|
const request = new Request(input, init);
|
|
179
179
|
const event = new FetchEvent(request);
|
|
@@ -214,10 +214,10 @@ function gr() {
|
|
|
214
214
|
}
|
|
215
215
|
function ce(e) {
|
|
216
216
|
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
|
|
218
|
-
return
|
|
217
|
+
const t = wt(e);
|
|
218
|
+
return mt(e, {
|
|
219
219
|
exports: Be({
|
|
220
|
-
...
|
|
220
|
+
...t,
|
|
221
221
|
WeakRef: ee("WeakRef", e)
|
|
222
222
|
}),
|
|
223
223
|
enumerable: ["crypto"],
|
|
@@ -273,37 +273,37 @@ function ce(e) {
|
|
|
273
273
|
]
|
|
274
274
|
}), e;
|
|
275
275
|
}
|
|
276
|
-
function x(e,
|
|
277
|
-
Object.defineProperty(e,
|
|
278
|
-
configurable:
|
|
279
|
-
enumerable:
|
|
280
|
-
value:
|
|
281
|
-
writable:
|
|
276
|
+
function x(e, t, r) {
|
|
277
|
+
Object.defineProperty(e, t, {
|
|
278
|
+
configurable: r.configurable ?? !1,
|
|
279
|
+
enumerable: r.enumerable ?? !1,
|
|
280
|
+
value: r.value,
|
|
281
|
+
writable: r.writable ?? !0
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
|
-
function
|
|
285
|
-
for (const
|
|
286
|
-
if (!
|
|
287
|
-
throw new Error(`Attempt to export a nullable value for "${
|
|
288
|
-
x(e,
|
|
284
|
+
function mt(e, t) {
|
|
285
|
+
for (const r of t.enumerable ?? []) {
|
|
286
|
+
if (!t.exports[r])
|
|
287
|
+
throw new Error(`Attempt to export a nullable value for "${r}"`);
|
|
288
|
+
x(e, r, {
|
|
289
289
|
enumerable: !0,
|
|
290
|
-
value:
|
|
290
|
+
value: t.exports[r]
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
|
-
for (const
|
|
294
|
-
if (!
|
|
295
|
-
throw new Error(`Attempt to export a nullable value for "${
|
|
296
|
-
x(e,
|
|
297
|
-
value:
|
|
293
|
+
for (const r of t.nonenumerable ?? []) {
|
|
294
|
+
if (!t.exports[r])
|
|
295
|
+
throw new Error(`Attempt to export a nullable value for "${r}"`);
|
|
296
|
+
x(e, r, {
|
|
297
|
+
value: t.exports[r]
|
|
298
298
|
});
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
|
-
function
|
|
302
|
-
const
|
|
303
|
-
return ee(
|
|
301
|
+
function wt(e) {
|
|
302
|
+
const r = `({${Ee.join(",")}})`;
|
|
303
|
+
return ee(r, e);
|
|
304
304
|
}
|
|
305
|
-
function ve(e,
|
|
306
|
-
const
|
|
305
|
+
function ve(e, t = !1) {
|
|
306
|
+
const r = (s) => (s.RESERVED_FETCH = s.fetch.bind(s), s.fetch = async (i, o) => Ce(
|
|
307
307
|
s,
|
|
308
308
|
i,
|
|
309
309
|
o,
|
|
@@ -311,88 +311,88 @@ function ve(e, r = !1) {
|
|
|
311
311
|
globalThis?.AZION_BUCKET_NAME,
|
|
312
312
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
313
313
|
globalThis?.AZION_BUCKET_PREFIX
|
|
314
|
-
), s.FetchEvent =
|
|
315
|
-
return new
|
|
314
|
+
), s.FetchEvent = t ? Fe : _e, s.Response = t ? Response : s.Response, s.eval = eval, s.process = { env: process.env }, s.File = void 0, s.WebSocket = void 0, s.ASYNC_LOCAL_STORAGE = Ae, s.STORAGE_CONTEXT = Oe, s.ENV_VARS_CONTEXT = je, s.NETWORK_LIST_CONTEXT = Re, s.FS_CONTEXT = Ue, s.STREAM_CONTEXT = Ne, s.CRYPTO_CONTEXT = Ie, 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 = De, s);
|
|
315
|
+
return new ft({ extend: r, initialCode: e, codeGeneration: { strings: !0 } });
|
|
316
316
|
}
|
|
317
317
|
class Te extends Error {
|
|
318
|
-
constructor(
|
|
319
|
-
super(
|
|
318
|
+
constructor(t, r) {
|
|
319
|
+
super(t), this.code = r, this.name = "PackageJsonError";
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
|
-
class
|
|
323
|
-
constructor(
|
|
324
|
-
super(`Please install dependencies using ${
|
|
322
|
+
class yt extends Error {
|
|
323
|
+
constructor(t) {
|
|
324
|
+
super(`Please install dependencies using ${t}`), this.name = "DependenciesError";
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
const
|
|
327
|
+
const bt = async () => {
|
|
328
328
|
const e = C(process.cwd(), "package.json");
|
|
329
329
|
try {
|
|
330
|
-
const
|
|
331
|
-
return JSON.parse(
|
|
332
|
-
} catch (
|
|
333
|
-
throw new Te("Failed to read package.json",
|
|
330
|
+
const t = await Je(e, "utf8");
|
|
331
|
+
return JSON.parse(t);
|
|
332
|
+
} catch (t) {
|
|
333
|
+
throw new Te("Failed to read package.json", t.code);
|
|
334
334
|
}
|
|
335
|
-
},
|
|
335
|
+
}, Et = async () => {
|
|
336
336
|
const e = C(process.cwd(), "node_modules");
|
|
337
337
|
try {
|
|
338
338
|
return (await Xe(e)).isDirectory();
|
|
339
339
|
} catch {
|
|
340
340
|
return !1;
|
|
341
341
|
}
|
|
342
|
-
},
|
|
342
|
+
}, vt = async () => {
|
|
343
343
|
let e;
|
|
344
344
|
try {
|
|
345
|
-
e = await
|
|
346
|
-
} catch (
|
|
347
|
-
if (
|
|
345
|
+
e = await bt();
|
|
346
|
+
} catch (t) {
|
|
347
|
+
if (t instanceof Te && t.code === "ENOENT")
|
|
348
348
|
return;
|
|
349
|
-
throw
|
|
349
|
+
throw t;
|
|
350
350
|
}
|
|
351
351
|
if (e && (e.dependencies || e.devDependencies)) {
|
|
352
|
-
const
|
|
353
|
-
if (!await
|
|
354
|
-
throw new
|
|
352
|
+
const t = await Ge();
|
|
353
|
+
if (!await Et())
|
|
354
|
+
throw new yt(t);
|
|
355
355
|
}
|
|
356
356
|
};
|
|
357
357
|
function U({
|
|
358
358
|
inputValue: e,
|
|
359
|
-
fileValue:
|
|
360
|
-
storeValue:
|
|
359
|
+
fileValue: t,
|
|
360
|
+
storeValue: r,
|
|
361
361
|
defaultValue: n
|
|
362
362
|
}) {
|
|
363
|
-
return ((o) => o === "true" ? !0 : o === "false" ? !1 : o)(e ??
|
|
363
|
+
return ((o) => o === "true" ? !0 : o === "false" ? !1 : o)(e ?? t ?? r ?? n);
|
|
364
364
|
}
|
|
365
|
-
const
|
|
365
|
+
const Tt = async (e) => {
|
|
366
366
|
try {
|
|
367
367
|
await Promise.all(
|
|
368
|
-
e.map(async (
|
|
368
|
+
e.map(async (t) => {
|
|
369
369
|
try {
|
|
370
|
-
await Q(
|
|
371
|
-
} catch (
|
|
372
|
-
if (
|
|
373
|
-
throw
|
|
370
|
+
await Q(t, { recursive: !0, force: !0 });
|
|
371
|
+
} catch (r) {
|
|
372
|
+
if (r.code !== "ENOENT")
|
|
373
|
+
throw r;
|
|
374
374
|
}
|
|
375
|
-
await ye(
|
|
375
|
+
await ye(t, { recursive: !0 });
|
|
376
376
|
})
|
|
377
377
|
);
|
|
378
|
-
} catch (
|
|
379
|
-
throw new Error(`Failed to clean directories: ${
|
|
378
|
+
} catch (t) {
|
|
379
|
+
throw new Error(`Failed to clean directories: ${t}`);
|
|
380
380
|
}
|
|
381
|
-
},
|
|
381
|
+
}, St = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10).replace(/-/g, ""), Pt = async ({
|
|
382
382
|
entry: e,
|
|
383
|
-
ext:
|
|
384
|
-
basePath:
|
|
383
|
+
ext: t = "js",
|
|
384
|
+
basePath: r = ".edge/functions",
|
|
385
385
|
production: n = !0,
|
|
386
386
|
bundler: s
|
|
387
387
|
}) => {
|
|
388
|
-
const i =
|
|
389
|
-
const l = J(a, H(a)), f = we(a), w = `azion-${l}-${i}.temp.${
|
|
388
|
+
const i = St(), o = (a, c) => {
|
|
389
|
+
const l = J(a, H(a)), f = we(a), w = `azion-${l}-${i}.temp.${t}`, d = Y(f, w), m = s === "webpack" ? ".js" : "", g = n ? "" : ".dev";
|
|
390
390
|
let y;
|
|
391
391
|
if (c) {
|
|
392
392
|
const S = c.replace(/\.[^/.]+$/, "");
|
|
393
|
-
y = C(
|
|
393
|
+
y = C(r, `${S}${g}${m}`);
|
|
394
394
|
} else
|
|
395
|
-
y = C(
|
|
395
|
+
y = C(r, f, `${l}${g}${m}`);
|
|
396
396
|
return { [y]: d };
|
|
397
397
|
};
|
|
398
398
|
if (typeof e == "string") {
|
|
@@ -403,16 +403,16 @@ const Tr = async (e) => {
|
|
|
403
403
|
(a, [c, l]) => ({ ...a, ...o(l, c) }),
|
|
404
404
|
{}
|
|
405
405
|
);
|
|
406
|
-
}, $
|
|
406
|
+
}, $t = async (e, t, r) => {
|
|
407
407
|
let n = {};
|
|
408
|
-
const s = e.build?.entry, i = async (o) => await
|
|
408
|
+
const s = e.build?.entry, i = async (o) => await Pt({
|
|
409
409
|
entry: o,
|
|
410
|
-
ext:
|
|
411
|
-
production:
|
|
412
|
-
bundler: e.build?.bundler ??
|
|
410
|
+
ext: t.metadata.ext ?? O.DEFAULT_OUTPUT_EXTENSION,
|
|
411
|
+
production: r,
|
|
412
|
+
bundler: e.build?.bundler ?? t.config.build?.bundler ?? ie.DEFAULT
|
|
413
413
|
});
|
|
414
|
-
if (s ? n = await i(s) :
|
|
415
|
-
const o =
|
|
414
|
+
if (s ? n = await i(s) : t.config.build?.entry ? n = await i(t.config.build.entry) : t.handler && (n = await i(O.DEFAULT_HANDLER_FILENAME)), Object.keys(n).length === 0) {
|
|
415
|
+
const o = t.config.build?.entry ? `(default is "${t.config.build.entry}")` : "";
|
|
416
416
|
throw new Error(
|
|
417
417
|
`No entry point found ${o}. Please specify one using --entry or create a default entry file in your project.`
|
|
418
418
|
);
|
|
@@ -420,48 +420,48 @@ const Tr = async (e) => {
|
|
|
420
420
|
return {
|
|
421
421
|
...e.build,
|
|
422
422
|
entry: n,
|
|
423
|
-
bundler: e.build?.bundler ??
|
|
424
|
-
preset:
|
|
423
|
+
bundler: e.build?.bundler ?? t.config.build?.bundler ?? ie.DEFAULT,
|
|
424
|
+
preset: t,
|
|
425
425
|
setup: {
|
|
426
426
|
contentToInject: void 0,
|
|
427
427
|
defineVars: {}
|
|
428
428
|
},
|
|
429
429
|
polyfills: !!e.build?.polyfills
|
|
430
430
|
};
|
|
431
|
-
},
|
|
431
|
+
}, xt = ({ projectDir: e = process.cwd() }) => et({
|
|
432
432
|
projectDir: e
|
|
433
|
-
}),
|
|
434
|
-
async function
|
|
433
|
+
}), kt = { listFrameworks: xt };
|
|
434
|
+
async function Ct() {
|
|
435
435
|
try {
|
|
436
|
-
const e = await
|
|
436
|
+
const e = await kt.listFrameworks({
|
|
437
437
|
projectDir: process.cwd()
|
|
438
438
|
});
|
|
439
439
|
if (e[0]?.id && Object.values(j).some(
|
|
440
440
|
(o) => o.metadata?.name === e[0].id
|
|
441
441
|
))
|
|
442
442
|
return e[0].id;
|
|
443
|
-
const
|
|
444
|
-
return ae.existsSync(
|
|
443
|
+
const t = C(process.cwd(), "tsconfig.json");
|
|
444
|
+
return ae.existsSync(t) || ae.readdirSync(process.cwd()).some((i) => [".ts", ".tsx"].includes(H(i))) ? "typescript" : "javascript";
|
|
445
445
|
} catch {
|
|
446
446
|
return "javascript";
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
|
-
const
|
|
449
|
+
const Ft = { inferPreset: Ct }, _t = (e) => Object.values(j).find((t) => t.metadata?.name === e), At = async (e) => {
|
|
450
450
|
if (e) {
|
|
451
|
-
const
|
|
452
|
-
k.feedback.build.info(`Using preset: ${
|
|
451
|
+
const t = typeof e == "string" ? e : e.metadata?.name;
|
|
452
|
+
k.feedback.build.info(`Using preset: ${t}`);
|
|
453
453
|
}
|
|
454
|
-
if (e || (k.feedback.build.info("No preset specified, using automatic detection..."), e = await
|
|
455
|
-
const
|
|
456
|
-
if (!
|
|
454
|
+
if (e || (k.feedback.build.info("No preset specified, using automatic detection..."), e = await Ft.inferPreset(), k.feedback.build.info(`Detected preset: ${e}`)), typeof e == "string") {
|
|
455
|
+
const t = _t(e);
|
|
456
|
+
if (!t)
|
|
457
457
|
throw new Error(`Invalid build preset name: '${e}'`);
|
|
458
|
-
return
|
|
458
|
+
return t;
|
|
459
459
|
}
|
|
460
460
|
return e;
|
|
461
|
-
},
|
|
461
|
+
}, Ot = async ({
|
|
462
462
|
namespace: e,
|
|
463
|
-
property:
|
|
464
|
-
dirs:
|
|
463
|
+
property: t,
|
|
464
|
+
dirs: r
|
|
465
465
|
}) => {
|
|
466
466
|
const n = {}, s = async (i) => {
|
|
467
467
|
for (const o of i) {
|
|
@@ -478,30 +478,30 @@ const Fr = { inferPreset: Cr }, _r = (e) => Object.values(j).find((r) => r.metad
|
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
480
|
};
|
|
481
|
-
return await s(
|
|
482
|
-
},
|
|
481
|
+
return await s(r), `globalThis.${e}.${t}=${JSON.stringify(n)};`;
|
|
482
|
+
}, jt = async ({ dirs: e, prefix: t, outputPath: r }) => {
|
|
483
483
|
await Promise.all(
|
|
484
484
|
e.map(async (n) => {
|
|
485
|
-
const s =
|
|
485
|
+
const s = t ? n.replace(t, "") : n, i = C(r, s);
|
|
486
486
|
await u.access(i).then(() => !0).catch(() => !1) || await u.mkdir(i, { recursive: !0 }), await u.cp(n, i, { recursive: !0 });
|
|
487
487
|
})
|
|
488
488
|
);
|
|
489
|
-
},
|
|
489
|
+
}, Rt = ({ namespace: e, property: t, vars: r }) => Object.entries(r).reduce(
|
|
490
490
|
(n, [s, i]) => {
|
|
491
|
-
const o =
|
|
491
|
+
const o = t ? `${e}.${t}` : e;
|
|
492
492
|
return `${n} globalThis.${o}.${s}=${i};`;
|
|
493
493
|
},
|
|
494
|
-
|
|
495
|
-
),
|
|
494
|
+
t ? `globalThis.${e}.${t}={};` : `globalThis.${e}={};`
|
|
495
|
+
), Ut = async ({
|
|
496
496
|
namespace: e,
|
|
497
|
-
property:
|
|
498
|
-
prefix:
|
|
499
|
-
}) => `globalThis.${e} = { ...globalThis.${e}, ${
|
|
500
|
-
injectWorkerMemoryFiles:
|
|
501
|
-
copyFilesToLocalEdgeStorage:
|
|
502
|
-
injectWorkerGlobals:
|
|
503
|
-
injectWorkerPathPrefix:
|
|
504
|
-
},
|
|
497
|
+
property: t,
|
|
498
|
+
prefix: r
|
|
499
|
+
}) => `globalThis.${e} = { ...globalThis.${e}, ${t}: '${r && typeof r == "string" && r !== "" ? r : '""'}'};`, N = {
|
|
500
|
+
injectWorkerMemoryFiles: Ot,
|
|
501
|
+
copyFilesToLocalEdgeStorage: jt,
|
|
502
|
+
injectWorkerGlobals: Rt,
|
|
503
|
+
injectWorkerPathPrefix: Ut
|
|
504
|
+
}, Nt = {
|
|
505
505
|
filesToInject: [],
|
|
506
506
|
injection: {
|
|
507
507
|
globals: {}
|
|
@@ -510,18 +510,18 @@ const Fr = { inferPreset: Cr }, _r = (e) => Object.values(j).find((r) => r.metad
|
|
|
510
510
|
defineVars: {},
|
|
511
511
|
plugins: []
|
|
512
512
|
}
|
|
513
|
-
},
|
|
513
|
+
}, It = async ({
|
|
514
514
|
buildConfig: e,
|
|
515
|
-
ctx:
|
|
515
|
+
ctx: t
|
|
516
516
|
}) => {
|
|
517
|
-
const
|
|
517
|
+
const r = await e.preset.prebuild?.(e, t) || Nt, n = N.injectWorkerGlobals({
|
|
518
518
|
namespace: O.NAMESPACE,
|
|
519
519
|
// Transform globals object:
|
|
520
520
|
// 1. Convert object to entries
|
|
521
521
|
// 2. Remove any entries with undefined values
|
|
522
522
|
// 3. Ensure remaining values are typed as string
|
|
523
523
|
vars: Object.fromEntries(
|
|
524
|
-
Object.entries(
|
|
524
|
+
Object.entries(r.injection?.globals || {}).filter(([a, c]) => c !== void 0).map(([a, c]) => [a, c])
|
|
525
525
|
)
|
|
526
526
|
}), s = await N.injectWorkerMemoryFiles({
|
|
527
527
|
namespace: O.NAMESPACE,
|
|
@@ -540,46 +540,46 @@ const Fr = { inferPreset: Cr }, _r = (e) => Object.values(j).find((r) => r.metad
|
|
|
540
540
|
}), o = `${n}${i}
|
|
541
541
|
${s}`;
|
|
542
542
|
return {
|
|
543
|
-
filesToInject:
|
|
543
|
+
filesToInject: r.filesToInject || [],
|
|
544
544
|
injection: {
|
|
545
|
-
globals:
|
|
545
|
+
globals: r.injection?.globals || {},
|
|
546
546
|
entry: "",
|
|
547
547
|
banner: o
|
|
548
548
|
},
|
|
549
549
|
bundler: {
|
|
550
|
-
defineVars:
|
|
551
|
-
plugins:
|
|
550
|
+
defineVars: r.bundler?.defineVars || {},
|
|
551
|
+
plugins: r.bundler?.plugins || []
|
|
552
552
|
}
|
|
553
553
|
};
|
|
554
|
-
},
|
|
555
|
-
createAzionESBuildConfigWrapper:
|
|
556
|
-
createAzionWebpackConfigWrapper:
|
|
557
|
-
executeESBuildBuildWrapper:
|
|
558
|
-
executeWebpackBuildWrapper:
|
|
559
|
-
},
|
|
560
|
-
const
|
|
561
|
-
let i = e.replace(
|
|
554
|
+
}, Wt = (e, t) => st(e, t), Dt = (e, t) => tt(e, t), Bt = async (e) => nt(e), Mt = async (e) => rt(e), I = {
|
|
555
|
+
createAzionESBuildConfigWrapper: Wt,
|
|
556
|
+
createAzionWebpackConfigWrapper: Dt,
|
|
557
|
+
executeESBuildBuildWrapper: Bt,
|
|
558
|
+
executeWebpackBuildWrapper: Mt
|
|
559
|
+
}, Lt = (e) => {
|
|
560
|
+
const t = /import\s+.*?from\s*['"](.*?)['"];?/g, r = /(const\s+.*?=\s*require\(.*\).*);/g, n = (e.match(t) || []).map((o) => o.trim()), s = (e.match(r) || []).map((o) => o.trim());
|
|
561
|
+
let i = e.replace(t, "").replace(r, "").replace(/\n\s*\n\s*\n/g, `
|
|
562
562
|
|
|
563
563
|
`);
|
|
564
564
|
return (n.length || s.length) && (i = `${[...n, ...s].join(`
|
|
565
565
|
`)}
|
|
566
566
|
|
|
567
567
|
${i.trim()}`), i;
|
|
568
|
-
},
|
|
569
|
-
${e}` : e,
|
|
568
|
+
}, Ht = (e, t, r) => t.polyfills && r.production ? `import SRC_NODE_FS from "node:fs";
|
|
569
|
+
${e}` : e, Vt = async ({
|
|
570
570
|
buildConfig: e,
|
|
571
|
-
prebuildResult:
|
|
572
|
-
ctx:
|
|
571
|
+
prebuildResult: t,
|
|
572
|
+
ctx: r
|
|
573
573
|
}) => {
|
|
574
574
|
try {
|
|
575
575
|
const n = typeof e.entry == "string" ? [e.entry] : Array.isArray(e.entry) ? e.entry : Object.values(e.entry);
|
|
576
|
-
if (
|
|
576
|
+
if (t.filesToInject.length > 0) {
|
|
577
577
|
const i = await Promise.all(
|
|
578
|
-
|
|
578
|
+
t.filesToInject.map((o) => u.readFile(o, "utf-8"))
|
|
579
579
|
).then((o) => o.join(" "));
|
|
580
580
|
await Promise.all(
|
|
581
581
|
n.map(async (o) => {
|
|
582
|
-
const a = await u.readFile(o, "utf-8"), c = `${i} ${a}`, l =
|
|
582
|
+
const a = await u.readFile(o, "utf-8"), c = `${i} ${a}`, l = Lt(c);
|
|
583
583
|
return u.writeFile(o, l);
|
|
584
584
|
})
|
|
585
585
|
);
|
|
@@ -587,21 +587,21 @@ ${e}` : e, Vr = async ({
|
|
|
587
587
|
const s = {
|
|
588
588
|
...e,
|
|
589
589
|
setup: {
|
|
590
|
-
contentToInject:
|
|
590
|
+
contentToInject: t.injection.banner,
|
|
591
591
|
defineVars: Object.fromEntries(
|
|
592
592
|
// Get all entries from defineVars
|
|
593
|
-
Object.entries(
|
|
593
|
+
Object.entries(t.bundler.defineVars).filter(([i, o]) => o !== void 0).map(([i, o]) => [i, o])
|
|
594
594
|
)
|
|
595
595
|
}
|
|
596
596
|
};
|
|
597
|
-
return await
|
|
597
|
+
return await zt(s, r), Promise.all(
|
|
598
598
|
Object.entries(s.entry).map(async ([i]) => {
|
|
599
599
|
const o = i.endsWith(".js") ? i : `${i}.js`, a = await u.readFile(o, "utf-8");
|
|
600
|
-
if (!
|
|
601
|
-
const c =
|
|
600
|
+
if (!r.production) return a;
|
|
601
|
+
const c = Ht(
|
|
602
602
|
a,
|
|
603
603
|
e,
|
|
604
|
-
|
|
604
|
+
r
|
|
605
605
|
);
|
|
606
606
|
return await u.writeFile(o, c), c;
|
|
607
607
|
})
|
|
@@ -609,46 +609,48 @@ ${e}` : e, Vr = async ({
|
|
|
609
609
|
} catch (n) {
|
|
610
610
|
return Promise.reject(n);
|
|
611
611
|
}
|
|
612
|
-
},
|
|
612
|
+
}, zt = async (e, t) => {
|
|
613
613
|
switch (e.bundler) {
|
|
614
614
|
case "esbuild": {
|
|
615
|
-
const
|
|
616
|
-
return I.executeESBuildBuildWrapper(
|
|
615
|
+
const r = I.createAzionESBuildConfigWrapper(e, t);
|
|
616
|
+
return I.executeESBuildBuildWrapper(r);
|
|
617
617
|
}
|
|
618
618
|
case "webpack": {
|
|
619
|
-
const
|
|
620
|
-
return I.executeWebpackBuildWrapper(
|
|
619
|
+
const r = I.createAzionWebpackConfigWrapper(e, t);
|
|
620
|
+
return I.executeWebpackBuildWrapper(r);
|
|
621
621
|
}
|
|
622
622
|
default:
|
|
623
623
|
throw new Error(`Unsupported bundler: ${e.bundler}`);
|
|
624
624
|
}
|
|
625
|
-
},
|
|
626
|
-
const { postbuild:
|
|
627
|
-
|
|
628
|
-
},
|
|
629
|
-
const
|
|
625
|
+
}, Gt = async ({ buildConfig: e, ctx: t }) => {
|
|
626
|
+
const { postbuild: r } = e.preset;
|
|
627
|
+
r && await r(e, { ...t });
|
|
628
|
+
}, qt = (e, t) => {
|
|
629
|
+
const r = (n, s) => {
|
|
630
630
|
if (n && !n.build || Array.isArray(n) && !Array.isArray(s))
|
|
631
631
|
return s;
|
|
632
632
|
};
|
|
633
|
-
return
|
|
634
|
-
},
|
|
633
|
+
return it.mergeWith({}, e, t, r);
|
|
634
|
+
}, Kt = { mergeConfigWithUserOverrides: qt }, le = async ({
|
|
635
635
|
config: e,
|
|
636
|
-
preset:
|
|
636
|
+
preset: t
|
|
637
637
|
}) => {
|
|
638
638
|
try {
|
|
639
|
-
const { config:
|
|
640
|
-
|
|
639
|
+
const { config: r } = t;
|
|
640
|
+
e.firewall && (delete r.applications, delete r.workloads, delete r.connectors, delete r.functions);
|
|
641
|
+
const n = Kt.mergeConfigWithUserOverrides(
|
|
642
|
+
r,
|
|
641
643
|
e
|
|
642
644
|
);
|
|
643
645
|
return n.build?.preset || (n.build = {
|
|
644
646
|
...n.build,
|
|
645
|
-
preset:
|
|
646
|
-
...!
|
|
647
|
+
preset: t.metadata.name,
|
|
648
|
+
...!t.handler && e.build?.entry && {
|
|
647
649
|
entry: e.build?.entry
|
|
648
650
|
}
|
|
649
651
|
}), await pe.readAzionConfig() || await pe.writeUserConfig(n), n;
|
|
650
|
-
} catch (
|
|
651
|
-
throw new Error(`Failed to set environment: ${
|
|
652
|
+
} catch (r) {
|
|
653
|
+
throw new Error(`Failed to set environment: ${r.message}`);
|
|
652
654
|
}
|
|
653
655
|
}, z = {
|
|
654
656
|
LEGACY_DEPRECATION: "DEPRECATED: Migrate handler to → export default { fetch: (request, env, ctx) => {...} }",
|
|
@@ -699,18 +701,18 @@ if (fetchHandler) {
|
|
|
699
701
|
throw new Error("No fetch handler found in default export object.");
|
|
700
702
|
}`
|
|
701
703
|
}, Se = (e) => {
|
|
702
|
-
const
|
|
703
|
-
`),
|
|
704
|
-
return
|
|
704
|
+
const t = e.split(`
|
|
705
|
+
`), r = /addEventListener\s*\(\s*['"`](fetch|firewall)['"`]\s*,/;
|
|
706
|
+
return t.some((n) => {
|
|
705
707
|
const s = n.trim();
|
|
706
|
-
return s.startsWith("//") || s.startsWith("/*") ? !1 :
|
|
708
|
+
return s.startsWith("//") || s.startsWith("/*") ? !1 : r.test(n);
|
|
707
709
|
});
|
|
708
|
-
},
|
|
710
|
+
}, Jt = async (e) => {
|
|
709
711
|
try {
|
|
710
|
-
const
|
|
712
|
+
const t = await import(e), r = t.default || t;
|
|
711
713
|
return {
|
|
712
|
-
hasFirewall: !!
|
|
713
|
-
hasFetch: !!
|
|
714
|
+
hasFirewall: !!r.firewall,
|
|
715
|
+
hasFetch: !!r.fetch
|
|
714
716
|
};
|
|
715
717
|
} catch {
|
|
716
718
|
return {
|
|
@@ -718,18 +720,18 @@ if (fetchHandler) {
|
|
|
718
720
|
hasFetch: !0
|
|
719
721
|
};
|
|
720
722
|
}
|
|
721
|
-
},
|
|
722
|
-
const { hasFirewall:
|
|
723
|
-
if (!
|
|
723
|
+
}, Xt = async (e, t) => {
|
|
724
|
+
const { hasFirewall: r, hasFetch: n } = await Jt(e);
|
|
725
|
+
if (!r && !n)
|
|
724
726
|
return `// No fetch or firewall handlers found in: ${e}
|
|
725
727
|
// The original file will be used as-is in production mode.
|
|
726
728
|
// Consider adding: export default { fetch: (request, env, ctx) => { ... } }
|
|
727
729
|
|
|
728
730
|
console.warn('No Edge Function handlers found. File will run as-is.');`;
|
|
729
731
|
const s = [G.baseImport(e)];
|
|
730
|
-
return
|
|
732
|
+
return r && s.push(G.firewallHandler), n && s.push(G.fetchHandler(t)), s.join(`
|
|
731
733
|
`);
|
|
732
|
-
},
|
|
734
|
+
}, Zt = (e) => `
|
|
733
735
|
import handler from '${e}';
|
|
734
736
|
|
|
735
737
|
// Legacy pattern wrapper: export default function → addEventListener
|
|
@@ -738,51 +740,51 @@ addEventListener('fetch', (event) => {
|
|
|
738
740
|
return await handler(event);
|
|
739
741
|
})());
|
|
740
742
|
});
|
|
741
|
-
`,
|
|
743
|
+
`, te = (e) => /export\s+default\s*\{[\s\S]*fetch[\s\S]*\}/.test(e), Pe = (e) => !(!/export\s+default\s+/.test(e) || te(e)), Yt = async (e) => {
|
|
742
744
|
try {
|
|
743
|
-
const
|
|
744
|
-
return typeof
|
|
745
|
+
const t = await import(e);
|
|
746
|
+
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";
|
|
745
747
|
} catch {
|
|
746
748
|
const n = await (await import("fs/promises")).readFile(e, "utf-8");
|
|
747
|
-
return Se(n) ? "serviceWorker" :
|
|
749
|
+
return Se(n) ? "serviceWorker" : te(n) ? "ESModules" : Pe(n) ? "legacy" : "unsupported";
|
|
748
750
|
}
|
|
749
|
-
},
|
|
751
|
+
}, Qt = (e) => typeof e == "string" ? [e] : Array.isArray(e) ? e : Object.values(e), er = (e) => Se(e) ? "serviceWorker" : te(e) ? "ESModules" : Pe(e) ? "legacy" : "unsupported", tr = async (e, t, r) => {
|
|
750
752
|
let n;
|
|
751
753
|
try {
|
|
752
|
-
n = await
|
|
754
|
+
n = await Yt(t);
|
|
753
755
|
} catch {
|
|
754
|
-
n =
|
|
756
|
+
n = er(e);
|
|
755
757
|
}
|
|
756
758
|
switch (n) {
|
|
757
759
|
case "serviceWorker":
|
|
758
760
|
return e;
|
|
759
761
|
case "ESModules":
|
|
760
|
-
return await
|
|
762
|
+
return await Xt(t, r);
|
|
761
763
|
case "legacy":
|
|
762
|
-
return p.build.warn(z.LEGACY_DEPRECATION),
|
|
764
|
+
return p.build.warn(z.LEGACY_DEPRECATION), Zt(t);
|
|
763
765
|
default:
|
|
764
766
|
return p.build.warn(z.UNSUPPORTED_PATTERN_DETECTED), p.build.info(z.UNSUPPORTED_PATTERN_SUGGESTIONS), e;
|
|
765
767
|
}
|
|
766
|
-
},
|
|
768
|
+
}, rr = async (e, t) => {
|
|
767
769
|
try {
|
|
768
|
-
const
|
|
769
|
-
|
|
770
|
-
const a = Object.values(n)[o], c = await u.readFile(i, "utf-8"), l = await
|
|
770
|
+
const r = Qt(t.handler), n = e.entry || {}, s = await Promise.all(
|
|
771
|
+
r.map(async (i, o) => {
|
|
772
|
+
const a = Object.values(n)[o], c = await u.readFile(i, "utf-8"), l = await tr(c, i, t.production);
|
|
771
773
|
return [a, l];
|
|
772
774
|
})
|
|
773
775
|
);
|
|
774
776
|
return Object.fromEntries(s);
|
|
775
|
-
} catch (
|
|
777
|
+
} catch (r) {
|
|
776
778
|
throw new Error(
|
|
777
|
-
`Failed to setup worker code: ${
|
|
779
|
+
`Failed to setup worker code: ${r instanceof Error ? r.message : String(r)}`
|
|
778
780
|
);
|
|
779
781
|
}
|
|
780
|
-
}, fe = (e) => e ? typeof e == "string" ? [e] : Array.isArray(e) ? e : Object.values(e) : [],
|
|
782
|
+
}, fe = (e) => e ? typeof e == "string" ? [e] : Array.isArray(e) ? e : Object.values(e) : [], nr = async ({
|
|
781
783
|
entrypoint: e,
|
|
782
|
-
preset:
|
|
784
|
+
preset: t
|
|
783
785
|
}) => {
|
|
784
|
-
if (e && !
|
|
785
|
-
const
|
|
786
|
+
if (e && !t.handler) {
|
|
787
|
+
const r = fe(e), n = r.map((s) => v.resolve(s));
|
|
786
788
|
return await Promise.all(
|
|
787
789
|
n.map(async (s) => {
|
|
788
790
|
try {
|
|
@@ -794,43 +796,43 @@ addEventListener('fetch', (event) => {
|
|
|
794
796
|
}
|
|
795
797
|
})
|
|
796
798
|
), k.feedback.build.info(
|
|
797
|
-
`Using entry point(s): ${
|
|
799
|
+
`Using entry point(s): ${r.map((s) => Ke(process.cwd(), s)).join(", ")}`
|
|
798
800
|
), n;
|
|
799
801
|
}
|
|
800
|
-
if (
|
|
801
|
-
const
|
|
802
|
-
|
|
802
|
+
if (t.handler) {
|
|
803
|
+
const r = globalThis.bundler.root.includes("node_modules") ? v.resolve(globalThis.bundler.root, "../") : v.resolve(globalThis.bundler.root, "node_modules"), n = v.resolve(
|
|
804
|
+
r,
|
|
803
805
|
"azion/packages/presets/dist/presets",
|
|
804
|
-
|
|
806
|
+
t.metadata.name,
|
|
805
807
|
"handler.js"
|
|
806
808
|
);
|
|
807
809
|
try {
|
|
808
810
|
await u.access(n);
|
|
809
811
|
} catch (s) {
|
|
810
812
|
throw h.error(s), new Error(
|
|
811
|
-
`Missing handler "${n}" (default for "${
|
|
813
|
+
`Missing handler "${n}" (default for "${t.metadata.name}" preset). Either create this file or specify a custom entry point using --entry.`
|
|
812
814
|
);
|
|
813
815
|
}
|
|
814
|
-
return k.feedback.build.info(`Using built-in handler from "${
|
|
816
|
+
return k.feedback.build.info(`Using built-in handler from "${t.metadata.name}" preset.`), [n];
|
|
815
817
|
}
|
|
816
|
-
if (
|
|
817
|
-
const
|
|
818
|
+
if (t.config.build?.entry) {
|
|
819
|
+
const r = fe(t.config.build.entry), n = r.map((s) => v.resolve(s));
|
|
818
820
|
return await Promise.all(
|
|
819
821
|
n.map(async (s) => {
|
|
820
822
|
try {
|
|
821
823
|
await u.access(s);
|
|
822
824
|
} catch (i) {
|
|
823
825
|
throw h.error(i), new Error(
|
|
824
|
-
`Missing default entry point "${s}" for "${
|
|
826
|
+
`Missing default entry point "${s}" for "${t.metadata.name}" preset. Either create this file or specify a custom entry point using --entry.`
|
|
825
827
|
);
|
|
826
828
|
}
|
|
827
829
|
})
|
|
828
|
-
), k.feedback.build.info(`Using preset default entry: ${
|
|
830
|
+
), k.feedback.build.info(`Using preset default entry: ${r.join(", ")}`), n;
|
|
829
831
|
}
|
|
830
832
|
throw new Error(
|
|
831
833
|
"Cannot determine entry point. Please specify one using --entry or in your configuration."
|
|
832
834
|
);
|
|
833
|
-
},
|
|
835
|
+
}, sr = (e) => `//---
|
|
834
836
|
//storages:
|
|
835
837
|
// - name: assets
|
|
836
838
|
// bucket: ${e.bucket}
|
|
@@ -838,13 +840,13 @@ addEventListener('fetch', (event) => {
|
|
|
838
840
|
//---
|
|
839
841
|
/* this temporary binding is used to inject the storage name and prefix into the function file */
|
|
840
842
|
globalThis.AZION_BUCKET_NAME = '${e.bucket}';
|
|
841
|
-
globalThis.AZION_BUCKET_PREFIX = '${e.prefix}';`,
|
|
843
|
+
globalThis.AZION_BUCKET_PREFIX = '${e.prefix}';`, ir = async (e) => {
|
|
842
844
|
try {
|
|
843
845
|
return await u.access(e), !0;
|
|
844
846
|
} catch {
|
|
845
847
|
return !1;
|
|
846
848
|
}
|
|
847
|
-
},
|
|
849
|
+
}, or = (e) => v.isAbsolute(e) ? e : v.resolve(process.cwd(), _.OUTPUT_BASE_PATH, e), ar = (e, t) => t.find((r) => r.name === e), cr = async (e, t, r) => {
|
|
848
850
|
if (!e.path) {
|
|
849
851
|
h.warn(`Function ${e.name} does not have a defined path`);
|
|
850
852
|
return;
|
|
@@ -854,10 +856,10 @@ globalThis.AZION_BUCKET_PREFIX = '${e.prefix}';`, it = async (e) => {
|
|
|
854
856
|
h.info(`Function ${e.name} does not have storage bindings`);
|
|
855
857
|
return;
|
|
856
858
|
}
|
|
857
|
-
const s =
|
|
858
|
-
e.path.replace(/\.js$/,
|
|
859
|
+
const s = or(
|
|
860
|
+
e.path.replace(/\.js$/, r ? ".js" : ".dev.js")
|
|
859
861
|
);
|
|
860
|
-
if (!await
|
|
862
|
+
if (!await ir(s)) {
|
|
861
863
|
p.bindings.warn(`Function file not found: ${s}.`), p.bindings.info(`Binding injection skipped for function ${e.name}`);
|
|
862
864
|
return;
|
|
863
865
|
}
|
|
@@ -867,7 +869,7 @@ globalThis.AZION_BUCKET_PREFIX = '${e.prefix}';`, it = async (e) => {
|
|
|
867
869
|
h.info(`Function ${e.name} already has injected bindings`);
|
|
868
870
|
return;
|
|
869
871
|
}
|
|
870
|
-
const o = String(n.bucket), a =
|
|
872
|
+
const o = String(n.bucket), a = ar(o, t);
|
|
871
873
|
if (!a) {
|
|
872
874
|
h.warn(`Storage '${o}' not found for function ${e.name}`);
|
|
873
875
|
return;
|
|
@@ -876,7 +878,7 @@ globalThis.AZION_BUCKET_PREFIX = '${e.prefix}';`, it = async (e) => {
|
|
|
876
878
|
c || p.postbuild.info(
|
|
877
879
|
`No prefix provided for binding in function '${e.name}', using storage prefix: ${l}`
|
|
878
880
|
);
|
|
879
|
-
const f =
|
|
881
|
+
const f = sr({
|
|
880
882
|
bucket: o,
|
|
881
883
|
prefix: l
|
|
882
884
|
});
|
|
@@ -887,10 +889,10 @@ ${i}`;
|
|
|
887
889
|
} catch (i) {
|
|
888
890
|
throw h.error(`Failed to process bindings for function ${e.name}:`, i), i;
|
|
889
891
|
}
|
|
890
|
-
},
|
|
892
|
+
}, lr = async ({
|
|
891
893
|
config: e,
|
|
892
|
-
storageSetup:
|
|
893
|
-
isProduction:
|
|
894
|
+
storageSetup: t,
|
|
895
|
+
isProduction: r
|
|
894
896
|
}) => {
|
|
895
897
|
try {
|
|
896
898
|
const n = e.functions || [];
|
|
@@ -899,45 +901,45 @@ ${i}`;
|
|
|
899
901
|
return;
|
|
900
902
|
}
|
|
901
903
|
h.info("Injecting bindings into functions..."), await Promise.all(
|
|
902
|
-
n.map((s) =>
|
|
904
|
+
n.map((s) => cr(s, t, r))
|
|
903
905
|
);
|
|
904
906
|
} catch (n) {
|
|
905
907
|
return h.error("Failed to execute bindings setup:", n), Promise.reject(n);
|
|
906
908
|
}
|
|
907
|
-
},
|
|
909
|
+
}, fr = () => `${Date.now()}`, ur = async (e) => {
|
|
908
910
|
try {
|
|
909
911
|
return await u.access(e), (await u.stat(e)).isDirectory();
|
|
910
912
|
} catch {
|
|
911
913
|
return !1;
|
|
912
914
|
}
|
|
913
|
-
},
|
|
915
|
+
}, dr = async (e, t) => {
|
|
914
916
|
try {
|
|
915
|
-
const
|
|
917
|
+
const r = _.OUTPUT_STORAGE_METADATA_PATH;
|
|
916
918
|
let n = [];
|
|
917
919
|
try {
|
|
918
|
-
const i = await u.readFile(
|
|
920
|
+
const i = await u.readFile(r, "utf-8");
|
|
919
921
|
n = JSON.parse(i);
|
|
920
922
|
} catch {
|
|
921
923
|
h.info("Creating new storage metadata file");
|
|
922
924
|
}
|
|
923
925
|
const s = {
|
|
924
|
-
...
|
|
926
|
+
...t,
|
|
925
927
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
926
928
|
};
|
|
927
|
-
n = n.filter((i) => i.name !== e), n.push(s), await u.writeFile(
|
|
928
|
-
} catch (
|
|
929
|
-
throw h.error(`Failed to save storage metadata for ${e}:`,
|
|
929
|
+
n = n.filter((i) => i.name !== e), n.push(s), await u.writeFile(r, JSON.stringify(n, null, 2), "utf-8"), h.info(`Storage metadata saved for: ${e}`);
|
|
930
|
+
} catch (r) {
|
|
931
|
+
throw h.error(`Failed to save storage metadata for ${e}:`, r), r;
|
|
930
932
|
}
|
|
931
|
-
},
|
|
933
|
+
}, pr = async (e, t, r, n) => {
|
|
932
934
|
const s = e.name;
|
|
933
935
|
try {
|
|
934
|
-
const i = v.join(
|
|
935
|
-
await u.mkdir(v.join(
|
|
936
|
+
const i = v.join(r, s, n);
|
|
937
|
+
await u.mkdir(v.join(r, s), { recursive: !0 });
|
|
936
938
|
try {
|
|
937
|
-
const o = await u.readdir(v.join(
|
|
939
|
+
const o = await u.readdir(v.join(r, s));
|
|
938
940
|
await Promise.all(
|
|
939
941
|
o.filter((a) => a !== n).map(async (a) => {
|
|
940
|
-
const c = v.join(
|
|
942
|
+
const c = v.join(r, s, a);
|
|
941
943
|
try {
|
|
942
944
|
const l = await u.lstat(c);
|
|
943
945
|
l.isSymbolicLink() ? await u.unlink(c) : l.isDirectory() ? await u.rmdir(c, { recursive: !0 }) : await u.unlink(c);
|
|
@@ -945,64 +947,64 @@ ${i}`;
|
|
|
945
947
|
h.warn(`Failed to remove ${c}:`, l);
|
|
946
948
|
}
|
|
947
949
|
})
|
|
948
|
-
), h.info(`Cleaned up existing storage items in: ${v.join(
|
|
950
|
+
), h.info(`Cleaned up existing storage items in: ${v.join(r, s)}`);
|
|
949
951
|
} catch {
|
|
950
|
-
h.warn(`Storage directory not found or empty: ${v.join(
|
|
952
|
+
h.warn(`Storage directory not found or empty: ${v.join(r, s)}`);
|
|
951
953
|
}
|
|
952
954
|
try {
|
|
953
955
|
const o = await u.lstat(i);
|
|
954
956
|
o.isSymbolicLink() ? (await u.unlink(i), h.info(`Removed existing symlink: ${i}`)) : o.isDirectory() && (await u.rmdir(i, { recursive: !0 }), h.info(`Removed existing directory: ${i}`));
|
|
955
957
|
} catch {
|
|
956
958
|
}
|
|
957
|
-
await u.symlink(
|
|
959
|
+
await u.symlink(t, i, "dir"), h.info(`Storage link created: ${s} -> ${t}`), await dr(s, {
|
|
958
960
|
name: s,
|
|
959
961
|
workloadsAccess: e.workloadsAccess || "read_only",
|
|
960
|
-
sourceDir:
|
|
962
|
+
sourceDir: t,
|
|
961
963
|
targetDir: i,
|
|
962
964
|
prefix: n
|
|
963
965
|
});
|
|
964
966
|
} catch (i) {
|
|
965
967
|
throw h.error(`Failed to create storage link for ${s}:`, i), i;
|
|
966
968
|
}
|
|
967
|
-
},
|
|
969
|
+
}, hr = (e) => !e.name || !e.dir ? (h.warn("Storage configuration is missing required fields (name or dir)"), !1) : !0, gr = async ({ config: e }) => {
|
|
968
970
|
try {
|
|
969
|
-
const
|
|
970
|
-
if (
|
|
971
|
-
return h.info("No storages found to setup"),
|
|
971
|
+
const t = e.storage || [], r = [];
|
|
972
|
+
if (t.length === 0)
|
|
973
|
+
return h.info("No storages found to setup"), r;
|
|
972
974
|
await u.mkdir(_.OUTPUT_STORAGE_PATH, { recursive: !0 });
|
|
973
|
-
for (const n of
|
|
974
|
-
if (!
|
|
975
|
+
for (const n of t) {
|
|
976
|
+
if (!hr(n))
|
|
975
977
|
continue;
|
|
976
978
|
const s = v.resolve(process.cwd(), n.dir);
|
|
977
|
-
if (!await
|
|
979
|
+
if (!await ur(s))
|
|
978
980
|
throw new Error(
|
|
979
981
|
`Storage directory not found: ${s}.
|
|
980
982
|
- Please check the path provided in the azion.config file on storage[].dir`
|
|
981
983
|
);
|
|
982
|
-
const i = n.prefix, o = i ||
|
|
984
|
+
const i = n.prefix, o = i || fr();
|
|
983
985
|
i || p.storage.info(
|
|
984
986
|
`No prefix provided for storage '${n.name}', generating version prefix: ${o}`
|
|
985
|
-
), i && p.storage.info(`Using provided prefix for storage '${n.name}': ${o}`), await
|
|
987
|
+
), i && p.storage.info(`Using provided prefix for storage '${n.name}': ${o}`), await pr(n, s, _.OUTPUT_STORAGE_PATH, o), r.push({
|
|
986
988
|
...n,
|
|
987
989
|
prefix: o
|
|
988
990
|
});
|
|
989
991
|
}
|
|
990
|
-
return h.info("Storage setup completed successfully"),
|
|
991
|
-
} catch (
|
|
992
|
-
throw h.error("Failed to setup storages:",
|
|
992
|
+
return h.info("Storage setup completed successfully"), r;
|
|
993
|
+
} catch (t) {
|
|
994
|
+
throw h.error("Failed to setup storages:", t), t;
|
|
993
995
|
}
|
|
994
|
-
},
|
|
996
|
+
}, mr = async (e) => {
|
|
995
997
|
try {
|
|
996
|
-
const { config:
|
|
997
|
-
|
|
998
|
-
const s = await
|
|
999
|
-
if (
|
|
998
|
+
const { config: t, options: r } = e, n = !!r.production;
|
|
999
|
+
r.skipFrameworkBuild && p.build.warn("Skipping framework build"), await vt();
|
|
1000
|
+
const s = await At(t.build?.preset), i = await $t(t, s, n);
|
|
1001
|
+
if (r.onlyGenerateConfig) {
|
|
1000
1002
|
const d = await le({
|
|
1001
|
-
config:
|
|
1003
|
+
config: t,
|
|
1002
1004
|
preset: s,
|
|
1003
1005
|
ctx: {
|
|
1004
1006
|
production: n ?? F.PRODUCTION,
|
|
1005
|
-
skipFrameworkBuild: !!
|
|
1007
|
+
skipFrameworkBuild: !!r.skipFrameworkBuild,
|
|
1006
1008
|
handler: ""
|
|
1007
1009
|
}
|
|
1008
1010
|
});
|
|
@@ -1010,7 +1012,7 @@ ${i}`;
|
|
|
1010
1012
|
config: d,
|
|
1011
1013
|
ctx: {
|
|
1012
1014
|
production: n ?? F.PRODUCTION,
|
|
1013
|
-
skipFrameworkBuild: !!
|
|
1015
|
+
skipFrameworkBuild: !!r.skipFrameworkBuild,
|
|
1014
1016
|
handler: ""
|
|
1015
1017
|
},
|
|
1016
1018
|
setup: i
|
|
@@ -1018,28 +1020,28 @@ ${i}`;
|
|
|
1018
1020
|
}
|
|
1019
1021
|
let o = {
|
|
1020
1022
|
production: n ?? F.PRODUCTION,
|
|
1021
|
-
skipFrameworkBuild: !!
|
|
1023
|
+
skipFrameworkBuild: !!r.skipFrameworkBuild,
|
|
1022
1024
|
handler: ""
|
|
1023
1025
|
};
|
|
1024
1026
|
const a = await le({
|
|
1025
|
-
config:
|
|
1027
|
+
config: t,
|
|
1026
1028
|
preset: s,
|
|
1027
1029
|
ctx: o
|
|
1028
1030
|
});
|
|
1029
1031
|
oe(a), p.prebuild.info("Starting pre-build...");
|
|
1030
|
-
const c = await
|
|
1032
|
+
const c = await It({
|
|
1031
1033
|
buildConfig: i,
|
|
1032
1034
|
ctx: o
|
|
1033
1035
|
});
|
|
1034
1036
|
p.prebuild.info("Pre-build completed successfully"), o = {
|
|
1035
1037
|
production: n ?? F.PRODUCTION,
|
|
1036
|
-
handler: await
|
|
1037
|
-
entrypoint:
|
|
1038
|
+
handler: await nr({
|
|
1039
|
+
entrypoint: t.build?.entry,
|
|
1038
1040
|
preset: s
|
|
1039
1041
|
}),
|
|
1040
|
-
skipFrameworkBuild: !!
|
|
1042
|
+
skipFrameworkBuild: !!r.skipFrameworkBuild
|
|
1041
1043
|
};
|
|
1042
|
-
const l = await
|
|
1044
|
+
const l = await rr(i, o), f = [];
|
|
1043
1045
|
await Promise.all(
|
|
1044
1046
|
Object.entries(l).map(async ([d, m]) => {
|
|
1045
1047
|
await ye(we(d), { recursive: !0 }), await Ze(d, m, "utf-8"), f.push(d);
|
|
@@ -1047,54 +1049,54 @@ ${i}`;
|
|
|
1047
1049
|
);
|
|
1048
1050
|
for (const d of f)
|
|
1049
1051
|
await Le(d);
|
|
1050
|
-
p.build.info("Starting build..."), await
|
|
1052
|
+
p.build.info("Starting build..."), await Vt({
|
|
1051
1053
|
buildConfig: i,
|
|
1052
1054
|
prebuildResult: c,
|
|
1053
1055
|
ctx: o
|
|
1054
|
-
}), p.build.success("Build completed successfully"), await He(), p.postbuild.info("Starting post-build..."), await
|
|
1055
|
-
const w = await
|
|
1056
|
-
return await
|
|
1056
|
+
}), p.build.success("Build completed successfully"), await He(), p.postbuild.info("Starting post-build..."), await Gt({ buildConfig: i, ctx: o }), p.postbuild.success("Post-build completed successfully");
|
|
1057
|
+
const w = await gr({ config: a });
|
|
1058
|
+
return await lr({ config: a, storageSetup: w, isProduction: n }), await Ve(), {
|
|
1057
1059
|
config: a,
|
|
1058
1060
|
ctx: o,
|
|
1059
1061
|
setup: i
|
|
1060
1062
|
};
|
|
1061
|
-
} catch (
|
|
1062
|
-
h.error("Build process failed:",
|
|
1063
|
-
`${
|
|
1063
|
+
} catch (t) {
|
|
1064
|
+
h.error("Build process failed:", t), p.build.error(
|
|
1065
|
+
`${t instanceof Error ? t.message : String(t)}${A}`
|
|
1064
1066
|
), process.exit(1);
|
|
1065
1067
|
}
|
|
1066
1068
|
};
|
|
1067
|
-
async function
|
|
1068
|
-
const
|
|
1069
|
+
async function wr(e) {
|
|
1070
|
+
const t = await Z() || {}, { build: r } = t, n = {
|
|
1069
1071
|
preset: U({
|
|
1070
1072
|
inputValue: e.preset,
|
|
1071
|
-
fileValue:
|
|
1073
|
+
fileValue: r?.preset,
|
|
1072
1074
|
defaultValue: F.PRESET
|
|
1073
1075
|
}),
|
|
1074
1076
|
entry: U({
|
|
1075
1077
|
inputValue: e.entry,
|
|
1076
|
-
fileValue:
|
|
1078
|
+
fileValue: r?.entry,
|
|
1077
1079
|
defaultValue: F.ENTRY
|
|
1078
1080
|
}),
|
|
1079
1081
|
bundler: U({
|
|
1080
1082
|
inputValue: void 0,
|
|
1081
|
-
fileValue:
|
|
1083
|
+
fileValue: r?.bundler,
|
|
1082
1084
|
defaultValue: F.BUNDLER
|
|
1083
1085
|
}),
|
|
1084
1086
|
polyfills: U({
|
|
1085
|
-
inputValue:
|
|
1087
|
+
inputValue: r?.polyfills,
|
|
1086
1088
|
fileValue: e.polyfills,
|
|
1087
1089
|
defaultValue: F.POLYFILLS
|
|
1088
1090
|
})
|
|
1089
1091
|
}, s = {
|
|
1090
|
-
...
|
|
1092
|
+
...t,
|
|
1091
1093
|
build: {
|
|
1092
1094
|
...n,
|
|
1093
|
-
memoryFS:
|
|
1094
|
-
extend:
|
|
1095
|
+
memoryFS: t?.build?.memoryFS,
|
|
1096
|
+
extend: t?.build?.extend
|
|
1095
1097
|
}
|
|
1096
1098
|
};
|
|
1097
|
-
return e.production && await
|
|
1099
|
+
return e.production && await Tt([_.OUTPUT_BASE_PATH]), mr({
|
|
1098
1100
|
config: s,
|
|
1099
1101
|
options: {
|
|
1100
1102
|
production: e.production,
|
|
@@ -1104,67 +1106,67 @@ async function wt(e) {
|
|
|
1104
1106
|
});
|
|
1105
1107
|
}
|
|
1106
1108
|
let q, L = !1;
|
|
1107
|
-
const
|
|
1108
|
-
let s =
|
|
1109
|
-
const i = new RegExp(`addEventListener\\((['"]?)${e}\\1,`, "g"), o = /firewall:\s*\(event\)\s*=>\s*{/g, a = !!
|
|
1110
|
-
return (n && l || a) && (s =
|
|
1109
|
+
const yr = (e, t, r, n = !0) => {
|
|
1110
|
+
let s = r;
|
|
1111
|
+
const i = new RegExp(`addEventListener\\((['"]?)${e}\\1,`, "g"), o = /firewall:\s*\(event\)\s*=>\s*{/g, a = !!r.match(o), c = /eventType\s*=\s*['"]firewall['"];/g, l = !!r.match(i);
|
|
1112
|
+
return (n && l || a) && (s = r.replace(i, `addEventListener("${t}",`), a && (s = s.replace(c, "eventType = 'fetch';"))), { matchEvent: l || a, codeChanged: s };
|
|
1111
1113
|
};
|
|
1112
|
-
function
|
|
1113
|
-
return new Promise((
|
|
1114
|
-
const
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
}),
|
|
1118
|
-
|
|
1119
|
-
}),
|
|
1120
|
-
|
|
1121
|
-
}),
|
|
1114
|
+
function br(e) {
|
|
1115
|
+
return new Promise((t) => {
|
|
1116
|
+
const r = new ot.Socket();
|
|
1117
|
+
r.setTimeout(1e3), r.on("connect", () => {
|
|
1118
|
+
r.destroy(), t(!0);
|
|
1119
|
+
}), r.on("timeout", () => {
|
|
1120
|
+
r.destroy(), t(!1);
|
|
1121
|
+
}), r.on("error", (n) => {
|
|
1122
|
+
r.destroy(), n.message.includes("ECONNREFUSED") ? t(!1) : t(!0);
|
|
1123
|
+
}), r.connect(e, "127.0.0.1");
|
|
1122
1124
|
});
|
|
1123
1125
|
}
|
|
1124
|
-
async function
|
|
1126
|
+
async function Er(e) {
|
|
1125
1127
|
try {
|
|
1126
1128
|
return await u.access(e), await u.readFile(e, "utf8");
|
|
1127
|
-
} catch (
|
|
1128
|
-
if (
|
|
1129
|
-
const
|
|
1129
|
+
} catch (t) {
|
|
1130
|
+
if (t.message.includes("ENOENT")) {
|
|
1131
|
+
const r = J(e);
|
|
1130
1132
|
throw new Error(
|
|
1131
|
-
`Server entry file "${
|
|
1133
|
+
`Server entry file "${r}" not found. Please specify your entry point using "azion dev <path>" or create the default handler file.${A}`
|
|
1132
1134
|
);
|
|
1133
1135
|
}
|
|
1134
|
-
throw new Error(`Error reading file ${e}: ${
|
|
1136
|
+
throw new Error(`Error reading file ${e}: ${t.message}${A}`);
|
|
1135
1137
|
}
|
|
1136
1138
|
}
|
|
1137
|
-
async function
|
|
1138
|
-
const { matchEvent:
|
|
1139
|
+
async function vr(e, t) {
|
|
1140
|
+
const { matchEvent: r, codeChanged: n } = (
|
|
1139
1141
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1140
|
-
|
|
1141
|
-
), i = ve(
|
|
1142
|
-
return
|
|
1142
|
+
yr("firewall", "fetch", t)
|
|
1143
|
+
), i = ve(r ? n : t, r);
|
|
1144
|
+
return at({ port: e, host: "0.0.0.0", runtime: i });
|
|
1143
1145
|
}
|
|
1144
|
-
function ue(e,
|
|
1145
|
-
const
|
|
1146
|
-
return { bucketName:
|
|
1146
|
+
function ue(e, t) {
|
|
1147
|
+
const r = e?.bindings?.storage?.bucket || t?.storage?.[0].name || "", n = e?.bindings?.storage?.prefix || t?.storage?.[0].prefix || "";
|
|
1148
|
+
return { bucketName: r, prefix: n };
|
|
1147
1149
|
}
|
|
1148
|
-
function
|
|
1150
|
+
function Tr(e, t, r) {
|
|
1149
1151
|
const n = Object.keys(e).find((s) => {
|
|
1150
1152
|
const i = s.replace(/\.dev$/, "").replace(/\.edge\//, "");
|
|
1151
|
-
return
|
|
1153
|
+
return r.replace(/\.js$/, "").endsWith(i);
|
|
1152
1154
|
});
|
|
1153
1155
|
if (!n)
|
|
1154
|
-
throw new Error(`Entry path not found for function "${
|
|
1156
|
+
throw new Error(`Entry path not found for function "${t}"`);
|
|
1155
1157
|
return n;
|
|
1156
1158
|
}
|
|
1157
1159
|
function de(e) {
|
|
1158
1160
|
return e.endsWith(".js") ? e : `${e}.js`;
|
|
1159
1161
|
}
|
|
1160
|
-
function
|
|
1162
|
+
function Sr(e, t, r) {
|
|
1161
1163
|
if (!e || Object.keys(e).length === 0)
|
|
1162
1164
|
throw new Error("No entries provided");
|
|
1163
|
-
if (
|
|
1164
|
-
const o =
|
|
1165
|
+
if (r) {
|
|
1166
|
+
const o = t.functions?.find((l) => l.name === r);
|
|
1165
1167
|
if (!o)
|
|
1166
|
-
throw new Error(`Function "${
|
|
1167
|
-
const a =
|
|
1168
|
+
throw new Error(`Function "${r}" not found in edge functions configuration`);
|
|
1169
|
+
const a = Tr(e, r, o.path), c = ue(o, t);
|
|
1168
1170
|
return {
|
|
1169
1171
|
name: o.name,
|
|
1170
1172
|
bucket: c.bucketName,
|
|
@@ -1172,7 +1174,7 @@ function St(e, r, t) {
|
|
|
1172
1174
|
path: de(a)
|
|
1173
1175
|
};
|
|
1174
1176
|
}
|
|
1175
|
-
const n = Object.keys(e)[0], s =
|
|
1177
|
+
const n = Object.keys(e)[0], s = t.functions?.[0], i = ue(s, t);
|
|
1176
1178
|
return {
|
|
1177
1179
|
name: s?.name,
|
|
1178
1180
|
bucket: i.bucketName,
|
|
@@ -1180,31 +1182,31 @@ function St(e, r, t) {
|
|
|
1180
1182
|
path: de(n)
|
|
1181
1183
|
};
|
|
1182
1184
|
}
|
|
1183
|
-
async function
|
|
1185
|
+
async function re(e, t, r = !1, n) {
|
|
1184
1186
|
try {
|
|
1185
1187
|
q && await q.close();
|
|
1186
1188
|
const {
|
|
1187
1189
|
setup: { entry: s },
|
|
1188
1190
|
config: { functions: i, storage: o }
|
|
1189
|
-
} = await
|
|
1191
|
+
} = await wr({ production: !1, skipFrameworkBuild: r });
|
|
1190
1192
|
let a;
|
|
1191
1193
|
try {
|
|
1192
1194
|
const {
|
|
1193
1195
|
path: c,
|
|
1194
1196
|
bucket: l,
|
|
1195
1197
|
prefix: f
|
|
1196
|
-
} =
|
|
1197
|
-
globalThis.AZION_BUCKET_NAME = l, globalThis.AZION_BUCKET_PREFIX = f, a = await
|
|
1198
|
+
} = Sr(s, { functions: i, storage: o }, n);
|
|
1199
|
+
globalThis.AZION_BUCKET_NAME = l, globalThis.AZION_BUCKET_PREFIX = f, a = await Er(c);
|
|
1198
1200
|
} catch (c) {
|
|
1199
1201
|
p.server.error(c.message), h.error(`Error reading worker file: ${c}`), process.exit(1);
|
|
1200
1202
|
}
|
|
1201
1203
|
try {
|
|
1202
|
-
q = await
|
|
1203
|
-
`Function running on port 0.0.0.0:${
|
|
1204
|
+
q = await vr(t, a), p.server.success(
|
|
1205
|
+
`Function running on port 0.0.0.0:${t}, url: http://localhost:${t}`
|
|
1204
1206
|
);
|
|
1205
1207
|
} catch (c) {
|
|
1206
1208
|
if (c.message.includes("EADDRINUSE"))
|
|
1207
|
-
await
|
|
1209
|
+
await re(e, t + 1);
|
|
1208
1210
|
else
|
|
1209
1211
|
throw c;
|
|
1210
1212
|
}
|
|
@@ -1216,11 +1218,11 @@ async function te(e, r, t = !1, n) {
|
|
|
1216
1218
|
L = !1;
|
|
1217
1219
|
}
|
|
1218
1220
|
}
|
|
1219
|
-
async function
|
|
1221
|
+
async function Pr(e, t, r) {
|
|
1220
1222
|
if (!L && !(e.startsWith(".azion-bundler") || e.startsWith("azion") && e.includes(".temp") || e.startsWith(".edge") || e.startsWith("node_modules") || e.startsWith(".vercel"))) {
|
|
1221
1223
|
L = !0;
|
|
1222
1224
|
try {
|
|
1223
|
-
p.build.info("Rebuilding with the new changes..."), await
|
|
1225
|
+
p.build.info("Rebuilding with the new changes..."), await re(t, r);
|
|
1224
1226
|
} catch (n) {
|
|
1225
1227
|
h.error(`Build or server restart failed: ${n}`);
|
|
1226
1228
|
} finally {
|
|
@@ -1228,8 +1230,8 @@ async function Pt(e, r, t) {
|
|
|
1228
1230
|
}
|
|
1229
1231
|
}
|
|
1230
1232
|
}
|
|
1231
|
-
async function $e(e,
|
|
1232
|
-
await
|
|
1233
|
+
async function $e(e, t, r = !1, n) {
|
|
1234
|
+
await br(t) && (p.server.error(`Port ${t} is in use. Please choose another port.`), process.exit(1)), await re(e, t, r, n);
|
|
1233
1235
|
const i = qe.watch("./", {
|
|
1234
1236
|
persistent: !0,
|
|
1235
1237
|
ignoreInitial: !0,
|
|
@@ -1238,7 +1240,7 @@ async function $e(e, r, t = !1, n) {
|
|
|
1238
1240
|
ignored: [".git", ".vscode", ".idea", ".sublime-text", ".history"]
|
|
1239
1241
|
// Added common IDE-related folders
|
|
1240
1242
|
}), o = async (a) => {
|
|
1241
|
-
await
|
|
1243
|
+
await Pr(a, e, t);
|
|
1242
1244
|
};
|
|
1243
1245
|
i.on("add", o).on("change", o).on("unlink", o).on("addDir", o).on("unlinkDir", o).on("error", (a) => h.error(`Watcher error: ${a}`)).on("ready", () => p.server.info("Initial scan complete. Ready for changes."));
|
|
1244
1246
|
}
|
|
@@ -1252,40 +1254,40 @@ const pe = {
|
|
|
1252
1254
|
};
|
|
1253
1255
|
async function un({
|
|
1254
1256
|
entry: e,
|
|
1255
|
-
port:
|
|
1256
|
-
skipFrameworkBuild:
|
|
1257
|
+
port: t,
|
|
1258
|
+
skipFrameworkBuild: r = !1,
|
|
1257
1259
|
functionName: n
|
|
1258
1260
|
}) {
|
|
1259
|
-
const s = parseInt(
|
|
1260
|
-
$e(e || null, s,
|
|
1261
|
+
const s = parseInt(t, 10);
|
|
1262
|
+
$e(e || null, s, r, n);
|
|
1261
1263
|
}
|
|
1262
|
-
function $
|
|
1263
|
-
return Object.values(j).map((
|
|
1264
|
+
function $r() {
|
|
1265
|
+
return Object.values(j).map((t) => t.metadata.name);
|
|
1264
1266
|
}
|
|
1265
|
-
function
|
|
1267
|
+
function xr() {
|
|
1266
1268
|
return Object.keys(j);
|
|
1267
1269
|
}
|
|
1268
|
-
function
|
|
1269
|
-
const
|
|
1270
|
-
if (!
|
|
1270
|
+
function kr(e) {
|
|
1271
|
+
const t = j[e];
|
|
1272
|
+
if (!t)
|
|
1271
1273
|
throw new Error(
|
|
1272
1274
|
`Preset '${e}' not found. Run 'ef presets ls' to see available presets.`
|
|
1273
1275
|
);
|
|
1274
|
-
return
|
|
1276
|
+
return t.config;
|
|
1275
1277
|
}
|
|
1276
|
-
async function dn(e,
|
|
1277
|
-
const
|
|
1278
|
+
async function dn(e, t = {}) {
|
|
1279
|
+
const r = process.env.CLEAN_OUTPUT_MODE === "true";
|
|
1278
1280
|
switch (e) {
|
|
1279
1281
|
case "ls":
|
|
1280
|
-
|
|
1282
|
+
r && xr().forEach((n) => console.log(n)), r || $r().forEach((n) => p.option(n));
|
|
1281
1283
|
break;
|
|
1282
1284
|
case "config":
|
|
1283
|
-
if (!
|
|
1285
|
+
if (!t.preset) {
|
|
1284
1286
|
p.error("Preset name is required. Use: ef presets config <preset-name>");
|
|
1285
1287
|
return;
|
|
1286
1288
|
}
|
|
1287
1289
|
try {
|
|
1288
|
-
const n =
|
|
1290
|
+
const n = kr(t.preset);
|
|
1289
1291
|
console.log(JSON.stringify(n, null, 2));
|
|
1290
1292
|
} catch (n) {
|
|
1291
1293
|
p.error(n instanceof Error ? n.message : "Unknown error occurred");
|
|
@@ -1296,64 +1298,64 @@ async function dn(e, r = {}) {
|
|
|
1296
1298
|
break;
|
|
1297
1299
|
}
|
|
1298
1300
|
}
|
|
1299
|
-
function
|
|
1301
|
+
function Cr(e) {
|
|
1300
1302
|
return Ye(e);
|
|
1301
1303
|
}
|
|
1302
|
-
const
|
|
1304
|
+
const Fr = { processConfigWrapper: Cr }, _r = ".edge/manifest.json", Ar = "azion.config", Or = async (e, t = C(process.cwd(), ".edge")) => {
|
|
1303
1305
|
try {
|
|
1304
|
-
await D.access(
|
|
1306
|
+
await D.access(t);
|
|
1305
1307
|
} catch {
|
|
1306
|
-
await D.mkdir(
|
|
1308
|
+
await D.mkdir(t, { recursive: !0 });
|
|
1307
1309
|
}
|
|
1308
|
-
let
|
|
1310
|
+
let r;
|
|
1309
1311
|
if (typeof e == "object")
|
|
1310
|
-
|
|
1312
|
+
r = e;
|
|
1311
1313
|
else {
|
|
1312
1314
|
const i = await me.readAzionConfig(e);
|
|
1313
1315
|
if (!i)
|
|
1314
1316
|
throw new Error(
|
|
1315
1317
|
e ? `Failed to load config from ${e}` : "No configuration found. Please provide a config file or object."
|
|
1316
1318
|
);
|
|
1317
|
-
|
|
1319
|
+
r = i;
|
|
1318
1320
|
}
|
|
1319
|
-
const n =
|
|
1321
|
+
const n = Fr.processConfigWrapper(r), s = C(t, "manifest.json");
|
|
1320
1322
|
await D.writeFile(s, JSON.stringify(n, null, 2)), k.feedback.manifest.success(`Manifest generated successfully at ${s}`);
|
|
1321
|
-
},
|
|
1323
|
+
}, jr = async (e, t = Ar) => {
|
|
1322
1324
|
const n = await (async (s) => {
|
|
1323
1325
|
const i = Y(process.cwd(), s);
|
|
1324
1326
|
if (H(i) !== ".json")
|
|
1325
1327
|
throw new Error("Input file must be .json");
|
|
1326
1328
|
const o = await D.readFile(i, "utf8");
|
|
1327
1329
|
return Qe(o);
|
|
1328
|
-
})(e ||
|
|
1329
|
-
await me.writeUserConfig(n,
|
|
1330
|
+
})(e || _r);
|
|
1331
|
+
await me.writeUserConfig(n, t), k.feedback.manifest.success(`Config file generated successfully at ${t}`);
|
|
1330
1332
|
};
|
|
1331
1333
|
async function pn(e) {
|
|
1332
1334
|
try {
|
|
1333
|
-
const
|
|
1335
|
+
const t = e.action || "generate", n = {
|
|
1334
1336
|
generate: async () => {
|
|
1335
1337
|
const s = e.entry || e.config;
|
|
1336
|
-
await
|
|
1338
|
+
await Or(s, e.output);
|
|
1337
1339
|
},
|
|
1338
1340
|
transform: async () => {
|
|
1339
|
-
await
|
|
1341
|
+
await jr(e.entry, e.output);
|
|
1340
1342
|
}
|
|
1341
|
-
}[
|
|
1343
|
+
}[t];
|
|
1342
1344
|
n && await n(), n || (p.manifest.error(
|
|
1343
1345
|
"Only transform and generate actions are supported"
|
|
1344
1346
|
), process.exit(1));
|
|
1345
|
-
} catch (
|
|
1346
|
-
h.error(
|
|
1347
|
+
} catch (t) {
|
|
1348
|
+
h.error(t), p.error(`${t instanceof Error ? t.message : String(t)}${A}`), await Q(_.OUTPUT_BASE_PATH, { recursive: !0, force: !0 }), process.exit(1);
|
|
1347
1349
|
}
|
|
1348
1350
|
}
|
|
1349
|
-
async function hn({ command: e, options:
|
|
1350
|
-
const
|
|
1351
|
-
typeof
|
|
1352
|
-
), n =
|
|
1351
|
+
async function hn({ command: e, options: t }) {
|
|
1352
|
+
const r = JSON.parse(
|
|
1353
|
+
typeof t.config == "string" ? t.config : "{}"
|
|
1354
|
+
), n = t.scope || "global";
|
|
1353
1355
|
try {
|
|
1354
1356
|
switch (e) {
|
|
1355
1357
|
case "init": {
|
|
1356
|
-
const s = { ...
|
|
1358
|
+
const s = { ...r };
|
|
1357
1359
|
await ge(s, n), p.info(`Store file initialized with scope: ${n}`);
|
|
1358
1360
|
break;
|
|
1359
1361
|
}
|
|
@@ -1370,8 +1372,8 @@ async function hn({ command: e, options: r }) {
|
|
|
1370
1372
|
function X(e) {
|
|
1371
1373
|
if (typeof e != "string")
|
|
1372
1374
|
return e;
|
|
1373
|
-
const
|
|
1374
|
-
if (!
|
|
1375
|
+
const t = e.trim();
|
|
1376
|
+
if (!t.startsWith("{") && !t.startsWith("["))
|
|
1375
1377
|
return e;
|
|
1376
1378
|
try {
|
|
1377
1379
|
return JSON.parse(e);
|
|
@@ -1379,8 +1381,8 @@ function X(e) {
|
|
|
1379
1381
|
return e;
|
|
1380
1382
|
}
|
|
1381
1383
|
}
|
|
1382
|
-
async function
|
|
1383
|
-
const
|
|
1384
|
+
async function Rr() {
|
|
1385
|
+
const t = await ct("azion", {
|
|
1384
1386
|
searchPlaces: [
|
|
1385
1387
|
"azion.config.ts",
|
|
1386
1388
|
"azion.config.mts",
|
|
@@ -1396,38 +1398,38 @@ async function Rt() {
|
|
|
1396
1398
|
".cts": V()
|
|
1397
1399
|
}
|
|
1398
1400
|
}).search();
|
|
1399
|
-
if (!
|
|
1401
|
+
if (!t)
|
|
1400
1402
|
throw new Error("No azion config file found");
|
|
1401
|
-
const
|
|
1402
|
-
return { configPath:
|
|
1403
|
+
const r = t.filepath, n = await u.readFile(r, "utf8");
|
|
1404
|
+
return { configPath: r, fileContent: n };
|
|
1403
1405
|
}
|
|
1404
1406
|
const xe = {
|
|
1405
|
-
findAndReadConfigFile:
|
|
1407
|
+
findAndReadConfigFile: Rr,
|
|
1406
1408
|
tryParseJSON: X
|
|
1407
1409
|
};
|
|
1408
|
-
function
|
|
1409
|
-
const
|
|
1410
|
-
let n =
|
|
1411
|
-
for (let s = 0; s <
|
|
1412
|
-
const i =
|
|
1410
|
+
function Ur(e) {
|
|
1411
|
+
const t = {}, r = e.key.split(".");
|
|
1412
|
+
let n = t;
|
|
1413
|
+
for (let s = 0; s < r.length; s++) {
|
|
1414
|
+
const i = r[s], o = i.match(/^(.+)\[(\d+)\]$/);
|
|
1413
1415
|
if (o) {
|
|
1414
1416
|
const a = o[1], c = parseInt(o[2]);
|
|
1415
|
-
s ===
|
|
1417
|
+
s === r.length - 1 ? (n[a] || (n[a] = []), n[a][c] = X(e.value)) : (n[a] || (n[a] = []), n[a][c] || (n[a][c] = {}), n = n[a][c]);
|
|
1416
1418
|
} else
|
|
1417
|
-
s ===
|
|
1419
|
+
s === r.length - 1 ? n[i] = X(e.value) : (n[i] || (n[i] = {}), n = n[i]);
|
|
1418
1420
|
}
|
|
1419
|
-
return
|
|
1421
|
+
return t;
|
|
1420
1422
|
}
|
|
1421
|
-
function
|
|
1423
|
+
function Nr(e) {
|
|
1422
1424
|
if (!e.config)
|
|
1423
1425
|
throw new Error("Config is required for read");
|
|
1424
|
-
const
|
|
1426
|
+
const t = e.config, r = e.key.split(".").flatMap((s) => {
|
|
1425
1427
|
const i = s.match(/^(.+)\[(\d+)\]$/);
|
|
1426
1428
|
return i ? [i[1], parseInt(i[2])] : [s];
|
|
1427
1429
|
});
|
|
1428
|
-
let n =
|
|
1429
|
-
for (let s = 0; s <
|
|
1430
|
-
const i =
|
|
1430
|
+
let n = t;
|
|
1431
|
+
for (let s = 0; s < r.length; s++) {
|
|
1432
|
+
const i = r[s], o = r[s + 1];
|
|
1431
1433
|
if (typeof i == "number") {
|
|
1432
1434
|
if (!Array.isArray(n))
|
|
1433
1435
|
throw new Error("Property is not an array");
|
|
@@ -1449,13 +1451,13 @@ function Nt(e) {
|
|
|
1449
1451
|
}
|
|
1450
1452
|
return n;
|
|
1451
1453
|
}
|
|
1452
|
-
function
|
|
1454
|
+
function Ir(e) {
|
|
1453
1455
|
if (!e.config)
|
|
1454
1456
|
throw new Error("Config is required for delete");
|
|
1455
|
-
const
|
|
1456
|
-
let n =
|
|
1457
|
-
for (let o = 0; o <
|
|
1458
|
-
const a =
|
|
1457
|
+
const t = { ...e.config }, r = e.key.split(".");
|
|
1458
|
+
let n = t;
|
|
1459
|
+
for (let o = 0; o < r.length - 1; o++) {
|
|
1460
|
+
const a = r[o], c = a.match(/^(.+)\[(\d+)\]$/);
|
|
1459
1461
|
if (c) {
|
|
1460
1462
|
const l = c[1], f = parseInt(c[2]);
|
|
1461
1463
|
if (!n[l])
|
|
@@ -1471,7 +1473,7 @@ function It(e) {
|
|
|
1471
1473
|
n = n[a];
|
|
1472
1474
|
}
|
|
1473
1475
|
}
|
|
1474
|
-
const s =
|
|
1476
|
+
const s = r[r.length - 1], i = s.match(/^(.+)\[(\d+)\]$/);
|
|
1475
1477
|
if (i) {
|
|
1476
1478
|
const o = i[1], a = parseInt(i[2]);
|
|
1477
1479
|
if (!n[o])
|
|
@@ -1486,19 +1488,19 @@ function It(e) {
|
|
|
1486
1488
|
throw new Error(`Property '${s}' does not exist`);
|
|
1487
1489
|
delete n[s];
|
|
1488
1490
|
}
|
|
1489
|
-
return
|
|
1491
|
+
return t;
|
|
1490
1492
|
}
|
|
1491
|
-
function
|
|
1492
|
-
const
|
|
1493
|
+
function Wr(e) {
|
|
1494
|
+
const t = e.match(
|
|
1493
1495
|
/^\s*export\s+default\s+defineConfig\s*\(\s*/m
|
|
1494
|
-
),
|
|
1496
|
+
), r = e.match(
|
|
1495
1497
|
/^\s*module\.exports\s*=\s*defineConfig\s*\(\s*/m
|
|
1496
1498
|
), n = e.match(/^\s*export\s+default\s+/m), s = e.match(/^\s*module\.exports\s*=\s*/m);
|
|
1497
1499
|
let i = -1;
|
|
1498
|
-
if (
|
|
1499
|
-
i = r.index + r[0].length;
|
|
1500
|
-
else if (t)
|
|
1500
|
+
if (t)
|
|
1501
1501
|
i = t.index + t[0].length;
|
|
1502
|
+
else if (r)
|
|
1503
|
+
i = r.index + r[0].length;
|
|
1502
1504
|
else if (n) {
|
|
1503
1505
|
const m = n.index + n[0].length;
|
|
1504
1506
|
let g = m;
|
|
@@ -1538,11 +1540,11 @@ function Wt(e) {
|
|
|
1538
1540
|
}
|
|
1539
1541
|
return { start: i, end: d };
|
|
1540
1542
|
}
|
|
1541
|
-
async function
|
|
1543
|
+
async function Dr(e, t) {
|
|
1542
1544
|
try {
|
|
1543
|
-
if (typeof e != "string" || typeof
|
|
1545
|
+
if (typeof e != "string" || typeof t != "string")
|
|
1544
1546
|
throw new Error("Placeholder and value must be strings");
|
|
1545
|
-
const { configPath:
|
|
1547
|
+
const { configPath: r, fileContent: n } = await xe.findAndReadConfigFile(), { start: s, end: i } = Wr(n), o = n.slice(0, s), a = n.slice(s, i), c = n.slice(i);
|
|
1546
1548
|
let l = a, f = 0;
|
|
1547
1549
|
for (; f < l.length; ) {
|
|
1548
1550
|
const m = l.indexOf(e, f);
|
|
@@ -1553,7 +1555,7 @@ async function Dt(e, r) {
|
|
|
1553
1555
|
const $ = g && g.match(/[A-Za-z0-9_$]/), E = y && y.match(/[A-Za-z0-9_]/);
|
|
1554
1556
|
($ || E) && (S = !1);
|
|
1555
1557
|
}
|
|
1556
|
-
S ? (l = l.slice(0, m) +
|
|
1558
|
+
S ? (l = l.slice(0, m) + t + l.slice(m + e.length), f = m + t.length) : f = m + 1;
|
|
1557
1559
|
}
|
|
1558
1560
|
const w = o + l + c;
|
|
1559
1561
|
let d;
|
|
@@ -1567,18 +1569,18 @@ async function Dt(e, r) {
|
|
|
1567
1569
|
} catch {
|
|
1568
1570
|
d = w;
|
|
1569
1571
|
}
|
|
1570
|
-
await u.writeFile(
|
|
1571
|
-
`Successfully replaced "${e}" with "${
|
|
1572
|
+
await u.writeFile(r, d, "utf8"), p.info(
|
|
1573
|
+
`Successfully replaced "${e}" with "${t}" in ${v.basename(r)}`
|
|
1572
1574
|
);
|
|
1573
|
-
} catch (
|
|
1575
|
+
} catch (r) {
|
|
1574
1576
|
throw new Error(
|
|
1575
|
-
`Failed to replace in config file: ${
|
|
1577
|
+
`Failed to replace in config file: ${r instanceof Error ? r.message : String(r)}`
|
|
1576
1578
|
);
|
|
1577
1579
|
}
|
|
1578
1580
|
}
|
|
1579
|
-
async function
|
|
1581
|
+
async function Br(e, t) {
|
|
1580
1582
|
try {
|
|
1581
|
-
const { configPath:
|
|
1583
|
+
const { configPath: r, fileContent: n } = await xe.findAndReadConfigFile(), s = Mr(n, e, t);
|
|
1582
1584
|
let i;
|
|
1583
1585
|
try {
|
|
1584
1586
|
i = await be.format(s, {
|
|
@@ -1590,20 +1592,20 @@ async function Bt(e, r) {
|
|
|
1590
1592
|
} catch {
|
|
1591
1593
|
i = s;
|
|
1592
1594
|
}
|
|
1593
|
-
await u.writeFile(
|
|
1594
|
-
`Successfully updated "${e}" to "${
|
|
1595
|
+
await u.writeFile(r, i, "utf8"), k.feedback.info(
|
|
1596
|
+
`Successfully updated "${e}" to "${t}" in ${v.basename(r)}`
|
|
1595
1597
|
);
|
|
1596
|
-
} catch (
|
|
1598
|
+
} catch (r) {
|
|
1597
1599
|
throw new Error(
|
|
1598
|
-
`Failed to update config file: ${
|
|
1600
|
+
`Failed to update config file: ${r instanceof Error ? r.message : String(r)}`
|
|
1599
1601
|
);
|
|
1600
1602
|
}
|
|
1601
1603
|
}
|
|
1602
|
-
function
|
|
1603
|
-
return
|
|
1604
|
+
function Mr(e, t, r) {
|
|
1605
|
+
return Lr(e, t, r);
|
|
1604
1606
|
}
|
|
1605
|
-
function
|
|
1606
|
-
const n =
|
|
1607
|
+
function Lr(e, t, r) {
|
|
1608
|
+
const n = Vr(r), s = e.replace(/\n\s*/g, " ").replace(/\s+/g, " "), i = s.match(
|
|
1607
1609
|
/(.*(?:module\.exports\s*=(?:\s+\w+\()?|export default(?:\s+\w+\()?)\s*)\{/
|
|
1608
1610
|
);
|
|
1609
1611
|
if (!i)
|
|
@@ -1619,7 +1621,7 @@ function Lt(e, r, t) {
|
|
|
1619
1621
|
}
|
|
1620
1622
|
if (a !== 0)
|
|
1621
1623
|
return e;
|
|
1622
|
-
const w = s.substring(o, c), d =
|
|
1624
|
+
const w = s.substring(o, c), d = Hr(t), m = ne(w, d, n), g = e.match(
|
|
1623
1625
|
/(.*(?:module\.exports\s*=(?:\s+\w+\()?|export default(?:\s+\w+\()?)\s*)\{/s
|
|
1624
1626
|
);
|
|
1625
1627
|
if (!g)
|
|
@@ -1636,33 +1638,33 @@ function Lt(e, r, t) {
|
|
|
1636
1638
|
const ke = "}" + e.substring(E + 1);
|
|
1637
1639
|
return y + m + ke;
|
|
1638
1640
|
}
|
|
1639
|
-
function
|
|
1640
|
-
const
|
|
1641
|
-
let
|
|
1641
|
+
function Hr(e) {
|
|
1642
|
+
const t = [];
|
|
1643
|
+
let r = "", n = 0;
|
|
1642
1644
|
for (; n < e.length; ) {
|
|
1643
1645
|
const s = e[n];
|
|
1644
1646
|
if (s === ".")
|
|
1645
|
-
|
|
1647
|
+
r && (t.push(r), r = "");
|
|
1646
1648
|
else if (s === "[") {
|
|
1647
|
-
|
|
1649
|
+
r && (t.push(r), r = ""), n++;
|
|
1648
1650
|
let i = "";
|
|
1649
1651
|
for (; n < e.length && e[n] !== "]"; )
|
|
1650
1652
|
i += e[n], n++;
|
|
1651
|
-
|
|
1653
|
+
t.push(parseInt(i));
|
|
1652
1654
|
} else
|
|
1653
|
-
|
|
1655
|
+
r += s;
|
|
1654
1656
|
n++;
|
|
1655
1657
|
}
|
|
1656
|
-
return
|
|
1658
|
+
return r && t.push(r), t;
|
|
1657
1659
|
}
|
|
1658
|
-
function ne(e,
|
|
1659
|
-
if (
|
|
1660
|
-
const [n, ...s] =
|
|
1660
|
+
function ne(e, t, r) {
|
|
1661
|
+
if (t.length === 0) return e;
|
|
1662
|
+
const [n, ...s] = t;
|
|
1661
1663
|
if (typeof n == "string") {
|
|
1662
1664
|
const i = n.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
1663
1665
|
if (s.length === 0) {
|
|
1664
1666
|
const o = new RegExp(`(${i}\\s*:\\s*)([^,}]+)`);
|
|
1665
|
-
return e.replace(o, `$1${
|
|
1667
|
+
return e.replace(o, `$1${r}`);
|
|
1666
1668
|
} else {
|
|
1667
1669
|
const o = e.match(
|
|
1668
1670
|
new RegExp(`(.*${i}\\s*:\\s*)([^,}]+)(.*)`)
|
|
@@ -1689,7 +1691,7 @@ function ne(e, r, t) {
|
|
|
1689
1691
|
}
|
|
1690
1692
|
if (d === -1)
|
|
1691
1693
|
return e;
|
|
1692
|
-
const g = e.substring(c, d + 1).slice(1, -1), y = ne(g, s,
|
|
1694
|
+
const g = e.substring(c, d + 1).slice(1, -1), y = ne(g, s, r), S = e.substring(0, c), $ = e.substring(d + 1);
|
|
1693
1695
|
return S + `{ ${y} }` + $;
|
|
1694
1696
|
} else if (a.trim().startsWith("[")) {
|
|
1695
1697
|
const c = e.indexOf(a.trim());
|
|
@@ -1711,18 +1713,18 @@ function ne(e, r, t) {
|
|
|
1711
1713
|
}
|
|
1712
1714
|
if (d === -1)
|
|
1713
1715
|
return e;
|
|
1714
|
-
const g = e.substring(c, d + 1).slice(1, -1), y = he(g, s,
|
|
1716
|
+
const g = e.substring(c, d + 1).slice(1, -1), y = he(g, s, r), S = e.substring(0, c), $ = e.substring(d + 1);
|
|
1715
1717
|
return S + `[ ${y} ]` + $;
|
|
1716
1718
|
}
|
|
1717
1719
|
}
|
|
1718
1720
|
}
|
|
1719
1721
|
} else if (typeof n == "number")
|
|
1720
|
-
return he(e,
|
|
1722
|
+
return he(e, t, r);
|
|
1721
1723
|
return e;
|
|
1722
1724
|
}
|
|
1723
|
-
function he(e,
|
|
1724
|
-
if (
|
|
1725
|
-
const [n, ...s] =
|
|
1725
|
+
function he(e, t, r) {
|
|
1726
|
+
if (t.length === 0) return e;
|
|
1727
|
+
const [n, ...s] = t;
|
|
1726
1728
|
if (typeof n != "number") return e;
|
|
1727
1729
|
const i = [];
|
|
1728
1730
|
let o = 0;
|
|
@@ -1774,74 +1776,74 @@ function he(e, r, t) {
|
|
|
1774
1776
|
}
|
|
1775
1777
|
if (n < i.length)
|
|
1776
1778
|
if (s.length === 0)
|
|
1777
|
-
i[n] =
|
|
1779
|
+
i[n] = r;
|
|
1778
1780
|
else {
|
|
1779
1781
|
const a = i[n];
|
|
1780
1782
|
if (a.startsWith("{") && a.endsWith("}")) {
|
|
1781
|
-
const c = a.slice(1, -1), l = ne(c, s,
|
|
1783
|
+
const c = a.slice(1, -1), l = ne(c, s, r);
|
|
1782
1784
|
i[n] = `{ ${l} }`;
|
|
1783
1785
|
}
|
|
1784
1786
|
}
|
|
1785
1787
|
return i.join(", ");
|
|
1786
1788
|
}
|
|
1787
|
-
function
|
|
1789
|
+
function Vr(e) {
|
|
1788
1790
|
if (typeof e == "string") {
|
|
1789
1791
|
if (e.startsWith('"') && e.endsWith('"') || e.startsWith("'") && e.endsWith("'"))
|
|
1790
1792
|
return e;
|
|
1791
|
-
const
|
|
1792
|
-
return
|
|
1793
|
+
const t = e.trim();
|
|
1794
|
+
return t.startsWith("{") && t.endsWith("}") || t.startsWith("[") && t.endsWith("]") || e.includes("=>") || e.trim().startsWith("function") ? e : `'${e}'`;
|
|
1793
1795
|
}
|
|
1794
1796
|
return String(e);
|
|
1795
1797
|
}
|
|
1796
|
-
async function gn({ command: e, options:
|
|
1798
|
+
async function gn({ command: e, options: t }) {
|
|
1797
1799
|
try {
|
|
1798
|
-
const
|
|
1799
|
-
if (
|
|
1800
|
+
const r = await Z();
|
|
1801
|
+
if (t.all) {
|
|
1800
1802
|
let l;
|
|
1801
1803
|
switch (e) {
|
|
1802
1804
|
case "read":
|
|
1803
|
-
return l =
|
|
1805
|
+
return l = r || {}, console.log(JSON.stringify(l, null, 2)), l;
|
|
1804
1806
|
case "delete":
|
|
1805
1807
|
return await K({}), {};
|
|
1806
1808
|
default:
|
|
1807
1809
|
throw new Error("--all flag is only supported for read and delete commands");
|
|
1808
1810
|
}
|
|
1809
1811
|
}
|
|
1810
|
-
const n = Array.isArray(
|
|
1812
|
+
const n = Array.isArray(t.key) ? t.key : t.key ? [t.key] : [], s = Array.isArray(t.value) ? t.value : t.value !== void 0 ? [t.value] : [];
|
|
1811
1813
|
if (n.length === 0 && e !== "replace")
|
|
1812
1814
|
throw new Error("Key is required when --all is not used");
|
|
1813
1815
|
const i = n[0], o = s[0];
|
|
1814
1816
|
let a, c;
|
|
1815
1817
|
switch (e) {
|
|
1816
1818
|
case "create":
|
|
1817
|
-
if (
|
|
1819
|
+
if (r)
|
|
1818
1820
|
throw new Error("Configuration already exists. Use update command instead.");
|
|
1819
1821
|
if (o === void 0)
|
|
1820
1822
|
throw new Error("Value is required for create command");
|
|
1821
|
-
a =
|
|
1823
|
+
a = Ur({
|
|
1822
1824
|
key: i,
|
|
1823
1825
|
value: o
|
|
1824
1826
|
});
|
|
1825
1827
|
break;
|
|
1826
1828
|
case "update":
|
|
1827
|
-
if (!
|
|
1829
|
+
if (!r)
|
|
1828
1830
|
throw new Error("No configuration found. Use create command first.");
|
|
1829
1831
|
if (o === void 0)
|
|
1830
1832
|
throw new Error("Value is required for update command");
|
|
1831
|
-
return await
|
|
1833
|
+
return await Br(i, o), {};
|
|
1832
1834
|
case "read":
|
|
1833
|
-
if (!
|
|
1835
|
+
if (!r)
|
|
1834
1836
|
throw new Error("No configuration found");
|
|
1835
|
-
return c =
|
|
1837
|
+
return c = Nr({
|
|
1836
1838
|
key: i,
|
|
1837
|
-
config:
|
|
1839
|
+
config: r
|
|
1838
1840
|
}), c;
|
|
1839
1841
|
case "delete":
|
|
1840
|
-
if (!
|
|
1842
|
+
if (!r)
|
|
1841
1843
|
throw new Error("No configuration found");
|
|
1842
|
-
a =
|
|
1844
|
+
a = Ir({
|
|
1843
1845
|
key: i,
|
|
1844
|
-
config:
|
|
1846
|
+
config: r
|
|
1845
1847
|
});
|
|
1846
1848
|
break;
|
|
1847
1849
|
case "replace":
|
|
@@ -1849,17 +1851,17 @@ async function gn({ command: e, options: r }) {
|
|
|
1849
1851
|
throw new Error("Placeholder is required for replace command (use -k or --key)");
|
|
1850
1852
|
if (o === void 0)
|
|
1851
1853
|
throw new Error("Value is required for replace command");
|
|
1852
|
-
return await
|
|
1854
|
+
return await Dr(i, o), {};
|
|
1853
1855
|
default:
|
|
1854
1856
|
throw new Error(`Unknown command: ${e}`);
|
|
1855
1857
|
}
|
|
1856
1858
|
return await K(a), a;
|
|
1857
|
-
} catch (
|
|
1858
|
-
h.error(
|
|
1859
|
+
} catch (r) {
|
|
1860
|
+
h.error(r), p.error(`${r instanceof Error ? r.message : String(r)}`), process.exit(1);
|
|
1859
1861
|
}
|
|
1860
1862
|
}
|
|
1861
1863
|
export {
|
|
1862
|
-
|
|
1864
|
+
wr as buildCommand,
|
|
1863
1865
|
gn as configCommand,
|
|
1864
1866
|
un as devCommand,
|
|
1865
1867
|
pn as manifestCommand,
|