@aziontech/bundler 1.1.4 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/index-Dx9B4Utx.js +2290 -0
- package/dist/index.js +93 -58
- package/dist/utils-CSEkDVys.js +399 -0
- package/package.json +9 -9
- package/dist/index-CgialJ1S.js +0 -2165
- package/dist/utils-B43tliMf.js +0 -377
package/dist/utils-B43tliMf.js
DELETED
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
import w, { readFileSync as I, unlinkSync as x } from "fs";
|
|
2
|
-
import m, { writeFile as R } from "fs/promises";
|
|
3
|
-
import { getAbsoluteDirPath as V, feedback as E } from "@aziontech/utils/node";
|
|
4
|
-
import { tmpdir as k } from "os";
|
|
5
|
-
import f, { join as u, resolve as B } from "path";
|
|
6
|
-
import "@aziontech/builder/polyfills";
|
|
7
|
-
import "@edge-runtime/primitives/dist/load.js";
|
|
8
|
-
import "chokidar";
|
|
9
|
-
import "@aziontech/bundler-telemetry";
|
|
10
|
-
import { convertJsonConfigToObject as M } from "@aziontech/config";
|
|
11
|
-
import "@aziontech/builder";
|
|
12
|
-
import "lodash";
|
|
13
|
-
import "@aziontech/presets";
|
|
14
|
-
import "@netlify/framework-info";
|
|
15
|
-
import "edge-runtime";
|
|
16
|
-
import j from "prettier";
|
|
17
|
-
import { cosmiconfig as H } from "cosmiconfig";
|
|
18
|
-
import { TypeScriptLoader as S } from "cosmiconfig-typescript-loader";
|
|
19
|
-
const $ = {
|
|
20
|
-
OUTPUT_BASE_PATH: ".edge",
|
|
21
|
-
OUTPUT_FUNCTIONS_PATH: u(".edge", "functions"),
|
|
22
|
-
OUTPUT_STORAGE_PATH: u(".edge", "storage"),
|
|
23
|
-
OUTPUT_MANIFEST_PATH: u(".edge", "manifest.json"),
|
|
24
|
-
OUTPUT_ENV_VARS_PATH: u(".edge", ".env"),
|
|
25
|
-
/**
|
|
26
|
-
* Temporary workaround for Azion's global environment variables
|
|
27
|
-
*/
|
|
28
|
-
OUTPUT_ENV_VARS_LOCAL_PATH: u(".edge", ".env.azion"),
|
|
29
|
-
OUTPUT_STORAGE_METADATA_PATH: u(".edge", "storage", "metadata.json"),
|
|
30
|
-
OUTPUT_KV_PATH: u(".edge", "kv")
|
|
31
|
-
}, _e = {
|
|
32
|
-
POLYFILLS: !0,
|
|
33
|
-
WORKER: !1,
|
|
34
|
-
PRODUCTION: !0,
|
|
35
|
-
EXTENSION: "js",
|
|
36
|
-
PRESET: void 0,
|
|
37
|
-
ENTRY: void 0,
|
|
38
|
-
BUNDLER: void 0
|
|
39
|
-
}, Te = {
|
|
40
|
-
DEFAULT: "esbuild"
|
|
41
|
-
}, U = {
|
|
42
|
-
NAMESPACE: "bundler",
|
|
43
|
-
EXPERIMENTAL: !1,
|
|
44
|
-
MIN_NODE_VERSION: "18.0.0",
|
|
45
|
-
CONFIG_FILENAME: "azion.config",
|
|
46
|
-
DEFAULT_HANDLER_FILENAME: "handler",
|
|
47
|
-
DEFAULT_DEV_WORKER_FILENAME: "handler.dev",
|
|
48
|
-
DEFAULT_OUTPUT_EXTENSION: "js",
|
|
49
|
-
LIB_DIR: V(import.meta.url, "bundler"),
|
|
50
|
-
ARGS_PATH: "@aziontech/args.json",
|
|
51
|
-
IS_DEBUG: process.env.DEBUG === "true",
|
|
52
|
-
TEMP_DIR: (n) => u(k(), ".azion", n),
|
|
53
|
-
get ROOT_PATH() {
|
|
54
|
-
return B(U.LIB_DIR, ".");
|
|
55
|
-
},
|
|
56
|
-
get PACKAGE_JSON() {
|
|
57
|
-
return JSON.parse(I(`${U.ROOT_PATH}/package.json`, "utf8"));
|
|
58
|
-
},
|
|
59
|
-
get VERSION() {
|
|
60
|
-
return U.PACKAGE_JSON.version;
|
|
61
|
-
}
|
|
62
|
-
}, g = `
|
|
63
|
-
|
|
64
|
-
📚 Need help? Check out our documentation:
|
|
65
|
-
- Azion CLI Documentation: https://www.azion.com/en/documentation/devtools/cli/build/
|
|
66
|
-
- Azion Library on Github: https://github.com/aziontech/lib/tree/main/packages/config/
|
|
67
|
-
- Azion Bundler on GitHub: https://github.com/aziontech/bundler
|
|
68
|
-
`, P = {
|
|
69
|
-
ENV_PREFIX_VAR: "AZ_BUNDLER_ENV_ALIAS_PREFIX",
|
|
70
|
-
ENABLE_VAR: "AZ_BUNDLER_ENV_ALIAS_ENABLED"
|
|
71
|
-
}, Ae = {
|
|
72
|
-
ENV_ENABLED: "AZ_BUNDLER_TELEMETRY",
|
|
73
|
-
ENV_FORMAT: "AZ_BUNDLER_TELEMETRY_FORMAT",
|
|
74
|
-
ENV_OUTPUT: "AZ_BUNDLER_TELEMETRY_OUTPUT",
|
|
75
|
-
DEFAULT_FORMAT: "both",
|
|
76
|
-
DEFAULT_OUTPUT_PATH: ".edge/telemetry-report.json",
|
|
77
|
-
DEFAULT_HTML_OUTPUT_PATH: ".edge/telemetry-report.html"
|
|
78
|
-
}, J = (n) => n.split(`
|
|
79
|
-
`).map((e) => e.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/)).filter((e) => !!e).map((e) => ({ key: e[1], value: e[2] })), he = (n) => {
|
|
80
|
-
const e = n.trim().replace(/\r$/, "");
|
|
81
|
-
return e.length >= 2 && (e.startsWith('"') && e.endsWith('"') || e.startsWith("'") && e.endsWith("'")) ? e.slice(1, -1) : e;
|
|
82
|
-
}, G = (n) => n ? [".env.production.local", ".env.local", ".env.production", ".env"] : [".env.development.local", ".env.local", ".env.development", ".env"];
|
|
83
|
-
async function L(n, e) {
|
|
84
|
-
const t = /* @__PURE__ */ new Map();
|
|
85
|
-
for (const r of [...G(e)].reverse()) {
|
|
86
|
-
const i = u(n, r);
|
|
87
|
-
if (!await m.access(i, w.constants.F_OK).then(() => !0).catch(() => !1)) continue;
|
|
88
|
-
const c = await m.readFile(i, "utf-8");
|
|
89
|
-
J(c).forEach(({ key: T, value: A }) => t.set(T, A));
|
|
90
|
-
}
|
|
91
|
-
return Array.from(t, ([r, i]) => ({ key: r, value: i }));
|
|
92
|
-
}
|
|
93
|
-
const Z = (n) => {
|
|
94
|
-
const e = n.toUpperCase().replace(/[^A-Z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
95
|
-
return e ? `${e}_` : "";
|
|
96
|
-
}, Y = (n) => process.env[P.ENABLE_VAR] !== "true" ? "" : process.env[P.ENV_PREFIX_VAR] || Z(n || "");
|
|
97
|
-
async function O(n, e = "global") {
|
|
98
|
-
let t;
|
|
99
|
-
switch (e) {
|
|
100
|
-
case "global":
|
|
101
|
-
t = globalThis.bundler.tempPath;
|
|
102
|
-
break;
|
|
103
|
-
case "local":
|
|
104
|
-
t = f.join(process.cwd());
|
|
105
|
-
break;
|
|
106
|
-
default:
|
|
107
|
-
t = e;
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
const r = f.join(t, ".azion-bundler.json");
|
|
111
|
-
try {
|
|
112
|
-
await m.mkdir(t, { recursive: !0 });
|
|
113
|
-
} catch (i) {
|
|
114
|
-
throw a.error(i), E.build.error(
|
|
115
|
-
`An error occurred while creating the ${r} folder.${g}`
|
|
116
|
-
), i;
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
await m.writeFile(r, JSON.stringify(n, null, 2));
|
|
120
|
-
} catch (i) {
|
|
121
|
-
throw a.error(i), E.build.error(
|
|
122
|
-
`An error occurred while writing the ${r} file.${g}`
|
|
123
|
-
), i;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async function N(n = "global") {
|
|
127
|
-
let e;
|
|
128
|
-
switch (n) {
|
|
129
|
-
case "global":
|
|
130
|
-
e = globalThis.bundler.tempPath;
|
|
131
|
-
break;
|
|
132
|
-
case "local":
|
|
133
|
-
e = f.join(process.cwd());
|
|
134
|
-
break;
|
|
135
|
-
default:
|
|
136
|
-
e = n;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
if (!e) return {};
|
|
140
|
-
const t = f.join(e, ".azion-bundler.json");
|
|
141
|
-
try {
|
|
142
|
-
await m.access(t);
|
|
143
|
-
const r = await m.readFile(t, "utf8");
|
|
144
|
-
return JSON.parse(r);
|
|
145
|
-
} catch {
|
|
146
|
-
return {};
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function K(n, e) {
|
|
150
|
-
if (n.message.includes("ERR_MODULE_NOT_FOUND")) {
|
|
151
|
-
const t = n.message.match(/'([^']+)'/)?.[1];
|
|
152
|
-
t ? E.build.error(
|
|
153
|
-
`Missing dependency: ${t}. Please install it using 'npm install ${t}' or 'yarn add ${t}'.${g}`
|
|
154
|
-
) : E.build.error(
|
|
155
|
-
`A required dependency is missing. Please ensure all dependencies are installed.${g}`
|
|
156
|
-
), a.error(`Failed to load configuration from ${e}. ${n.message}`);
|
|
157
|
-
} else
|
|
158
|
-
throw n;
|
|
159
|
-
}
|
|
160
|
-
async function W(n) {
|
|
161
|
-
const e = H("azion", {
|
|
162
|
-
searchPlaces: [
|
|
163
|
-
"azion.config.ts",
|
|
164
|
-
"azion.config.mts",
|
|
165
|
-
"azion.config.cts",
|
|
166
|
-
"azion.config.js",
|
|
167
|
-
"azion.config.mjs",
|
|
168
|
-
"azion.config.cjs",
|
|
169
|
-
"azion.config.json"
|
|
170
|
-
],
|
|
171
|
-
loaders: {
|
|
172
|
-
".ts": S(),
|
|
173
|
-
".mts": S(),
|
|
174
|
-
".cts": S()
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
try {
|
|
178
|
-
const t = n ? await e.load(n) : await e.search();
|
|
179
|
-
if (!t) return null;
|
|
180
|
-
const r = t.config, i = t.filepath;
|
|
181
|
-
return f.extname(i) === ".json" ? M(JSON.stringify(r)) : r;
|
|
182
|
-
} catch (t) {
|
|
183
|
-
if (t.message.includes("ERR_MODULE_NOT_FOUND"))
|
|
184
|
-
return K(t, n || "azion.config"), null;
|
|
185
|
-
if (t.message.includes("TypeScriptLoader failed to compile")) {
|
|
186
|
-
const r = t.message.split(`TypeScriptLoader failed to compile TypeScript:
|
|
187
|
-
`)[1]?.trim();
|
|
188
|
-
E.build.error(`${r || t.message}${g}`), process.exit(1);
|
|
189
|
-
}
|
|
190
|
-
t.message.includes("ERR_REQUIRE_CYCLE_MODULE") && (E.build.error(
|
|
191
|
-
`Circular dependency detected while loading configuration file. This usually happens when using ES modules. Please ensure your configuration file doesn't have circular imports.${g}`
|
|
192
|
-
), process.exit(1)), a.error(t), E.build.error(
|
|
193
|
-
`Failed to load configuration file. For detailed debugging information, run with DEBUG=true environment variable.${g}`
|
|
194
|
-
), process.exit(1);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function X() {
|
|
198
|
-
const n = f.join(process.cwd(), "package.json");
|
|
199
|
-
return w.existsSync(n) ? JSON.parse(w.readFileSync(n, "utf8")).type !== "module" : !0;
|
|
200
|
-
}
|
|
201
|
-
async function Q(n, e) {
|
|
202
|
-
const r = X() ? ".cjs" : ".mjs", i = n.build?.preset === "typescript";
|
|
203
|
-
let s = i ? ".ts" : r, c;
|
|
204
|
-
if (e) {
|
|
205
|
-
const o = f.parse(e);
|
|
206
|
-
if ([".js", ".mjs", ".cjs", ".ts"].includes(o.ext))
|
|
207
|
-
c = f.resolve(e), s = o.ext;
|
|
208
|
-
else {
|
|
209
|
-
const l = f.resolve(e);
|
|
210
|
-
try {
|
|
211
|
-
(await m.stat(l)).isFile() ? c = `${l}${s}` : c = f.join(l, `azion.config${s}`);
|
|
212
|
-
} catch {
|
|
213
|
-
e.includes("/") || e.includes("\\") ? c = f.join(l, `azion.config${s}`) : c = `${l}${s}`;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
} else
|
|
217
|
-
c = f.join(process.cwd(), `azion.config${s}`);
|
|
218
|
-
const T = i ? "export default" : s === ".cjs" ? "module.exports =" : "export default", A = `/**
|
|
219
|
-
* This file was automatically generated based on your preset configuration.
|
|
220
|
-
*
|
|
221
|
-
* For better type checking and IntelliSense:
|
|
222
|
-
* 1. Install azion config as dev dependency:
|
|
223
|
-
* npm install -D @aziontech/config
|
|
224
|
-
*
|
|
225
|
-
* 2. Use defineConfig:
|
|
226
|
-
* import { defineConfig } from '@aziontech/config'
|
|
227
|
-
*
|
|
228
|
-
* 3. Replace the configuration with defineConfig:
|
|
229
|
-
* export default defineConfig({
|
|
230
|
-
* // Your configuration here
|
|
231
|
-
* })
|
|
232
|
-
*
|
|
233
|
-
* For more configuration options, visit:
|
|
234
|
-
* https://github.com/aziontech/lib/tree/main/packages/config
|
|
235
|
-
*/
|
|
236
|
-
|
|
237
|
-
`;
|
|
238
|
-
function v(o) {
|
|
239
|
-
if (o == null)
|
|
240
|
-
return o;
|
|
241
|
-
if (Array.isArray(o))
|
|
242
|
-
return o.map(v).filter((d) => d !== void 0);
|
|
243
|
-
if (typeof o == "object") {
|
|
244
|
-
const d = {};
|
|
245
|
-
for (const [p, l] of Object.entries(o))
|
|
246
|
-
if (l !== void 0) {
|
|
247
|
-
const _ = v(l);
|
|
248
|
-
_ !== void 0 && (d[p] = _);
|
|
249
|
-
}
|
|
250
|
-
return d;
|
|
251
|
-
}
|
|
252
|
-
return o;
|
|
253
|
-
}
|
|
254
|
-
function y(o, d = 0) {
|
|
255
|
-
const p = " ".repeat(d);
|
|
256
|
-
if (typeof o == "function")
|
|
257
|
-
return o.toString();
|
|
258
|
-
if (typeof o == "string")
|
|
259
|
-
return `'${o.replaceAll("'", "\\'")}'`;
|
|
260
|
-
if (typeof o == "number" || typeof o == "boolean" || o == null)
|
|
261
|
-
return String(o);
|
|
262
|
-
if (Array.isArray(o)) {
|
|
263
|
-
if (o.length === 0) return "[]";
|
|
264
|
-
const l = o.map((_) => y(_, d + 1));
|
|
265
|
-
return `[
|
|
266
|
-
${p} ${l.join(`,
|
|
267
|
-
${p} `)}
|
|
268
|
-
${p}]`;
|
|
269
|
-
}
|
|
270
|
-
if (typeof o == "object") {
|
|
271
|
-
const l = Object.entries(o).filter(([, h]) => h !== void 0);
|
|
272
|
-
return l.length === 0 ? "{}" : `{
|
|
273
|
-
${l.map(([h, C]) => {
|
|
274
|
-
const z = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h) ? h : `'${h}'`;
|
|
275
|
-
return `${p} ${z}: ${y(C, d + 1)}`;
|
|
276
|
-
}).join(`,
|
|
277
|
-
`)}
|
|
278
|
-
${p}}`;
|
|
279
|
-
}
|
|
280
|
-
return String(o);
|
|
281
|
-
}
|
|
282
|
-
const F = v(n), b = y(F), D = await j.format(
|
|
283
|
-
A + `${T} ${b};`,
|
|
284
|
-
{
|
|
285
|
-
parser: "babel",
|
|
286
|
-
semi: !1,
|
|
287
|
-
singleQuote: !0,
|
|
288
|
-
trailingComma: "none"
|
|
289
|
-
}
|
|
290
|
-
);
|
|
291
|
-
await m.writeFile(c, D);
|
|
292
|
-
}
|
|
293
|
-
const ve = {
|
|
294
|
-
writeStore: O,
|
|
295
|
-
readStore: N,
|
|
296
|
-
readAzionConfig: W,
|
|
297
|
-
writeUserConfig: Q
|
|
298
|
-
};
|
|
299
|
-
async function ye(n) {
|
|
300
|
-
try {
|
|
301
|
-
const e = await N("global"), t = e.tempFiles || [];
|
|
302
|
-
t.includes(n) || (t.push(n), await O({ ...e, tempFiles: t }, "global"));
|
|
303
|
-
} catch {
|
|
304
|
-
a.warn("Failed to register temp file:", n);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
async function Se() {
|
|
308
|
-
try {
|
|
309
|
-
const n = await N("global"), e = n.tempFiles || [], t = [];
|
|
310
|
-
e.forEach((r) => {
|
|
311
|
-
try {
|
|
312
|
-
x(r), a.info("Successfully removed temp file:", r);
|
|
313
|
-
} catch {
|
|
314
|
-
a.warn("Failed to remove temp file:", r), t.push(r);
|
|
315
|
-
}
|
|
316
|
-
}), await O({ ...n, tempFiles: t }, "global"), t.length > 0 && a.warn(`${t.length} temp files could not be removed and will be retried later`);
|
|
317
|
-
} catch (n) {
|
|
318
|
-
a.warn("Failed to clean temp files from store:", n);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
const a = {};
|
|
322
|
-
Object.keys(console).forEach((n) => {
|
|
323
|
-
typeof console[n] == "function" && (a[n] = (...e) => {
|
|
324
|
-
process.env.DEBUG === "true" && console[n](...e);
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
async function Ue(n = !0) {
|
|
328
|
-
const e = process.cwd(), t = $.OUTPUT_ENV_VARS_PATH;
|
|
329
|
-
try {
|
|
330
|
-
const r = await L(e, n);
|
|
331
|
-
if (r.length === 0) return;
|
|
332
|
-
const i = r.map(({ key: s, value: c }) => `${s}=${c}`).join(`
|
|
333
|
-
`);
|
|
334
|
-
await R(t, `${i}
|
|
335
|
-
`, "utf-8"), a.info(`Environment file copied to ${t}`);
|
|
336
|
-
} catch {
|
|
337
|
-
a.warn("No .env file found or error copying environment file");
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
async function we(n, e = !0) {
|
|
341
|
-
const t = Y(n);
|
|
342
|
-
if (!t) return;
|
|
343
|
-
const r = process.cwd(), i = $.OUTPUT_ENV_VARS_LOCAL_PATH;
|
|
344
|
-
try {
|
|
345
|
-
const s = await L(r, e);
|
|
346
|
-
if (s.length === 0) return;
|
|
347
|
-
const c = s.map(({ key: T, value: A }) => `${t}${T}=${A}`).join(`
|
|
348
|
-
`);
|
|
349
|
-
await R(i, `${c}
|
|
350
|
-
`, "utf-8"), a.info(`Prefixed environment file written to ${i}`);
|
|
351
|
-
} catch {
|
|
352
|
-
a.warn("No .env file found or error writing prefixed environment file");
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
export {
|
|
356
|
-
U as B,
|
|
357
|
-
$ as D,
|
|
358
|
-
P as E,
|
|
359
|
-
Te as S,
|
|
360
|
-
Ae as T,
|
|
361
|
-
L as a,
|
|
362
|
-
_e as b,
|
|
363
|
-
Ue as c,
|
|
364
|
-
a as d,
|
|
365
|
-
Se as e,
|
|
366
|
-
g as f,
|
|
367
|
-
W as g,
|
|
368
|
-
Q as h,
|
|
369
|
-
O as i,
|
|
370
|
-
N as j,
|
|
371
|
-
ve as k,
|
|
372
|
-
ye as m,
|
|
373
|
-
J as p,
|
|
374
|
-
Y as r,
|
|
375
|
-
he as u,
|
|
376
|
-
we as w
|
|
377
|
-
};
|