@flatjs/evolve 1.5.20 → 1.5.21

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 +2 -2
  2. package/package.json +3 -2
package/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  /*! @flatjs/forge MIT @flatjs/evolve */
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("webpack-bundle-analyzer");var h=require("webpack-sources");var v=require("webpack/lib/util/extractUrlAndGlobal");var g=require("html-webpack-plugin");var b=require("webpack-dev-server");var y=require("express");var w=require("https");var j=require("fs");var C=require("better-opn");function k(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 S=(e,t=false)=>{if(!t){return require(e)}else{return n.loadModule(e)}};const P=(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}=S(k("@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 O=[`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 x={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 A={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 B={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 E={flatjsEvolve:{projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",forBuild:{rejectWarnings:false},forServe:{pageMiddlewares:[],defaultServeGlobalData:()=>({})},target:["web","es5"],liveReload:false,minimizeTerserOptions:{},multiHtmlCdn:{},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 $=(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 M=`(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 q={title:"",favicon:"",inlineScripts:()=>[],headBeforeStyles:()=>[],headBeforeScripts:e=>[...O,...e==="development"?B.reactDev:B.reactProd],bodyAfterScripts:()=>[],viewport:M,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=q[e];return typeof t==="function"?t(n):t}return s};const D=(e,t)=>Object.assign({sourceMap:e,javascriptEnabled:true},t);const R=(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 T=(e,t={})=>{const n={hints:e?false:"warning"};return Object.assign(n,t)};const N=(e={})=>({parallel:true,
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 h=require("webpack-bundle-analyzer");var v=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:{},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 F={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 D=(e,n,r)=>{let s;if(r){s=typeof r==="function"?r(n):r}if(t.isUndefined(s)){const t=F[e];return typeof t==="function"?t(n):t}return s};const R=(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 W=(n=process.cwd(),r)=>{const s=e.loadFlatjsConfig(n,"flatjsEvolve","flatjs.evolve.js");return t.merge({},E.flatjsEvolve,s.flatjsEvolve,r,{projectCwd:n})};const z=e=>{try{C(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){const t=new RegExp("[?&]env(=([^&#]*)|&|#|$)");const n=t.exec(window.location.href);const r=n&&n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):"prod";const s=e[r]||e["prod"]||[];const o=s[Math.floor(Math.random()*s.length)];return o.replace(/\/$/,"")+"/"}function H(e={},t="prod"){const n=e[t]||e["prod"]||[];return n[Math.floor(Math.random()*n.length)]}function I(e){return`window.evolveFetchMicroWidgets = function () {\n var cdnConfig = ${JSON.stringify(e)};\n var cdnFinder = ${U.toString()};\n return (cdnFinder(cdnConfig) || '').replace(/\\/$/, '');\n }`}function J(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 V=(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 _=(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 G=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 K=()=>Date.now().toString();const X=(e,t,n=true)=>{const r=e==="js"?".js":".css";if(t){return`bundle${r}`}if(n){return`bundle[contenthash]${r}`}return`bundle${r}?${K()}`};const Y=/svg-icons\//;const Q=/\.(jpe?g|png|gif|svg)$/;const Z=/\.(ttf|eot|woff|woff2)(\?.+)?$/;const ee=e=>Y.test(e)&&e.endsWith(".svg");const te=({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 ne=(e,t)=>{const n={test(e){return Z.test(e)||Q.test(e)&&!ee(e)},type:"asset",generator:{filename({filename:n}){return te(e,n,t)}},parser:{dataUrlCondition:{maxSize:4*1024}}};return n};const re=()=>{const e={test(e){return ee(e)},use:[{loader:require.resolve("./loader-icon"),options:{svgo:{plugins:[{name:"removeTitle"},{name:"removeDimensions"}]}}}]};return e};function se(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 oe=(e,n={})=>{const{babelOptions:r={},modularImports:s=[]}=n;const o=se(r,e);const i=t.isFunction(s)?s(e):s;const a=P(o,i);const l={test:/\.(tsx|ts|js|jsx)$/,use:[{loader:require.resolve("babel-loader"),options:a}]};return l};const ie=(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:R(e,r,s),sourceMap:e}})}return n};const ae=(e,t={})=>{const n=ie(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 le=(e,t,n,r={})=>{const s=[re(),ne(t,n),ie(e,r),ae(e,r),oe(e,r)];return s};const ce=new Map;const pe=()=>{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(!ce.get(n)){ce.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 ue=e=>new u(N(e.minimizeTerserOptions));const de=(e,t)=>{if(e){return[]}return[ue(t),pe()].filter(Boolean)};class me{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 fe=t=>new me({verbose:true,cleanOnceBeforeBuildPatterns:[`${s.join(e.ensureSlash(t[0],true),"**/*")}`]});const he=(e,t)=>new l({filename:`[name]/${X("css",e,t==null?void 0:t.enableBundleHashName)}`,chunkFilename:"[id].[contenthash].css"});const ve="ExternalTemplateRemotesPlugin";const ge=e=>e.constructor.name==="ExternalModule";class be{apply(e){e.hooks.make.tap(ve,(e=>{const t=[];e.hooks.buildModule.tap(ve,(e=>{if(ge(e)&&e.externalType==="script"){t.push(e)}}));e.hooks.afterCodeGeneration.tap(ve,(()=>{t.map((t=>{const n=v(t.request)[0];const r=ye(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 ye(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 we=`HtmlInjectScriptPlugin`;class je{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(`${we}_compilation`,(e=>{const t=g.getHooks(e);t.alterAssetTags.tap(`${we}_alterAssetTags`,(e=>{e.assetTags.scripts.unshift(...this.processScripts());return e}))}))}}const Ce=(e="")=>e.replace(/[\/-]/gi,"_").toLowerCase();const ke=e=>s.join(e,`micro-remote-module.js`);const Se=(t,[n,r],s)=>{var o;const i=(o=r.options)==null?void 0:o.moduleFederation;const l=[];if(i){const{remotes:r,...o}=i;const c=ke(n);const p=Ce(n);const u=(r||[]).map((({name:t,endpoint:n})=>{const r=Ce(t);const s=ke(t);const o=n?e.ensureSlash(n(t),false):`[window.evolveFetchMicroWidgets()]`;return{[r]:`${r}@${o}/${s}`}}));l.push(new a.container.ModuleFederationPlugin({name:p,filename:c,remotes:u,...o}),new be);if(!t){l.unshift(new je([I(s)]))}}return l};const Pe={minifyJS:true,removeComments:true,collapseWhitespace:true,collapseBooleanAttributes:false};const Oe=(e,t,[n,r],s)=>{const o=[];const{options:i}=r;const a=e?"development":"production";for(const e of s){o.push(new g({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:Pe,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:_(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 xe{constructor(e){var t;this.config=e;this.pluginName="FlatEvolveMultiCdnPlugin";this.requireFn=a.RuntimeGlobals.publicPath;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([`cdnFinder: ${U.toString()}`])));s.push(a.Template.indent(`};`));s.push(a.Template.indent(`${this.requireFn} = flatjsMultiCdn.cdnFinder(flatjsMultiCdn.cdnConfig) || ${this.requireFn};`));s.push("})();")}return a.Template.asString(s)}))}));e.hooks.compilation.tap(this.pluginName,(e=>{g.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=H(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=H(this.config,r.env);return L(t,e.replace(o,""))}));e.assets.js=i;e.assets.css=a;return e}))}))}}const Ae=(e,t,n)=>{var r;const s=[new m];if(n.analyzer){s.push(new f.BundleAnalyzerPlugin({analyzerPort:"auto",analyzerMode:"server",...n.analyzer}))}s.push(he(e,n.pluginLoaderOptions));s.push(...Se(e,t,n.multiHtmlCdn));if(!e){s.push(fe(t));const r=Object.keys(n.multiHtmlCdn);s.push(...Oe(e,n,t,r));s.push(new xe(n.multiHtmlCdn))}const o=se(((r=n.pluginLoaderOptions)==null?void 0:r.babelOptions)||{},e);if(o.usePreset==="react"&&e){s.push(new d({overlay:false}))}return s};const Be=(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=G(o);const d=t.isFunction(i.extraLoaders)?i.extraLoaders(a):i.extraLoaders;const m=[...le(a,i,u,c),...d||[]];const f=t.isFunction(i.extraPlugins)?i.extraPlugins(a):i.extraPlugins;const h=t.isFunction(i.resolveAlias)?i.resolveAlias(a):i.resolveAlias;const v=[...Ae(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:v,watchOptions:p,context:l,cache:{type:"memory"},resolve:{mainFields:["browser","module","main"],extensions:[".ts",".tsx",".js",".json",".vue"],alias:h||{}},module:{rules:m},externals:$(a,i.externals,u),performance:T(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]/${X("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:de(a,i),splitChunks:{name:false,chunks:"all",minSize:25e5,cacheGroups:{default:false,defaultVendors:false}}}};return g};const Ee=(e,t,n)=>{const r=Be("production",t,e,n);const s=J(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 $e=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=V(r,n);const s={[e]:r};const l=(a=r.options)==null?void 0:a.useRelativeAssetPath;o.push(Ee(s,l?"auto":i,t))}return Promise.all(o)};const Me=async(n,r,o)=>{const i=await e.getPackageDir(__dirname,process.cwd());const a=j.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 qe=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=j.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 h=n[d];const v=(h==null?void 0:h.devServerHostUri)||i;const g=(f==null?void 0:f.serveModuleTemplate)||"./templates/module.html";const b=s.join(l.projectCwd,"./templates/module.html");const y=j.readFileSync(s.isAbsolute(g)?g:e.existsSync(b)?b:s.join(u,"./templates/module.html"),"utf-8");const w=l.forServe;const C=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:_(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:I({me:[e.urlJoin(i,["public"])]}),global:{hostUrl:i,apiBase:e.urlJoin(i,[a]),routeBaseName:s.join(`/pages`,d),moduleName:d.replace(l.projectVirtualPath,"").replace(/^\//,""),...C,...(f==null?void 0:f.serveGlobalData)||{}},styles:[e.urlJoin(v,[s.join("public",d,"bundle.css")])],scripts:[e.urlJoin(v,[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 Me(r,t,s)}else{a=await qe(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 Re=(e,t="development",r,s,o,i,a)=>{const l=y();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?w.createServer(i.https,l):l;t.listen(r,(()=>{e(true)}))}))};const Te=(e,t,n)=>{const{projectCwd:r,https:o,liveReload:i}=n;const a=new b({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 Ne=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 h={};for(const[e]of Object.entries(o)){m=m+1;const{mockPort:r,hostUri:s}=await n.prepareMockDomain(t.merge({},l,{port:m}));h[e]={devServerPort:r,devServerHostUri:s}}for(const[t,n]of Object.entries(o)){var v,g;const o=((v=n.options)==null?void 0:(g=v.moduleFederation)==null?void 0:g.remotes)||[];o.forEach((t=>{t.endpoint=t=>{var n;return e.urlJoin(((n=h[t])==null?void 0:n.devServerHostUri)||u,["/public"])}}));const{devServerPort:l,devServerHostUri:p}=h[t];const m=e.urlJoin(p,["public"]);const b={[t]:n};const y=V(n,i);const w=Be("development",m,b,y);const j=a.webpack(J(b,w)[0]);f.push(Te(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 Re(r,"development",p,u,h,i,l);z(d);return Promise.all(f).then((()=>true)).catch((e=>{console.log("evolve serve err: ",e);return false}))};const We=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 Re(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=W(e,n);const s=ze(t,r.entryMap);return $e(s,r)};const Ue=(e,t,r={},s={})=>{const o=W(e,r);const i=n.loadMockConfiguration(e,s);const a=ze(t,o.entryMap);return Ne(e,a,o,i)};const He=(e,t={},r={})=>{const s=W(e,t);const o=n.loadMockConfiguration(e,r);return We(e,s,o)};exports.cdnBoot=B;exports.cdnJsDelivr=A;exports.cdnUnpkg=x;exports.createPageMiddleware=Fe;exports.createPublicAssetsMiddleware=De;exports.defaultFlatjsConfig=E;exports.evolveBuild=Le;exports.evolveServe=Ue;exports.evolveStatic=He;exports.flatBabelOptions=P;exports.flatExternalOptions=$;exports.flatLessLoaderOptions=D;exports.flatPerformanceOptions=T;exports.flatPostcssLoaderOptions=R;exports.getHtmlPluginConfig=F;exports.loadEvolveConfiguration=W;exports.loadModule=S;exports.normalizeEntries=ze;exports.polyfill=O;exports.terserOptions=N;exports.viewportScripts=M;
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 z=(n=process.cwd(),r)=>{const s=e.loadFlatjsConfig(n,"flatjsEvolve","flatjs.evolve.js");return t.merge({},$.flatjsEvolve,s.flatjsEvolve,r,{projectCwd:n})};const L=e=>{try{k(e)}catch(e){console.warn(`Unable to open browser. If you are running in a headless environment\n`)}};function U(e="",t=""){return e.replace(/\/$/,"")+"/"+t.replace(/^\//,"")}function H(e){const t=new RegExp("[?&]env(=([^&#]*)|&|#|$)");const n=t.exec(window.location.href);const r=n&&n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):"prod";const s=e[r]||e["prod"]||[];const o=s[Math.floor(Math.random()*s.length)];return o.replace(/\/$/,"")+"/"}function I(e={},t="prod"){const n=e[t]||e["prod"]||[];return n[Math.floor(Math.random()*n.length)]}function J(e){return`window.evolveFetchMicroWidgets = function () {\n var cdnConfig = ${JSON.stringify(e)};\n var cdnFinder = ${H.toString()};\n return (cdnFinder(cdnConfig) || '').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:R(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 he=t=>new fe({verbose:true,cleanOnceBeforeBuildPatterns:[`${s.join(e.ensureSlash(t[0],true),"**/*")}`]});const ve=(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 v.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=(o=r.options)==null?void 0:o.moduleFederation;const l=[];if(i){const{remotes:r,...o}=i;const c=Se(n);const p=ke(n);const u=(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}`}}));l.push(new a.container.ModuleFederationPlugin({name:p,filename:c,remotes:u,...o}),new ye);if(!t){l.unshift(new Ce([J(s)]))}}return l};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:D("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:D("template",a,i==null?void 0:i.template).replace(`{0}`,e),templateParameters:{title:D("title",a,i==null?void 0:i.title),favicon:D("favicon",a,i==null?void 0:i.favicon),inlineScripts:D("inlineScripts",a,i==null?void 0:i.inlineScripts),headBeforeStyles:D("headBeforeStyles",a,i==null?void 0:i.headBeforeStyles),headBeforeScripts:D("headBeforeScripts",a,i==null?void 0:i.headBeforeScripts),bodyAfterScripts:D("bodyAfterScripts",a,i==null?void 0:i.bodyAfterScripts),viewport:G(t,i)?D("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.config=e;this.pluginName="FlatEvolveMultiCdnPlugin";this.requireFn=a.RuntimeGlobals.publicPath;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([`cdnFinder: ${H.toString()}`])));s.push(a.Template.indent(`};`));s.push(a.Template.indent(`${this.requireFn} = flatjsMultiCdn.cdnFinder(flatjsMultiCdn.cdnConfig) || ${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 U(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 U(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 h.BundleAnalyzerPlugin({analyzerPort:"auto",analyzerMode:"server",...n.analyzer}))}s.push(new f({async:e}));s.push(ve(e,n.pluginLoaderOptions));s.push(...Pe(e,t,n.multiHtmlCdn));if(!e){s.push(he(t));const r=Object.keys(n.multiHtmlCdn);s.push(...xe(e,n,t,r));s.push(new Ae(n.multiHtmlCdn))}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 h=t.isFunction(i.resolveAlias)?i.resolveAlias(a):i.resolveAlias;const v=[...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:v,watchOptions:p,context:l,cache:{type:"memory"},resolve:{mainFields:["browser","module","main"],extensions:[".ts",".tsx",".js",".json",".vue"],alias:h||{}},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 Fe=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 h=n[d];const v=(h==null?void 0:h.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:D("title",r,f==null?void 0:f.title),favicon:D("favicon",r,f==null?void 0:f.favicon),viewport:G(l,f)?D("viewport",r,f==null?void 0:f.viewport):"",inlineScripts:D("inlineScripts",r,f==null?void 0:f.inlineScripts),headBeforeStyles:D("headBeforeStyles",r,f==null?void 0:f.headBeforeStyles),headBeforeScripts:D("headBeforeScripts",r,f==null?void 0:f.headBeforeScripts),bodyAfterScripts:D("bodyAfterScripts",r,f==null?void 0:f.bodyAfterScripts),moduleFederationScripts:J({me:[e.urlJoin(i,["public"])]}),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(v,[s.join("public",d,"bundle.css")])],scripts:[e.urlJoin(v,[s.join("public",d,"bundle.js")])]};return t.template(y)(k)};const De=(e,t,n,r,s)=>{const o=async(o,i)=>{let a;if(o.path==="/"){a=await qe(r,t,s)}else{a=await Fe(r,e,o,t,n,s)}i.send(a)};return(s.forServe.pageMiddlewares||[]).concat(o)};const Re=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",...De(t,s,a.apiContext||"api",o,i));l.use("*",Re(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 h={};for(const[e]of Object.entries(o)){m=m+1;const{mockPort:r,hostUri:s}=await n.prepareMockDomain(t.merge({},l,{port:m}));h[e]={devServerPort:r,devServerHostUri:s}}for(const[t,n]of Object.entries(o)){var v,g;const o=((v=n.options)==null?void 0:(g=v.moduleFederation)==null?void 0:g.remotes)||[];o.forEach((t=>{t.endpoint=t=>{var n;return e.urlJoin(((n=h[t])==null?void 0:n.devServerHostUri)||u,["/public"])}}));const{devServerPort:l,devServerHostUri:p}=h[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,h,i,l);L(d);return Promise.all(f).then((()=>true)).catch((e=>{console.log("evolve serve err: ",e);return false}))};const ze=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 Le=(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 Ue=(e,t,n={})=>{const r=z(e,n);const s=Le(t,r.entryMap);return Me(s,r)};const He=(e,t,r={},s={})=>{const o=z(e,r);const i=n.loadMockConfiguration(e,s);const a=Le(t,o.entryMap);return We(e,a,o,i)};const Ie=(e,t={},r={})=>{const s=z(e,t);const o=n.loadMockConfiguration(e,r);return ze(e,s,o)};exports.cdnBoot=E;exports.cdnJsDelivr=B;exports.cdnUnpkg=A;exports.createPageMiddleware=De;exports.createPublicAssetsMiddleware=Re;exports.defaultFlatjsConfig=$;exports.evolveBuild=Ue;exports.evolveServe=He;exports.evolveStatic=Ie;exports.flatBabelOptions=O;exports.flatExternalOptions=M;exports.flatLessLoaderOptions=R;exports.flatPerformanceOptions=N;exports.flatPostcssLoaderOptions=T;exports.getHtmlPluginConfig=D;exports.loadEvolveConfiguration=z;exports.loadModule=P;exports.normalizeEntries=Le;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.20",
3
+ "version": "1.5.21",
4
4
  "description": "the webpack based tools `evolve` of @flatjs",
5
5
  "keywords": [
6
6
  "shared",
@@ -37,6 +37,7 @@
37
37
  "css-loader": "^6.7.3",
38
38
  "cssnano": "^5.1.14",
39
39
  "cssnano-preset-default": "^5.2.13",
40
+ "fork-ts-checker-webpack-plugin": "^8.0.0",
40
41
  "html-webpack-plugin": "^5.5.0",
41
42
  "image-minimizer-webpack-plugin": "^3.8.1",
42
43
  "imagemin": "^8.0.1",
@@ -72,5 +73,5 @@
72
73
  "publishConfig": {
73
74
  "access": "public"
74
75
  },
75
- "gitHead": "9bc8e8c85ba56072c0c71d8af207f3d3e1511cb1"
76
+ "gitHead": "f3e0c0b5bbac7bea1cb447b9164f69eef5dcde95"
76
77
  }