@flatjs/evolve 1.5.22 → 1.5.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/cjs/index.js +1 -1
  2. package/package.json +18 -18
package/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  /*! @flatjs/forge MIT @flatjs/evolve */
2
2
  "use strict";var e=require("@flatjs/common");var t=require("lodash");var n=require("@flatjs/mock");var r=require("babel-merge");var s=require("path");var o=require("@flatjs/forge-plugin-postcss-pixel");var i=require("cssnano");var a=require("webpack");var l=require("mini-css-extract-plugin");var c=require("chalk");var p=require("image-minimizer-webpack-plugin");var u=require("terser-webpack-plugin");var d=require("@pmmmwh/react-refresh-webpack-plugin");var m=require("case-sensitive-paths-webpack-plugin");var f=require("fork-ts-checker-webpack-plugin");var v=require("webpack-bundle-analyzer");var h=require("webpack-sources");var g=require("webpack/lib/util/extractUrlAndGlobal");var b=require("html-webpack-plugin");var y=require("webpack-dev-server");var w=require("express");var j=require("https");var C=require("fs");var k=require("better-opn");function S(e){let t;const n=process.env.NODE_ENV==="FLATJS_CORE";switch(e){case"@flatjs/evolve-preset-babel":t=require.resolve(n?"../../../evolve-preset-babel/src/index":e);break}return t}const P=(e,t=false)=>{if(!t){return require(e)}else{return n.loadModule(e)}};const O=(t={usePreset:"react"},n=[])=>{const{usePreset:s,...o}=t;const i=n.map((e=>[require.resolve("babel-plugin-import"),{transformToDefaultImport:false,libraryDirectory:"cjs",style:()=>false,...e},e.libraryName]));const{reactBabelPreset:a,infernoBabelPreset:l,vueBabelPreset:c}=P(S("@flatjs/evolve-preset-babel"));const p=s==="react"?a():s==="vue"?c():l();let u={};try{u=r(p,o);if(u.plugins){u.plugins.unshift(...i)}else{u.plugins=i}}catch(t){e.printError(t)}return Object.assign({babelrc:false},u)};const x=[`https://polyfill.io/v3/polyfill.min.js?features=Array.from%2CArray.isArray%2CArray.of%2CArray.prototype.entries%2CArray.prototype.every%2CArray.prototype.fill%2CArray.prototype.filter%2CArray.prototype.find%2CArray.prototype.findIndex%2CArray.prototype.flat%2CArray.prototype.forEach%2CArray.prototype.flatMap%2CArray.prototype.keys%2CArray.prototype.indexOf%2CArray.prototype.includes%2CArray.prototype.lastIndexOf%2CArray.prototype.map%2CArray.prototype.reduce%2CArray.prototype.reduceRight%2CArray.prototype.some%2CArray.prototype.sort%2CArray.prototype.values%2CArrayBuffer%2CBlob%2CDataView%2CDate.now%2CObject.assign%2CObject.create%2CObject.defineProperties%2CObject.defineProperty%2CObject.entries%2CObject.freeze%2CObject.fromEntries%2CObject.getOwnPropertySymbols%2CObject.getOwnPropertyNames%2CObject.getOwnPropertyDescriptors%2CObject.getOwnPropertyDescriptor%2CObject.getPrototypeOf%2CObject.is%2CObject.isExtensible%2CObject.isFrozen%2CObject.isSealed%2CObject.keys%2CObject.values%2CObject.setPrototypeOf%2CPromise%2CPromise.prototype.finally%2CReflect%2CReflect.apply%2CReflect.construct%2CReflect.defineProperty%2CReflect.deleteProperty%2CReflect.getPrototypeOf%2CReflect.getOwnPropertyDescriptor%2CReflect.get%2CReflect.ownKeys%2CReflect.isExtensible%2CReflect.has%2CReflect.preventExtensions%2CReflect.set%2CReflect.setPrototypeOf%2CSet%2CString.prototype.trimStart%2CString.prototype.trimEnd%2CString.prototype.trim%2CString.prototype.startsWith%2CString.prototype.repeat%2CString.prototype.replaceAll%2CString.prototype.padStart%2CString.prototype.padEnd%2CMap%2CObject.seal%2Cconsole.groupEnd%2Cconsole.group`];const A={reactDev:[`https://unpkg.com/react@18.2.0/umd/react.development.js`,`https://unpkg.com/react-dom@18.2.0/umd/react-dom.development.js`],reactProd:[`https://unpkg.com/react@18.2.0/umd/react.production.min.js`,`https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js`]};const B={reactDev:[`https://cdn.jsdelivr.net/npm/react@18.2.0/umd/react.development.js`,`https://cdn.jsdelivr.net/npm/react-dom@18.2.0/umd/react-dom.development.js`],reactProd:[`https://cdn.jsdelivr.net/npm/react@18.2.0/umd/react.production.min.js`,`https://cdn.jsdelivr.net/npm/react-dom@18.2.0/umd/react-dom.production.min.js`]};const E={reactDev:[`https://cdn.bootcdn.net/ajax/libs/react/18.2.0/umd/react.development.js`,`https://cdn.bootcdn.net/ajax/libs/react-dom/18.2.0/umd/react-dom.development.js`],reactProd:[`https://cdn.bootcdn.net/ajax/libs/react/18.2.0/umd/react.production.min.js`,`https://cdn.bootcdn.net/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js`]};const $={flatjsEvolve:{projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",forBuild:{rejectWarnings:false},forServe:{pageMiddlewares:[],defaultServeGlobalData:()=>({})},target:["web","es5"],liveReload:false,minimizeTerserOptions:{},multiHtmlCdn:{},multiHtmlCdnResolver:()=>undefined,watchOptions:{poll:1e3,ignored:/node_modules/,aggregateTimeout:500},extraPlugins:()=>[],pluginLoaderOptions:{babelOptions:{usePreset:"react"},lessOptions:{},cssnanoOptions:{},pixelOptions:{enabled:true,rootValue:{px:100,rpx:1},outputUnit:"rem"},enableBundleHashName:true,modularImports:[]}}};const M=(e,n={},r)=>{var s,o,i;const a=r[1];const l={vue:"Vue",react:"React","react-dom":"ReactDOM"};const c=t.isFunction(n)?n(e):n;const p=t.isFunction((s=a.options)==null?void 0:s.externals)?(o=a.options)==null?void 0:o.externals(e):(i=a.options)==null?void 0:i.externals;return Object.assign({},l,c,p||{})};const q=`(function(d){var j;var b=1;var i=1;var h=750;var c=100;function e(s,o){var q=d.document;var l=q.documentElement;var k=navigator.userAgent;var m=k.toLowerCase().indexOf("android")>-1;i=d.devicePixelRatio||1;if(i>3){i=3}if(m){i=1}console.log("current devicePixelRatio:",i);l.setAttribute("data-dpr",i.toString());var p=q.querySelector('meta[name="viewport"]');if(!p){b=1/i;p=q.createElement("meta");p.setAttribute("name","viewport");q.head.appendChild(p);p.setAttribute(["content","width=device-width,user-scalable=no,initial-scale=",b,",maximum-scale=",b,",minimum-scale=",b].join(""))}function n(){var t=document.documentElement.clientWidth;j=t/o*(s/i)*i;q.documentElement.style.fontSize=String(j)+"px"}var r;d.addEventListener("resize",function(){clearTimeout(r);r=setTimeout(n,300)},false);d.addEventListener("onload",n,false);n()}e(c,h);window.fabricViewport={currRem:j,currDpr:i,currScale:b,dpiPX2px:function f(k){return parseFloat(k.toString())/j*100+"px"},px2DPIpx:function a(k){return parseFloat(k.toString())/100*j+"px"},px2rem:function g(k){return parseFloat(k.toString())/100+"rem"}}})(window);`;const R={title:"",favicon:"",inlineScripts:()=>[],headBeforeStyles:()=>[],headBeforeScripts:e=>[...x,...e==="development"?E.reactDev:E.reactProd],bodyAfterScripts:()=>[],viewport:q,excludeCdnEnvs:["me","dev","ntv"],minify:true,template:s.join(e.getPackageDirSync(__dirname,""),"templates/html-plugin/index-{0}.html")};const F=(e,n,r)=>{let s;if(r){s=typeof r==="function"?r(n):r}if(t.isUndefined(s)){const t=R[e];return typeof t==="function"?t(n):t}return s};const D=(e,t)=>Object.assign({sourceMap:e,javascriptEnabled:true},t);const T=(e,t={},n={})=>{const r=[i({preset:["default",{discardComments:{removeAll:!e},reduceInitial:false,normalizeWhitespace:!e,...n}]})];if(t.enabled!==false){r.push(o.forgePluginPostcssPixel(t))}return{plugins:r}};const N=(e,t={})=>{const n={hints:e?false:"warning"};return Object.assign(n,t)};const W=(e={})=>({parallel:true,
3
3
  // Disable Extract all or some (use /^\**!|@preserve|@license|@cc_on/i RegExp) comments.
4
- extractComments:false,terserOptions:t.merge({ecma:undefined,parse:{},compress:{},mangle:true,module:false,output:null,toplevel:false,nameCache:null,ie8:false,keep_classnames:undefined,keep_fnames:false,safari10:false},e)});const H=(n=process.cwd(),r)=>{const s=e.loadFlatjsConfig(n,"flatjsEvolve","flatjs.evolve.js");return t.merge({},$.flatjsEvolve,s.flatjsEvolve,r,{projectCwd:n})};const z=e=>{try{k(e)}catch(e){console.warn(`Unable to open browser. If you are running in a headless environment\n`)}};function L(e="",t=""){return e.replace(/\/$/,"")+"/"+t.replace(/^\//,"")}function U(e,t){const n=new RegExp("[?&]env(=([^&#]*)|&|#|$)");const r=window.location.href;const s=n.exec(r);let o=s&&s[2]?decodeURIComponent(s[2].replace(/\+/g," ")):"prod";o=t(r)||o;const i=e[o]||e["prod"]||[];const a=i[Math.floor(Math.random()*i.length)];return a.replace(/\/$/,"")+"/"}function I(e={},t="prod"){const n=e[t]||e["prod"]||[];return n[Math.floor(Math.random()*n.length)]}function J(e,t=(()=>undefined)){return`window.evolveFetchMicroWidgets = function () {\n var cdnConfig = ${JSON.stringify(e)};\n var cdnResolver = ${t.toString()};\n var cdnFinder = ${U.toString()};\n return (cdnFinder(cdnConfig, cdnResolver) || '').replace(/\\/$/, '');\n }`}function V(e,n){const r=[];for(const[t,n]of Object.entries(e)){r.push({[t]:n.entry})}return r.map((e=>t.merge({},n,{name:Object.keys(e)[0],entry:e})))}const _=(e,n)=>{var r,s;const o=t.merge({},n.pluginLoaderOptions);if(typeof((r=e.options)==null?void 0:r.allowPx2rem)!=="undefined"){t.set(o,"pixelOptions.enabled",e.options.allowPx2rem)}if(typeof((s=e.options)==null?void 0:s.enableBundleHashName)!=="undefined"){t.set(o,"enableBundleHashName",e.options.enableBundleHashName)}const i={...n,pluginLoaderOptions:o};return i};const G=(e,t)=>{var n,r;const s=(n=e.pluginLoaderOptions)==null?void 0:(r=n.pixelOptions)==null?void 0:r.enabled;const o=(t==null?void 0:t.allowPx2rem)??s;return!!o};const K=e=>{if(Object.keys(e).length>1){throw new Error(`Only single one entry map support now while "serve", "build" process!`)}let t=undefined;for(const[n,r]of Object.entries(e)){t=[n,r];break}if(!t){throw new Error(`No entry map found while "serve", "build" process!`)}return t};const X=()=>Date.now().toString();const Y=(e,t,n=true)=>{const r=e==="js"?".js":".css";if(t){return`bundle${r}`}if(n){return`bundle[contenthash]${r}`}return`bundle${r}?${X()}`};const Q=/svg-icons\//;const Z=/\.(jpe?g|png|gif|svg)$/;const ee=/\.(ttf|eot|woff|woff2)(\?.+)?$/;const te=e=>Q.test(e)&&e.endsWith(".svg");const ne=({projectCwd:e,projectVirtualPath:t},n,[r,o])=>{let i=s.dirname(s.join(t,n.replace(/^src/,"")));const a=o.entry.map((t=>s.dirname(s.join(e,t))));const l=s.resolve(e,n);const c=a.find((e=>l.startsWith(e)));if(c){i=s.dirname(s.join(r,s.relative(c,l)))}return`${i}/[name]-[contenthash:8][ext]`};const re=(e,t)=>{const n={test(e){return ee.test(e)||Z.test(e)&&!te(e)},type:"asset",generator:{filename({filename:n}){return ne(e,n,t)}},parser:{dataUrlCondition:{maxSize:4*1024}}};return n};const se=()=>{const e={test(e){return te(e)},use:[{loader:require.resolve("./loader-icon"),options:{svgo:{plugins:[{name:"removeTitle"},{name:"removeDimensions"}]}}}]};return e};function oe(e,n){const r=t.isFunction(e)?e(n):e;if(r.usePreset==="react"&&n){if(r.plugins){r.plugins.push(require.resolve("react-refresh/babel"))}else{r.plugins=[require.resolve("react-refresh/babel")]}}return r}const ie=(e,n={})=>{const{babelOptions:r={},modularImports:s=[]}=n;const o=oe(r,e);const i=t.isFunction(s)?s(e):s;const a=O(o,i);const l={test:/\.(tsx|ts|js|jsx)$/,use:[{loader:require.resolve("babel-loader"),options:a}]};return l};const ae=(e,t={})=>{const n={test:/\.css$/i,use:[{loader:l.loader,options:{esModule:true}},{loader:"css-loader",options:{sourceMap:e}}]};const{pixelOptions:r,cssnanoOptions:s}=t;if(Array.isArray(n.use)){n.use.push({loader:"postcss-loader",options:{postcssOptions:T(e,r,s),sourceMap:e}})}return n};const le=(e,t={})=>{const n=ae(e,t);n.test=/\.less$/i;const r=t.lessOptions;if(Array.isArray(n.use)){n.use.push({loader:require.resolve("less-loader"),options:{sourceMap:e,lessOptions:D(e,r)}})}return n};const ce=(e,t,n,r={})=>{const s=[se(),re(t,n),ae(e,r),le(e,r),ie(e,r)];return s};const pe=new Map;const ue=()=>{const t=[["svgo",{}],["gifsicle",{}],["jpegtran",{}],["pngquant",{}]];const n=t.map((t=>{const n=t[0];try{require.resolve(`imagemin-${n}`);return t}catch(t){if(!pe.get(n)){pe.set(n,true);const t=c.magenta(`"${e.hasYarn()?"yarn add":"npm install"} imagemin-${n} -D"`);e.Logger.warn(`Execute ${t} for assets optimization`,"@flatjs/evolve")}return null}})).filter(Boolean);if(n.length){return new p({minimizer:{implementation:p.imageminMinify,options:{plugins:n}}})}return null};const de=e=>new u(W(e.minimizeTerserOptions));const me=(e,t)=>{if(e){return[]}return[de(t),ue()].filter(Boolean)};class fe{constructor(e={}){this.verbose=void 0;this.cleanStaleWebpackAssets=void 0;this.protectWebpackAssets=void 0;this.cleanAfterEveryBuildPatterns=void 0;this.cleanOnceBeforeBuildPatterns=void 0;this.currentAssets=void 0;this.initialClean=void 0;this.outputPath=void 0;this.verbose=e.verbose===true||false;this.cleanStaleWebpackAssets=e.cleanStaleWebpackAssets===true||e.cleanStaleWebpackAssets===false?e.cleanStaleWebpackAssets:true;this.protectWebpackAssets=e.protectWebpackAssets===true||e.protectWebpackAssets===false?e.protectWebpackAssets:true;this.cleanAfterEveryBuildPatterns=Array.isArray(e.cleanAfterEveryBuildPatterns)?e.cleanAfterEveryBuildPatterns:[];this.cleanOnceBeforeBuildPatterns=Array.isArray(e.cleanOnceBeforeBuildPatterns)?e.cleanOnceBeforeBuildPatterns:["**/*"];this.currentAssets=[];this.initialClean=false;this.outputPath="";this.apply=this.apply.bind(this);this.handleInitial=this.handleInitial.bind(this);this.handleDone=this.handleDone.bind(this);this.removeFiles=this.removeFiles.bind(this)}apply(e){if(!e.options.output||!e.options.output.path){console.warn("clean-webpack-plugin: options.output.path not defined. Plugin disabled...");return}this.outputPath=e.options.output.path;const t=e.hooks;if(this.cleanOnceBeforeBuildPatterns.length!==0){t.emit.tap("clean-webpack-plugin",(e=>{this.handleInitial(e)}))}t.done.tap("clean-webpack-plugin",(e=>{this.handleDone(e)}))}handleInitial(e){if(this.initialClean){return}const t=e.getStats();if(t.hasErrors()){return}this.initialClean=true;this.removeFiles(this.cleanOnceBeforeBuildPatterns)}handleDone(e){if(e.hasErrors()){if(this.verbose){console.warn("clean-webpack-plugin: pausing due to webpack errors")}return}const t=e.toJson({assets:true}).assets||[];const n=t.map((e=>e.name));const r=this.currentAssets.filter((e=>{const t=n.includes(e)===false;return t}));this.currentAssets=n.sort();const s=[];if(this.cleanStaleWebpackAssets===true&&r.length!==0){s.push(...r)}if(this.cleanAfterEveryBuildPatterns.length!==0){s.push(...this.cleanAfterEveryBuildPatterns)}if(s.length!==0){this.removeFiles(s)}}removeFiles(t){try{const n=e.delFilesSync(t,{cwd:this.outputPath,dot:true,ignore:this.protectWebpackAssets?this.currentAssets:[]});if(this.verbose){n.forEach((e=>{const t=s.relative(process.cwd(),e);const n="removed";console.warn(`clean-webpack-plugin: ${n} ${t}`)}))}}catch(e){const t=/Cannot delete files\/folders outside the current working directory\./.test(e.message);if(t){const e="clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the `dangerouslyAllowCleanPatternsOutsideProject` option.";throw new Error(e)}throw e}}}const ve=t=>new fe({verbose:true,cleanOnceBeforeBuildPatterns:[`${s.join(e.ensureSlash(t[0],true),"**/*")}`]});const he=(e,t)=>new l({filename:`[name]/${Y("css",e,t==null?void 0:t.enableBundleHashName)}`,chunkFilename:"[id].[contenthash].css"});const ge="ExternalTemplateRemotesPlugin";const be=e=>e.constructor.name==="ExternalModule";class ye{apply(e){e.hooks.make.tap(ge,(e=>{const t=[];e.hooks.buildModule.tap(ge,(e=>{if(be(e)&&e.externalType==="script"){t.push(e)}}));e.hooks.afterCodeGeneration.tap(ge,(()=>{t.map((t=>{const n=g(t.request)[0];const r=we(n);const s=e.codeGenerationResults.get(t,undefined).sources;const o=s.get("javascript");if(o){const e=new h.RawSource(o.source().toString().replace(`"${n}"`,r));s.set("javascript",e)}}))}))}))}}function we(e){const t=[];const n=[];let r=false;let s=false;for(const o of e){if(o==="["){if(r){s=true;break}r=true;if(n.length){t.push(`"${n.join("")}"`);n.length=0}}else if(o==="]"){if(!r){s=true;break}r=false;if(n.length){t.push(`${n.join("")}`);n.length=0}n.length=0}else{n.push(o)}}if(r||s){throw new Error(`Invalid template URL "${e}"`)}if(n.length){t.push(`"${n.join("")}"`)}return t.join(" + ")}const je=`HtmlInjectScriptPlugin`;class Ce{constructor(e){this.scripts=void 0;this.scripts=e||[]}processScripts(){return this.scripts.filter(Boolean).map((e=>({tagName:"script",innerHTML:e,voidTag:false,attributes:{},meta:{plugin:"html-inject-script-webpack-plugin"}})))}apply(e){e.hooks.compilation.tap(`${je}_compilation`,(e=>{const t=b.getHooks(e);t.alterAssetTags.tap(`${je}_alterAssetTags`,(e=>{e.assetTags.scripts.unshift(...this.processScripts());return e}))}))}}const ke=(e="")=>e.replace(/[\/-]/gi,"_").toLowerCase();const Se=e=>s.join(e,`micro-remote-module.js`);const Pe=(t,[n,r],s)=>{var o;const i=s.multiHtmlCdn;const l=s.multiHtmlCdnResolver;const c=(o=r.options)==null?void 0:o.moduleFederation;const p=[];if(c){const{remotes:r,...s}=c;const o=Se(n);const u=ke(n);const d=(r||[]).map((({name:t,endpoint:n})=>{const r=ke(t);const s=Se(t);const o=n?e.ensureSlash(n(t),false):`[window.evolveFetchMicroWidgets()]`;return{[r]:`${r}@${o}/${s}`}}));p.push(new a.container.ModuleFederationPlugin({name:u,filename:o,remotes:d,...s}),new ye);if(!t){p.unshift(new Ce([J(i,l)]))}}return p};const Oe={minifyJS:true,removeComments:true,collapseWhitespace:true,collapseBooleanAttributes:false};const xe=(e,t,[n,r],s)=>{const o=[];const{options:i}=r;const a=e?"development":"production";for(const e of s){o.push(new b({inject:"body",title:F("title",a,i==null?void 0:i.title),chunks:[n],minify:(i==null?void 0:i.minify)===false?false:["me","dev"].includes(e)?false:Oe,filename:`${n}/index${e==="prod"?"":`-${e}`}.html`,template:F("template",a,i==null?void 0:i.template).replace(`{0}`,e),templateParameters:{title:F("title",a,i==null?void 0:i.title),favicon:F("favicon",a,i==null?void 0:i.favicon),inlineScripts:F("inlineScripts",a,i==null?void 0:i.inlineScripts),headBeforeStyles:F("headBeforeStyles",a,i==null?void 0:i.headBeforeStyles),headBeforeScripts:F("headBeforeScripts",a,i==null?void 0:i.headBeforeScripts),bodyAfterScripts:F("bodyAfterScripts",a,i==null?void 0:i.bodyAfterScripts),viewport:G(t,i)?F("viewport",a,i==null?void 0:i.viewport):""},multiCdn:{env:e,disabled:((i==null?void 0:i.excludeCdnEnvs)||["me","dev","ntv"]).includes(e)}}))}return o};class Ae{constructor(e){var t;this.pluginName="FlatEvolveMultiCdnPlugin";this.requireFn=a.RuntimeGlobals.publicPath;this.config=void 0;this.cdnResolver=void 0;this.config=e.multiHtmlCdn;this.cdnResolver=e.multiHtmlCdnResolver||(()=>undefined);if(!((t=this.config)!=null&&t.prod)){throw new Error("We must setup `prod` for each CDN config node!")}}apply(e){e.hooks.thisCompilation.tap(this.pluginName,(e=>{e.mainTemplate.hooks.requireExtensions.tap(this.pluginName,((t,n)=>{var r;const s=[];s.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)");const o=(r=e.chunkGraph)==null?void 0:r.getTreeRuntimeRequirements(n);if(o&&o.has(a.RuntimeGlobals.requireScope)){s.push("(function () {");s.push(a.Template.indent(`var flatjsMultiCdn = {`));s.push(a.Template.indent(a.Template.indent([`cdnConfig: ${JSON.stringify(this.config||{})},`])));s.push(a.Template.indent(a.Template.indent([`cdnResolver: ${this.cdnResolver.toString()},`])));s.push(a.Template.indent(a.Template.indent([`cdnFinder: ${U.toString()}`])));s.push(a.Template.indent(`};`));s.push(a.Template.indent(`${this.requireFn} = flatjsMultiCdn.cdnFinder(flatjsMultiCdn.cdnConfig, flatjsMultiCdn.cdnResolver) || ${this.requireFn};`));s.push("})();")}return a.Template.asString(s)}))}));e.hooks.compilation.tap(this.pluginName,(e=>{b.getHooks(e).beforeAssetTagGeneration.tap(this.pluginName,(e=>{const{assets:t}=e;const{userOptions:n}=e.plugin;const r=n.multiCdn;const o=t.publicPath;const i=t.js.map((e=>{if(r.disabled){return s.basename(e)}const t=I(this.config,r.env);return L(t,e.replace(o,""))}));const a=t.css.map((e=>{if(r.disabled){return s.basename(e)}const t=I(this.config,r.env);return L(t,e.replace(o,""))}));e.assets.js=i;e.assets.css=a;return e}))}))}}const Be=(e,t,n)=>{var r;const s=[new m];if(n.analyzer){s.push(new v.BundleAnalyzerPlugin({analyzerPort:"auto",analyzerMode:"server",...n.analyzer}))}s.push(new f({async:e}));s.push(he(e,n.pluginLoaderOptions));s.push(...Pe(e,t,n));if(!e){s.push(ve(t));const r=Object.keys(n.multiHtmlCdn);s.push(...xe(e,n,t,r));s.push(new Ae(n))}const o=oe(((r=n.pluginLoaderOptions)==null?void 0:r.babelOptions)||{},e);if(o.usePreset==="react"&&e){s.push(new d({overlay:false}))}return s};const Ee=(n,r,o,i)=>{process.env.NODE_ENV=n;r=r==="auto"?"auto":e.ensureSlash(r,true);const a=n==="development";const l=i.projectCwd;const c=i.pluginLoaderOptions;const p=i.watchOptions;const u=K(o);const d=t.isFunction(i.extraLoaders)?i.extraLoaders(a):i.extraLoaders;const m=[...ce(a,i,u,c),...d||[]];const f=t.isFunction(i.extraPlugins)?i.extraPlugins(a):i.extraPlugins;const v=t.isFunction(i.resolveAlias)?i.resolveAlias(a):i.resolveAlias;const h=[...Be(a,u,i),...f||[]];const g={mode:n,target:i.target,stats:{preset:"minimal"},infrastructureLogging:{level:"warn"},devtool:a?"eval-source-map":i.productionSourceMap||false,plugins:h,watchOptions:p,context:l,cache:{type:"memory"},resolve:{mainFields:["browser","module","main"],extensions:[".ts",".tsx",".js",".json",".vue"],alias:v||{}},module:{rules:m},externals:M(a,i.externals,u),performance:N(a,i.performance),output:{devtoolModuleFilenameTemplate:({namespace:e,resourcePath:t})=>`webpack:///${s.join(e,t)}`,environment:{},pathinfo:false,path:s.join(l,"public"),publicPath:r,filename:`[name]/${Y("js",a,c==null?void 0:c.enableBundleHashName)}`,chunkFilename:`[id].[contenthash].js`},optimization:{nodeEnv:a?"development":"production",chunkIds:a?"named":"named",moduleIds:a?"named":"named",minimize:i.minimize===false?false:a?false:true,minimizer:me(a,i),splitChunks:{name:false,chunks:"all",minSize:25e5,cacheGroups:{default:false,defaultVendors:false}}}};return g};const $e=(e,t,n)=>{const r=Ee("production",t,e,n);const s=V(e,r);if(s.length>1){throw new Error("startSingleEntryBuild() only support `compiler` at a time")}const o=s[0];return new Promise(((e,t)=>{a(o,((r,s)=>{var i,a;if(r){return t(r)}const l=s==null?void 0:s.toJson();if(l!=null&&(i=l.errors)!=null&&i.length){return t(l.errors)}if(n.forBuild.rejectWarnings&&l!=null&&(a=l.warnings)!=null&&a.length){return t(l.warnings)}e({name:o.name,warningStats:l==null?void 0:l.warnings})}))}))};const Me=async(t,n)=>{var r;await e.keepPackageDepsUpToDateForNonMonoRepo({cwd:process.cwd(),autoUpgrade:true,needVerifyPackages:n.needVerifyPackages||{}});const s=((r=n.multiHtmlCdn)==null?void 0:r.prod)||[];const o=[];const i=e.ensureSlash(s[Math.floor(Math.random()*s.length)],true);for(const[e,r]of Object.entries(t)){var a;const t=_(r,n);const s={[e]:r};const l=(a=r.options)==null?void 0:a.useRelativeAssetPath;o.push($e(s,l?"auto":i,t))}return Promise.all(o)};const qe=async(n,r,o)=>{const i=await e.getPackageDir(__dirname,process.cwd());const a=C.readFileSync(s.join(i,"./templates/main.html"),"utf-8");const l=[];for(const[t,s]of Object.entries(o.entryMap)){var c;const i=((c=s.options)==null?void 0:c.servePageMainLinkFn)||(e=>e);const a=Object.keys(n).includes(t);const p=o.projectVirtualPath.replace(/^\//,"");l.push({name:t.replace(p,"").replace(/^\//,""),link:i(e.urlJoin(r,["pages",t],{env:"me"}),{hostUri:r,entryName:t,virtualPath:p}),flagText:a?"serve":"static",isServed:a?1:0})}const p={title:"@flatjs/evolve",modules:l.sort(((e,t)=>t.isServed-e.isServed))};return t.template(a)(p)};const Re=async(n,r,o,i,a,l)=>{const c=l.entryMap;const p=Object.keys(c).sort(((e,t)=>t.length-e.length));const u=await e.getPackageDir(__dirname,process.cwd());const d=p.find((t=>e.ensureSlash(o.path.replace(/^\//,""),true).startsWith(e.ensureSlash(t,true))));if(!d){const e=C.readFileSync(s.join(u,`./templates/module-404.html`),"utf-8");return t.template(e)({title:"404 Not Found",errorMeta:[{name:`@flatjs/evolve workspace`,value:u},{name:`served entry names`,value:JSON.stringify(p)},{name:`module path`,value:`${o.path}`}]})}const m=c[d];const f=m.options;const v=n[d];const h=(v==null?void 0:v.devServerHostUri)||i;const g=(f==null?void 0:f.serveModuleTemplate)||"./templates/module.html";const b=s.join(l.projectCwd,"./templates/module.html");const y=C.readFileSync(s.isAbsolute(g)?g:e.existsSync(b)?b:s.join(u,"./templates/module.html"),"utf-8");const w=l.forServe;const j=w.defaultServeGlobalData?w.defaultServeGlobalData(m,i):{};const k={title:F("title",r,f==null?void 0:f.title),favicon:F("favicon",r,f==null?void 0:f.favicon),viewport:G(l,f)?F("viewport",r,f==null?void 0:f.viewport):"",inlineScripts:F("inlineScripts",r,f==null?void 0:f.inlineScripts),headBeforeStyles:F("headBeforeStyles",r,f==null?void 0:f.headBeforeStyles),headBeforeScripts:F("headBeforeScripts",r,f==null?void 0:f.headBeforeScripts),bodyAfterScripts:F("bodyAfterScripts",r,f==null?void 0:f.bodyAfterScripts),moduleFederationScripts:J({me:[e.urlJoin(i,["public"])]},l.multiHtmlCdnResolver),global:{hostUrl:i,apiBase:e.urlJoin(i,[a]),routeBaseName:s.join(`/pages`,d),moduleName:d.replace(l.projectVirtualPath,"").replace(/^\//,""),...j,...(f==null?void 0:f.serveGlobalData)||{}},styles:[e.urlJoin(h,[s.join("public",d,"bundle.css")])],scripts:[e.urlJoin(h,[s.join("public",d,"bundle.js")])]};return t.template(y)(k)};const Fe=(e,t,n,r,s)=>{const o=async(o,i)=>{let a;if(o.path==="/"){a=await qe(r,t,s)}else{a=await Re(r,e,o,t,n,s)}i.send(a)};return(s.forServe.pageMiddlewares||[]).concat(o)};const De=t=>async(n,r)=>{const o=n.baseUrl;if(!o.startsWith("/public")){r.redirect("/pages")}else{const n=await e.fileWalk(s.join("public/","**/*.{js,css}"),{cwd:t});const i=s.extname(o);const a=n.find((e=>s.extname(e)===i&&e.indexOf(o.replace(/\.(js|css)$/,""))!==-1));if(a){r.sendFile(a)}else{r.sendFile(s.join(t,o))}}};const Te=(e,t="development",r,s,o,i,a)=>{const l=w();n.attachMockMiddlewares(l,a);l.set("hostUri",s);l.use("/pages",...Fe(t,s,a.apiContext||"api",o,i));l.use("*",De(e));return new Promise((e=>{const t=i.https?j.createServer(i.https,l):l;t.listen(r,(()=>{e(true)}))}))};const Ne=(e,t,n)=>{const{projectCwd:r,https:o,liveReload:i}=n;const a=new y({server:{type:o?"https":"http",options:{...o}},open:false,compress:true,port:t,hot:!i,liveReload:i,allowedHosts:"all",static:{directory:`${s.join(r,"/public")}`},headers:{"Access-Control-Allow-Origin":"*"},client:{progress:true,overlay:{errors:true,warnings:false}}},e);return new Promise(((e,t)=>{a.startCallback((n=>{if(n){return t(n)}e(true)}))}))};const We=async(r,o,i,l)=>{await e.keepPackageDepsUpToDateForNonMonoRepo({cwd:process.cwd(),autoUpgrade:true,needVerifyPackages:i.needVerifyPackages||{}});if(i.https){l.https=i.https}const{mockPort:p,hostUri:u}=await n.prepareMockDomain(l);const d=e.urlJoin(u,["/pages"]);let m=p;const f=[];const v={};for(const[e]of Object.entries(o)){m=m+1;const{mockPort:r,hostUri:s}=await n.prepareMockDomain(t.merge({},l,{port:m}));v[e]={devServerPort:r,devServerHostUri:s}}for(const[t,n]of Object.entries(o)){var h,g;const o=((h=n.options)==null?void 0:(g=h.moduleFederation)==null?void 0:g.remotes)||[];o.forEach((t=>{t.endpoint=t=>{var n;return e.urlJoin(((n=v[t])==null?void 0:n.devServerHostUri)||u,["/public"])}}));const{devServerPort:l,devServerHostUri:p}=v[t];const m=e.urlJoin(p,["public"]);const b={[t]:n};const y=_(n,i);const w=Ee("development",m,b,y);const j=a.webpack(V(b,w)[0]);f.push(Ne(j,l,i));const C=c.bgBlack(`[${c.magenta("@flatjs")}:${c.bold(j.name||"")}]`);j.hooks.invalid.tap("fileChange",(e=>{console.log(C,`${"file change".padEnd(12," ")} ➩ ${c.cyan(s.relative(r,e||""))}`)}));j.hooks.done.tap("compileDone",(()=>{console.log(C,`${"serve page".padEnd(12," ")} ➩ ${c.cyan(d)}`)}))}await Te(r,"development",p,u,v,i,l);z(d);return Promise.all(f).then((()=>true)).catch((e=>{console.log("evolve serve err: ",e);return false}))};const He=async(t,r,s)=>{if(r.https){s.https=r.https}const{mockPort:o,hostUri:i}=await n.prepareMockDomain(s);const a=e.urlJoin(i,["/pages"]);return Te(t,"development",o,i,{},r,s).then((e=>{const t=c.bgBlack(`[${c.magenta("@flatjs")}:`);console.log(t,`${"serve page".padEnd(12," ")} ➩ ${c.cyan(a)}`);return e}))};const ze=(e={},n={})=>{const r={};for(const[s,o]of Object.entries(n)){const n={options:{}};if(e[s]){r[s]=t.merge({},n,o,e[s])}t.merge(o,n)}return r};const Le=(e,t,n={})=>{const r=H(e,n);const s=ze(t,r.entryMap);return Me(s,r)};const Ue=(e,t,r={},s={})=>{const o=H(e,r);const i=n.loadMockConfiguration(e,s);const a=ze(t,o.entryMap);return We(e,a,o,i)};const Ie=(e,t={},r={})=>{const s=H(e,t);const o=n.loadMockConfiguration(e,r);return He(e,s,o)};exports.cdnBoot=E;exports.cdnJsDelivr=B;exports.cdnUnpkg=A;exports.createPageMiddleware=Fe;exports.createPublicAssetsMiddleware=De;exports.defaultFlatjsConfig=$;exports.evolveBuild=Le;exports.evolveServe=Ue;exports.evolveStatic=Ie;exports.flatBabelOptions=O;exports.flatExternalOptions=M;exports.flatLessLoaderOptions=D;exports.flatPerformanceOptions=N;exports.flatPostcssLoaderOptions=T;exports.getHtmlPluginConfig=F;exports.loadEvolveConfiguration=H;exports.loadModule=P;exports.normalizeEntries=ze;exports.polyfill=x;exports.terserOptions=W;exports.viewportScripts=q;
4
+ extractComments:false,terserOptions:t.merge({ecma:undefined,parse:{},compress:{},mangle:true,module:false,output:null,toplevel:false,nameCache:null,ie8:false,keep_classnames:undefined,keep_fnames:false,safari10:false},e)});const H=(n=process.cwd(),r)=>{const s=e.loadFlatjsConfig(n,"flatjsEvolve","flatjs.evolve.js");return t.merge({},$.flatjsEvolve,s.flatjsEvolve,r,{projectCwd:n})};const z=e=>{try{k(e)}catch(e){console.warn(`Unable to open browser. If you are running in a headless environment\n`)}};function L(e="",t=""){return e.replace(/\/$/,"")+"/"+t.replace(/^\//,"")}function U(e,t){const n=new RegExp("[?&]env(=([^&#]*)|&|#|$)");const r=window.location.href;const s=n.exec(r);let o=s&&s[2]?decodeURIComponent(s[2].replace(/\+/g," ")):"prod";o=t(r)||o;const i=e[o]||e["prod"]||[];const a=i[Math.floor(Math.random()*i.length)];return a.replace(/\/$/,"")+"/"}function I(e={},t="prod"){const n=e[t]||e["prod"]||[];return n[Math.floor(Math.random()*n.length)]}function J(e,t=(()=>undefined)){return`window.evolveFetchMicroWidgets = function () {\n var cdnConfig = ${JSON.stringify(e)};\n var cdnResolver = ${t.toString()};\n var cdnFinder = ${U.toString()};\n return (cdnFinder(cdnConfig, cdnResolver) || '').replace(/\\/$/, '');\n }`}function V(e,n){const r=[];for(const[t,n]of Object.entries(e)){r.push({[t]:n.entry})}return r.map((e=>t.merge({},n,{name:Object.keys(e)[0],entry:e})))}const _=(e,n)=>{var r,s;const o=t.merge({},n.pluginLoaderOptions);if(typeof((r=e.options)==null?void 0:r.allowPx2rem)!=="undefined"){t.set(o,"pixelOptions.enabled",e.options.allowPx2rem)}if(typeof((s=e.options)==null?void 0:s.enableBundleHashName)!=="undefined"){t.set(o,"enableBundleHashName",e.options.enableBundleHashName)}const i={...n,pluginLoaderOptions:o};return i};const G=(e,t)=>{var n,r;const s=(n=e.pluginLoaderOptions)==null?void 0:(r=n.pixelOptions)==null?void 0:r.enabled;const o=(t==null?void 0:t.allowPx2rem)??s;return!!o};const K=e=>{if(Object.keys(e).length>1){throw new Error(`Only single one entry map support now while "serve", "build" process!`)}let t=undefined;for(const[n,r]of Object.entries(e)){t=[n,r];break}if(!t){throw new Error(`No entry map found while "serve", "build" process!`)}return t};const X=()=>Date.now().toString();const Y=(e,t,n=true)=>{const r=e==="js"?".js":".css";if(t){return`bundle${r}`}if(n){return`bundle[contenthash]${r}`}return`bundle${r}?${X()}`};const Q=/svg-icons\//;const Z=/\.(jpe?g|png|gif|svg)$/;const ee=/\.(ttf|eot|woff|woff2)(\?.+)?$/;const te=e=>Q.test(e)&&e.endsWith(".svg");const ne=({projectCwd:e,projectVirtualPath:t},n,[r,o])=>{let i=s.dirname(s.join(t,n.replace(/^src/,"")));const a=o.entry.map((t=>s.dirname(s.join(e,t))));const l=s.resolve(e,n);const c=a.find((e=>l.startsWith(e)));if(c){i=s.dirname(s.join(r,s.relative(c,l)))}return`${i}/[name]-[contenthash:8][ext]`};const re=(e,t)=>{const n={test(e){return ee.test(e)||Z.test(e)&&!te(e)},type:"asset",generator:{filename({filename:n}){return ne(e,n,t)}},parser:{dataUrlCondition:{maxSize:4*1024}}};return n};const se=()=>{const e={test(e){return te(e)},use:[{loader:require.resolve("./loader-icon"),options:{svgo:{plugins:[{name:"removeTitle"},{name:"removeDimensions"}]}}}]};return e};function oe(e,n){const r=t.isFunction(e)?e(n):e;if(r.usePreset==="react"&&n){if(r.plugins){r.plugins.push(require.resolve("react-refresh/babel"))}else{r.plugins=[require.resolve("react-refresh/babel")]}}return r}const ie=(e,n={})=>{const{babelOptions:r={},modularImports:s=[]}=n;const o=oe(r,e);const i=t.isFunction(s)?s(e):s;const a=O(o,i);const l={test:/\.(tsx|ts|js|jsx)$/,use:[{loader:require.resolve("babel-loader"),options:a}]};return l};const ae=(e,t={})=>{const n={test:/\.css$/i,use:[{loader:l.loader,options:{esModule:true}},{loader:"css-loader",options:{sourceMap:e}}]};const{pixelOptions:r,cssnanoOptions:s}=t;if(Array.isArray(n.use)){n.use.push({loader:"postcss-loader",options:{postcssOptions:T(e,r,s),sourceMap:e}})}return n};const le=(e,t={})=>{const n=ae(e,t);n.test=/\.less$/i;const r=t.lessOptions;if(Array.isArray(n.use)){n.use.push({loader:require.resolve("less-loader"),options:{sourceMap:e,lessOptions:D(e,r)}})}return n};const ce=(e,t,n,r={})=>{const s=[se(),re(t,n),ae(e,r),le(e,r),ie(e,r)];return s};const pe=new Map;const ue=()=>{const t=[["svgo",{}],["gifsicle",{}],["jpegtran",{}],["pngquant",{}]];const n=t.map((t=>{const n=t[0];try{require.resolve(`imagemin-${n}`);return t}catch(t){if(!pe.get(n)){pe.set(n,true);const t=c.magenta(`"${e.hasYarn()?"yarn add":"npm install"} imagemin-${n} -D"`);e.Logger.warn(`Execute ${t} for assets optimization`,"@flatjs/evolve")}return null}})).filter(Boolean);if(n.length){return new p({minimizer:{implementation:p.imageminMinify,options:{plugins:n}}})}return null};const de=e=>new u(W(e.minimizeTerserOptions));const me=(e,t)=>{if(e){return[]}return[de(t),ue()].filter(Boolean)};class fe{constructor(e={}){this.verbose=void 0;this.cleanStaleWebpackAssets=void 0;this.protectWebpackAssets=void 0;this.cleanAfterEveryBuildPatterns=void 0;this.cleanOnceBeforeBuildPatterns=void 0;this.currentAssets=void 0;this.initialClean=void 0;this.outputPath=void 0;this.verbose=e.verbose===true||false;this.cleanStaleWebpackAssets=e.cleanStaleWebpackAssets===true||e.cleanStaleWebpackAssets===false?e.cleanStaleWebpackAssets:true;this.protectWebpackAssets=e.protectWebpackAssets===true||e.protectWebpackAssets===false?e.protectWebpackAssets:true;this.cleanAfterEveryBuildPatterns=Array.isArray(e.cleanAfterEveryBuildPatterns)?e.cleanAfterEveryBuildPatterns:[];this.cleanOnceBeforeBuildPatterns=Array.isArray(e.cleanOnceBeforeBuildPatterns)?e.cleanOnceBeforeBuildPatterns:["**/*"];this.currentAssets=[];this.initialClean=false;this.outputPath="";this.apply=this.apply.bind(this);this.handleInitial=this.handleInitial.bind(this);this.handleDone=this.handleDone.bind(this);this.removeFiles=this.removeFiles.bind(this)}apply(e){if(!e.options.output||!e.options.output.path){console.warn("clean-webpack-plugin: options.output.path not defined. Plugin disabled...");return}this.outputPath=e.options.output.path;const t=e.hooks;if(this.cleanOnceBeforeBuildPatterns.length!==0){t.emit.tap("clean-webpack-plugin",(e=>{this.handleInitial(e)}))}t.done.tap("clean-webpack-plugin",(e=>{this.handleDone(e)}))}handleInitial(e){if(this.initialClean){return}const t=e.getStats();if(t.hasErrors()){return}this.initialClean=true;this.removeFiles(this.cleanOnceBeforeBuildPatterns)}handleDone(e){if(e.hasErrors()){if(this.verbose){console.warn("clean-webpack-plugin: pausing due to webpack errors")}return}const t=e.toJson({assets:true}).assets||[];const n=t.map((e=>e.name));const r=this.currentAssets.filter((e=>{const t=n.includes(e)===false;return t}));this.currentAssets=n.sort();const s=[];if(this.cleanStaleWebpackAssets===true&&r.length!==0){s.push(...r)}if(this.cleanAfterEveryBuildPatterns.length!==0){s.push(...this.cleanAfterEveryBuildPatterns)}if(s.length!==0){this.removeFiles(s)}}removeFiles(t){try{const n=e.delFilesSync(t,{cwd:this.outputPath,dot:true,ignore:this.protectWebpackAssets?this.currentAssets:[]});if(this.verbose){n.forEach((e=>{const t=s.relative(process.cwd(),e);const n="removed";console.warn(`clean-webpack-plugin: ${n} ${t}`)}))}}catch(e){const t=/Cannot delete files\/folders outside the current working directory\./.test(e.message);if(t){const e="clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the `dangerouslyAllowCleanPatternsOutsideProject` option.";throw new Error(e)}throw e}}}const ve=t=>new fe({verbose:true,cleanOnceBeforeBuildPatterns:[`${s.join(e.ensureSlash(t[0],true),"**/*")}`]});const he=(e,t)=>new l({filename:`[name]/${Y("css",e,t==null?void 0:t.enableBundleHashName)}`,chunkFilename:"[id].[contenthash].css"});const ge="ExternalTemplateRemotesPlugin";const be=e=>e.constructor.name==="ExternalModule";class ye{apply(e){e.hooks.make.tap(ge,(e=>{const t=[];e.hooks.buildModule.tap(ge,(e=>{if(be(e)&&e.externalType==="script"){t.push(e)}}));e.hooks.afterCodeGeneration.tap(ge,(()=>{t.map((t=>{const n=g(t.request)[0];const r=we(n);const s=e.codeGenerationResults.get(t,undefined).sources;const o=s.get("javascript");if(o){const e=new h.RawSource(o.source().toString().replace(`"${n}"`,r));s.set("javascript",e)}}))}))}))}}function we(e){const t=[];const n=[];let r=false;let s=false;for(const o of e){if(o==="["){if(r){s=true;break}r=true;if(n.length){t.push(`"${n.join("")}"`);n.length=0}}else if(o==="]"){if(!r){s=true;break}r=false;if(n.length){t.push(`${n.join("")}`);n.length=0}n.length=0}else{n.push(o)}}if(r||s){throw new Error(`Invalid template URL "${e}"`)}if(n.length){t.push(`"${n.join("")}"`)}return t.join(" + ")}const je=`HtmlInjectScriptPlugin`;class Ce{constructor(e){this.scripts=void 0;this.scripts=e||[]}processScripts(){return this.scripts.filter(Boolean).map((e=>({tagName:"script",innerHTML:e,voidTag:false,attributes:{},meta:{plugin:"html-inject-script-webpack-plugin"}})))}apply(e){e.hooks.compilation.tap(`${je}_compilation`,(e=>{const t=b.getHooks(e);t.alterAssetTags.tap(`${je}_alterAssetTags`,(e=>{e.assetTags.scripts.unshift(...this.processScripts());return e}))}))}}const ke=(e="")=>e.replace(/[\/-]/gi,"_").toLowerCase();const Se=e=>s.join(e,`micro-remote-module.js`);const Pe=(t,[n,r],s)=>{var o;const i=s.multiHtmlCdn;const l=s.multiHtmlCdnResolver;const c=(o=r.options)==null?void 0:o.moduleFederation;const p=[];if(c){const{remotes:r,...s}=c;const o=Se(n);const u=ke(n);const d=(r||[]).map((({name:t,endpoint:n})=>{const r=ke(t);const s=Se(t);const o=n?e.ensureSlash(n(t),false):`[window.evolveFetchMicroWidgets()]`;return{[r]:`${r}@${o}/${s}`}}));p.push(new a.container.ModuleFederationPlugin({name:u,filename:o,remotes:d,...s}),new ye);if(!t){p.unshift(new Ce([J(i,l)]))}}return p};const Oe={minifyJS:true,removeComments:true,collapseWhitespace:true,collapseBooleanAttributes:false};const xe=(e,t,[n,r],s)=>{const o=[];const{options:i}=r;const a=e?"development":"production";for(const e of s){o.push(new b({inject:"body",title:F("title",a,i==null?void 0:i.title),chunks:[n],minify:(i==null?void 0:i.minify)===false?false:["me","dev"].includes(e)?false:Oe,filename:`${n}/index${e==="prod"?"":`-${e}`}.html`,template:F("template",a,i==null?void 0:i.template).replace(`{0}`,e),templateParameters:{title:F("title",a,i==null?void 0:i.title),favicon:F("favicon",a,i==null?void 0:i.favicon),inlineScripts:F("inlineScripts",a,i==null?void 0:i.inlineScripts),headBeforeStyles:F("headBeforeStyles",a,i==null?void 0:i.headBeforeStyles),headBeforeScripts:F("headBeforeScripts",a,i==null?void 0:i.headBeforeScripts),bodyAfterScripts:F("bodyAfterScripts",a,i==null?void 0:i.bodyAfterScripts),viewport:G(t,i)?F("viewport",a,i==null?void 0:i.viewport):""},multiCdn:{env:e,disabled:((i==null?void 0:i.excludeCdnEnvs)||["me","dev","ntv"]).includes(e)}}))}return o};class Ae{constructor(e){var t;this.pluginName="FlatEvolveMultiCdnPlugin";this.requireFn=a.RuntimeGlobals.publicPath;this.config=void 0;this.cdnResolver=void 0;this.config=e.multiHtmlCdn;this.cdnResolver=e.multiHtmlCdnResolver||(()=>undefined);if(!((t=this.config)!=null&&t.prod)){throw new Error("We must setup `prod` for each CDN config node!")}}apply(e){e.hooks.thisCompilation.tap(this.pluginName,(e=>{e.mainTemplate.hooks.requireExtensions.tap(this.pluginName,((t,n)=>{var r;const s=[];s.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)");const o=(r=e.chunkGraph)==null?void 0:r.getTreeRuntimeRequirements(n);if(o&&o.has(a.RuntimeGlobals.requireScope)){s.push("(function () {");s.push(a.Template.indent(`var flatjsMultiCdn = {`));s.push(a.Template.indent(a.Template.indent([`cdnConfig: ${JSON.stringify(this.config||{})},`])));s.push(a.Template.indent(a.Template.indent([`cdnResolver: ${this.cdnResolver.toString()},`])));s.push(a.Template.indent(a.Template.indent([`cdnFinder: ${U.toString()}`])));s.push(a.Template.indent(`};`));s.push(a.Template.indent(`${this.requireFn} = flatjsMultiCdn.cdnFinder(flatjsMultiCdn.cdnConfig, flatjsMultiCdn.cdnResolver) || ${this.requireFn};`));s.push("})();")}return a.Template.asString(s)}))}));e.hooks.compilation.tap(this.pluginName,(e=>{b.getHooks(e).beforeAssetTagGeneration.tap(this.pluginName,(e=>{const{assets:t}=e;const{userOptions:n}=e.plugin;const r=n.multiCdn;const o=t.publicPath;const i=t.js.map((e=>{if(r.disabled){return s.basename(e)}const t=I(this.config,r.env);return L(t,e.replace(o,""))}));const a=t.css.map((e=>{if(r.disabled){return s.basename(e)}const t=I(this.config,r.env);return L(t,e.replace(o,""))}));e.assets.js=i;e.assets.css=a;return e}))}))}}const Be=(e,t,n)=>{var r;const s=[new m];if(n.analyzer){s.push(new v.BundleAnalyzerPlugin({analyzerPort:"auto",analyzerMode:"server",...n.analyzer}))}s.push(new f({async:e}));s.push(he(e,n.pluginLoaderOptions));s.push(...Pe(e,t,n));if(!e){s.push(ve(t));const r=Object.keys(n.multiHtmlCdn);s.push(...xe(e,n,t,r));s.push(new Ae(n))}const o=oe(((r=n.pluginLoaderOptions)==null?void 0:r.babelOptions)||{},e);if(o.usePreset==="react"&&e){s.push(new d({overlay:false}))}return s};const Ee=(n,r,o,i)=>{process.env.NODE_ENV=n;r=r==="auto"?"auto":e.ensureSlash(r,true);const a=n==="development";const l=i.projectCwd;const c=i.pluginLoaderOptions;const p=i.watchOptions;const u=K(o);const d=t.isFunction(i.extraLoaders)?i.extraLoaders(a):i.extraLoaders;const m=[...ce(a,i,u,c),...d||[]];const f=t.isFunction(i.extraPlugins)?i.extraPlugins(a):i.extraPlugins;const v=t.isFunction(i.resolveAlias)?i.resolveAlias(a):i.resolveAlias;const h=[...Be(a,u,i),...f||[]];const g={mode:n,target:i.target,stats:{preset:"minimal"},infrastructureLogging:{level:"warn"},devtool:a?"eval-source-map":i.productionSourceMap||false,plugins:h,watchOptions:p,context:l,cache:{type:"memory"},resolve:{mainFields:["browser","module","main"],extensions:[".ts",".tsx",".js",".json",".vue"],alias:v||{}},module:{rules:m},externals:M(a,i.externals,u),performance:N(a,i.performance),output:{devtoolModuleFilenameTemplate:({namespace:e,resourcePath:t})=>`webpack:///${s.join(e,t)}`,environment:{},pathinfo:false,path:s.join(l,"public"),publicPath:r,filename:`[name]/${Y("js",a,c==null?void 0:c.enableBundleHashName)}`,chunkFilename:`[id].[contenthash].js`},optimization:{nodeEnv:a?"development":"production",chunkIds:a?"named":"named",moduleIds:a?"named":"named",minimize:i.minimize===false?false:a?false:true,minimizer:me(a,i),splitChunks:{name:false,chunks:"all",minSize:25e5,cacheGroups:{default:false,defaultVendors:false}}}};return g};const $e=(e,t,n)=>{const r=Ee("production",t,e,n);const s=V(e,r);if(s.length>1){throw new Error("startSingleEntryBuild() only support `compiler` at a time")}const o=s[0];return new Promise(((e,t)=>{a(o,((r,s)=>{var i,a;if(r){return t(r)}const l=s==null?void 0:s.toJson();if(l!=null&&(i=l.errors)!=null&&i.length){return t(l.errors)}if(n.forBuild.rejectWarnings&&l!=null&&(a=l.warnings)!=null&&a.length){return t(l.warnings)}e({name:o.name,warningStats:l==null?void 0:l.warnings})}))}))};const Me=async(t,n)=>{var r;await e.keepPackageDepsUpToDateForNonMonoRepo({cwd:process.cwd(),autoUpgrade:true,needVerifyPackages:n.needVerifyPackages||{}});const s=((r=n.multiHtmlCdn)==null?void 0:r.prod)||[];const o=[];const i=e.ensureSlash(s[Math.floor(Math.random()*s.length)],true);for(const[e,r]of Object.entries(t)){var a;const t=_(r,n);const s={[e]:r};const l=(a=r.options)==null?void 0:a.useRelativeAssetPath;o.push($e(s,l?"auto":i,t))}return Promise.all(o)};const qe=async(n,r,o)=>{const i=await e.getPackageDir(__dirname,process.cwd());const a=C.readFileSync(s.join(i,"./templates/main.html"),"utf-8");const l=[];for(const[t,s]of Object.entries(o.entryMap)){var c;const i=((c=s.options)==null?void 0:c.servePageMainLinkFn)||(e=>e);const a=Object.keys(n).includes(t);const p=o.projectVirtualPath.replace(/^\//,"");l.push({name:t.replace(p,"").replace(/^\//,""),link:i(e.urlJoin(r,["pages",t],{env:"me"}),{hostUri:r,entryName:t,virtualPath:p}),flagText:a?"serve":"static",isServed:a?1:0})}const p={title:"@flatjs/evolve",modules:l.sort(((e,t)=>t.isServed-e.isServed))};return t.template(a)(p)};const Re=async(n,r,o,i,a,l)=>{const c=l.entryMap;const p=Object.keys(c).sort(((e,t)=>t.length-e.length));const u=await e.getPackageDir(__dirname,process.cwd());const d=p.find((t=>e.ensureSlash(o.path.replace(/^\//,""),true).startsWith(e.ensureSlash(t,true))));if(!d){const e=C.readFileSync(s.join(u,`./templates/module-404.html`),"utf-8");return t.template(e)({title:"404 Not Found",errorMeta:[{name:`@flatjs/evolve workspace`,value:u},{name:`served entry names`,value:JSON.stringify(p)},{name:`module path`,value:`${o.path}`}]})}const m=c[d];const f=m.options;const v=n[d];const h=(v==null?void 0:v.devServerHostUri)||i;const g=(f==null?void 0:f.serveModuleTemplate)||"./templates/module.html";const b=s.join(l.projectCwd,"./templates/module.html");const y=C.readFileSync(s.isAbsolute(g)?g:e.existsSync(b)?b:s.join(u,"./templates/module.html"),"utf-8");const w=l.forServe;const j=w.defaultServeGlobalData?w.defaultServeGlobalData(m,i):{};const k={title:F("title",r,f==null?void 0:f.title),favicon:F("favicon",r,f==null?void 0:f.favicon),viewport:G(l,f)?F("viewport",r,f==null?void 0:f.viewport):"",inlineScripts:F("inlineScripts",r,f==null?void 0:f.inlineScripts),headBeforeStyles:F("headBeforeStyles",r,f==null?void 0:f.headBeforeStyles),headBeforeScripts:F("headBeforeScripts",r,f==null?void 0:f.headBeforeScripts),bodyAfterScripts:F("bodyAfterScripts",r,f==null?void 0:f.bodyAfterScripts),moduleFederationScripts:J({me:[e.urlJoin(i,["public"])]},l.multiHtmlCdnResolver),global:{hostUrl:i,apiBase:e.urlJoin(i,[a]),routeBaseName:s.join(`/pages`,d),moduleName:d.replace(l.projectVirtualPath,"").replace(/^\//,""),...j,...(f==null?void 0:f.serveGlobalData)||{}},styles:[e.urlJoin(h,[s.join("public",d,"bundle.css")])],scripts:[e.urlJoin(h,[s.join("public",d,"bundle.js")])]};return t.template(y)(k)};const Fe=(e,t,n,r,s)=>{const o=async(o,i)=>{let a;if(o.path==="/"){a=await qe(r,t,s)}else{a=await Re(r,e,o,t,n,s)}i.send(a)};return(s.forServe.pageMiddlewares||[]).concat(o)};const De=t=>async(n,r)=>{const o=n.baseUrl;if(!o.startsWith("/public")){r.redirect("/pages")}else{const n=await e.fileWalk(s.join("public/","**/*.{js,css}"),{cwd:t});const i=s.extname(o);const a=n.find((e=>s.extname(e)===i&&e.indexOf(o.replace(/\.(js|css)$/,""))!==-1));if(a){r.sendFile(a)}else{r.sendFile(s.join(t,o))}}};const Te=(e,t="development",r,s,o,i,a)=>{const l=w();n.attachMockMiddlewares(l,a,i.projectCwd);l.set("hostUri",s);l.use("/pages",...Fe(t,s,a.apiContext||"api",o,i));l.use("*",De(e));return new Promise((e=>{const t=i.https?j.createServer(i.https,l):l;t.listen(r,(()=>{e(true)}))}))};const Ne=(e,t,n)=>{const{projectCwd:r,https:o,liveReload:i}=n;const a=new y({server:{type:o?"https":"http",options:{...o}},open:false,compress:true,port:t,hot:!i,liveReload:i,allowedHosts:"all",static:{directory:`${s.join(r,"/public")}`},headers:{"Access-Control-Allow-Origin":"*"},client:{progress:true,overlay:{errors:true,warnings:false}}},e);return new Promise(((e,t)=>{a.startCallback((n=>{if(n){return t(n)}e(true)}))}))};const We=async(r,o,i,l)=>{await e.keepPackageDepsUpToDateForNonMonoRepo({cwd:process.cwd(),autoUpgrade:true,needVerifyPackages:i.needVerifyPackages||{}});if(i.https){l.https=i.https}const{mockPort:p,hostUri:u}=await n.prepareMockDomain(l);const d=e.urlJoin(u,["/pages"]);let m=p;const f=[];const v={};for(const[e]of Object.entries(o)){m=m+1;const{mockPort:r,hostUri:s}=await n.prepareMockDomain(t.merge({},l,{port:m}));v[e]={devServerPort:r,devServerHostUri:s}}for(const[t,n]of Object.entries(o)){var h,g;const o=((h=n.options)==null?void 0:(g=h.moduleFederation)==null?void 0:g.remotes)||[];o.forEach((t=>{t.endpoint=t=>{var n;return e.urlJoin(((n=v[t])==null?void 0:n.devServerHostUri)||u,["/public"])}}));const{devServerPort:l,devServerHostUri:p}=v[t];const m=e.urlJoin(p,["public"]);const b={[t]:n};const y=_(n,i);const w=Ee("development",m,b,y);const j=a.webpack(V(b,w)[0]);f.push(Ne(j,l,i));const C=c.bgBlack(`[${c.magenta("@flatjs")}:${c.bold(j.name||"")}]`);j.hooks.invalid.tap("fileChange",(e=>{console.log(C,`${"file change".padEnd(12," ")} ➩ ${c.cyan(s.relative(r,e||""))}`)}));j.hooks.done.tap("compileDone",(()=>{console.log(C,`${"serve page".padEnd(12," ")} ➩ ${c.cyan(d)}`)}))}await Te(r,"development",p,u,v,i,l);z(d);return Promise.all(f).then((()=>true))};const He=async(t,r,s)=>{if(r.https){s.https=r.https}const{mockPort:o,hostUri:i}=await n.prepareMockDomain(s);const a=e.urlJoin(i,["/pages"]);return Te(t,"development",o,i,{},r,s).then((e=>{const t=c.bgBlack(`[${c.magenta("@flatjs")}:`);console.log(t,`${"serve page".padEnd(12," ")} ➩ ${c.cyan(a)}`);return e}))};const ze=(e={},n={})=>{const r={};for(const[s,o]of Object.entries(n)){const n={options:{}};if(e[s]){r[s]=t.merge({},n,o,e[s])}t.merge(o,n)}return r};const Le=(e,t,n={})=>{const r=H(e,n);const s=ze(t,r.entryMap);return Me(s,r)};const Ue=(e,t,r={},s={})=>{const o=H(e,r);const i=n.loadMockConfiguration(e,s);const a=ze(t,o.entryMap);return We(e,a,o,i)};const Ie=(e,t={},r={})=>{const s=H(e,t);const o=n.loadMockConfiguration(e,r);return He(e,s,o)};exports.cdnBoot=E;exports.cdnJsDelivr=B;exports.cdnUnpkg=A;exports.createPageMiddleware=Fe;exports.createPublicAssetsMiddleware=De;exports.defaultFlatjsConfig=$;exports.evolveBuild=Le;exports.evolveServe=Ue;exports.evolveStatic=Ie;exports.flatBabelOptions=O;exports.flatExternalOptions=M;exports.flatLessLoaderOptions=D;exports.flatPerformanceOptions=N;exports.flatPostcssLoaderOptions=T;exports.getHtmlPluginConfig=F;exports.loadEvolveConfiguration=H;exports.loadModule=P;exports.normalizeEntries=ze;exports.polyfill=x;exports.terserOptions=W;exports.viewportScripts=q;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "1.5.22",
3
+ "version": "1.5.24",
4
4
  "description": "the webpack based tools `evolve` of @flatjs",
5
5
  "keywords": [
6
6
  "shared",
@@ -22,11 +22,11 @@
22
22
  "package.json"
23
23
  ],
24
24
  "dependencies": {
25
- "@babel/core": "^7.20.12",
26
- "@flatjs/common": "^1.5.19",
27
- "@flatjs/evolve-preset-babel": "^1.5.12",
25
+ "@babel/core": "^7.21.4",
26
+ "@flatjs/common": "^1.5.24",
27
+ "@flatjs/evolve-preset-babel": "^1.5.23",
28
28
  "@flatjs/forge-plugin-postcss-pixel": "^1.5.0",
29
- "@flatjs/mock": "^1.5.19",
29
+ "@flatjs/mock": "^1.5.24",
30
30
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
31
31
  "babel-loader": "^9.1.2",
32
32
  "babel-merge": "^3.0.0",
@@ -35,37 +35,37 @@
35
35
  "case-sensitive-paths-webpack-plugin": "^2.4.0",
36
36
  "chalk": "^4.1.2",
37
37
  "css-loader": "^6.7.3",
38
- "cssnano": "^5.1.14",
39
- "cssnano-preset-default": "^5.2.13",
38
+ "cssnano": "^6.0.0",
39
+ "cssnano-preset-default": "^6.0.0",
40
40
  "fork-ts-checker-webpack-plugin": "^8.0.0",
41
41
  "html-webpack-plugin": "^5.5.0",
42
- "image-minimizer-webpack-plugin": "^3.8.1",
42
+ "image-minimizer-webpack-plugin": "^3.8.2",
43
43
  "imagemin": "^8.0.1",
44
44
  "less": "^4.1.3",
45
45
  "less-loader": "^11.1.0",
46
46
  "lodash": "^4.17.21",
47
- "mini-css-extract-plugin": "^2.7.2",
47
+ "mini-css-extract-plugin": "^2.7.5",
48
48
  "postcss": "^8.4.21",
49
- "postcss-loader": "^7.0.2",
49
+ "postcss-loader": "^7.2.4",
50
50
  "react-refresh": "^0.14.0",
51
51
  "svgo": "^3.0.2",
52
- "terser-webpack-plugin": "^5.3.6",
53
- "webpack": "^5.75.0",
54
- "webpack-bundle-analyzer": "^4.7.0",
55
- "webpack-dev-server": "4.11.1",
52
+ "terser-webpack-plugin": "^5.3.7",
53
+ "webpack": "^5.78.0",
54
+ "webpack-bundle-analyzer": "^4.8.0",
55
+ "webpack-dev-server": "4.13.2",
56
56
  "webpack-sources": "^3.2.3"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/cssnano": "^5.0.0",
60
- "@types/lodash": "^4.14.191",
60
+ "@types/lodash": "^4.14.192",
61
61
  "@types/webpack-sources": "^3.2.0",
62
62
  "express": "^4.18.2",
63
63
  "imagemin-gifsicle": "^7.0.0",
64
64
  "imagemin-jpegtran": "^7.0.0",
65
65
  "imagemin-pngquant": "^9.0.2",
66
66
  "imagemin-svgo": "^10.0.1",
67
- "sharp": "^0.31.3",
68
- "type-fest": "^3.5.4"
67
+ "sharp": "^0.32.0",
68
+ "type-fest": "^3.8.0"
69
69
  },
70
70
  "engines": {
71
71
  "node": ">=16.0.0"
@@ -73,5 +73,5 @@
73
73
  "publishConfig": {
74
74
  "access": "public"
75
75
  },
76
- "gitHead": "5d3dfba4e0cb12afb753c083554d5dc725fc9657"
76
+ "gitHead": "7ed70b185902b03c723849d0e498a73801f56333"
77
77
  }