@empjs/cli 3.0.0-alpha.38 → 3.0.0-beta.2
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.
|
@@ -3,5 +3,5 @@ export declare const __filename: string;
|
|
|
3
3
|
export declare const __dirname: string;
|
|
4
4
|
export declare const getFileJson: (url: string) => Promise<any>;
|
|
5
5
|
export declare const require: NodeRequire;
|
|
6
|
-
export declare const importResolve:
|
|
6
|
+
export declare const importResolve: (scope: string, importMetaUrl?: string) => string;
|
|
7
7
|
export declare const empRoot: string;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Le=Object.defineProperty;var c=(i,e)=>()=>(i&&(e=i(i=0)),e);var $=(i,e)=>{for(var t in e)Le(i,t,{get:e[t],enumerable:!0})};import{fileURLToPath as Ae}from"node:url";import{dirname as Fe}from"node:path";import{readFile as Me}from"node:fs/promises";import X from"node:module";import R from"node:path";var Y,Ne,T,Ge,Z,K,ee=c(()=>{"use strict";Y=Ae(import.meta.url),Ne=Fe(Y),T=async i=>{try{let e=await Me(i);return JSON.parse(e)}catch(e){console.error(e)}},Ge=X.createRequire(import.meta.url),Z=(i,e)=>{let t=Ge;return e&&(t=X.createRequire(e)),t.resolve(i)},K=R.resolve(Ne,Y).replace(`${R.sep}dist${R.sep}index.js`,"")});import w from"@rspack/core";import te from"fs";var D,se,re=c(()=>{"use strict";D=class{store;async setup(e){this.store=e;let t=[this.define(),this.anylayze(),this.progress(),this.copy(),this.empShare(),this.minJs(),this.minCss()];await Promise.all(t)}async anylayze(){if(!this.store.cliOptions.analyze)return;let{default:{BundleAnalyzerPlugin:e}}=await import("webpack-bundle-analyzer");this.store.chain.plugin("bundleAnalyzerPlugin").use(e,[{}])}async define(){this.store.chain.plugin("definePlugin").use(w.DefinePlugin,[this.store.empConfig.define])}async copy(){let e=this.store.resolve("public");te.existsSync(e)&&te.readdirSync(e).length>0&&this.store.chain.plugin("copyRspackPlugin").use(w.CopyRspackPlugin,[{patterns:[{from:e,to:this.store.resolve("dist")}]}])}async progress(){this.store.empConfig.debug.progress&&this.store.chain.plugin("progressPlugin").use(w.ProgressPlugin,[{prefix:"EMP"}])}async empShare(){if(!this.store.empConfig.empShare.name)return;let{ModuleFederationPlugin:e}=w.container;this.store.chain.plugin("empShare").use(e,[{...this.store.empConfig.empShare}])}minJs(){this.store.mode==="production"&&this.store.chain.plugin("minJs").use(w.SwcJsMinimizerRspackPlugin,[this.store.empConfig.build.minOptions])}minCss(){this.store.mode==="production"&&this.store.chain.plugin("minJs").use(w.SwcJsMinimizerRspackPlugin,[{}])}},se=new D});var L,oe,ie=c(()=>{"use strict";L=class{store;async setup(e){this.store=e;let t=[this.react(),this.files(),this.scripts()];await Promise.all(t)}async scripts(){let{isDev:e}=this.store,t=this.store.reactVersion?{react:{runtime:this.store.empConfig.reactRuntime,development:e,refresh:e}}:{};this.store.chain.merge({module:{parser:{javascript:{exportsPresence:"error",importExportsPresence:"error"}},rule:{mjs:{test:/\.m?js/,resolve:{fullySpecified:!1}},typescript:{test:/\.(ts|tsx)$/,sideEffects:!1,use:[{loader:"builtin:swc-loader",options:{jsc:{parser:{syntax:"typescript",decorators:!0,tsx:!0,dynamicImport:!0},transform:t}}}]},javascript:{test:/\.(js|jsx)$/,sideEffects:!1,use:[{loader:"builtin:swc-loader",options:{jsc:{parser:{syntax:"ecmascript",jsx:!0,decorators:!0,decoratorsBeforeExport:!1},transform:t}}}]}}}})}async react(){if(this.store.reactVersion&&(this.store.empConfig.react.svgr&&this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,issuer:/\.[jt]sx?$/,resourceQuery:/svgr/,use:[{loader:this.store.importResolve("@svgr/webpack"),options:{}}]}}}}),this.store.isDev&&this.store.empConfig.react.hmr)){let{default:e}=await import("@rspack/plugin-react-refresh"),t={};this.store.empConfig.empShare.name&&(t.library=this.store.empConfig.empShare.name),this.store.chain.plugin("plugin-react-refresh").use(e,[t])}}async files(){(!this.store.reactVersion||!this.store.empConfig.react.svgr)&&this.store.chain.merge({module:{rule:{svg:{test:/\.svg$/,type:"asset/resource"}}}}),this.store.chain.merge({module:{rule:{inline:{resourceQuery:/inline/,type:"asset/inline"}}}}),this.store.chain.merge({module:{rule:{image:{test:/\.(png|jpe?g|gif|webp|ico)$/i,type:"asset/resource"},fonts:{test:/\.(|otf|ttf|eot|woff|woff2)$/i,type:"asset/resource"},svga:{test:/\.(svga)$/i,type:"asset/resource"}}}})}},oe=new L});var A,ne,pe=c(()=>{"use strict";A=class{store;async setup(e){this.store=e;let t=[this.common(),this.stats(),this.devServer(),this.optimization()];await Promise.all(t)}async common(){this.store.merge({experiments:{rspackFuture:{}},mode:this.store.mode,cache:!1,devtool:this.store.empConfig.build.sourcemap?"source-map":!1,builtins:{css:{modules:{localIdentName:this.store.isDev?"[path][name]-[local]-[hash:5]":"[local]-[hash:5]"}}},output:this.store.empConfig.output,resolve:this.store.empConfig.resolve,externals:this.store.empConfig.externals})}async stats(){this.store.merge({stats:{colors:!0,all:!1,assets:!1,chunks:!1,timings:!0,version:!0}})}async devServer(){this.store.merge({devServer:this.store.empConfig.server})}async optimization(){this.store.chain.merge({optimization:{chunkIds:this.store.empConfig.build.chunkIds,minimize:this.store.empConfig.build.minify}})}},ne=new A});function ae(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}function S(i,...e){for(let t of e)for(let s in t){let r=t[s],o=i[s];if(Object(r)==r&&Object(o)===o){i[s]=S(o,r);continue}i[s]=t[s]}return i}var O,E=c(()=>{"use strict";O=(i="",e="")=>{let t=i.replace("^","").split("."),s=e.replace("^","").split("."),r=Math.max(t.length,s.length),o=0;for(let n=0;n<r;n++){let m=t.length>n?t[n]:0,l=isNaN(Number(m))?m.charCodeAt():Number(m),u=s.length>n?s[n]:0,f=isNaN(Number(u))?u.charCodeAt():Number(u);if(l<f){o=-1;break}else if(l>f){o=1;break}}return o}});import Ie from"html-webpack-plugin";import He from"fast-glob";import y from"node:path";var F,le,ce=c(()=>{"use strict";E();F=class{store;entriesConfig={};async setup(e){this.store=e,await this.init(),this.toConfig()}setHtmlConfig(e,t){return e.template=this.setTemplate(e.template),e.favicon=this.setFavicion(e.favicon),e.chunks=t,e.filename=`${t[0]}.html`,this.store.empConfig.base&&(e.publicPath=this.store.empConfig.base),this.store.empConfig.empShareLib&&(e.files=S(e.files,this.store.empConfig.empShareLib.externalAssets)),e}setChunk(e){return e.replace(y.extname(e),"").replace(`${this.store.empConfig.appSrc}${y.sep}`,"")}setTemplate(e){return e?this.store.resolve(e):this.store.empResolve(y.join("template","index.html"))}setFavicion(e){return e?this.store.resolve(e):this.store.empResolve(y.join("template","favicon.ico"))}setEntryItem(e,t,s){s=s||this.store.resolve(y.join(this.store.empConfig.appSrc,e));let r=this.setChunk(e);this.entriesConfig[r]={entry:{[r]:s},html:this.setHtmlConfig(t,[r])}}setRspackHtmlPlugin(e,t){this.store.chain.plugin(`html-plugin-${t}`).use(Ie,[e])}setRspackEntry(e){this.store.merge({entry:e})}async init(){let e=y.join(this.store.appSrc,this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index.{ts,tsx,jsx,js}").replace(/\\/g,"/"),t=await He([e]);if(t[0]){let s=y.join(this.store.empConfig.appSrc,Object.keys(this.store.empConfig.entries).length>0&&this.store.empConfig.appEntry?this.store.empConfig.appEntry:"index");this.setEntryItem(s,this.store.empConfig.html,t[0])}if(Object.keys(this.store.empConfig.entries).length>0)for(let[s,r]of Object.entries(this.store.empConfig.entries))this.setEntryItem(s,{...this.store.empConfig.html,...r})}toConfig(){for(let[e,t]of Object.entries(this.entriesConfig))this.setRspackHtmlPlugin(t.html,e),this.setRspackEntry(t.entry)}},le=new F});var M,me,he=c(()=>{"use strict";M=class{store;async setup(e){this.store=e;let t=[this.sass(),this.less(),this.css()];await Promise.all(t)}async sass(){let e={loader:this.store.importResolve("sass-loader"),options:{}};this.store.chain.merge({module:{rule:{sass:{test:/\.(sass|scss)$/,use:[this.postcss,e],type:"css/auto"}}}})}async less(){let e={loader:this.store.importResolve("less-loader"),options:{lessOptions:{javascriptEnabled:!0}}};this.store.chain.merge({module:{rule:{less:{test:/\.less$/,use:[this.postcss,e],type:"css/auto"}}}})}async css(){this.store.chain.merge({module:{rule:{css:{test:/\.css$/,use:[this.postcss],type:"css/auto"}}}})}get postcss(){return{loader:this.store.importResolve("postcss-loader"),options:{postcssOptions:{plugins:this.store.empConfig.css.postcss}}}}},me=new M});var N,ue,fe=c(()=>{"use strict";re();ie();pe();ce();he();N=class{store;async setup(e){this.store=e;let t=[ne.setup(this.store),oe.setup(this.store),se.setup(this.store),le.setup(this.store),me.setup(this.store)];await Promise.all(t),await this.store.empConfig.plugins(),await this.store.empConfig.chain()}},ue=new N});import h from"chalk";import{table as Je}from"table";var G,a,b=c(()=>{"use strict";G=class{pname="";logLevel="debug";setup({pname:e,logLevel:t}){this.pname=e,t&&(this.logLevel=t)}debug=(...e)=>["debug"].includes(this.logLevel)&&console.log(...e);info=(...e)=>["debug","info"].includes(this.logLevel)&&console.log(...e);warn=(...e)=>["debug","info","warn"].includes(this.logLevel)&&console.warn(...e);error=(...e)=>["debug","info","warn","error"].includes(this.logLevel)&&console.error(...e);blue=e=>{console.log(`${h.white.bgBlue(this.pname)}${h.blue.bgWhite(` ${e} `)}
|
|
2
2
|
`)};cyan=e=>{console.log(`${h.white.bgCyan(this.pname)}${h.cyan.bgWhite(` ${e} `)}
|
|
3
3
|
`)};magenta=e=>{console.log(`${h.white.bgMagenta(this.pname)}${h.magenta.bgWhite(` ${e} `)}
|
|
4
4
|
`)};green=e=>{console.log(`${h.white.bgGreen(this.pname)}${h.green.bgWhite(` ${e} `)}
|
|
5
5
|
`)};yellow=e=>{console.log(`${h.white.bgYellow(this.pname)}${h.yellow.bgWhite(` ${e} `)}
|
|
6
6
|
`)};red=e=>{console.log(`${h.white.bgRed(this.pname)}${h.red.bgWhite(` ${e} `)}
|
|
7
7
|
`)};sysError=e=>{console.log(`${h.white.bgRed(" System Error Tips ")}${h.red.bgWhite(` ${e} `)}
|
|
8
|
-
`)};link=e=>h.hex("#3498db")(e);tableData=[];tableConfig={border:{topBody:"\u2500",topJoin:"\u252C",topLeft:"\u250C",topRight:"\u2510",bottomBody:"\u2500",bottomJoin:"\u2534",bottomLeft:"\u2514",bottomRight:"\u2518",bodyLeft:"\u2502",bodyRight:"\u2502",bodyJoin:"\u2502",joinBody:"\u2500",joinLeft:"\u251C",joinRight:"\u2524",joinJoin:"\u253C"}};tableInput(e){this.tableData.push(e)}tableOutput(){console.log(Je(this.tableData,this.tableConfig))}},a=new G});var P,fe=c(()=>{"use strict";P=class{externals={};externalAssets={js:[],css:[]};exp=/^([0-9a-zA-Z_\s]+)@(.*)/;async setup(e){this.setShareLib(e),delete e.shareLib}async setShareLib(e){let t=[];if(typeof e.shareLib=="object")for(let[s,o]of Object.entries(e.shareLib)){let r={};if(r.module=s,typeof o=="string"){let n=o.match(this.exp)||[];n.length>0?(r.global=n[1],r.entry=n[2],r.type="js",t.push(r),r={}):(r.global="",r.entry=o,r.type="js",t.push(r),r={})}else Array.isArray(o)?o.map(n=>{if(!n)return;if(n.split("?")[0].endsWith(".css"))r.entry=n,r.type="css";else{let l=n.match(this.exp)||[];l.length>0?(r.global=l[1],r.entry=l[2],r.type="js"):(r.global="",r.entry=n,r.type="js")}t.push(r),r={}}):typeof o=="object"&&o.entry&&(r.entry=o.entry,r.global=o.global,r.type=o.type,t.push(r),r={})}await Promise.all([this.setExternalAssets(t)])}async setExternalAssets(e=[]){if(e.length>0){let t=[];t=t.concat(e),t.map(s=>{s.type=s.type||"js",s.type==="js"&&s.module?(s.global&&(this.externals[s.module]=s.global),s.entry&&this.externalAssets.js.push(s.entry)):s.type==="css"&&s.entry&&this.externalAssets.css.push(s.entry)})}}}});import Ue from"node:fs";var I,ge,de=c(()=>{"use strict";S();fe();I=class{store;appSrc="src";appEntry="";base="";assign(e,t){return t=t||{},w(e,t)}empShareLib=new P;async setup(e){this.store=e,await this.syncEmpOptions();let{appSrc:t,base:s,appEntry:o}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),o&&(this.appEntry=o),this.store.empOptions.empShare?.shareLib&&await this.empShareLib.setup(this.store.empOptions.empShare)}async chain(){this.store.empOptions.chain&&await this.store.empOptions.chain(this.store.chain)}async plugins(){let e=[];this.store.empOptions.plugins&&Array.isArray(this.store.empOptions.plugins)&&this.store.empOptions.plugins.length>0&&(this.store.empOptions.plugins.map(t=>{e.push(t.rsConfig(this.store))}),await Promise.all(e))}get debug(){return this.assign({loggerLevel:"info",clearLog:!0,progress:!1,showRsconfig:!1},this.store.empOptions.debug)}get build(){let e=this.store.empOptions.build?.staticDir?`${this.store.empOptions.build?.staticDir}/`:"";return this.assign({outDir:"dist",staticDir:e,assetsDir:"assets",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev,minOptions:{}},{...this.store.empOptions.build,staticDir:e})}get html(){return this.assign({lang:"zh-CN",title:"EMP",inject:"body",minify:!this.store.isDev,meta:{charset:{charset:"utf-8"},"http-equiv":{"http-equiv":"X-UA-Compatible",content:"IE=edge"},viewport:{content:"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"}},files:{css:[],js:[]},tags:{headTags:[],bodyTags:[]}},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get react(){return this.assign({hmr:!0,svgr:!1},this.store.empOptions.react)}get server(){return this.assign({host:"0.0.0.0",port:8e3,open:!1,hot:!0,allowedHosts:["all"],historyApiFallback:!0,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS","Access-Control-Allow-Headers":"X-Requested-With, content-type, Authorization"}},this.store.empOptions.server)}get empShare(){return this.assign({name:"",filename:"emp.js",shared:{}},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}get output(){let e=(this.store.isDev,".[contenthash:8]"),{assetsDir:t,staticDir:s}=this.store.empConfig.build;return this.assign({publicPath:this.store.empConfig.base?this.store.empConfig.base:"auto",crossOriginLoading:"anonymous",filename:`${s}js/[name]${e}.js`,cssFilename:`${s}css/[name]${e}.css`,cssChunkFilename:`${s}css/[name]${e}.css`,assetModuleFilename:`${s}${t}/[name]${e}[ext][query]`,path:this.store.outDir,clean:!0},this.store.empOptions.output)}get define(){let e={mode:this.store.mode,env:this.store.cliOptions.env};this.store.empOptions.define&&(e={...e,...this.store.empOptions.define});let t={};return Object.keys(e).map(s=>{t[`import.meta.env.${s}`]=JSON.stringify(e[s]),t[`process.env.${s}`]=JSON.stringify(e[s]),t[`${s}`]=JSON.stringify(e[s])}),t}get externals(){return this.assign(this.empShareLib.externals,this.store.empOptions.externals)}get resolve(){return w({alias:{src:this.store.resolve("src"),"@":this.store.resolve("src")},extensions:["...",".js",".jsx",".mjs",".ts",".tsx",".css",".less",".scss",".sass",".json",".wasm",".vue",".svg",".svga"]},this.store.empOptions.resolve)}async syncEmpOptions(){let e=this.store.resolve("emp-config.js");if(!Ue.existsSync(e))return;let{default:t}=await import(e);typeof t=="function"?this.store.empOptions=await t(this.store):this.store.empOptions=t||{}}get moduleTransformRule(){let e={and:[/(node_modules|bower_components)/]},{moduleTransform:t}=this.store.empOptions;return t?.exclude&&(e.and=t.exclude),t?.include&&(e.not=t.include),e}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}get reactRuntime(){if(this.store.reactVersion)return this.store.empOptions.reactRuntime?this.store.empOptions.reactRuntime:O(this.store.reactVersion,"17")>-1?"automatic":"classic"}},ge=new I});import b from"node:path";import Ve from"webpack-chain";var H,p,g=c(()=>{"use strict";K();ue();y();de();H=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=Z;empSource=b.resolve(this.empRoot,"dist");resolve=e=>b.isAbsolute(e)?e:b.resolve(this.root,e);empResolve=e=>b.resolve(this.empRoot,e);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};cacheDir="";mode="development";cliMode="dev";isDev=!0;reactVersion=void 0;cliOptions;chain;rsConfig;empOptions={};empConfig;async setup(e,t){await this.initVars(e,t),this.empConfig=ge,await this.empConfig.setup(this),this.initPaths(),this.chain=new Ve,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 T(this.empResolve("package.json")),o=await T(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...o},this.reactVersion=this.pkg.dependencies.react||this.pkg.devDependencies.react}initPaths(){this.appSrc=this.resolve(this.empConfig.appSrc),this.outDir=this.resolve(this.empConfig.build.outDir),this.publicDir=this.resolve(this.empConfig.build.publicDir),this.cacheDir=this.resolve(this.empConfig.cacheDir),this.resource.dir=b.join(this.empRoot,"resource"),this.resource.cert=b.join(this.resource.dir,"emp.cert"),this.resource.key=b.join(this.resource.dir,"emp.key")}setLogger(){let e=this.cliMode==="dev"?"debug":"info";this.empConfig.debug.loggerLevel&&(e=this.empConfig.debug.loggerLevel),a.setup({pname:` EMP v${this.empPkg.version} ${this.cliMode==="dev"?"DEV ":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e){return Y(e)}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){this.empConfig.debug.showRsconfig&&console.log("[ChainConfig]",JSON.stringify(this.rsConfig,null,2))}},p=new H});import ye from"node:fs/promises";var d,j=c(()=>{"use strict";y();g();S();d=class{async setup(e,t){await p.setup(e,t),p.empConfig.debug.clearLog&&pe(),a.blue(`${e} Running`),await this.run()}async run(){}get isHttps(){let{server:e,https:t}=p.rsConfig.devServer||{};return e==="https"||typeof e=="object"&&e.type==="https"||t===!0}getcert(){return Promise.all([ye.readFile(p.resource.key),ye.readFile(p.resource.cert)])}}});import ze from"net";import Be from"os";async function k(i,e="localhost"){if(i!==We&&(i<be||i>J))throw new Error(`Port number must lie between ${be} and ${J}`);let t=i,s=_e(),o;e&&!s.has(e)?o=new Set([e]):o=s;let r=new Set(["EADDRINUSE","EACCES"]);for(;t<=J;)try{return await Qe(t,o)}catch(n){if(!r.has(n.code))throw n;t+=1}throw new Error("No available ports found")}var be,J,We,_e,qe,Qe,U=c(()=>{"use strict";be=1024,J=65535,We=443,_e=()=>{let i=Be.networkInterfaces(),e=new Set([void 0,"0.0.0.0"]);for(let t of Object.values(i))if(t)for(let s of t)e.add(s.address);return e},qe=(i,e)=>new Promise((t,s)=>{let o=ze.createServer();o.unref(),o.on("error",s),o.listen(i,e,()=>{let{port:r}=o.address();o.close(()=>{t(r)})})}),Qe=async(i,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await qe(i,s)}catch(o){if(!t.has(o.code))throw o}return i}});var ve={};$(ve,{default:()=>Ze});import{rspack as Xe}from"@rspack/core";import{RspackDevServer as Ye}from"@rspack/dev-server";var V,Ze,Ce=c(()=>{"use strict";g();j();y();U();V=class extends d{async run(){let e=Xe(p.rsConfig);if(!p.rsConfig.devServer){a.error("devServer is not defined in config");return}let t=Object.assign({},p.rsConfig.devServer),{host:s,port:o}=t;if(this.isHttps&&(t.https===!0&&delete t.https,!t.server)){let[m,l]=await this.getcert();t.server={type:"https",options:{key:m,cert:l}}}let r=await k(Number(o),s);r!==o&&(p.rsConfig.devServer.port=r,t.port=r),new Ye(t,e).start()}},Ze=new V});var xe={};$(xe,{default:()=>et});import{rspack as Ke}from"@rspack/core";var z,et,we=c(()=>{"use strict";y();g();j();z=class extends d{async run(){Ke(p.rsConfig,(e,t)=>{if(e!==null){a.error(e.stack||e),e.message&&a.error(e.message);return}if(!t){a.red("Stats is Undefined.");return}t.hasErrors()&&(a.error(t.toString({colors:!0,children:!0})),a.red("Failed to compile."),process.exit(1)),t.hasWarnings()&&(a.yellow("Compiled with warnings."),a.warn(t.toString({colors:!0,children:!0}))),a.info(t.toString({all:!1,colors:!0,assets:!0,chunks:!1,entrypoints:!0,timings:!0,version:!0})),a.green("Compiled successfully.")})}},et=new z});import Se from"url";import Ee from"chalk";import{ip as tt}from"address";import{gateway4sync as st}from"default-gateway";function Oe(i,e,t,s="/"){let o=C=>Se.format({protocol:i,hostname:C,port:t,pathname:s}),r=C=>Se.format({protocol:i,hostname:C,port:Ee.bold(t),pathname:s}),n=e==="0.0.0.0"||e==="::",m,l,u=Ee.gray("unavailable");if(n){m="localhost";try{let{int:C}=st();l=tt(C||""),l&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(l)?u=r(l):l=void 0)}catch{}}else m=e,l=e,u=r(l);let f=r(m),Q=o(m);return{lanUrlForConfig:l,lanUrlForTerminal:u,localUrlForTerminal:f,localUrlForBrowser:Q}}var Pe=c(()=>{"use strict"});var ke={};$(ke,{default:()=>at});import je from"express";import rt from"cors";import ot from"compression";import it from"https";import nt from"path";import pt from"node:fs/promises";var B,at,$e=c(()=>{"use strict";U();Pe();g();y();j();B=class extends d{app;startLogger({host:e,port:t,publicPath:s}){if(s&&(s.indexOf("http://")>-1||s.indexOf("https://")>-1))a.info(`- Network: ${a.link(s)}`);else{let o=this.isHttps?"https":"http",n=Oe(o,e||"0.0.0.0",t,s);a.info(`- Local: ${a.link(n.localUrlForTerminal)}`),a.info(`- Network: ${a.link(n.lanUrlForTerminal)}`)}}async run(){let e=je();e.use(ot()),e.use(rt()),this.app=e;let t=p.resolve(p.rsConfig.output?.path);this.app.use(je.static(t));let s=await pt.readFile(nt.join(t,"index.html"),"utf8");this.app.get("*",(u,f)=>f.send(s));let o=Object.assign({},p.rsConfig.devServer),{host:r,port:n}=o,m=p.rsConfig.output?.publicPath==="auto"?"/":p.rsConfig.output?.publicPath,l=await k(Number(n),r);if(this.isHttps){let[u,f]=await this.getcert();it.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:u,cert:f},this.app).listen(l,()=>{this.startLogger({host:r,port:l,publicPath:m})})}else this.app.listen(l,()=>{this.startLogger({host:r,port:l,publicPath:m})})}},at=new B});g();g();S();y();import{program as v}from"commander";import W,{exit as lt}from"node:process";function Re(){let i="20.0.0";O(i,W.versions.node)===1&&(a.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${W.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${i}`),lt(0)),v.version(p.empPkg.version,"-v, --version").usage("<command> [options]"),v.command("dev").description("Dev \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-h, --hot","\u662F\u5426\u4F7F\u7528\u70ED\u66F4\u65B0 \u9ED8\u8BA4\u542F\u52A8").option("-o, --open","\u662F\u5426\u6253\u5F00\u8C03\u8BD5\u9875\u9762 \u9ED8\u8BA4\u4E0D\u6253\u5F00").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(Ce(),ve));await t.setup("dev",e)}),v.command("build").description("Build \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-a, --analyze","\u751F\u6210\u5206\u6790\u62A5\u544A \u9ED8\u8BA4\u4E3A false").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(we(),xe));await t.setup("build",e)}),v.command("serve").description("Server \u6A21\u5F0F").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>($e(),ke));await t.setup("serve",e)}),v.command("dts").description("\u62C9\u53D6 remote \u9879\u76EE\u7684 d.ts").option("-p, --typingsPath <typingsPath>","\u4E0B\u8F7D\u76EE\u5F55").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").action(e=>{}),v.command("init").description("\u521D\u59CB\u5316 emp \u9879\u76EE").option("-d, --data [data]","JSON\u6570\u636E http\u5730\u5740 \u6216\u8005 \u6587\u4EF6\u8DEF\u5F84\u76F8\u5BF9\u3001\u7EDD\u5BF9\u8DEF\u5F84").action(e=>{}),v.parse(W.argv)}g();import ct from"fast-glob";import Te from"node:fs/promises";import _ from"node:path";var mt=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,ht=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,ut=/import\(['"]([^;\n]+?)['"]\)/,q=class{list=[];outDir=p.resolve("dist");aliasName="@empjs/cli";async setup(e,t){e&&(this.outDir=e),t&&(this.aliasName=t);let s=await this.readDts();await this.writeCode(s)}async readDts(){this.list=await ct([`${p.empConfig.build.outDir}/**/*.d.ts`]);let e=[];this.list.map(s=>{s=p.resolve(s),e.push(this.readFile(s))});let t=await Promise.all(e);return t=t.map(s=>this.replaceAliasPath(s)),t}async readFile(e){let t=await Te.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(mt,o=>{let r=o.match(ht);if(r||(r=o.match(ut)),r&&r[1]){let n=r[1];if(!n.startsWith("."))return o;let m=_.resolve(_.dirname(e),n).replace(this.outDir,this.aliasName);return o.replace(r[1],m)}return o});let s=e.replace(this.outDir,this.aliasName).replace(".d.ts","");return s.endsWith("/index")&&(s=s.replace("/index","")),t=this.warpDeclareModule(s,t),{code:t,src:e,mod:s}}warpDeclareModule(e,t){return`declare module '${e}' {\r
|
|
8
|
+
`)};link=e=>h.hex("#3498db")(e);tableData=[];tableConfig={border:{topBody:"\u2500",topJoin:"\u252C",topLeft:"\u250C",topRight:"\u2510",bottomBody:"\u2500",bottomJoin:"\u2534",bottomLeft:"\u2514",bottomRight:"\u2518",bodyLeft:"\u2502",bodyRight:"\u2502",bodyJoin:"\u2502",joinBody:"\u2500",joinLeft:"\u251C",joinRight:"\u2524",joinJoin:"\u253C"}};tableInput(e){this.tableData.push(e)}tableOutput(){console.log(Je(this.tableData,this.tableConfig))}},a=new G});var P,ge=c(()=>{"use strict";P=class{externals={};externalAssets={js:[],css:[]};exp=/^([0-9a-zA-Z_\s]+)@(.*)/;async setup(e){this.setShareLib(e),delete e.shareLib}async setShareLib(e){let t=[];if(typeof e.shareLib=="object")for(let[s,r]of Object.entries(e.shareLib)){let o={};if(o.module=s,typeof r=="string"){let n=r.match(this.exp)||[];n.length>0?(o.global=n[1],o.entry=n[2],o.type="js",t.push(o),o={}):(o.global="",o.entry=r,o.type="js",t.push(o),o={})}else Array.isArray(r)?r.map(n=>{if(!n)return;if(n.split("?")[0].endsWith(".css"))o.entry=n,o.type="css";else{let l=n.match(this.exp)||[];l.length>0?(o.global=l[1],o.entry=l[2],o.type="js"):(o.global="",o.entry=n,o.type="js")}t.push(o),o={}}):typeof r=="object"&&r.entry&&(o.entry=r.entry,o.global=r.global,o.type=r.type,t.push(o),o={})}await Promise.all([this.setExternalAssets(t)])}async setExternalAssets(e=[]){if(e.length>0){let t=[];t=t.concat(e),t.map(s=>{s.type=s.type||"js",s.type==="js"&&s.module?(s.global&&(this.externals[s.module]=s.global),s.entry&&this.externalAssets.js.push(s.entry)):s.type==="css"&&s.entry&&this.externalAssets.css.push(s.entry)})}}}});import Ue from"node:fs";var I,de,ye=c(()=>{"use strict";E();ge();I=class{store;appSrc="src";appEntry="";base="";assign(e,t){return t=t||{},S(e,t)}empShareLib=new P;async setup(e){this.store=e,await this.syncEmpOptions();let{appSrc:t,base:s,appEntry:r}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),r&&(this.appEntry=r),this.store.empOptions.empShare?.shareLib&&await this.empShareLib.setup(this.store.empOptions.empShare)}async chain(){this.store.empOptions.chain&&await this.store.empOptions.chain(this.store.chain)}async plugins(){let e=[];this.store.empOptions.plugins&&Array.isArray(this.store.empOptions.plugins)&&this.store.empOptions.plugins.length>0&&(this.store.empOptions.plugins.map(t=>{e.push(t.rsConfig(this.store))}),await Promise.all(e))}get debug(){return this.assign({loggerLevel:"info",clearLog:!0,progress:!0,showRsconfig:!1},this.store.empOptions.debug)}get build(){let e=this.store.empOptions.build?.staticDir?`${this.store.empOptions.build?.staticDir}/`:"";return this.assign({outDir:"dist",staticDir:e,assetsDir:"assets",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev,minOptions:{}},{...this.store.empOptions.build,staticDir:e})}get html(){return this.assign({lang:"zh-CN",title:"EMP",inject:"body",minify:!this.store.isDev,meta:{charset:{charset:"utf-8"},"http-equiv":{"http-equiv":"X-UA-Compatible",content:"IE=edge"},viewport:{content:"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"}},files:{css:[],js:[]},tags:{headTags:[],bodyTags:[]}},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get react(){return this.assign({hmr:!0,svgr:!1},this.store.empOptions.react)}get server(){return this.assign({host:"0.0.0.0",port:8e3,open:!1,hot:!0,allowedHosts:["all"],historyApiFallback:!0,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS","Access-Control-Allow-Headers":"X-Requested-With, content-type, Authorization"}},this.store.empOptions.server)}get empShare(){return this.assign({name:"",filename:"emp.js",shared:{}},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}get output(){let e=(this.store.isDev,".[contenthash:8]"),{assetsDir:t,staticDir:s}=this.store.empConfig.build;return this.assign({publicPath:this.store.empConfig.base?this.store.empConfig.base:"auto",crossOriginLoading:"anonymous",filename:`${s}js/[name]${e}.js`,cssFilename:`${s}css/[name]${e}.css`,cssChunkFilename:`${s}css/[name]${e}.css`,assetModuleFilename:`${s}${t}/[name]${e}[ext][query]`,path:this.store.outDir,clean:!0},this.store.empOptions.output)}get define(){let e=this.store.empOptions.defineFix?this.store.empOptions.defineFix:"cjs",t={mode:this.store.mode,env:this.store.cliOptions.env};this.store.empOptions.define&&(t={...t,...this.store.empOptions.define});let s={};return Object.keys(t).map(r=>{(e==="all"||e==="esm")&&(s[`import.meta.env.${r}`]=JSON.stringify(t[r])),(e==="all"||e==="cjs")&&(s[`process.env.${r}`]=JSON.stringify(t[r])),s[`${r}`]=JSON.stringify(t[r])}),s}get externals(){return this.assign(this.empShareLib.externals,this.store.empOptions.externals)}get resolve(){return S({alias:{src:this.store.resolve("src"),"@":this.store.resolve("src")},extensions:["...",".js",".jsx",".mjs",".ts",".tsx",".css",".less",".scss",".sass",".json",".wasm",".vue",".svg",".svga"]},this.store.empOptions.resolve)}async syncEmpOptions(){let e=this.store.resolve("emp-config.js");if(!Ue.existsSync(e))return;let{default:t}=await import(this.store.importFileUrl(e));typeof t=="function"?this.store.empOptions=await t(this.store):this.store.empOptions=t||{}}get moduleTransformRule(){let e={and:[/(node_modules|bower_components)/]},{moduleTransform:t}=this.store.empOptions;return t?.exclude&&(e.and=t.exclude),t?.include&&(e.not=t.include),e}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}get reactRuntime(){if(this.store.reactVersion)return this.store.empOptions.reactRuntime?this.store.empOptions.reactRuntime:O(this.store.reactVersion,"17")>-1?"automatic":"classic"}},de=new I});import v from"node:path";import Ve from"webpack-chain";import{pathToFileURL as ze}from"node:url";var H,p,g=c(()=>{"use strict";ee();fe();b();ye();H=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=K;empSource=v.resolve(this.empRoot,"dist");resolve=e=>v.isAbsolute(e)?e:v.resolve(this.root,e);empResolve=e=>v.resolve(this.empRoot,e);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};cacheDir="";mode="development";cliMode="dev";isDev=!0;reactVersion=void 0;cliOptions;chain;rsConfig;empOptions={};empConfig;async setup(e,t){await this.initVars(e,t),this.empConfig=de,await this.empConfig.setup(this),this.initPaths(),this.chain=new Ve,await ue.setup(this),this.setLogger(),this.toConfig(),this.logConfig()}async initVars(e,t){this.cliOptions=t||{},this.cliMode="prod",this.mode=e==="dev"?"development":"production",this.isDev=this.mode==="development";let s=await T(this.empResolve("package.json")),r=await T(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...r},this.reactVersion=this.pkg.dependencies.react||this.pkg.devDependencies.react}initPaths(){this.appSrc=this.resolve(this.empConfig.appSrc),this.outDir=this.resolve(this.empConfig.build.outDir),this.publicDir=this.resolve(this.empConfig.build.publicDir),this.cacheDir=this.resolve(this.empConfig.cacheDir),this.resource.dir=v.join(this.empRoot,"resource"),this.resource.cert=v.join(this.resource.dir,"emp.cert"),this.resource.key=v.join(this.resource.dir,"emp.key")}setLogger(){let e=this.cliMode==="dev"?"debug":"info";this.empConfig.debug.loggerLevel&&(e=this.empConfig.debug.loggerLevel),a.setup({pname:` EMP v${this.empPkg.version} ${this.cliMode==="dev"?"DEV ":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e,t){return Z(e,t)}importFileUrl(e){return ze(e).toString()}toConfig(){this.rsConfig=this.chain.toConfig()}logConfig(){this.empConfig.debug.showRsconfig&&console.log("[ChainConfig]",JSON.stringify(this.rsConfig,null,2))}},p=new H});import be from"node:fs/promises";var d,j=c(()=>{"use strict";b();g();E();d=class{async setup(e,t){await p.setup(e,t),p.empConfig.debug.clearLog&&ae(),a.blue(`${e} Running`),await this.run()}async run(){}get isHttps(){let{server:e,https:t}=p.rsConfig.devServer||{};return e==="https"||typeof e=="object"&&e.type==="https"||t===!0}getcert(){return Promise.all([be.readFile(p.resource.key),be.readFile(p.resource.cert)])}}});import Be from"net";import We from"os";async function k(i,e="localhost"){if(i!==_e&&(i<ve||i>J))throw new Error(`Port number must lie between ${ve} and ${J}`);let t=i,s=qe(),r;e&&!s.has(e)?r=new Set([e]):r=s;let o=new Set(["EADDRINUSE","EACCES"]);for(;t<=J;)try{return await Xe(t,r)}catch(n){if(!o.has(n.code))throw n;t+=1}throw new Error("No available ports found")}var ve,J,_e,qe,Qe,Xe,U=c(()=>{"use strict";ve=1024,J=65535,_e=443,qe=()=>{let i=We.networkInterfaces(),e=new Set([void 0,"0.0.0.0"]);for(let t of Object.values(i))if(t)for(let s of t)e.add(s.address);return e},Qe=(i,e)=>new Promise((t,s)=>{let r=Be.createServer();r.unref(),r.on("error",s),r.listen(i,e,()=>{let{port:o}=r.address();r.close(()=>{t(o)})})}),Xe=async(i,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await Qe(i,s)}catch(r){if(!t.has(r.code))throw r}return i}});var Ce={};$(Ce,{default:()=>Ke});import{rspack as Ye}from"@rspack/core";import{RspackDevServer as Ze}from"@rspack/dev-server";var V,Ke,xe=c(()=>{"use strict";g();j();b();U();V=class extends d{async run(){let e=Ye(p.rsConfig);if(!p.rsConfig.devServer){a.error("devServer is not defined in config");return}let t=Object.assign({},p.rsConfig.devServer),{host:s,port:r}=t;if(this.isHttps&&(t.https===!0&&delete t.https,!t.server)){let[m,l]=await this.getcert();t.server={type:"https",options:{key:m,cert:l}}}let o=await k(Number(r),s);o!==r&&(p.rsConfig.devServer.port=o,t.port=o),new Ze(t,e).start()}},Ke=new V});var we={};$(we,{default:()=>tt});import{rspack as et}from"@rspack/core";var z,tt,Se=c(()=>{"use strict";b();g();j();z=class extends d{async run(){et(p.rsConfig,(e,t)=>{if(e!==null){a.error(e.stack||e),e.message&&a.error(e.message);return}if(!t){a.red("Stats is Undefined.");return}t.hasErrors()&&(a.error(t.toString({colors:!0,children:!0})),a.red("Failed to compile."),process.exit(1)),t.hasWarnings()&&(a.yellow("Compiled with warnings."),a.warn(t.toString({colors:!0,children:!0}))),a.info(t.toString({all:!1,colors:!0,assets:!0,chunks:!1,entrypoints:!0,timings:!0,version:!0})),a.green("Compiled successfully.")})}},tt=new z});import Ee from"url";import Oe from"chalk";import{ip as st}from"address";import{gateway4sync as rt}from"default-gateway";function Pe(i,e,t,s="/"){let r=x=>Ee.format({protocol:i,hostname:x,port:t,pathname:s}),o=x=>Ee.format({protocol:i,hostname:x,port:Oe.bold(t),pathname:s}),n=e==="0.0.0.0"||e==="::",m,l,u=Oe.gray("unavailable");if(n){m="localhost";try{let{int:x}=rt();l=st(x||""),l&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(l)?u=o(l):l=void 0)}catch{}}else m=e,l=e,u=o(l);let f=o(m),Q=r(m);return{lanUrlForConfig:l,lanUrlForTerminal:u,localUrlForTerminal:f,localUrlForBrowser:Q}}var je=c(()=>{"use strict"});var $e={};$($e,{default:()=>lt});import ke from"express";import ot from"cors";import it from"compression";import nt from"https";import pt from"path";import at from"node:fs/promises";var B,lt,Re=c(()=>{"use strict";U();je();g();b();j();B=class extends d{app;startLogger({host:e,port:t,publicPath:s}){if(s&&(s.indexOf("http://")>-1||s.indexOf("https://")>-1))a.info(`- Network: ${a.link(s)}`);else{let r=this.isHttps?"https":"http",n=Pe(r,e||"0.0.0.0",t,s);a.info(`- Local: ${a.link(n.localUrlForTerminal)}`),a.info(`- Network: ${a.link(n.lanUrlForTerminal)}`)}}async run(){let e=ke();e.use(it()),e.use(ot()),this.app=e;let t=p.resolve(p.rsConfig.output?.path);this.app.use(ke.static(t));let s=await at.readFile(pt.join(t,"index.html"),"utf8");this.app.get("*",(u,f)=>f.send(s));let r=Object.assign({},p.rsConfig.devServer),{host:o,port:n}=r,m=p.rsConfig.output?.publicPath==="auto"?"/":p.rsConfig.output?.publicPath,l=await k(Number(n),o);if(this.isHttps){let[u,f]=await this.getcert();nt.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:u,cert:f},this.app).listen(l,()=>{this.startLogger({host:o,port:l,publicPath:m})})}else this.app.listen(l,()=>{this.startLogger({host:o,port:l,publicPath:m})})}},lt=new B});g();g();E();b();import{program as C}from"commander";import W,{exit as ct}from"node:process";function Te(){let i="20.0.0";O(i,W.versions.node)===1&&(a.sysError(`\u5F53\u524D\u7248\u672C\u4E3Av${W.versions.node} \u6700\u4F4E\u8981\u6C42\u4E3Av${i}`),ct(0)),C.version(p.empPkg.version,"-v, --version").usage("<command> [options]"),C.command("dev").description("Dev \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-h, --hot","\u662F\u5426\u4F7F\u7528\u70ED\u66F4\u65B0 \u9ED8\u8BA4\u542F\u52A8").option("-o, --open","\u662F\u5426\u6253\u5F00\u8C03\u8BD5\u9875\u9762 \u9ED8\u8BA4\u4E0D\u6253\u5F00").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(xe(),Ce));await t.setup("dev",e)}),C.command("build").description("Build \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-a, --analyze","\u751F\u6210\u5206\u6790\u62A5\u544A \u9ED8\u8BA4\u4E3A false").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(Se(),we));await t.setup("build",e)}),C.command("serve").description("Server \u6A21\u5F0F").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async e=>{let{default:t}=await Promise.resolve().then(()=>(Re(),$e));await t.setup("serve",e)}),C.command("dts").description("\u62C9\u53D6 remote \u9879\u76EE\u7684 d.ts").option("-p, --typingsPath <typingsPath>","\u4E0B\u8F7D\u76EE\u5F55").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").action(e=>{}),C.command("init").description("\u521D\u59CB\u5316 emp \u9879\u76EE").option("-d, --data [data]","JSON\u6570\u636E http\u5730\u5740 \u6216\u8005 \u6587\u4EF6\u8DEF\u5F84\u76F8\u5BF9\u3001\u7EDD\u5BF9\u8DEF\u5F84").action(e=>{}),C.parse(W.argv)}g();import mt from"fast-glob";import De from"node:fs/promises";import _ from"node:path";var ht=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,ut=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,ft=/import\(['"]([^;\n]+?)['"]\)/,q=class{list=[];outDir=p.resolve("dist");aliasName="@empjs/cli";async setup(e,t){e&&(this.outDir=e),t&&(this.aliasName=t);let s=await this.readDts();await this.writeCode(s)}async readDts(){this.list=await mt([`${p.empConfig.build.outDir}/**/*.d.ts`]);let e=[];this.list.map(s=>{s=p.resolve(s),e.push(this.readFile(s))});let t=await Promise.all(e);return t=t.map(s=>this.replaceAliasPath(s)),t}async readFile(e){let t=await De.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(ht,r=>{let o=r.match(ut);if(o||(o=r.match(ft)),o&&o[1]){let n=o[1];if(!n.startsWith("."))return r;let m=_.resolve(_.dirname(e),n).replace(this.outDir,this.aliasName);return r.replace(o[1],m)}return r});let s=e.replace(this.outDir,this.aliasName).replace(".d.ts","");return s.endsWith("/index")&&(s=s.replace("/index","")),t=this.warpDeclareModule(s,t),{code:t,src:e,mod:s}}warpDeclareModule(e,t){return`declare module '${e}' {\r
|
|
9
9
|
${t}}\r
|
|
10
|
-
`}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await
|
|
10
|
+
`}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await De.writeFile(_.join(this.outDir.replace("dist","types"),"type.d.ts"),t)}},gt=new q;function er(i){return i}export{er as defineConfig,gt as dts,Te as runScript,p as store};
|
package/dist/store/index.d.ts
CHANGED
|
@@ -92,7 +92,14 @@ export declare class GlobalStore {
|
|
|
92
92
|
*/
|
|
93
93
|
setLogger(): void;
|
|
94
94
|
merge(o: RspackOptions): void;
|
|
95
|
-
importResolve(scope: string): string;
|
|
95
|
+
importResolve(scope: string, importMetaUrl?: string): string;
|
|
96
|
+
/**
|
|
97
|
+
* windows import() 情况下 ES 的物理路径转换
|
|
98
|
+
* pathToFileURL 是为了解决在window下,import文件路径解析异常
|
|
99
|
+
* @param scope
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
importFileUrl(scope: string): string;
|
|
96
103
|
/**
|
|
97
104
|
* 同步 chain 配置到 rsConfig
|
|
98
105
|
*/
|
package/dist/types/config.d.ts
CHANGED
|
@@ -218,6 +218,15 @@ export type EmpOptions = {
|
|
|
218
218
|
* 全局环境替换
|
|
219
219
|
*/
|
|
220
220
|
define?: Record<string, any>;
|
|
221
|
+
/**
|
|
222
|
+
* 是否创建 cjs 的 process.env 或者 esm 的 import.meta.env
|
|
223
|
+
* all 两者创建
|
|
224
|
+
* esm 创建 import.meta.env
|
|
225
|
+
* cjs 创建 process.env
|
|
226
|
+
* none 不创建
|
|
227
|
+
* @default cjs
|
|
228
|
+
*/
|
|
229
|
+
defineFix?: 'all' | 'esm' | 'cjs' | 'none';
|
|
221
230
|
/**
|
|
222
231
|
* externals
|
|
223
232
|
*/
|