@flatjs/evolve 2.0.11 → 2.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",rejectWarnings:!1,devServer:{autoOpen:!0,pageProxy:"/pages",mockOptions:{mockBaseDir:"mocks"},clientOverlay:{errors:!0,warnings:!1},webSocketURL:"localIp",middlewares:[],watchOptions:{poll:1e3,ignored:["**/node_modules","**/mocks"],aggregateTimeout:500},defaultServeGlobalData:()=>Promise.resolve({})},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",resolve:{},externals:{vue:"Vue",react:"React","react-dom":"ReactDOM"},outputDir:"public",enableBundleHashName:!0},pluginOptions:{},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},runTsChecker:!0,lessOptions:{},postcssOptions:{cssnanoOptions:{}},pixelOptions:{rootValue:{px:100,rpx:1},outputUnit:"rem"},modularImports:[]},entryMap:{},multiHtmlCdn:{},multiHtmlCdnEnvResolver:function cdnResolver(){},needVerifyPackages:{},packageInstallChecker:{enabled:!1,detectModules:["@dimjs/*"],throwError:!1,showAllInstalledGraph:!0},maxProcesses:5,ci:{basedBranch:"origin/master"}};
1
+ export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",rejectWarnings:!1,devServer:{autoOpen:!0,pageProxy:"/pages",mockOptions:{mockBaseDir:"mocks"},clientOverlay:{errors:!0,warnings:!1},webSocketURL:"localIp",middlewares:[],watchOptions:{poll:1e3,ignored:["**/node_modules","**/mocks"],aggregateTimeout:500},defaultServeGlobalData:()=>Promise.resolve({}),bundleDirResolver:e=>e},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",resolve:{},externals:{vue:"Vue",react:"React","react-dom":"ReactDOM"},outputDir:"public",enableBundleHashName:!0},pluginOptions:{},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},runTsChecker:!0,lessOptions:{},postcssOptions:{cssnanoOptions:{}},pixelOptions:{rootValue:{px:100,rpx:1},outputUnit:"rem"},modularImports:[]},entryMap:{},multiHtmlCdn:{},multiHtmlCdnEnvResolver:function cdnResolver(){},needVerifyPackages:{},packageInstallChecker:{enabled:!1,detectModules:["@dimjs/*"],throwError:!1,showAllInstalledGraph:!0},maxProcesses:5,ci:{basedBranch:"origin/master"}};
@@ -1 +1 @@
1
- import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import _ from"lodash";import{devReactFastRefresh}from"../../constants.js";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{shouldEnableReactFastRefresh}from"../../helpers/should-enable-react-fast-refresh.js";const getPageMainHtml=async(e,t,r)=>{const l=getPackageDir(),a=readFileSync(join(l,"./templates/main.html"),"utf-8"),o=[],i=r.projectVirtualPath.replace(/^\//,"");for(const[l,a]of Object.entries(r.entryMap)){const s=a.options?.servePageMainLinkFn||(e=>e),n=Object.keys(e).includes(l),m=normalizeEvolveEntryName(l,i),c=r.devServer?.pageProxy||"/pages",p=urlJoin(t,[c,m],{env:"me"});o.push({name:l.replace(i,"").replace(/^\//,""),link:s(p,{hostUri:t,entryName:l,virtualPath:i}),flagText:n?"serve":"static",isServed:n?1:0})}const s={title:"@flatjs/evolve",modules:o.sort(((e,t)=>t.isServed-e.isServed))};return _.template(a)(s)},getPageModuleHtml=async(e,t,r,l,a)=>{const{entryMap:o,projectVirtualPath:i}=a,s=Object.keys(o).sort(((e,t)=>t.length-e.length)),n=getPackageDir(),m=s.find((e=>{const r=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(r,!0))}));if(!m){const e=readFileSync(join(n,"./templates/module-404.html"),"utf-8");return _.template(e)({title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:n},{name:"served entry names",value:JSON.stringify(s)},{name:"module path",value:`${t.path}`}]})}const c=normalizeEvolveEntryName(m,i),p=o[m],d=p.options,u=e[m],f=u?.devServerHostUri||r,g=d?.serveModuleTemplate||"./templates/module.html",h=join(a.projectCwd,"./templates/module.html"),v=readFileSync(isAbsolute(g)?g:existsSync(h)?h:join(n,"./templates/module.html"),"utf-8"),S=a.devServer,j=S?.defaultServeGlobalData?await S.defaultServeGlobalData(p,r):{},y={mode:"development",envCdn:urlJoin(r,["public"])},P=S?.pageProxy||"/pages",b={title:getHtmlPluginConfig("title",y,d?.title),favicon:getHtmlPluginConfig("favicon",y,d?.favicon),viewport:allowPx2remForModule([m,p],a)?getHtmlPluginConfig("viewport",y,d?.viewport):"",headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags",y,d?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts",y,d?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles",y,d?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts",y,d?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts",y,d?.bodyAfterScripts),moduleFederationScripts:injectFederationScripts({me:[urlJoin(r,["public"])]},a.multiHtmlCdnEnvResolver),global:{hostUrl:r,apiBase:urlJoin(r,[l]),virtualPath:join(P,i),moduleName:m.replace(i,"").replace(/^\//,""),...j,...d?.serveGlobalData||{}},styles:[urlJoin(f,[join("public",c,"bundle.css")])],scripts:[urlJoin(f,[join("public",c,"bundle.js")])]};if(e[m]&&shouldEnableReactFastRefresh(!0,[c,p],a)){const e=[devReactFastRefresh.runtime,devReactFastRefresh.reactRefreshSetup];b.headBeforeHtmlTags?b.headBeforeHtmlTags=b.headBeforeHtmlTags.slice(0):b.headBeforeHtmlTags=[],e.forEach((e=>{const t=urlJoin(f,[join("public",join(c,e),"bundle.js")]);b.headBeforeHtmlTags?.push(`<script src="${t}"><\/script>`)}))}return _.template(v)(b)};export const createPageMiddleware=(e,t,r,l)=>(l.devServer?.middlewares||[]).concat((async(a,o)=>{let i;i="/"===a.path?await getPageMainHtml(r,e,l):await getPageModuleHtml(r,a,e,t,l),o.send(i)}));
1
+ import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import _ from"lodash";import{devReactFastRefresh}from"../../constants.js";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{shouldEnableReactFastRefresh}from"../../helpers/should-enable-react-fast-refresh.js";const getPageMainHtml=async(e,t,r)=>{const l=getPackageDir(),a=readFileSync(join(l,"./templates/main.html"),"utf-8"),o=[],i=r.projectVirtualPath.replace(/^\//,"");for(const[l,a]of Object.entries(r.entryMap)){const s=a.options?.servePageMainLinkFn||(e=>e),n=Object.keys(e).includes(l),m=normalizeEvolveEntryName(l,i),c=r.devServer?.pageProxy||"/pages",p=urlJoin(t,[c,m],{env:"me"});o.push({name:l.replace(i,"").replace(/^\//,""),link:s(p,{hostUri:t,entryName:l,virtualPath:i}),flagText:n?"serve":"static",isServed:n?1:0})}const s={title:"@flatjs/evolve",modules:o.sort(((e,t)=>t.isServed-e.isServed))};return _.template(a)(s)},getPageModuleHtml=async(e,t,r,l,a)=>{const{entryMap:o,projectVirtualPath:i}=a,s=Object.keys(o).sort(((e,t)=>t.length-e.length)),n=getPackageDir(),m=s.find((e=>{const r=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(r,!0))}));if(!m){const e=readFileSync(join(n,"./templates/module-404.html"),"utf-8");return _.template(e)({title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:n},{name:"served entry names",value:JSON.stringify(s)},{name:"module path",value:`${t.path}`}]})}const c=o[m],p=c.options,d=e[m],u=d?.devServerHostUri||r,f=p?.serveModuleTemplate||"./templates/module.html",g=join(a.projectCwd,"./templates/module.html"),h=readFileSync(isAbsolute(f)?f:existsSync(g)?g:join(n,"./templates/module.html"),"utf-8"),v=a.devServer,S=v?.defaultServeGlobalData?await v.defaultServeGlobalData(c,r):{},j={mode:"development",envCdn:urlJoin(r,["public"])};let y=normalizeEvolveEntryName(m,i);v?.bundleDirResolver&&(y=v?.bundleDirResolver(y,{currEntry:m,projectVirtualPath:i}));const P=v?.pageProxy||"/pages",b={title:getHtmlPluginConfig("title",j,p?.title),favicon:getHtmlPluginConfig("favicon",j,p?.favicon),viewport:allowPx2remForModule([m,c],a)?getHtmlPluginConfig("viewport",j,p?.viewport):"",headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags",j,p?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts",j,p?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles",j,p?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts",j,p?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts",j,p?.bodyAfterScripts),moduleFederationScripts:injectFederationScripts({me:[urlJoin(r,["public"])]},a.multiHtmlCdnEnvResolver),global:{hostUrl:r,apiBase:urlJoin(r,[l]),virtualPath:join(P,i),moduleName:m.replace(i,"").replace(/^\//,""),...S,...p?.serveGlobalData||{}},styles:[urlJoin(u,[join("public",y,"bundle.css")])],scripts:[urlJoin(u,[join("public",y,"bundle.js")])]};if(e[m]&&shouldEnableReactFastRefresh(!0,[y,c],a)){const e=[devReactFastRefresh.runtime,devReactFastRefresh.reactRefreshSetup];b.headBeforeHtmlTags?b.headBeforeHtmlTags=b.headBeforeHtmlTags.slice(0):b.headBeforeHtmlTags=[],e.forEach((e=>{const t=urlJoin(u,[join("public",join(y,e),"bundle.js")]);b.headBeforeHtmlTags?.push(`<script src="${t}"><\/script>`)}))}return _.template(h)(b)};export const createPageMiddleware=(e,t,r,l)=>(l.devServer?.middlewares||[]).concat((async(a,o)=>{let i;i="/"===a.path?await getPageMainHtml(r,e,l):await getPageModuleHtml(r,a,e,t,l),o.send(i)}));
@@ -40,6 +40,16 @@ export type FlatEvolveDevServerOptions = {
40
40
  * Allow us costomized global serve data injected into `window.GLOBAL = {...globalData}`
41
41
  */
42
42
  defaultServeGlobalData?: (entryItem: EvolveEntryMapContent, hostUrl: string) => Promise<Record<string, unknown>> | Record<string, unknown>;
43
+ /**
44
+ * Allow us customized `styles`, `scripts` bundle path lookup resolver
45
+ * The full directory path such as '/public/${virtualPath}/${entryName}/bundle.js'`
46
+ * @default `(dir)=>dir`
47
+ * @returns
48
+ */
49
+ bundleDirResolver?: (dir: string, data: {
50
+ currEntry: string;
51
+ projectVirtualPath: string;
52
+ }) => string;
43
53
  /**
44
54
  * The value indicates if we will auto open broswers page for `serve`
45
55
  * @default true
@@ -57,7 +57,9 @@ export interface FlatEvolveOptions {
57
57
  */
58
58
  devServer?: FlatEvolveDevServerOptions;
59
59
  /**
60
- * The plugin for `@flatjs/evolve-multi-html-cdn-plugin`
60
+ * We can define multiple `CDN` for my project.
61
+ * --
62
+ * Note: We do not support `//` as prefix please use `https://` or `http://`
61
63
  */
62
64
  multiHtmlCdn: EvolveMultiCDNConfig;
63
65
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -45,7 +45,7 @@
45
45
  "@flatjs/evolve-preset-babel": "2.0.4",
46
46
  "@flatjs/forge-postcss-plugin-pixel": "2.0.4",
47
47
  "@flatjs/graph": "2.0.6",
48
- "@flatjs/mock": "2.0.6",
48
+ "@flatjs/mock": "2.0.7",
49
49
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.11",
50
50
  "@types/babel__core": "7.20.5",
51
51
  "babel-loader": "9.1.3",