@empjs/cli 3.0.0-beta.2 → 3.0.0-beta.21

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.
@@ -0,0 +1,15 @@
1
+ import type { Stats } from '@rspack/core';
2
+ export declare const HTML_REGEX: RegExp;
3
+ export declare const JS_REGEX: RegExp;
4
+ export declare const TS_REGEX: RegExp;
5
+ export declare const SCRIPT_REGEX: RegExp;
6
+ export declare const TS_AND_JSX_REGEX: RegExp;
7
+ export declare const SVG_REGEX: RegExp;
8
+ export declare const CSS_REGEX: RegExp;
9
+ export declare const LESS_REGEX: RegExp;
10
+ export declare const SASS_REGEX: RegExp;
11
+ export declare const CSS_MODULES_REGEX: RegExp;
12
+ export declare const NODE_MODULES_REGEX: RegExp;
13
+ export declare const filterAsset: (asset: string) => boolean;
14
+ export declare function printFileSizes(stats: Stats): Promise<void>;
15
+ export declare function timeDone(mis?: number | string): void;
@@ -0,0 +1,2 @@
1
+ declare let ep: any;
2
+ export default ep;
@@ -0,0 +1,14 @@
1
+ declare const _default: {
2
+ path: string;
3
+ timeout: number;
4
+ overlay: boolean;
5
+ reload: boolean;
6
+ log: boolean;
7
+ warn: boolean;
8
+ name: string;
9
+ autoConnect: boolean;
10
+ overlayStyles: {};
11
+ overlayWarnings: boolean;
12
+ ansiColors: {};
13
+ };
14
+ export default _default;
@@ -0,0 +1,6 @@
1
+ export declare const pathMatch: (url: string, path: string) => boolean;
2
+ export default function webpackHotMiddleware(compiler: any, opts?: any): {
3
+ (req: any, res: any, next: any): any;
4
+ publish(payload: any): void;
5
+ close(): void;
6
+ };
@@ -0,0 +1,6 @@
1
+ export declare function showProblems(type: any, lines: any): void;
2
+ export declare function clear(): void;
3
+ export default function (options: any): {
4
+ showProblems: typeof showProblems;
5
+ clear: typeof clear;
6
+ };
@@ -0,0 +1 @@
1
+ export default function (hash: any, moduleMap: any, options: any): void;
@@ -15,6 +15,7 @@ declare class Logger {
15
15
  red: (msg: string) => void;
16
16
  sysError: (msg: string) => void;
17
17
  link: (msg: string) => string;
18
+ title: (msg: string) => void;
18
19
  tableData: any;
19
20
  tableConfig: {
20
21
  border: {
@@ -0,0 +1,2 @@
1
+ export declare const openBrowser: (url: string) => Promise<boolean>;
2
+ export default openBrowser;
@@ -9,3 +9,4 @@ export declare const ensureArray: <T>(params: T | T[]) => T[];
9
9
  */
10
10
  export declare const jsonFilter: (d?: any, notIncludeKeys?: string[]) => any;
11
11
  export declare const vCompare: (preVersion?: string, lastVersion?: string) => number;
12
+ export declare const timeFormat: (seconds: number) => string;
package/dist/index.js CHANGED
@@ -1,10 +1,15 @@
1
- var Le=Object.defineProperty;var c=(i,e)=>()=>(i&&(e=i(i=0)),e);var $=(i,e)=>{for(var t in e)Le(i,t,{get:e[t],enumerable:!0})};import{fileURLToPath as Ae}from"node:url";import{dirname as Fe}from"node:path";import{readFile as Me}from"node:fs/promises";import X from"node:module";import R from"node:path";var Y,Ne,T,Ge,Z,K,ee=c(()=>{"use strict";Y=Ae(import.meta.url),Ne=Fe(Y),T=async i=>{try{let e=await Me(i);return JSON.parse(e)}catch(e){console.error(e)}},Ge=X.createRequire(import.meta.url),Z=(i,e)=>{let t=Ge;return e&&(t=X.createRequire(e)),t.resolve(i)},K=R.resolve(Ne,Y).replace(`${R.sep}dist${R.sep}index.js`,"")});import w from"@rspack/core";import te from"fs";var D,se,re=c(()=>{"use strict";D=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(w.DefinePlugin,[this.store.empConfig.define])}async copy(){let e=this.store.resolve("public");te.existsSync(e)&&te.readdirSync(e).length>0&&this.store.chain.plugin("copyRspackPlugin").use(w.CopyRspackPlugin,[{patterns:[{from:e,to:this.store.resolve("dist")}]}])}async progress(){this.store.empConfig.debug.progress&&this.store.chain.plugin("progressPlugin").use(w.ProgressPlugin,[{prefix:"EMP"}])}async empShare(){if(!this.store.empConfig.empShare.name)return;let{ModuleFederationPlugin:e}=w.container;this.store.chain.plugin("empShare").use(e,[{...this.store.empConfig.empShare}])}minJs(){this.store.mode==="production"&&this.store.chain.plugin("minJs").use(w.SwcJsMinimizerRspackPlugin,[this.store.empConfig.build.minOptions])}minCss(){this.store.mode==="production"&&this.store.chain.plugin("minJs").use(w.SwcJsMinimizerRspackPlugin,[{}])}},se=new D});var L,oe,ie=c(()=>{"use strict";L=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)$/,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"}}}})}},oe=new L});var A,ne,pe=c(()=>{"use strict";A=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:!1,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}})}},ne=new A});function ae(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}function S(i,...e){for(let t of e)for(let s in t){let r=t[s],o=i[s];if(Object(r)==r&&Object(o)===o){i[s]=S(o,r);continue}i[s]=t[s]}return i}var O,E=c(()=>{"use strict";O=(i="",e="")=>{let t=i.replace("^","").split("."),s=e.replace("^","").split("."),r=Math.max(t.length,s.length),o=0;for(let n=0;n<r;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){o=-1;break}else if(l>f){o=1;break}}return o}});import Ie from"html-webpack-plugin";import He from"fast-glob";import y from"node:path";var F,le,ce=c(()=>{"use strict";E();F=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=S(e.files,this.store.empConfig.empShareLib.externalAssets)),e}setChunk(e){return e.replace(y.extname(e),"").replace(`${this.store.empConfig.appSrc}${y.sep}`,"")}setTemplate(e){return e?this.store.resolve(e):this.store.empResolve(y.join("template","index.html"))}setFavicion(e){return e?this.store.resolve(e):this.store.empResolve(y.join("template","favicon.ico"))}setEntryItem(e,t,s){s=s||this.store.resolve(y.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(Ie,[e])}setRspackEntry(e){this.store.merge({entry:e})}async init(){let e=y.join(this.store.appSrc,this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}").replace(/\\/g,"/"),t=await He([e]);if(t[0]){let s=y.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,r]of Object.entries(this.store.empConfig.entries))this.setEntryItem(s,{...this.store.empConfig.html,...r})}toConfig(){for(let[e,t]of Object.entries(this.entriesConfig))this.setRspackHtmlPlugin(t.html,e),this.setRspackEntry(t.entry)}},le=new F});var M,me,he=c(()=>{"use strict";M=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}}}}},me=new M});var N,ue,fe=c(()=>{"use strict";re();ie();pe();ce();he();N=class{store;async setup(e){this.store=e;let t=[ne.setup(this.store),oe.setup(this.store),se.setup(this.store),le.setup(this.store),me.setup(this.store)];await Promise.all(t),await this.store.empConfig.plugins(),await this.store.empConfig.chain()}},ue=new N});import h from"chalk";import{table as Je}from"table";var G,a,b=c(()=>{"use strict";G=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
- `)};cyan=e=>{console.log(`${h.white.bgCyan(this.pname)}${h.cyan.bgWhite(` ${e} `)}
3
- `)};magenta=e=>{console.log(`${h.white.bgMagenta(this.pname)}${h.magenta.bgWhite(` ${e} `)}
4
- `)};green=e=>{console.log(`${h.white.bgGreen(this.pname)}${h.green.bgWhite(` ${e} `)}
5
- `)};yellow=e=>{console.log(`${h.white.bgYellow(this.pname)}${h.yellow.bgWhite(` ${e} `)}
6
- `)};red=e=>{console.log(`${h.white.bgRed(this.pname)}${h.red.bgWhite(` ${e} `)}
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(Je(this.tableData,this.tableConfig))}},a=new G});var P,ge=c(()=>{"use strict";P=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,r]of Object.entries(e.shareLib)){let o={};if(o.module=s,typeof r=="string"){let n=r.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=r,o.type="js",t.push(o),o={})}else Array.isArray(r)?r.map(n=>{if(!n)return;if(n.split("?")[0].endsWith(".css"))o.entry=n,o.type="css";else{let l=n.match(this.exp)||[];l.length>0?(o.global=l[1],o.entry=l[2],o.type="js"):(o.global="",o.entry=n,o.type="js")}t.push(o),o={}}):typeof r=="object"&&r.entry&&(o.entry=r.entry,o.global=r.global,o.type=r.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 Ue from"node:fs";var I,de,ye=c(()=>{"use strict";E();ge();I=class{store;appSrc="src";appEntry="";base="";assign(e,t){return t=t||{},S(e,t)}empShareLib=new P;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),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},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:!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]"),{assetsDir:t,staticDir:s}=this.store.empConfig.build;return this.assign({publicPath:this.store.empConfig.base?this.store.empConfig.base:"auto",crossOriginLoading:"anonymous",filename:`${s}js/[name]${e}.js`,cssFilename:`${s}css/[name]${e}.css`,cssChunkFilename:`${s}css/[name]${e}.css`,assetModuleFilename:`${s}${t}/[name]${e}[ext][query]`,path:this.store.outDir,clean:!0},this.store.empOptions.output)}get define(){let e=this.store.empOptions.defineFix?this.store.empOptions.defineFix:"cjs",t={mode:this.store.mode,env:this.store.cliOptions.env};this.store.empOptions.define&&(t={...t,...this.store.empOptions.define});let s={};return Object.keys(t).map(r=>{(e==="all"||e==="esm")&&(s[`import.meta.env.${r}`]=JSON.stringify(t[r])),(e==="all"||e==="cjs")&&(s[`process.env.${r}`]=JSON.stringify(t[r])),s[`${r}`]=JSON.stringify(t[r])}),s}get externals(){return this.assign(this.empShareLib.externals,this.store.empOptions.externals)}get resolve(){return S({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(!Ue.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 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"}get reactRuntime(){if(this.store.reactVersion)return this.store.empOptions.reactRuntime?this.store.empOptions.reactRuntime:O(this.store.reactVersion,"17")>-1?"automatic":"classic"}},de=new I});import v from"node:path";import Ve from"webpack-chain";import{pathToFileURL as ze}from"node:url";var H,p,g=c(()=>{"use strict";ee();fe();b();ye();H=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=K;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=de,await this.empConfig.setup(this),this.initPaths(),this.chain=new Ve,await ue.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")),r=await T(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),a.setup({pname:` EMP v${this.empPkg.version} ${this.cliMode==="dev"?"DEV ":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e,t){return Z(e,t)}importFileUrl(e){return ze(e).toString()}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){this.empConfig.debug.showRsconfig&&console.log("[ChainConfig]",JSON.stringify(this.rsConfig,null,2))}},p=new H});import be from"node:fs/promises";var d,j=c(()=>{"use strict";b();g();E();d=class{async setup(e,t){await p.setup(e,t),p.empConfig.debug.clearLog&&ae(),a.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([be.readFile(p.resource.key),be.readFile(p.resource.cert)])}}});import Be from"net";import We from"os";async function k(i,e="localhost"){if(i!==_e&&(i<ve||i>J))throw new Error(`Port number must lie between ${ve} and ${J}`);let t=i,s=qe(),r;e&&!s.has(e)?r=new Set([e]):r=s;let o=new Set(["EADDRINUSE","EACCES"]);for(;t<=J;)try{return await Xe(t,r)}catch(n){if(!o.has(n.code))throw n;t+=1}throw new Error("No available ports found")}var ve,J,_e,qe,Qe,Xe,U=c(()=>{"use strict";ve=1024,J=65535,_e=443,qe=()=>{let i=We.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},Qe=(i,e)=>new Promise((t,s)=>{let r=Be.createServer();r.unref(),r.on("error",s),r.listen(i,e,()=>{let{port:o}=r.address();r.close(()=>{t(o)})})}),Xe=async(i,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await Qe(i,s)}catch(r){if(!t.has(r.code))throw r}return i}});var Ce={};$(Ce,{default:()=>Ke});import{rspack as Ye}from"@rspack/core";import{RspackDevServer as Ze}from"@rspack/dev-server";var V,Ke,xe=c(()=>{"use strict";g();j();b();U();V=class extends d{async run(){let e=Ye(p.rsConfig);if(!p.rsConfig.devServer){a.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 o=await k(Number(r),s);o!==r&&(p.rsConfig.devServer.port=o,t.port=o),new Ze(t,e).start()}},Ke=new V});var we={};$(we,{default:()=>tt});import{rspack as et}from"@rspack/core";var z,tt,Se=c(()=>{"use strict";b();g();j();z=class extends d{async run(){et(p.rsConfig,(e,t)=>{if(e!==null){a.error(e.stack||e),e.message&&a.error(e.message);return}if(!t){a.red("Stats is Undefined.");return}t.hasErrors()&&(a.error(t.toString({colors:!0,children:!0})),a.red("Failed to compile."),process.exit(1)),t.hasWarnings()&&(a.yellow("Compiled with warnings."),a.warn(t.toString({colors:!0,children:!0}))),a.info(t.toString({all:!1,colors:!0,assets:!0,chunks:!1,entrypoints:!0,timings:!0,version:!0})),a.green("Compiled successfully.")})}},tt=new z});import Ee from"url";import Oe from"chalk";import{ip as st}from"address";import{gateway4sync as rt}from"default-gateway";function Pe(i,e,t,s="/"){let r=x=>Ee.format({protocol:i,hostname:x,port:t,pathname:s}),o=x=>Ee.format({protocol:i,hostname:x,port:Oe.bold(t),pathname:s}),n=e==="0.0.0.0"||e==="::",m,l,u=Oe.gray("unavailable");if(n){m="localhost";try{let{int:x}=rt();l=st(x||""),l&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(l)?u=o(l):l=void 0)}catch{}}else m=e,l=e,u=o(l);let f=o(m),Q=r(m);return{lanUrlForConfig:l,lanUrlForTerminal:u,localUrlForTerminal:f,localUrlForBrowser:Q}}var je=c(()=>{"use strict"});var $e={};$($e,{default:()=>lt});import ke from"express";import ot from"cors";import it from"compression";import nt from"https";import pt from"path";import at from"node:fs/promises";var B,lt,Re=c(()=>{"use strict";U();je();g();b();j();B=class extends d{app;startLogger({host:e,port:t,publicPath:s}){if(s&&(s.indexOf("http://")>-1||s.indexOf("https://")>-1))a.info(`- Network: ${a.link(s)}`);else{let r=this.isHttps?"https":"http",n=Pe(r,e||"0.0.0.0",t,s);a.info(`- Local: ${a.link(n.localUrlForTerminal)}`),a.info(`- Network: ${a.link(n.lanUrlForTerminal)}`)}}async run(){let e=ke();e.use(it()),e.use(ot()),this.app=e;let t=p.resolve(p.rsConfig.output?.path);this.app.use(ke.static(t));let s=await at.readFile(pt.join(t,"index.html"),"utf8");this.app.get("*",(u,f)=>f.send(s));let r=Object.assign({},p.rsConfig.devServer),{host:o,port:n}=r,m=p.rsConfig.output?.publicPath==="auto"?"/":p.rsConfig.output?.publicPath,l=await k(Number(n),o);if(this.isHttps){let[u,f]=await this.getcert();nt.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:u,cert:f},this.app).listen(l,()=>{this.startLogger({host:o,port:l,publicPath:m})})}else this.app.listen(l,()=>{this.startLogger({host:o,port:l,publicPath:m})})}},lt=new B});g();g();E();b();import{program as C}from"commander";import W,{exit as ct}from"node:process";function Te(){let i="20.0.0";O(i,W.versions.node)===1&&(a.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${W.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${i}`),ct(0)),C.version(p.empPkg.version,"-v, --version").usage("<command> [options]"),C.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(()=>(xe(),Ce));await t.setup("dev",e)}),C.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(()=>(Se(),we));await t.setup("build",e)}),C.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(()=>(Re(),$e));await t.setup("serve",e)}),C.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=>{}),C.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=>{}),C.parse(W.argv)}g();import mt from"fast-glob";import De from"node:fs/promises";import _ from"node:path";var ht=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,ut=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,ft=/import\(['"]([^;\n]+?)['"]\)/,q=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 mt([`${p.empConfig.build.outDir}/**/*.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 De.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(ht,r=>{let o=r.match(ut);if(o||(o=r.match(ft)),o&&o[1]){let n=o[1];if(!n.startsWith("."))return r;let m=_.resolve(_.dirname(e),n).replace(this.outDir,this.aliasName);return r.replace(o[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
1
+ var Ze=Object.defineProperty;var h=(r,e)=>()=>(r&&(e=r(r=0)),e);var G=(r,e)=>{for(var t in e)Ze(r,t,{get:e[t],enumerable:!0})};import{fileURLToPath as Ke}from"node:url";import{dirname as et}from"node:path";import{readFile as tt}from"node:fs/promises";import ae from"node:module";import B from"node:path";var pe,st,M,rt,le,ce,me=h(()=>{"use strict";pe=Ke(import.meta.url),st=et(pe),M=async r=>{try{let e=await tt(r);return JSON.parse(e)}catch(e){console.error(e)}},rt=ae.createRequire(import.meta.url),le=(r,e)=>{let t=rt;return e&&(t=ae.createRequire(e)),t.resolve(r)},ce=B.resolve(st,pe).replace(`${B.sep}dist${B.sep}index.js`,"")});import P from"@rspack/core";import he from"fs";var N,ue,fe=h(()=>{"use strict";N=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(P.DefinePlugin,[this.store.empConfig.define])}async copy(){let e=this.store.resolve("public");he.existsSync(e)&&he.readdirSync(e).length>0&&this.store.chain.plugin("copyRspackPlugin").use(P.CopyRspackPlugin,[{patterns:[{from:e,to:this.store.resolve("dist")}]}])}async progress(){this.store.empConfig.debug.progress&&this.store.chain.plugin("progressPlugin").use(P.ProgressPlugin,[{prefix:"EMP"}])}async empShare(){if(!this.store.empConfig.empShare.name)return;let{ModuleFederationPlugin:e}=P.container;this.store.chain.plugin("empShare").use(e,[{...this.store.empConfig.empShare}])}minJs(){this.store.mode==="production"&&this.store.chain.plugin("minJs").use(P.SwcJsMinimizerRspackPlugin,[this.store.empConfig.build.minOptions])}minCss(){this.store.mode==="production"&&this.store.chain.plugin("minJs").use(P.SwcJsMinimizerRspackPlugin,[{}])}},ue=new N});var U,ge,de=h(()=>{"use strict";U=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"}}}})}},ge=new U});var _,ye,be=h(()=>{"use strict";_=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}})}},ye=new _});import it from"chalk";function ve(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}function x(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]=x(o,i);continue}r[s]=t[s]}return r}var k,xe,S=h(()=>{"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 n=0;n<i;n++){let l=t.length>n?t[n]:0,c=isNaN(Number(l))?l.charCodeAt():Number(l),g=s.length>n?s[n]:0,m=isNaN(Number(g))?g.charCodeAt():Number(g);if(c<m){o=-1;break}else if(c>m){o=1;break}}return o},xe=r=>{r=r/1e3;let e=s=>it.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 ot from"html-webpack-plugin";import nt from"fast-glob";import E from"node:path";var I,Ce,we=h(()=>{"use strict";S();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=x(e.files,this.store.empConfig.empShareLib.externalAssets)),e}setChunk(e){return e.replace(E.extname(e),"").replace(`${this.store.empConfig.appSrc}${E.sep}`,"")}setTemplate(e){return e?this.store.resolve(e):this.store.empResolve(E.join("template","index.html"))}setFavicion(e){return e?this.store.resolve(e):this.store.empResolve(E.join("template","favicon.ico"))}setEntryItem(e,t,s){s=s||this.store.resolve(E.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(ot,[e])}setRspackEntry(e){this.store.merge({entry:e})}async init(){let e=E.join(this.store.appSrc,this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}").replace(/\\/g,"/"),t=await nt([e]);if(t[0]){let s=E.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)}},Ce=new I});var H,Se,Ee=h(()=>{"use strict";H=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}}}}},Se=new H});var J,Oe,$e=h(()=>{"use strict";fe();de();be();we();Ee();J=class{store;async setup(e){this.store=e;let t=[ye.setup(this.store),ge.setup(this.store),ue.setup(this.store),Ce.setup(this.store),Se.setup(this.store)];await Promise.all(t),await this.store.empConfig.plugins(),await this.store.empConfig.chain()}},Oe=new J});import u from"chalk";import{table as at}from"table";var V,p,b=h(()=>{"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(`${u.white.bgBlue(this.pname)}${u.blue.bgWhite(` ${e} `)}
2
+ `)};cyan=e=>{console.log(`${u.white.bgCyan(this.pname)}${u.cyan.bgWhite(` ${e} `)}
3
+ `)};magenta=e=>{console.log(`${u.white.bgMagenta(this.pname)}${u.magenta.bgWhite(` ${e} `)}
4
+ `)};green=e=>{console.log(`${u.white.bgGreen(this.pname)}${u.green.bgWhite(` ${e} `)}
5
+ `)};yellow=e=>{console.log(`${u.white.bgYellow(this.pname)}${u.yellow.bgWhite(` ${e} `)}
6
+ `)};red=e=>{console.log(`${u.white.bgRed(this.pname)}${u.red.bgWhite(` ${e} `)}
7
+ `)};sysError=e=>{console.log(`${u.white.bgRed(" System Error Tips ")}${u.red.bgWhite(` ${e} `)}
8
+ `)};link=e=>u.hex("#3498db")(e);title=e=>{console.log(`${u.greenBright.bold(`${this.pname}`)} ${u.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(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:"/",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:{}},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 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 M(this.empResolve("package.json")),i=await M(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 Be 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
+ `),this.localUrl=n.localUrlForBrowser}this.isOpenBrower&&ze(this.localUrl)}async setup(e,t){await a.setup(e,t),a.empConfig.debug.clearLog&&ve(),p.title(`${e}`),this.publicPath=a.rsConfig.output?.publicPath==="auto"?"/":a.rsConfig.output?.publicPath||"/",this.isOpenBrower=!!a.empConfig.server.open,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([Be.readFile(a.resource.key),Be.readFile(a.resource.cert)])}}});import yt from"net";import bt from"os";async function L(r,e="localhost"){if(r!==vt&&(r<Me||r>Q))throw new Error(`Port number must lie between ${Me} and ${Q}`);let t=r,s=xt(),i;e&&!s.has(e)?i=new Set([e]):i=s;let o=new Set(["EADDRINUSE","EACCES"]);for(;t<=Q;)try{return await wt(t,i)}catch(n){if(!o.has(n.code))throw n;t+=1}throw new Error("No available ports found")}var Me,Q,vt,xt,Ct,wt,Y=h(()=>{"use strict";Me=1024,Q=65535,vt=443,xt=()=>{let r=bt.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},Ct=(r,e)=>new Promise((t,s)=>{let i=yt.createServer();i.unref(),i.on("error",s),i.listen(r,e,()=>{let{port:o}=i.address();i.close(()=>{t(o)})})}),wt=async(r,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await Ct(r,s)}catch(i){if(!t.has(i.code))throw i}return r}});import f from"chalk";import w from"node:path";import{gzipSizeSync as St}from"gzip-size";import Et from"node:fs";function Dt(r,e){let t=[r,e],s=["File","Size","Gzipped"].reduce((i,o,n)=>{let l=t[n],c=o;return l&&(c=o.length<l?o+" ".repeat(l-o.length):o),`${i+c} `}," ");console.log(f.bold.blue(s))}async function Ne(r){let e=r.toJson({all:!1,assets:!0,timings:!0});R(e.time);let s=e.assets.filter(m=>Rt(m.name)).map(jt);s.sort((m,d)=>m.size-d.size);let i=Math.max(...s.map(m=>m.sizeLabel.length)),o=Math.max(...s.map(m=>(m.folder+w.sep+m.name).length));Dt(o,i);let n=0,l=0;s.forEach(m=>{let{sizeLabel:d}=m,{name:v,folder:Qe,gzipSizeLabel:Ye}=m,ie=(Qe+w.sep+v).length,oe=d.length;if(n+=m.size,l+=m.gzippedSize,oe<i){let z=" ".repeat(i-oe);d+=z}let ne=f.gray(m.folder+w.sep)+Lt(m.name);if(ie<o){let z=" ".repeat(o-ie);ne+=z}p.info(` ${ne} ${f.gray(d)} ${Ye}`)});let c=`${f.bold.blue("Total size:")} ${T(n)}`,g=`${f.bold.blue("Gzipped size:")} ${T(l)}`;p.info(`
11
+ ${c}
12
+ ${g}
13
+ `)}function R(r=0){p.info(`${f.greenBright("\u2713")} Ready in ${xe(Number(r))}`)}var Ot,$t,Pt,Rt,kt,jt,T,Lt,A=h(()=>{"use strict";y();b();S();Ot=/\.html$/,$t=/\.(?:js|mjs|cjs|jsx)$/,Pt=/\.css$/,Rt=r=>!/\.map$/.test(r)&&!/\.LICENSE\.txt$/.test(r),kt=r=>r>300*1e3?f.red:r>100*1e3?f.yellow:f.white,jt=r=>{let e=r.name.split("?")[0],t=T(r.size),s=w.basename(e),i=w.join(w.basename(a.empConfig.build.outDir),w.dirname(e)),o=Et.readFileSync(w.join(a.empConfig.build.outDir,e)),n=o.length,l=St(o),c=kt(l)(T(l));return{size:n,folder:i,name:s,gzippedSize:l,sizeLabel:t,gzipSizeLabel:c}};T=r=>{let e=r/1e3;return`${e.toFixed(e<1?2:1)} kB`},Lt=r=>$t.test(r)?f.yellowBright(r):Pt.test(r)?f.greenBright(r):Ot.test(r)?f.blueBright(r):f.magenta(r)});var Ue={};G(Ue,{default:()=>Ft});import{rspack as Tt}from"@rspack/core";import{RspackDevServer as At}from"@rspack/dev-server";var Z,Ft,_e=h(()=>{"use strict";y();D();b();Y();S();A();Z=class extends C{async run(){let e=x(a.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=Tt(e);if(!a.rsConfig.devServer){p.error("devServer is not defined in config");return}let s=Object.assign({},a.rsConfig.devServer),{host:i,port:o}=s;if(this.isHttps&&(s.https===!0&&delete s.https,!s.server)){let[m,d]=await this.getcert();s.server={type:"https",options:{key:m,cert:d}}}let n=await L(Number(o),i);n!==o&&(a.rsConfig.devServer.port=n,s.port=n);let{afterDevServe:l,beforeDevServe:c}=a.empConfig.lifeCycle,g=new At(s,t);this.startOpen({host:i,port:n}),c&&c(),await g.start(),g.middleware?.waitUntilValid(m=>{let d=m?.toJson({all:!1,colors:!1,assets:!1,chunks:!1,timings:!0});R(d.time),l&&l()})}},Ft=new Z});var Ie={};G(Ie,{default:()=>Gt});import{rspack as zt}from"@rspack/core";var K,Gt,He=h(()=>{"use strict";b();y();D();A();K=class extends C{async run(){let{afterBulid:e,beforeBuild:t}=a.empConfig.lifeCycle;t&&t(),zt(a.rsConfig,async(s,i)=>{if(s!==null){p.error(s.stack||s),s.message&&p.error(s.message);return}if(!i){p.red("Stats is Undefined.");return}i.hasErrors()&&(p.error(i.toString({colors:!0,children:!0})),p.red("Failed to compile."),process.exit(1)),i.hasWarnings()&&(p.yellow("Compiled with warnings."),p.warn(i.toString({colors:!0,children:!0}))),await Ne(i),e&&e()})}},Gt=new K});import Bt from"express";import Mt from"cors";import Nt from"compression";import Ut from"https";var F,Je=h(()=>{"use strict";Y();y();D();F=class extends C{app;async init(){let e=Bt();e.use(Nt()),e.use(Mt()),this.app=e}async server(){let e=Object.assign({},a.rsConfig.devServer),{host:t,port:s}=e,i=await L(Number(s),t);if(this.isHttps){let[o,n]=await this.getcert();Ut.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:o,cert:n},this.app).listen(i,async()=>{this.startOpen({host:t,port:i}),await this.onReady()})}else this.app.listen(i,async()=>{this.startOpen({host:t,port:i}),await this.onReady()})}async onReady(){}async middleware(){}async start(){await this.init(),await this.middleware(),await this.server()}}});var Ve={};G(Ve,{default:()=>Vt});import _t from"express";import It from"path";import Ht from"node:fs/promises";import Jt from"node:fs";var ee,Vt,We=h(()=>{"use strict";Je();y();b();A();ee=class extends F{timing=0;async run(){if(this.timing=Date.now(),!Jt.existsSync(a.outDir))return p.sysError(`emp serve must be executed after emp build,${a.outDir} not exist!`);let{beforeServe:e}=a.empConfig.lifeCycle;e&&e(),this.start()}async middleware(){let e=a.resolve(a.rsConfig.output?.path);this.app.use(_t.static(e));let t=await Ht.readFile(It.join(e,"index.html"),"utf8");this.app.get("*",(s,i)=>i.send(t))}async onReady(){R(Date.now()-this.timing);let{afterServe:e}=a.empConfig.lifeCycle;e&&e()}},Vt=new ee});y();y();S();b();import{program as $}from"commander";import te,{exit as Wt}from"node:process";function Xe(){let r="20.0.0";k(r,te.versions.node)===1&&(p.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${te.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${r}`),Wt(0)),$.version(a.empPkg.version,"-v, --version").usage("<command> [options]"),$.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(()=>(_e(),Ue));await t.setup("dev",e)}),$.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(()=>(He(),Ie));await t.setup("build",e)}),$.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(()=>(We(),Ve));await t.setup("serve",e)}),$.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=>{}),$.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=>{}),$.parse(te.argv)}y();import Xt from"fast-glob";import qe from"node:fs/promises";import se from"node:path";var qt=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,Qt=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,Yt=/import\(['"]([^;\n]+?)['"]\)/,re=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 Xt([`${a.empConfig.build.outDir}/**/*.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 qe.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(qt,i=>{let o=i.match(Qt);if(o||(o=i.match(Yt)),o&&o[1]){let n=o[1];if(!n.startsWith("."))return i;let l=se.resolve(se.dirname(e),n).replace(this.outDir,this.aliasName);return i.replace(o[1],l)}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
9
14
  ${t}}\r
10
- `}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await De.writeFile(_.join(this.outDir.replace("dist","types"),"type.d.ts"),t)}},gt=new q;function er(i){return i}export{er as defineConfig,gt as dts,Te as runScript,p as store};
15
+ `}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await qe.writeFile(se.join(this.outDir.replace("dist","types"),"type.d.ts"),t)}},Zt=new re;function li(r){return r}export{li as defineConfig,Zt as dts,Xe as runScript,a as store};
@@ -1,5 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  export declare class BaseScript {
3
+ publicPath: string;
4
+ localUrl: string;
5
+ isOpenBrower: boolean;
6
+ startOpen({ host, port }: any): void;
3
7
  setup(cliName: string, o: any): Promise<void>;
4
8
  run(): Promise<void>;
5
9
  get isHttps(): boolean;
@@ -0,0 +1,7 @@
1
+ import { HttpServer } from './httpBase';
2
+ declare class ServeScript extends HttpServer {
3
+ run(): Promise<void>;
4
+ middleware(): Promise<void>;
5
+ }
6
+ declare const _default: ServeScript;
7
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import { Express } from 'express';
2
+ import { BaseScript } from '../script/base';
3
+ export declare class HttpServer extends BaseScript {
4
+ app: Express;
5
+ init(): Promise<void>;
6
+ server(): Promise<void>;
7
+ onReady(): Promise<void>;
8
+ middleware(): Promise<void>;
9
+ start(): Promise<void>;
10
+ }
@@ -1,9 +1,9 @@
1
- import { Express } from 'express';
2
- import { BaseScript } from '../script/base';
3
- declare class ServeScript extends BaseScript {
4
- app: Express;
5
- startLogger({ host, port, publicPath }: any): void;
1
+ import { HttpServer } from './httpBase';
2
+ declare class ServeScript extends HttpServer {
3
+ timing: number;
6
4
  run(): Promise<void>;
5
+ middleware(): Promise<void>;
6
+ onReady(): Promise<void>;
7
7
  }
8
8
  declare const _default: ServeScript;
9
9
  export default _default;
@@ -1,5 +1,5 @@
1
1
  import { GlobalStore } from '../store';
2
- import { BuildType, DebugType, HtmlType, ReactType, ServerType } from '../types/config';
2
+ import { BuildType, DebugType, HtmlType, LifeCycle, ReactType, ServerType } from '../types/config';
3
3
  import { Output } from '@rspack/core';
4
4
  import { EMPShareLib } from '../store/empShareLib';
5
5
  export declare class EmpConfig {
@@ -42,12 +42,16 @@ export declare class EmpConfig {
42
42
  postcss: never[];
43
43
  };
44
44
  get output(): Output;
45
- get define(): any;
45
+ get define(): {
46
+ [k: string]: string;
47
+ };
48
+ private setDefine;
46
49
  get externals(): any;
47
50
  get resolve(): import("@rspack/core").ResolveOptions;
48
51
  syncEmpOptions(): Promise<void>;
49
52
  get moduleTransformRule(): any;
50
53
  get cacheDir(): string;
54
+ get lifeCycle(): LifeCycle;
51
55
  get reactRuntime(): "automatic" | "classic" | undefined;
52
56
  }
53
57
  declare const _default: EmpConfig;
@@ -1,3 +1,4 @@
1
+ import type { Configuration as RsConfig } from '@rspack/core';
1
2
  import { Configuration as devServerConfig } from '@rspack/dev-server';
2
3
  import Chain from 'webpack-chain';
3
4
  import { Externals, HtmlRspackPluginOptions, ModuleFederationPluginOptions, Output, Resolve, RuleSetRule, SwcJsMinimizerRspackPluginOptions } from '@rspack/core';
@@ -8,6 +9,11 @@ export type DebugType = {
8
9
  clearLog: boolean;
9
10
  progress: boolean;
10
11
  showRsconfig: boolean;
12
+ /**
13
+ * 是否显示执行日志
14
+ * @default false
15
+ */
16
+ infrastructureLogging: RsConfig['infrastructureLogging'];
11
17
  };
12
18
  export type ServerType = devServerConfig & {
13
19
  /**
@@ -128,6 +134,11 @@ export type CSSOptions = {
128
134
  export interface ModuleTransform {
129
135
  exclude?: RuleSetRule['exclude'][];
130
136
  include?: RuleSetRule['include'][];
137
+ /**
138
+ * 默认exclude /(node_modules|bower_components)/
139
+ * @default false
140
+ */
141
+ defaultExclude?: boolean;
131
142
  }
132
143
  export type EMPShareType = ModuleFederationPluginOptions & {
133
144
  /**
@@ -172,6 +183,14 @@ export type ExternalsItemType = {
172
183
  */
173
184
  type?: string;
174
185
  };
186
+ export type LifeCycle = {
187
+ afterBulid?: () => void;
188
+ beforeBuild?: () => void;
189
+ afterDevServe?: () => void;
190
+ beforeDevServe?: () => void;
191
+ afterServe?: () => void;
192
+ beforeServe?: () => void;
193
+ };
175
194
  export type EmpOptions = {
176
195
  /**
177
196
  * publicPath 根路径 可参考webpack,业务模式默认为 auto
@@ -246,4 +265,8 @@ export type EmpOptions = {
246
265
  * @default undefined
247
266
  */
248
267
  reactRuntime?: 'automatic' | 'classic';
268
+ /**
269
+ * emp 执行周期
270
+ */
271
+ lifeCycle?: LifeCycle;
249
272
  };
package/package.json CHANGED
@@ -1,108 +1,116 @@
1
1
  {
2
- "name": "@empjs/cli",
3
- "version": "3.0.0-beta.2",
4
- "description": "emp",
5
- "license": "MIT",
6
- "type": "module",
7
- "files": [
8
- "dist",
9
- "bin",
10
- "resource",
11
- "template",
12
- "client.d.ts",
13
- "emp-tsconfig.json"
14
- ],
15
- "maintainers": [
16
- "xuhongbin",
17
- "ckken"
18
- ],
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/empjs/emp.git",
22
- "directory": "packages/cli"
23
- },
24
- "publishConfig": {
25
- "access": "public"
26
- },
27
- "keywords": [
28
- "react",
29
- "rspack",
30
- "typescript"
31
- ],
32
- "bin": {
33
- "emp": "./bin/emp.js"
34
- },
35
- "main": "dist/index.js",
36
- "module": "dist/index.js",
37
- "types": "dist/index.d.ts",
38
- "exports": {
39
- ".": {
40
- "import": {
41
- "default": "./dist/index.js",
42
- "types": "./dist/index.d.ts"
43
- },
44
- "require": {
45
- "default": "./dist/index.js",
46
- "types": "./dist/index.d.ts"
47
- }
48
- },
49
- "./emp-tsconfig.json": "./emp-tsconfig.json"
50
- },
51
- "scripts": {
52
- "d": "rimraf dist && pnpm run esdev:build",
53
- "b": "rimraf dist && pnpm run esbuild:build",
54
- "dev": "rimraf dist && pnpm run /^esdev:.*/",
55
- "esdev:build": "cross-env ENV=dev node esbuild.js",
56
- "esdev:tsc": "tsc -w",
57
- "esdev:tsc-alias": "tsc-alias -w",
58
- "build": "rimraf dist && pnpm run /^esbuild:.*/",
59
- "esbuild:build": "cross-env ENV=prod node esbuild.js",
60
- "esbuild:tsc": "tsc && tsc-alias",
61
- "dts": "node dts-bundle.js"
62
- },
63
- "engines": {
64
- "node": ">=20.0.0"
65
- },
66
- "author": "Ken",
67
- "devDependencies": {
68
- "@types/compression": "^1.7.2",
69
- "@types/cors": "^2.8.12",
70
- "@types/default-gateway": "^7.2.1",
71
- "@types/express": "^4.17.13",
72
- "@types/fs-extra": "^9.0.13",
73
- "@types/watchpack": "^2.4.3",
74
- "@types/webpack": "^5.28.4",
75
- "@types/webpack-bundle-analyzer": "^4.6.2",
76
- "@types/webpack-sources": "^3.2.2",
77
- "cross-env": "^7.0.3",
78
- "esbuild": "^0.19.5",
79
- "rimraf": "^5.0.5",
80
- "tsc-alias": "^1.8.8"
81
- },
82
- "dependencies": {
83
- "@rspack/core": "^0.5.4",
84
- "@rspack/dev-server": "^0.5.4",
85
- "@rspack/plugin-react-refresh": "^0.5.4",
86
- "react-refresh": "^0.14.0",
87
- "@svgr/webpack": "^8.1.0",
88
- "@types/node": "^20.8.7",
89
- "@types/react": "^18.2.30",
90
- "address": "^2.0.1",
91
- "chalk": "^5.3.0",
92
- "commander": "^11.1.0",
93
- "compression": "^1.7.4",
94
- "cors": "^2.8.5",
95
- "default-gateway": "^7.2.2",
96
- "express": "^4.18.2",
97
- "fast-glob": "^3.3.1",
98
- "html-webpack-plugin": "^5.6.0",
99
- "less-loader": "^11.1.3",
100
- "postcss": "^8.4.33",
101
- "postcss-loader": "^7.3.4",
102
- "sass-loader": "^13.3.2",
103
- "table": "^6.8.1",
104
- "typescript-plugin-css-modules": "^5.0.2",
105
- "webpack-bundle-analyzer": "^4.9.1",
106
- "webpack-chain": "^6.5.1"
107
- }
108
- }
2
+ "name": "@empjs/cli",
3
+ "version": "3.0.0-beta.21",
4
+ "description": "emp",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "files": [
8
+ "dist",
9
+ "bin",
10
+ "resource",
11
+ "template",
12
+ "client.d.ts",
13
+ "emp-tsconfig.json"
14
+ ],
15
+ "maintainers": [
16
+ "xuhongbin",
17
+ "ckken"
18
+ ],
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/empjs/emp.git",
22
+ "directory": "packages/cli"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "keywords": [
28
+ "react",
29
+ "rspack",
30
+ "typescript"
31
+ ],
32
+ "bin": {
33
+ "emp": "./bin/emp.js"
34
+ },
35
+ "main": "dist/index.js",
36
+ "module": "dist/index.js",
37
+ "types": "dist/index.d.ts",
38
+ "exports": {
39
+ ".": {
40
+ "import": {
41
+ "default": "./dist/index.js",
42
+ "types": "./dist/index.d.ts"
43
+ },
44
+ "require": {
45
+ "default": "./dist/index.js",
46
+ "types": "./dist/index.d.ts"
47
+ }
48
+ },
49
+ "./emp-tsconfig.json": "./emp-tsconfig.json"
50
+ },
51
+ "scripts": {
52
+ "d": "rimraf dist && pnpm run esdev:build",
53
+ "b": "rimraf dist && pnpm run esbuild:build",
54
+ "dev": "rimraf dist && pnpm run /^esdev:.*/",
55
+ "esdev:build": "cross-env ENV=dev node esbuild.js",
56
+ "esdev:tsc": "tsc -w",
57
+ "esdev:tsc-alias": "tsc-alias -w",
58
+ "build": "rimraf dist && pnpm run /^esbuild:.*/",
59
+ "esbuild:build": "cross-env ENV=prod node esbuild.js",
60
+ "esbuild:tsc": "tsc && tsc-alias",
61
+ "dts": "node dts-bundle.js"
62
+ },
63
+ "engines": {
64
+ "node": ">=20.0.0"
65
+ },
66
+ "author": "Ken",
67
+ "devDependencies": {
68
+ "@types/compression": "^1.7.2",
69
+ "@types/cors": "^2.8.12",
70
+ "@types/default-gateway": "^7.2.1",
71
+ "@types/express": "^4.17.13",
72
+ "@types/fs-extra": "^9.0.13",
73
+ "@types/watchpack": "^2.4.3",
74
+ "@types/webpack": "^5.28.4",
75
+ "@types/webpack-bundle-analyzer": "^4.6.2",
76
+ "@types/webpack-hot-middleware": "^2.25.9",
77
+ "@types/webpack-sources": "^3.2.2",
78
+ "cross-env": "^7.0.3",
79
+ "esbuild": "^0.19.5",
80
+ "rimraf": "^5.0.5",
81
+ "tsc-alias": "^1.8.8"
82
+ },
83
+ "dependencies": {
84
+ "@rspack/core": "0.5.7",
85
+ "@rspack/dev-server": "0.5.7",
86
+ "@rspack/plugin-react-refresh": "0.5.7",
87
+ "@svgr/webpack": "^8.1.0",
88
+ "@types/node": "^20.8.7",
89
+ "@types/react": "^18.2.30",
90
+ "address": "^2.0.1",
91
+ "ansi-html-community": "^0.0.8",
92
+ "chalk": "^5.3.0",
93
+ "commander": "^11.1.0",
94
+ "compression": "^1.7.4",
95
+ "cors": "^2.8.5",
96
+ "default-gateway": "^7.2.2",
97
+ "express": "^4.18.2",
98
+ "fast-glob": "^3.3.1",
99
+ "gzip-size": "^7.0.0",
100
+ "html-entities": "^2.5.2",
101
+ "html-webpack-plugin": "^5.6.0",
102
+ "less-loader": "^11.1.3",
103
+ "open": "^10.1.0",
104
+ "postcss": "^8.4.33",
105
+ "postcss-loader": "^7.3.4",
106
+ "react-refresh": "^0.14.0",
107
+ "sass-loader": "^13.3.2",
108
+ "strip-ansi": "^7.1.0",
109
+ "table": "^6.8.1",
110
+ "typescript-plugin-css-modules": "^5.0.2",
111
+ "webpack-bundle-analyzer": "^4.9.1",
112
+ "webpack-chain": "^6.5.1",
113
+ "webpack-dev-middleware": "^7.0.0",
114
+ "webpack-hot-middleware": "^2.26.1"
115
+ }
116
+ }
@@ -0,0 +1,95 @@
1
+ (*
2
+ Copyright (c) 2015-present, Facebook, Inc.
3
+
4
+ This source code is licensed under the MIT license found in the
5
+ LICENSE file at
6
+ https://github.com/facebookincubator/create-react-app/blob/master/LICENSE
7
+ *)
8
+
9
+ property targetTab: null
10
+ property targetTabIndex: -1
11
+ property targetWindow: null
12
+ property theProgram: "Google Chrome"
13
+
14
+ on run argv
15
+ set theURL to item 1 of argv
16
+
17
+ -- Allow requested program to be optional,
18
+ -- default to Google Chrome
19
+ if (count of argv) > 1 then
20
+ set theProgram to item 2 of argv
21
+ end if
22
+
23
+ using terms from application "Google Chrome"
24
+ tell application theProgram
25
+
26
+ if (count every window) = 0 then
27
+ make new window
28
+ end if
29
+
30
+ -- 1: Looking for tab running debugger
31
+ -- then, Reload debugging tab if found
32
+ -- then return
33
+ set found to my lookupTabWithUrl(theURL)
34
+ if found then
35
+ set targetWindow's active tab index to targetTabIndex
36
+ tell targetTab to reload
37
+ tell targetWindow to activate
38
+ set index of targetWindow to 1
39
+ return
40
+ end if
41
+
42
+ -- 2: Looking for Empty tab
43
+ -- In case debugging tab was not found
44
+ -- We try to find an empty tab instead
45
+ set found to my lookupTabWithUrl("chrome://newtab/")
46
+ if found then
47
+ set targetWindow's active tab index to targetTabIndex
48
+ set URL of targetTab to theURL
49
+ tell targetWindow to activate
50
+ return
51
+ end if
52
+
53
+ -- 3: Create new tab
54
+ -- both debugging and empty tab were not found
55
+ -- make a new tab with url
56
+ tell window 1
57
+ activate
58
+ make new tab with properties {URL:theURL}
59
+ end tell
60
+ end tell
61
+ end using terms from
62
+ end run
63
+
64
+ -- Function:
65
+ -- Lookup tab with given url
66
+ -- if found, store tab, index, and window in properties
67
+ -- (properties were declared on top of file)
68
+ on lookupTabWithUrl(lookupUrl)
69
+ using terms from application "Google Chrome"
70
+ tell application theProgram
71
+ -- Find a tab with the given url
72
+ set found to false
73
+ set theTabIndex to -1
74
+ repeat with theWindow in every window
75
+ set theTabIndex to 0
76
+ repeat with theTab in every tab of theWindow
77
+ set theTabIndex to theTabIndex + 1
78
+ if (theTab's URL as string) contains lookupUrl then
79
+ -- assign tab, tab index, and window to properties
80
+ set targetTab to theTab
81
+ set targetTabIndex to theTabIndex
82
+ set targetWindow to theWindow
83
+ set found to true
84
+ exit repeat
85
+ end if
86
+ end repeat
87
+
88
+ if found then
89
+ exit repeat
90
+ end if
91
+ end repeat
92
+ end tell
93
+ end using terms from
94
+ return found
95
+ end lookupTabWithUrl
@@ -1,6 +0,0 @@
1
- import { GlobalStore } from '../store';
2
- declare class LifeCycle {
3
- afterChain(store: GlobalStore): Promise<void>;
4
- }
5
- declare const _default: LifeCycle;
6
- export default _default;