@flatjs/evolve 3.0.13 → 3.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import{parseTemplate}from"@hyperse/html-webpack-plugin-loader";import{envVariablesName}from"../../constants.js";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{checkHtmlTemplateOptions}from"../../helpers/check-html-template-options.js";import{getHtmlMaxOrder,getHtmlMinOrder}from"../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{getRuntimeCDNBase}from"../../helpers/get-runtime-cdn-base.js";import{loadEnvConfig}from"../../helpers/load-env-config.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{normalizePageProxy}from"../../helpers/normalize-page-proxy.js";import{normalizeTemplateInjectTokens}from"../../helpers/normalize-template-inject-tokens.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{ErrorModuleParser}from"./error-module-parser.js";import{getBundleAsset}from"./get-bundle-asset.js";import{getDevServerHostUri}from"./get-dev-server-host-uri.js";import{getHmrRuntimeChunks}from"./get-hmr-runtime-chunks.js";import{getNormalizedEntryName}from"./get-normalized-entry-name.js";export const getPageModuleHtml=async(e,t,r,o,n)=>{const{entryMap:s,projectVirtualPath:i}=n,a=Object.keys(s).sort((e,t)=>t.length-e.length),l=getPackageDir(),m=a.find(e=>{const r=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(r,!0))});if(!m){const e=readFileSync(join(l,"./templates/module-404.html"),"utf-8");return new ErrorModuleParser(e,{title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:l},{name:"served entry names",value:JSON.stringify(a)},{name:"module path",value:`${t.path}`}]}).serialize()}const p=s[m],d=p.options,u=getDevServerHostUri(e,m,r),c=d?.templatePath||"./templates/module.html",g=join(n.projectCwd,"./templates/module.html"),h=readFileSync(isAbsolute(c)?c:existsSync(g)?g:join(l,"./templates/module.html"),"utf-8"),f=n.devServer,v=f?.defaultServeGlobalData?await f.defaultServeGlobalData(p,r):{},j={mode:"development",envCdn:urlJoin(r,["public"])},y=getNormalizedEntryName(m,i,e,f),S=normalizePageProxy(n.routeBaseName||"/pages"),H=normalizeTemplateInjectTokens(j,d);checkHtmlTemplateOptions(H);const N=parseTemplate(h);N.upsertTitleTag(getHtmlPluginConfig("title",j,d?.title));const M=H.favicon;M&&N.upsertFaviconTag(M.href,M.rel,M.attributes);const
|
|
1
|
+
import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import{parseTemplate}from"@hyperse/html-webpack-plugin-loader";import{envVariablesName}from"../../constants.js";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{checkHtmlTemplateOptions}from"../../helpers/check-html-template-options.js";import{getHtmlMaxOrder,getHtmlMinOrder}from"../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{getRuntimeCDNBase}from"../../helpers/get-runtime-cdn-base.js";import{loadEnvConfig}from"../../helpers/load-env-config.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{normalizePageProxy}from"../../helpers/normalize-page-proxy.js";import{normalizeTemplateInjectTokens}from"../../helpers/normalize-template-inject-tokens.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{ErrorModuleParser}from"./error-module-parser.js";import{getBundleAsset}from"./get-bundle-asset.js";import{getDevServerHostUri}from"./get-dev-server-host-uri.js";import{getHmrRuntimeChunks}from"./get-hmr-runtime-chunks.js";import{getNormalizedEntryName}from"./get-normalized-entry-name.js";export const getPageModuleHtml=async(e,t,r,o,n)=>{const{entryMap:s,projectVirtualPath:i}=n,a=Object.keys(s).sort((e,t)=>t.length-e.length),l=getPackageDir(),m=a.find(e=>{const r=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(r,!0))});if(!m){const e=readFileSync(join(l,"./templates/module-404.html"),"utf-8");return new ErrorModuleParser(e,{title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:l},{name:"served entry names",value:JSON.stringify(a)},{name:"module path",value:`${t.path}`}]}).serialize()}const p=s[m],d=p.options,u=getDevServerHostUri(e,m,r),c=d?.templatePath||"./templates/module.html",g=join(n.projectCwd,"./templates/module.html"),h=readFileSync(isAbsolute(c)?c:existsSync(g)?g:join(l,"./templates/module.html"),"utf-8"),f=n.devServer,v=f?.defaultServeGlobalData?await f.defaultServeGlobalData(p,r):{},j={mode:"development",envCdn:urlJoin(r,["public"])},y=getNormalizedEntryName(m,i,e,f),S=normalizePageProxy(n.routeBaseName||"/pages"),H=normalizeTemplateInjectTokens(j,d);checkHtmlTemplateOptions(H);const N=parseTemplate(h);N.upsertTitleTag(getHtmlPluginConfig("title",j,d?.title));const M=H.favicon;M&&N.upsertFaviconTag(M.href,M.rel,M.attributes);const P=H.headMetaTags||[];N.upsertHeadMetaTags(P);const b=H.headStyles||[],w=getHtmlMaxOrder(b),k=getBundleAsset(u,y,".css");b.push({id:k,href:k,position:"end",order:w+1}),N.upsertHeadStyles(b);const C=H.headScripts||[],x=getHtmlMinOrder(C);getHmrRuntimeChunks(e,m,y,p,n,u).forEach(e=>{C.unshift({id:e,src:e,position:"end",order:x-1})}),N.upsertHeadScripts(C);const z=H.headInlineScripts||[],O=getHtmlMaxOrder(z),E=getHtmlMinOrder(z),T=Math.min(E,x),B=await loadEnvConfig("me",n)||{};z.push({id:"envVariables",content:`window.${envVariablesName}=${JSON.stringify({env:"me",appName:n.projectVirtualPath,routeBaseName:n.routeBaseName,projectVirtualPath:i,moduleName:m.replace(i,"").replace(/^\//,""),...B})}`,position:"beginning",order:-99});const D={hostUrl:r,apiBase:urlJoin(r,[o]),virtualPath:join(S,i),moduleName:m.replace(i,"").replace(/^\//,""),...v,...d?.serveGlobalData||{}};z.push({id:"globalData",content:`window.GLOBAL=${JSON.stringify(D)}`,position:"end",order:T-2}),allowPx2remForModule([m,p],n)&&z.push({id:"viewport",content:getHtmlPluginConfig("viewport",j,d?.viewport),position:"end",order:E-1});const F=getRuntimeCDNBase(n.multiHtmlCdn,n.multiHtmlCdnEnvResolver||function cdnResolver(){});z.push({id:"flatjsMultiCdn",content:F,position:"end",order:O+1});const J=injectFederationScripts({me:[urlJoin(r,["public"])]},n.multiHtmlCdnEnvResolver);z.push({id:"evolveFetchMicroWidgets",content:J,position:"end",order:O+2}),N.upsertHeadInlineScripts(z);const R=H.headInlineStyles||[];N.upsertHeadInlineStyles(R);const A=H.bodyScripts||[],I=getHtmlMaxOrder(A),V=getBundleAsset(u,y,".js");return A.push({id:V,src:V,position:"end",order:I+1}),N.upsertBodyScripts(A),N.serialize()};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import HtmlWebpackPlugin from"html-webpack-plugin";import{ensureSlash}from"@flatjs/common";import{parseTemplate}from"@hyperse/html-webpack-plugin-loader";import{envVariablesName}from"../../../constants.js";import{loadEnvConfig}from"../../../helpers/load-env-config.js";const getCurrentEntry=(e=[],t)=>{const i=e.find(e=>t.includes(ensureSlash(e[0],!0)));return i||void 0};export class MultiHtmlModifyRspackPlugin{constructor(e,t){this.pluginName="MultiHtmlModifyRspackPlugin",this.evolveOptions=e,this.entryMapItemList=t}apply(e){e.hooks.compilation.tap(this.pluginName,e=>{HtmlWebpackPlugin.getHooks(e).beforeEmit.tapAsync(this.pluginName,async(e,t)=>{const{projectVirtualPath:i,routeBaseName:n}=this.evolveOptions,{userOptions:o}=e.plugin,a=getCurrentEntry(this.entryMapItemList,e.outputName);if(!a)throw new Error("No entry map found!");const
|
|
1
|
+
import HtmlWebpackPlugin from"html-webpack-plugin";import{ensureSlash}from"@flatjs/common";import{parseTemplate}from"@hyperse/html-webpack-plugin-loader";import{envVariablesName}from"../../../constants.js";import{loadEnvConfig}from"../../../helpers/load-env-config.js";const getCurrentEntry=(e=[],t)=>{const i=e.find(e=>t.includes(ensureSlash(e[0],!0)));return i||void 0};export class MultiHtmlModifyRspackPlugin{constructor(e,t){this.pluginName="MultiHtmlModifyRspackPlugin",this.evolveOptions=e,this.entryMapItemList=t}apply(e){e.hooks.compilation.tap(this.pluginName,e=>{HtmlWebpackPlugin.getHooks(e).beforeEmit.tapAsync(this.pluginName,async(e,t)=>{const{projectVirtualPath:i,routeBaseName:n}=this.evolveOptions,{userOptions:o}=e.plugin,a=getCurrentEntry(this.entryMapItemList,e.outputName);if(!a)throw new Error("No entry map found!");const r=a[0],l=a[1].options,s=parseTemplate(e.html,{title:l?.title||""}),p=await loadEnvConfig(o.multiCdn.env,this.evolveOptions)||{};s.upsertHeadInlineScripts([{id:"envVariables",content:`window.${envVariablesName}=${JSON.stringify({env:o.multiCdn.env,appName:i,routeBaseName:n,projectVirtualPath:i,moduleName:r.replace(i,"").replace(/^\//,""),...p})}`,position:"beginning",order:-99}]),t(null,{...e,html:s.serialize()})})})}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import HtmlWebpackPlugin from"html-webpack-plugin";import{ensureSlash}from"@flatjs/common";import{parseTemplate}from"@hyperse/html-webpack-plugin-loader";import{envVariablesName}from"../../../constants.js";import{loadEnvConfig}from"../../../helpers/load-env-config.js";const getCurrentEntry=(e=[],t)=>{const i=e.find(e=>t.includes(ensureSlash(e[0],!0)));return i||void 0};export class MultiHtmlModifyWebpackPlugin{constructor(e,t){this.pluginName="MultiHtmlModifyWebpackPlugin",this.evolveOptions=e,this.entryMapItemList=t}apply(e){e.hooks.compilation.tap(this.pluginName,e=>{HtmlWebpackPlugin.getHooks(e).beforeEmit.tapAsync(this.pluginName,async(e,t)=>{const{projectVirtualPath:i,routeBaseName:n}=this.evolveOptions,{userOptions:o}=e.plugin,a=getCurrentEntry(this.entryMapItemList,e.outputName);if(!a)throw new Error("No entry map found!");const
|
|
1
|
+
import HtmlWebpackPlugin from"html-webpack-plugin";import{ensureSlash}from"@flatjs/common";import{parseTemplate}from"@hyperse/html-webpack-plugin-loader";import{envVariablesName}from"../../../constants.js";import{loadEnvConfig}from"../../../helpers/load-env-config.js";const getCurrentEntry=(e=[],t)=>{const i=e.find(e=>t.includes(ensureSlash(e[0],!0)));return i||void 0};export class MultiHtmlModifyWebpackPlugin{constructor(e,t){this.pluginName="MultiHtmlModifyWebpackPlugin",this.evolveOptions=e,this.entryMapItemList=t}apply(e){e.hooks.compilation.tap(this.pluginName,e=>{HtmlWebpackPlugin.getHooks(e).beforeEmit.tapAsync(this.pluginName,async(e,t)=>{const{projectVirtualPath:i,routeBaseName:n}=this.evolveOptions,{userOptions:o}=e.plugin,a=getCurrentEntry(this.entryMapItemList,e.outputName);if(!a)throw new Error("No entry map found!");const r=a[0],l=a[1].options,s=parseTemplate(e.html,{title:l?.title||""}),p=await loadEnvConfig(o.multiCdn.env,this.evolveOptions)||{};s.upsertHeadInlineScripts([{id:"envVariables",content:`window.${envVariablesName}=${JSON.stringify({env:o.multiCdn.env,appName:i,routeBaseName:n,projectVirtualPath:i,moduleName:r.replace(i,"").replace(/^\//,""),...p})}`,position:"beginning",order:-99}]),t(null,{...e,html:s.serialize()})})})}}
|