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