@empjs/cli 3.0.0-beta.23 → 3.0.0-beta.25
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/helper/ipAddress.d.ts +27 -0
- package/dist/index.js +14 -14
- package/dist/script/base.d.ts +18 -4
- package/dist/store/cycle/autoDevBase.d.ts +8 -0
- package/dist/store/cycleRuntime.d.ts +5 -0
- package/dist/store/empConfig.d.ts +1 -0
- package/dist/types/config.d.ts +4 -0
- package/package.json +1 -1
- package/dist/helper/prepareURLs.d.ts +0 -6
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type IpAdressOpt = {
|
|
2
|
+
protocol?: string;
|
|
3
|
+
port?: number;
|
|
4
|
+
pathname?: string;
|
|
5
|
+
host?: string;
|
|
6
|
+
};
|
|
7
|
+
declare class IpAdress {
|
|
8
|
+
imf: {
|
|
9
|
+
protocol: string;
|
|
10
|
+
port: number;
|
|
11
|
+
pathname: string;
|
|
12
|
+
};
|
|
13
|
+
host: string;
|
|
14
|
+
urls: {
|
|
15
|
+
lanUrlForConfig: string;
|
|
16
|
+
lanUrlForTerminal: string;
|
|
17
|
+
localUrlForTerminal: string;
|
|
18
|
+
localUrlForBrowser: string;
|
|
19
|
+
};
|
|
20
|
+
setup(o: IpAdressOpt): void;
|
|
21
|
+
private setupUrls;
|
|
22
|
+
getLanIp(): string;
|
|
23
|
+
formatUrl(hostname: string): string;
|
|
24
|
+
prettyPrintUrl(hostname: string): string;
|
|
25
|
+
}
|
|
26
|
+
declare const _default: IpAdress;
|
|
27
|
+
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)};cyan=e=>{console.log(`${
|
|
3
|
-
`)};magenta=e=>{console.log(`${
|
|
4
|
-
`)};green=e=>{console.log(`${
|
|
5
|
-
`)};yellow=e=>{console.log(`${
|
|
6
|
-
`)};red=e=>{console.log(`${
|
|
7
|
-
`)};sysError=e=>{console.log(`${
|
|
8
|
-
`)};link=e=>
|
|
9
|
-
`)};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(at(this.tableData,this.tableConfig))}},p=new V});var j,Pe=h(()=>{"use strict";j=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,i]of Object.entries(e.shareLib)){let o={};if(o.module=s,typeof i=="string"){let n=i.match(this.exp)||[];n.length>0?(o.global=n[1],o.entry=n[2],o.type="js",t.push(o),o={}):(o.global="",o.entry=i,o.type="js",t.push(o),o={})}else Array.isArray(i)?i.map(n=>{if(!n)return;if(n.split("?")[0].endsWith(".css"))o.entry=n,o.type="css";else{let c=n.match(this.exp)||[];c.length>0?(o.global=c[1],o.entry=c[2],o.type="js"):(o.global="",o.entry=n,o.type="js")}t.push(o),o={}}):typeof i=="object"&&i.entry&&(o.entry=i.entry,o.global=i.global,o.type=i.type,t.push(o),o={})}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 pt from"node:fs";var W,Re,ke=h(()=>{"use strict";S();Pe();W=class{store;appSrc="src";appEntry="";base="/";assign(e,t){return t=t||{},x(e,t)}empShareLib=new j;async setup(e){this.store=e,await this.syncEmpOptions();let{appSrc:t,base:s,appEntry:i}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),i&&(this.appEntry=i),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:!0,showRsconfig:!1,infrastructureLogging:{appendOnly:!0,level:"warn"}},this.store.empOptions.debug)}get build(){let e=this.store.empOptions.build?.staticDir?`${this.store.empOptions.build?.staticDir}/`:"";return this.assign({outDir:"dist",staticDir:e,assetsDir:"assets",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev,minOptions:{}},{...this.store.empOptions.build,staticDir:e})}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:process.platform==="darwin",hot:!0,watchFiles:["src/**/*.html"],static:[{directory:this.store.publicDir,watch:this.store.isDev},{directory:this.store.outDir,watch:this.store.isDev,publicPath:this.base,staticOptions:{setHeaders:function(e,t){t.toString().endsWith(".d.ts")&&e?.set("Content-Type","application/javascript; charset=utf-8")}}}],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:{},mfVersion:1},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}get output(){let e=(this.store.isDev,".[contenthash:8]"),t=this.store.isDev?"":".[contenthash:8]",{assetsDir:s,staticDir:i}=this.store.empConfig.build;return this.assign({publicPath:this.base,crossOriginLoading:"anonymous",filename:`${i}js/[name]${e}.js`,cssFilename:`${i}css/[name]${t}.css`,cssChunkFilename:`${i}css/[name]${t}.css`,assetModuleFilename:`${i}${s}/[name]${e}[ext][query]`,path:this.store.outDir,clean:!0},this.store.empOptions.output)}get define(){let e={mode:this.store.mode,env:this.store.cliOptions.env};return this.store.empOptions.define&&(e={...e,...this.store.empOptions.define}),this.setDefine(e)}setDefine(e){let t=this.store.empOptions.defineFix?this.store.empOptions.defineFix:"cjs",s={};return Object.keys(e).map(i=>{(t==="all"||t==="esm")&&(s[`import.meta.env.${i}`]=JSON.stringify(e[i])),(t==="all"||t==="cjs")&&(s[`process.env.${i}`]=JSON.stringify(e[i])),s[`${i}`]=JSON.stringify(e[i])}),s}get externals(){return this.assign(this.empShareLib.externals,this.store.empOptions.externals)}get resolve(){return x({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(!pt.existsSync(e))return;let{default:t}=await import(this.store.importFileUrl(e));typeof t=="function"?this.store.empOptions=await t(this.store):this.store.empOptions=t||{}}get moduleTransformRule(){let{moduleTransform:e}=this.store.empOptions,t=this.assign({defaultExclude:!1},e),s={and:[],not:[]};return t.defaultExclude===!0&&s.and.push(/(node_modules|bower_components)/),t?.exclude&&(s.and=s.and.concat(t.exclude)),e?.include&&(s.not=t.include),s}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}get lifeCycle(){return this.assign({},this.store.empOptions.lifeCycle)}get reactRuntime(){if(this.store.reactVersion)return this.store.empOptions.reactRuntime?this.store.empOptions.reactRuntime:k(this.store.reactVersion,"17")>-1?"automatic":"classic"}},Re=new W});import O from"node:path";import lt from"webpack-chain";import{pathToFileURL as ct}from"node:url";var X,a,y=h(()=>{"use strict";me();$e();b();ke();X=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=ce;empSource=O.resolve(this.empRoot,"dist");resolve=e=>O.isAbsolute(e)?e:O.resolve(this.root,e);empResolve=e=>O.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=Re,await this.empConfig.setup(this),this.initPaths(),this.chain=new lt,await Oe.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 B(this.empResolve("package.json")),i=await B(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...i},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=O.join(this.empRoot,"resource"),this.resource.cert=O.join(this.resource.dir,"emp.cert"),this.resource.key=O.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\u26A1${this.empPkg.version}${this.cliMode==="dev"?".DEV":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e,t){return le(e,t)}importFileUrl(e){return ct(e).toString()}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){this.empConfig.debug.showRsconfig&&console.log("[ChainConfig]",JSON.stringify(this.rsConfig,null,2))}},a=new X});import je from"url";import De from"chalk";import{ip as mt}from"address";import{gateway4sync as ht}from"default-gateway";function Le(r,e,t,s="/"){let i=v=>je.format({protocol:r,hostname:v,port:t,pathname:s}),o=v=>je.format({protocol:r,hostname:v,port:De.bold(t),pathname:s}),n=e==="0.0.0.0"||e==="::",l,c,g=De.gray("unavailable");if(n){l="localhost";try{let{int:v}=ht();c=mt(v||""),c&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(c)?g=o(c):c=void 0)}catch{}}else l=e,c=e,g=o(c);let m=o(l),d=i(l);return{lanUrlForConfig:c,lanUrlForTerminal:g,localUrlForTerminal:m,localUrlForBrowser:d}}var Te=h(()=>{"use strict"});import{exec as ut}from"node:child_process";import{promisify as ft}from"node:util";var Fe,Ae,gt,dt,ze,Ge=h(()=>{"use strict";b();y();Fe=ft(ut),Ae=["Google Chrome Canary","Google Chrome Dev","Google Chrome Beta","Google Chrome","Microsoft Edge","Brave Browser","Vivaldi","Chromium"],gt=async()=>{let r=process.env.BROWSER;if(!r||!Ae.includes(r)){let{stdout:e}=await Fe("ps cax");r=Ae.find(t=>e.includes(t))}return r},dt=async r=>{if(process.platform==="darwin")try{let t=await gt();if(t){let s=`osascript openChrome.applescript "${encodeURI(r)}" "${t}"`;return await Fe(s,{cwd:a.resource.dir}),!0}}catch(t){p.debug(t)}try{let{default:t}=await import("open");return await t(r),!0}catch(t){return p.error("Failed to open start URL."),p.error(t),!1}},ze=dt});import Me from"node:fs/promises";import q from"chalk";var C,D=h(()=>{"use strict";b();y();S();Te();Ge();C=class{publicPath;localUrl;isOpenBrower=!1;startOpen({host:e,port:t}){let s=this.publicPath;if(s&&(s.indexOf("http://")>-1||s.indexOf("https://")>-1))p.info(`${q.greenBright("\u279C")} Network: ${p.link(s)}`),this.localUrl=s;else{let i=this.isHttps?"https":"http",n=Le(i,e||"0.0.0.0",t,s);p.info(`${q.greenBright("\u279C")} Local: ${p.link(n.localUrlForTerminal)}`),p.info(`${q.greenBright("\u279C")} Network: ${p.link(n.lanUrlForTerminal)}
|
|
10
|
-
`)
|
|
11
|
-
${
|
|
12
|
-
${
|
|
13
|
-
`)}function R(r=0){
|
|
1
|
+
var ot=Object.defineProperty;var l=(r,e)=>()=>(r&&(e=r(r=0)),e);var z=(r,e)=>{for(var t in e)ot(r,t,{get:e[t],enumerable:!0})};import{fileURLToPath as nt}from"node:url";import{dirname as pt}from"node:path";import{readFile as at}from"node:fs/promises";import me from"node:module";import G from"node:path";var he,lt,U,ct,fe,ue,ge=l(()=>{"use strict";he=nt(import.meta.url),lt=pt(he),U=async r=>{try{let e=await at(r);return JSON.parse(e)}catch(e){console.error(e)}},ct=me.createRequire(import.meta.url),fe=(r,e)=>{let t=ct;return e&&(t=me.createRequire(e)),t.resolve(r)},ue=G.resolve(lt,he).replace(`${G.sep}dist${G.sep}index.js`,"")});import E from"@rspack/core";import de from"fs";var M,ye,be=l(()=>{"use strict";M=class{store;async setup(e){this.store=e;let t=[this.define(),this.anylayze(),this.progress(),this.copy(),this.empShare(),this.minJs(),this.minCss()];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");de.existsSync(e)&&de.readdirSync(e).length>0&&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{ModuleFederationPluginV1:e,ModuleFederationPlugin:t}=E.container,s=this.store.empConfig.empShare.mfVersion===1?e:t;this.store.chain.plugin("empShare").use(s,[{...this.store.empConfig.empShare}])}minJs(){this.store.mode==="production"&&this.store.chain.plugin("minJs").use(E.SwcJsMinimizerRspackPlugin,[this.store.empConfig.build.minOptions])}minCss(){this.store.mode==="production"&&this.store.chain.plugin("minJs").use(E.SwcJsMinimizerRspackPlugin,[{}])}},ye=new M});var H,ve,Ce=l(()=>{"use strict";H=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:this.store.empConfig.reactRuntime,development:e,refresh:e}}:{};this.store.chain.merge({module:{parser:{javascript:{exportsPresence:"error",importExportsPresence:"error"}},rule:{mjs:{test:/\.m?js/,resolve:{fullySpecified:!1}},typescript:{test:/\.(ts|tsx)$/,sideEffects:!1,use:[{loader:"builtin:swc-loader",options:{jsc:{parser:{syntax:"typescript",decorators:!0,tsx:!0,dynamicImport:!0},transform:t}}}]},javascript:{test:/\.(js|jsx)$/,exclude:this.store.empConfig.moduleTransformRule,sideEffects:!1,use:[{loader:"builtin:swc-loader",options:{jsc:{parser:{syntax:"ecmascript",jsx:!0,decorators:!0,decoratorsBeforeExport:!1},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"}}}})}},ve=new H});var N,xe,we=l(()=>{"use strict";N=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:{}},infrastructureLogging:this.store.empConfig.debug.infrastructureLogging,context:this.store.root,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}})}},xe=new N});import mt from"chalk";function Se(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}function d(r,...e){for(let t of e)for(let s in t){let i=t[s],o=r[s];if(Object(i)==i&&Object(o)===o){r[s]=d(o,i);continue}r[s]=t[s]}return r}var k,Ee,b=l(()=>{"use strict";k=(r="",e="")=>{let t=r.replace("^","").split("."),s=e.replace("^","").split("."),i=Math.max(t.length,s.length),o=0;for(let p=0;p<i;p++){let c=t.length>p?t[p]:0,h=isNaN(Number(c))?c.charCodeAt():Number(c),O=s.length>p?s[p]:0,m=isNaN(Number(O))?O.charCodeAt():Number(O);if(h<m){o=-1;break}else if(h>m){o=1;break}}return o},Ee=r=>{r=r/1e3;let e=s=>mt.bold(s);if(r<1)return`${r*1e3} ms`;if(r<10){let s=r>=.01?2:3;return`${e(r.toFixed(s))} s`}if(r<60)return`${e(r.toFixed(1))} s`;let t=r/60;return`${e(t.toFixed(2))} m`}});import ht from"html-webpack-plugin";import ft from"fast-glob";import x from"node:path";var I,Oe,$e=l(()=>{"use strict";b();I=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=d(e.files,this.store.empConfig.empShareLib.externalAssets)),e}setChunk(e){return e.replace(x.extname(e),"").replace(`${this.store.empConfig.appSrc}${x.sep}`,"")}setTemplate(e){return e?this.store.resolve(e):this.store.empResolve(x.join("template","index.html"))}setFavicion(e){return e?this.store.resolve(e):this.store.empResolve(x.join("template","favicon.ico"))}setEntryItem(e,t,s){s=s||this.store.resolve(x.join(this.store.empConfig.appSrc,e));let i=this.setChunk(e);this.entriesConfig[i]={entry:{[i]:s},html:this.setHtmlConfig(t,[i])}}setRspackHtmlPlugin(e,t){this.store.chain.plugin(`html-plugin-${t}`).use(ht,[e])}setRspackEntry(e){this.store.merge({entry:e})}async init(){let e=x.join(this.store.appSrc,this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}").replace(/\\/g,"/"),t=await ft([e]);if(t[0]){let s=x.join(this.store.empConfig.appSrc,Object.keys(this.store.empConfig.entries).length>0&&this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index");this.setEntryItem(s,this.store.empConfig.html,t[0])}if(Object.keys(this.store.empConfig.entries).length>0)for(let[s,i]of Object.entries(this.store.empConfig.entries))this.setEntryItem(s,{...this.store.empConfig.html,...i})}toConfig(){for(let[e,t]of Object.entries(this.entriesConfig))this.setRspackHtmlPlugin(t.html,e),this.setRspackEntry(t.entry)}},Oe=new I});var _,Pe,Re=l(()=>{"use strict";_=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:{lessOptions:{javascriptEnabled:!0}}};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}}}}},Pe=new _});var J,ke,De=l(()=>{"use strict";be();Ce();we();$e();Re();J=class{store;async setup(e){this.store=e;let t=[xe.setup(this.store),ve.setup(this.store),ye.setup(this.store),Oe.setup(this.store),Pe.setup(this.store)];await Promise.all(t),await this.store.empConfig.plugins(),await this.store.empConfig.chain()}},ke=new J});import f from"chalk";import{table as ut}from"table";var V,a,y=l(()=>{"use strict";V=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(`${f.white.bgBlue(this.pname)}${f.blue.bgWhite(` ${e} `)}
|
|
2
|
+
`)};cyan=e=>{console.log(`${f.white.bgCyan(this.pname)}${f.cyan.bgWhite(` ${e} `)}
|
|
3
|
+
`)};magenta=e=>{console.log(`${f.white.bgMagenta(this.pname)}${f.magenta.bgWhite(` ${e} `)}
|
|
4
|
+
`)};green=e=>{console.log(`${f.white.bgGreen(this.pname)}${f.green.bgWhite(` ${e} `)}
|
|
5
|
+
`)};yellow=e=>{console.log(`${f.white.bgYellow(this.pname)}${f.yellow.bgWhite(` ${e} `)}
|
|
6
|
+
`)};red=e=>{console.log(`${f.white.bgRed(this.pname)}${f.red.bgWhite(` ${e} `)}
|
|
7
|
+
`)};sysError=e=>{console.log(`${f.white.bgRed(" System Error Tips ")}${f.red.bgWhite(` ${e} `)}
|
|
8
|
+
`)};link=e=>f.hex("#3498db")(e);title=e=>{console.log(`${f.greenBright.bold(`${this.pname}`)} ${f.bgGreenBright(` ${e} `)}
|
|
9
|
+
`)};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(ut(this.tableData,this.tableConfig))}},a=new V});var D,je=l(()=>{"use strict";D=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,i]of Object.entries(e.shareLib)){let o={};if(o.module=s,typeof i=="string"){let p=i.match(this.exp)||[];p.length>0?(o.global=p[1],o.entry=p[2],o.type="js",t.push(o),o={}):(o.global="",o.entry=i,o.type="js",t.push(o),o={})}else Array.isArray(i)?i.map(p=>{if(!p)return;if(p.split("?")[0].endsWith(".css"))o.entry=p,o.type="css";else{let h=p.match(this.exp)||[];h.length>0?(o.global=h[1],o.entry=h[2],o.type="js"):(o.global="",o.entry=p,o.type="js")}t.push(o),o={}}):typeof i=="object"&&i.entry&&(o.entry=i.entry,o.global=i.global,o.type=i.type,t.push(o),o={})}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 Le from"url";import Te from"chalk";import{ip as gt}from"address";import{gateway4sync as dt}from"default-gateway";var W,P,X=l(()=>{"use strict";W=class{imf={protocol:"",port:8e3,pathname:"/"};host="0.0.0.0";urls={lanUrlForConfig:"",lanUrlForTerminal:Te.gray("unavailable"),localUrlForTerminal:"",localUrlForBrowser:""};setup(e){e.host&&(this.host=e.host),e.protocol&&(this.imf.protocol=e.protocol),e.pathname&&(this.imf.pathname=e.pathname),e.port&&(this.imf.port=e.port),this.setupUrls()}setupUrls(){let{host:e}=this,t=e==="0.0.0.0"||e==="::",s;if(t){s="localhost";try{this.urls.lanUrlForConfig=this.getLanIp(),this.urls.lanUrlForConfig&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(this.urls.lanUrlForConfig)?this.urls.lanUrlForTerminal=this.prettyPrintUrl(this.urls.lanUrlForConfig):this.urls.lanUrlForConfig="")}catch{}}else s=e,this.urls.lanUrlForConfig=e,this.urls.lanUrlForTerminal=this.prettyPrintUrl(this.urls.lanUrlForConfig);this.urls.localUrlForTerminal=this.prettyPrintUrl(s),this.urls.localUrlForBrowser=this.formatUrl(s)}getLanIp(){let{int:e}=dt();return gt(e||"")||"127.0.0.1"}formatUrl(e){let{protocol:t,port:s,pathname:i}=this.imf;return Le.format({protocol:t,hostname:e,port:s,pathname:i})}prettyPrintUrl(e){let{protocol:t,port:s,pathname:i}=this.imf;return Le.format({protocol:t,hostname:e,port:Te.bold(s),pathname:i})}},P=new W});var q,j,Q=l(()=>{"use strict";X();b();g();q=class{isADB=!1;isHttps=!1;get isHttpBase(){let e=n.empOptions.base||"";return console.log("store.empOptions.base",n.empOptions.base,e.indexOf("http://")>-1||e.indexOf("https://")>-1),e.indexOf("http://")>-1||e.indexOf("https://")>-1}setup(){if(this.isADB=!!n.empOptions.autoDevBase&&n.mode==="development"&&!this.isHttpBase,!this.isADB)return;let{server:e,https:t}=n.empOptions.server||{};this.isHttps=e==="https"||typeof e=="object"&&e.type==="https"||t===!0;let s=P.getLanIp(),i=this.isHttps?"https":"http",o=n.empOptions.server?.port||8e3;n.empOptions.base=`${i}://${s}:${o}/`,n.empOptions.server=d({host:s,port:o,client:{webSocketURL:`ws://${s}:${o}/ws`}},n.empOptions.server)}},j=new q});var Y,Fe,Ae=l(()=>{"use strict";Q();Y=class{async afterGetEmpOptions(){j.setup()}},Fe=new Y});import yt from"node:fs";var Z,Be,ze=l(()=>{"use strict";b();je();Ae();Z=class{store;appSrc="src";appEntry="";base="";assign(e,t){return t=t||{},d(e,t)}empShareLib=new D;async autoDevSet(){this.store.mode==="development"&&this.store.empOptions.autoDevBase}async setup(e){this.store=e,await this.syncEmpOptions(),await Fe.afterGetEmpOptions();let{appSrc:t,base:s,appEntry:i}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),i&&(this.appEntry=i),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:!0,showRsconfig:!1,infrastructureLogging:{appendOnly:!0,level:"warn"}},this.store.empOptions.debug)}get build(){let e=this.store.empOptions.build?.staticDir?`${this.store.empOptions.build?.staticDir}/`:"";return this.assign({outDir:"dist",staticDir:e,assetsDir:"assets",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev,minOptions:{}},{...this.store.empOptions.build,staticDir:e})}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(){let e={host:"0.0.0.0",port:8e3,open:process.platform==="darwin",hot:!0,watchFiles:["src/**/*.html"],static:[{directory:this.store.publicDir,watch:this.store.isDev}],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"}};return this.assign(e,this.store.empOptions.server)}get empShare(){return this.assign({name:"",filename:"emp.js",shared:{},mfVersion:1},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}get output(){let e=(this.store.isDev,".[contenthash:8]"),t=this.store.isDev?"":".[contenthash:8]",{assetsDir:s,staticDir:i}=this.store.empConfig.build;return this.assign({publicPath:this.store.empConfig.base?this.store.empConfig.base:"auto",crossOriginLoading:"anonymous",filename:`${i}js/[name]${e}.js`,cssFilename:`${i}css/[name]${t}.css`,cssChunkFilename:`${i}css/[name]${t}.css`,assetModuleFilename:`${i}${s}/[name]${e}[ext][query]`,path:this.store.outDir,clean:!0},this.store.empOptions.output)}get define(){let e={mode:this.store.mode,env:this.store.cliOptions.env};return this.store.empOptions.define&&(e={...e,...this.store.empOptions.define}),this.setDefine(e)}setDefine(e){let t=this.store.empOptions.defineFix?this.store.empOptions.defineFix:"cjs",s={};return Object.keys(e).map(i=>{(t==="all"||t==="esm")&&(s[`import.meta.env.${i}`]=JSON.stringify(e[i])),(t==="all"||t==="cjs")&&(s[`process.env.${i}`]=JSON.stringify(e[i])),s[`${i}`]=JSON.stringify(e[i])}),s}get externals(){return this.assign(this.empShareLib.externals,this.store.empOptions.externals)}get resolve(){return d({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(!yt.existsSync(e))return;let{default:t}=await import(this.store.importFileUrl(e));typeof t=="function"?this.store.empOptions=await t(this.store):this.store.empOptions=t||{}}get moduleTransformRule(){let{moduleTransform:e}=this.store.empOptions,t=this.assign({defaultExclude:!1},e),s={and:[],not:[]};return t.defaultExclude===!0&&s.and.push(/(node_modules|bower_components)/),t?.exclude&&(s.and=s.and.concat(t.exclude)),e?.include&&(s.not=t.include),s}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}get lifeCycle(){return this.assign({},this.store.empOptions.lifeCycle)}get reactRuntime(){if(this.store.reactVersion)return this.store.empOptions.reactRuntime?this.store.empOptions.reactRuntime:k(this.store.reactVersion,"17")>-1?"automatic":"classic"}},Be=new Z});import w from"node:path";import bt from"webpack-chain";import{pathToFileURL as vt}from"node:url";var K,n,g=l(()=>{"use strict";ge();De();y();ze();K=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=ue;empSource=w.resolve(this.empRoot,"dist");resolve=e=>w.isAbsolute(e)?e:w.resolve(this.root,e);empResolve=e=>w.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=Be,await this.empConfig.setup(this),this.initPaths(),this.chain=new bt,await ke.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 U(this.empResolve("package.json")),i=await U(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...i},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=w.join(this.empRoot,"resource"),this.resource.cert=w.join(this.resource.dir,"emp.cert"),this.resource.key=w.join(this.resource.dir,"emp.key")}setLogger(){let e=this.cliMode==="dev"?"debug":"info";this.empConfig.debug.loggerLevel&&(e=this.empConfig.debug.loggerLevel),a.setup({pname:`EMP\u26A1${this.empPkg.version}${this.cliMode==="dev"?".DEV":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e,t){return fe(e,t)}importFileUrl(e){return vt(e).toString()}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){this.empConfig.debug.showRsconfig&&console.log("[ChainConfig]",JSON.stringify(this.rsConfig,null,2))}},n=new K});import{exec as Ct}from"node:child_process";import{promisify as xt}from"node:util";var Ue,Ge,wt,St,Me,He=l(()=>{"use strict";y();g();Ue=xt(Ct),Ge=["Google Chrome Canary","Google Chrome Dev","Google Chrome Beta","Google Chrome","Microsoft Edge","Brave Browser","Vivaldi","Chromium"],wt=async()=>{let r=process.env.BROWSER;if(!r||!Ge.includes(r)){let{stdout:e}=await Ue("ps cax");r=Ge.find(t=>e.includes(t))}return r},St=async r=>{if(process.platform==="darwin")try{let t=await wt();if(t){let s=`osascript openChrome.applescript "${encodeURI(r)}" "${t}"`;return await Ue(s,{cwd:n.resource.dir}),!0}}catch(t){a.debug(t)}try{let{default:t}=await import("open");return await t(r),!0}catch(t){return a.error("Failed to open start URL."),a.error(t),!1}},Me=St});import Et from"net";import Ot from"os";async function Ie(r,e="localhost"){if(r!==$t&&(r<Ne||r>ee))throw new Error(`Port number must lie between ${Ne} and ${ee}`);let t=r,s=Pt(),i;e&&!s.has(e)?i=new Set([e]):i=s;let o=new Set(["EADDRINUSE","EACCES"]);for(;t<=ee;)try{return await kt(t,i)}catch(p){if(!o.has(p.code))throw p;t+=1}throw new Error("No available ports found")}var Ne,ee,$t,Pt,Rt,kt,_e=l(()=>{"use strict";Ne=1024,ee=65535,$t=443,Pt=()=>{let r=Ot.networkInterfaces(),e=new Set([void 0,"0.0.0.0"]);for(let t of Object.values(r))if(t)for(let s of t)e.add(s.address);return e},Rt=(r,e)=>new Promise((t,s)=>{let i=Et.createServer();i.unref(),i.on("error",s),i.listen(r,e,()=>{let{port:o}=i.address();i.close(()=>{t(o)})})}),kt=async(r,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await Rt(r,s)}catch(i){if(!t.has(i.code))throw i}return r}});import Je from"node:fs/promises";import te from"chalk";var v,L=l(()=>{"use strict";y();g();b();X();He();_e();Q();v=class{sf={protocol:"http",host:"0.0.0.0",port:8e3,publicPath:"",publicHasHttp:!1,isOpenBrower:!1,url:"",urls:{localUrlForBrowser:"",localUrlForTerminal:"",lanUrlForTerminal:"",lanUrlForConfig:""}};async adaptServer(){this.sf.publicPath=n.rsConfig.output?.publicPath==="auto"?"/":n.rsConfig.output?.publicPath||"/",this.sf.isOpenBrower=!!n.empConfig.server.open,this.sf.protocol=this.isHttps?"https":"http",this.sf.host=n.empConfig.server.host?n.empConfig.server.host:this.sf.host,this.sf.port=n.empConfig.server.port,await this.serverPort(),this.sf.publicPath&&(this.sf.publicPath.indexOf("http://")>-1||this.sf.publicPath.indexOf("https://")>-1)?(this.sf.url=this.sf.publicPath,this.sf.publicHasHttp=!0):(P.setup(this.sf),this.sf.urls=P.urls,this.sf.url=this.sf.urls.localUrlForBrowser)}startOpen(){if(this.sf.publicHasHttp)a.info(`${te.greenBright("\u279C")} Network: ${a.link(this.sf.publicPath)}`);else{let{urls:e}=this.sf;a.info(`${te.greenBright("\u279C")} Local: ${a.link(e.localUrlForTerminal)}`),a.info(`${te.greenBright("\u279C")} Network: ${a.link(e.lanUrlForTerminal)}
|
|
10
|
+
`)}this.sf.isOpenBrower&&Me(this.sf.url)}async setup(e,t){await n.setup(e,t),n.empConfig.debug.clearLog&&Se(),a.title(`${e}`),await this.adaptServer(),await this.run()}async run(){}get isHttps(){let{server:e,https:t}=n.empConfig.server||{};return e==="https"||typeof e=="object"&&e.type==="https"||t===!0}getcert(){return Promise.all([Je.readFile(n.resource.key),Je.readFile(n.resource.cert)])}async serverPort(){if(j.isADB)return;let{port:e,host:t}=this.sf,s=await Ie(e,t);s!==e&&(this.sf.port=s,n.rsConfig.devServer?.port&&(n.rsConfig.devServer.port=s))}}});import u from"chalk";import C from"node:path";import{gzipSizeSync as Dt}from"gzip-size";import jt from"node:fs";function Gt(r,e){let t=[r,e],s=["File","Size","Gzipped"].reduce((i,o,p)=>{let c=t[p],h=o;return c&&(h=o.length<c?o+" ".repeat(c-o.length):o),`${i+h} `}," ");console.log(u.bold.blue(s))}async function Ve(r){let e=r.toJson({all:!1,assets:!0,timings:!0});R(e.time);let s=e.assets.filter(m=>At(m.name)).map(zt);s.sort((m,$)=>m.size-$.size);let i=Math.max(...s.map(m=>m.sizeLabel.length)),o=Math.max(...s.map(m=>(m.folder+C.sep+m.name).length));Gt(o,i);let p=0,c=0;s.forEach(m=>{let{sizeLabel:$}=m,{name:st,folder:rt,gzipSizeLabel:it}=m,ae=(rt+C.sep+st).length,le=$.length;if(p+=m.size,c+=m.gzippedSize,le<i){let B=" ".repeat(i-le);$+=B}let ce=u.gray(m.folder+C.sep)+Ut(m.name);if(ae<o){let B=" ".repeat(o-ae);ce+=B}a.info(` ${ce} ${u.gray($)} ${it}`)});let h=`${u.bold.blue("Total size:")} ${T(p)}`,O=`${u.bold.blue("Gzipped size:")} ${T(c)}`;a.info(`
|
|
11
|
+
${h}
|
|
12
|
+
${O}
|
|
13
|
+
`)}function R(r=0){a.info(`${u.greenBright("\u2713")} Ready in ${Ee(Number(r))}`)}var Lt,Tt,Ft,At,Bt,zt,T,Ut,F=l(()=>{"use strict";g();y();b();Lt=/\.html$/,Tt=/\.(?:js|mjs|cjs|jsx)$/,Ft=/\.css$/,At=r=>!/\.map$/.test(r)&&!/\.LICENSE\.txt$/.test(r),Bt=r=>r>300*1e3?u.red:r>100*1e3?u.yellow:u.white,zt=r=>{let e=r.name.split("?")[0],t=T(r.size),s=C.basename(e),i=C.join(C.basename(n.empConfig.build.outDir),C.dirname(e)),o=jt.readFileSync(C.join(n.empConfig.build.outDir,e)),p=o.length,c=Dt(o),h=Bt(c)(T(c));return{size:p,folder:i,name:s,gzippedSize:c,sizeLabel:t,gzipSizeLabel:h}};T=r=>{let e=r/1e3;return`${e.toFixed(e<1?2:1)} kB`},Ut=r=>Tt.test(r)?u.yellowBright(r):Ft.test(r)?u.greenBright(r):Lt.test(r)?u.blueBright(r):u.magenta(r)});var We={};z(We,{default:()=>Nt});import{rspack as Mt}from"@rspack/core";import{RspackDevServer as Ht}from"@rspack/dev-server";var se,Nt,Xe=l(()=>{"use strict";g();L();y();b();F();se=class extends v{async run(){let e=d(n.rsConfig,{stats:{all:!1,colors:!0,assets:!1,chunks:!1,entrypoints:!1,timings:!1,version:!1,errors:!0,warnings:!0},devServer:{open:!1,setupExitSignals:!0}}),t=Mt(e);if(!n.rsConfig.devServer){a.error("devServer is not defined in config");return}let s=Object.assign({},n.rsConfig.devServer);if(this.isHttps&&(s.https===!0&&delete s.https,!s.server)){let[c,h]=await this.getcert();s.server={type:"https",options:{key:c,cert:h}}}let{afterDevServe:i,beforeDevServe:o}=n.empConfig.lifeCycle,p=new Ht(s,t);this.startOpen(),o&&o(),await p.start(),p.middleware?.waitUntilValid(c=>{let h=c?.toJson({all:!1,colors:!1,assets:!1,chunks:!1,timings:!0});R(h.time),i&&i()})}},Nt=new se});var qe={};z(qe,{default:()=>_t});import{rspack as It}from"@rspack/core";var re,_t,Qe=l(()=>{"use strict";y();g();L();F();re=class extends v{async run(){let{afterBulid:e,beforeBuild:t}=n.empConfig.lifeCycle;t&&t(),It(n.rsConfig,async(s,i)=>{if(s!==null){a.error(s.stack||s),s.message&&a.error(s.message);return}if(!i){a.red("Stats is Undefined.");return}i.hasErrors()&&(a.error(i.toString({colors:!0,children:!0})),a.red("Failed to compile."),process.exit(1)),i.hasWarnings()&&(a.yellow("Compiled with warnings."),a.warn(i.toString({colors:!0,children:!0}))),await Ve(i),e&&e()})}},_t=new re});import Jt from"express";import Vt from"cors";import Wt from"compression";import Xt from"https";var A,Ye=l(()=>{"use strict";L();A=class extends v{app;async init(){let e=Jt();e.use(Wt()),e.use(Vt()),this.app=e}async server(){if(this.isHttps){let[e,t]=await this.getcert();Xt.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:e,cert:t},this.app).listen(this.sf.port,async()=>{this.startOpen(),await this.onReady()})}else this.app.listen(this.sf.port,async()=>{this.startOpen(),await this.onReady()})}async onReady(){}async middleware(){}async start(){await this.init(),await this.middleware(),await this.server()}}});var Ze={};z(Ze,{default:()=>Kt});import qt from"express";import Qt from"path";import Yt from"node:fs/promises";import Zt from"node:fs";var ie,Kt,Ke=l(()=>{"use strict";Ye();g();y();F();ie=class extends A{timing=0;async run(){if(this.timing=Date.now(),!Zt.existsSync(n.outDir))return a.sysError(`emp serve must be executed after emp build,${n.outDir} not exist!`);let{beforeServe:e}=n.empConfig.lifeCycle;e&&e(),this.start()}async middleware(){let e=n.resolve(n.rsConfig.output?.path);this.app.use(qt.static(e));let t=await Yt.readFile(Qt.join(e,"index.html"),"utf8");this.app.get("*",(s,i)=>i.send(t))}async onReady(){R(Date.now()-this.timing);let{afterServe:e}=n.empConfig.lifeCycle;e&&e()}},Kt=new ie});g();g();b();y();import{program as S}from"commander";import oe,{exit as es}from"node:process";function et(){let r="20.0.0";k(r,oe.versions.node)===1&&(a.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${oe.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${r}`),es(0)),S.version(n.empPkg.version,"-v, --version").usage("<command> [options]"),S.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").option("-ev, --env-vars <key=value>","\u5B9A\u4E49\u4E00\u4E2A\u73AF\u5883\u53D8\u91CF -ev key=value \u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u91CD\u590D\u8C03\u7528 -ev key=value -ev key=value",(e,t)=>{let[s,i]=e.split("=");return t[s]=i,t},{}).action(async e=>{let{default:t}=await Promise.resolve().then(()=>(Xe(),We));await t.setup("dev",e)}),S.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").option("-ev, --env-vars <key=value>","\u5B9A\u4E49\u4E00\u4E2A\u73AF\u5883\u53D8\u91CF -ev key=value \u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u91CD\u590D\u8C03\u7528 -ev key=value -ev key=value",(e,t)=>{let[s,i]=e.split("=");return t[s]=i,t},{}).action(async e=>{let{default:t}=await Promise.resolve().then(()=>(Qe(),qe));await t.setup("build",e)}),S.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(()=>(Ke(),Ze));await t.setup("serve",e)}),S.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=>{}),S.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=>{}),S.parse(oe.argv)}g();import ts from"fast-glob";import tt from"node:fs/promises";import ne from"node:path";var ss=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,rs=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,is=/import\(['"]([^;\n]+?)['"]\)/,pe=class{list=[];outDir=n.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 ts([`${n.empConfig.build.outDir}/**/*.d.ts`]);let e=[];this.list.map(s=>{s=n.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 tt.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(ss,i=>{let o=i.match(rs);if(o||(o=i.match(is)),o&&o[1]){let p=o[1];if(!p.startsWith("."))return i;let c=ne.resolve(ne.dirname(e),p).replace(this.outDir,this.aliasName);return i.replace(o[1],c)}return i});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
|
|
14
14
|
${t}}\r
|
|
15
|
-
`}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await
|
|
15
|
+
`}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await tt.writeFile(ne.join(this.outDir.replace("dist","types"),"type.d.ts"),t)}},os=new pe;function wi(r){return r}export{wi as defineConfig,os as dts,et as runScript,n as store};
|
package/dist/script/base.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
export declare class BaseScript {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
sf: {
|
|
4
|
+
protocol: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
publicPath: string;
|
|
8
|
+
publicHasHttp: boolean;
|
|
9
|
+
isOpenBrower: boolean;
|
|
10
|
+
url: string;
|
|
11
|
+
urls: {
|
|
12
|
+
localUrlForBrowser: string;
|
|
13
|
+
localUrlForTerminal: string;
|
|
14
|
+
lanUrlForTerminal: string;
|
|
15
|
+
lanUrlForConfig: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
adaptServer(): Promise<void>;
|
|
19
|
+
startOpen(): void;
|
|
7
20
|
setup(cliName: string, o: any): Promise<void>;
|
|
8
21
|
run(): Promise<void>;
|
|
9
22
|
get isHttps(): boolean;
|
|
10
23
|
getcert(): Promise<[Buffer, Buffer]>;
|
|
24
|
+
serverPort(): Promise<void>;
|
|
11
25
|
}
|
package/dist/types/config.d.ts
CHANGED
package/package.json
CHANGED