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