azion
Version:
Azion Packages for Edge Computing.
37 lines (36 loc) • 21.1 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const re=require("esbuild"),$=require("lodash-es"),y=require("webpack"),f=require("fs"),d=require("path"),H=require("signale"),R=require("module"),ie=require("url"),ae=require("node:module"),J=require("unenv");var u=typeof document<"u"?document.currentScript:null;function le(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const o=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,o.get?o:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ce=le(re),B=`
/**
* Built with Azion CLI
* For more information, visit: https://www.azion.com/en/documentation/products/cli/
*/
`,ue=`
/**
* 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.
*/
`,G=e=>{const t=e;return{applyPolyfills:n=>r=>i=>i.polyfills?q(t.NodePolyfillsPlugin)?(r.plugins=[...r.plugins||[],new t.NodePolyfillsPlugin(n.production),new t.BabelCustomLoaderPlugin(i.preset.metadata.name,["next"])],r):(r.plugins=[...r.plugins||[],t.NodePolyfillsPlugin(n.production),..."OptionalChainingAssignmentPlugin"in t?[t.OptionalChainingAssignmentPlugin()]:[],..."SanitizeWorker"in t?[t.SanitizeWorker(process.env.AZ_ENABLE_SANITIZE_WORKER??!1,{options:{outfile:r.outfile}})]:[]],r):r,applyAzionModule:n=>r=>(r.plugins=[...r.plugins||[],q(t.AzionPolyfillsPlugin)?new t.AzionPolyfillsPlugin(n.production):t.AzionPolyfillsPlugin(n.production)],r)}};function q(e){return"prototype"in e}const K=(e,t)=>(s={})=>s?t==="esbuild"?(e.define={...e.define,...s},e):(e.plugins=[...e.plugins||[],new y.DefinePlugin(s)],e):e,Z=e=>e.production?B:`${B}${ue}`,Q=e=>t=>t===void 0?e:t(e),pe={bundle:!0,format:"esm",platform:"browser",mainFields:["browser","module","main"],target:"es2022",keepNames:!0,allowOverwrite:!0,loader:{".js":"js"},outdir:"."},ee=process.env.CLEAN_OUTPUT_MODE==="true",te={displayScope:!1,displayBadge:!1,displayDate:!1,displayFilename:!1,displayLabel:!1,displayTimestamp:!1,underlineLabel:!1,underlineMessage:!1,underlinePrefix:!1,underlineSuffix:!1,uppercaseLabel:!1},P=(e={})=>{const t=new H.Signale({...e});return ee&&t.config(te),Object.assign(t,{breakInteractiveChain:()=>console.log()})},m={deployed:{badge:"🚀",color:"green",label:"forged",logLevel:"info"},option:{badge:"📦",color:"green",label:"",logLevel:"info"}},g=(e="Azion")=>new H.Signale({interactive:!1,scope:e,types:m});ee&&g().config(te);const de=(e="Azion")=>({...g(e),interactive:{...P({interactive:!0,scope:[e],types:m})},server:{...g(e).scope(e,"Server"),interactive:P({interactive:!0,scope:[e,"Server"],types:m})},runtime:{...g(e).scope(e,"Runtime"),interactive:P({interactive:!0,scope:[e,"Runtime"],types:m})},prebuild:{...g(e).scope(e,"Pre-Build"),interactive:P({interactive:!0,scope:[e,"Pre-Build"],types:m})},build:{...g(e).scope(e,"Build"),interactive:P({interactive:!0,scope:[e,"Build"],types:m})},postbuild:{...g(e).scope(e,"Post-Build"),interactive:P({interactive:!0,scope:[e,"Post-build"],types:m})},storage:{...g(e).scope(e,"Storage"),interactive:P({interactive:!0,scope:[e,"Storage"],types:m})},bindings:{...g(e).scope(e,"Bindings"),interactive:P({interactive:!0,scope:[e,"Bindings"],types:m})},manifest:{...g(e).scope(e,"IaC"),interactive:P({interactive:!0,scope:[e,"IaC"],types:m})}});({...de()});const M=process.platform==="win32";function z(e=typeof document>"u"?require("url").pathToFileURL(__filename).href:u&&u.tagName.toUpperCase()==="SCRIPT"&&u.src||new URL("index.cjs",document.baseURI).href,t="bundler"){const s=new RegExp(`(.*${t})(.*)`),o=e.match(s);let n=o?o[1]:"";if(e.includes("edge-functions")&&t==="bundler"){const r=new RegExp("(.*edge-functions)(.*)"),i=e.match(r);n=i?i[1]:n}return M&&(n=new URL(n).pathname,n.startsWith("/")&&(n=n.slice(1))),M||(n=n.replace("file://","")),n}const fe=()=>d.resolve(z(typeof document>"u"?require("url").pathToFileURL(__filename).href:u&&u.tagName.toUpperCase()==="SCRIPT"&&u.src||new URL("index.cjs",document.baseURI).href,"bundler"),"src"),w=`${fe()}/polyfills/azion`,b={external:new Map([["azion:storage",`${w}/storage/storage.polyfills.js`],["Azion.env",`${w}/env-vars/env-vars.polyfills.js`],["Azion.networkList",`${w}/network-list/network-list.polyfills.js`],["Azion.Storage",`${w}/storage/storage.polyfills.js`],["Azion.KV",`${w}/kv/kv.polyfills.js`]])},he=e=>{const t="bundler-azion-modules-polyfills",s=t,o=/^azion:/,n="azion:";return{name:t,setup:r=>{const i=r.initialOptions;e&&(i.external=i.external||[],[...b.external].forEach(([a])=>{i.external=i.external||[],/^[^:]+:/.test(a)&&!i.external.includes(a)&&i.external.push(a)})),e||(i.inject=i.inject||[],b.external&&[...b.external].forEach(([a,l])=>{!/^[^:]+:/.test(a)&&a?.toLowerCase()?.includes(n.replace(":",""))&&(i.inject=i.inject||[],i.inject.push(l))})),r.onResolve({filter:o},async a=>{if(!e&&b.external.has(a.path))return{path:a.path,namespace:s};if(b.external.has(a.path)&&!(Array.isArray(i?.external)&&i.external.includes(a.path)))return{path:a.path,namespace:s}}),r.onLoad({filter:o,namespace:s},async a=>{if(!b.external.has(a.path))return;const l=b.external.get(a.path);if(!l)throw new Error(`Could not resolve module: ${a.path}`);const c=await f.promises.readFile(l,"utf8"),p=d.dirname(l);return{loader:"js",contents:c,resolveDir:p}})}}},L=R.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:u&&u.tagName.toUpperCase()==="SCRIPT"&&u.src||new URL("index.cjs",document.baseURI).href),me=()=>({name:"babel-custom-loader",setup(t){t.onLoad({filter:/\.func\.m?js$/},async s=>{const o=await f.promises.readFile(s.path,"utf8");if(!o.includes("?.")||!/\?\.\s*\w+\s*=/.test(o))return null;try{const r=L("@babel/core").transformSync(o,{filename:s.path,plugins:[[L("@babel/plugin-proposal-optional-chaining-assign"),{version:"2023-07"}]],compact:!1,sourceMaps:!1});if(r?.code&&r.code!==o)return{contents:r.code,loader:"js"}}catch(n){console.warn(`Babel custom loader failed for ${s.path}:`,n)}return null}),t.onLoad({filter:/\.ts$/,namespace:"babel-custom"},async s=>{const o=await f.promises.readFile(s.path,"utf8");try{const r=L("@babel/core").transformSync(o,{filename:s.path,compact:!1,presets:[[L("@babel/preset-env"),{targets:{node:"current"}}],L("@babel/preset-typescript")]});if(r?.code)return{contents:r.code,loader:"js"}}catch(n){console.warn(`Babel TypeScript transform failed for ${s.path}:`,n)}return null})}}),ge=ie.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:u&&u.tagName.toUpperCase()==="SCRIPT"&&u.src||new URL("index.cjs",document.baseURI).href),be=d.dirname(ge),Pe=()=>d.resolve(be,"../../","unenv-preset","src"),h=`${Pe()}/polyfills`,ne={inject:{__dirname:`${h}/node/globals/path-dirname.js`,__filename:`${h}/node/globals/path-filename.js`,process:`${h}/node/globals/process.cjs`,performance:"unenv/polyfill/performance",setInterval:`${h}/node/globals/set-interval.js`,clearInterval:`${h}/node/globals/clear-interval.js`,console:`${h}/node/globals/console.js`,asyncStorage:`${h}/node/globals/async-storage.js`,dateToString:`${h}/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:`${h}/node/buffer.js`,https:`${h}/node/https.js`,module:`${h}/node/module.js`,string_decoder:"string_decoder/lib/string_decoder.js",timers:"timers-browserify/",util:`${h}/node/util.js`,zlib:`${h}/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"]},ye=(e,t)=>`${d.join(z(typeof document>"u"?require("url").pathToFileURL(__filename).href:u&&u.tagName.toUpperCase()==="SCRIPT"&&u.src||new URL("index.cjs",document.baseURI).href,"bundler"),e)}${t?`${t}`:""}`,ve={getAbsolutePath:ye},C=R.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:u&&u.tagName.toUpperCase()==="SCRIPT"&&u.src||new URL("index.cjs",document.baseURI).href),{env:Ee}=J.defineEnv({nodeCompat:!0,resolve:!1,overrides:{...ne}}),{alias:T,inject:k,polyfill:S,external:W}=Ee;function we(e){if(typeof e=="string")return{importStatement:`import globalVar from "${e}";`,exportName:"globalVar"};if(Array.isArray(e)&&e.length===2){const[t,s]=e;return{importStatement:`import { ${s} } from "${t}";`,exportName:s}}throw new Error(`Invalid global inject value: ${e}`)}function Le(e){const t="imported-unenv-alias",s={};Object.entries(T).forEach(([n,r])=>{try{const i=r.startsWith("unenv/"),a=C.resolve(r);s[n]=i?a.replace(/\.cjs$/,".mjs"):a.replace(/\.cjs$/,".js")}catch(i){i instanceof Error&&console.log(i.message)}});const o=new RegExp(`^(${Object.keys(s).join("|")})$`);e.onResolve({filter:o},n=>({path:n.path,namespace:t})),e.onLoad({filter:/.*/,namespace:t},async n=>{const r=s[n.path],i=await f.promises.readFile(r,"utf8"),a=d.dirname(r);return{loader:"js",contents:i,resolveDir:a}})}function _e(e,t,s,o,n,r){const i="node-built-in-modules",a=new RegExp(`^(node:)?(${ae.builtinModules.join("|")})$`);e.onResolve({filter:a},l=>{const c=l.path.replace("node:",""),p=T[c]??T[l.path]??l.path,x=(A,I)=>S.find(v=>v.startsWith(`${A}${I}`)),U=(A,I,v)=>{const D=W.find(N=>N===v||N===l.path||`node:${v}`===N),F=x(A,v);if(!F&&D)return{path:l.path.startsWith("node:")?l.path:`node:${l.path}`,external:D.includes(l.path)};if(F)return{path:v,namespace:I}};return(t?U(s,n,c):U(o,r,c))??{path:p,namespace:i,external:W.includes(l.path)}}),e.onLoad({filter:/.*/,namespace:i},async l=>{const c=C.resolve(l.path),p=await f.promises.readFile(c,"utf8"),x=d.dirname(c);return{loader:"js",contents:p,resolveDir:x}})}function je(e,t){const s=/_global_polyfill-([^.]+)\.js$/,o=d.resolve(t("../"),"_global_polyfill-");e.initialOptions.inject=[...e.initialOptions.inject??[],...Object.keys(k).map(n=>`${o}${n}.js`)],e.onResolve({filter:s},n=>({path:n.path})),e.onLoad({filter:s},n=>{const r=n.path.match(s);if(!r?.[1])throw new Error(`Invalid global name: ${n.path}`);const i=r[1],{importStatement:a,exportName:l}=we(k[i]);return{contents:`
${a}
globalThis.${i} = ${l};
`}})}function $e(e,t,s,o){e.onLoad({filter:/.*/,namespace:t},async n=>{try{const r=n.path.replace("node:",""),i=S.find(p=>p.startsWith(`${s}${r}`));if(!i)throw new Error(`Polyfill not found for ${r}`);const a=d.join(o,i.replace(`${s}${r}:/`,"")),l=await f.promises.readFile(a,"utf8"),c=d.dirname(a);return{loader:"js",contents:l,resolveDir:c}}catch(r){console.error(`Error loading polyfill for ${n.path}`,r)}})}function Re(e,t,s,o){e.onLoad({filter:/.*/,namespace:t},async n=>{try{const r=S.find(p=>p.startsWith(`${s}${n.path}`));if(!r)throw new Error(`Polyfill not found for ${n.path}`);const i=d.join(o,r.replace(`${s}${n.path}:/`,"")),a=C.resolve(i),l=await f.promises.readFile(a,"utf8"),c=d.dirname(a);return{loader:"js",contents:l,resolveDir:c}}catch(r){console.error(`Error loading polyfill prod for ${n.path}`,r)}})}function xe(e){if(f.existsSync(d.join(process.cwd(),".next"))){const t=f.readFileSync(d.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 Ae=e=>{const t="bundler-node-modules-polyfills",s="internal-env-dev",o="internal-env-prod",n="/polyfills",r="/polyfills/node",i="aziondev:",a="azionprd:",l=(c,p)=>ve.getAbsolutePath(c,p);return{name:t,setup:c=>{const p=c.initialOptions;p.define=p.define||{},p.define?.global||(p.define.global="globalThis"),p.define={...p.define,"process.env.NODE_ENV":'"production"'},xe(p),p.inject=p.inject||[],p.alias={...p.alias},_e(c,e,a,i,o,s),Le(c),je(c,l),$e(c,s,i,l("src",n)),Re(c,o,a,l("../unenv-preset/src",r))}}},Ie=(e,t)=>{const s="sanitize-worker",o=r=>{let i=0;return{result:Array.from(r).map(c=>{const p=c.codePointAt(0);return p>=65536?(i++,`\\u{${p.toString(16)}}`):c}).join(""),escapedCount:i}},n=r=>{const i=f.readFileSync(r,"utf-8"),{result:a,escapedCount:l}=o(i);l>0&&(console.log(`[sanitize-worker] Escaped ${l} Unicode character(s) in ${r}`),f.writeFileSync(r,a,"utf-8"))};return{name:s,setup(r){r.onEnd(async i=>{if(!(!e||i.errors.length>0))if(r.initialOptions.entryPoints)for(const a of Object.keys(r.initialOptions.entryPoints))n(`${a}.js`);else{const a=t?.outfile||r.initialOptions.outfile;a&&n(a)}})}}},Y=G({NodePolyfillsPlugin:Ae,AzionPolyfillsPlugin:he,OptionalChainingAssignmentPlugin:me,SanitizeWorker:Ie}),Ne=(e,t)=>s=>(s&&(e.banner=e.banner||{},e.banner.js=e.banner.js?`${e.banner.js} ${s}`:s,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),Oe=(e,t)=>{const s=e.baseOutputDir;return{baseConfig:{...pe,entryPoints:typeof e.entry=="string"?[e.entry]:e.entry,...s?{outdir:s}:{},entryNames:"[dir]/[name]",minify:t.production,plugins:[],banner:{js:Z(t)}},mergeConfig:n=>$.flow([()=>Y.applyPolyfills(t)(n)(e),()=>Y.applyAzionModule(t)(n),()=>Ne(n,t)(e?.setup?.contentToInject),()=>K(n,"esbuild")(e?.setup?.defineVars),()=>Q(n)(e.extend)])(n),applyConfig:n=>n,executeBuild:oe}},oe=async e=>{const t=$.flow([()=>e.mergeConfig(e.baseConfig),()=>e.applyConfig(e.baseConfig)])(e.baseConfig);await ce.build(t)};function Te(e){try{return e.map(t=>f.readFileSync(t,"utf-8")).join(`
`)}catch(t){throw new Error(`Failed to generate webpack banner: ${t instanceof Error?t.message:String(t)}`)}}class ze{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}`),o=>{const n=o.request.replace(new RegExp(`^${this.prefix}`),"");o.request=n}));const s=new Map([...b.external].filter(([o])=>new RegExp(`^${this.prefix}`).test(o)));this.buildProd||[...b.external].forEach(([o])=>{if(!/^[^:]+:/.test(o)&&o?.toLowerCase()?.includes(this.prefix.replace(":",""))){const r=b.external.get(o);if(!r)throw new Error(`Banner content not found for key: ${o}`);t.options.plugins?.push(new t.webpack.BannerPlugin({banner:Te([r]),raw:!0}))}}),this.buildProd?t.options.externals={...Object.fromEntries([...s].flatMap(([o])=>[[o,o],[`${this.prefix}${o}`,`${this.prefix}${o}`]])),...typeof t.options.externals=="object"?t.options.externals:{}}:(t.options.plugins?.push(new t.webpack.NormalModuleReplacementPlugin(new RegExp(`^${this.prefix}`),o=>{const n=o.request.replace(new RegExp(`^${this.prefix}`),"");o.request=n})),t.options.resolve=t.options.resolve||{},t.options.resolve.fallback={...Object.fromEntries([...s].map(([o,n])=>[o.replace(new RegExp(`^${this.prefix}`),""),n])),...t.options.resolve.fallback})}}const _=R.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:u&&u.tagName.toUpperCase()==="SCRIPT"&&u.src||new URL("index.cjs",document.baseURI).href);class Ce{preset;presetsAllowed;constructor(t,s){this.preset=t||"",this.presetsAllowed=s||[]}apply(t){const s=t.options.module.rules||[];this.presetsAllowed.includes(this.preset)&&s.push({test:/\.func.m?js$/,exclude:/node_modules/,use:{loader:_.resolve("babel-loader"),options:{compact:!1,plugins:[[_.resolve("@babel/plugin-proposal-optional-chaining-assign"),{version:"2023-07"}]]}}}),s.push({test:/\.ts$/,exclude:/node_modules/,use:{loader:_.resolve("babel-loader"),options:{compact:!1,presets:[[_.resolve("@babel/preset-env"),{targets:{node:"current"}}],_.resolve("@babel/preset-typescript")]}}}),t.options.module.rules=s}}const O=R.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:u&&u.tagName.toUpperCase()==="SCRIPT"&&u.src||new URL("index.cjs",document.baseURI).href),{env:Se}=J.defineEnv({nodeCompat:!0,resolve:!1,overrides:{...ne}}),{alias:V,inject:Ue,polyfill:De,external:Fe}=Se;class E{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,s)=>`${d.join(z(typeof document>"u"?require("url").pathToFileURL(__filename).href:u&&u.tagName.toUpperCase()==="SCRIPT"&&u.src||new URL("index.cjs",document.baseURI).href,"bundler"),s)}${t}`;changeToPolyfillPath=(t,s,o,n)=>{const r=t.replace(new RegExp(`^${this.prefix}`),""),i=De.find(a=>a.startsWith(`${o}${r}`));if(i){const[,,a]=i.split(":"),l=d.join(n,a),c=O.resolve(l);return[t,c]}return[t,O.resolve(s)]};apply(t){t.options.plugins?.length||(t.options.plugins=[]),t.options.plugins.push(new t.webpack.NormalModuleReplacementPlugin(new RegExp(`^${this.prefix}`),o=>{const n=o.request.replace(new RegExp(`^${this.prefix}`),"");o.request=n})),t.options.plugins.push(new t.webpack.ProvidePlugin(Object.fromEntries(Object.entries(Ue).map(([o,n])=>typeof n=="string"?[o,O.resolve(n)]:[o,n]))));const s={NODE_ENV:"production"};if(f.existsSync(d.join(process.cwd(),".next"))){const o=f.readFileSync(d.join(process.cwd(),".next/BUILD_ID"),"utf-8");s.NEXT_RUNTIME="edge",s.NEXT_COMPUTE_JS=!0,s.__NEXT_BUILD_ID=o}t.options.plugins.push(new t.webpack.EnvironmentPlugin(s)),this.isProduction&&(t.options.externals={...typeof t.options.externals=="object"?t.options.externals:{},...Object.fromEntries([...Fe].flatMap(o=>{const n=o.replace(new RegExp(`^${this.prefix}`),"");return[[o,o],[n,n]]}))}),t.options.resolve.alias={...t.options.resolve.alias,...V},t.options.resolve.fallback={...t.options.resolve.fallback,...V},this.isProduction?(t.options.resolve.alias={...Object.fromEntries(Object.entries(t.options.resolve.alias).map(([o,n])=>this.changeToPolyfillPath(o,n,this.POLYFILL_PREFIX_PROD,E.getAbsolutePath(this.INTERNAL_POLYFILL_PATH_PROD,"../unenv-preset/src"))))},t.options.resolve.fallback={...Object.fromEntries(Object.entries(t.options.resolve.fallback).map(([o,n])=>this.changeToPolyfillPath(o,n,this.POLYFILL_PREFIX_PROD,E.getAbsolutePath(this.INTERNAL_POLYFILL_PATH_PROD,"../unenv-preset/src"))))}):(t.options.resolve.alias={...Object.fromEntries(Object.entries(t.options.resolve.alias).map(([o,n])=>this.changeToPolyfillPath(o,n,this.POLYFILL_PREFIX_DEV,E.getAbsolutePath(this.INTERNAL_POLYFILL_PATH,"src"))))},t.options.resolve.fallback={...Object.fromEntries(Object.entries(t.options.resolve.fallback).map(([o,n])=>this.changeToPolyfillPath(o,n,this.POLYFILL_PREFIX_DEV,E.getAbsolutePath(this.INTERNAL_POLYFILL_PATH,"src"))))})}}const j={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})]},X=G({NodePolyfillsPlugin:E,AzionPolyfillsPlugin:ze,BabelCustomLoaderPlugin:Ce}),Be=e=>t=>{if(!t)return e;const s=e.plugins?.findIndex(o=>o instanceof y.BannerPlugin)??-1;if(s!==-1&&e.plugins){const o=e.plugins[s].options.banner;e.plugins=e.plugins.filter((n,r)=>r!==s),e.plugins.push(new y.BannerPlugin({banner:`${o} ${t}`,raw:!0}))}else e.plugins=[...e.plugins||[],new y.BannerPlugin({banner:t,raw:!0})];return e},qe=(e,t)=>{const s=e.baseOutputDir||process.cwd(),o=j.plugins||[];return{baseConfig:{...j,entry:e.entry,output:{...j.output,path:s,filename:"[name]",globalObject:"globalThis"},plugins:[...o.filter(r=>!!r),new y.BannerPlugin({banner:Z(t),raw:!0,entryOnly:!0})],optimization:{...j.optimization,minimize:t.production}},mergeConfig:r=>$.flow([()=>X.applyPolyfills(t)(r)(e),()=>X.applyAzionModule(t)(r),()=>Be(r)(e?.setup?.contentToInject),()=>K(r,"webpack")(e?.setup?.defineVars),()=>Q(r)(e.extend)])(r),applyConfig:r=>r,executeBuild:se}},se=async e=>{await new Promise((t,s)=>{const o=$.flow([()=>e.mergeConfig(e.baseConfig)])(e.baseConfig);y(o,(n,r)=>{if(n||r?.hasErrors()){const a=r?.toJson()?.errors?.map(l=>l.message).join(`
`);console.log(n),s(new Error(a));return}t()})})};exports.createAzionESBuildConfig=Oe;exports.createAzionWebpackConfig=qe;exports.executeESBuildBuild=oe;exports.executeWebpackBuild=se;