@flatjs/evolve 1.8.1-next.24 → 1.8.1-next.25

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @flatjs/evolve
2
2
 
3
+ ## 1.8.1-next.25
4
+
5
+ ### Patch Changes
6
+
7
+ - 52ab6a8: Change defaultServeGlobalData to support promise
8
+
3
9
  ## 1.8.1-next.24
4
10
 
5
11
  ### Patch Changes
@@ -1 +1 @@
1
- export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",rejectWarnings:!1,devServer:{autoOpen:!0,mockOptions:{mockBaseDir:"mocks"},middlewares:[],watchOptions:{poll:1e3,ignored:/node_modules/,aggregateTimeout:500},defaultServeGlobalData:()=>({})},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",externals:{vue:"Vue",react:"React","react-dom":"ReactDOM"},enableBundleHashName:!0},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},runTsChecker:!0,lessOptions:{},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}};
1
+ export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",rejectWarnings:!1,devServer:{autoOpen:!0,mockOptions:{mockBaseDir:"mocks"},middlewares:[],watchOptions:{poll:1e3,ignored:/node_modules/,aggregateTimeout:500},defaultServeGlobalData:()=>Promise.resolve({})},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",externals:{vue:"Vue",react:"React","react-dom":"ReactDOM"},enableBundleHashName:!0},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},runTsChecker:!0,lessOptions:{},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}};
@@ -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{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";const getPageMainHtml=async(e,t,l)=>{const r=getPackageDir(),o=readFileSync(join(r,"./templates/main.html"),"utf-8"),a=[],i=l.projectVirtualPath.replace(/^\//,"");for(const[r,o]of Object.entries(l.entryMap)){const l=o.options?.servePageMainLinkFn||(e=>e),n=Object.keys(e).includes(r),s=normalizeEvolveEntryName(r,i),m=urlJoin(t,["pages",s],{env:"me"});a.push({name:r.replace(i,"").replace(/^\//,""),link:l(m,{hostUri:t,entryName:r,virtualPath:i}),flagText:n?"serve":"static",isServed:n?1:0})}const n={title:"@flatjs/evolve",modules:a.sort(((e,t)=>t.isServed-e.isServed))};return _.template(o)(n)},getPageModuleHtml=async(e,t,l,r,o)=>{const{entryMap:a,projectVirtualPath:i}=o,n=Object.keys(a).sort(((e,t)=>t.length-e.length)),s=getPackageDir(),m=n.find((e=>{const l=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(l,!0))}));if(!m){const e=readFileSync(join(s,"./templates/module-404.html"),"utf-8");return _.template(e)({title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:s},{name:"served entry names",value:JSON.stringify(n)},{name:"module path",value:`${t.path}`}]})}const p=normalizeEvolveEntryName(m,i),c=a[m],d=c.options,u=e[m],g=u?.devServerHostUri||l,f=d?.serveModuleTemplate||"./templates/module.html",v=join(o.projectCwd,"./templates/module.html"),h=readFileSync(isAbsolute(f)?f:existsSync(v)?v:join(s,"./templates/module.html"),"utf-8"),S=o.devServer,y=S?.defaultServeGlobalData?S.defaultServeGlobalData(c,l):{},j={title:getHtmlPluginConfig("title","development",d?.title),favicon:getHtmlPluginConfig("favicon","development",d?.favicon),viewport:allowPx2remForModule([m,c],o)?getHtmlPluginConfig("viewport","development",d?.viewport):"",headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags","development",d?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts","development",d?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles","development",d?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts","development",d?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts","development",d?.bodyAfterScripts),moduleFederationScripts:injectFederationScripts({me:[urlJoin(l,["public"])]},o.multiHtmlCdnEnvResolver),global:{hostUrl:l,apiBase:urlJoin(l,[r]),virtualPath:join("/pages",i),moduleName:m.replace(i,"").replace(/^\//,""),...y,...d?.serveGlobalData||{}},styles:[urlJoin(g,[join("public",p,"bundle.css")])],scripts:[urlJoin(g,[join("public",p,"bundle.js")])]};return _.template(h)(j)};export const createPageMiddleware=(e,t,l,r)=>(r.devServer?.middlewares||[]).concat((async(o,a)=>{let i;i="/"===o.path?await getPageMainHtml(l,e,r):await getPageModuleHtml(l,o,e,t,r),a.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{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";const getPageMainHtml=async(e,t,l)=>{const r=getPackageDir(),o=readFileSync(join(r,"./templates/main.html"),"utf-8"),a=[],i=l.projectVirtualPath.replace(/^\//,"");for(const[r,o]of Object.entries(l.entryMap)){const l=o.options?.servePageMainLinkFn||(e=>e),n=Object.keys(e).includes(r),s=normalizeEvolveEntryName(r,i),m=urlJoin(t,["pages",s],{env:"me"});a.push({name:r.replace(i,"").replace(/^\//,""),link:l(m,{hostUri:t,entryName:r,virtualPath:i}),flagText:n?"serve":"static",isServed:n?1:0})}const n={title:"@flatjs/evolve",modules:a.sort(((e,t)=>t.isServed-e.isServed))};return _.template(o)(n)},getPageModuleHtml=async(e,t,l,r,o)=>{const{entryMap:a,projectVirtualPath:i}=o,n=Object.keys(a).sort(((e,t)=>t.length-e.length)),s=getPackageDir(),m=n.find((e=>{const l=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(l,!0))}));if(!m){const e=readFileSync(join(s,"./templates/module-404.html"),"utf-8");return _.template(e)({title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:s},{name:"served entry names",value:JSON.stringify(n)},{name:"module path",value:`${t.path}`}]})}const p=normalizeEvolveEntryName(m,i),c=a[m],d=c.options,u=e[m],g=u?.devServerHostUri||l,f=d?.serveModuleTemplate||"./templates/module.html",v=join(o.projectCwd,"./templates/module.html"),h=readFileSync(isAbsolute(f)?f:existsSync(v)?v:join(s,"./templates/module.html"),"utf-8"),S=o.devServer,y=S?.defaultServeGlobalData?await S.defaultServeGlobalData(c,l):{},j={title:getHtmlPluginConfig("title","development",d?.title),favicon:getHtmlPluginConfig("favicon","development",d?.favicon),viewport:allowPx2remForModule([m,c],o)?getHtmlPluginConfig("viewport","development",d?.viewport):"",headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags","development",d?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts","development",d?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles","development",d?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts","development",d?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts","development",d?.bodyAfterScripts),moduleFederationScripts:injectFederationScripts({me:[urlJoin(l,["public"])]},o.multiHtmlCdnEnvResolver),global:{hostUrl:l,apiBase:urlJoin(l,[r]),virtualPath:join("/pages",i),moduleName:m.replace(i,"").replace(/^\//,""),...y,...d?.serveGlobalData||{}},styles:[urlJoin(g,[join("public",p,"bundle.css")])],scripts:[urlJoin(g,[join("public",p,"bundle.js")])]};return _.template(h)(j)};export const createPageMiddleware=(e,t,l,r)=>(r.devServer?.middlewares||[]).concat((async(o,a)=>{let i;i="/"===o.path?await getPageMainHtml(l,e,r):await getPageModuleHtml(l,o,e,t,r),a.send(i)}));
@@ -34,7 +34,7 @@ export type FlatEvolveDevServerOptions = {
34
34
  /**
35
35
  * Allow us costomized global serve data injected into `window.GLOBAL = {...globalData}`
36
36
  */
37
- defaultServeGlobalData?: (entryItem: EvolveEntryMapContent, hostUrl: string) => Record<string, unknown>;
37
+ defaultServeGlobalData?: (entryItem: EvolveEntryMapContent, hostUrl: string) => Promise<Record<string, unknown>>;
38
38
  /**
39
39
  * The value indicates if we will auto open broswers page for `serve`
40
40
  * @default true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "1.8.1-next.24",
3
+ "version": "1.8.1-next.25",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {