@empjs/cli 3.0.0-alpha.28 → 3.0.0-alpha.29

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.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- var Oe=Object.defineProperty;var c=(o,e)=>()=>(o&&(e=o(o=0)),e);var P=(o,e)=>{for(var t in e)Oe(o,t,{get:e[t],enumerable:!0})};import{fileURLToPath as Pe}from"node:url";import{dirname as ke}from"node:path";import{readFile as $e}from"node:fs/promises";var je,mt,k,J=c(()=>{"use strict";je=Pe(import.meta.url),mt=ke(je),k=async o=>{try{let e=await $e(o);return JSON.parse(e)}catch(e){console.error(e)}}});import x from"@rspack/core";import De from"fs";var $,q,Q=c(()=>{"use strict";$=class{store;async setup(e){this.store=e;let t=[this.define(),this.anylayze(),this.progress(),this.copy(),this.empShare()];await Promise.all(t)}async anylayze(){if(!this.store.cliOptions.analyze)return;let{default:{BundleAnalyzerPlugin:e}}=await import("webpack-bundle-analyzer");this.store.chain.plugin("bundleAnalyzerPlugin").use(e,[{}])}async define(){this.store.chain.plugin("definePlugin").use(x.DefinePlugin,[this.store.empConfig.define])}async copy(){let e=this.store.resolve("public");De.existsSync(e)&&this.store.chain.plugin("copyRspackPlugin").use(x.CopyRspackPlugin,[{patterns:[{from:e,to:this.store.resolve("dist")}]}])}async progress(){this.store.empConfig.debug.progress&&this.store.chain.plugin("progressPlugin").use(x.ProgressPlugin,[{prefix:"EMP"}])}async empShare(){if(!this.store.empConfig.empShare.name)return;let{ModuleFederationPlugin:e}=x.container;this.store.chain.plugin("empShare").use(e,[{...this.store.empConfig.empShare}])}},q=new $});var j,X,Y=c(()=>{"use strict";j=class{store;async setup(e){this.store=e;let t=[this.react(),this.files(),this.scripts()];await Promise.all(t)}async scripts(){let{isDev:e}=this.store,t=this.store.reactVersion?{react:{runtime:"automatic",development:e,refresh:e}}:{};this.store.chain.merge({module:{parser:{javascript:{exportsPresence:"error",importExportsPresence:"error"}},rule:{mjs:{test:/\.m?js/,resolve:{fullySpecified:!1}},scripts:{test:/\.(jsx?|tsx?)$/,use:[{loader:"builtin:swc-loader",options:{sourceMap:!0,jsc:{parser:{syntax:"typescript",tsx:!0},transform:t}}}]}}}})}async react(){if(this.store.reactVersion&&(this.store.empConfig.react.svgr&&this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,issuer:/\.[jt]sx?$/,resourceQuery:/svgr/,use:[{loader:this.store.importResolve("@svgr/webpack"),options:{}}]}}}}),this.store.isDev&&this.store.empConfig.react.hmr)){let{default:e}=await import("@rspack/plugin-react-refresh"),t={};this.store.empConfig.empShare.name&&(t.library=this.store.empConfig.empShare.name),this.store.chain.plugin("plugin-react-refresh").use(e,[t])}}async files(){(!this.store.reactVersion||!this.store.empConfig.react.svgr)&&this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,type:"asset/resource"}}}}),this.store.chain.merge({module:{rule:{inline:{resourceQuery:/inline/,type:"asset/inline"}}}}),this.store.chain.merge({module:{rule:{image:{test:/\.(png|jpe?g|gif|webp|ico)$/i,type:"asset/resource"},fonts:{test:/\.(|otf|ttf|eot|woff|woff2)$/i,type:"asset/resource"},svga:{test:/\.(svga)$/i,type:"asset/resource"}}}})}},X=new j});var D,K,Z=c(()=>{"use strict";D=class{store;async setup(e){this.store=e;let t=[this.common(),this.stats(),this.devServer(),this.optimization()];await Promise.all(t)}async common(){this.store.merge({experiments:{rspackFuture:{}},mode:this.store.mode,cache:!0,devtool:this.store.empConfig.build.sourcemap?"source-map":!1,builtins:{css:{modules:{localIdentName:this.store.isDev?"[path][name]-[local]-[hash:5]":"[local]-[hash:5]"}}},output:this.store.empConfig.output,resolve:this.store.empConfig.resolve,externals:this.store.empConfig.externals})}async stats(){this.store.merge({stats:{colors:!0,all:!1,assets:!1,chunks:!1,timings:!0,version:!0}})}async devServer(){this.store.merge({devServer:this.store.empConfig.server})}async optimization(){this.store.chain.merge({optimization:{chunkIds:this.store.empConfig.build.chunkIds,minimize:this.store.empConfig.build.minify}})}},K=new D});import Re from"html-webpack-plugin";import Te from"fast-glob";import w from"node:path";var R,ee,te=c(()=>{"use strict";R=class{store;entriesConfig={};async setup(e){this.store=e,await this.init(),this.toConfig()}setHtmlConfig(e,t){return e.template=this.setTemplate(e.template),e.favicon=this.setFavicion(e.favicon),e.chunks=t,e.filename=`${t[0]}.html`,this.store.empConfig.base&&(e.publicPath=this.store.empConfig.base),e}setChunk(e){return e.replace(w.extname(e),"").replace(`${this.store.empConfig.appSrc}/`,"")}setTemplate(e){return e?this.store.resolve(e):this.store.empResolve(w.join("template","index.html"))}setFavicion(e){return e?this.store.resolve(e):this.store.empResolve(w.join("template","favicon.ico"))}setEntryItem(e,t,s){s=s||this.store.resolve(w.join(this.store.empConfig.appSrc,e));let r=this.setChunk(e);this.entriesConfig[r]={entry:{[r]:s},html:this.setHtmlConfig(t,[r])}}setRspackHtmlPlugin(e,t){this.store.chain.plugin(`html-plugin-${t}`).use(Re,[e])}setRspackEntry(e){this.store.merge({entry:e})}async init(){let e=await Te([`${this.store.appSrc}/${this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}"}`]);if(e[0]){let t=w.join(this.store.empConfig.appSrc,Object.keys(this.store.empConfig.entries).length>0&&this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index");this.setEntryItem(t,this.store.empConfig.html,e[0])}if(Object.keys(this.store.empConfig.entries).length>0)for(let[t,s]of Object.entries(this.store.empConfig.entries))this.setEntryItem(t,{...this.store.empConfig.html,...s})}toConfig(){for(let[e,t]of Object.entries(this.entriesConfig))this.setRspackHtmlPlugin(t.html,e),this.setRspackEntry(t.entry)}},ee=new R});var T,se,oe=c(()=>{"use strict";T=class{store;async setup(e){this.store=e;let t=[this.sass(),this.less(),this.css()];await Promise.all(t)}async sass(){let e={loader:this.store.importResolve("sass-loader"),options:{}};this.store.chain.merge({module:{rule:{sass:{test:/\.(sass|scss)$/,use:[this.postcss,e],type:"css/auto"}}}})}async less(){let e={loader:this.store.importResolve("less-loader"),options:{}};this.store.chain.merge({module:{rule:{less:{test:/\.less$/,use:[this.postcss,e],type:"css/auto"}}}})}async css(){this.store.chain.merge({module:{rule:{css:{test:/\.css$/,use:[this.postcss],type:"css/auto"}}}})}get postcss(){return{loader:this.store.importResolve("postcss-loader"),options:{postcssOptions:{plugins:this.store.empConfig.css.postcss}}}}},se=new T});var F,re,ie=c(()=>{"use strict";Q();Y();Z();te();oe();F=class{store;async setup(e){this.store=e;let t=[K.setup(this.store),X.setup(this.store),q.setup(this.store),ee.setup(this.store),se.setup(this.store)];await Promise.all(t),await this.store.empConfig.plugins(),await this.store.empConfig.chain()}},re=new F});import h from"chalk";import{table as Fe}from"table";var L,n,y=c(()=>{"use strict";L=class{pname="";logLevel="debug";setup({pname:e,logLevel:t}){this.pname=e,t&&(this.logLevel=t)}debug=(...e)=>["debug"].includes(this.logLevel)&&console.log(...e);info=(...e)=>["debug","info"].includes(this.logLevel)&&console.log(...e);warn=(...e)=>["debug","info","warn"].includes(this.logLevel)&&console.warn(...e);error=(...e)=>["debug","info","warn","error"].includes(this.logLevel)&&console.error(...e);blue=e=>{console.log(`${h.white.bgBlue(this.pname)}${h.blue.bgWhite(` ${e} `)}
1
+ var ke=Object.defineProperty;var c=(i,e)=>()=>(i&&(e=i(i=0)),e);var j=(i,e)=>{for(var t in e)ke(i,t,{get:e[t],enumerable:!0})};import{fileURLToPath as je}from"node:url";import{dirname as Te}from"node:path";import{readFile as $e}from"node:fs/promises";var De,ut,T,q=c(()=>{"use strict";De=je(import.meta.url),ut=Te(De),T=async i=>{try{let e=await $e(i);return JSON.parse(e)}catch(e){console.error(e)}}});import E from"@rspack/core";import Re from"fs";var $,Q,X=c(()=>{"use strict";$=class{store;async setup(e){this.store=e;let t=[this.define(),this.anylayze(),this.progress(),this.copy(),this.empShare()];await Promise.all(t)}async anylayze(){if(!this.store.cliOptions.analyze)return;let{default:{BundleAnalyzerPlugin:e}}=await import("webpack-bundle-analyzer");this.store.chain.plugin("bundleAnalyzerPlugin").use(e,[{}])}async define(){this.store.chain.plugin("definePlugin").use(E.DefinePlugin,[this.store.empConfig.define])}async copy(){let e=this.store.resolve("public");Re.existsSync(e)&&this.store.chain.plugin("copyRspackPlugin").use(E.CopyRspackPlugin,[{patterns:[{from:e,to:this.store.resolve("dist")}]}])}async progress(){this.store.empConfig.debug.progress&&this.store.chain.plugin("progressPlugin").use(E.ProgressPlugin,[{prefix:"EMP"}])}async empShare(){if(!this.store.empConfig.empShare.name)return;let{ModuleFederationPlugin:e}=E.container;this.store.chain.plugin("empShare").use(e,[{...this.store.empConfig.empShare}])}},Q=new $});var D,Y,Z=c(()=>{"use strict";D=class{store;async setup(e){this.store=e;let t=[this.react(),this.files(),this.scripts()];await Promise.all(t)}async scripts(){let{isDev:e}=this.store,t=this.store.reactVersion?{react:{runtime:"automatic",development:e,refresh:e}}:{};this.store.chain.merge({module:{parser:{javascript:{exportsPresence:"error",importExportsPresence:"error"}},rule:{mjs:{test:/\.m?js/,resolve:{fullySpecified:!1}},scripts:{test:/\.(jsx?|tsx?)$/,use:[{loader:"builtin:swc-loader",options:{sourceMap:!0,jsc:{parser:{syntax:"typescript",tsx:!0},transform:t}}}]}}}})}async react(){if(this.store.reactVersion&&(this.store.empConfig.react.svgr&&this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,issuer:/\.[jt]sx?$/,resourceQuery:/svgr/,use:[{loader:this.store.importResolve("@svgr/webpack"),options:{}}]}}}}),this.store.isDev&&this.store.empConfig.react.hmr)){let{default:e}=await import("@rspack/plugin-react-refresh"),t={};this.store.empConfig.empShare.name&&(t.library=this.store.empConfig.empShare.name),this.store.chain.plugin("plugin-react-refresh").use(e,[t])}}async files(){(!this.store.reactVersion||!this.store.empConfig.react.svgr)&&this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,type:"asset/resource"}}}}),this.store.chain.merge({module:{rule:{inline:{resourceQuery:/inline/,type:"asset/inline"}}}}),this.store.chain.merge({module:{rule:{image:{test:/\.(png|jpe?g|gif|webp|ico)$/i,type:"asset/resource"},fonts:{test:/\.(|otf|ttf|eot|woff|woff2)$/i,type:"asset/resource"},svga:{test:/\.(svga)$/i,type:"asset/resource"}}}})}},Y=new D});var R,K,ee=c(()=>{"use strict";R=class{store;async setup(e){this.store=e;let t=[this.common(),this.stats(),this.devServer(),this.optimization()];await Promise.all(t)}async common(){this.store.merge({experiments:{rspackFuture:{}},mode:this.store.mode,cache:!0,devtool:this.store.empConfig.build.sourcemap?"source-map":!1,builtins:{css:{modules:{localIdentName:this.store.isDev?"[path][name]-[local]-[hash:5]":"[local]-[hash:5]"}}},output:this.store.empConfig.output,resolve:this.store.empConfig.resolve,externals:this.store.empConfig.externals})}async stats(){this.store.merge({stats:{colors:!0,all:!1,assets:!1,chunks:!1,timings:!0,version:!0}})}async devServer(){this.store.merge({devServer:this.store.empConfig.server})}async optimization(){this.store.chain.merge({optimization:{chunkIds:this.store.empConfig.build.chunkIds,minimize:this.store.empConfig.build.minify}})}},K=new R});function te(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}function w(i,...e){for(let t of e)for(let s in t){let o=t[s],r=i[s];if(Object(o)==o&&Object(r)===r){i[s]=w(r,o);continue}i[s]=t[s]}return i}var se,x=c(()=>{"use strict";se=(i="",e="")=>{let t=i.replace("^","").split("."),s=e.replace("^","").split("."),o=Math.max(t.length,s.length),r=0;for(let n=0;n<o;n++){let m=t.length>n?t[n]:0,l=isNaN(Number(m))?m.charCodeAt():Number(m),u=s.length>n?s[n]:0,f=isNaN(Number(u))?u.charCodeAt():Number(u);if(l<f){r=-1;break}else if(l>f){r=1;break}}return r}});import Le from"html-webpack-plugin";import Ae from"fast-glob";import S from"node:path";var L,re,oe=c(()=>{"use strict";x();L=class{store;entriesConfig={};async setup(e){this.store=e,await this.init(),this.toConfig()}setHtmlConfig(e,t){return e.template=this.setTemplate(e.template),e.favicon=this.setFavicion(e.favicon),e.chunks=t,e.filename=`${t[0]}.html`,this.store.empConfig.base&&(e.publicPath=this.store.empConfig.base),this.store.empConfig.empShareLib&&(e.files=w(e.files,this.store.empConfig.empShareLib.externalAssets)),e}setChunk(e){return e.replace(S.extname(e),"").replace(`${this.store.empConfig.appSrc}/`,"")}setTemplate(e){return e?this.store.resolve(e):this.store.empResolve(S.join("template","index.html"))}setFavicion(e){return e?this.store.resolve(e):this.store.empResolve(S.join("template","favicon.ico"))}setEntryItem(e,t,s){s=s||this.store.resolve(S.join(this.store.empConfig.appSrc,e));let o=this.setChunk(e);this.entriesConfig[o]={entry:{[o]:s},html:this.setHtmlConfig(t,[o])}}setRspackHtmlPlugin(e,t){this.store.chain.plugin(`html-plugin-${t}`).use(Le,[e])}setRspackEntry(e){this.store.merge({entry:e})}async init(){let e=await Ae([`${this.store.appSrc}/${this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}"}`]);if(e[0]){let t=S.join(this.store.empConfig.appSrc,Object.keys(this.store.empConfig.entries).length>0&&this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index");this.setEntryItem(t,this.store.empConfig.html,e[0])}if(Object.keys(this.store.empConfig.entries).length>0)for(let[t,s]of Object.entries(this.store.empConfig.entries))this.setEntryItem(t,{...this.store.empConfig.html,...s})}toConfig(){for(let[e,t]of Object.entries(this.entriesConfig))this.setRspackHtmlPlugin(t.html,e),this.setRspackEntry(t.entry)}},re=new L});var A,ie,ne=c(()=>{"use strict";A=class{store;async setup(e){this.store=e;let t=[this.sass(),this.less(),this.css()];await Promise.all(t)}async sass(){let e={loader:this.store.importResolve("sass-loader"),options:{}};this.store.chain.merge({module:{rule:{sass:{test:/\.(sass|scss)$/,use:[this.postcss,e],type:"css/auto"}}}})}async less(){let e={loader:this.store.importResolve("less-loader"),options:{}};this.store.chain.merge({module:{rule:{less:{test:/\.less$/,use:[this.postcss,e],type:"css/auto"}}}})}async css(){this.store.chain.merge({module:{rule:{css:{test:/\.css$/,use:[this.postcss],type:"css/auto"}}}})}get postcss(){return{loader:this.store.importResolve("postcss-loader"),options:{postcssOptions:{plugins:this.store.empConfig.css.postcss}}}}},ie=new A});var F,pe,ae=c(()=>{"use strict";X();Z();ee();oe();ne();F=class{store;async setup(e){this.store=e;let t=[K.setup(this.store),Y.setup(this.store),Q.setup(this.store),re.setup(this.store),ie.setup(this.store)];await Promise.all(t),await this.store.empConfig.plugins(),await this.store.empConfig.chain()}},pe=new F});import h from"chalk";import{table as Fe}from"table";var N,p,y=c(()=>{"use strict";N=class{pname="";logLevel="debug";setup({pname:e,logLevel:t}){this.pname=e,t&&(this.logLevel=t)}debug=(...e)=>["debug"].includes(this.logLevel)&&console.log(...e);info=(...e)=>["debug","info"].includes(this.logLevel)&&console.log(...e);warn=(...e)=>["debug","info","warn"].includes(this.logLevel)&&console.warn(...e);error=(...e)=>["debug","info","warn","error"].includes(this.logLevel)&&console.error(...e);blue=e=>{console.log(`${h.white.bgBlue(this.pname)}${h.blue.bgWhite(` ${e} `)}
2
2
  `)};cyan=e=>{console.log(`${h.white.bgCyan(this.pname)}${h.cyan.bgWhite(` ${e} `)}
3
3
  `)};magenta=e=>{console.log(`${h.white.bgMagenta(this.pname)}${h.magenta.bgWhite(` ${e} `)}
4
4
  `)};green=e=>{console.log(`${h.white.bgGreen(this.pname)}${h.green.bgWhite(` ${e} `)}
5
5
  `)};yellow=e=>{console.log(`${h.white.bgYellow(this.pname)}${h.yellow.bgWhite(` ${e} `)}
6
6
  `)};red=e=>{console.log(`${h.white.bgRed(this.pname)}${h.red.bgWhite(` ${e} `)}
7
7
  `)};sysError=e=>{console.log(`${h.white.bgRed(" System Error Tips ")}${h.red.bgWhite(` ${e} `)}
8
- `)};link=e=>h.hex("#3498db")(e);tableData=[];tableConfig={border:{topBody:"\u2500",topJoin:"\u252C",topLeft:"\u250C",topRight:"\u2510",bottomBody:"\u2500",bottomJoin:"\u2534",bottomLeft:"\u2514",bottomRight:"\u2518",bodyLeft:"\u2502",bodyRight:"\u2502",bodyJoin:"\u2502",joinBody:"\u2500",joinLeft:"\u251C",joinRight:"\u2524",joinJoin:"\u253C"}};tableInput(e){this.tableData.push(e)}tableOutput(){console.log(Fe(this.tableData,this.tableConfig))}},n=new L});function ne(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}function A(o,...e){for(let t of e)for(let s in t){let r=t[s],i=o[s];if(Object(r)==r&&Object(i)===i){o[s]=A(i,r);continue}o[s]=t[s]}return o}var pe,E=c(()=>{"use strict";pe=(o="",e="")=>{let t=o.replace("^","").split("."),s=e.replace("^","").split("."),r=Math.max(t.length,s.length),i=0;for(let a=0;a<r;a++){let m=t.length>a?t[a]:0,l=isNaN(Number(m))?m.charCodeAt():Number(m),u=s.length>a?s[a]:0,g=isNaN(Number(u))?u.charCodeAt():Number(u);if(l<g){i=-1;break}else if(l>g){i=1;break}}return i}});import Le from"node:fs";var N,ae,le=c(()=>{"use strict";E();N=class{store;appSrc="src";appEntry="";base="";assign(e,t){return t=t||{},{...e,...t}}async setup(e){this.store=e,await this.syncEmpOptions();let{appSrc:t,base:s,appEntry:r}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),r&&(this.appEntry=r)}async chain(){this.store.empOptions.chain&&await this.store.empOptions.chain(this.store.chain)}async plugins(){let e=[];this.store.empOptions.plugins&&Array.isArray(this.store.empOptions.plugins)&&this.store.empOptions.plugins.length>0&&(this.store.empOptions.plugins.map(t=>{e.push(t.rsConfig(this.store))}),await Promise.all(e))}get debug(){return this.assign({loggerLevel:"info",clearLog:!0,progress:!1,showRsconfig:!1},this.store.empOptions.debug)}get build(){return this.assign({outDir:"dist",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev},this.store.empOptions.build)}get html(){return this.assign({lang:"zh-CN",title:"EMP",inject:"body",minify:!this.store.isDev,meta:{charset:{charset:"utf-8"},"http-equiv":{"http-equiv":"X-UA-Compatible",content:"IE=edge"},viewport:{content:"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"}},files:{css:[],js:[]},tags:{headTags:[],bodyTags:[]}},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get react(){return this.assign({hmr:!0,svgr:!1},this.store.empOptions.react)}get server(){return this.assign({host:"0.0.0.0",port:8e3,open:!1,hot:!0,allowedHosts:["all"],historyApiFallback:!0,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS","Access-Control-Allow-Headers":"X-Requested-With, content-type, Authorization"}},this.store.empOptions.server)}get empShare(){return this.assign({name:"",filename:"emp.js"},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}get output(){let e=(this.store.isDev,".[contenthash:8]");return this.assign({publicPath:this.store.empConfig.base?this.store.empConfig.base:"auto",crossOriginLoading:"anonymous",filename:`js/[name]${e}.js`,cssFilename:`css/[name]${e}.css`,cssChunkFilename:`css/[name]${e}.css`,assetModuleFilename:`assets/[name]${e}[ext][query]`,path:this.store.outDir,clean:!0},this.store.empOptions.output)}get define(){return this.assign({"process.env.NODE_ENV":`'${this.store.mode}'`,"import.meta.env.NODE_ENV":`'${this.store.mode}'`},this.store.empOptions.define)}get externals(){return this.assign({},this.store.empOptions.externals)}get resolve(){return A({alias:{src:this.store.resolve("src"),"@":this.store.resolve("src")},extensions:["...",".js",".jsx",".mjs",".ts",".tsx",".css",".less",".scss",".sass",".json",".wasm",".vue",".svg",".svga"]},this.store.empOptions.resolve)}async syncEmpOptions(){let e=this.store.resolve("emp-config.js");if(!Le.existsSync(e))return;let{default:t}=await import(e);typeof t=="function"?this.store.empOptions=await t(this.store):this.store.empOptions=t||{}}get moduleTransformRule(){let e={and:[/(node_modules|bower_components)/]},{moduleTransform:t}=this.store.empOptions;return t?.exclude&&(e.and=t.exclude),t?.include&&(e.not=t.include),e}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}},ae=new N});import v from"node:path";import Ae from"webpack-chain";var M,p,f=c(()=>{"use strict";J();ie();y();le();M=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=import.meta.resolve("@empjs/cli").replace("/dist/index.js","").replace("file://","");empSource=v.resolve(this.empRoot,"dist");resolve=e=>v.isAbsolute(e)?e:v.resolve(this.root,e);empResolve=e=>v.resolve(this.empRoot,e);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};cacheDir="";mode="development";cliMode="dev";isDev=!0;reactVersion=void 0;cliOptions;chain;rsConfig;empOptions={};empConfig;async setup(e,t){await this.initVars(e,t),this.empConfig=ae,await this.empConfig.setup(this),this.initPaths(),this.chain=new Ae,await re.setup(this),this.setLogger(),this.toConfig(),this.logConfig()}async initVars(e,t){this.cliOptions=t||{},this.cliMode="prod",this.mode=e==="dev"?"development":"production",this.isDev=this.mode==="development";let s=await k(this.empResolve("package.json")),r=await k(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...r},this.reactVersion=this.pkg.dependencies.react||this.pkg.devDependencies.react}initPaths(){this.appSrc=this.resolve(this.empConfig.appSrc),this.outDir=this.resolve(this.empConfig.build.outDir),this.publicDir=this.resolve(this.empConfig.build.publicDir),this.cacheDir=this.resolve(this.empConfig.cacheDir),this.resource.dir=v.join(this.empRoot,"resource"),this.resource.cert=v.join(this.resource.dir,"emp.cert"),this.resource.key=v.join(this.resource.dir,"emp.key")}setLogger(){let e=this.cliMode==="dev"?"debug":"info";this.empConfig.debug.loggerLevel&&(e=this.empConfig.debug.loggerLevel),n.setup({pname:` EMP v${this.empPkg.version} ${this.cliMode==="dev"?"DEV ":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e){return import.meta.resolve(e).replace("file://","")}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){this.empConfig.debug.showRsconfig&&console.log("[ChainConfig]",JSON.stringify(this.rsConfig,null,2))}},p=new M});import ce from"node:fs/promises";var d,S=c(()=>{"use strict";y();f();E();d=class{async setup(e,t){await p.setup(e,t),p.empConfig.debug.clearLog&&ne(),n.blue(`${e} Running`),await this.run()}async run(){}get isHttps(){let{server:e,https:t}=p.rsConfig.devServer||{};return e==="https"||typeof e=="object"&&e.type==="https"||t===!0}getcert(){return Promise.all([ce.readFile(p.resource.key),ce.readFile(p.resource.cert)])}}});import Ne from"net";import Me from"os";async function O(o,e="localhost"){if(o!==Ge&&(o<me||o>G))throw new Error(`Port number must lie between ${me} and ${G}`);let t=o,s=He(),r;e&&!s.has(e)?r=new Set([e]):r=s;let i=new Set(["EADDRINUSE","EACCES"]);for(;t<=G;)try{return await Ue(t,r)}catch(a){if(!i.has(a.code))throw a;t+=1}throw new Error("No available ports found")}var me,G,Ge,He,Ie,Ue,H=c(()=>{"use strict";me=1024,G=65535,Ge=443,He=()=>{let o=Me.networkInterfaces(),e=new Set([void 0,"0.0.0.0"]);for(let t of Object.values(o))if(t)for(let s of t)e.add(s.address);return e},Ie=(o,e)=>new Promise((t,s)=>{let r=Ne.createServer();r.unref(),r.on("error",s),r.listen(o,e,()=>{let{port:i}=r.address();r.close(()=>{t(i)})})}),Ue=async(o,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await Ie(o,s)}catch(r){if(!t.has(r.code))throw r}return o}});var he={};P(he,{default:()=>We});import{rspack as Ve}from"@rspack/core";import{RspackDevServer as Be}from"@rspack/dev-server";var I,We,ue=c(()=>{"use strict";f();S();y();H();I=class extends d{async run(){let e=Ve(p.rsConfig);if(!p.rsConfig.devServer){n.error("devServer is not defined in config");return}let t=Object.assign({},p.rsConfig.devServer),{host:s,port:r}=t;if(this.isHttps&&(t.https===!0&&delete t.https,!t.server)){let[m,l]=await this.getcert();t.server={type:"https",options:{key:m,cert:l}}}let i=await O(Number(r),s);i!==r&&(p.rsConfig.devServer.port=i,t.port=i),new Be(t,e).start()}},We=new I});var ge={};P(ge,{default:()=>ze});import{rspack as _e}from"@rspack/core";var U,ze,fe=c(()=>{"use strict";y();f();S();U=class extends d{async run(){_e(p.rsConfig,(e,t)=>{if(e!==null){n.error(e.stack||e),e.message&&n.error(e.message);return}if(!t){n.red("Stats is Undefined.");return}let s=t.toString({all:!1,colors:!0,assets:!0,chunks:!1,entrypoints:!0,timings:!0,version:!0});t.hasErrors()&&(n.error(s),n.red("Failed to compile."),process.exit(1)),t.hasWarnings()&&(n.yellow("Compiled with warnings."),n.warn(s)),n.info(s),n.green("Compiled successfully.")})}},ze=new U});import de from"url";import ye from"chalk";import{ip as Je}from"address";import{gateway4sync as qe}from"default-gateway";function ve(o,e,t,s="/"){let r=C=>de.format({protocol:o,hostname:C,port:t,pathname:s}),i=C=>de.format({protocol:o,hostname:C,port:ye.bold(t),pathname:s}),a=e==="0.0.0.0"||e==="::",m,l,u=ye.gray("unavailable");if(a){m="localhost";try{let{int:C}=qe();l=Je(C||""),l&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(l)?u=i(l):l=void 0)}catch{}}else m=e,l=e,u=i(l);let g=i(m),z=r(m);return{lanUrlForConfig:l,lanUrlForTerminal:u,localUrlForTerminal:g,localUrlForBrowser:z}}var be=c(()=>{"use strict"});var we={};P(we,{default:()=>et});import Ce from"express";import Qe from"cors";import Xe from"compression";import Ye from"https";import Ke from"path";import Ze from"node:fs/promises";var V,et,xe=c(()=>{"use strict";H();be();f();y();S();V=class extends d{app;startLogger({host:e,port:t,publicPath:s}){if(s&&(s.indexOf("http://")>-1||s.indexOf("https://")>-1))n.info(`- Network: ${n.link(s)}`);else{let r=this.isHttps?"https":"http",a=ve(r,e||"0.0.0.0",t,s);n.info(`- Local: ${n.link(a.localUrlForTerminal)}`),n.info(`- Network: ${n.link(a.lanUrlForTerminal)}`)}}async run(){let e=Ce();e.use(Xe()),e.use(Qe()),this.app=e;let t=p.resolve(p.rsConfig.output?.path);this.app.use(Ce.static(t));let s=await Ze.readFile(Ke.join(t,"index.html"),"utf8");this.app.get("*",(u,g)=>g.send(s));let r=Object.assign({},p.rsConfig.devServer),{host:i,port:a}=r,m=p.rsConfig.output?.publicPath==="auto"?"/":p.rsConfig.output?.publicPath,l=await O(Number(a),i);if(this.isHttps){let[u,g]=await this.getcert();Ye.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:u,cert:g},this.app).listen(l,()=>{this.startLogger({host:i,port:l,publicPath:m})})}else this.app.listen(l,()=>{this.startLogger({host:i,port:l,publicPath:m})})}},et=new V});f();f();E();y();import{program as b}from"commander";import B,{exit as tt}from"node:process";function Ee(){let o="20.0.0";pe(o,B.versions.node)===1&&(n.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${B.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${o}`),tt(0)),b.version(p.empPkg.version,"-v, --version").usage("<command> [options]"),b.command("dev").description("Dev \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-h, --hot","\u662F\u5426\u4F7F\u7528\u70ED\u66F4\u65B0 \u9ED8\u8BA4\u542F\u52A8").option("-o, --open","\u662F\u5426\u6253\u5F00\u8C03\u8BD5\u9875\u9762 \u9ED8\u8BA4\u4E0D\u6253\u5F00").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(ue(),he));await t.setup("dev",e)}),b.command("build").description("Build \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-a, --analyze","\u751F\u6210\u5206\u6790\u62A5\u544A \u9ED8\u8BA4\u4E3A false").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(fe(),ge));await t.setup("build",e)}),b.command("serve").description("Server \u6A21\u5F0F").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(xe(),we));await t.setup("serve",e)}),b.command("dts").description("\u62C9\u53D6 remote \u9879\u76EE\u7684 d.ts").option("-p, --typingsPath <typingsPath>","\u4E0B\u8F7D\u76EE\u5F55").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").action(e=>{}),b.command("init").description("\u521D\u59CB\u5316 emp \u9879\u76EE").option("-d, --data [data]","JSON\u6570\u636E http\u5730\u5740 \u6216\u8005 \u6587\u4EF6\u8DEF\u5F84\u76F8\u5BF9\u3001\u7EDD\u5BF9\u8DEF\u5F84").action(e=>{}),b.parse(B.argv)}f();import st from"fast-glob";import Se from"node:fs/promises";import W from"node:path";var ot=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,rt=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,it=/import\(['"]([^;\n]+?)['"]\)/,_=class{list=[];outDir=p.resolve("dist");aliasName="@empjs/cli";async setup(e,t){e&&(this.outDir=e),t&&(this.aliasName=t);let s=await this.readDts();await this.writeCode(s)}async readDts(){this.list=await st(["dist/**/*.d.ts"]);let e=[];this.list.map(s=>{s=p.resolve(s),e.push(this.readFile(s))});let t=await Promise.all(e);return t=t.map(s=>this.replaceAliasPath(s)),t}async readFile(e){let t=await Se.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(ot,r=>{let i=r.match(rt);if(i||(i=r.match(it)),i&&i[1]){let a=i[1];if(!a.startsWith("."))return r;let m=W.resolve(W.dirname(e),a).replace(this.outDir,this.aliasName);return r.replace(i[1],m)}return r});let s=e.replace(this.outDir,this.aliasName).replace(".d.ts","");return s.endsWith("/index")&&(s=s.replace("/index","")),t=this.warpDeclareModule(s,t),{code:t,src:e,mod:s}}warpDeclareModule(e,t){return`declare module '${e}' {\r
8
+ `)};link=e=>h.hex("#3498db")(e);tableData=[];tableConfig={border:{topBody:"\u2500",topJoin:"\u252C",topLeft:"\u250C",topRight:"\u2510",bottomBody:"\u2500",bottomJoin:"\u2534",bottomLeft:"\u2514",bottomRight:"\u2518",bodyLeft:"\u2502",bodyRight:"\u2502",bodyJoin:"\u2502",joinBody:"\u2500",joinLeft:"\u251C",joinRight:"\u2524",joinJoin:"\u253C"}};tableInput(e){this.tableData.push(e)}tableOutput(){console.log(Fe(this.tableData,this.tableConfig))}},p=new N});var O,le=c(()=>{"use strict";O=class{externals={};externalAssets={js:[],css:[]};exp=/^([0-9a-zA-Z_\s]+)@(.*)/;async setup(e){this.setShareLib(e),delete e.shareLib}async setShareLib(e){let t=[];if(typeof e.shareLib=="object")for(let[s,o]of Object.entries(e.shareLib)){let r={};if(r.module=s,typeof o=="string"){let n=o.match(this.exp)||[];n.length>0?(r.global=n[1],r.entry=n[2],r.type="js",t.push(r),r={}):(r.global="",r.entry=o,r.type="js",t.push(r),r={})}else Array.isArray(o)?o.map(n=>{if(!n)return;if(n.split("?")[0].endsWith(".css"))r.entry=n,r.type="css";else{let l=n.match(this.exp)||[];l.length>0?(r.global=l[1],r.entry=l[2],r.type="js"):(r.global="",r.entry=n,r.type="js")}t.push(r),r={}}):typeof o=="object"&&o.entry&&(r.entry=o.entry,r.global=o.global,r.type=o.type,t.push(r),r={})}await Promise.all([this.setExternalAssets(t)])}async setExternalAssets(e=[]){if(e.length>0){let t=[];t=t.concat(e),t.map(s=>{s.type=s.type||"js",s.type==="js"&&s.module?(s.global&&(this.externals[s.module]=s.global),s.entry&&this.externalAssets.js.push(s.entry)):s.type==="css"&&s.entry&&this.externalAssets.css.push(s.entry)})}}}});import Ne from"node:fs";var M,ce,me=c(()=>{"use strict";x();le();M=class{store;appSrc="src";appEntry="";base="";assign(e,t){return t=t||{},w(e,t)}empShareLib=new O;async setup(e){this.store=e,await this.syncEmpOptions();let{appSrc:t,base:s,appEntry:o}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),o&&(this.appEntry=o),this.store.empOptions.empShare?.shareLib&&await this.empShareLib.setup(this.store.empOptions.empShare)}async chain(){this.store.empOptions.chain&&await this.store.empOptions.chain(this.store.chain)}async plugins(){let e=[];this.store.empOptions.plugins&&Array.isArray(this.store.empOptions.plugins)&&this.store.empOptions.plugins.length>0&&(this.store.empOptions.plugins.map(t=>{e.push(t.rsConfig(this.store))}),await Promise.all(e))}get debug(){return this.assign({loggerLevel:"info",clearLog:!0,progress:!1,showRsconfig:!1},this.store.empOptions.debug)}get build(){return this.assign({outDir:"dist",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev},this.store.empOptions.build)}get html(){return this.assign({lang:"zh-CN",title:"EMP",inject:"body",minify:!this.store.isDev,meta:{charset:{charset:"utf-8"},"http-equiv":{"http-equiv":"X-UA-Compatible",content:"IE=edge"},viewport:{content:"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"}},files:{css:[],js:[]},tags:{headTags:[],bodyTags:[]}},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get react(){return this.assign({hmr:!0,svgr:!1},this.store.empOptions.react)}get server(){return this.assign({host:"0.0.0.0",port:8e3,open:!1,hot:!0,allowedHosts:["all"],historyApiFallback:!0,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS","Access-Control-Allow-Headers":"X-Requested-With, content-type, Authorization"}},this.store.empOptions.server)}get empShare(){return this.assign({name:"",filename:"emp.js",shared:{}},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}get output(){let e=(this.store.isDev,".[contenthash:8]");return this.assign({publicPath:this.store.empConfig.base?this.store.empConfig.base:"auto",crossOriginLoading:"anonymous",filename:`js/[name]${e}.js`,cssFilename:`css/[name]${e}.css`,cssChunkFilename:`css/[name]${e}.css`,assetModuleFilename:`assets/[name]${e}[ext][query]`,path:this.store.outDir,clean:!0},this.store.empOptions.output)}get define(){return this.assign({"process.env.NODE_ENV":`'${this.store.mode}'`,"import.meta.env.NODE_ENV":`'${this.store.mode}'`},this.store.empOptions.define)}get externals(){return this.assign(this.empShareLib.externals,this.store.empOptions.externals)}get resolve(){return w({alias:{src:this.store.resolve("src"),"@":this.store.resolve("src")},extensions:["...",".js",".jsx",".mjs",".ts",".tsx",".css",".less",".scss",".sass",".json",".wasm",".vue",".svg",".svga"]},this.store.empOptions.resolve)}async syncEmpOptions(){let e=this.store.resolve("emp-config.js");if(!Ne.existsSync(e))return;let{default:t}=await import(e);typeof t=="function"?this.store.empOptions=await t(this.store):this.store.empOptions=t||{}}get moduleTransformRule(){let e={and:[/(node_modules|bower_components)/]},{moduleTransform:t}=this.store.empOptions;return t?.exclude&&(e.and=t.exclude),t?.include&&(e.not=t.include),e}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}},ce=new M});import b from"node:path";import Me from"webpack-chain";var G,a,g=c(()=>{"use strict";q();ae();y();me();G=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=import.meta.resolve("@empjs/cli").replace("/dist/index.js","").replace("file://","");empSource=b.resolve(this.empRoot,"dist");resolve=e=>b.isAbsolute(e)?e:b.resolve(this.root,e);empResolve=e=>b.resolve(this.empRoot,e);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};cacheDir="";mode="development";cliMode="dev";isDev=!0;reactVersion=void 0;cliOptions;chain;rsConfig;empOptions={};empConfig;async setup(e,t){await this.initVars(e,t),this.empConfig=ce,await this.empConfig.setup(this),this.initPaths(),this.chain=new Me,await pe.setup(this),this.setLogger(),this.toConfig(),this.logConfig()}async initVars(e,t){this.cliOptions=t||{},this.cliMode="prod",this.mode=e==="dev"?"development":"production",this.isDev=this.mode==="development";let s=await T(this.empResolve("package.json")),o=await T(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...o},this.reactVersion=this.pkg.dependencies.react||this.pkg.devDependencies.react}initPaths(){this.appSrc=this.resolve(this.empConfig.appSrc),this.outDir=this.resolve(this.empConfig.build.outDir),this.publicDir=this.resolve(this.empConfig.build.publicDir),this.cacheDir=this.resolve(this.empConfig.cacheDir),this.resource.dir=b.join(this.empRoot,"resource"),this.resource.cert=b.join(this.resource.dir,"emp.cert"),this.resource.key=b.join(this.resource.dir,"emp.key")}setLogger(){let e=this.cliMode==="dev"?"debug":"info";this.empConfig.debug.loggerLevel&&(e=this.empConfig.debug.loggerLevel),p.setup({pname:` EMP v${this.empPkg.version} ${this.cliMode==="dev"?"DEV ":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e){return import.meta.resolve(e).replace("file://","")}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){this.empConfig.debug.showRsconfig&&console.log("[ChainConfig]",JSON.stringify(this.rsConfig,null,2))}},a=new G});import he from"node:fs/promises";var d,P=c(()=>{"use strict";y();g();x();d=class{async setup(e,t){await a.setup(e,t),a.empConfig.debug.clearLog&&te(),p.blue(`${e} Running`),await this.run()}async run(){}get isHttps(){let{server:e,https:t}=a.rsConfig.devServer||{};return e==="https"||typeof e=="object"&&e.type==="https"||t===!0}getcert(){return Promise.all([he.readFile(a.resource.key),he.readFile(a.resource.cert)])}}});import Ge from"net";import Ie from"os";async function k(i,e="localhost"){if(i!==He&&(i<ue||i>I))throw new Error(`Port number must lie between ${ue} and ${I}`);let t=i,s=Ue(),o;e&&!s.has(e)?o=new Set([e]):o=s;let r=new Set(["EADDRINUSE","EACCES"]);for(;t<=I;)try{return await We(t,o)}catch(n){if(!r.has(n.code))throw n;t+=1}throw new Error("No available ports found")}var ue,I,He,Ue,Ve,We,H=c(()=>{"use strict";ue=1024,I=65535,He=443,Ue=()=>{let i=Ie.networkInterfaces(),e=new Set([void 0,"0.0.0.0"]);for(let t of Object.values(i))if(t)for(let s of t)e.add(s.address);return e},Ve=(i,e)=>new Promise((t,s)=>{let o=Ge.createServer();o.unref(),o.on("error",s),o.listen(i,e,()=>{let{port:r}=o.address();o.close(()=>{t(r)})})}),We=async(i,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await Ve(i,s)}catch(o){if(!t.has(o.code))throw o}return i}});var fe={};j(fe,{default:()=>ze});import{rspack as _e}from"@rspack/core";import{RspackDevServer as Be}from"@rspack/dev-server";var U,ze,ge=c(()=>{"use strict";g();P();y();H();U=class extends d{async run(){let e=_e(a.rsConfig);if(!a.rsConfig.devServer){p.error("devServer is not defined in config");return}let t=Object.assign({},a.rsConfig.devServer),{host:s,port:o}=t;if(this.isHttps&&(t.https===!0&&delete t.https,!t.server)){let[m,l]=await this.getcert();t.server={type:"https",options:{key:m,cert:l}}}let r=await k(Number(o),s);r!==o&&(a.rsConfig.devServer.port=r,t.port=r),new Be(t,e).start()}},ze=new U});var de={};j(de,{default:()=>qe});import{rspack as Je}from"@rspack/core";var V,qe,ye=c(()=>{"use strict";y();g();P();V=class extends d{async run(){Je(a.rsConfig,(e,t)=>{if(e!==null){p.error(e.stack||e),e.message&&p.error(e.message);return}if(!t){p.red("Stats is Undefined.");return}let s=t.toString({all:!1,colors:!0,assets:!0,chunks:!1,entrypoints:!0,timings:!0,version:!0});t.hasErrors()&&(p.error(s),p.red("Failed to compile."),process.exit(1)),t.hasWarnings()&&(p.yellow("Compiled with warnings."),p.warn(s)),p.info(s),p.green("Compiled successfully.")})}},qe=new V});import be from"url";import ve from"chalk";import{ip as Qe}from"address";import{gateway4sync as Xe}from"default-gateway";function Ce(i,e,t,s="/"){let o=C=>be.format({protocol:i,hostname:C,port:t,pathname:s}),r=C=>be.format({protocol:i,hostname:C,port:ve.bold(t),pathname:s}),n=e==="0.0.0.0"||e==="::",m,l,u=ve.gray("unavailable");if(n){m="localhost";try{let{int:C}=Xe();l=Qe(C||""),l&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(l)?u=r(l):l=void 0)}catch{}}else m=e,l=e,u=r(l);let f=r(m),J=o(m);return{lanUrlForConfig:l,lanUrlForTerminal:u,localUrlForTerminal:f,localUrlForBrowser:J}}var we=c(()=>{"use strict"});var Se={};j(Se,{default:()=>st});import xe from"express";import Ye from"cors";import Ze from"compression";import Ke from"https";import et from"path";import tt from"node:fs/promises";var W,st,Ee=c(()=>{"use strict";H();we();g();y();P();W=class extends d{app;startLogger({host:e,port:t,publicPath:s}){if(s&&(s.indexOf("http://")>-1||s.indexOf("https://")>-1))p.info(`- Network: ${p.link(s)}`);else{let o=this.isHttps?"https":"http",n=Ce(o,e||"0.0.0.0",t,s);p.info(`- Local: ${p.link(n.localUrlForTerminal)}`),p.info(`- Network: ${p.link(n.lanUrlForTerminal)}`)}}async run(){let e=xe();e.use(Ze()),e.use(Ye()),this.app=e;let t=a.resolve(a.rsConfig.output?.path);this.app.use(xe.static(t));let s=await tt.readFile(et.join(t,"index.html"),"utf8");this.app.get("*",(u,f)=>f.send(s));let o=Object.assign({},a.rsConfig.devServer),{host:r,port:n}=o,m=a.rsConfig.output?.publicPath==="auto"?"/":a.rsConfig.output?.publicPath,l=await k(Number(n),r);if(this.isHttps){let[u,f]=await this.getcert();Ke.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:u,cert:f},this.app).listen(l,()=>{this.startLogger({host:r,port:l,publicPath:m})})}else this.app.listen(l,()=>{this.startLogger({host:r,port:l,publicPath:m})})}},st=new W});g();g();x();y();import{program as v}from"commander";import _,{exit as rt}from"node:process";function Oe(){let i="20.0.0";se(i,_.versions.node)===1&&(p.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${_.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${i}`),rt(0)),v.version(a.empPkg.version,"-v, --version").usage("<command> [options]"),v.command("dev").description("Dev \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-h, --hot","\u662F\u5426\u4F7F\u7528\u70ED\u66F4\u65B0 \u9ED8\u8BA4\u542F\u52A8").option("-o, --open","\u662F\u5426\u6253\u5F00\u8C03\u8BD5\u9875\u9762 \u9ED8\u8BA4\u4E0D\u6253\u5F00").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(ge(),fe));await t.setup("dev",e)}),v.command("build").description("Build \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-a, --analyze","\u751F\u6210\u5206\u6790\u62A5\u544A \u9ED8\u8BA4\u4E3A false").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(ye(),de));await t.setup("build",e)}),v.command("serve").description("Server \u6A21\u5F0F").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(Ee(),Se));await t.setup("serve",e)}),v.command("dts").description("\u62C9\u53D6 remote \u9879\u76EE\u7684 d.ts").option("-p, --typingsPath <typingsPath>","\u4E0B\u8F7D\u76EE\u5F55").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").action(e=>{}),v.command("init").description("\u521D\u59CB\u5316 emp \u9879\u76EE").option("-d, --data [data]","JSON\u6570\u636E http\u5730\u5740 \u6216\u8005 \u6587\u4EF6\u8DEF\u5F84\u76F8\u5BF9\u3001\u7EDD\u5BF9\u8DEF\u5F84").action(e=>{}),v.parse(_.argv)}g();import ot from"fast-glob";import Pe from"node:fs/promises";import B from"node:path";var it=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,nt=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,pt=/import\(['"]([^;\n]+?)['"]\)/,z=class{list=[];outDir=a.resolve("dist");aliasName="@empjs/cli";async setup(e,t){e&&(this.outDir=e),t&&(this.aliasName=t);let s=await this.readDts();await this.writeCode(s)}async readDts(){this.list=await ot(["dist/**/*.d.ts"]);let e=[];this.list.map(s=>{s=a.resolve(s),e.push(this.readFile(s))});let t=await Promise.all(e);return t=t.map(s=>this.replaceAliasPath(s)),t}async readFile(e){let t=await Pe.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(it,o=>{let r=o.match(nt);if(r||(r=o.match(pt)),r&&r[1]){let n=r[1];if(!n.startsWith("."))return o;let m=B.resolve(B.dirname(e),n).replace(this.outDir,this.aliasName);return o.replace(r[1],m)}return o});let s=e.replace(this.outDir,this.aliasName).replace(".d.ts","");return s.endsWith("/index")&&(s=s.replace("/index","")),t=this.warpDeclareModule(s,t),{code:t,src:e,mod:s}}warpDeclareModule(e,t){return`declare module '${e}' {\r
9
9
  ${t}}\r
10
- `}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await Se.writeFile(W.join(this.outDir.replace("dist","types"),"type.d.ts"),t)}},nt=new _;function Is(o){return o}export{Is as defineConfig,nt as dts,Ee as runScript,p as store};
10
+ `}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await Pe.writeFile(B.join(this.outDir.replace("dist","types"),"type.d.ts"),t)}},at=new z;function Bs(i){return i}export{Bs as defineConfig,at as dts,Oe as runScript,a as store};
@@ -1,8 +1,9 @@
1
1
  import { GlobalStore } from '../store';
2
2
  import { BuildType, DebugType, HtmlType, ReactType, ServerType } from '../types/config';
3
3
  import { Output } from '@rspack/core';
4
+ import { EMPShareLib } from '../store/empShareLib';
4
5
  export declare class EmpConfig {
5
- store: GlobalStore;
6
+ private store;
6
7
  /**
7
8
  * 项目代码路径
8
9
  * @default 'src'
@@ -22,6 +23,7 @@ export declare class EmpConfig {
22
23
  */
23
24
  base: string;
24
25
  private assign;
26
+ empShareLib: EMPShareLib;
25
27
  setup(store: GlobalStore): Promise<void>;
26
28
  chain(): Promise<void>;
27
29
  plugins(): Promise<void>;
@@ -34,6 +36,7 @@ export declare class EmpConfig {
34
36
  get empShare(): {
35
37
  name: string;
36
38
  filename: string;
39
+ shared: {};
37
40
  };
38
41
  get css(): {
39
42
  postcss: never[];
@@ -43,7 +46,7 @@ export declare class EmpConfig {
43
46
  'process.env.NODE_ENV': string;
44
47
  'import.meta.env.NODE_ENV': string;
45
48
  };
46
- get externals(): {};
49
+ get externals(): any;
47
50
  get resolve(): import("@rspack/core").ResolveOptions;
48
51
  syncEmpOptions(): Promise<void>;
49
52
  get moduleTransformRule(): any;
@@ -0,0 +1,14 @@
1
+ import { Configuration } from '@rspack/core';
2
+ import type { EMPShareType } from '../types/config';
3
+ export type externalAssetsType = {
4
+ js: string[];
5
+ css: string[];
6
+ };
7
+ export declare class EMPShareLib {
8
+ externals: Configuration['externals'] | any;
9
+ externalAssets: externalAssetsType;
10
+ private exp;
11
+ setup(empShare: EMPShareType): Promise<void>;
12
+ setShareLib(mf: EMPShareType): Promise<void>;
13
+ private setExternalAssets;
14
+ }
@@ -114,6 +114,49 @@ export interface ModuleTransform {
114
114
  exclude?: RuleSetRule['exclude'][];
115
115
  include?: RuleSetRule['include'][];
116
116
  }
117
+ export type EMPShareType = ModuleFederationPluginOptions & {
118
+ /**
119
+ * emp 基于库共享模块
120
+ */
121
+ shareLib?: EMPshareLibItemType;
122
+ /**
123
+ * 是否使用 importMap
124
+ */
125
+ useImportMap?: boolean;
126
+ };
127
+ export type EMPshareLibItemType = {
128
+ [module: string]: {
129
+ entry: string;
130
+ global?: string;
131
+ type?: 'js' | 'css';
132
+ } | string | string[];
133
+ };
134
+ export type ExternalsItemType = {
135
+ /**
136
+ * 模块名
137
+ * @example react-dom
138
+ */
139
+ module?: string;
140
+ /**
141
+ * 全局变量
142
+ * @example ReactDom
143
+ */
144
+ global?: string;
145
+ /**
146
+ * 入口地址
147
+ * 不填则可以通过 emp-config 里的 html.files.js[url] 传入合并后的请求
148
+ * 如 http://...?react&react-dom&react-router&mobx
149
+ * @example http://
150
+ */
151
+ entry?: string;
152
+ /**
153
+ * 类型入口
154
+ * @default js
155
+ * @enum js | css
156
+ * @example css
157
+ */
158
+ type?: string;
159
+ };
117
160
  export type EmpOptions = {
118
161
  /**
119
162
  * publicPath 根路径 可参考webpack,业务模式默认为 auto
@@ -141,7 +184,7 @@ export type EmpOptions = {
141
184
  debug?: DebugType;
142
185
  chain?: (chain: Chain) => void;
143
186
  react?: ReactType;
144
- empShare?: ModuleFederationPluginOptions;
187
+ empShare?: EMPShareType;
145
188
  /**
146
189
  * css 相关设置
147
190
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empjs/cli",
3
- "version": "3.0.0-alpha.28",
3
+ "version": "3.0.0-alpha.29",
4
4
  "description": "emp",
5
5
  "license": "MIT",
6
6
  "type": "module",