@aziontech/bundler 1.1.3 → 1.2.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 +79 -68
- package/dist/index-Dx9B4Utx.js +2290 -0
- package/dist/index.js +94 -54
- package/dist/utils-CSEkDVys.js +399 -0
- package/package.json +9 -10
- package/dist/index-dMuB6SYF.js +0 -2147
- package/dist/utils-DkUMNTN3.js +0 -329
package/dist/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import { Command as
|
|
2
|
+
import { Command as g } from "commander";
|
|
3
3
|
import { satisfies as b } from "semver";
|
|
4
|
-
import { B as
|
|
5
|
-
import { feedback as
|
|
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
6
|
import { createHash as y } from "crypto";
|
|
7
|
-
import { mkdir as
|
|
8
|
-
const
|
|
9
|
-
function
|
|
7
|
+
import { mkdir as z } from "fs/promises";
|
|
8
|
+
const t = new g();
|
|
9
|
+
function w() {
|
|
10
10
|
const e = process.cwd();
|
|
11
11
|
return y("md5").update(e).digest("hex");
|
|
12
12
|
}
|
|
13
|
-
async function
|
|
14
|
-
const e =
|
|
15
|
-
return await
|
|
13
|
+
async function x() {
|
|
14
|
+
const e = w(), o = i.TEMP_DIR(e);
|
|
15
|
+
return await z(o, { recursive: !0 }), o;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
return b(process.version, `>= ${
|
|
17
|
+
function p() {
|
|
18
|
+
return b(process.version, `>= ${i.MIN_NODE_VERSION}`);
|
|
19
19
|
}
|
|
20
|
-
async function
|
|
20
|
+
async function E() {
|
|
21
21
|
return {
|
|
22
|
-
root:
|
|
23
|
-
package:
|
|
24
|
-
debug:
|
|
25
|
-
version:
|
|
26
|
-
tempPath: await
|
|
27
|
-
argsPath:
|
|
28
|
-
experimental:
|
|
22
|
+
root: i.ROOT_PATH,
|
|
23
|
+
package: i.PACKAGE_JSON,
|
|
24
|
+
debug: i.IS_DEBUG,
|
|
25
|
+
version: i.VERSION,
|
|
26
|
+
tempPath: await x(),
|
|
27
|
+
argsPath: i.ARGS_PATH,
|
|
28
|
+
experimental: i.EXPERIMENTAL
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function k() {
|
|
32
32
|
process.on("exit", a), process.on("SIGINT", () => {
|
|
33
33
|
a(), process.exit(0);
|
|
34
34
|
}), process.on("SIGTERM", () => {
|
|
@@ -43,22 +43,32 @@ function E() {
|
|
|
43
43
|
console.error("Unhandled Promise Rejection:", e), a(), process.exit(1);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
const { storeCommand:
|
|
49
|
-
await
|
|
46
|
+
function A() {
|
|
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-Dx9B4Utx.js");
|
|
49
|
+
await n({
|
|
50
50
|
command: e,
|
|
51
51
|
options: o
|
|
52
52
|
});
|
|
53
|
-
}),
|
|
53
|
+
}), t.command("build").description("Build your project for edge deployment").option("-e, --entry <entries...>", "Code entrypoint (default: ./main.js or ./main.ts)").option("-p, --preset <type>", "Preset of build target (e.g., vue, next, javascript)").option(
|
|
54
54
|
"--polyfills [boolean]",
|
|
55
55
|
"Use node polyfills in build. Use --polyfills or --polyfills=true to enable, --polyfills=false to disable"
|
|
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", "Skip framework build step", !1).option(
|
|
60
|
+
"--config-version <version>",
|
|
61
|
+
'Config (Azion API) version of the project: 3 or 4. Overrides the "version" field of azion.config (default: 4)'
|
|
62
|
+
).option(
|
|
63
|
+
"--config-file <path>",
|
|
64
|
+
"Path to the azion.config file to use (default: azion.config.* found in the current directory)"
|
|
65
|
+
).option("--only-generate-config", "Build only generate azion.config", !1).option(
|
|
60
66
|
"--telemetry [format]",
|
|
61
67
|
"Enable telemetry output (console, json, html or both). Defaults to both if flag is present without value."
|
|
68
|
+
).option(
|
|
69
|
+
"--alias-env",
|
|
70
|
+
"Temporary: rewrite env var names to a per-project prefix to avoid cross-project naming collisions",
|
|
71
|
+
!1
|
|
62
72
|
).addHelpText(
|
|
63
73
|
"after",
|
|
64
74
|
`
|
|
@@ -67,44 +77,73 @@ Examples:
|
|
|
67
77
|
$ azbundler build --only-generate-config -e index.js -p javascript
|
|
68
78
|
$ azbundler build --preset opennextjs
|
|
69
79
|
$ azbundler build --preset opennextjs --skip-framework-build
|
|
80
|
+
$ azbundler build --preset react --config-version 3
|
|
81
|
+
$ azbundler build --config-file ./azion.config.ts
|
|
70
82
|
$ azbundler build --telemetry
|
|
71
83
|
$ azbundler build --telemetry json
|
|
72
84
|
`
|
|
73
85
|
).action(async (e) => {
|
|
74
|
-
const { buildCommand: o, manifestCommand:
|
|
75
|
-
if (
|
|
76
|
-
const
|
|
77
|
-
process.env.AZ_BUNDLER_TELEMETRY = "true", process.env.AZ_BUNDLER_TELEMETRY_FORMAT =
|
|
86
|
+
const { buildCommand: o, manifestCommand: n } = await import("./index-Dx9B4Utx.js"), { dev: r, experimental: c, telemetry: s, aliasEnv: f, ...d } = e;
|
|
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;
|
|
78
90
|
}
|
|
79
|
-
|
|
91
|
+
f && (process.env[v.ENABLE_VAR] = "true");
|
|
92
|
+
const { config: u } = await o({
|
|
80
93
|
...d,
|
|
81
|
-
production: !
|
|
94
|
+
production: !r
|
|
82
95
|
});
|
|
83
|
-
await
|
|
84
|
-
}),
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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(
|
|
98
|
+
"--config-file <path>",
|
|
99
|
+
"Path to the azion.config file to use (default: azion.config.* found in the current directory)"
|
|
100
|
+
).option(
|
|
101
|
+
"--config-version <version>",
|
|
102
|
+
'Config (Azion API) version of the project: 3 or 4. Overrides the "version" field of azion.config (default: 4)'
|
|
103
|
+
).action(async (e, o) => {
|
|
104
|
+
const { devCommand: n } = await import("./index-Dx9B4Utx.js"), { experimental: r } = o;
|
|
105
|
+
r && (globalThis.bundler.experimental = !0), await n({ entry: e, ...o });
|
|
106
|
+
}), t.command("presets <command>").description("Manage presets for Azion projects").argument("[preset]", "Preset name (required for config command)").option(
|
|
107
|
+
"--config-version <version>",
|
|
108
|
+
"Config (Azion API) version of the preset config to show: 3 or 4 (default: 4)"
|
|
109
|
+
).option(
|
|
110
|
+
"--config-file <path>",
|
|
111
|
+
'Path to the azion.config file whose "version" is used when --config-version is not given'
|
|
112
|
+
).action(async (e, o, n) => {
|
|
113
|
+
const { presetsCommand: r } = await import("./index-Dx9B4Utx.js");
|
|
114
|
+
await r(e, {
|
|
115
|
+
preset: o,
|
|
116
|
+
configVersion: n?.configVersion,
|
|
117
|
+
configFile: n?.configFile
|
|
118
|
+
});
|
|
119
|
+
}), t.command("manifest [action]").description("Manage manifest files for Azion").argument(
|
|
91
120
|
"[action]",
|
|
92
121
|
'Action to perform: "transform" (JSON to JS) or "generate" (config to manifest)'
|
|
93
|
-
).option("-e, --entry <path>", "Path to the input file or configuration file").option("-o, --output <path>", "Output file/directory path").
|
|
122
|
+
).option("-e, --entry <path>", "Path to the input file or configuration file").option("-o, --output <path>", "Output file/directory path").option(
|
|
123
|
+
"--config-file <path>",
|
|
124
|
+
"Path to the azion.config file (generate action). Same as --entry, which takes precedence"
|
|
125
|
+
).option(
|
|
126
|
+
"--config-version <version>",
|
|
127
|
+
'Config (Azion API) version of the project: 3 or 4. Used when azion.config does not declare "version" (default: 4)'
|
|
128
|
+
).addHelpText(
|
|
94
129
|
"after",
|
|
95
130
|
`
|
|
96
131
|
Examples:
|
|
97
132
|
$ azbundler manifest transform -e manifest.json -o azion.config.js
|
|
98
133
|
$ azbundler manifest generate -e azion.config.js -o .edge
|
|
99
134
|
$ azbundler manifest -e azion.config.js -o .edge
|
|
135
|
+
$ azbundler manifest generate --config-file ./azion.config.ts
|
|
100
136
|
`
|
|
101
|
-
).action(async (e, o,
|
|
102
|
-
const { manifestCommand:
|
|
103
|
-
await
|
|
104
|
-
...o ||
|
|
137
|
+
).action(async (e, o, n) => {
|
|
138
|
+
const { manifestCommand: r } = await import("./index-Dx9B4Utx.js");
|
|
139
|
+
await r({
|
|
140
|
+
...o || n,
|
|
105
141
|
action: e
|
|
106
142
|
});
|
|
107
|
-
}),
|
|
143
|
+
}), t.command("config <command>").description("Manage azion.config settings").option("-k, --key <key...>", "Property key (e.g., build.preset or applications[0].name)").option("-v, --value <value...>", "Value to be set").option("-a, --all", "Read or delete entire configuration (for read/delete commands)").option("-r, --replacements <replacements>", "JSON string of key-value pairs for replacement").option(
|
|
144
|
+
"--config-file <path>",
|
|
145
|
+
"Path to the azion.config file to use (default: azion.config.* found in the current directory)"
|
|
146
|
+
).addHelpText(
|
|
108
147
|
"after",
|
|
109
148
|
`
|
|
110
149
|
Examples:
|
|
@@ -115,14 +154,15 @@ Examples:
|
|
|
115
154
|
$ azbundler config delete -a
|
|
116
155
|
$ azbundler config delete -k "build.preset"
|
|
117
156
|
$ azbundler config replace -k '$EDGE_FUNCTION_NAME' -v "my-func"
|
|
157
|
+
$ azbundler config read -a --config-file ./azion.config.ts
|
|
118
158
|
`
|
|
119
159
|
).action(async (e, o) => {
|
|
120
|
-
const { configCommand:
|
|
121
|
-
await
|
|
160
|
+
const { configCommand: n } = await import("./index-Dx9B4Utx.js");
|
|
161
|
+
await n({
|
|
122
162
|
command: e,
|
|
123
163
|
options: o
|
|
124
164
|
});
|
|
125
|
-
}),
|
|
165
|
+
}), t.command("telemetry").description("Open the telemetry HTML report in the default browser").option("-p, --path <path>", "Custom path to the telemetry HTML file").addHelpText(
|
|
126
166
|
"after",
|
|
127
167
|
`
|
|
128
168
|
Examples:
|
|
@@ -130,14 +170,14 @@ Examples:
|
|
|
130
170
|
$ azbundler telemetry --path ./custom-report.html
|
|
131
171
|
`
|
|
132
172
|
).action(async (e) => {
|
|
133
|
-
const { telemetryCommand: o } = await import("./index-
|
|
173
|
+
const { telemetryCommand: o } = await import("./index-Dx9B4Utx.js");
|
|
134
174
|
await o(e);
|
|
135
|
-
}),
|
|
175
|
+
}), t.parse(process.argv);
|
|
136
176
|
}
|
|
137
177
|
try {
|
|
138
|
-
|
|
139
|
-
`Invalid Node version. Node version must be greater than ${
|
|
178
|
+
p() && (globalThis.bundler = await E(), A(), k()), p() || (l.error(
|
|
179
|
+
`Invalid Node version. Node version must be greater than ${i.MIN_NODE_VERSION}.`
|
|
140
180
|
), process.exit(1));
|
|
141
181
|
} catch (e) {
|
|
142
|
-
|
|
182
|
+
l.error("An unknown error occurred."), h.error(e), process.exit(1);
|
|
143
183
|
}
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import w, { readFileSync as V, unlinkSync as x } from "fs";
|
|
2
|
+
import g, { writeFile as $ } from "fs/promises";
|
|
3
|
+
import { getAbsoluteDirPath as k, feedback as m } from "@aziontech/utils/node";
|
|
4
|
+
import { tmpdir as B } from "os";
|
|
5
|
+
import f, { join as u, resolve as M } from "path";
|
|
6
|
+
import "@aziontech/builder/polyfills";
|
|
7
|
+
import "@edge-runtime/primitives/dist/load.js";
|
|
8
|
+
import "chokidar";
|
|
9
|
+
import { DEFAULT_API_VERSION as j, isSupportedApiVersion as H, SUPPORTED_API_VERSIONS as J, convertJsonConfigToObject as G } from "@aziontech/config";
|
|
10
|
+
import "@aziontech/bundler-telemetry";
|
|
11
|
+
import "@aziontech/builder";
|
|
12
|
+
import "lodash";
|
|
13
|
+
import "@aziontech/presets";
|
|
14
|
+
import "@netlify/framework-info";
|
|
15
|
+
import "edge-runtime";
|
|
16
|
+
import Z from "prettier";
|
|
17
|
+
import { cosmiconfig as Y } from "cosmiconfig";
|
|
18
|
+
import { TypeScriptLoader as y } from "cosmiconfig-typescript-loader";
|
|
19
|
+
const F = {
|
|
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
|
+
}, Se = {
|
|
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
|
+
}, ye = {
|
|
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: k(import.meta.url, "bundler"),
|
|
50
|
+
ARGS_PATH: "@aziontech/args.json",
|
|
51
|
+
IS_DEBUG: process.env.DEBUG === "true",
|
|
52
|
+
TEMP_DIR: (e) => u(B(), ".azion", e),
|
|
53
|
+
get ROOT_PATH() {
|
|
54
|
+
return M(U.LIB_DIR, ".");
|
|
55
|
+
},
|
|
56
|
+
get PACKAGE_JSON() {
|
|
57
|
+
return JSON.parse(V(`${U.ROOT_PATH}/package.json`, "utf8"));
|
|
58
|
+
},
|
|
59
|
+
get VERSION() {
|
|
60
|
+
return U.PACKAGE_JSON.version;
|
|
61
|
+
}
|
|
62
|
+
}, E = `
|
|
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
|
+
`, R = {
|
|
69
|
+
ENV_PREFIX_VAR: "AZ_BUNDLER_ENV_ALIAS_PREFIX",
|
|
70
|
+
ENABLE_VAR: "AZ_BUNDLER_ENV_ALIAS_ENABLED"
|
|
71
|
+
}, Ue = {
|
|
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
|
+
}, 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) => {
|
|
80
|
+
const n = e.trim().replace(/\r$/, "");
|
|
81
|
+
return n.length >= 2 && (n.startsWith('"') && n.endsWith('"') || n.startsWith("'") && n.endsWith("'")) ? n.slice(1, -1) : n;
|
|
82
|
+
}, W = (e) => e ? [".env.production.local", ".env.local", ".env.production", ".env"] : [".env.development.local", ".env.local", ".env.development", ".env"];
|
|
83
|
+
async function L(e, n) {
|
|
84
|
+
const t = /* @__PURE__ */ new Map();
|
|
85
|
+
for (const o of [...W(n)].reverse()) {
|
|
86
|
+
const r = u(e, o);
|
|
87
|
+
if (!await g.access(r, w.constants.F_OK).then(() => !0).catch(() => !1)) continue;
|
|
88
|
+
const a = await g.readFile(r, "utf-8");
|
|
89
|
+
K(a).forEach(({ key: T, value: A }) => t.set(T, A));
|
|
90
|
+
}
|
|
91
|
+
return Array.from(t, ([o, r]) => ({ key: o, value: r }));
|
|
92
|
+
}
|
|
93
|
+
const X = () => J.join(", "), O = (e) => {
|
|
94
|
+
if (e == null || e === "") return;
|
|
95
|
+
const n = typeof e == "string" ? Number(e.trim().replace(/^v/i, "")) : e;
|
|
96
|
+
if (!H(n))
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Invalid config version "${String(e)}". Supported versions: ${X()}.`
|
|
99
|
+
);
|
|
100
|
+
return n;
|
|
101
|
+
}, Oe = ({
|
|
102
|
+
flag: e,
|
|
103
|
+
config: n
|
|
104
|
+
}) => {
|
|
105
|
+
const t = O(e), o = n?.version, r = o == null ? void 0 : O(o);
|
|
106
|
+
if (t !== void 0 && r !== void 0 && t !== r)
|
|
107
|
+
throw new Error(
|
|
108
|
+
`Conflicting config versions: --config-version is ${t} but azion.config declares version ${r}. Remove the flag or update the "version" field of your azion.config.`
|
|
109
|
+
);
|
|
110
|
+
return t ?? r ?? j;
|
|
111
|
+
}, Q = (e) => {
|
|
112
|
+
const n = e.toUpperCase().replace(/[^A-Z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
113
|
+
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") {
|
|
116
|
+
let t;
|
|
117
|
+
switch (n) {
|
|
118
|
+
case "global":
|
|
119
|
+
t = globalThis.bundler.tempPath;
|
|
120
|
+
break;
|
|
121
|
+
case "local":
|
|
122
|
+
t = f.join(process.cwd());
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
t = n;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
const o = f.join(t, ".azion-bundler.json");
|
|
129
|
+
try {
|
|
130
|
+
await g.mkdir(t, { recursive: !0 });
|
|
131
|
+
} catch (r) {
|
|
132
|
+
throw c.error(r), m.build.error(
|
|
133
|
+
`An error occurred while creating the ${o} folder.${E}`
|
|
134
|
+
), r;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
await g.writeFile(o, JSON.stringify(e, null, 2));
|
|
138
|
+
} catch (r) {
|
|
139
|
+
throw c.error(r), m.build.error(
|
|
140
|
+
`An error occurred while writing the ${o} file.${E}`
|
|
141
|
+
), r;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function P(e = "global") {
|
|
145
|
+
let n;
|
|
146
|
+
switch (e) {
|
|
147
|
+
case "global":
|
|
148
|
+
n = globalThis.bundler.tempPath;
|
|
149
|
+
break;
|
|
150
|
+
case "local":
|
|
151
|
+
n = f.join(process.cwd());
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
n = e;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
if (!n) return {};
|
|
158
|
+
const t = f.join(n, ".azion-bundler.json");
|
|
159
|
+
try {
|
|
160
|
+
await g.access(t);
|
|
161
|
+
const o = await g.readFile(t, "utf8");
|
|
162
|
+
return JSON.parse(o);
|
|
163
|
+
} catch {
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function ee(e, n) {
|
|
168
|
+
if (e.message.includes("ERR_MODULE_NOT_FOUND")) {
|
|
169
|
+
const t = e.message.match(/'([^']+)'/)?.[1];
|
|
170
|
+
t ? m.build.error(
|
|
171
|
+
`Missing dependency: ${t}. Please install it using 'npm install ${t}' or 'yarn add ${t}'.${E}`
|
|
172
|
+
) : m.build.error(
|
|
173
|
+
`A required dependency is missing. Please ensure all dependencies are installed.${E}`
|
|
174
|
+
), c.error(`Failed to load configuration from ${n}. ${e.message}`);
|
|
175
|
+
} else
|
|
176
|
+
throw e;
|
|
177
|
+
}
|
|
178
|
+
async function ne(e, n = {}) {
|
|
179
|
+
const t = Y("azion", {
|
|
180
|
+
searchPlaces: [
|
|
181
|
+
"azion.config.ts",
|
|
182
|
+
"azion.config.mts",
|
|
183
|
+
"azion.config.cts",
|
|
184
|
+
"azion.config.js",
|
|
185
|
+
"azion.config.mjs",
|
|
186
|
+
"azion.config.cjs",
|
|
187
|
+
"azion.config.json"
|
|
188
|
+
],
|
|
189
|
+
loaders: {
|
|
190
|
+
".ts": y(),
|
|
191
|
+
".mts": y(),
|
|
192
|
+
".cts": y()
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
try {
|
|
196
|
+
const o = e ? await t.load(e) : await t.search();
|
|
197
|
+
if (!o) return null;
|
|
198
|
+
const r = o.config, s = o.filepath;
|
|
199
|
+
return f.extname(s) === ".json" ? G(JSON.stringify(r), {
|
|
200
|
+
version: O(n.configVersion)
|
|
201
|
+
}) : r;
|
|
202
|
+
} catch (o) {
|
|
203
|
+
if (o.message.includes("ERR_MODULE_NOT_FOUND"))
|
|
204
|
+
return ee(o, e || "azion.config"), null;
|
|
205
|
+
if (o.message.includes("TypeScriptLoader failed to compile")) {
|
|
206
|
+
const r = o.message.split(`TypeScriptLoader failed to compile TypeScript:
|
|
207
|
+
`)[1]?.trim();
|
|
208
|
+
m.build.error(`${r || o.message}${E}`), process.exit(1);
|
|
209
|
+
}
|
|
210
|
+
o.message.includes("ERR_REQUIRE_CYCLE_MODULE") && (m.build.error(
|
|
211
|
+
`Circular dependency detected while loading configuration file. This usually happens when using ES modules. Please ensure your configuration file doesn't have circular imports.${E}`
|
|
212
|
+
), process.exit(1)), c.error(o), m.build.error(
|
|
213
|
+
`Failed to load configuration file. For detailed debugging information, run with DEBUG=true environment variable.${E}`
|
|
214
|
+
), process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function te() {
|
|
218
|
+
const e = f.join(process.cwd(), "package.json");
|
|
219
|
+
return w.existsSync(e) ? JSON.parse(w.readFileSync(e, "utf8")).type !== "module" : !0;
|
|
220
|
+
}
|
|
221
|
+
async function oe(e, n) {
|
|
222
|
+
const o = te() ? ".cjs" : ".mjs", r = e.build?.preset === "typescript";
|
|
223
|
+
let s = r ? ".ts" : o, a;
|
|
224
|
+
if (n) {
|
|
225
|
+
const i = f.parse(n);
|
|
226
|
+
if ([".js", ".mjs", ".cjs", ".ts"].includes(i.ext))
|
|
227
|
+
a = f.resolve(n), s = i.ext;
|
|
228
|
+
else {
|
|
229
|
+
const l = f.resolve(n);
|
|
230
|
+
try {
|
|
231
|
+
(await g.stat(l)).isFile() ? a = `${l}${s}` : a = f.join(l, `azion.config${s}`);
|
|
232
|
+
} catch {
|
|
233
|
+
n.includes("/") || n.includes("\\") ? a = f.join(l, `azion.config${s}`) : a = `${l}${s}`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
} else
|
|
237
|
+
a = f.join(process.cwd(), `azion.config${s}`);
|
|
238
|
+
const T = r ? "export default" : s === ".cjs" ? "module.exports =" : "export default", A = `/**
|
|
239
|
+
* This file was automatically generated based on your preset configuration.
|
|
240
|
+
*
|
|
241
|
+
* For better type checking and IntelliSense:
|
|
242
|
+
* 1. Install azion config as dev dependency:
|
|
243
|
+
* npm install -D @aziontech/config
|
|
244
|
+
*
|
|
245
|
+
* 2. Use defineConfig:
|
|
246
|
+
* import { defineConfig } from '@aziontech/config'
|
|
247
|
+
*
|
|
248
|
+
* 3. Replace the configuration with defineConfig:
|
|
249
|
+
* export default defineConfig({
|
|
250
|
+
* // Your configuration here
|
|
251
|
+
* })
|
|
252
|
+
*
|
|
253
|
+
* For more configuration options, visit:
|
|
254
|
+
* https://github.com/aziontech/lib/tree/main/packages/config
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
`;
|
|
258
|
+
function v(i) {
|
|
259
|
+
if (i == null)
|
|
260
|
+
return i;
|
|
261
|
+
if (Array.isArray(i))
|
|
262
|
+
return i.map(v).filter((d) => d !== void 0);
|
|
263
|
+
if (typeof i == "object") {
|
|
264
|
+
const d = {};
|
|
265
|
+
for (const [p, l] of Object.entries(i))
|
|
266
|
+
if (l !== void 0) {
|
|
267
|
+
const _ = v(l);
|
|
268
|
+
_ !== void 0 && (d[p] = _);
|
|
269
|
+
}
|
|
270
|
+
return d;
|
|
271
|
+
}
|
|
272
|
+
return i;
|
|
273
|
+
}
|
|
274
|
+
function S(i, d = 0) {
|
|
275
|
+
const p = " ".repeat(d);
|
|
276
|
+
if (typeof i == "function")
|
|
277
|
+
return i.toString();
|
|
278
|
+
if (typeof i == "string")
|
|
279
|
+
return `'${i.replaceAll("'", "\\'")}'`;
|
|
280
|
+
if (typeof i == "number" || typeof i == "boolean" || i == null)
|
|
281
|
+
return String(i);
|
|
282
|
+
if (Array.isArray(i)) {
|
|
283
|
+
if (i.length === 0) return "[]";
|
|
284
|
+
const l = i.map((_) => S(_, d + 1));
|
|
285
|
+
return `[
|
|
286
|
+
${p} ${l.join(`,
|
|
287
|
+
${p} `)}
|
|
288
|
+
${p}]`;
|
|
289
|
+
}
|
|
290
|
+
if (typeof i == "object") {
|
|
291
|
+
const l = Object.entries(i).filter(([, h]) => h !== void 0);
|
|
292
|
+
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)}`;
|
|
296
|
+
}).join(`,
|
|
297
|
+
`)}
|
|
298
|
+
${p}}`;
|
|
299
|
+
}
|
|
300
|
+
return String(i);
|
|
301
|
+
}
|
|
302
|
+
const b = v(e), D = S(b), C = await Z.format(
|
|
303
|
+
A + `${T} ${D};`,
|
|
304
|
+
{
|
|
305
|
+
parser: "babel",
|
|
306
|
+
semi: !1,
|
|
307
|
+
singleQuote: !0,
|
|
308
|
+
trailingComma: "none"
|
|
309
|
+
}
|
|
310
|
+
);
|
|
311
|
+
await g.writeFile(a, C);
|
|
312
|
+
}
|
|
313
|
+
const Ne = {
|
|
314
|
+
writeStore: N,
|
|
315
|
+
readStore: P,
|
|
316
|
+
readAzionConfig: ne,
|
|
317
|
+
writeUserConfig: oe
|
|
318
|
+
};
|
|
319
|
+
async function Pe(e) {
|
|
320
|
+
try {
|
|
321
|
+
const n = await P("global"), t = n.tempFiles || [];
|
|
322
|
+
t.includes(e) || (t.push(e), await N({ ...n, tempFiles: t }, "global"));
|
|
323
|
+
} catch {
|
|
324
|
+
c.warn("Failed to register temp file:", e);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async function Re() {
|
|
328
|
+
try {
|
|
329
|
+
const e = await P("global"), n = e.tempFiles || [], t = [];
|
|
330
|
+
n.forEach((o) => {
|
|
331
|
+
try {
|
|
332
|
+
x(o), c.info("Successfully removed temp file:", o);
|
|
333
|
+
} catch {
|
|
334
|
+
c.warn("Failed to remove temp file:", o), t.push(o);
|
|
335
|
+
}
|
|
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
|
+
} catch (e) {
|
|
338
|
+
c.warn("Failed to clean temp files from store:", e);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const c = {};
|
|
342
|
+
Object.keys(console).forEach((e) => {
|
|
343
|
+
typeof console[e] == "function" && (c[e] = (...n) => {
|
|
344
|
+
process.env.DEBUG === "true" && console[e](...n);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
async function $e(e = !0) {
|
|
348
|
+
const n = process.cwd(), t = F.OUTPUT_ENV_VARS_PATH;
|
|
349
|
+
try {
|
|
350
|
+
const o = await L(n, e);
|
|
351
|
+
if (o.length === 0) return;
|
|
352
|
+
const r = o.map(({ key: s, value: a }) => `${s}=${a}`).join(`
|
|
353
|
+
`);
|
|
354
|
+
await $(t, `${r}
|
|
355
|
+
`, "utf-8"), c.info(`Environment file copied to ${t}`);
|
|
356
|
+
} catch {
|
|
357
|
+
c.warn("No .env file found or error copying environment file");
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
async function Fe(e, n = !0) {
|
|
361
|
+
const t = q(e);
|
|
362
|
+
if (!t) return;
|
|
363
|
+
const o = process.cwd(), r = F.OUTPUT_ENV_VARS_LOCAL_PATH;
|
|
364
|
+
try {
|
|
365
|
+
const s = await L(o, n);
|
|
366
|
+
if (s.length === 0) return;
|
|
367
|
+
const a = s.map(({ key: T, value: A }) => `${t}${T}=${A}`).join(`
|
|
368
|
+
`);
|
|
369
|
+
await $(r, `${a}
|
|
370
|
+
`, "utf-8"), c.info(`Prefixed environment file written to ${r}`);
|
|
371
|
+
} catch {
|
|
372
|
+
c.warn("No .env file found or error writing prefixed environment file");
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
export {
|
|
376
|
+
U as B,
|
|
377
|
+
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,
|
|
384
|
+
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,
|
|
393
|
+
Pe as m,
|
|
394
|
+
O as n,
|
|
395
|
+
K as p,
|
|
396
|
+
q as r,
|
|
397
|
+
we as u,
|
|
398
|
+
Fe as w
|
|
399
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aziontech/bundler",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"author": "aziontech",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@aziontech/builder": "1.0.
|
|
17
|
-
"@aziontech/bundler-telemetry": "1.0.0",
|
|
18
|
-
"@aziontech/config": "1.0
|
|
19
|
-
"@aziontech/presets": "1.
|
|
20
|
-
"@aziontech/utils": "1.0.0",
|
|
16
|
+
"@aziontech/builder": "~1.0.6",
|
|
17
|
+
"@aziontech/bundler-telemetry": "~1.0.0",
|
|
18
|
+
"@aziontech/config": "~1.1.0",
|
|
19
|
+
"@aziontech/presets": "~1.2.0",
|
|
20
|
+
"@aziontech/utils": "~1.0.0",
|
|
21
21
|
"@edge-runtime/primitives": "4.0.5",
|
|
22
22
|
"@netlify/framework-info": "^9.9.1",
|
|
23
|
-
"chokidar": "^
|
|
23
|
+
"chokidar": "^4.0.3",
|
|
24
24
|
"commander": "^10.0.1",
|
|
25
25
|
"cosmiconfig": "^9.0.0",
|
|
26
26
|
"cosmiconfig-typescript-loader": "^6.1.0",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"@types/tmp": "^0.2.6",
|
|
44
44
|
"globals": "^16.0.0",
|
|
45
45
|
"jest": "^30.4.2",
|
|
46
|
-
"markdown-table": "^3.0.3",
|
|
47
46
|
"mock-fs": "^5.2.0",
|
|
48
47
|
"puppeteer": "^25.3.0",
|
|
49
48
|
"supertest": "^7.2.2",
|
|
@@ -80,8 +79,8 @@
|
|
|
80
79
|
"e2e:start": "pnpm submodule:update && tests/scripts/start-e2e-env.sh",
|
|
81
80
|
"e2e:stop": "tests/scripts/stop-e2e-env.sh",
|
|
82
81
|
"e2e:destroy": "tests/scripts/destroy-e2e-env.sh",
|
|
83
|
-
"test:e2e": "pnpm e2e:start && NODE_OPTIONS='--experimental-vm-modules' jest --detectOpenHandles --forceExit --runInBand --config=./jest-e2e.config.js tests/e2e/ --json --outputFile e2e_results.json
|
|
84
|
-
"test:nodejs-apis": "pnpm e2e:start && NODE_OPTIONS='--experimental-vm-modules' jest --forceExit --runInBand --config=./jest-e2e.config.js tests/nodejs-apis/ --json --outputFile nodejs_apis_results.json
|
|
82
|
+
"test:e2e": "pnpm e2e:start && NODE_OPTIONS='--experimental-vm-modules' jest --detectOpenHandles --forceExit --runInBand --config=./jest-e2e.config.js tests/e2e/ --json --outputFile e2e_results.json; TEST_EXIT_CODE=$?; pnpm e2e:stop; pnpm task:reports; exit $TEST_EXIT_CODE",
|
|
83
|
+
"test:nodejs-apis": "pnpm e2e:start && NODE_OPTIONS='--experimental-vm-modules' jest --forceExit --runInBand --config=./jest-e2e.config.js tests/nodejs-apis/ --json --outputFile nodejs_apis_results.json; TEST_EXIT_CODE=$?; pnpm e2e:stop; pnpm task:reports-nodejs-apis; exit $TEST_EXIT_CODE",
|
|
85
84
|
"submodule:update": "git submodule update --init --recursive && git submodule foreach git pull origin main"
|
|
86
85
|
}
|
|
87
86
|
}
|