@aziontech/bundler 1.3.1 → 1.3.2

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.js CHANGED
@@ -1,34 +1,34 @@
1
1
  #! /usr/bin/env node
2
- import { Command as g } from "commander";
3
- import { satisfies as b } from "semver";
4
- import { B as i, d as h, E as v, e as a } from "./utils-CSEkDVys.js";
5
- import { feedback as l } from "@aziontech/utils/node";
6
- import { createHash as y } from "crypto";
7
- import { mkdir as z } from "fs/promises";
8
- const t = new g();
9
- function w() {
2
+ import { Command as b } from "commander";
3
+ import { satisfies as h } from "semver";
4
+ import { B as i, d as v, S as l, E as y, e as a } from "./utils-DRPMQ0Y1.js";
5
+ import { feedback as p } from "@aziontech/utils/node";
6
+ import { createHash as z } from "crypto";
7
+ import { mkdir as x } from "fs/promises";
8
+ const t = new b();
9
+ function E() {
10
10
  const e = process.cwd();
11
- return y("md5").update(e).digest("hex");
11
+ return z("md5").update(e).digest("hex");
12
12
  }
13
- async function x() {
14
- const e = w(), o = i.TEMP_DIR(e);
15
- return await z(o, { recursive: !0 }), o;
13
+ async function w() {
14
+ const e = E(), o = i.TEMP_DIR(e);
15
+ return await x(o, { recursive: !0 }), o;
16
16
  }
17
- function p() {
18
- return b(process.version, `>= ${i.MIN_NODE_VERSION}`);
17
+ function f() {
18
+ return h(process.version, `>= ${i.MIN_NODE_VERSION}`);
19
19
  }
20
- async function E() {
20
+ async function A() {
21
21
  return {
22
22
  root: i.ROOT_PATH,
23
23
  package: i.PACKAGE_JSON,
24
24
  debug: i.IS_DEBUG,
25
25
  version: i.VERSION,
26
- tempPath: await x(),
26
+ tempPath: await w(),
27
27
  argsPath: i.ARGS_PATH,
28
28
  experimental: i.EXPERIMENTAL
29
29
  };
30
30
  }
31
- function k() {
31
+ function j() {
32
32
  process.on("exit", a), process.on("SIGINT", () => {
33
33
  a(), process.exit(0);
34
34
  }), process.on("SIGTERM", () => {
@@ -43,9 +43,9 @@ function k() {
43
43
  console.error("Unhandled Promise Rejection:", e), a(), process.exit(1);
44
44
  });
45
45
  }
46
- function A() {
46
+ function P() {
47
47
  t.version(globalThis.bundler.version), t.command("store <command>").description("Manage store configuration").option("-c, --config <json>", `Configuration in JSON format (e.g., '{"key": "value"}')`).option("-s, --scope <scope>", "Scope of the store (default: global)").action(async (e, o) => {
48
- const { storeCommand: n } = await import("./index-B3LSRKMb.js");
48
+ const { storeCommand: n } = await import("./index-MYaWgYMJ.js");
49
49
  await n({
50
50
  command: e,
51
51
  options: o
@@ -56,7 +56,7 @@ function A() {
56
56
  ).option(
57
57
  "-w, --worker [boolean]",
58
58
  "Indicates that the constructed code inserts its own worker expression. Use --worker or --worker=true to enable, --worker=false to disable"
59
- ).option("-d, --dev", "Build in development mode", !1).option("-x, --experimental [boolean]", "Enable experimental features", !1).option("--skip-framework-build", "Skip framework build step", !1).option(
59
+ ).option("-d, --dev", "Build in development mode", !1).option("-x, --experimental [boolean]", "Enable experimental features", !1).option("--skip-framework-build", l, !1).option(
60
60
  "--config-version <version>",
61
61
  'Config (Azion API) version of the project: 3, 4 or 6. Overrides the "version" field of azion.config (default: 4)'
62
62
  ).option(
@@ -83,25 +83,28 @@ Examples:
83
83
  $ azbundler build --telemetry json
84
84
  `
85
85
  ).action(async (e) => {
86
- const { buildCommand: o, manifestCommand: n } = await import("./index-B3LSRKMb.js"), { dev: r, experimental: c, telemetry: s, aliasEnv: f, ...d } = e;
86
+ const { buildCommand: o, manifestCommand: n } = await import("./index-MYaWgYMJ.js"), { dev: r, experimental: c, telemetry: s, aliasEnv: d, ...u } = e;
87
87
  if (c && (globalThis.bundler.experimental = !0), s !== void 0) {
88
- const m = typeof s == "string" ? s : "both";
89
- process.env.AZ_BUNDLER_TELEMETRY = "true", process.env.AZ_BUNDLER_TELEMETRY_FORMAT = m;
88
+ const g = typeof s == "string" ? s : "both";
89
+ process.env.AZ_BUNDLER_TELEMETRY = "true", process.env.AZ_BUNDLER_TELEMETRY_FORMAT = g;
90
90
  }
91
- f && (process.env[v.ENABLE_VAR] = "true");
92
- const { config: u } = await o({
93
- ...d,
91
+ d && (process.env[y.ENABLE_VAR] = "true");
92
+ const { config: m } = await o({
93
+ ...u,
94
94
  production: !r
95
95
  });
96
- await n({ action: "generate", config: u });
97
- }), t.command("dev").description("Start local development environment").argument("[entry]", "Specify the entry file (default: .edge/worker.dev.js)").option("-p, --port <port>", "Specify the port", "3333").option("-x, --experimental [boolean]", "Enable experimental features", !1).option("--skip-framework-build", "Skip framework build step", !1).option("--function-name <name>", "Specify the function name").option(
96
+ await n({ action: "generate", config: m });
97
+ }), t.command("dev").description("Start local development environment").argument("[entry]", "Specify the entry file (default: .edge/worker.dev.js)").option("-p, --port <port>", "Specify the port", "3333").option("-x, --experimental [boolean]", "Enable experimental features", !1).option("--skip-framework-build", l, !1).option("--function-name <name>", "Specify the function name").option(
98
98
  "--config-file <path>",
99
99
  "Path to the azion.config file to use (default: azion.config.* found in the current directory)"
100
100
  ).option(
101
101
  "--config-version <version>",
102
102
  'Config (Azion API) version of the project: 3, 4 or 6. Overrides the "version" field of azion.config (default: 4)'
103
+ ).option(
104
+ "--args-path <path>",
105
+ "Path to the args JSON file bound to ctx.args (event.args) of the function (default: azion/args.json)"
103
106
  ).action(async (e, o) => {
104
- const { devCommand: n } = await import("./index-B3LSRKMb.js"), { experimental: r } = o;
107
+ const { devCommand: n } = await import("./index-MYaWgYMJ.js"), { experimental: r } = o;
105
108
  r && (globalThis.bundler.experimental = !0), await n({ entry: e, ...o });
106
109
  }), t.command("presets <command>").description("Manage presets for Azion projects").argument("[preset]", "Preset name (required for config command)").option(
107
110
  "--config-version <version>",
@@ -110,7 +113,7 @@ Examples:
110
113
  "--config-file <path>",
111
114
  'Path to the azion.config file whose "version" is used when --config-version is not given'
112
115
  ).action(async (e, o, n) => {
113
- const { presetsCommand: r } = await import("./index-B3LSRKMb.js");
116
+ const { presetsCommand: r } = await import("./index-MYaWgYMJ.js");
114
117
  await r(e, {
115
118
  preset: o,
116
119
  configVersion: n?.configVersion,
@@ -135,7 +138,7 @@ Examples:
135
138
  $ azbundler manifest generate --config-file ./azion.config.ts
136
139
  `
137
140
  ).action(async (e, o, n) => {
138
- const { manifestCommand: r } = await import("./index-B3LSRKMb.js");
141
+ const { manifestCommand: r } = await import("./index-MYaWgYMJ.js");
139
142
  await r({
140
143
  ...o || n,
141
144
  action: e
@@ -157,7 +160,7 @@ Examples:
157
160
  $ azbundler config read -a --config-file ./azion.config.ts
158
161
  `
159
162
  ).action(async (e, o) => {
160
- const { configCommand: n } = await import("./index-B3LSRKMb.js");
163
+ const { configCommand: n } = await import("./index-MYaWgYMJ.js");
161
164
  await n({
162
165
  command: e,
163
166
  options: o
@@ -170,14 +173,14 @@ Examples:
170
173
  $ azbundler telemetry --path ./custom-report.html
171
174
  `
172
175
  ).action(async (e) => {
173
- const { telemetryCommand: o } = await import("./index-B3LSRKMb.js");
176
+ const { telemetryCommand: o } = await import("./index-MYaWgYMJ.js");
174
177
  await o(e);
175
178
  }), t.parse(process.argv);
176
179
  }
177
180
  try {
178
- p() && (globalThis.bundler = await E(), A(), k()), p() || (l.error(
181
+ f() && (globalThis.bundler = await A(), P(), j()), f() || (p.error(
179
182
  `Invalid Node version. Node version must be greater than ${i.MIN_NODE_VERSION}.`
180
183
  ), process.exit(1));
181
184
  } catch (e) {
182
- l.error("An unknown error occurred."), h.error(e), process.exit(1);
185
+ p.error("An unknown error occurred."), v.error(e), process.exit(1);
183
186
  }
@@ -1,4 +1,4 @@
1
- import w, { readFileSync as V, unlinkSync as x } from "fs";
1
+ import U, { readFileSync as V, unlinkSync as x } from "fs";
2
2
  import g, { writeFile as $ } from "fs/promises";
3
3
  import { getAbsoluteDirPath as k, feedback as m } from "@aziontech/utils/node";
4
4
  import { tmpdir as B } from "os";
@@ -14,8 +14,8 @@ import "@aziontech/presets";
14
14
  import "@netlify/framework-info";
15
15
  import "edge-runtime";
16
16
  import Z from "prettier";
17
- import { cosmiconfig as Y } from "cosmiconfig";
18
- import { TypeScriptLoader as y } from "cosmiconfig-typescript-loader";
17
+ import { cosmiconfig as K } from "cosmiconfig";
18
+ import { TypeScriptLoader as w } from "cosmiconfig-typescript-loader";
19
19
  const F = {
20
20
  OUTPUT_BASE_PATH: ".edge",
21
21
  OUTPUT_FUNCTIONS_PATH: u(".edge", "functions"),
@@ -36,9 +36,9 @@ const F = {
36
36
  PRESET: void 0,
37
37
  ENTRY: void 0,
38
38
  BUNDLER: void 0
39
- }, ye = {
39
+ }, we = {
40
40
  DEFAULT: "esbuild"
41
- }, U = {
41
+ }, y = {
42
42
  NAMESPACE: "bundler",
43
43
  EXPERIMENTAL: !1,
44
44
  MIN_NODE_VERSION: "18.0.0",
@@ -47,17 +47,18 @@ const F = {
47
47
  DEFAULT_DEV_WORKER_FILENAME: "handler.dev",
48
48
  DEFAULT_OUTPUT_EXTENSION: "js",
49
49
  LIB_DIR: k(import.meta.url, "bundler"),
50
- ARGS_PATH: "@aziontech/args.json",
50
+ // where the Azion CLI keeps the args it uploads with the function, relative to the project root
51
+ ARGS_PATH: "azion/args.json",
51
52
  IS_DEBUG: process.env.DEBUG === "true",
52
53
  TEMP_DIR: (e) => u(B(), ".azion", e),
53
54
  get ROOT_PATH() {
54
- return M(U.LIB_DIR, ".");
55
+ return M(y.LIB_DIR, ".");
55
56
  },
56
57
  get PACKAGE_JSON() {
57
- return JSON.parse(V(`${U.ROOT_PATH}/package.json`, "utf8"));
58
+ return JSON.parse(V(`${y.ROOT_PATH}/package.json`, "utf8"));
58
59
  },
59
60
  get VERSION() {
60
- return U.PACKAGE_JSON.version;
61
+ return y.PACKAGE_JSON.version;
61
62
  }
62
63
  }, E = `
63
64
 
@@ -65,18 +66,18 @@ const F = {
65
66
  - Azion CLI Documentation: https://www.azion.com/en/documentation/devtools/cli/build/
66
67
  - Azion Library on Github: https://github.com/aziontech/lib/tree/main/packages/config/
67
68
  - Azion Bundler on GitHub: https://github.com/aziontech/bundler
68
- `, R = {
69
+ `, P = {
69
70
  ENV_PREFIX_VAR: "AZ_BUNDLER_ENV_ALIAS_PREFIX",
70
71
  ENABLE_VAR: "AZ_BUNDLER_ENV_ALIAS_ENABLED"
71
- }, Ue = {
72
+ }, ye = {
72
73
  ENV_ENABLED: "AZ_BUNDLER_TELEMETRY",
73
74
  ENV_FORMAT: "AZ_BUNDLER_TELEMETRY_FORMAT",
74
75
  ENV_OUTPUT: "AZ_BUNDLER_TELEMETRY_OUTPUT",
75
76
  DEFAULT_FORMAT: "both",
76
77
  DEFAULT_OUTPUT_PATH: ".edge/telemetry-report.json",
77
78
  DEFAULT_HTML_OUTPUT_PATH: ".edge/telemetry-report.html"
78
- }, K = (e) => e.split(`
79
- `).map((n) => n.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/)).filter((n) => !!n).map((n) => ({ key: n[1], value: n[2] })), we = (e) => {
79
+ }, Ue = 'Do not run the framework build (e.g. "npm run build"); reuse the output of a previous one (e.g. dist). Run the framework build first: a warning is shown if its output is missing or empty', Y = (e) => e.split(`
80
+ `).map((n) => n.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/)).filter((n) => !!n).map((n) => ({ key: n[1], value: n[2] })), Oe = (e) => {
80
81
  const n = e.trim().replace(/\r$/, "");
81
82
  return n.length >= 2 && (n.startsWith('"') && n.endsWith('"') || n.startsWith("'") && n.endsWith("'")) ? n.slice(1, -1) : n;
82
83
  }, W = (e) => e ? [".env.production.local", ".env.local", ".env.production", ".env"] : [".env.development.local", ".env.local", ".env.development", ".env"];
@@ -84,9 +85,9 @@ async function L(e, n) {
84
85
  const t = /* @__PURE__ */ new Map();
85
86
  for (const o of [...W(n)].reverse()) {
86
87
  const r = u(e, o);
87
- if (!await g.access(r, w.constants.F_OK).then(() => !0).catch(() => !1)) continue;
88
+ if (!await g.access(r, U.constants.F_OK).then(() => !0).catch(() => !1)) continue;
88
89
  const a = await g.readFile(r, "utf-8");
89
- K(a).forEach(({ key: T, value: A }) => t.set(T, A));
90
+ Y(a).forEach(({ key: T, value: A }) => t.set(T, A));
90
91
  }
91
92
  return Array.from(t, ([o, r]) => ({ key: o, value: r }));
92
93
  }
@@ -98,7 +99,7 @@ const X = () => J.join(", "), O = (e) => {
98
99
  `Invalid config version "${String(e)}". Supported versions: ${X()}.`
99
100
  );
100
101
  return n;
101
- }, Oe = ({
102
+ }, Re = ({
102
103
  flag: e,
103
104
  config: n
104
105
  }) => {
@@ -111,8 +112,8 @@ const X = () => J.join(", "), O = (e) => {
111
112
  }, Q = (e) => {
112
113
  const n = e.toUpperCase().replace(/[^A-Z0-9]+/g, "_").replace(/^_+|_+$/g, "");
113
114
  return n ? `${n}_` : "";
114
- }, q = (e) => process.env[R.ENABLE_VAR] !== "true" ? "" : process.env[R.ENV_PREFIX_VAR] || Q(e || "");
115
- async function N(e, n = "global") {
115
+ }, q = (e) => process.env[P.ENABLE_VAR] !== "true" ? "" : process.env[P.ENV_PREFIX_VAR] || Q(e || "");
116
+ async function R(e, n = "global") {
116
117
  let t;
117
118
  switch (n) {
118
119
  case "global":
@@ -141,7 +142,7 @@ async function N(e, n = "global") {
141
142
  ), r;
142
143
  }
143
144
  }
144
- async function P(e = "global") {
145
+ async function N(e = "global") {
145
146
  let n;
146
147
  switch (e) {
147
148
  case "global":
@@ -176,7 +177,7 @@ function ee(e, n) {
176
177
  throw e;
177
178
  }
178
179
  async function ne(e, n = {}) {
179
- const t = Y("azion", {
180
+ const t = K("azion", {
180
181
  searchPlaces: [
181
182
  "azion.config.ts",
182
183
  "azion.config.mts",
@@ -187,9 +188,9 @@ async function ne(e, n = {}) {
187
188
  "azion.config.json"
188
189
  ],
189
190
  loaders: {
190
- ".ts": y(),
191
- ".mts": y(),
192
- ".cts": y()
191
+ ".ts": w(),
192
+ ".mts": w(),
193
+ ".cts": w()
193
194
  }
194
195
  });
195
196
  try {
@@ -216,7 +217,7 @@ async function ne(e, n = {}) {
216
217
  }
217
218
  function te() {
218
219
  const e = f.join(process.cwd(), "package.json");
219
- return w.existsSync(e) ? JSON.parse(w.readFileSync(e, "utf8")).type !== "module" : !0;
220
+ return U.existsSync(e) ? JSON.parse(U.readFileSync(e, "utf8")).type !== "module" : !0;
220
221
  }
221
222
  async function oe(e, n) {
222
223
  const o = te() ? ".cjs" : ".mjs", r = e.build?.preset === "typescript";
@@ -290,9 +291,9 @@ ${p}]`;
290
291
  if (typeof i == "object") {
291
292
  const l = Object.entries(i).filter(([, h]) => h !== void 0);
292
293
  return l.length === 0 ? "{}" : `{
293
- ${l.map(([h, z]) => {
294
- const I = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h) ? h : `'${h}'`;
295
- return `${p} ${I}: ${S(z, d + 1)}`;
294
+ ${l.map(([h, I]) => {
295
+ const z = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(h) ? h : `'${h}'`;
296
+ return `${p} ${z}: ${S(I, d + 1)}`;
296
297
  }).join(`,
297
298
  `)}
298
299
  ${p}}`;
@@ -311,29 +312,29 @@ ${p}}`;
311
312
  await g.writeFile(a, C);
312
313
  }
313
314
  const Ne = {
314
- writeStore: N,
315
- readStore: P,
315
+ writeStore: R,
316
+ readStore: N,
316
317
  readAzionConfig: ne,
317
318
  writeUserConfig: oe
318
319
  };
319
320
  async function Pe(e) {
320
321
  try {
321
- const n = await P("global"), t = n.tempFiles || [];
322
- t.includes(e) || (t.push(e), await N({ ...n, tempFiles: t }, "global"));
322
+ const n = await N("global"), t = n.tempFiles || [];
323
+ t.includes(e) || (t.push(e), await R({ ...n, tempFiles: t }, "global"));
323
324
  } catch {
324
325
  c.warn("Failed to register temp file:", e);
325
326
  }
326
327
  }
327
- async function Re() {
328
+ async function $e() {
328
329
  try {
329
- const e = await P("global"), n = e.tempFiles || [], t = [];
330
+ const e = await N("global"), n = e.tempFiles || [], t = [];
330
331
  n.forEach((o) => {
331
332
  try {
332
333
  x(o), c.info("Successfully removed temp file:", o);
333
334
  } catch {
334
335
  c.warn("Failed to remove temp file:", o), t.push(o);
335
336
  }
336
- }), await N({ ...e, tempFiles: t }, "global"), t.length > 0 && c.warn(`${t.length} temp files could not be removed and will be retried later`);
337
+ }), await R({ ...e, tempFiles: t }, "global"), t.length > 0 && c.warn(`${t.length} temp files could not be removed and will be retried later`);
337
338
  } catch (e) {
338
339
  c.warn("Failed to clean temp files from store:", e);
339
340
  }
@@ -344,7 +345,7 @@ Object.keys(console).forEach((e) => {
344
345
  process.env.DEBUG === "true" && console[e](...n);
345
346
  });
346
347
  });
347
- async function $e(e = !0) {
348
+ async function Fe(e = !0) {
348
349
  const n = process.cwd(), t = F.OUTPUT_ENV_VARS_PATH;
349
350
  try {
350
351
  const o = await L(n, e);
@@ -357,7 +358,7 @@ async function $e(e = !0) {
357
358
  c.warn("No .env file found or error copying environment file");
358
359
  }
359
360
  }
360
- async function Fe(e, n = !0) {
361
+ async function Le(e, n = !0) {
361
362
  const t = q(e);
362
363
  if (!t) return;
363
364
  const o = process.cwd(), r = F.OUTPUT_ENV_VARS_LOCAL_PATH;
@@ -373,27 +374,28 @@ async function Fe(e, n = !0) {
373
374
  }
374
375
  }
375
376
  export {
376
- U as B,
377
+ y as B,
377
378
  F as D,
378
- R as E,
379
- ye as S,
380
- Ue as T,
381
- L as a,
382
- Se as b,
383
- $e as c,
379
+ P as E,
380
+ Ue as S,
381
+ ye as T,
382
+ we as a,
383
+ L as b,
384
+ Se as c,
384
385
  c as d,
385
- Re as e,
386
- E as f,
387
- ne as g,
388
- Oe as h,
389
- oe as i,
390
- N as j,
391
- P as k,
392
- Ne as l,
386
+ $e as e,
387
+ Fe as f,
388
+ E as g,
389
+ ne as h,
390
+ Re as i,
391
+ oe as j,
392
+ R as k,
393
+ N as l,
393
394
  Pe as m,
394
- O as n,
395
- K as p,
395
+ Ne as n,
396
+ O as o,
397
+ Y as p,
396
398
  q as r,
397
- we as u,
398
- Fe as w
399
+ Oe as u,
400
+ Le as w
399
401
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aziontech/bundler",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Tool to launch and build JavaScript/Frameworks. This tool automates polyfills for Edge Computing and assists in creating Workers, notably for the Azion platform.",
5
5
  "index": "dist/index.js",
6
6
  "module": "dist/index.js",