azion
Version:
Azion Packages for Edge Computing.
891 lines (890 loc) • 26.8 kB
JavaScript
import * as ne from "esbuild";
import { flow as j } from "lodash-es";
import y from "webpack";
import f, { readFileSync as oe } from "fs";
import c from "path";
import X from "signale";
import { createRequire as x } from "module";
import { fileURLToPath as se } from "url";
import { builtinModules as re } from "node:module";
import { defineEnv as H } from "unenv";
const B = `
/**
* Built with Azion CLI
* For more information, visit: https://www.azion.com/en/documentation/products/cli/
*/
`, ie = `
/**
* WARNING: DEVELOPMENT BUILD
*
* This file is a development build and contains additional injected code
* to facilitate the development and debugging process.
*
* IMPORTANT NOTICES:
* - DO NOT use this build in a production environment.
* - The injected code may cause unexpected behaviors in production.
* - Performance of this build is not optimized for production use.
* - This build may include sensitive debugging information.
*
* To generate an optimized and secure production build use 'azion build'.
*
* If you are seeing this message in a production environment, stop immediately
* and replace this file with a proper production build.
*
* For any issues or questions, please refer to the documentation or contact
* the development team.
*/
`, J = (e) => {
const t = e;
return {
applyPolyfills: (n) => (o) => (i) => i.polyfills ? M(t.NodePolyfillsPlugin) ? (o.plugins = [
...o.plugins || [],
new t.NodePolyfillsPlugin(n.production),
new t.BabelCustomLoaderPlugin(
i.preset.metadata.name,
["next"]
)
], o) : (o.plugins = [
...o.plugins || [],
t.NodePolyfillsPlugin(n.production),
// Add optional chaining assignment plugin if available (esbuild only)
..."OptionalChainingAssignmentPlugin" in t ? (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[t.OptionalChainingAssignmentPlugin()]
) : [],
// Add sanitize worker plugin if available (esbuild only)
..."SanitizeWorker" in t ? [
// eslint-disable-next-line @typescript-eslint/no-explicit-any
t.SanitizeWorker(process.env.AZ_ENABLE_SANITIZE_WORKER ?? !1, {
options: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
outfile: o.outfile
}
})
] : []
], o) : o,
applyAzionModule: (n) => (o) => (o.plugins = [
...o.plugins || [],
M(t.AzionPolyfillsPlugin) ? new t.AzionPolyfillsPlugin(n.production) : t.AzionPolyfillsPlugin(n.production)
], o)
};
};
function M(e) {
return "prototype" in e;
}
const G = (e, t) => (r = {}) => r ? t === "esbuild" ? (e.define = {
...e.define,
...r
}, e) : (e.plugins = [
...e.plugins || [],
new y.DefinePlugin(r)
], e) : e, K = (e) => e.production ? B : `${B}${ie}`, Z = (e) => (t) => t === void 0 ? e : t(e), le = {
bundle: !0,
format: "esm",
platform: "browser",
mainFields: ["browser", "module", "main"],
target: "es2022",
keepNames: !0,
allowOverwrite: !0,
loader: {
".js": "js"
},
outdir: "."
}, Q = process.env.CLEAN_OUTPUT_MODE === "true", ee = {
displayScope: !1,
displayBadge: !1,
displayDate: !1,
displayFilename: !1,
displayLabel: !1,
displayTimestamp: !1,
underlineLabel: !1,
underlineMessage: !1,
underlinePrefix: !1,
underlineSuffix: !1,
uppercaseLabel: !1
}, g = (e = {}) => {
const t = new X.Signale({ ...e });
return Q && t.config(ee), Object.assign(t, {
breakInteractiveChain: () => console.log()
});
}, h = {
deployed: {
badge: "🚀",
color: "green",
label: "forged",
logLevel: "info"
},
option: {
badge: "📦",
color: "green",
label: "",
logLevel: "info"
}
}, m = (e = "Azion") => new X.Signale({
interactive: !1,
scope: e,
types: h
});
Q && m().config(ee);
const ae = (e = "Azion") => ({
...m(e),
interactive: {
...g({
interactive: !0,
scope: [e],
types: h
})
},
server: {
...m(e).scope(e, "Server"),
interactive: g({
interactive: !0,
scope: [e, "Server"],
types: h
})
},
runtime: {
...m(e).scope(e, "Runtime"),
interactive: g({
interactive: !0,
scope: [e, "Runtime"],
types: h
})
},
prebuild: {
...m(e).scope(e, "Pre-Build"),
interactive: g({
interactive: !0,
scope: [e, "Pre-Build"],
types: h
})
},
build: {
...m(e).scope(e, "Build"),
interactive: g({
interactive: !0,
scope: [e, "Build"],
types: h
})
},
postbuild: {
...m(e).scope(e, "Post-Build"),
interactive: g({
interactive: !0,
scope: [e, "Post-build"],
types: h
})
},
storage: {
...m(e).scope(e, "Storage"),
interactive: g({
interactive: !0,
scope: [e, "Storage"],
types: h
})
},
bindings: {
...m(e).scope(e, "Bindings"),
interactive: g({
interactive: !0,
scope: [e, "Bindings"],
types: h
})
},
manifest: {
...m(e).scope(e, "IaC"),
interactive: g({
interactive: !0,
scope: [e, "IaC"],
types: h
})
}
});
({
...ae()
});
const k = process.platform === "win32";
function z(e = import.meta.url, t = "bundler") {
const r = new RegExp(`(.*${t})(.*)`), s = e.match(r);
let n = s ? s[1] : "";
if (e.includes("edge-functions") && t === "bundler") {
const o = new RegExp("(.*edge-functions)(.*)"), i = e.match(o);
n = i ? i[1] : n;
}
return k && (n = new URL(n).pathname, n.startsWith("/") && (n = n.slice(1))), k || (n = n.replace("file://", "")), n;
}
const pe = () => c.resolve(z(import.meta.url, "bundler"), "src"), E = `${pe()}/polyfills/azion`, P = {
external: /* @__PURE__ */ new Map([
["azion:storage", `${E}/storage/storage.polyfills.js`],
["Azion.env", `${E}/env-vars/env-vars.polyfills.js`],
["Azion.networkList", `${E}/network-list/network-list.polyfills.js`],
["Azion.Storage", `${E}/storage/storage.polyfills.js`],
["Azion.KV", `${E}/kv/kv.polyfills.js`]
])
}, ue = (e) => {
const t = "bundler-azion-modules-polyfills", r = t, s = /^azion:/, n = "azion:";
return {
/**
* Name and setup of the ESBuild plugin.
* @param {object} build - ESBuild build object.
*/
name: t,
setup: (o) => {
const i = o.initialOptions;
e && (i.external = i.external || [], [...P.external].forEach(([l]) => {
i.external = i.external || [], /^[^:]+:/.test(l) && !i.external.includes(l) && i.external.push(l);
})), e || (i.inject = i.inject || [], P.external && [...P.external].forEach(([l, a]) => {
!/^[^:]+:/.test(l) && l?.toLowerCase()?.includes(n.replace(":", "")) && (i.inject = i.inject || [], i.inject.push(a));
})), o.onResolve({ filter: s }, async (l) => {
if (!e && P.external.has(l.path))
return {
path: l.path,
namespace: r
};
if (P.external.has(l.path) && !(Array.isArray(i?.external) && i.external.includes(l.path)))
return {
path: l.path,
namespace: r
};
}), o.onLoad({ filter: s, namespace: r }, async (l) => {
if (!P.external.has(l.path))
return;
const a = P.external.get(l.path);
if (!a)
throw new Error(`Could not resolve module: ${l.path}`);
const p = await f.promises.readFile(a, "utf8"), u = c.dirname(a);
return {
loader: "js",
contents: p,
resolveDir: u
};
});
}
};
}, $ = x(import.meta.url), ce = () => ({
name: "babel-custom-loader",
setup(t) {
t.onLoad({ filter: /\.func\.m?js$/ }, async (r) => {
const s = await f.promises.readFile(r.path, "utf8");
if (!s.includes("?.") || !/\?\.\s*\w+\s*=/.test(s))
return null;
try {
const o = $("@babel/core").transformSync(s, {
filename: r.path,
plugins: [[$("@babel/plugin-proposal-optional-chaining-assign"), { version: "2023-07" }]],
compact: !1,
sourceMaps: !1
});
if (o?.code && o.code !== s)
return {
contents: o.code,
loader: "js"
};
} catch (n) {
console.warn(`Babel custom loader failed for ${r.path}:`, n);
}
return null;
}), t.onLoad({ filter: /\.ts$/, namespace: "babel-custom" }, async (r) => {
const s = await f.promises.readFile(r.path, "utf8");
try {
const o = $("@babel/core").transformSync(s, {
filename: r.path,
compact: !1,
presets: [
[
$("@babel/preset-env"),
{
targets: {
node: "current"
}
}
],
$("@babel/preset-typescript")
]
});
if (o?.code)
return {
contents: o.code,
loader: "js"
};
} catch (n) {
console.warn(`Babel TypeScript transform failed for ${r.path}:`, n);
}
return null;
});
}
}), de = se(import.meta.url), fe = c.dirname(de), he = () => c.resolve(fe, "../../", "unenv-preset", "src"), d = `${he()}/polyfills`, te = {
inject: {
__dirname: `${d}/node/globals/path-dirname.js`,
__filename: `${d}/node/globals/path-filename.js`,
process: `${d}/node/globals/process.cjs`,
performance: "unenv/polyfill/performance",
setInterval: `${d}/node/globals/set-interval.js`,
clearInterval: `${d}/node/globals/clear-interval.js`,
console: `${d}/node/globals/console.js`,
asyncStorage: `${d}/node/globals/async-storage.js`,
dateToString: `${d}/node/globals/date-to-string.js`
},
alias: {
"azion/utils": "azion/utils",
"azion/utils/edge": "azion/utils/edge",
"azion/utils/node": "azion/utils/node",
"@fastly/http-compute-js": "@fastly/http-compute-js",
accepts: "accepts",
assert: "assert-browserify",
buffer: `${d}/node/buffer.js`,
https: `${d}/node/https.js`,
module: `${d}/node/module.js`,
string_decoder: "string_decoder/lib/string_decoder.js",
timers: "timers-browserify/",
util: `${d}/node/util.js`,
zlib: `${d}/node/zlib.js`
},
external: ["node:async_hooks", "node:fs/promises", "node:stream", "node:crypto"],
polyfill: [
"aziondev:async_hooks:/async-hooks/async-hooks.polyfills.js",
"aziondev:fs:/fs/fs.polyfills.js",
"aziondev:fs/promises:/fs/promises/promises.polyfills.js",
"aziondev:stream:/stream/stream.polyfills.js",
"aziondev:crypto:/crypto/crypto.polyfills.js",
"azionprd:fs:/fs.js"
]
}, me = (e, t) => `${c.join(z(import.meta.url, "bundler"), e)}${t ? `${t}` : ""}`, Pe = { getAbsolutePath: me }, T = x(import.meta.url), { env: ge } = H({
nodeCompat: !0,
resolve: !1,
overrides: {
...te
}
}), { alias: R, inject: U, polyfill: D, external: W } = ge;
function ye(e) {
if (typeof e == "string")
return {
importStatement: `import globalVar from "${e}";`,
exportName: "globalVar"
};
if (Array.isArray(e) && e.length === 2) {
const [t, r] = e;
return {
importStatement: `import { ${r} } from "${t}";`,
exportName: r
};
}
throw new Error(`Invalid global inject value: ${e}`);
}
function be(e) {
const t = "imported-unenv-alias", r = {};
Object.entries(R).forEach(([n, o]) => {
try {
const i = o.startsWith("unenv/"), l = T.resolve(o);
r[n] = i ? l.replace(/\.cjs$/, ".mjs") : l.replace(/\.cjs$/, ".js");
} catch (i) {
i instanceof Error && console.log(i.message);
}
});
const s = new RegExp(`^(${Object.keys(r).join("|")})$`);
e.onResolve({ filter: s }, (n) => ({
path: n.path,
namespace: t
})), e.onLoad({ filter: /.*/, namespace: t }, async (n) => {
const o = r[n.path], i = await f.promises.readFile(o, "utf8"), l = c.dirname(o);
return {
loader: "js",
contents: i,
resolveDir: l
};
});
}
function ve(e, t, r, s, n, o) {
const i = "node-built-in-modules", l = new RegExp(`^(node:)?(${re.join("|")})$`);
e.onResolve({ filter: l }, (a) => {
const p = a.path.replace("node:", ""), u = R[p] ?? R[a.path] ?? a.path, _ = (A, O) => D.find((b) => b.startsWith(`${A}${O}`)), S = (A, O, b) => {
const F = W.find((N) => N === b || N === a.path || `node:${b}` === N), C = _(A, b);
if (!C && F)
return {
path: a.path.startsWith("node:") ? a.path : `node:${a.path}`,
external: F.includes(a.path)
};
if (C)
return { path: b, namespace: O };
};
return (t ? S(r, n, p) : S(s, o, p)) ?? {
path: u,
namespace: i,
external: W.includes(a.path)
};
}), e.onLoad({ filter: /.*/, namespace: i }, async (a) => {
const p = T.resolve(a.path), u = await f.promises.readFile(p, "utf8"), _ = c.dirname(p);
return {
loader: "js",
contents: u,
resolveDir: _
};
});
}
function Ee(e, t) {
const r = /_global_polyfill-([^.]+)\.js$/, s = c.resolve(t("../"), "_global_polyfill-");
e.initialOptions.inject = [
...e.initialOptions.inject ?? [],
...Object.keys(U).map((n) => `${s}${n}.js`)
], e.onResolve({ filter: r }, (n) => ({
path: n.path
})), e.onLoad({ filter: r }, (n) => {
const o = n.path.match(r);
if (!o?.[1]) throw new Error(`Invalid global name: ${n.path}`);
const i = o[1], { importStatement: l, exportName: a } = ye(U[i]);
return {
contents: `
${l}
globalThis.${i} = ${a};
`
};
});
}
function $e(e, t, r, s) {
e.onLoad({ filter: /.*/, namespace: t }, async (n) => {
try {
const o = n.path.replace("node:", ""), i = D.find((u) => u.startsWith(`${r}${o}`));
if (!i)
throw new Error(`Polyfill not found for ${o}`);
const l = c.join(
s,
i.replace(`${r}${o}:/`, "")
), a = await f.promises.readFile(l, "utf8"), p = c.dirname(l);
return {
loader: "js",
contents: a,
resolveDir: p
};
} catch (o) {
console.error(`Error loading polyfill for ${n.path}`, o);
}
});
}
function we(e, t, r, s) {
e.onLoad({ filter: /.*/, namespace: t }, async (n) => {
try {
const o = D.find((u) => u.startsWith(`${r}${n.path}`));
if (!o)
throw new Error(`Polyfill not found for ${n.path}`);
const i = c.join(s, o.replace(`${r}${n.path}:/`, "")), l = T.resolve(i), a = await f.promises.readFile(l, "utf8"), p = c.dirname(l);
return {
loader: "js",
contents: a,
resolveDir: p
};
} catch (o) {
console.error(`Error loading polyfill prod for ${n.path}`, o);
}
});
}
function Le(e) {
if (f.existsSync(c.join(process.cwd(), ".next"))) {
const t = f.readFileSync(c.join(process.cwd(), ".next/BUILD_ID"), "utf-8");
e.define = {
...e.define,
"process.env.NEXT_RUNTIME": e.define?.["process.env.NEXT_RUNTIME"] || '"edge"',
"process.env.NEXT_COMPUTE_JS": "true",
"process.env.__NEXT_BUILD_ID": `"${t}"`
};
}
}
const je = (e) => {
const t = "bundler-node-modules-polyfills", r = "internal-env-dev", s = "internal-env-prod", n = "/polyfills", o = "/polyfills/node", i = "aziondev:", l = "azionprd:", a = (p, u) => Pe.getAbsolutePath(p, u);
return {
/**
* Name and setup of the ESBuild plugin.
* @param {object} build - ESBuild build object.
*/
name: t,
setup: (p) => {
const u = p.initialOptions;
u.define = u.define || {}, u.define?.global || (u.define.global = "globalThis"), u.define = {
...u.define,
"process.env.NODE_ENV": '"production"'
}, Le(u), u.inject = u.inject || [], u.alias = {
...u.alias
}, ve(
p,
e,
l,
i,
s,
r
), be(p), Ee(p, a), $e(
p,
r,
i,
a("src", n)
), we(
p,
s,
l,
a("../unenv-preset/src", o)
);
}
};
}, xe = (e, t) => {
const r = "sanitize-worker", s = (o) => {
let i = 0;
return { result: Array.from(o).map((p) => {
const u = p.codePointAt(0);
return u >= 65536 ? (i++, `\\u{${u.toString(16)}}`) : p;
}).join(""), escapedCount: i };
}, n = (o) => {
const i = f.readFileSync(o, "utf-8"), { result: l, escapedCount: a } = s(i);
a > 0 && (console.log(`[sanitize-worker] Escaped ${a} Unicode character(s) in ${o}`), f.writeFileSync(o, l, "utf-8"));
};
return {
name: r,
setup(o) {
o.onEnd(async (i) => {
if (!(!e || i.errors.length > 0))
if (o.initialOptions.entryPoints)
for (const l of Object.keys(o.initialOptions.entryPoints))
n(`${l}.js`);
else {
const l = t?.outfile || o.initialOptions.outfile;
l && n(l);
}
});
}
};
}, Y = J({
NodePolyfillsPlugin: je,
AzionPolyfillsPlugin: ue,
OptionalChainingAssignmentPlugin: ce,
SanitizeWorker: xe
}), _e = (e, t) => (r) => (r && (e.banner = e.banner || {}, e.banner.js = e.banner.js ? `${e.banner.js} ${r}` : r, t.production && (e.banner.js += `
// This file is generated by Azion. Do not edit it manually.
// Dynamic require is not supported in production mode.
import { createRequire as _createRequire } from "node:module";
const require = _createRequire(import.meta.url);`)), e), He = (e, t) => {
const r = e.baseOutputDir;
return {
baseConfig: {
...le,
entryPoints: typeof e.entry == "string" ? [e.entry] : e.entry,
...r ? { outdir: r } : {},
entryNames: "[dir]/[name]",
minify: t.production,
plugins: [],
banner: {
js: K(t)
}
},
mergeConfig: (n) => j([
() => Y.applyPolyfills(t)(n)(e),
() => Y.applyAzionModule(t)(n),
() => _e(n, t)(e?.setup?.contentToInject),
() => G(n, "esbuild")(e?.setup?.defineVars),
() => Z(n)(e.extend)
])(n),
applyConfig: (n) => n,
executeBuild: Ae
};
}, Ae = async (e) => {
const t = j([
() => e.mergeConfig(e.baseConfig),
() => e.applyConfig(e.baseConfig)
])(e.baseConfig);
await ne.build(t);
};
function Oe(e) {
try {
return e.map((t) => oe(t, "utf-8")).join(`
`);
} catch (t) {
throw new Error(`Failed to generate webpack banner: ${t instanceof Error ? t.message : String(t)}`);
}
}
class Ne {
buildProd;
prefix;
constructor(t) {
this.buildProd = t, this.prefix = "azion:";
}
apply(t) {
t.options.plugins?.length || (t.options.plugins = []), t.options.plugins.push(
new t.webpack.NormalModuleReplacementPlugin(new RegExp(`^${this.prefix}`), (s) => {
const n = s.request.replace(new RegExp(`^${this.prefix}`), "");
s.request = n;
})
);
const r = new Map(
[...P.external].filter(([s]) => new RegExp(`^${this.prefix}`).test(s))
);
this.buildProd || [...P.external].forEach(([s]) => {
if (!/^[^:]+:/.test(s) && s?.toLowerCase()?.includes(this.prefix.replace(":", ""))) {
const o = P.external.get(s);
if (!o)
throw new Error(`Banner content not found for key: ${s}`);
t.options.plugins?.push(
new t.webpack.BannerPlugin({
banner: Oe([o]),
raw: !0
})
);
}
}), this.buildProd ? t.options.externals = {
...Object.fromEntries(
[...r].flatMap(([s]) => [
[s, s],
[`${this.prefix}${s}`, `${this.prefix}${s}`]
])
),
...typeof t.options.externals == "object" ? t.options.externals : {}
} : (t.options.plugins?.push(
new t.webpack.NormalModuleReplacementPlugin(new RegExp(`^${this.prefix}`), (s) => {
const n = s.request.replace(new RegExp(`^${this.prefix}`), "");
s.request = n;
})
), t.options.resolve = t.options.resolve || {}, t.options.resolve.fallback = {
...Object.fromEntries(
[...r].map(([s, n]) => [
s.replace(new RegExp(`^${this.prefix}`), ""),
n
])
),
...t.options.resolve.fallback
});
}
}
const w = x(import.meta.url);
class Ie {
preset;
presetsAllowed;
constructor(t, r) {
this.preset = t || "", this.presetsAllowed = r || [];
}
apply(t) {
const r = t.options.module.rules || [];
this.presetsAllowed.includes(this.preset) && r.push({
test: /\.func.m?js$/,
exclude: /node_modules/,
use: {
loader: w.resolve("babel-loader"),
options: {
compact: !1,
plugins: [[w.resolve("@babel/plugin-proposal-optional-chaining-assign"), { version: "2023-07" }]]
}
}
}), r.push({
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: w.resolve("babel-loader"),
options: {
compact: !1,
presets: [
[
w.resolve("@babel/preset-env"),
{
targets: {
node: "current"
}
}
],
w.resolve("@babel/preset-typescript")
]
}
}
}), t.options.module.rules = r;
}
}
const I = x(import.meta.url), { env: Re } = H({
nodeCompat: !0,
resolve: !1,
overrides: {
...te
}
}), { alias: q, inject: ze, polyfill: Te, external: De } = Re;
class v {
INTERNAL_POLYFILL_PATH = "/polyfills";
INTERNAL_POLYFILL_PATH_PROD = "/polyfills/node";
POLYFILL_PREFIX_DEV = "aziondev:";
POLYFILL_PREFIX_PROD = "azionprd:";
isProduction;
prefix;
constructor(t) {
this.isProduction = t, this.prefix = "node:";
}
static getAbsolutePath = (t, r) => `${c.join(z(import.meta.url, "bundler"), r)}${t}`;
changeToPolyfillPath = (t, r, s, n) => {
const o = t.replace(new RegExp(`^${this.prefix}`), ""), i = Te.find((l) => l.startsWith(`${s}${o}`));
if (i) {
const [, , l] = i.split(":"), a = c.join(n, l), p = I.resolve(a);
return [t, p];
}
return [t, I.resolve(r)];
};
apply(t) {
t.options.plugins?.length || (t.options.plugins = []), t.options.plugins.push(
new t.webpack.NormalModuleReplacementPlugin(new RegExp(`^${this.prefix}`), (s) => {
const n = s.request.replace(new RegExp(`^${this.prefix}`), "");
s.request = n;
})
), t.options.plugins.push(
new t.webpack.ProvidePlugin(
Object.fromEntries(
Object.entries(ze).map(([s, n]) => typeof n == "string" ? [s, I.resolve(n)] : [s, n])
)
)
);
const r = {
NODE_ENV: "production"
};
if (f.existsSync(c.join(process.cwd(), ".next"))) {
const s = f.readFileSync(c.join(process.cwd(), ".next/BUILD_ID"), "utf-8");
r.NEXT_RUNTIME = "edge", r.NEXT_COMPUTE_JS = !0, r.__NEXT_BUILD_ID = s;
}
t.options.plugins.push(new t.webpack.EnvironmentPlugin(r)), this.isProduction && (t.options.externals = {
...typeof t.options.externals == "object" ? t.options.externals : {},
...Object.fromEntries(
[...De].flatMap((s) => {
const n = s.replace(new RegExp(`^${this.prefix}`), "");
return [
[s, s],
[n, n]
];
})
)
}), t.options.resolve.alias = {
...t.options.resolve.alias,
...q
}, t.options.resolve.fallback = {
...t.options.resolve.fallback,
...q
}, this.isProduction ? (t.options.resolve.alias = {
...Object.fromEntries(
Object.entries(t.options.resolve.alias).map(([s, n]) => this.changeToPolyfillPath(
s,
n,
this.POLYFILL_PREFIX_PROD,
v.getAbsolutePath(this.INTERNAL_POLYFILL_PATH_PROD, "../unenv-preset/src")
))
)
}, t.options.resolve.fallback = {
...Object.fromEntries(
Object.entries(t.options.resolve.fallback).map(([s, n]) => this.changeToPolyfillPath(
s,
n,
this.POLYFILL_PREFIX_PROD,
v.getAbsolutePath(this.INTERNAL_POLYFILL_PATH_PROD, "../unenv-preset/src")
))
)
}) : (t.options.resolve.alias = {
...Object.fromEntries(
Object.entries(t.options.resolve.alias).map(([s, n]) => this.changeToPolyfillPath(
s,
n,
this.POLYFILL_PREFIX_DEV,
v.getAbsolutePath(this.INTERNAL_POLYFILL_PATH, "src")
))
)
}, t.options.resolve.fallback = {
...Object.fromEntries(
Object.entries(t.options.resolve.fallback).map(([s, n]) => this.changeToPolyfillPath(
s,
n,
this.POLYFILL_PREFIX_DEV,
v.getAbsolutePath(this.INTERNAL_POLYFILL_PATH, "src")
))
)
});
}
}
const L = {
experiments: {
outputModule: !0
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
mainFields: ["browser", "module", "main"]
},
mode: "production",
target: ["webworker", "es2022"],
plugins: [
new y.ProgressPlugin(),
new y.optimize.LimitChunkCountPlugin({
maxChunks: 1
})
]
}, V = J({
NodePolyfillsPlugin: v,
AzionPolyfillsPlugin: Ne,
BabelCustomLoaderPlugin: Ie
}), Se = (e) => (t) => {
if (!t) return e;
const r = e.plugins?.findIndex((s) => s instanceof y.BannerPlugin) ?? -1;
if (r !== -1 && e.plugins) {
const s = e.plugins[r].options.banner;
e.plugins = e.plugins.filter((n, o) => o !== r), e.plugins.push(
new y.BannerPlugin({
banner: `${s} ${t}`,
raw: !0
})
);
} else
e.plugins = [
...e.plugins || [],
new y.BannerPlugin({
banner: t,
raw: !0
})
];
return e;
}, Je = (e, t) => {
const r = e.baseOutputDir || process.cwd(), s = L.plugins || [];
return {
baseConfig: {
...L,
entry: e.entry,
output: {
...L.output,
path: r,
filename: "[name]",
globalObject: "globalThis"
},
plugins: [
...s.filter((o) => !!o),
new y.BannerPlugin({
banner: K(t),
raw: !0,
entryOnly: !0
})
],
optimization: {
...L.optimization,
minimize: t.production
}
},
mergeConfig: (o) => j([
() => V.applyPolyfills(t)(o)(e),
() => V.applyAzionModule(t)(o),
() => Se(o)(e?.setup?.contentToInject),
() => G(o, "webpack")(e?.setup?.defineVars),
() => Z(o)(e.extend)
])(o),
applyConfig: (o) => o,
executeBuild: Fe
};
}, Fe = async (e) => {
await new Promise((t, r) => {
const s = j([() => e.mergeConfig(e.baseConfig)])(e.baseConfig);
y(s, (n, o) => {
if (n || o?.hasErrors()) {
const l = o?.toJson()?.errors?.map((a) => a.message).join(`
`);
console.log(n), r(new Error(l));
return;
}
t();
});
});
};
export {
He as createAzionESBuildConfig,
Je as createAzionWebpackConfig,
Ae as executeESBuildBuild,
Fe as executeWebpackBuild
};