@aziontech/bundler 1.1.2 → 1.1.4

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