UNPKG

azion

Version:

Azion Packages for Edge Computing.

2,051 lines 127 kB
import F, { existsSync as M, mkdirSync as Q, readdirSync as ee, lstatSync as at, copyFileSync as it, promises as j, readFileSync as L, constants as st, writeFileSync as V, rmSync as be } from "fs"; import N, { resolve as I, join as g, relative as te, dirname as ne, basename as G, extname as ot } from "path"; import ct, { spawn as ut, exec as lt } from "child_process"; import re from "signale"; import { mkdir as A, access as _e, readFile as w, copyFile as W, stat as ve, constants as dt, rm as B, readdir as Ce, lstat as R } from "fs/promises"; import pt from "webpack"; import ft from "pcre-to-regexp/dist/index.js"; import { tmpdir as oe } from "os"; import { valid as Pe, coerce as Te, gte as mt } from "semver"; import gt from "fast-glob"; import ce from "mime-types"; const S = { // Images IMAGES: ["jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", "ico"], // Fonts FONTS: ["ttf", "otf", "woff", "woff2", "eot"], // Documents DOCUMENTS: ["pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx"], // Media MEDIA: ["mp4", "webm", "mp3", "wav", "ogg"], // Code & Data CODE_AND_DATA: ["css", "js", "json", "xml", "html", "txt", "csv"], // Archives ARCHIVES: ["zip", "rar", "7z", "tar", "gz"], // Other OTHER: ["webmanifest", "map", "md", "yaml", "yml"] }, Oe = [ ...S.IMAGES, ...S.FONTS, ...S.DOCUMENTS, ...S.MEDIA, ...S.CODE_AND_DATA, ...S.ARCHIVES, ...S.OTHER ]; function v(e = {}) { const { connector: t = "name-connector", application: n = "name-application", staticExtensions: r = Oe } = e; return { request: [ { name: "Deliver Static Assets and Set Cache Policy", description: "Deliver static assets directly from storage and set cache policy", active: !0, criteria: [ [ { variable: "${uri}", conditional: "if", operator: "matches", argument: `\\.(${r.join("|")})$` } ] ], behaviors: [ { type: "set_connector", attributes: { value: t } }, { type: "set_cache_policy", attributes: { value: n } }, { type: "deliver" } ] }, { name: "Redirect to index.html", description: "Handle directory requests by rewriting to index.html", active: !0, criteria: [ [ { variable: "${uri}", conditional: "if", operator: "matches", argument: ".*/$" } ] ], behaviors: [ { type: "set_connector", attributes: { value: t } }, { type: "rewrite_request", attributes: { value: "${uri}index.html" } } ] }, { name: "Redirect to index.html for Subpaths", description: "Handle subpath requests by rewriting to index.html", active: !0, criteria: [ [ { variable: "${uri}", conditional: "if", operator: "matches", argument: "^(?!.*\\/$)(?![\\s\\S]*\\.[a-zA-Z0-9]+$).*" } ] ], behaviors: [ { type: "set_connector", attributes: { value: t } }, { type: "rewrite_request", attributes: { value: "${uri}/index.html" } } ] } ], response: [] }; } function K(e = {}) { const { connector: t = "name-connector", application: n = "name-application", staticExtensions: r = Oe } = e; return { request: [ { name: "Deliver Static Assets and Set Cache Policy", description: "Deliver static assets directly from storage and set cache policy", active: !0, criteria: [ [ { variable: "${uri}", conditional: "if", operator: "matches", argument: `\\.(${r.join("|")})$` } ] ], behaviors: [ { type: "set_connector", attributes: { value: t } }, { type: "set_cache_policy", attributes: { value: n } }, { type: "deliver" } ] }, { name: "Redirect to index.html", description: "Handle all routes by rewriting to index.html for client-side routing", active: !0, criteria: [ [ { variable: "${uri}", conditional: "if", operator: "matches", argument: "^\\/" } ] ], behaviors: [ { type: "set_connector", attributes: { value: t } }, { type: "rewrite_request", attributes: { value: "/index.html" } } ] } ], response: [] }; } const ht = { build: { bundler: "esbuild" }, storage: [ { name: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX", dir: "./dist", workloadsAccess: "read_only" } ], connectors: [ { name: "$CONNECTOR_NAME", active: !0, type: "storage", attributes: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } ], applications: [ { name: "$APPLICATION_NAME", cache: [ { name: "$APPLICATION_NAME", browser: { maxAgeSeconds: 7200 }, edge: { maxAgeSeconds: 7200 } } ], rules: K({ connector: "$CONNECTOR_NAME", application: "$APPLICATION_NAME" }) } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, y = (e) => { const t = new URL(e).pathname, n = t.endsWith("/") ? t.slice(0, -1) : t, r = /\.[^.]+$/; let a; return n === "" ? a = new URL("index.html", "file:///") : r.test(n) ? a = new URL(n.slice(1), "file:///") : a = new URL(`${n.slice(1)}/index.html`, "file:///"), fetch(a); }, X = (e) => { const t = new URL(e).pathname; let n; return /\.[^.]+$/.test(t) ? n = new URL(t.slice(1), "file:///") : n = new URL("index.html", "file:///"), fetch(n); }, xe = { name: "angular", registry: "angular" }, Et = { /** * Handles the 'fetch' event using Azion Workers pattern. * @param {Request} request - The request object with metadata. * @param {Object} env - The environment context containing Azion services. * @param {Object} ctx - The execution context. * @returns {Promise<Response>} The response for the request. */ fetch: async (e) => { try { return await X(e.url); } catch (t) { return new Response( JSON.stringify({ error: `Failed to mount ${xe.name} application`, message: t instanceof Error ? t.message : "Unknown error occurred", path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }; function T(e, t, n) { const r = I(e), a = I(t); if (r === a) return; M(a) || Q(a, { recursive: !0 }); const i = ee(r); for (const s of i) { const o = g(r, s), c = g(a, s); c.startsWith(o) || (at(o).isDirectory() ? T(o, c) : it(o, c)); } } async function h(e, { scope: t = "Azion", verbose: n = !1, interactive: r = !1 } = {}) { const a = new re.Signale({ interactive: !0, scope: t }); return new Promise((i, s) => { const o = e.split(" "), c = o.shift(); let u = "", l = ""; const d = ut(c, o, { shell: !0, stdio: r ? "inherit" : "pipe" }); r || (d.stdout?.on("data", (p) => { const m = p.toString(); u += m, n && a.info(m); }), d.stderr?.on("data", (p) => { const m = p.toString(); l += m, n && (m.toLowerCase().includes("error") ? a.error(m) : a.info(m)); }), d.on("error", (p) => { s(p); })), d.on("close", (p) => { p === 0 ? i({ stdout: u, stderr: l }) : s(new Error(`Command '${e}' failed with code ${p}`)); }), d.on("exit", (p) => { p === 0 ? i({ stdout: u, stderr: l }) : s(new Error(`Command '${e}' failed with code ${p}`)); }); }); } const Me = process.env.CLEAN_OUTPUT_MODE === "true", Ie = { displayScope: !1, displayBadge: !1, displayDate: !1, displayFilename: !1, displayLabel: !1, displayTimestamp: !1, underlineLabel: !1, underlineMessage: !1, underlinePrefix: !1, underlineSuffix: !1, uppercaseLabel: !1 }, O = (e = {}) => { const t = new re.Signale({ ...e }); return Me && t.config(Ie), Object.assign(t, { breakInteractiveChain: () => console.log() }); }, C = { deployed: { badge: "🚀", color: "green", label: "forged", logLevel: "info" }, option: { badge: "📦", color: "green", label: "", logLevel: "info" } }, P = (e = "Azion") => new re.Signale({ interactive: !1, scope: e, types: C }); Me && P().config(Ie); const ue = (e = "Azion") => ({ ...P(e), interactive: { ...O({ interactive: !0, scope: [e], types: C }) }, server: { ...P(e).scope(e, "Server"), interactive: O({ interactive: !0, scope: [e, "Server"], types: C }) }, runtime: { ...P(e).scope(e, "Runtime"), interactive: O({ interactive: !0, scope: [e, "Runtime"], types: C }) }, prebuild: { ...P(e).scope(e, "Pre-Build"), interactive: O({ interactive: !0, scope: [e, "Pre-Build"], types: C }) }, build: { ...P(e).scope(e, "Build"), interactive: O({ interactive: !0, scope: [e, "Build"], types: C }) }, postbuild: { ...P(e).scope(e, "Post-Build"), interactive: O({ interactive: !0, scope: [e, "Post-build"], types: C }) }, storage: { ...P(e).scope(e, "Storage"), interactive: O({ interactive: !0, scope: [e, "Storage"], types: C }) }, bindings: { ...P(e).scope(e, "Bindings"), interactive: O({ interactive: !0, scope: [e, "Bindings"], types: C }) }, manifest: { ...P(e).scope(e, "IaC"), interactive: O({ interactive: !0, scope: [e, "IaC"], types: C }) } }), f = { ...ue(), globalScope: (e) => ({ ...ue(e) }) }, le = process.platform === "win32"; function Re(e = import.meta.url, t = "bundler") { const n = new RegExp(`(.*${t})(.*)`), r = e.match(n); let a = r ? r[1] : ""; if (e.includes("edge-functions") && t === "bundler") { const i = new RegExp("(.*edge-functions)(.*)"), s = e.match(i); a = s ? s[1] : a; } return le && (a = new URL(a).pathname, a.startsWith("/") && (a = a.slice(1))), le || (a = a.replace("file://", "")), a; } const Nt = { yarn: { fileName: "yarn.lock", pmType: "yarn" }, npm: { fileName: "package-lock.json", pmType: "npm" }, pnpm: { fileName: "pnpm-lock.yaml", pmType: "pnpm" } }, At = "npx", yt = async (e) => { try { return await j.access(e), !0; } catch { return !1; } }, k = /* @__PURE__ */ new Map(), de = async (e) => { const t = `has_global_${e}`; return k.has(t) ? k.get(t) : new Promise((n) => { lt(`${e} --version`, (r, a) => { const i = !r && /^\d+\.\d+\.\d+$/.test(a.trim()); k.set(t, i), n(i); }); }); }, $t = async (e = ".") => { const t = `lockfile_${e}`; if (k.has(t)) return k.get(t); const r = (await Promise.all( Object.values(Nt).map(async ({ fileName: i, pmType: s }) => ({ exists: await yt(N.resolve(e, i)), pmType: s })) )).find(({ exists: i }) => i), a = r ? r.pmType : null; return k.set(t, a), a; }, $ = async ({ cwd: e } = {}) => { const t = await $t(e); if (t) return t; const [n, r] = await Promise.all([de("yarn"), de("pnpm")]); return n ? "yarn" : r ? "pnpm" : At; }; function wt(e) { const t = g(process.cwd(), "package.json"), n = L(t, "utf8"), r = JSON.parse(n); if (!r.dependencies || !r.dependencies[e]) throw new Error(`'${e}' not detected in project dependencies!`); return r.dependencies[e]; } async function bt(e, t) { try { const n = await j.readdir(e); await Promise.all(n.map((r) => j.rename(N.join(e, r), N.join(t, r)))), await j.rmdir(e); } catch (n) { throw console.error("Error moving browser files:", n), n; } } async function _t(e, t) { try { const n = "./dist"; if (t.skipFrameworkBuild) { await j.mkdir(n, { recursive: !0 }); return; } const r = await $(); await h(`${r} run build ${r === "npm" ? "--" : ""} --output-path=${n}`, { scope: "Angular", verbose: !0 }); const i = N.join(process.cwd(), n, "browser"); try { await j.access(i), await bt(i, N.join(process.cwd(), n)); } catch { } } catch (n) { throw new Error(`Error during Angular prebuild: ${n instanceof Error ? n.message : String(n)}`); } } const xa = { config: ht, metadata: xe, handler: Et, prebuild: _t }, vt = { build: { bundler: "esbuild" }, storage: [ { name: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX", dir: "./dist", workloadsAccess: "read_only" } ], connectors: [ { name: "$CONNECTOR_NAME", active: !0, type: "storage", attributes: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } ], applications: [ { name: "$APPLICATION_NAME", cache: [ { name: "$APPLICATION_NAME", browser: { maxAgeSeconds: 7200 }, edge: { maxAgeSeconds: 7200 } } ], rules: v({ connector: "$CONNECTOR_NAME", application: "$APPLICATION_NAME" }) } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, Se = { name: "astro", registry: "astro" }, Ct = { /** * Handles the 'fetch' event using Azion Workers pattern. * @param {Request} request - The request object with metadata. * @param {Object} env - The environment context containing Azion services. * @param {Object} ctx - The execution context. * @returns {Promise<Response>} The response for the request. */ fetch: async (e) => { try { return await y(e.url); } catch (t) { return new Response( JSON.stringify({ error: `Failed to mount ${Se.name} application`, message: t instanceof Error ? t.message : "Unknown error occurred", path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }, Pt = ["astro.config.ts", "astro.config.mjs", "astro.config.js", "astro.config.cjs"]; async function Tt() { for (const e of Pt) try { await _e(e, st.F_OK); const n = (await w(e, "utf-8")).match(/outDir\s*:\s*['"`]([^'"`]+)['"`]/); if (n && n[1]) return n[1].trim(); break; } catch { continue; } return "dist"; } async function Ot(e, t) { try { const [n, r] = await Promise.all([$(), Tt()]); if (t.skipFrameworkBuild) { await A(r, { recursive: !0 }); return; } await h(`${n} run build`, { scope: "Astro", verbose: !0 }); } catch (n) { throw new Error(`Error during Astro prebuild: ${n instanceof Error ? n.message : String(n)}`); } } const Ma = { config: vt, metadata: Se, handler: Ct, prebuild: Ot }, xt = { build: { bundler: "esbuild" }, storage: [ { name: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX", dir: "./build", workloadsAccess: "read_only" } ], connectors: [ { name: "$CONNECTOR_NAME", active: !0, type: "storage", attributes: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } ], applications: [ { name: "$APPLICATION_NAME", cache: [ { name: "$APPLICATION_NAME", browser: { maxAgeSeconds: 7200 }, edge: { maxAgeSeconds: 7200 } } ], rules: v({ connector: "$CONNECTOR_NAME", application: "$APPLICATION_NAME" }) } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, Fe = { name: "docusaurus" }, Mt = { /** * Handles the 'fetch' event using Azion Workers pattern. * @param {Request} request - The request object with metadata. * @param {Object} env - The environment context containing Azion services. * @param {Object} ctx - The execution context. * @returns {Promise<Response>} The response for the request. */ fetch: async (e) => { try { return await y(e.url); } catch (t) { return new Response( JSON.stringify({ error: `Failed to mount ${Fe.name} application`, message: t instanceof Error ? t.message : "Unknown error occurred", path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }; async function It(e, t) { const n = await $(), r = "build"; if (t.skipFrameworkBuild) { await A(r, { recursive: !0 }); return; } await h(`${n} run build`, { scope: "Docusaurus", verbose: !0 }); } const Ia = { config: xt, metadata: Fe, handler: Mt, prebuild: It }, Rt = { build: { bundler: "esbuild" }, storage: [ { name: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX", dir: "./_site", workloadsAccess: "read_only" } ], connectors: [ { name: "$CONNECTOR_NAME", active: !0, type: "storage", attributes: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } ], applications: [ { name: "$APPLICATION_NAME", cache: [ { name: "$APPLICATION_NAME", browser: { maxAgeSeconds: 7200 }, edge: { maxAgeSeconds: 7200 } } ], rules: v({ connector: "$CONNECTOR_NAME", application: "$APPLICATION_NAME" }) } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, je = { name: "eleventy" }, St = { /** * Handles the 'fetch' event using Azion Workers pattern. * @param {Request} request - The request object with metadata. * @param {Object} env - The environment context containing Azion services. * @param {Object} ctx - The execution context. * @returns {Promise<Response>} The response for the request. */ fetch: async (e) => { try { return await y(e.url); } catch (t) { return new Response( JSON.stringify({ error: `Failed to mount ${je.name} application`, message: t instanceof Error ? t.message : "Unknown error occurred", path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }; async function Ft(e, t) { const n = "_site"; if (t.skipFrameworkBuild) { await A(n, { recursive: !0 }); return; } await h("npx -y @11ty/eleventy", { scope: "Eleventy", verbose: !0 }); } const Ra = { config: Rt, metadata: je, handler: St, prebuild: Ft }, jt = { build: { entry: "handler.js", bundler: "webpack", polyfills: !1, extend: (e) => (e = { ...e, optimization: { minimize: !1 }, performance: { maxEntrypointSize: 2097152, maxAssetSize: 2097152 }, module: { rules: [ { test: /\.wasm$/, type: "asset/inline" } ] }, plugins: [ new pt.optimize.LimitChunkCountPlugin({ maxChunks: 1 }) ] }, e) }, functions: [ { name: "$FUNCTION_NAME", path: "./functions/handler.js" } ], applications: [ { name: "$APPLICATION_NAME", rules: { request: [ { name: "Execute Function", description: "Execute function for all requests", active: !0, criteria: [ [ { variable: "${uri}", conditional: "if", operator: "matches", argument: "^/" } ] ], behaviors: [ { type: "run_function", attributes: { value: "$FUNCTION_NAME" } } ] } ] }, functionsInstances: [ { name: "$FUNCTION_INSTANCE_NAME", ref: "$FUNCTION_NAME" } ] } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, ke = { name: "emscripten" }; let H = null; const kt = { /** * Handles the 'fetch' event using Emscripten WASM. * @param {Request} request - The request object with metadata. * @param {Object} env - The environment context containing Azion services. * @param {Object} ctx - The execution context. * @returns {Promise<Response>} The response for the request. */ fetch: async (e) => { try { H || (H = new Promise((r) => { import("./presets/emscripten/build/module").then( (a) => { r({ fetch_listener: a.cwrap("fetch_listener", "string", ["object"]), module: a }); } ); })); const n = await (await H).fetch_listener(e); return new Response(n); } catch (t) { return new Response( JSON.stringify({ error: `Failed to mount ${ke.name} application`, message: t instanceof Error ? t.message : String(t), path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }; async function Dt() { const r = `'["cwrap", "setValue"]'`, a = `'["_fetch_listener"]'`, l = '"createModule"', p = "./build/module", m = "./src/main.cpp", E = "-lembind"; await A("./build", { recursive: !0 }); const b = [ "emcc", "-O2", "-s WASM=1", "-s ASYNCIFY=1", `-s EXPORTED_RUNTIME_METHODS=${r}`, `-s EXPORTED_FUNCTIONS=${a}`, "-s ALLOW_MEMORY_GROWTH=1", "-s DYNAMIC_EXECUTION=0", "-s TEXTDECODER=0", "-s MODULARIZE=1", "-s ENVIRONMENT=web", `-s EXPORT_NAME="${l}"`, "-s SINGLE_FILE=1", E, `-o ${p}`, m ].join(" "); await h(b, { scope: "Emscripten", verbose: !0 }); } const Sa = { config: jt, metadata: ke, handler: kt, prebuild: Dt }, Lt = { build: { bundler: "esbuild" }, storage: [ { name: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX", dir: "./public", workloadsAccess: "read_only" } ], connectors: [ { name: "$CONNECTOR_NAME", active: !0, type: "storage", attributes: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } ], applications: [ { name: "$APPLICATION_NAME", cache: [ { name: "$APPLICATION_NAME", browser: { maxAgeSeconds: 7200 }, edge: { maxAgeSeconds: 7200 } } ], rules: v({ connector: "$CONNECTOR_NAME", application: "$APPLICATION_NAME" }) } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, De = { name: "gatsby" }, Ut = { fetch: async (e) => { try { return await y(e.url); } catch (t) { return new Response( JSON.stringify({ error: `Failed to mount ${De.name} application`, message: t instanceof Error ? t.message : "Unknown error occurred", path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }; async function Bt(e, t) { const n = await $(), r = "public"; if (t.skipFrameworkBuild) { await A(r, { recursive: !0 }); return; } await h(`${n} run build`, { scope: "Gatsby", verbose: !0 }); } const Fa = { config: Lt, metadata: De, handler: Ut, prebuild: Bt }, Kt = { build: { bundler: "esbuild" }, storage: [ { name: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX", dir: "./public", workloadsAccess: "read_only" } ], connectors: [ { name: "$CONNECTOR_NAME", active: !0, type: "storage", attributes: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } ], applications: [ { name: "$APPLICATION_NAME", cache: [ { name: "$APPLICATION_NAME", browser: { maxAgeSeconds: 7200 }, edge: { maxAgeSeconds: 7200 } } ], rules: v({ connector: "$CONNECTOR_NAME", application: "$APPLICATION_NAME" }) } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, Le = { name: "hexo" }, zt = { /** * Handles the 'fetch' event using Azion Workers pattern. * @param {Request} request - The request object with metadata. * @param {Object} env - The environment context containing Azion services. * @param {Object} ctx - The execution context. * @returns {Promise<Response>} The response for the request. */ fetch: async (e) => { try { return await y(e.url); } catch (t) { return new Response( JSON.stringify({ error: `Failed to mount ${Le.name} application`, message: t instanceof Error ? t.message : "Unknown error occurred", path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }; async function Wt(e, t) { const n = await $(); let r = "public"; if (t.skipFrameworkBuild) { await A(r, { recursive: !0 }); return; } const a = await w("./_config.yml", "utf-8"), i = Array.from(a.matchAll(/public_dir:(.*)\n/g), (o) => o)[0]; i && (r = i[1].trim().replace(/["']/g, "")), await h(`${n === "npm" ? "npx" : n} hexo generate`, { scope: "Hexo", verbose: !0 }); } const ja = { config: Kt, metadata: Le, handler: zt, prebuild: Wt }, Vt = { build: { bundler: "esbuild" }, storage: [ { name: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX", dir: "./www", workloadsAccess: "read_only" } ], connectors: [ { name: "$CONNECTOR_NAME", active: !0, type: "storage", attributes: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } ], applications: [ { name: "$APPLICATION_NAME", cache: [ { name: "$APPLICATION_NAME", browser: { maxAgeSeconds: 7200 }, edge: { maxAgeSeconds: 7200 } } ], rules: v({ connector: "$CONNECTOR_NAME", application: "$APPLICATION_NAME" }) } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, Ue = { name: "html" }, Xt = { /** * Handles the 'fetch' event using Azion Workers pattern. * @param {Request} request - The request object with metadata. * @param {Object} env - The environment context containing Azion services. * @param {Object} ctx - The execution context. * @returns {Promise<Response>} The response for the request. */ fetch: async (e) => { try { return await y(e.url); } catch (t) { return new Response( JSON.stringify({ error: `Failed to mount ${Ue.name} application`, message: t instanceof Error ? t.message : "Unknown error occurred", path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }, ka = { config: Vt, metadata: Ue, handler: Xt }, Jt = { build: { bundler: "esbuild" }, storage: [ { name: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX", dir: "./public", workloadsAccess: "read_only" } ], connectors: [ { name: "$CONNECTOR_NAME", active: !0, type: "storage", attributes: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } ], applications: [ { name: "$APPLICATION_NAME", cache: [ { name: "$APPLICATION_NAME", browser: { maxAgeSeconds: 7200 }, edge: { maxAgeSeconds: 7200 } } ], rules: v({ connector: "$CONNECTOR_NAME", application: "$APPLICATION_NAME" }) } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, Be = { name: "hugo" }, Ht = { /** * Handles the 'fetch' event using Azion Workers pattern. * @param {Request} request - The request object with metadata. * @param {Object} env - The environment context containing Azion services. * @param {Object} ctx - The execution context. * @returns {Promise<Response>} The response for the request. */ fetch: async (e) => { try { return await y(e.url); } catch (t) { return new Response( JSON.stringify({ error: `Failed to mount ${Be.name} application`, message: t instanceof Error ? t.message : "Unknown error occurred", path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }; async function qt(e, t) { const n = await $(), r = "public"; if (t.skipFrameworkBuild) { await A(r, { recursive: !0 }); return; } await h(`${n === "npm" ? "npx" : n} hugo`, { scope: "Hugo", verbose: !0 }); } const Da = { config: Jt, metadata: Be, handler: Ht, prebuild: qt }, Yt = { build: { entry: "index.js" }, functions: [ { name: "$FUNCTION_NAME", path: "./functions/index.js" // path to the edge function. This path is relative to the .edge folder. } ], applications: [ { name: "$APPLICATION_NAME", rules: { request: [ { name: "Execute Function", description: "Execute function for all requests", active: !0, criteria: [ [ { variable: "${uri}", conditional: "if", operator: "matches", argument: "^/" } ] ], behaviors: [ { type: "run_function", attributes: { value: "$FUNCTION_NAME" } } ] } ] }, functionsInstances: [ { name: "$FUNCTION_INSTANCE_NAME", ref: "$FUNCTION_NAME" } ] } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, Gt = { name: "javascript", ext: "js" }, La = { config: Yt, metadata: Gt }, Zt = { build: { bundler: "esbuild" }, storage: [ { name: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX", dir: "./_site", workloadsAccess: "read_only" } ], connectors: [ { name: "$CONNECTOR_NAME", active: !0, type: "storage", attributes: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } ], applications: [ { name: "$APPLICATION_NAME", cache: [ { name: "$APPLICATION_NAME", browser: { maxAgeSeconds: 7200 }, edge: { maxAgeSeconds: 7200 } } ], rules: v({ connector: "$CONNECTOR_NAME", application: "$APPLICATION_NAME" }) } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }, Ke = { name: "jekyll", registry: "jekyll" }, Qt = { /** * Handles the 'fetch' event using Azion Workers pattern. * @param {Request} request - The request object with metadata. * @param {Object} env - The environment context containing Azion services. * @param {Object} ctx - The execution context. * @returns {Promise<Response>} The response for the request. */ fetch: async (e) => { try { return await y(e.url); } catch (t) { return new Response( JSON.stringify({ error: `Failed to mount ${Ke.name} application`, message: t instanceof Error ? t.message : "Unknown error occurred", path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }; async function en(e, t) { const n = "_site"; if (t.skipFrameworkBuild) { await A(n, { recursive: !0 }); return; } await h("bundle install && bundle exec jekyll build", { scope: "Jekyll", verbose: !0 }); } const Ua = { config: Zt, metadata: Ke, handler: Qt, prebuild: en }, tn = { build: { bundler: "esbuild", polyfills: !0 }, storage: [ { name: "$BUCKET_NAME", dir: ".edge/next-build-assets", workloadsAccess: "read_only", prefix: "$BUCKET_PREFIX" } ], connectors: [ { name: "$CONNECTOR_NAME", active: !0, type: "storage", attributes: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } ], functions: [ { name: "$FUNCTION_NAME", path: "./functions/handler.js", bindings: { storage: { bucket: "$BUCKET_NAME", prefix: "$BUCKET_PREFIX" } } } ], applications: [ { name: "$APPLICATION_NAME", cache: [ { name: "$APPLICATION_NAME", browser: { maxAgeSeconds: 7200 }, edge: { maxAgeSeconds: 7200 } } ], rules: { request: [ { name: "Next.js Static Assets and set cache policy", description: "Serve Next.js static assets through edge connector and set cache policy", active: !0, criteria: [ [ { variable: "${uri}", conditional: "if", operator: "matches", argument: "^/_next/static/" } ] ], behaviors: [ { type: "set_connector", attributes: { value: "$CONNECTOR_NAME" } }, { type: "set_cache_policy", attributes: { value: "$APPLICATION_NAME" } }, { type: "deliver" } ] }, { name: "Deliver Static Assets and set cache policy", description: "Serve static assets through edge connector and set cache policy", active: !0, criteria: [ [ { variable: "${uri}", conditional: "if", operator: "matches", argument: ".(css|js|ttf|woff|woff2|pdf|svg|jpg|jpeg|gif|bmp|png|ico|mp4|json|xml|html)$" } ] ], behaviors: [ { type: "set_connector", attributes: { value: "$CONNECTOR_NAME" } }, { type: "set_cache_policy", attributes: { value: "$APPLICATION_NAME" } }, { type: "deliver" } ] }, { name: "Execute Next.js Function", description: "Execute Next.js edge function for all requests", active: !0, criteria: [ [ { variable: "${uri}", conditional: "if", operator: "matches", argument: "^/" } ] ], behaviors: [ { type: "run_function", attributes: { value: "$FUNCTION_NAME" } }, { type: "forward_cookies" } ] } ] }, functionsInstances: [ { name: "$FUNCTION_INSTANCE_NAME", ref: "$FUNCTION_NAME" } ] } ], workloads: [ { name: "$WORKLOAD_NAME", active: !0, infrastructure: 1, deployments: [ { name: "$DEPLOYMENT_NAME", current: !0, active: !0, strategy: { type: "default", attributes: { application: "$APPLICATION_NAME" } } } ] } ] }; function Ba(e, t, n) { const r = n ? "" : "i", a = []; return { match: ft(`%${e}%${r}`, a).exec(t), captureGroupKeys: a }; } function nn(e, t, n) { return e.replace(/\$([a-zA-Z0-9]+)/g, (a, i) => { const s = n.indexOf(i); return (s === -1 ? t[parseInt(i, 10)] : t[s + 1]) || ""; }).replace(/^(\/)+/, "/"); } function rn(e, t, n) { const r = t instanceof Headers ? t.entries() : Object.entries(t); for (const [a, i] of r) { const s = a.toLowerCase(), o = n?.match ? nn(i, n.match, n.captureGroupKeys) : i; s === "set-cookie" ? e.append(s, o) : e.set(s, o); } } function Ka(e) { return /^https?:\/\//.test(e); } function an(e, t) { for (const [n, r] of t.entries()) if (!e.has(n) || r) { e.set(n, r); const a = /^nxtP(.+)$/.exec(n); a?.[1] && !e.has(a[1]) && e.set(a[1], r); } } function za(e, t) { const n = new URL(t, e.url); return an(n.searchParams, new URL(e.url).searchParams), new Request(n, e); } function sn(e) { return new Response(e.body, e); } function Wa(e) { return e.split(",").map((t) => { const [n, r] = t.split(";"), a = parseFloat((r ?? "q=1").replace(/q *= */gi, "")); return [n.trim(), Number.isNaN(a) ? 1 : a]; }).sort((t, n) => n[1] - t[1]).map(([t]) => t === "*" || t === "" ? [] : t).flat(); } function on(e) { const t = new Headers(e.headers); return e.cf && (t.append("x-vercel-ip-city", "request.cf.city"), t.append("x-vercel-ip-country", "request.cf.country"), t.append("x-vercel-ip-country-region", "request.cf.region"), t.append("x-vercel-ip-latitude", "request.cf.latitude"), t.append("x-vercel-ip-longitude", "request.cf.longitude")), new Request(e, { headers: t }); } function cn(e, { protocol: t, hostname: n, port: r, pathname: a }) { return !(t && e.protocol.replace(/:$/, "") !== t || !new RegExp(n).test(e.hostname) || r && !new RegExp(r).test(e.port) || a && !new RegExp(a).test(e.pathname)); } function un(e, t) { if (e.method !== "GET") return; const { origin: n, searchParams: r } = new URL(e.url), a = r.get("url"), i = Number.parseInt(r.get("w") ?? "", 10), s = Number.parseInt(r.get("q") ?? "75", 10); if (!a || Number.isNaN(i) || Number.isNaN(s) || !t?.sizes?.includes(i) || s < 0 || s > 100) return; const o = new URL(a, n); if (o.pathname.endsWith(".svg") && !t?.dangerouslyAllowSVG) return; const c = a.startsWith("/") || a.startsWith("%2F"); if ( // Relative URL means same origin as deployment and is allowed. !c && // External image URL must be allowed by domains or remote patterns. !t?.domains?.includes(o.hostname) && !t?.remotePatterns?.find((d) => cn(o, d)) ) return; const u = e.headers.get("Accept") ?? "", l = t?.formats?.find((d) => u.includes(d))?.replace("image/", ""); return { isRelative: c, imageUrl: o, options: { width: i, quality: s, format: l } }; } function ln(e, t, n) { const r = new Headers(); if (n?.contentSecurityPolicy && r.set("Content-Security-Policy", n.contentSecurityPolicy), n?.contentDispositionType) { const i = t.pathname.split("/").pop(), s = i ? `${n.contentDispositionType}; filename="${i}"` : n.contentDispositionType; r.set("Content-Disposition", s); } e.headers.has("Cache-Control") || r.set("Cache-Control", `public, max-age=${n?.minimumCacheTTL ?? 60}`); const a = sn(e); return rn(a.headers, r), a; } async function dn(e, { buildOutput: t, assetsFetcher: n, imagesConfig: r }) { const a = un(e, r); if (!a) return new Response("Invalid image resizing request", { status: 400 }); const { isRelative: i, imageUrl: s } = a, o = new Request(s, { headers: e.headers }), c = i && s.pathname in t ? await n.fetch(o) : await fetch(o); return ln(c, s, r); } const pn = { fetch: async (e) => { try { return await y(e.url); } catch (t) { return new Response( JSON.stringify({ error: "Failed to mount Next.js application", message: t instanceof Error ? t.message : "Unknown error occurred", path: e.url }), { status: 500, headers: { "Content-Type": "application/json" } } ); } } }, fn = async (e) => { try { const t = new URL(e.url).pathname, n = new URL(t === "/" ? "index.html" : t, "file://"); return fetch(n); } catch (t) { return new Response(t.message || t.toString(), { status: 500 }); } }; async function mn(e, t, n) { const r = new AsyncLocalStorage(); return globalThis.process.env = { ...globalThis.process.env, ...t }, r.run({ ...t }, async () => { if (new URL(e.url).pathname.startsWith("/_next/image")) return dn(e, { // @ts-expect-error - Ignore TS error because this file is not compiled buildOutput: __BUILD_OUTPUT__, assetsFetcher: t.ASSETS, // @ts-expect-error - Ignore TS error because this file is not compiled imagesConfig: __CONFIG__.images }); const i = on(e); return (await import("./index-Cn3EVFBu.js")).handleRequest( { request: i, ctx: n, assetsFetcher: t.ASSETS }, // @ts-expect-error - Ignore TS error because this file is not compiled __CONFIG__, // @ts-expect-error - Ignore TS error because this file is not compiled __BUILD_OUTPUT__, // @ts-expect-error - Ignore TS error because this file is not compiled __BUILD_METADATA__ ); }); } async function gn(e, t) { const n = { ASSETS: { fetch: fn } }, r = { waitUntil: t.waitUntil.bind(t), passThroughOnException: () => null }, a = new URL(decodeURI(e.url)), i = new Request(a, e); return mn(i, n, r); } async function hn(e, t, n) { return globalThis.bundler?.nextBuildStatic ? pn.fetch(e) : gn(e, n); } const En = { fetch: hn }, Nn = { name: "next", registry: "next" }; async function An(e, t) { const n = /Object\.defineProperty\(\s*globalThis\s*,\s*"__import_unsupported"[\s\S]*?,\s*configurable\s*:\s*[^}]*\}\)/gm, r = "true", a = e.entry; for (const i of Object.keys(a)) try { const s = i.endsWith(".js") ? i : `${i}.js`, o = I(s), u = L(o, "utf-8").replace(n, r); V(o, u); } catch (s) { throw new Error(`Failed to process file ${i}: ${s}`); } } function yn() { const e = g(".vercel", "output", "static", "_next", "__private"); be(e, { force: !0, recursive: !0 }); } function $n() { try { const e = ".vercel", t = `${e}/project.json`; M(t) || (M(e) || Q(e), V(t, '{"projectId":"_","orgId":"_","settings":{}}')); } catch (e) { throw new Error(e.message); } } async function wn() { await new Promise((e, t) => { const n = ["npx", "--yes", "vercel@32.6.1", "build", "--prod"], r = n.shift(), a = ct.spawn(r, n, { shell: !0, stdio: "inherit" }); a.on("close", (i) => { i === 0 ? e() : t(new Error(`Command '${n.join(" ")}' failed with code ${i}`)); }), a.on("exit", (i) => { i === 0 ? e() : t(new Error(`Command '${n.join(" ")}' failed with code ${i}`)); }); }); } function bn() { try { const e = L(".vercel/output/config.json", "utf8"); return JSON.parse(e); } catch (e) { throw new Error(e.message); } } const ze = { deleteTelemetryFiles: yn, createVercelProjectConfig: $n, runVercelBuild: wn, loadVercelConfigs: bn }; async function We() { const e = g(process.cwd(), "next.config.js"); let t = null; try { t = (await import(e)).default; } catch { f.prebuild.info("Configuration file ('next.config.js') not found."); } return t; } function _n(e, t) { let n = !1; return t && t?.length > 0 && t.forEach((r) => { (e.includes(`/${r}/`) || e.includes(`/${r}.func/`)) && (n = !0); }), n; } function vn(e) { const t = []; function n(r, a) { if (r !== "node_modules") for (const i of ee(r, { withFileTypes: !0 })) i.isDirectory() ? n(g(r, i.name), a) : i.isFile() && a.push(g(r, i.name)); } return n(e, t), t; } function Cn(e) { const t = []; return vn(e).forEach((r) => { t.push(`/${te(e, r)}`); }), t; } function U(e) { return e.startsWith("\\\\?\\") ? e : e.replace(/\\/g, "/"); } async function Pn(e) { let t = null; try { const n = await w(e, "utf8"); t = JSON.parse(n); } catch { t = null; } return t; } async function Tn(e, t) { try { const n = await ve(e); if (t === "file" && n.isFile()) return !0; t === "directory" && n.isDirectory(); } catch { } return !1; } function ae(e) { return Tn(e, "file"); } async function On(e, t) { await A(ne