@flatjs/evolve 3.0.11 → 3.0.12

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
- 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:{},outputDir:"public",enableBundleHashName:!0},pluginOptions:{},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},lessOptions:{},postcssOptions:{cssnanoOptions:{}},pixelOptions:{rootValue:{px:100,rpx:1},outputUnit:"rem"},modularImports:[]},globalCompilerOptions:{runTsChecker:!0},entryMap:{},multiHtmlCdn:{},multiHtmlCdnEnvResolver:function cdnResolver(){},needVerifyPackages:{},packageInstallChecker:{enabled:!1,detectModules:["@dimjs/*"],throwError:!1,showAllInstalledGraph:!0},ci:{basedBranch:"origin/master"},isolation:!1,maxEntryGroupSize:10,compiler:"webpack",openRsdoctor:!1,inspector:{keys:["$mod","i"],customLaunchEditorEndpoint:"/__hps_inspector",trustedEditor:"code",injectClient:!0}};
1
+ export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",routeBaseName:"/pages",rejectWarnings:!1,devServer:{autoOpen:!0,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:{},outputDir:"public",enableBundleHashName:!0},pluginOptions:{},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},lessOptions:{},postcssOptions:{cssnanoOptions:{}},pixelOptions:{rootValue:{px:100,rpx:1},outputUnit:"rem"},modularImports:[]},globalCompilerOptions:{runTsChecker:!0},entryMap:{},multiHtmlCdn:{},multiHtmlCdnEnvResolver:function cdnResolver(){},needVerifyPackages:{},packageInstallChecker:{enabled:!1,detectModules:["@dimjs/*"],throwError:!1,showAllInstalledGraph:!0},ci:{basedBranch:"origin/master"},isolation:!1,maxEntryGroupSize:10,compiler:"webpack",openRsdoctor:!1,inspector:{keys:["$mod","i"],customLaunchEditorEndpoint:"/__hps_inspector",trustedEditor:"code",injectClient:!0}};
@@ -1 +1 @@
1
- import{createLaunchEditorMiddleware}from"@hyperse/inspector-middleware";import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{createPageMiddleware,createPublicAssetsMiddleware}from"./middlewares/index.js";export const createAppPageRoute=(e,r,t,a,o)=>{const{devServer:d,inspector:i}=o,s=normalizePageProxy(d?.pageProxy||"/pages");i&&d?.middlewares?.push(createLaunchEditorMiddleware({customLaunchEditorEndpoint:i.customLaunchEditorEndpoint,trustedEditor:i.trustedEditor,projectCwd:e})),r.use(s,...createPageMiddleware(t,d?.mockOptions?.apiContext||"api",a,o)),r.use("*splat",createPublicAssetsMiddleware(e,s))};
1
+ import{createLaunchEditorMiddleware}from"@hyperse/inspector-middleware";import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{createPageMiddleware,createPublicAssetsMiddleware}from"./middlewares/index.js";export const createAppPageRoute=(e,r,t,a,o)=>{const{devServer:d,inspector:i,routeBaseName:s}=o,c=normalizePageProxy(s||"/pages");i&&d?.middlewares?.push(createLaunchEditorMiddleware({customLaunchEditorEndpoint:i.customLaunchEditorEndpoint,trustedEditor:i.trustedEditor,projectCwd:e})),r.use(c,...createPageMiddleware(t,d?.mockOptions?.apiContext||"api",a,o)),r.use("*splat",createPublicAssetsMiddleware(e,c))};
@@ -1 +1 @@
1
- import{readFileSync}from"node:fs";import{join}from"node:path";import{urlJoin}from"@flatjs/common";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{normalizePageProxy}from"../../helpers/normalize-page-proxy.js";import{getSortedModules}from"./get-all-sorted-modules.js";import{MainModuleParser}from"./main-module-parser.js";export const getPageMainHtml=async(e,r,t)=>{const o=getPackageDir(),a=readFileSync(join(o,"./templates/main.html"),"utf-8"),n=getSortedModules(t,e,r),i=normalizePageProxy(t.devServer?.pageProxy||"/pages"),s=n.map(e=>{const{entryName:t,entryContent:o,isServedEntry:a,projectVirtualPath:n,normalizedEntryName:s}=e,m=urlJoin(r,[i,s],{env:"me"}),l=o.options?.servePageMainLinkFn||(e=>e);return{link:l(m,{hostUri:r,entryName:t,virtualPath:n}),name:t.replace(n,"").replace(/^\//,""),flagText:a?"serve":"static",isServed:a?1:0}});s.push({flagText:"serve",isServed:1,link:urlJoin(r,[i,"/runtime/manifest.json"]),name:"Runtime Manifest"});const m={title:"@flatjs/evolve",modules:s.sort((e,r)=>r.isServed-e.isServed)};return new MainModuleParser(a,m).serialize()};
1
+ import{readFileSync}from"node:fs";import{join}from"node:path";import{urlJoin}from"@flatjs/common";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{normalizePageProxy}from"../../helpers/normalize-page-proxy.js";import{getSortedModules}from"./get-all-sorted-modules.js";import{MainModuleParser}from"./main-module-parser.js";export const getPageMainHtml=async(e,r,t)=>{const o=getPackageDir(),a=readFileSync(join(o,"./templates/main.html"),"utf-8"),n=getSortedModules(t,e,r),i=normalizePageProxy(t.routeBaseName||"/pages"),s=n.map(e=>{const{entryName:t,entryContent:o,isServedEntry:a,projectVirtualPath:n,normalizedEntryName:s}=e,m=urlJoin(r,[i,s],{env:"me"}),l=o.options?.servePageMainLinkFn||(e=>e);return{link:l(m,{hostUri:r,entryName:t,virtualPath:n}),name:t.replace(n,"").replace(/^\//,""),flagText:a?"serve":"static",isServed:a?1:0}});s.push({flagText:"serve",isServed:1,link:urlJoin(r,[i,"/runtime/manifest.json"]),name:"Runtime Manifest"});const m={title:"@flatjs/evolve",modules:s.sort((e,r)=>r.isServed-e.isServed)};return new MainModuleParser(a,m).serialize()};
@@ -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,l=Object.keys(s).sort((e,t)=>t.length-e.length),a=getPackageDir(),m=l.find(e=>{const r=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(r,!0))});if(!m){const e=readFileSync(join(a,"./templates/module-404.html"),"utf-8");return new ErrorModuleParser(e,{title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:a},{name:"served entry names",value:JSON.stringify(l)},{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(a,"./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(f?.pageProxy||"/pages"),H=normalizeTemplateInjectTokens(j,d);checkHtmlTemplateOptions(H);const M=parseTemplate(h);M.upsertTitleTag(getHtmlPluginConfig("title",j,d?.title));const P=H.favicon;P&&M.upsertFaviconTag(P.href,P.rel,P.attributes);const b=H.headMetaTags||[];M.upsertHeadMetaTags(b);const w=H.headStyles||[],k=getHtmlMaxOrder(w),x=getBundleAsset(u,y,".css");w.push({id:x,href:x,position:"end",order:k+1}),M.upsertHeadStyles(w);const C=H.headScripts||[],N=getHtmlMinOrder(C);getHmrRuntimeChunks(e,m,y,p,n,u).forEach(e=>{C.unshift({id:e,src:e,position:"end",order:N-1})}),M.upsertHeadScripts(C);const z=H.headInlineScripts||[],O=getHtmlMaxOrder(z),E=getHtmlMinOrder(z),T=Math.min(E,N),D=await loadEnvConfig("me",n);D&&z.push({id:"envVariables",content:`window.${envVariablesName}=${JSON.stringify(D)}`,position:"end",order:T-3});const F={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(F)}`,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 B=getRuntimeCDNBase(n.multiHtmlCdn,n.multiHtmlCdnEnvResolver||function cdnResolver(){});z.push({id:"flatjsMultiCdn",content:B,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}),M.upsertHeadInlineScripts(z);const R=H.headInlineStyles||[];M.upsertHeadInlineStyles(R);const A=H.bodyScripts||[],I=getHtmlMaxOrder(A),G=getBundleAsset(u,y,".js");return A.push({id:G,src:G,position:"end",order:I+1}),M.upsertBodyScripts(A),M.serialize()};
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 b=H.headMetaTags||[];N.upsertHeadMetaTags(b);const P=H.headStyles||[],w=getHtmlMaxOrder(P),k=getBundleAsset(u,y,".css");P.push({id:k,href:k,position:"end",order:w+1}),N.upsertHeadStyles(P);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({appName:n.projectVirtualPath,routeBaseName:n.routeBaseName,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{dirname,join}from"path";import{fileURLToPath}from"url";import{searchPackageDir}from"@armit/package";import{logger,mergeOptions,requireResolve}from"@flatjs/common";import{normalizePageProxy}from"./normalize-page-proxy.js";export const mergeInspectorEvolveConfig=e=>{const{inspector:r,devServer:o}=e;if(!r)return e;const{externals:n}=e.webpack||{};if(n){let r=n;if("function"==typeof n&&(r=n()),r.react||r["react-dom"])return logger.warn("React and ReactDOM are external dependencies, you need to manually integrate Inspector"),e}const t=normalizePageProxy(o?.pageProxy||"/pages"),{keys:i=["$mod","i"],customLaunchEditorEndpoint:s="/__hps_inspector"}=r,a={"process.env.INSPECTOR_ENDPOINT":JSON.stringify(join(t,s)),"process.env.INSPECTOR_KEYS":JSON.stringify(i.join(",")),"process.env.INSPECTOR_HIDE_CONSOLE":JSON.stringify("FALSE"),"process.env.INSPECTOR_HIDE_CONTEXT":JSON.stringify("TRUE"),"process.env.INSPECTOR_HIDE_DOM_PATH_ATTR":JSON.stringify("TRUE"),"process.env.INSPECTOR_DISABLE":JSON.stringify("FALSE")},p=mergeOptions(e,{pluginOptions:{definePlugin:a}}),c=requireResolve(import.meta.url,"@hyperse/inspector"),g=searchPackageDir({cwd:fileURLToPath(dirname(c))});if(!g)return logger.debug("@hyperse/inspector package not found"),p;const m=join(g,"dist","client","index.js"),f=p.entryMap;for(const[e,r]of Object.entries(f)){r.entry.unshift(m)}return p};
1
+ import{dirname,join}from"path";import{fileURLToPath}from"url";import{searchPackageDir}from"@armit/package";import{logger,mergeOptions,requireResolve}from"@flatjs/common";import{normalizePageProxy}from"./normalize-page-proxy.js";export const mergeInspectorEvolveConfig=e=>{const{inspector:r}=e;if(!r)return e;const{externals:o}=e.webpack||{};if(o){let r=o;if("function"==typeof o&&(r=o()),r.react||r["react-dom"])return logger.warn("React and ReactDOM are external dependencies, you need to manually integrate Inspector"),e}const n=normalizePageProxy(e.routeBaseName||"/pages"),{keys:t=["$mod","i"],customLaunchEditorEndpoint:i="/__hps_inspector"}=r,s={"process.env.INSPECTOR_ENDPOINT":JSON.stringify(join(n,i)),"process.env.INSPECTOR_KEYS":JSON.stringify(t.join(",")),"process.env.INSPECTOR_HIDE_CONSOLE":JSON.stringify("FALSE"),"process.env.INSPECTOR_HIDE_CONTEXT":JSON.stringify("TRUE"),"process.env.INSPECTOR_HIDE_DOM_PATH_ATTR":JSON.stringify("TRUE"),"process.env.INSPECTOR_DISABLE":JSON.stringify("FALSE")},a=mergeOptions(e,{pluginOptions:{definePlugin:s}}),c=requireResolve(import.meta.url,"@hyperse/inspector"),p=searchPackageDir({cwd:fileURLToPath(dirname(c))});if(!p)return logger.debug("@hyperse/inspector package not found"),a;const g=join(p,"dist","client","index.js"),m=a.entryMap;for(const[e,r]of Object.entries(m)){r.entry.unshift(g)}return a};
@@ -1 +1 @@
1
- import{arrayUnique,chalk,logger,urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{ignoreEntryOptionKeys,moduleName}from"../constants.js";import{createRspackCompilerTask}from"../core/rspack/dev-serve/create-rspack-compiler-task.js";import{createWebpackCompilerTask}from"../core/webpack/dev-serve/create-webpack-compiler-task.js";import{createAppPageRoute,createDevServer,createDevServerEntries}from"../dev-server/index.js";import{flatEntryMap,openPage}from"../helpers/index.js";import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{printPromotions}from"../helpers/print-promotion.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{verifyGroupEntryOptions}from"../helpers/verify-group-entry-options.js";import{envVerify}from"./env-verify.js";export const prepareServe=async(e,r,o)=>{await envVerify(e,o);const t=splitToEntryGroup(r,o,ignoreEntryOptionKeys,!0);if(!t.length)return void logger.warn("No served entries provided!");const s=[],{app:a,devPort:n,devHostUri:p,publicIp:i}=await createDevServer(o),c=o.devServer?.mockOptions?.mockFilters||[];for(const[,e]of Object.entries(r))c.push(...e.options?.mockFilters||[]);await attachMockMiddlewares(a,{...o.devServer?.mockOptions,mockFilters:arrayUnique(c),projectCwd:e});let m=n;const l=[];for(const e of t){if(!verifyGroupEntryOptions(e,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");m++;const r=await createDevServerEntries(m,e,o);l.push(r)}const v=flatEntryMap(l);createAppPageRoute(e,a,p,v,o);const d=normalizePageProxy(o.devServer?.pageProxy||"/pages"),f=urlJoin(p,[d]);o.devServer?.autoOpen&&openPage(f);const{compiler:g}=o;printPromotions(o);for(const e of l){const r="webpack"===g?createWebpackCompilerTask(i,e,l,o):createRspackCompilerTask(i,e,l,o);s.push(r)}return Promise.all(s).then(()=>(logger.info(`debug page ➩ ${chalk(["cyan"])(f)}`,moduleName),process.stdin.resume(),process.stdin.setEncoding("utf8"),process.stdin.on("data",e=>{const r=e.toString();12===r.charCodeAt(0)?console.clear():[102,70].includes(r.charCodeAt(0))&&logger.info(`debug page ➩ ${chalk(["cyan"])(f)}`,moduleName)}),a))};
1
+ import{arrayUnique,chalk,logger,urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{ignoreEntryOptionKeys,moduleName}from"../constants.js";import{createRspackCompilerTask}from"../core/rspack/dev-serve/create-rspack-compiler-task.js";import{createWebpackCompilerTask}from"../core/webpack/dev-serve/create-webpack-compiler-task.js";import{createAppPageRoute,createDevServer,createDevServerEntries}from"../dev-server/index.js";import{flatEntryMap,openPage}from"../helpers/index.js";import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{printPromotions}from"../helpers/print-promotion.js";import{splitToEntryGroup}from"../helpers/split-to-entry-group.js";import{verifyGroupEntryOptions}from"../helpers/verify-group-entry-options.js";import{envVerify}from"./env-verify.js";export const prepareServe=async(e,r,o)=>{await envVerify(e,o);const t=splitToEntryGroup(r,o,ignoreEntryOptionKeys,!0);if(!t.length)return void logger.warn("No served entries provided!");const s=[],{app:a,devPort:n,devHostUri:p,publicIp:i}=await createDevServer(o),c=o.devServer?.mockOptions?.mockFilters||[];for(const[,e]of Object.entries(r))c.push(...e.options?.mockFilters||[]);await attachMockMiddlewares(a,{...o.devServer?.mockOptions,mockFilters:arrayUnique(c),projectCwd:e});let m=n;const l=[];for(const e of t){if(!verifyGroupEntryOptions(e,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");m++;const r=await createDevServerEntries(m,e,o);l.push(r)}const f=flatEntryMap(l);createAppPageRoute(e,a,p,f,o);const v=normalizePageProxy(o.routeBaseName||"/pages"),d=urlJoin(p,[v]);o.devServer?.autoOpen&&openPage(d);const{compiler:u}=o;printPromotions(o);for(const e of l){const r="webpack"===u?createWebpackCompilerTask(i,e,l,o):createRspackCompilerTask(i,e,l,o);s.push(r)}return Promise.all(s).then(()=>(logger.info(`debug page ➩ ${chalk(["cyan"])(d)}`,moduleName),process.stdin.resume(),process.stdin.setEncoding("utf8"),process.stdin.on("data",e=>{const r=e.toString();12===r.charCodeAt(0)?console.clear():[102,70].includes(r.charCodeAt(0))&&logger.info(`debug page ➩ ${chalk(["cyan"])(d)}`,moduleName)}),a))};
@@ -1 +1 @@
1
- import{chalk,logger,urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{createAppPageRoute}from"../dev-server/create-app-page-route.js";import{createDevServer}from"../dev-server/create-dev-server.js";import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{openPage}from"../helpers/open-page.js";export const prepareStatic=async(e,r)=>{const{app:a,devHostUri:o}=await createDevServer(r);await attachMockMiddlewares(a,{...r.devServer?.mockOptions,projectCwd:e}),createAppPageRoute(e,a,o,{},r);const t=normalizePageProxy(r.devServer?.pageProxy||"/pages"),p=urlJoin(o,[t]);r.devServer?.autoOpen&&openPage(p),logger.info(`${"static page".padEnd(12," ")} ➩ ${chalk(["cyan"])(p)}`)};
1
+ import{chalk,logger,urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{createAppPageRoute}from"../dev-server/create-app-page-route.js";import{createDevServer}from"../dev-server/create-dev-server.js";import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{openPage}from"../helpers/open-page.js";export const prepareStatic=async(e,r)=>{const{app:a,devHostUri:o}=await createDevServer(r);await attachMockMiddlewares(a,{...r.devServer?.mockOptions,projectCwd:e}),createAppPageRoute(e,a,o,{},r);const t=normalizePageProxy(r.routeBaseName||"/pages"),p=urlJoin(o,[t]);r.devServer?.autoOpen&&openPage(p),logger.info(`${"static page".padEnd(12," ")} ➩ ${chalk(["cyan"])(p)}`)};
@@ -1,5 +1,6 @@
1
1
  import type { Compiler } from 'webpack';
2
2
  import type { EntryMapItem } from '../../../types/types-entry-map.js';
3
+ import type { FlatEvolveOptions } from '../../../types/types-options.js';
3
4
  /**
4
5
  * The MultiHtmlModifyPlugin class is responsible for modifying the HTML output of the webpack compiler.
5
6
  * It hooks into the compilation process and replaces occurrences of "<%= title %>" with the title specified in the options.
@@ -7,6 +8,7 @@ import type { EntryMapItem } from '../../../types/types-entry-map.js';
7
8
  export declare class MultiHtmlModifyRspackPlugin {
8
9
  private pluginName;
9
10
  private entryMapItemList;
10
- constructor(list: EntryMapItem[]);
11
+ private evolveOptions;
12
+ constructor(evolveOptions: FlatEvolveOptions, list: EntryMapItem[]);
11
13
  apply(compiler: Compiler): void;
12
14
  }
@@ -1 +1 @@
1
- import HtmlWebpackPlugin from"html-webpack-plugin";import{ensureSlash}from"@flatjs/common";import{parseTemplate}from"@hyperse/html-webpack-plugin-loader";const getCurrentEntryOptions=(t=[],e)=>{const i=t.find(t=>e.includes(ensureSlash(t[0],!0)));return i?i[1]?.options:void 0};export class MultiHtmlModifyRspackPlugin{constructor(t){this.pluginName="MultiHtmlModifyRspackPlugin",this.entryMapItemList=t}apply(t){t.hooks.compilation.tap(this.pluginName,t=>{HtmlWebpackPlugin.getHooks(t).beforeEmit.tapAsync(this.pluginName,(t,e)=>{const i=getCurrentEntryOptions(this.entryMapItemList,t.outputName),l=parseTemplate(t.html,{title:i?.title||""});e(null,{...t,html:l.serialize()})})})}}
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 s=a[0],r=a[1].options,l=parseTemplate(e.html,{title:r?.title||""}),p=await loadEnvConfig(o.multiCdn.env,this.evolveOptions)||{};l.upsertHeadInlineScripts([{id:"envVariables",content:`window.${envVariablesName}=${JSON.stringify({appName:i,routeBaseName:n,moduleName:s.replace(i,"").replace(/^\//,""),...p})}`,position:"beginning",order:-99}]),t(null,{...e,html:l.serialize()})})})}}
@@ -1 +1 @@
1
- import HtmlWebpackPlugin from"html-webpack-plugin";import{existsSync}from"node:fs";import{logger,requireResolve}from"@flatjs/common";import{envVariablesName}from"../../../constants.js";import{allowPx2remForModule}from"../../../helpers/allow-px2rem-for-module.js";import{checkHtmlTemplateOptions}from"../../../helpers/check-html-template-options.js";import{getHtmlMinOrder}from"../../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../../helpers/get-html-plugin-config.js";import{loadEnvConfig}from"../../../helpers/load-env-config.js";import{normalizeTemplateInjectTokens}from"../../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../../helpers/script-injects.js";import{MultiHtmlModifyRspackPlugin}from"./multi-html-modify-rspack-plugin.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlRspackPlugins=async(e,t,i,l)=>{const n=i[0],[,o]=n,m=[new MultiHtmlModifyRspackPlugin(i)],{options:r}=o,s=e?"development":"production",p=i.map(e=>e[0]);for(const e of l){const i={mode:s,envCdn:findEnvCdn(t.multiHtmlCdn,e)},l=normalizeTemplateInjectTokens(i,r);checkHtmlTemplateOptions(l);const o=l?.headInlineScripts||[],a=getHtmlMinOrder(o),c=await loadEnvConfig(e,t);if(c&&o?.push({id:"envVariables",content:`window.${envVariablesName}=${JSON.stringify(c)}`,position:"end",order:a-2}),allowPx2remForModule(n,t)){const e=getHtmlMinOrder(o),t=getHtmlPluginConfig("viewport",i,r?.viewport);o.push({id:"viewport",content:t,position:"end",order:e-1})}let d=getHtmlPluginConfig("templatePath",i,r?.templatePath).replace("{0}",e.trim());existsSync(d)||(logger.warn(`The template file ${d} is not exists, use \`prod\` instead!`),d=getHtmlPluginConfig("templatePath",i,r?.templatePath).replace("{0}","prod"));d=`${requireResolve(import.meta.url,"@hyperse/html-webpack-plugin-loader/loader")}!${d}`,m.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",i,r?.title),chunks:p,minify:!1!==r?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:t=>`${t}/index${"prod"===e?"":`-${e}`}.html`,template:d,templateParameters:{title:"",...l,headInlineScripts:o},multiCdn:{env:e,disabled:(r?.excludeCdnEnvs||["me","dev","ntv"]).includes(e)}}))}return m};
1
+ import HtmlWebpackPlugin from"html-webpack-plugin";import{existsSync}from"node:fs";import{logger,requireResolve}from"@flatjs/common";import{allowPx2remForModule}from"../../../helpers/allow-px2rem-for-module.js";import{checkHtmlTemplateOptions}from"../../../helpers/check-html-template-options.js";import{getHtmlMinOrder}from"../../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../../helpers/get-html-plugin-config.js";import{normalizeTemplateInjectTokens}from"../../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../../helpers/script-injects.js";import{MultiHtmlModifyRspackPlugin}from"./multi-html-modify-rspack-plugin.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlRspackPlugins=async(e,t,l,i)=>{const o=l[0],[,n]=o,m=[new MultiHtmlModifyRspackPlugin(t,l)],{options:r}=n,p=e?"development":"production",s=l.map(e=>e[0]);for(const e of i){const l={mode:p,envCdn:findEnvCdn(t.multiHtmlCdn,e)},i=normalizeTemplateInjectTokens(l,r);checkHtmlTemplateOptions(i);const n=i?.headInlineScripts||[];if(allowPx2remForModule(o,t)){const e=getHtmlMinOrder(n),t=getHtmlPluginConfig("viewport",l,r?.viewport);n.push({id:"viewport",content:t,position:"end",order:e-1})}let a=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}",e.trim());existsSync(a)||(logger.warn(`The template file ${a} is not exists, use \`prod\` instead!`),a=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}","prod"));a=`${requireResolve(import.meta.url,"@hyperse/html-webpack-plugin-loader/loader")}!${a}`,m.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",l,r?.title),chunks:s,minify:!1!==r?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:t=>`${t}/index${"prod"===e?"":`-${e}`}.html`,template:a,templateParameters:{title:"",...i,headInlineScripts:n},multiCdn:{env:e,disabled:(r?.excludeCdnEnvs||["me","dev","ntv"]).includes(e)}}))}return m};
@@ -1,5 +1,6 @@
1
1
  import type { Compiler } from 'webpack';
2
2
  import type { EntryMapItem } from '../../../types/types-entry-map.js';
3
+ import type { FlatEvolveOptions } from '../../../types/types-options.js';
3
4
  /**
4
5
  * The MultiHtmlModifyPlugin class is responsible for modifying the HTML output of the webpack compiler.
5
6
  * It hooks into the compilation process and replaces occurrences of "<%= title %>" with the title specified in the options.
@@ -7,6 +8,7 @@ import type { EntryMapItem } from '../../../types/types-entry-map.js';
7
8
  export declare class MultiHtmlModifyWebpackPlugin {
8
9
  private pluginName;
9
10
  private entryMapItemList;
10
- constructor(list: EntryMapItem[]);
11
+ private evolveOptions;
12
+ constructor(evolveOptions: FlatEvolveOptions, list: EntryMapItem[]);
11
13
  apply(compiler: Compiler): void;
12
14
  }
@@ -1 +1 @@
1
- import HtmlWebpackPlugin from"html-webpack-plugin";import{ensureSlash}from"@flatjs/common";import{parseTemplate}from"@hyperse/html-webpack-plugin-loader";const getCurrentEntryOptions=(t=[],e)=>{const i=t.find(t=>e.includes(ensureSlash(t[0],!0)));return i?i[1]?.options:void 0};export class MultiHtmlModifyWebpackPlugin{constructor(t){this.pluginName="MultiHtmlModifyWebpackPlugin",this.entryMapItemList=t}apply(t){t.hooks.compilation.tap(this.pluginName,t=>{HtmlWebpackPlugin.getHooks(t).beforeEmit.tapAsync(this.pluginName,(t,e)=>{const i=getCurrentEntryOptions(this.entryMapItemList,t.outputName),l=parseTemplate(t.html,{title:i?.title||""});e(null,{...t,html:l.serialize()})})})}}
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({appName:i,routeBaseName:n,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{existsSync}from"node:fs";import{logger,requireResolve}from"@flatjs/common";import{envVariablesName}from"../../../constants.js";import{allowPx2remForModule}from"../../../helpers/allow-px2rem-for-module.js";import{checkHtmlTemplateOptions}from"../../../helpers/check-html-template-options.js";import{getHtmlMinOrder}from"../../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../../helpers/get-html-plugin-config.js";import{loadEnvConfig}from"../../../helpers/load-env-config.js";import{normalizeTemplateInjectTokens}from"../../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../../helpers/script-injects.js";import{MultiHtmlModifyWebpackPlugin}from"./multi-html-modify-webpack-plugin.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlWebpackPlugins=async(e,t,i,l)=>{const n=i[0],[,o]=n,m=[new MultiHtmlModifyWebpackPlugin(i)],{options:r}=o,p=e?"development":"production",s=i.map(e=>e[0]);for(const e of l){const i={mode:p,envCdn:findEnvCdn(t.multiHtmlCdn,e)},l=normalizeTemplateInjectTokens(i,r);checkHtmlTemplateOptions(l);const o=l?.headInlineScripts||[],a=getHtmlMinOrder(o),c=await loadEnvConfig(e,t);if(c&&o?.push({id:"envVariables",content:`window.${envVariablesName}=${JSON.stringify(c)}`,position:"end",order:a-2}),allowPx2remForModule(n,t)){const e=getHtmlPluginConfig("viewport",i,r?.viewport);o.unshift({id:"viewport",content:e,position:"end",order:a-1})}let d=getHtmlPluginConfig("templatePath",i,r?.templatePath).replace("{0}",e.trim());existsSync(d)||(logger.warn(`The template file ${d} is not exists, use \`prod\` instead!`),d=getHtmlPluginConfig("templatePath",i,r?.templatePath).replace("{0}","prod"));d=`${requireResolve(import.meta.url,"@hyperse/html-webpack-plugin-loader/loader")}!${d}`,m.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",i,r?.title),chunks:s,minify:!1!==r?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:t=>`${t}/index${"prod"===e?"":`-${e}`}.html`,template:d,templateParameters:{title:"",...l,headInlineScripts:o},multiCdn:{env:e,disabled:(r?.excludeCdnEnvs||["me","dev","ntv"]).includes(e)}}))}return m};
1
+ import HtmlWebpackPlugin from"html-webpack-plugin";import{existsSync}from"node:fs";import{logger,requireResolve}from"@flatjs/common";import{allowPx2remForModule}from"../../../helpers/allow-px2rem-for-module.js";import{checkHtmlTemplateOptions}from"../../../helpers/check-html-template-options.js";import{getHtmlMinOrder}from"../../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../../helpers/get-html-plugin-config.js";import{normalizeTemplateInjectTokens}from"../../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../../helpers/script-injects.js";import{MultiHtmlModifyWebpackPlugin}from"./multi-html-modify-webpack-plugin.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlWebpackPlugins=async(e,t,l,i)=>{const o=l[0],[,n]=o,m=[new MultiHtmlModifyWebpackPlugin(t,l)],{options:r}=n,p=e?"development":"production",s=l.map(e=>e[0]);for(const e of i){const l={mode:p,envCdn:findEnvCdn(t.multiHtmlCdn,e)},i=normalizeTemplateInjectTokens(l,r);checkHtmlTemplateOptions(i);const n=i?.headInlineScripts||[],a=getHtmlMinOrder(n);if(allowPx2remForModule(o,t)){const e=getHtmlPluginConfig("viewport",l,r?.viewport);n.unshift({id:"viewport",content:e,position:"end",order:a-1})}let c=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}",e.trim());existsSync(c)||(logger.warn(`The template file ${c} is not exists, use \`prod\` instead!`),c=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}","prod"));c=`${requireResolve(import.meta.url,"@hyperse/html-webpack-plugin-loader/loader")}!${c}`,m.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",l,r?.title),chunks:s,minify:!1!==r?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:t=>`${t}/index${"prod"===e?"":`-${e}`}.html`,template:c,templateParameters:{title:"",...i,headInlineScripts:n},multiCdn:{env:e,disabled:(r?.excludeCdnEnvs||["me","dev","ntv"]).includes(e)}}))}return m};
@@ -22,11 +22,6 @@ export interface WebpackWatchOptions {
22
22
  poll?: number | boolean;
23
23
  }
24
24
  export type FlatEvolveDevServerOptions = {
25
- /**
26
- * must have prefix slash `/`
27
- * @default `/pages`
28
- */
29
- pageProxy?: string;
30
25
  /**
31
26
  * Allow us provider customized middlewares for `page`, `modules`
32
27
  */
@@ -39,6 +39,13 @@ export interface FlatEvolveOptions {
39
39
  * The project workspace directory.
40
40
  */
41
41
  projectCwd: string;
42
+ /**
43
+ * The route base name for current `project`
44
+ * must have prefix slash `/`
45
+ * e.g. `/pages` or `/route`
46
+ * @default `/pages`
47
+ */
48
+ routeBaseName?: string;
42
49
  /**
43
50
  * The virtual path for current `project`
44
51
  * e.g. `evolve/test`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "3.0.11",
3
+ "version": "3.0.12",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {