@empjs/cli 3.0.0-beta.9 → 3.0.0-rc.1

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/client.d.ts CHANGED
@@ -41,13 +41,26 @@ declare module '*.webp' {
41
41
  const src: string
42
42
  export default src
43
43
  }
44
-
45
44
  declare module '*.svg' {
45
+ const src: string
46
+ export default src
47
+ }
48
+
49
+ /* declare module '*.svg' {
46
50
  const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>
47
51
  const content: string
48
-
49
52
  export {ReactComponent}
50
53
  export default content
54
+ } */
55
+ // declare module '*.svg?react' {
56
+ // const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>
57
+ // const content: string
58
+ // export {ReactComponent}
59
+ // export default content
60
+ // }
61
+ declare module '*.svg?react' {
62
+ const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>
63
+ export default ReactComponent
51
64
  }
52
65
  // styles
53
66
 
@@ -98,23 +111,3 @@ interface ImportMetaEnv {
98
111
  interface ImportMeta {
99
112
  readonly env: ImportMetaEnv
100
113
  }
101
-
102
- /**
103
- * polyfill all `core-js` features, including early-stage proposals:
104
- */
105
- // declare module 'core-js/full'
106
-
107
- /**
108
- * polyfill all actual features - stable ES, web standards and stage 3 ES proposals:
109
- */
110
- // declare module 'core-js/actual'
111
-
112
- /**
113
- * polyfill only stable features - ES and web standards:
114
- */
115
- // declare module 'core-js/stable'
116
-
117
- /**
118
- * polyfill only stable ES features:
119
- */
120
- // declare module 'core-js/es'
@@ -1,2 +0,0 @@
1
- declare let ep: any;
2
- export default ep;
@@ -1,14 +0,0 @@
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;
@@ -1,6 +0,0 @@
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
- };
@@ -1,6 +0,0 @@
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,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;
@@ -16,28 +16,6 @@ declare class Logger {
16
16
  sysError: (msg: string) => void;
17
17
  link: (msg: string) => string;
18
18
  title: (msg: string) => void;
19
- tableData: any;
20
- tableConfig: {
21
- border: {
22
- topBody: string;
23
- topJoin: string;
24
- topLeft: string;
25
- topRight: string;
26
- bottomBody: string;
27
- bottomJoin: string;
28
- bottomLeft: string;
29
- bottomRight: string;
30
- bodyLeft: string;
31
- bodyRight: string;
32
- bodyJoin: string;
33
- joinBody: string;
34
- joinLeft: string;
35
- joinRight: string;
36
- joinJoin: string;
37
- };
38
- };
39
- tableInput(d: any): void;
40
- tableOutput(): void;
41
19
  }
42
20
  declare const _default: Logger;
43
21
  export default _default;
@@ -1,3 +1,5 @@
1
+ export declare const getLanIp: () => string;
2
+ export declare const getPkgVersion: (pkgPath: string) => any;
1
3
  export declare function clearConsole(): void;
2
4
  export declare function deepAssign<T>(target: any, ...sources: any): T;
3
5
  export declare const ensureArray: <T>(params: T | T[]) => T[];
@@ -10,3 +12,4 @@ export declare const ensureArray: <T>(params: T | T[]) => T[];
10
12
  export declare const jsonFilter: (d?: any, notIncludeKeys?: string[]) => any;
11
13
  export declare const vCompare: (preVersion?: string, lastVersion?: string) => number;
12
14
  export declare const timeFormat: (seconds: number) => string;
15
+ export declare const importJsVm: (content: string) => string;
package/dist/index.js CHANGED
@@ -1,15 +1,16 @@
1
- var Ze=Object.defineProperty;var m=(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=m(()=>{"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=m(()=>{"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=m(()=>{"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)$/,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=m(()=>{"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:{appendOnly:!0,level:"warn"},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 v(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]=v(o,i);continue}r[s]=t[s]}return r}var k,xe,S=m(()=>{"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),f=s.length>n?s[n]:0,h=isNaN(Number(f))?f.charCodeAt():Number(f);if(c<h){o=-1;break}else if(c>h){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,we,Ce=m(()=>{"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=v(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)}},we=new I});var H,Se,Ee=m(()=>{"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=m(()=>{"use strict";fe();de();be();Ce();Ee();J=class{store;async setup(e){this.store=e;let t=[ye.setup(this.store),ge.setup(this.store),ue.setup(this.store),we.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,y=m(()=>{"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=m(()=>{"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=m(()=>{"use strict";S();Pe();W=class{store;appSrc="src";appEntry="";base="";assign(e,t){return t=t||{},v(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},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,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 v({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 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: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,d=m(()=>{"use strict";me();$e();y();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\u26A1v${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=b=>je.format({protocol:r,hostname:b,port:t,pathname:s}),o=b=>je.format({protocol:r,hostname:b,port:De.bold(t),pathname:s}),n=e==="0.0.0.0"||e==="::",l,c,f=De.gray("unavailable");if(n){l="localhost";try{let{int:b}=ht();c=mt(b||""),c&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(c)?f=o(c):c=void 0)}catch{}}else l=e,c=e,f=o(c);let h=o(l),C=i(l);return{lanUrlForConfig:c,lanUrlForTerminal:f,localUrlForTerminal:h,localUrlForBrowser:C}}var Te=m(()=>{"use strict"});import{exec as ut}from"node:child_process";import{promisify as ft}from"node:util";var Fe,Ae,gt,dt,ze,Ge=m(()=>{"use strict";y();d();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 x,D=m(()=>{"use strict";y();d();S();Te();Ge();x=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 Ct(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,wt,Ct,Y=m(()=>{"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},wt=(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)})})}),Ct=async(r,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await wt(r,s)}catch(i){if(!t.has(i.code))throw i}return r}});import g from"chalk";import w from"node:path";import{gzipSizeSync as St}from"gzip-size";import Et from"node:fs";async 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(g.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(h=>Rt(h.name)).map(jt);s.sort((h,C)=>h.size-C.size);let i=Math.max(...s.map(h=>h.sizeLabel.length)),o=Math.max(...s.map(h=>(h.folder+w.sep+h.name).length));Dt(o,i);let n=0,l=0;s.forEach(h=>{let{sizeLabel:C}=h,{name:b,folder:Qe,gzipSizeLabel:Ye}=h,ie=(Qe+w.sep+b).length,oe=C.length;if(n+=h.size,l+=h.gzippedSize,oe<i){let z=" ".repeat(i-oe);C+=z}let ne=g.gray(h.folder+w.sep)+Lt(h.name);if(ie<o){let z=" ".repeat(o-ie);ne+=z}p.info(` ${ne} ${g.gray(C)} ${Ye}`)});let c=`${g.bold.blue("Total size:")} ${T(n)}`,f=`${g.bold.blue("Gzipped size:")} ${T(l)}`;p.info(`
11
- ${c}
12
- ${f}
13
- `)}function R(r=0){p.info(`${g.greenBright("\u2713")} Ready in ${xe(Number(r))}`)}var Ot,$t,Pt,Rt,kt,jt,T,Lt,A=m(()=>{"use strict";d();y();S();Ot=/\.html$/,$t=/\.(?:js|mjs|cjs|jsx)$/,Pt=/\.css$/,Rt=r=>!/\.map$/.test(r)&&!/\.LICENSE\.txt$/.test(r),kt=r=>r>300*1e3?g.red:r>100*1e3?g.yellow:g.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)?g.yellowBright(r):Pt.test(r)?g.greenBright(r):Ot.test(r)?g.blueBright(r):g.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=m(()=>{"use strict";d();D();y();Y();S();A();Z=class extends x{async run(){let e=v(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[c,f]=await this.getcert();s.server={type:"https",options:{key:c,cert:f}}}let n=await L(Number(o),i);n!==o&&(a.rsConfig.devServer.port=n,s.port=n);let l=new At(s,t);this.startOpen({host:i,port:n}),await l.start(),l.middleware?.waitUntilValid(c=>{let f=c?.toJson({all:!1,colors:!1,assets:!1,chunks:!1,timings:!0});R(f.time)})}},Ft=new Z});var Ie={};G(Ie,{default:()=>Gt});import{rspack as zt}from"@rspack/core";var K,Gt,He=m(()=>{"use strict";y();d();D();A();K=class extends x{async run(){zt(a.rsConfig,(e,t)=>{if(e!==null){p.error(e.stack||e),e.message&&p.error(e.message);return}if(!t){p.red("Stats is Undefined.");return}t.hasErrors()&&(p.error(t.toString({colors:!0,children:!0})),p.red("Failed to compile."),process.exit(1)),t.hasWarnings()&&(p.yellow("Compiled with warnings."),p.warn(t.toString({colors:!0,children:!0}))),Ne(t)})}},Gt=new K});import Bt from"express";import Mt from"cors";import Nt from"compression";import Ut from"https";var F,Je=m(()=>{"use strict";Y();d();D();F=class extends x{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=m(()=>{"use strict";Je();d();y();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!`);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)}},Vt=new ee});d();d();S();y();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)}d();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
1
+ var dt=Object.defineProperty;var l=(r,e)=>()=>(r&&(e=r(r=0)),e);var J=(r,e)=>{for(var t in e)dt(r,t,{get:e[t],enumerable:!0})};import{fileURLToPath as yt}from"node:url";import{dirname as bt}from"node:path";import{readFile as vt}from"node:fs/promises";import be from"node:module";import _ from"node:path";var ve,Ct,V,T,Ce,we,W=l(()=>{"use strict";ve=yt(import.meta.url),Ct=bt(ve),V=async r=>{try{let e=await vt(r);return JSON.parse(e)}catch(e){console.error(e)}},T=be.createRequire(import.meta.url),Ce=(r,e)=>{let t=T;return e&&(t=be.createRequire(e)),t.resolve(r)},we=_.resolve(Ct,ve).replace(`${_.sep}dist${_.sep}index.js`,"")});import k from"@rspack/core";import xe from"fs";import{ModuleFederationPlugin as wt}from"@module-federation/enhanced/rspack";var X,Se,Ee=l(()=>{"use strict";X=class{store;async setup(e){this.store=e;let t=[this.define(),this.anylayze(),this.progress(),this.copy(),this.empShare(),this.minify()];await this.store.empConfig.lifeCycle.beforePlugin(),await Promise.all(t),await this.store.empConfig.lifeCycle.afterPlugin()}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(k.DefinePlugin,[this.store.empConfig.define])}async copy(){let e=this.store.resolve("public");xe.existsSync(e)&&xe.readdirSync(e).length>0&&this.store.chain.plugin("copyRspackPlugin").use(k.CopyRspackPlugin,[{patterns:[{from:e,to:this.store.resolve("dist")}]}])}async progress(){this.store.empConfig.debug.progress&&this.store.chain.plugin("progressPlugin").use(k.ProgressPlugin,[{prefix:"EMP"}])}async empShare(){let{isEmpshare:e}=this.store.empConfig.empShareLib;if(!e)return;let t=wt;this.store.chain.plugin("empShare").use(t,[this.store.empConfig.empShareLib.pluginConfig])}minify(){this.store.chain.optimization.minimize(this.store.mode==="production"),this.store.chain.optimization.minimizer("minJs").use(k.SwcJsMinimizerRspackPlugin,[this.store.empConfig.build.minOptions]),this.store.chain.optimization.minimizer("minCss").use(k.SwcCssMinimizerRspackPlugin,[{}])}},Se=new X});import xt from"chalk";import St from"fs-extra";import{ip as Et}from"address";import{gateway4sync as Ot}from"default-gateway";function Pe(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}function f(r,...e){for(let t of e)for(let s in t){let i=t[s],n=r[s];if(Object(i)==i&&Object(n)===n){r[s]=f(n,i);continue}r[s]=t[s]}return r}var j,Oe,L,ke,$e,y=l(()=>{"use strict";j=()=>{let{int:r}=Ot();return Et(r||"")||"127.0.0.1"},Oe=r=>{try{let{version:e}=St.readJSONSync(r);return e}catch{return}};L=(r="",e="")=>{let t=r.replace("^","").split("."),s=e.replace("^","").split("."),i=Math.max(t.length,s.length),n=0;for(let p=0;p<i;p++){let m=t.length>p?t[p]:0,g=isNaN(Number(m))?m.charCodeAt():Number(m),O=s.length>p?s[p]:0,c=isNaN(Number(O))?O.charCodeAt():Number(O);if(g<c){n=-1;break}else if(g>c){n=1;break}}return n},ke=r=>{r=r/1e3;let e=s=>xt.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`},$e=r=>`data:text/javascript,${r}`});import Te from"node:path";var q,je,Le=l(()=>{"use strict";W();y();q=class{store;swcJsOptions={};swcTsOptions={};coreJs={version:"3",alias:"",path:""};async setup(e){this.store=e;let t=[this.files(),this.scripts(),this.rspackGenerator(),this.rspackParser()];await Promise.all(t)}rspackGenerator(){let e=this.store.isDev?"[path][name]-[local]-[hash:5]":"[local]-[hash:5]";this.store.chain.merge({module:{generator:{css:{localIdentName:e},"css/auto":{localIdentName:e},"css/module":{localIdentName:e}}}})}rspackParser(){this.store.chain.merge({module:{parser:{css:{namedExports:!1},"css/auto":{namedExports:!1},"css/module":{namedExports:!1}}}})}get isPolyfill(){return this.store.empConfig.build.polyfill}swcParser(e){switch(e){case"js":return{syntax:"ecmascript",jsx:!0,decorators:!0,decoratorsBeforeExport:!1};case"ts":return{syntax:"typescript",decorators:!0,tsx:!0,dynamicImport:!0}}}swcJsc(e){let{target:t,externalHelpers:s}=this.store.empConfig.build;return{parser:this.swcParser(e),transform:{},target:t,externalHelpers:s,preserveAllComments:!0}}get swcCoreVersion(){let[e,t]=this.coreJs.version.split(".");return`${e}.${t}`}swcOptions(e){let t={jsc:this.swcJsc(e),isModule:"unknown"};return this.isPolyfill&&(delete t.jsc.target,t.env={coreJs:this.swcCoreVersion,targets:this.store.empConfig.build.browserslist},this.store.empConfig.isESM||(t.env.mode=this.store.empConfig.build.polyfill),this.store.empConfig.build.polyfill==="usage"&&(t.env.shippedProposals=!0,t.env.include=["es.object.values","es.array.flat"])),t}swcInitOptions(){let{externalHelpers:e}=this.store.empConfig.build;e&&this.store.chain.resolve.alias.set("@swc/helpers",Te.dirname(T.resolve("@swc/helpers/package.json"))),this.coreJs.path=T.resolve("core-js/package.json");let t=Oe(this.coreJs.path);t&&(this.coreJs.version=t),this.coreJs.alias=Te.dirname(this.coreJs.path),this.store.empConfig.build.polyfill&&(this.store.chain.resolve.alias.set("core-js",this.coreJs.alias),this.store.chain.module.rule("javascript").exclude.add(/core-js/),this.store.chain.module.rule("typescript").exclude.add(/core-js/)),this.swcTsOptions=this.swcOptions("ts"),this.swcJsOptions=this.swcOptions("js")}async scripts(){this.swcInitOptions();let e=!1,t=[];this.store.chain.merge({module:{parser:{javascript:{exportsPresence:"error",importExportsPresence:"error"}},rule:{mjs:{test:/\.m?js/,resolve:{fullySpecified:!1}},typescript:{test:/\.(ts|tsx)$/,exclude:t,sideEffects:e,use:{swc:{loader:"builtin:swc-loader",options:this.swcTsOptions}}},javascript:{test:/\.(js|jsx)$/,exclude:t,sideEffects:e,use:{swc:{loader:"builtin:swc-loader",options:this.swcJsOptions}}}}}})}async files(){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"}}}})}},je=new q});var Q,De,Fe=l(()=>{"use strict";Q=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({node:{global:!0},experiments:{rspackFuture:{newTreeshaking:this.store.empConfig.debug.newTreeshaking},outputModule:this.store.empConfig.isESM,topLevelAwait:!0},target:this.store.empConfig.target,infrastructureLogging:this.store.empConfig.debug.infrastructureLogging,context:this.store.root,mode:this.store.mode,cache:this.store.empConfig.debug.rspackCache,devtool:this.store.empConfig.build.sourcemap?"source-map":!1,builtins:{},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(){let e={moduleIds:this.store.empConfig.build.moduleIds,chunkIds:this.store.empConfig.build.chunkIds,minimize:this.store.empConfig.build.minify,splitChunks:{chunks:"async",cacheGroups:{}}};this.store.empConfig.build.polyfill&&(e.splitChunks.cacheGroups={}),this.store.chain.merge({optimization:e})}},De=new Q});import Ae from"html-webpack-plugin";var Me,D,Re,F,Pt,M,Y=l(()=>{"use strict";y();u();Me="HtmlImportMapPlugin",D=class{importMap;constructor(e){this.importMap=e}apply(e){e.hooks.compilation.tap(Me,t=>{Ae.getHooks(t).alterAssetTagGroups.tapAsync(Me,(s,i)=>{s.headTags.push({tagName:"script",attributes:{type:"importmap"},innerHTML:`${JSON.stringify(this.importMap,null,2)}`,voidTag:!1,meta:{plugin:void 0}}),i(null,s)})})}},Re="HtmlEmpShareLibPlugin",F=class{files;constructor(e){this.files=f({js:[],css:[]},e)}apply(e){e.hooks.compilation.tap(Re,t=>{let s=this.files;Ae.getHooks(t).alterAssetTagGroups.tapAsync(Re,(i,n)=>{s.js.map(p=>{i.headTags.push({tagName:"script",attributes:{src:p},voidTag:!1,meta:{plugin:void 0}})}),s.css.map(p=>{i.headTags.push({tagName:"link",attributes:{rel:"stylesheet",href:p},voidTag:!1,meta:{plugin:void 0}})}),n(null,i)})})}},Pt=()=>{let r=[`import 'core-js/${o.empConfig.build.coreJsFeatures}'`].join(`
2
+ `);return $e(r)},M=class{constructor(){}apply(e){let{webpack:t}=e;new t.EntryPlugin(e.context,Pt(),{name:void 0}).apply(e)}}});import kt from"html-webpack-plugin";import $t from"fast-glob";import x from"node:path";var Z,Be,Ge=l(()=>{"use strict";y();Y();Z=class{store;entriesConfig={};async setup(e){this.store=e,await this.init(),this.toConfig()}setHtmlConfig(e,t){return e.template=this.setTemplate(e.template),e.favicon=this.setFavicion(e.favicon),e.chunks=t,e.filename=`${t[0]}.html`,this.store.empConfig.base&&(e.publicPath=this.store.empConfig.base),e.tags=e.tags||{},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),n=[s];this.entriesConfig[i]={entry:{[i]:n},html:this.setHtmlConfig(t,[i])}}setRspackHtmlPlugin(e,t){this.store.chain.plugin(`html-plugin-${t}`).use(kt,[e]),this.store.empConfig.empShareLib&&(e.files=f(e.files,this.store.empConfig.empShareLib.externalAssets)),this.store.chain.plugin(`html-plugin-empShare-${t}`).use(F,[e.files]),this.store.empConfig.empShareLib.useImportMap&&this.store.chain.plugin(`html-plugin-import-map-${t}`).use(D,[this.store.empConfig.empShareLib.importMap])}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 $t([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)}},Be=new Z});var K,ze,Ie=l(()=>{"use strict";K=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:{sassLoader: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:{lessLoader:e},type:"css/auto"}}}})}async css(){this.store.chain.merge({module:{rule:{css:{test:/\.css$/,use:{},type:"css/auto"}}}})}},ze=new K});var ee,He,Ue=l(()=>{"use strict";Ee();Le();Fe();Ge();Ie();ee=class{store;async setup(e){this.store=e;let t=[De.setup(this.store),je.setup(this.store),Se.setup(this.store),Be.setup(this.store),ze.setup(this.store)];await Promise.all(t),await this.store.empConfig.plugins(),await this.store.empConfig.chain()}},He=new ee});import h from"chalk";var te,a,b=l(()=>{"use strict";te=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} `)}
3
+ `)};cyan=e=>{console.log(`${h.white.bgCyan(this.pname)}${h.cyan.bgWhite(` ${e} `)}
4
+ `)};magenta=e=>{console.log(`${h.white.bgMagenta(this.pname)}${h.magenta.bgWhite(` ${e} `)}
5
+ `)};green=e=>{console.log(`${h.white.bgGreen(this.pname)}${h.green.bgWhite(` ${e} `)}
6
+ `)};yellow=e=>{console.log(`${h.white.bgYellow(this.pname)}${h.yellow.bgWhite(` ${e} `)}
7
+ `)};red=e=>{console.log(`${h.white.bgRed(this.pname)}${h.red.bgWhite(` ${e} `)}
8
+ `)};sysError=e=>{console.log(`${h.white.bgRed(" System Error Tips ")}${h.red.bgWhite(` ${e} `)}
9
+ `)};link=e=>h.hex("#3498db")(e);title=e=>{console.log(`${h.greenBright.bold(`${this.pname}`)} ${h.bgGreenBright(` ${e} `)}
10
+ `)}},a=new te});var R,Ne=l(()=>{"use strict";u();R=class{externals={};externalAssets={js:[],css:[]};exp=/^([0-9a-zA-Z_\s]+)@(.*)/;config;importMap={imports:{}};version;isEmpshare=!1;async setup(){this.config=o.empConfig.empShare,this.version=o.empConfig.empShare.mfVersion,this.isEmpshare=!!o.empConfig.empShare.name,this.config.shareLib&&this.setShareLib(),this.prepareEsm()}get useImportMap(){return this.config.useImportMap&&o.empConfig.isESM}get pluginConfig(){let e={...this.config};return delete e.mfVersion,delete e.shareLib,delete e.useImportMap,{manifest:!1,dts:!1,dev:!1,...e}}prepareEsm(){if(o.empConfig.isESM){this.config.library={type:"module"};let e=this.config.remotes||{};for(let[t,s]of Object.entries(e))if(typeof s=="string"){let i=s.match(this.exp)||[];i.length>0&&(e[t]=i[2])}this.config.remotes=e}}async setShareLib(){let e=this.config,t=[];if(typeof e.shareLib=="object")for(let[s,i]of Object.entries(e.shareLib)){let n={};if(n.module=s,typeof i=="string"){let p=i.match(this.exp)||[];p.length>0?(n.global=p[1],n.entry=p[2],n.type="js",t.push(n),n={}):(n.global="",n.entry=i,n.type="js",t.push(n),n={})}else Array.isArray(i)?i.map(p=>{if(!p)return;if(p.split("?")[0].endsWith(".css"))n.entry=p,n.type="css";else{let g=p.match(this.exp)||[];g.length>0?(n.global=g[1],n.entry=g[2],n.type="js"):(n.global="",n.entry=p,n.type="js")}t.push(n),n={}}):typeof i=="object"&&i.entry&&(n.entry=i.entry,n.global=i.global,n.type=i.type,t.push(n),n={})}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:o.empConfig.isESM&&(this.useImportMap?(this.externals[s.module]=s.module,this.importMap.imports[s.module]=s.entry):this.externals[s.module]=s.entry),s.entry&&!o.empConfig.isESM&&this.externalAssets.js.push(s.entry)):s.type==="css"&&s.entry&&this.externalAssets.css.push(s.entry)})}}}});import Je from"url";import _e from"chalk";var se,E,re=l(()=>{"use strict";y();se=class{imf={protocol:"",port:8e3,pathname:"/"};host="0.0.0.0";urls={lanUrlForConfig:"",lanUrlForTerminal:_e.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=j;formatUrl(e){let{protocol:t,port:s,pathname:i}=this.imf;return Je.format({protocol:t,hostname:e,port:s,pathname:i})}prettyPrintUrl(e){let{protocol:t,port:s,pathname:i}=this.imf;return Je.format({protocol:t,hostname:e,port:_e.bold(s),pathname:i})}},E=new se});var ie,A,oe=l(()=>{"use strict";re();y();u();ie=class{isADB=!1;isHttps=!1;get isHttpBase(){let e=o.empOptions.base||"";return e.indexOf("http://")>-1||e.indexOf("https://")>-1}setup(){if(this.isADB=!!o.empOptions.autoDevBase&&o.mode==="development"&&!this.isHttpBase,!this.isADB)return;let{server:e,https:t}=o.empOptions.server||{};this.isHttps=e==="https"||typeof e=="object"&&e.type==="https"||t===!0;let s=E.getLanIp(),i=this.isHttps?"https":"http",n=o.empOptions.server?.port||8e3;o.empOptions.base=`${i}://${s}:${n}/`,o.empOptions.server=f({port:n,client:{webSocketURL:`${this.isHttps?"wss":"ws"}://${s}:${n}/ws`}},o.empOptions.server)}},A=new ie});var B,Ve=l(()=>{"use strict";oe();u();Y();B=class{op={};constructor(e={}){this.op=e}async afterGetEmpOptions(){A.setup(),this.op.afterGetEmpOptions&&await this.op.afterGetEmpOptions()}async beforePlugin(){o.empConfig.build.polyfill==="entry"&&o.chain.plugin("empPolyfill").use(M),this.op.beforePlugin&&await this.op.beforePlugin()}async afterPlugin(){this.op.afterPlugin&&await this.op.afterPlugin()}async beforeBuild(){this.op.beforeBuild&&await this.op.beforeBuild()}async afterBulid(){this.op.afterBulid&&await this.op.afterBulid()}async beforeDevServe(){console.log(this.op),this.op.beforeDevServe&&await this.op.beforeDevServe()}async afterDevServe(){this.op.afterDevServe&&await this.op.afterDevServe()}async beforeServe(){this.op.beforeServe&&await this.op.beforeServe()}async afterServe(){this.op.afterServe&&await this.op.afterServe()}}});import Tt from"node:fs";var ne,We,Xe=l(()=>{"use strict";y();Ne();Ve();ne=class{store;appSrc="src";appEntry="";base="";target=[];assign(e,t){return t=t||{},f(e,t)}empShareLib=new R;isESM=!1;async autoDevSet(){this.store.mode==="development"&&this.store.empOptions.autoDevBase}checkIsESM(e){return["es3","es5"].indexOf(e)===-1}lifeCycle;async setup(e){this.store=e,await this.syncEmpOptions(),this.lifeCycle=new B(this.store.empOptions.lifeCycle),await this.lifeCycle.afterGetEmpOptions(),this.isESM=this.checkIsESM(this.build.target),this.store.empOptions.target?(this.target=this.store.empOptions.target,Array.isArray(this.target)&&!this.target.includes(this.build.target)&&this.target.push(this.build.target)):this.target=["web",this.build.target];let{appSrc:t,base:s,appEntry:i}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),i&&(this.appEntry=i),this.store.empConfig.empShare&&await this.empShareLib.setup()}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,showPerformance:!1,rspackCache:!0,infrastructureLogging:{appendOnly:!0,level:"warn"},newTreeshaking:this.store.empConfig.isESM},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",moduleIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev,minOptions:{},target:"es5",polyfill:!1,coreJsFeatures:"stable",externalHelpers:!1,browserslist:this.store.browserslistOptions.default},{...this.store.empOptions.build,staticDir:e})}get html(){let e=this.store.empOptions.html?.template?[]:{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"},keywords:{keywords:""},description:{description:""}};return this.assign({lang:"zh-CN",title:"EMP",inject:"body",minify:!this.store.isDev,scriptLoading:this.isESM?"module":"defer",meta:e,files:{css:[],js:[]},tags:{headTags:[],bodyTags:[]}},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}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.5},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,n={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};return this.assign(n,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:this.isESM?"esm":"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 f({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(!Tt.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"}},We=new ne});import v from"node:path";import jt from"node:fs/promises";import Lt from"webpack-chain";import{pathToFileURL as Dt}from"node:url";import Ft from"node:util";var pe,o,u=l(()=>{"use strict";W();Ue();b();Xe();y();pe=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=we;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;cliOptions;chain;rsConfig;empOptions={};empConfig;vCompare=L;deepAssign=f;getLanIp=j;async setup(e,t){await this.initVars(e,t),this.empConfig=We,await this.empConfig.setup(this),this.initPaths(),this.chain=new Lt,await He.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 V(this.empResolve("package.json")),i=await V(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...i}}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\u26A1${this.empPkg.version}${this.cliMode==="dev"?".DEV":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e,t){return Ce(e,t)}importFileUrl(e){return Dt(e).toString()}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){if(this.empConfig.debug.showRsconfig)if(typeof this.empConfig.debug.showRsconfig=="string"){let e=v.join(this.root,this.empConfig.debug.showRsconfig);jt.writeFile(e,JSON.stringify(this.rsConfig,null,2))}else{let e={colors:!0,depth:null},t=typeof this.empConfig.debug.showRsconfig=="object"?f(e,this.empConfig.debug.showRsconfig):e;console.log(a.link("[Compile Config]")),console.log(Ft.inspect(this.rsConfig,t))}}get browserslistOptions(){return{default:["chrome >= 87","edge >= 88","firefox >= 78","safari >= 14"],h5:["iOS >= 9","Android >= 4.4","last 2 versions","> 0.2%","not dead"],node:["node >= 20"]}}},o=new pe});import{exec as Mt}from"node:child_process";import{promisify as Rt}from"node:util";var Qe,qe,At,Bt,Ye,Ze=l(()=>{"use strict";b();u();Qe=Rt(Mt),qe=["Google Chrome Canary","Google Chrome Dev","Google Chrome Beta","Google Chrome","Microsoft Edge","Brave Browser","Vivaldi","Chromium"],At=async()=>{let r=process.env.BROWSER;if(!r||!qe.includes(r)){let{stdout:e}=await Qe("ps cax");r=qe.find(t=>e.includes(t))}return r},Bt=async r=>{if(process.platform==="darwin")try{let t=await At();if(t){let s=`osascript openChrome.applescript "${encodeURI(r)}" "${t}"`;return await Qe(s,{cwd:o.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}},Ye=Bt});import Gt from"net";import zt from"os";async function et(r,e="localhost"){if(r!==It&&(r<Ke||r>ae))throw new Error(`Port number must lie between ${Ke} and ${ae}`);let t=r,s=Ht(),i;e&&!s.has(e)?i=new Set([e]):i=s;let n=new Set(["EADDRINUSE","EACCES"]);for(;t<=ae;)try{return await Nt(t,i)}catch(p){if(!n.has(p.code))throw p;t+=1}throw new Error("No available ports found")}var Ke,ae,It,Ht,Ut,Nt,tt=l(()=>{"use strict";Ke=1024,ae=65535,It=443,Ht=()=>{let r=zt.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},Ut=(r,e)=>new Promise((t,s)=>{let i=Gt.createServer();i.unref(),i.on("error",s),i.listen(r,e,()=>{let{port:n}=i.address();i.close(()=>{t(n)})})}),Nt=async(r,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await Ut(r,s)}catch(i){if(!t.has(i.code))throw i}return r}});import st from"node:fs/promises";import G from"chalk";var C,z=l(()=>{"use strict";b();u();y();re();Ze();tt();oe();C=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=o.rsConfig.output?.publicPath==="auto"?"/":o.rsConfig.output?.publicPath||"/",this.sf.isOpenBrower=!!o.empConfig.server.open,this.sf.protocol=this.isHttps?"https":"http",this.sf.host=o.empConfig.server.host?o.empConfig.server.host:this.sf.host,this.sf.port=o.empConfig.server.port,await this.serverPort(),E.setup(this.sf),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,this.sf.urls.localUrlForTerminal=E.prettyPrintUrl("localhost")):(this.sf.urls=E.urls,this.sf.url=this.sf.urls.localUrlForBrowser)}startOpen(){let{urls:e}=this.sf;this.sf.publicHasHttp?(a.info(`${G.greenBright("\u279C")} Local: ${a.link(e.localUrlForTerminal)}`),a.info(`${G.greenBright("\u279C")} Network: ${a.link(this.sf.publicPath)}`)):(a.info(`${G.greenBright("\u279C")} Local: ${a.link(e.localUrlForTerminal)}`),a.info(`${G.greenBright("\u279C")} Network: ${a.link(e.lanUrlForTerminal)}
11
+ `)),this.sf.isOpenBrower&&Ye(this.sf.url)}async setup(e,t){await o.setup(e,t),o.empConfig.debug.clearLog&&Pe(),a.title(`${e}`),await this.adaptServer(),await this.run(),this.afterRun()}async run(){}afterRun(){process.on("SIGINT",function(){process.exit()})}get isHttps(){let{server:e,https:t}=o.empConfig.server||{};return e==="https"||typeof e=="object"&&e.type==="https"||t===!0}getcert(){return Promise.all([st.readFile(o.resource.key),st.readFile(o.resource.cert)])}async serverPort(){if(A.isADB)return;let{port:e,host:t}=this.sf,s=await et(e,t);s!==e&&(this.sf.port=s,o.rsConfig.devServer?.port&&(o.rsConfig.devServer.port=s))}}});import d from"chalk";import w from"node:path";import{gzipSizeSync as Jt}from"gzip-size";import _t from"node:fs";function Zt(r,e){let t=[r,e],s=["File","Size","Gzipped"].reduce((i,n,p)=>{let m=t[p],g=n;return m&&(g=n.length<m?n+" ".repeat(m-n.length):n),`${i+g} `}," ");console.log(d.bold.blue(s))}async function rt(r){let e=r.toJson({all:!1,assets:!0,timings:!0});$(e.time);let s=e.assets.filter(c=>qt(c.name)).map(Yt);s.sort((c,P)=>c.size-P.size);let i=Math.max(...s.map(c=>c.sizeLabel.length)),n=Math.max(...s.map(c=>(c.folder+w.sep+c.name).length));Zt(n,i);let p=0,m=0;s.forEach(c=>{let{sizeLabel:P}=c,{name:ft,folder:ut,gzipSizeLabel:gt}=c,ge=(ut+w.sep+ft).length,de=P.length;if(p+=c.size,m+=c.gzippedSize,de<i){let N=" ".repeat(i-de);P+=N}let ye=d.gray(c.folder+w.sep)+Kt(c.name);if(ge<n){let N=" ".repeat(n-ge);ye+=N}a.info(` ${ye} ${d.gray(P)} ${gt}`)});let g=`${d.bold.blue("Total size:")} ${I(p)}`,O=`${d.bold.blue("Gzipped size:")} ${I(m)}`;a.info(`
12
+ ${g}
13
+ ${O}
14
+ `)}function $(r=0){a.info(`${d.greenBright("\u2713")} Ready in ${ke(Number(r))}`)}var Vt,Wt,Xt,qt,Qt,Yt,I,Kt,H=l(()=>{"use strict";u();b();y();Vt=/\.html$/,Wt=/\.(?:js|mjs|cjs|jsx)$/,Xt=/\.css$/,qt=r=>!/\.map$/.test(r)&&!/\.LICENSE\.txt$/.test(r),Qt=r=>r>300*1e3?d.red:r>100*1e3?d.yellow:d.white,Yt=r=>{let e=r.name.split("?")[0],t=I(r.size),s=w.basename(e),i=w.join(w.basename(o.empConfig.build.outDir),w.dirname(e)),n=_t.readFileSync(w.join(o.empConfig.build.outDir,e)),p=n.length,m=Jt(n),g=Qt(m)(I(m));return{size:p,folder:i,name:s,gzippedSize:m,sizeLabel:t,gzipSizeLabel:g}};I=r=>{let e=r/1e3;return`${e.toFixed(e<1?2:1)} kB`},Kt=r=>Wt.test(r)?d.yellowBright(r):Xt.test(r)?d.greenBright(r):Vt.test(r)?d.blueBright(r):d.magenta(r)});var it={};J(it,{default:()=>ss});import{rspack as es}from"@rspack/core";import{RspackDevServer as ts}from"@rspack/dev-server";var le,ss,ot=l(()=>{"use strict";u();z();b();y();H();le=class extends C{get rspackDevConfig(){return f(o.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}})}async devServerConfig(){let e=Object.assign({},o.rsConfig.devServer);if(this.isHttps&&(e.https===!0&&delete e.https,!e.server)){let[t,s]=await this.getcert();e.server={type:"https",options:{key:t,cert:s}}}return e}async run(){let e=es(this.rspackDevConfig);if(!o.rsConfig.devServer){a.error("devServer is not defined in config");return}let t=await this.devServerConfig(),s=new ts(t,e);this.startOpen(),o.empConfig.lifeCycle.beforeDevServe&&await o.empConfig.lifeCycle.beforeDevServe(),await s.start();let i=n=>{let p=n?.toJson({all:!1,colors:!1,assets:!1,chunks:!1,timings:!0});$(p.time)};o.empConfig.debug.showPerformance&&e.hooks.afterDone.tap("done",i),s.middleware?.waitUntilValid(n=>{o.empConfig.debug.showPerformance||i(n),o.empConfig.lifeCycle.afterDevServe&&o.empConfig.lifeCycle.afterDevServe()})}},ss=new le});var nt={};J(nt,{default:()=>is});import{rspack as rs}from"@rspack/core";var ce,is,pt=l(()=>{"use strict";b();u();z();H();ce=class extends C{async run(){o.empConfig.lifeCycle.beforeBuild&&await o.empConfig.lifeCycle.beforeBuild(),rs(o.rsConfig,async(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}))),await rt(t),o.empConfig.lifeCycle.afterBulid&&await o.empConfig.lifeCycle.afterBulid()})}},is=new ce});import os from"express";import ns from"cors";import ps from"compression";import as from"https";var U,at=l(()=>{"use strict";z();U=class extends C{app;async init(){let e=os();e.use(ps()),e.use(ns()),this.app=e}async server(){if(this.isHttps){let[e,t]=await this.getcert();as.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 lt={};J(lt,{default:()=>fs});import ls from"express";import cs from"path";import ms from"node:fs/promises";import hs from"node:fs";var me,fs,ct=l(()=>{"use strict";at();u();b();H();me=class extends U{timing=0;async run(){if(this.timing=Date.now(),!hs.existsSync(o.outDir))return a.sysError(`emp serve must be executed after emp build,${o.outDir} not exist!`);o.empConfig.lifeCycle.beforeServe&&await o.empConfig.lifeCycle.beforeServe(),this.start()}async middleware(){let e=o.resolve(o.rsConfig.output?.path);this.app.use(ls.static(e));let t=await ms.readFile(cs.join(e,"index.html"),"utf8");this.app.get("*",(s,i)=>i.send(t))}async onReady(){$(Date.now()-this.timing),o.empConfig.lifeCycle.afterServe&&await o.empConfig.lifeCycle.afterServe()}},fs=new me});u();u();y();b();import{program as S}from"commander";import he,{exit as us}from"node:process";function mt(){let r="20.0.0";L(r,he.versions.node)===1&&(a.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${he.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${r}`),us(0)),S.version(o.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(()=>(ot(),it));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(()=>(pt(),nt));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(()=>(ct(),lt));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(he.argv)}u();import gs from"fast-glob";import ht from"node:fs/promises";import fe from"node:path";var ds=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,ys=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,bs=/import\(['"]([^;\n]+?)['"]\)/,ue=class{list=[];outDir=o.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 gs([`${o.empConfig.build.outDir}/**/*.d.ts`]);let e=[];this.list.map(s=>{s=o.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 ht.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(ds,i=>{let n=i.match(ys);if(n||(n=i.match(bs)),n&&n[1]){let p=n[1];if(!p.startsWith("."))return i;let m=fe.resolve(fe.dirname(e),p).replace(this.outDir,this.aliasName);return i.replace(n[1],m)}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
15
  ${t}}\r
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};
16
+ `}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await ht.writeFile(fe.join(this.outDir.replace("dist","types"),"type.d.ts"),t)}},vs=new ue;function Zi(r){return r}export{Zi as defineConfig,vs as dts,mt as runScript,o as store};
@@ -1,11 +1,26 @@
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
+ 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>;
22
+ afterRun(): void;
9
23
  get isHttps(): boolean;
10
24
  getcert(): Promise<[Buffer, Buffer]>;
25
+ serverPort(): Promise<void>;
11
26
  }
@@ -1,5 +1,8 @@
1
+ import { RspackOptions } from '@rspack/core';
1
2
  import { BaseScript } from '../script/base';
2
3
  declare class DevScript extends BaseScript {
4
+ get rspackDevConfig(): RspackOptions;
5
+ devServerConfig(): Promise<import("@rspack/core").DevServer>;
3
6
  run(): Promise<void>;
4
7
  }
5
8
  declare const _default: DevScript;
@@ -1,7 +0,0 @@
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,8 @@
1
+ declare class AutoDevBase {
2
+ isADB: boolean;
3
+ isHttps: boolean;
4
+ get isHttpBase(): boolean;
5
+ setup(): void;
6
+ }
7
+ declare const _default: AutoDevBase;
8
+ export default _default;
@@ -1,7 +1,8 @@
1
1
  import { GlobalStore } from '../store';
2
- import { BuildType, DebugType, HtmlType, ReactType, ServerType } from '../types/config';
2
+ import { BuildType, DebugType, EMPShareType, HtmlType, RsTarget, ServerType } from '../types/config';
3
3
  import { Output } from '@rspack/core';
4
4
  import { EMPShareLib } from '../store/empShareLib';
5
+ import { LifeCycle } from '../store/lifeCycle';
5
6
  export declare class EmpConfig {
6
7
  private store;
7
8
  /**
@@ -22,8 +23,17 @@ export declare class EmpConfig {
22
23
  * @default undefined
23
24
  */
24
25
  base: string;
26
+ target: RsTarget;
25
27
  private assign;
26
28
  empShareLib: EMPShareLib;
29
+ /**
30
+ * 是否启动 esm 模块
31
+ * @default true
32
+ */
33
+ isESM: boolean;
34
+ autoDevSet(): Promise<void>;
35
+ checkIsESM(target: string): boolean;
36
+ lifeCycle: LifeCycle;
27
37
  setup(store: GlobalStore): Promise<void>;
28
38
  chain(): Promise<void>;
29
39
  plugins(): Promise<void>;
@@ -31,13 +41,8 @@ export declare class EmpConfig {
31
41
  get build(): Required<BuildType>;
32
42
  get html(): HtmlType;
33
43
  get entries(): import("../types/config").EntriesType;
34
- get react(): Required<ReactType>;
35
44
  get server(): ServerType;
36
- get empShare(): {
37
- name: string;
38
- filename: string;
39
- shared: {};
40
- };
45
+ get empShare(): EMPShareType;
41
46
  get css(): {
42
47
  postcss: never[];
43
48
  };
@@ -51,7 +56,6 @@ export declare class EmpConfig {
51
56
  syncEmpOptions(): Promise<void>;
52
57
  get moduleTransformRule(): any;
53
58
  get cacheDir(): string;
54
- get reactRuntime(): "automatic" | "classic" | undefined;
55
59
  }
56
60
  declare const _default: EmpConfig;
57
61
  export default _default;
@@ -1,14 +1,31 @@
1
1
  import { Configuration } from '@rspack/core';
2
2
  import type { EMPShareType } from '../types/config';
3
+ import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
3
4
  export type externalAssetsType = {
4
5
  js: string[];
5
6
  css: string[];
6
7
  };
8
+ export type ModuleFederationPluginOptions = ConstructorParameters<typeof ModuleFederationPlugin>[0];
9
+ export type ImportMapType = {
10
+ imports: {
11
+ [key: string]: any;
12
+ };
13
+ };
7
14
  export declare class EMPShareLib {
8
15
  externals: Configuration['externals'] | any;
9
16
  externalAssets: externalAssetsType;
10
17
  private exp;
11
- setup(empShare: EMPShareType): Promise<void>;
12
- setShareLib(mf: EMPShareType): Promise<void>;
18
+ config: EMPShareType;
19
+ importMap: ImportMapType;
20
+ version: EMPShareType['mfVersion'];
21
+ isEmpshare: boolean;
22
+ setup(): Promise<void>;
23
+ /**
24
+ * 是否取用 importMap
25
+ */
26
+ get useImportMap(): boolean | undefined;
27
+ get pluginConfig(): ModuleFederationPluginOptions;
28
+ prepareEsm(): void;
29
+ setShareLib(): Promise<void>;
13
30
  private setExternalAssets;
14
31
  }
@@ -3,6 +3,7 @@ import WPChain from 'webpack-chain';
3
3
  import type { Configuration as RsConfig, RspackOptions } from '@rspack/core';
4
4
  import type { EmpOptions } from '../types/config';
5
5
  import { EmpConfig } from '../store/empConfig';
6
+ import { deepAssign } from '../helper/utils';
6
7
  export declare class GlobalStore {
7
8
  /**
8
9
  * EMP Version
@@ -67,7 +68,6 @@ export declare class GlobalStore {
67
68
  mode: EMPModeType;
68
69
  cliMode: 'dev' | 'prod';
69
70
  isDev: boolean;
70
- reactVersion: undefined;
71
71
  /**
72
72
  * 项目配置
73
73
  */
@@ -76,6 +76,9 @@ export declare class GlobalStore {
76
76
  rsConfig: RsConfig;
77
77
  empOptions: EmpOptions;
78
78
  empConfig: EmpConfig;
79
+ vCompare: (preVersion?: string, lastVersion?: string) => number;
80
+ deepAssign: typeof deepAssign;
81
+ getLanIp: () => string;
79
82
  setup(mode: string, cliOptions: any): Promise<void>;
80
83
  /**
81
84
  * 初始化 基础变量
@@ -108,6 +111,11 @@ export declare class GlobalStore {
108
111
  * 打印 config
109
112
  */
110
113
  logConfig(): void;
114
+ get browserslistOptions(): {
115
+ default: string[];
116
+ h5: string[];
117
+ node: string[];
118
+ };
111
119
  }
112
120
  declare const _default: GlobalStore;
113
121
  export default _default;
@@ -1,6 +1,14 @@
1
- import { GlobalStore } from '../store';
2
- declare class LifeCycle {
3
- afterChain(store: GlobalStore): Promise<void>;
1
+ export type LifeCycleType = Partial<LifeCycle>;
2
+ export declare class LifeCycle {
3
+ op: LifeCycleType;
4
+ constructor(op?: LifeCycleType);
5
+ afterGetEmpOptions(): Promise<void>;
6
+ beforePlugin(): Promise<void>;
7
+ afterPlugin(): Promise<void>;
8
+ beforeBuild(): Promise<void>;
9
+ afterBulid(): Promise<void>;
10
+ beforeDevServe(): Promise<void>;
11
+ afterDevServe(): Promise<void>;
12
+ beforeServe(): Promise<void>;
13
+ afterServe(): Promise<void>;
4
14
  }
5
- declare const _default: LifeCycle;
6
- export default _default;
@@ -5,14 +5,6 @@ declare class RspackCss {
5
5
  sass(): Promise<void>;
6
6
  less(): Promise<void>;
7
7
  css(): Promise<void>;
8
- get postcss(): {
9
- loader: string;
10
- options: {
11
- postcssOptions: {
12
- plugins: never[];
13
- };
14
- };
15
- };
16
8
  }
17
9
  declare const _default: RspackCss;
18
10
  export default _default;
@@ -0,0 +1,22 @@
1
+ import { HtmlType } from '../../types/config';
2
+ import { EMPShareLib } from '../empShareLib';
3
+ import { type Compiler } from '@rspack/core';
4
+ export declare const HtmlImportMapPluginName = "HtmlImportMapPlugin";
5
+ export declare class HtmlImportMapPlugin {
6
+ importMap: EMPShareLib['importMap'];
7
+ constructor(importMap: EMPShareLib['importMap']);
8
+ apply(compiler: any): void;
9
+ }
10
+ export declare const HtmlEmpShareLibPluginName = "HtmlEmpShareLibPlugin";
11
+ export declare class HtmlEmpShareLibPlugin {
12
+ files: {
13
+ css: string[];
14
+ js: string[];
15
+ };
16
+ constructor(files: HtmlType['files']);
17
+ apply(compiler: any): void;
18
+ }
19
+ export declare class EmpPolyfillPlugin {
20
+ constructor();
21
+ apply(compiler: Compiler): void;
22
+ }
@@ -1,9 +1,19 @@
1
1
  import type { GlobalStore } from '../../store';
2
2
  declare class RspackModule {
3
3
  store: GlobalStore;
4
+ private swcJsOptions;
5
+ private swcTsOptions;
6
+ private coreJs;
4
7
  setup(store: GlobalStore): Promise<void>;
8
+ private rspackGenerator;
9
+ private rspackParser;
10
+ private get isPolyfill();
11
+ private swcParser;
12
+ private swcJsc;
13
+ private get swcCoreVersion();
14
+ private swcOptions;
15
+ swcInitOptions(): void;
5
16
  scripts(): Promise<void>;
6
- react(): Promise<void>;
7
17
  files(): Promise<void>;
8
18
  }
9
19
  declare const _default: RspackModule;
@@ -7,8 +7,7 @@ declare class RspackPlugin {
7
7
  copy(): Promise<void>;
8
8
  progress(): Promise<void>;
9
9
  empShare(): Promise<void>;
10
- minJs(): void;
11
- minCss(): void;
10
+ minify(): void;
12
11
  }
13
12
  declare const _default: RspackPlugin;
14
13
  export default _default;
@@ -1,13 +1,26 @@
1
+ /// <reference types="node" />
2
+ import type { Configuration as RsConfig } from '@rspack/core';
1
3
  import { Configuration as devServerConfig } from '@rspack/dev-server';
2
4
  import Chain from 'webpack-chain';
3
- import { Externals, HtmlRspackPluginOptions, ModuleFederationPluginOptions, Output, Resolve, RuleSetRule, SwcJsMinimizerRspackPluginOptions } from '@rspack/core';
5
+ import { Externals, HtmlRspackPluginOptions, Output, Resolve, RuleSetRule, SwcJsMinimizerRspackPluginOptions } from '@rspack/core';
4
6
  import { EMP3PluginType } from './plugin';
7
+ import { InspectOptions } from 'node:util';
8
+ import type { LifeCycle } from '../store/lifeCycle';
9
+ import type { ModuleFederationPluginOptions } from '../store/empShareLib';
5
10
  export type LoggerType = 'debug' | 'info' | 'warn' | 'error';
6
11
  export type DebugType = {
7
12
  loggerLevel: LoggerType;
8
13
  clearLog: boolean;
9
14
  progress: boolean;
10
- showRsconfig: boolean;
15
+ showRsconfig: boolean | string | InspectOptions;
16
+ showPerformance: boolean;
17
+ rspackCache: boolean;
18
+ newTreeshaking: boolean;
19
+ /**
20
+ * 是否显示执行日志
21
+ * @default false
22
+ */
23
+ infrastructureLogging: RsConfig['infrastructureLogging'];
11
24
  };
12
25
  export type ServerType = devServerConfig & {
13
26
  /**
@@ -52,6 +65,11 @@ export type BuildType = {
52
65
  * @default 'public'
53
66
  */
54
67
  publicDir?: string;
68
+ /**
69
+ * named 使用有意义、方便调试的内容当作模块 id。此选项会在开发环境下默认开启。
70
+ * deterministic 使用对模块标识符哈希后的数字当作模块 id,有益于长期缓存。此选项会在生产环境下默认开启。
71
+ */
72
+ moduleIds?: 'named' | 'deterministic';
55
73
  /**
56
74
  * chunkIds
57
75
  * @default named|deterministic
@@ -72,7 +90,32 @@ export type BuildType = {
72
90
  * @default {}
73
91
  */
74
92
  minOptions?: SwcJsMinimizerRspackPluginOptions;
93
+ /**
94
+ * 生成代码 参考 https://swc.rs/docs/configuring-swc#jsctarget
95
+ */
96
+ target?: JscTarget;
97
+ /**
98
+ * 注入兼容代码
99
+ * module federation 入口 建议使用 entry
100
+ * @default false
101
+ */
102
+ polyfill?: 'entry' | 'usage' | false;
103
+ /**
104
+ * 选择core-js的兼容版本有助于切换适当的代码体积
105
+ * @default stable
106
+ */
107
+ coreJsFeatures?: 'full' | 'actual' | 'stable' | 'es';
108
+ /**
109
+ * @swc/helpers 外置
110
+ * @default false
111
+ */
112
+ externalHelpers: boolean;
113
+ /**
114
+ * 浏览器 兼容版本
115
+ */
116
+ browserslist: string[];
75
117
  };
118
+ export type JscTarget = 'es3' | 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022';
76
119
  export interface HtmlType extends HtmlRspackPluginOptions {
77
120
  /**
78
121
  * 基于项目的根目录 index.html url
@@ -112,22 +155,17 @@ export interface HtmlType extends HtmlRspackPluginOptions {
112
155
  export type EntriesType = {
113
156
  [entryFilename: string]: HtmlType;
114
157
  };
115
- export type ReactType = {
116
- /**
117
- * 是否启动 热更 默认为 true
118
- */
119
- hmr: boolean;
120
- /**
121
- * 是否启动 Svg React Component 默认为 false
122
- */
123
- svgr: boolean;
124
- };
125
158
  export type CSSOptions = {
126
159
  postcss?: [string, any][];
127
160
  };
128
161
  export interface ModuleTransform {
129
162
  exclude?: RuleSetRule['exclude'][];
130
163
  include?: RuleSetRule['include'][];
164
+ /**
165
+ * 默认exclude /(node_modules|bower_components)/
166
+ * @default false
167
+ */
168
+ defaultExclude?: boolean;
131
169
  }
132
170
  export type EMPShareType = ModuleFederationPluginOptions & {
133
171
  /**
@@ -135,9 +173,15 @@ export type EMPShareType = ModuleFederationPluginOptions & {
135
173
  */
136
174
  shareLib?: EMPshareLibItemType;
137
175
  /**
176
+ * TODO
138
177
  * 是否使用 importMap
139
178
  */
140
179
  useImportMap?: boolean;
180
+ /**
181
+ * module federation 版本
182
+ * @default 1
183
+ */
184
+ mfVersion?: 1 | 1.5;
141
185
  };
142
186
  export type EMPshareLibItemType = {
143
187
  [module: string]: {
@@ -172,6 +216,7 @@ export type ExternalsItemType = {
172
216
  */
173
217
  type?: string;
174
218
  };
219
+ export type RsTarget = RsConfig['target'];
175
220
  export type EmpOptions = {
176
221
  /**
177
222
  * publicPath 根路径 可参考webpack,业务模式默认为 auto
@@ -180,6 +225,14 @@ export type EmpOptions = {
180
225
  * @default undefined
181
226
  */
182
227
  base?: string;
228
+ /**
229
+ * 构建target
230
+ */
231
+ target?: RsConfig['target'];
232
+ /**
233
+ * 启动后 自动设置 base 为当前 Ip+port的路径如 base = http://127.0.0.1:8080/ 并且固定 ws 方便代理调试
234
+ */
235
+ autoDevBase?: boolean;
183
236
  /**
184
237
  * 项目代码路径
185
238
  * @default 'src'
@@ -198,7 +251,6 @@ export type EmpOptions = {
198
251
  server?: ServerType;
199
252
  debug?: DebugType;
200
253
  chain?: (chain: Chain) => void;
201
- react?: ReactType;
202
254
  empShare?: EMPShareType;
203
255
  /**
204
256
  * css 相关设置
@@ -240,10 +292,7 @@ export type EmpOptions = {
240
292
  */
241
293
  output?: Output;
242
294
  /**
243
- * React Runtime 手动切换jsx模式
244
- * 当 external react时需要设置
245
- * 本地安装时会自动判断 不需要设置
246
- * @default undefined
295
+ * emp 执行周期
247
296
  */
248
- reactRuntime?: 'automatic' | 'classic';
297
+ lifeCycle?: LifeCycle;
249
298
  };
package/package.json CHANGED
@@ -1,116 +1,111 @@
1
1
  {
2
- "name": "@empjs/cli",
3
- "version": "3.0.0-beta.9",
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
- }
2
+ "name": "@empjs/cli",
3
+ "version": "3.0.0-rc.1",
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
+ "rspack",
29
+ "rust",
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": "^11.0.4",
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
+ "@types/node": "^20.8.7",
79
+ "cross-env": "^7.0.3",
80
+ "esbuild": "^0.19.5",
81
+ "rimraf": "^5.0.5",
82
+ "tsc-alias": "^1.8.8"
83
+ },
84
+ "dependencies": {
85
+ "@module-federation/enhanced": "^0.1.4",
86
+ "@rspack/core": "0.6.1",
87
+ "@rspack/dev-server": "0.6.1",
88
+ "@swc/helpers": "^0.5.9",
89
+ "address": "^2.0.1",
90
+ "ansi-html-community": "^0.0.8",
91
+ "chalk": "^5.3.0",
92
+ "commander": "^11.1.0",
93
+ "compression": "^1.7.4",
94
+ "core-js": "^3.36.1",
95
+ "cors": "^2.8.5",
96
+ "default-gateway": "^7.2.2",
97
+ "express": "^4.18.2",
98
+ "fast-glob": "^3.3.1",
99
+ "fs-extra": "^11.2.0",
100
+ "gzip-size": "^7.0.0",
101
+ "html-entities": "^2.5.2",
102
+ "html-webpack-plugin": "^5.6.0",
103
+ "less-loader": "^12.2.0",
104
+ "open": "^10.1.0",
105
+ "sass-loader": "^14.2.0",
106
+ "strip-ansi": "^7.1.0",
107
+ "typescript-plugin-css-modules": "^5.1.0",
108
+ "webpack-bundle-analyzer": "^4.10.2",
109
+ "webpack-chain": "^6.5.1"
110
+ }
116
111
  }
@@ -1,20 +1,14 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="<%= htmlWebpackPlugin.options.lang %>">
3
- <head>
4
- <!-- EMP inject title -->
5
- <title><%= htmlWebpackPlugin.options.title %></title>
6
- <meta name="keywords" content="<%= htmlWebpackPlugin.options.keywords %>" />
7
- <meta name="description" content="<%= htmlWebpackPlugin.options.description %>" />
8
- <!-- EMP inject css -->
9
- <% for (let i in htmlWebpackPlugin.options.files.css) { %>
10
- <link rel="stylesheet" href="<%= htmlWebpackPlugin.options.files.css[i] %>" />
11
- <% } %>
12
- </head>
13
- <body>
14
- <div id="emp-root"></div>
15
- <!-- EMP inject js -->
16
- <% for (let i in htmlWebpackPlugin.options.files.js) { %>
17
- <script src="<%= htmlWebpackPlugin.options.files.js[i] %>"></script>
18
- <% } %>
19
- </body>
20
- </html>
3
+
4
+ <head>
5
+ <title>
6
+ <%= htmlWebpackPlugin.options.title %>
7
+ </title>
8
+ </head>
9
+
10
+ <body>
11
+ <div id="emp-root"></div>
12
+ </body>
13
+
14
+ </html>
@@ -1,6 +0,0 @@
1
- export declare function prepareUrls(protocol: any, host: string, port: number, pathname?: string): {
2
- lanUrlForConfig: string | undefined;
3
- lanUrlForTerminal: string;
4
- localUrlForTerminal: string;
5
- localUrlForBrowser: string;
6
- };
@@ -1,12 +0,0 @@
1
- declare class RuntimePlugins {
2
- constructor();
3
- beforeInit(): void;
4
- beforeLoadingRemote(): void;
5
- loadRemoteMatch(): void;
6
- loadRemote(): void;
7
- errorLoadRemote(): void;
8
- beforeLoadShare(): void;
9
- beforePreloadRemote(): void;
10
- }
11
- declare const _default: RuntimePlugins;
12
- export default _default;
@@ -1,6 +0,0 @@
1
- import { GlobalStore } from '../../store';
2
- declare class Script {
3
- js(store: GlobalStore): void;
4
- }
5
- declare const _default: Script;
6
- export default _default;