@flatjs/evolve 1.5.27 → 1.5.29
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/index.js +1 -1
- package/package.json +4 -4
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 a=require("cssnano");var i=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 a=n.map((e=>[require.resolve("babel-plugin-import"),{transformToDefaultImport:false,libraryDirectory:"cjs",style:()=>false,...e},e.libraryName]));const{reactBabelPreset:i,infernoBabelPreset:l,vueBabelPreset:c}=P(S("@flatjs/evolve-preset-babel"));const p=s==="react"?i():s==="vue"?c():l();let u={};try{u=r(p,o);if(u.plugins){u.plugins.unshift(...a)}else{u.plugins=a}}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 E={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 $={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:()=>[],packageInstallChecker:{enabled:false,detectModules:["@dimjs/*"],throwError:false,showAllinstalledGraph:
|
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 a=require("cssnano");var i=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 a=n.map((e=>[require.resolve("babel-plugin-import"),{transformToDefaultImport:false,libraryDirectory:"cjs",style:()=>false,...e},e.libraryName]));const{reactBabelPreset:i,infernoBabelPreset:l,vueBabelPreset:c}=P(S("@flatjs/evolve-preset-babel"));const p=s==="react"?i():s==="vue"?c():l();let u={};try{u=r(p,o);if(u.plugins){u.plugins.unshift(...a)}else{u.plugins=a}}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 E={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 $={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:()=>[],packageInstallChecker:{enabled:false,detectModules:["@dimjs/*"],throwError:false,showAllinstalledGraph:true},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,a;const i=r[1];const l={vue:"Vue",react:"React","react-dom":"ReactDOM"};const c=t.isFunction(n)?n(e):n;const p=t.isFunction((s=i.options)==null?void 0:s.externals)?(o=i.options)==null?void 0:o.externals(e):(a=i.options)==null?void 0:a.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"?B.reactDev:B.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=[a({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 I=(e={})=>({parallel:true,
|
3
3
|
// Disable Extract all or some (use /^\**!|@preserve|@license|@cc_on/i RegExp) comments.
|
4
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({},$.flatjsEvolve,s.flatjsEvolve,r,{projectCwd:n})};const H=e=>{try{k(e)}catch(e){console.warn(`Unable to open browser. If you are running in a headless environment\n`)}};function z(e="",t=""){return e.replace(/\/$/,"")+"/"+t.replace(/^\//,"")}function L(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 a=e[o]||e["prod"]||[];const i=a[Math.floor(Math.random()*a.length)];return i.replace(/\/$/,"")+"/"}function U(e={},t="prod"){const n=e[t]||e["prod"]||[];return n[Math.floor(Math.random()*n.length)]}function G(e,t=(()=>undefined)){return`window.evolveFetchMicroWidgets = function () {\n var cdnConfig = ${JSON.stringify(e)};\n var cdnResolver = ${t.toString()};\n var cdnFinder = ${L.toString()};\n return (cdnFinder(cdnConfig, cdnResolver) || '').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 a={...n,pluginLoaderOptions:o};return a};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 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 a=s.dirname(s.join(t,n.replace(/^src/,"")));const i=o.entry.map((t=>s.dirname(s.join(e,t))));const l=s.resolve(e,n);const c=i.find((e=>l.startsWith(e)));if(c){a=s.dirname(s.join(r,s.relative(c,l)))}return`${a}/[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 ae=(e,n={})=>{const{babelOptions:r={},modularImports:s=[]}=n;const o=oe(r,e);const a=t.isFunction(s)?s(e):s;const i=O(o,a);const l={test:/\.(tsx|ts|js|jsx)$/,use:[{loader:require.resolve("babel-loader"),options:i}]};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:T(e,r,s),sourceMap:e}})}return n};const le=(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 ce=(e,t,n,r={})=>{const s=[se(),re(t,n),ie(e,r),le(e,r),ae(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(I(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 a=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 i.container.ModuleFederationPlugin({name:u,filename:o,remotes:d,...s}),new ye);if(!t){p.unshift(new Ce([G(a,l)]))}}return p};const Oe={minifyJS:true,removeComments:true,collapseWhitespace:true,collapseBooleanAttributes:false};const xe=(e,t,[n,r],s)=>{const o=[];const{options:a}=r;const i=e?"development":"production";for(const e of s){o.push(new b({inject:"body",title:F("title",i,a==null?void 0:a.title),chunks:[n],minify:(a==null?void 0:a.minify)===false?false:["me","dev"].includes(e)?false:Oe,filename:`${n}/index${e==="prod"?"":`-${e}`}.html`,template:F("template",i,a==null?void 0:a.template).replace(`{0}`,e),templateParameters:{title:F("title",i,a==null?void 0:a.title),favicon:F("favicon",i,a==null?void 0:a.favicon),inlineScripts:F("inlineScripts",i,a==null?void 0:a.inlineScripts),headBeforeStyles:F("headBeforeStyles",i,a==null?void 0:a.headBeforeStyles),headBeforeScripts:F("headBeforeScripts",i,a==null?void 0:a.headBeforeScripts),bodyAfterScripts:F("bodyAfterScripts",i,a==null?void 0:a.bodyAfterScripts),viewport:_(t,a)?F("viewport",i,a==null?void 0:a.viewport):""},multiCdn:{env:e,disabled:((a==null?void 0:a.excludeCdnEnvs)||["me","dev","ntv"]).includes(e)}}))}return o};class Ae{constructor(e){var t;this.pluginName="FlatEvolveMultiCdnPlugin";this.requireFn=i.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(i.RuntimeGlobals.requireScope)){s.push("(function () {");s.push(i.Template.indent(`var flatjsMultiCdn = {`));s.push(i.Template.indent(i.Template.indent([`cdnConfig: ${JSON.stringify(this.config||{})},`])));s.push(i.Template.indent(i.Template.indent([`cdnResolver: ${this.cdnResolver.toString()},`])));s.push(i.Template.indent(i.Template.indent([`cdnFinder: ${L.toString()}`])));s.push(i.Template.indent(`};`));s.push(i.Template.indent(`${this.requireFn} = flatjsMultiCdn.cdnFinder(flatjsMultiCdn.cdnConfig, flatjsMultiCdn.cdnResolver) || ${this.requireFn};`));s.push("})();")}return i.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 a=t.js.map((e=>{if(r.disabled){return s.basename(e)}const t=U(this.config,r.env);return z(t,e.replace(o,""))}));const i=t.css.map((e=>{if(r.disabled){return s.basename(e)}const t=U(this.config,r.env);return z(t,e.replace(o,""))}));e.assets.js=a;e.assets.css=i;return e}))}))}}const Ee=(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));if(!e){s.push(he(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 Be=(n,r,o,a)=>{process.env.NODE_ENV=n;r=r==="auto"?"auto":e.ensureSlash(r,true);const i=n==="development";const l=a.projectCwd;const c=a.pluginLoaderOptions;const p=a.watchOptions;const u=K(o);const d=t.isFunction(a.extraLoaders)?a.extraLoaders(i):a.extraLoaders;const m=[...ce(i,a,u,c),...d||[]];const f=t.isFunction(a.extraPlugins)?a.extraPlugins(i):a.extraPlugins;const h=t.isFunction(a.resolveAlias)?a.resolveAlias(i):a.resolveAlias;const v=[...Ee(i,u,a),...f||[]];const g={mode:n,target:a.target,stats:{preset:"minimal"},infrastructureLogging:{level:"warn"},devtool:i?"eval-source-map":a.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(i,a.externals,u),performance:N(i,a.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",i,c==null?void 0:c.enableBundleHashName)}`,chunkFilename:`[id].[contenthash].js`},optimization:{nodeEnv:i?"development":"production",chunkIds:i?"named":"named",moduleIds:i?"named":"named",minimize:a.minimize===false?false:i?false:true,minimizer:me(i,a),splitChunks:{name:false,chunks:"all",minSize:25e5,cacheGroups:{default:false,defaultVendors:false}}}};return g};const $e=(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)=>{i(o,((r,s)=>{var a,i;if(r){return t(r)}const l=s==null?void 0:s.toJson();if(l!=null&&(a=l.errors)!=null&&a.length){return t(l.errors)}if(n.forBuild.rejectWarnings&&l!=null&&(i=l.warnings)!=null&&i.length){return t(l.warnings)}e({name:o.name,warningStats:l==null?void 0:l.warnings})}))}))};const Me=async(t,n)=>{var r,s;if((r=n.packageInstallChecker)!=null&&r.enabled){var o,a,i;await e.installPackageChecker({cwd:process.cwd(),modules:(o=n.packageInstallChecker)==null?void 0:o.detectModules,throwError:(a=n.packageInstallChecker)==null?void 0:a.throwError,showAllinstalledGraph:(i=n.packageInstallChecker)==null?void 0:i.showAllinstalledGraph})}await e.keepPackageDepsUpToDateForNonMonoRepo({cwd:process.cwd(),autoUpgrade:true,needVerifyPackages:n.needVerifyPackages||{}});const l=((s=n.multiHtmlCdn)==null?void 0:s.prod)||[];const c=[];const p=e.ensureSlash(l[Math.floor(Math.random()*l.length)],true);for(const[e,r]of Object.entries(t)){var u;const t=V(r,n);const s={[e]:r};const o=(u=r.options)==null?void 0:u.useRelativeAssetPath;c.push($e(s,o?"auto":p,t))}return Promise.all(c)};const qe=async(n,r,o)=>{const a=await e.getPackageDir(__dirname,process.cwd());const i=C.readFileSync(s.join(a,"./templates/main.html"),"utf-8");const l=[];for(const[t,s]of Object.entries(o.entryMap)){var c;const a=((c=s.options)==null?void 0:c.servePageMainLinkFn)||(e=>e);const i=Object.keys(n).includes(t);const p=o.projectVirtualPath.replace(/^\//,"");l.push({name:t.replace(p,"").replace(/^\//,""),link:a(e.urlJoin(r,["pages",t],{env:"me"}),{hostUri:r,entryName:t,virtualPath:p}),flagText:i?"serve":"static",isServed:i?1:0})}const p={title:"@flatjs/evolve",modules:l.sort(((e,t)=>t.isServed-e.isServed))};return t.template(i)(p)};const Re=async(n,r,o,a,i,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)||a;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,a):{};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:G({me:[e.urlJoin(a,["public"])]},l.multiHtmlCdnResolver),global:{hostUrl:a,apiBase:e.urlJoin(a,[i]),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 Fe=(e,t,n,r,s)=>{const o=async(o,a)=>{let i;if(o.path==="/"){i=await qe(r,t,s)}else{i=await Re(r,e,o,t,n,s)}a.send(i)};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 a=s.extname(o);const i=n.find((e=>s.extname(e)===a&&e.indexOf(o.replace(/\.(js|css)$/,""))!==-1));if(i){r.sendFile(i)}else{r.sendFile(s.join(t,o))}}};const Te=(e,t="development",r,s,o,a,i)=>{const l=w();n.attachMockMiddlewares(l,i,a.projectCwd);l.set("hostUri",s);l.use("/pages",...Fe(t,s,i.apiContext||"api",o,a));l.use("*",De(e));return new Promise((e=>{const t=a.https?j.createServer(a.https,l):l;t.listen(r,(()=>{e(true)}))}))};const Ne=(e,t,n)=>{const{projectCwd:r,https:o,liveReload:a}=n;const i=new y({server:{type:o?"https":"http",options:{...o}},open:false,compress:true,port:t,hot:!a,liveReload:a,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)=>{i.startCallback((n=>{if(n){return t(n)}e(true)}))}))};const Ie=async(r,o,a,l)=>{var p;if((p=a.packageInstallChecker)!=null&&p.enabled){var u,d,m;await e.installPackageChecker({cwd:r,modules:(u=a.packageInstallChecker)==null?void 0:u.detectModules,throwError:(d=a.packageInstallChecker)==null?void 0:d.throwError,showAllinstalledGraph:(m=a.packageInstallChecker)==null?void 0:m.showAllinstalledGraph})}await e.keepPackageDepsUpToDateForNonMonoRepo({cwd:process.cwd(),autoUpgrade:true,needVerifyPackages:a.needVerifyPackages||{}});if(a.https){l.https=a.https}const{mockPort:f,hostUri:h}=await n.prepareMockDomain(l);const v=e.urlJoin(h,["/pages"]);let g=f;const b=[];const y={};for(const[e]of Object.entries(o)){g=g+1;const{mockPort:r,hostUri:s}=await n.prepareMockDomain(t.merge({},l,{port:g}));y[e]={devServerPort:r,devServerHostUri:s}}for(const[t,n]of Object.entries(o)){var w,j;const o=((w=n.options)==null?void 0:(j=w.moduleFederation)==null?void 0:j.remotes)||[];o.forEach((t=>{t.endpoint=t=>{var n;return e.urlJoin(((n=y[t])==null?void 0:n.devServerHostUri)||h,["/public"])}}));const{devServerPort:l,devServerHostUri:p}=y[t];const u=e.urlJoin(p,["public"]);const d={[t]:n};const m=V(n,a);const f=Be("development",u,d,m);const g=i.webpack(J(d,f)[0]);b.push(Ne(g,l,a));const C=c.bgBlack(`[${c.magenta("@flatjs")}:${c.bold(g.name||"")}]`);g.hooks.invalid.tap("fileChange",(e=>{console.log(C,`${"file change".padEnd(12," ")} ➩ ${c.cyan(s.relative(r,e||""))}`)}));g.hooks.done.tap("compileDone",(()=>{console.log(C,`${"serve page".padEnd(12," ")} ➩ ${c.cyan(v)}`)}))}await Te(r,"development",f,h,y,a,l);H(v);return Promise.all(b).then((()=>true))};const We=async(t,r,s)=>{if(r.https){s.https=r.https}const{mockPort:o,hostUri:a}=await n.prepareMockDomain(s);const i=e.urlJoin(a,["/pages"]);return Te(t,"development",o,a,{},r,s).then((e=>{const t=c.bgBlack(`[${c.magenta("@flatjs")}:`);console.log(t,`${"serve page".padEnd(12," ")} ➩ ${c.cyan(i)}`);return e}))};const He=(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 ze=(e,t,n={})=>{const r=W(e,n);const s=He(t,r.entryMap);return Me(s,r)};const Le=(e,t,r={},s={})=>{const o=W(e,r);const a=n.loadMockConfiguration(e,s);const i=He(t,o.entryMap);return Ie(e,i,o,a)};const Ue=(e,t={},r={})=>{const s=W(e,t);const o=n.loadMockConfiguration(e,r);return We(e,s,o)};exports.cdnBoot=B;exports.cdnJsDelivr=E;exports.cdnUnpkg=A;exports.createPageMiddleware=Fe;exports.createPublicAssetsMiddleware=De;exports.defaultFlatjsConfig=$;exports.evolveBuild=ze;exports.evolveServe=Le;exports.evolveStatic=Ue;exports.flatBabelOptions=O;exports.flatExternalOptions=M;exports.flatLessLoaderOptions=D;exports.flatPerformanceOptions=N;exports.flatPostcssLoaderOptions=T;exports.getHtmlPluginConfig=F;exports.loadEvolveConfiguration=W;exports.loadModule=P;exports.normalizeEntries=He;exports.polyfill=x;exports.terserOptions=I;exports.viewportScripts=q;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@flatjs/evolve",
|
3
|
-
"version": "1.5.
|
3
|
+
"version": "1.5.29",
|
4
4
|
"description": "the webpack based tools `evolve` of @flatjs",
|
5
5
|
"keywords": [
|
6
6
|
"shared",
|
@@ -23,10 +23,10 @@
|
|
23
23
|
],
|
24
24
|
"dependencies": {
|
25
25
|
"@babel/core": "^7.21.4",
|
26
|
-
"@flatjs/common": "^1.5.
|
26
|
+
"@flatjs/common": "^1.5.29",
|
27
27
|
"@flatjs/evolve-preset-babel": "^1.5.23",
|
28
28
|
"@flatjs/forge-plugin-postcss-pixel": "^1.6.0",
|
29
|
-
"@flatjs/mock": "^1.5.
|
29
|
+
"@flatjs/mock": "^1.5.29",
|
30
30
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
|
31
31
|
"babel-loader": "^9.1.2",
|
32
32
|
"babel-merge": "^3.0.0",
|
@@ -73,5 +73,5 @@
|
|
73
73
|
"publishConfig": {
|
74
74
|
"access": "public"
|
75
75
|
},
|
76
|
-
"gitHead": "
|
76
|
+
"gitHead": "67b0d557f0aa08d6071990f58f165223197cbb7e"
|
77
77
|
}
|