@moneko/core 3.56.14-beta.4 → 3.56.14-beta.5
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/lib/bin/build-dev.d.mts +1 -0
- package/lib/bin/build-dev.mjs +1 -0
- package/lib/bin/build.d.mts +0 -2
- package/lib/bin/build.mjs +1 -1
- package/lib/bin/index.mjs +1 -1
- package/lib/build/common.mjs +1 -1
- package/lib/build-dev.d.mts +1 -0
- package/lib/build-dev.mjs +2 -0
- package/lib/config.mjs +1 -1
- package/lib/dev.mjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function build(): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{argv as e,exit as o}from"node:process";import{ink as r,println as t}from"@moneko/utils";import m from"../commom/setup-env.mjs";export async function build(){let i=e[3],s=e[4],p=e.slice(5);i||(t(r(`type: 无效值 ${r(i,"245")}`,"red")),o(1));let n=p.indexOf("no-verify");-1!==n&&p.splice(n,1),await m("development",i,s,p,!0);try{await import("../build-dev.mjs")}catch(e){t(r(Error(e).message,"red")),o(1)}}
|
package/lib/bin/build.d.mts
CHANGED
package/lib/bin/build.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as o}from"node:path";import{argv as t,exit as e}from"node:process";import{ink as s,println as i,removeDir as r}from"@moneko/utils";import m from"../commom/setup-env.mjs";import{cwd as n,swcCachePath as l}from"./utils/config.mjs";import{getSwcOption as
|
|
1
|
+
import{join as o}from"node:path";import{argv as t,exit as e}from"node:process";import{ink as s,println as i,removeDir as r}from"@moneko/utils";import m from"../commom/setup-env.mjs";import{cwd as n,swcCachePath as l}from"./utils/config.mjs";import{getSwcOption as p}from"./utils/setup-swcrc.mjs";import{lesscCommonjs as c}from"./lessc.mjs";import d from"./tsc.mjs";export async function build(){let a=t[3],j=t[4],u=t.slice(5);a||(i(s(`type: 无效值 ${s(a,"245")}`,"red")),e(1));let f=!u.includes("no-docs"),x=!u.includes("no-lib"),y=!u.includes("no-es"),_=!u.includes("no-dts"),g=u.filter(o=>!["no-docs","no-es","no-lib"].includes(o));if(await m("production",a,j,g,!0),"library"===a){let t="solid"===j?await import("@moneko/convert/solid"):await import("@moneko/convert"),{CONFIG:e}=await import("../config.mjs"),s="swc"===e.dts,i=[x&&{type:"commonjs",dir:"lib",msg:"Convert to CommonJS"},y&&{type:"es6",dir:"es",msg:"Convert to ES Module"}].filter(Boolean);for(let m=0,a=i.length;m<a;m++){if(r(o(n,`./${i[m].dir}`)),"react"===j){let o=await p();"es6"===i[m].type&&(o.jsc.target="es2015"),o.jsc.experimental.emitIsolatedDts=_&&s,o.jsc.experimental.cacheRoot=l,o.module.type=i[m].type,t.convert({outDir:i[m].dir,inputDir:"components",ignore:[/^.*\/__*__\//,/\.test\.(js|ts)x?$/,/\.DS_Store/,/\.mdx?$/,/^.*\/examples\//,/\.d\.(cj|mj|j|t|ct|mt)sx?$/],options:o})}else if("solid"===j){let o={jsxOptions:e.jsxDomExpressions,presetEnvOption:{modules:"commonjs"}};"es6"===i[m].type&&(o.presetEnvOption.modules=!1),t.convertSolid({outDir:i[m].dir,inputDir:"components",ignore:[/^.*\/__*__\//,/\.test\.(js|ts)x?$/,/\.DS_Store/,/\.mdx?$/,/^.*\/examples\//,/\.d\.(cj|mj|j|t|ct|mt)sx?$/],options:o})}"commonjs"===i[m].type&&c(),_&&!s&&d(i[m].dir)}}if("library"!==a||f&&"library"===a)try{await import("../build.mjs")}catch(o){i(s(Error(o).message,"red")),e(1)}}
|
package/lib/bin/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{argv as a,exit as e}from"node:process";import{ink as t,println as i}from"@moneko/utils";import s from"../commom/require.mjs";import r from"../commom/sigint-exit.mjs";import{corePkg as m}from"./utils/config.mjs";switch(a[2]){case"-v":case"--version":i(`${t(m,"blue")}: ${s(`${m}/package.json`).version}`,!0);break;case"start":(await import("./start.mjs")).default();break;case"build":(await import("./build.mjs")).
|
|
2
|
+
import{argv as a,exit as e}from"node:process";import{ink as t,println as i}from"@moneko/utils";import s from"../commom/require.mjs";import r from"../commom/sigint-exit.mjs";import{corePkg as m}from"./utils/config.mjs";switch(a[2]){case"-v":case"--version":i(`${t(m,"blue")}: ${s(`${m}/package.json`).version}`,!0);break;case"start":(await import("./start.mjs")).default();break;case"build":(await import("./build.mjs")).build();break;case"build-dev":(await import("./build-dev.mjs")).build();break;case"eslint":(await import("./eslint.mjs")).default();break;case"stylelint":(await import("./stylelint.mjs")).default();break;case"githooks":(await import("./git-hooks.mjs")).default();break;case"buildApp":(await import("./build-app.mjs")).default();break;case"changelog":(await import("./changelog.mjs")).default();break;case"server":(await import("./server.mjs")).default();break;case"pin":(await import("./pin.mjs")).default();break;case"setup":(await import("./setup.mjs")).default();break;default:(await import("./help.mjs")).default()}r(()=>{e(0)});
|
package/lib/build/common.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"mini-css-extract-plugin";import i from"webpack";import{merge as n}from"webpack-merge";import{commonConfig as t}from"../common.mjs";import{CONFIG as r}from"../config.mjs";import{LightningCssMinifyPlugin as s}from"../plugin/lightningcss-plugin.mjs";import{SwcMinifyPlugin as m}from"../plugin/swc-minify-plugin.mjs";import{getLightningCssTargets as l}from"../polyfills/targets.mjs";import{isDev as p,isReact as o}from"../process-env.mjs";let
|
|
1
|
+
import e from"mini-css-extract-plugin";import i from"webpack";import{merge as n}from"webpack-merge";import{commonConfig as t}from"../common.mjs";import{CONFIG as r}from"../config.mjs";import{LightningCssMinifyPlugin as s}from"../plugin/lightningcss-plugin.mjs";import{SwcMinifyPlugin as m}from"../plugin/swc-minify-plugin.mjs";import{getLightningCssTargets as l}from"../polyfills/targets.mjs";import{isDev as p,isReact as o,refresh as a}from"../process-env.mjs";let u=[];r.minifier&&(u.push(new m(r.minifier)),u.push(new s({targets:l()})));let c={maxAssetSize:256e3,maxEntrypointSize:256e3,assetFilter:e=>!e.endsWith(".map")&&!e.endsWith("ce28377f3a428346.js"),...r.performance},h=n(t,{performance:r.performance&&c,plugins:[new e({filename:"style/[contenthash].css",chunkFilename:"style/[contenthash].css",ignoreOrder:!0})],optimization:Object.assign({splitChunks:r.splitChunk,runtimeChunk:r.runtimeChunk,minimize:!0,minimizer:u},{chunkIds:"deterministic",moduleIds:"deterministic",concatenateModules:!0,emitOnErrors:!1,removeAvailableModules:!0,removeEmptyChunks:!0,mergeDuplicateChunks:!0,sideEffects:!0,providedExports:!0,flagIncludedChunks:!0,innerGraph:!1,mangleExports:"deterministic",portableRecords:!0,realContentHash:!1})});if(p&&a&&(h.plugins.push(new i.HotModuleReplacementPlugin),o)){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;h.plugins.push(new e({overlay:!1}))}if(r.splitChunk&&h.plugins?.push(new i.optimize.MinChunkSizePlugin({minChunkSize:r.minChunkSize||1e3})),r.bundleAnalyzer){let e=(await import("webpack-bundle-analyzer")).BundleAnalyzerPlugin;h.plugins?.push(new e({analyzerMode:"static",reportFilename:"report.html",openAnalyzer:!1,defaultSizes:"gzip",logLevel:"silent",...r.bundleAnalyzer}))}export default h;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{relative as o}from"node:path";import r from"node:process";import{analyzeBundleSize as m,completedInfo as t,ink as e,println as i,progressBar as a}from"@moneko/utils";import n from"webpack";import{merge as s}from"webpack-merge";import p from"./commom/paths.mjs";import{empty as l}from"./utils/index.mjs";import{commonConfig as u}from"./common.mjs";import{CONFIG as c}from"./config.mjs";import f from"./module.config.mjs";import{isReact as g,refresh as h}from"./process-env.mjs";let w=s(u,{module:f(!1),plugins:[new n.HotModuleReplacementPlugin]});if(c.bar){let o=c.bar,m=o.name||"Build";w.plugins.push(new n.ProgressPlugin({handler(t,e,...i){let n=i.length?`[${e}] ${i.join(" ")}`:" ";o.quiet?r.stdout.write(`${n}
|
|
2
|
+
`):(a(t||0,1,{msg:n,name:m,barColor:o.barColor,nameColor:o.nameColor,barBgColor:o.barBgColor,msgColor:o.msgColor}),1===t&&r.stdout.write("\r\x1b[2K"))}}))}if(g&&h){let o=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;w.plugins.push(new o({overlay:!1}))}let d=n(w);async function b(){let r=await new Promise((o,r)=>{d?.run((m,t)=>{m&&r(m),t?o(t):r(Error("编译过程中没有生成统计信息"))})});(r.hasErrors()||r.hasWarnings())&&function(o){let{warnings:r,errors:m}=o.compilation;r.forEach(o=>{i(e(o.message,"178"))}),m.forEach(o=>{i(e(o.message,"red"))})}(r),await new Promise(a=>{r.compilation.compiler.cache.shutdown(n=>{n&&i(e(n.toString(),"red")),m(r.compilation.outputOptions.path,["\\.js$"]),t(~~((r.endTime-r.startTime)/10)/100,o(p.programPath,r.compilation.outputOptions.path)),a()})})}r.on("exit",l),await b();
|
package/lib/config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as e,relative as o}from"node:path";import t from"node:process";import{fileExists as r}from"@moneko/utils";import{merge as n}from"webpack-merge";import a from"./commom/paths.mjs";import s from"./commom/require.mjs";import i from"./commom/setup-env.mjs";import l from"./options/jsx-dom-expressions.mjs";import m from"./options/split-chunk.mjs";import{isFunction as p,node_modules as c,resolveProgram as u}from"./utils/index.mjs";import{APPTYPE as d,FRAMEWORK as f,frameworkVersion as h,isCI as g,isDev as v,isLibrary as x,isMobile as j,isReact as C,jsxImportSource as P,mainDirectory as k,NODE_ENV as b,PACKAGENAME as w}from"./process-env.mjs";let O=["@app","@moneko","neko-ui",".cache/http/data","@element-plus","ant-design-vue","element-plus","element-ui","ng-zorro-antd","@mui","@du","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design","monaco-editor"];export function getConfig(e){return delete s.cache[e],new Promise(o=>{if(r(e)){let r=s(e).default;return o(p(r)?r(t):r)}return o({})})}let S=await Promise.all([i(b,d,f,[],"true"===t.env.IS_BUILD),getConfig(a.configPath),getConfig(a.customConfigPath)]),
|
|
1
|
+
import{join as e,relative as o}from"node:path";import t from"node:process";import{fileExists as r}from"@moneko/utils";import{merge as n}from"webpack-merge";import a from"./commom/paths.mjs";import s from"./commom/require.mjs";import i from"./commom/setup-env.mjs";import l from"./options/jsx-dom-expressions.mjs";import m from"./options/split-chunk.mjs";import{isFunction as p,node_modules as c,resolveProgram as u}from"./utils/index.mjs";import{APPTYPE as d,FRAMEWORK as f,frameworkVersion as h,isCI as g,isDev as v,isLibrary as x,isMobile as j,isReact as C,jsxImportSource as P,mainDirectory as k,NODE_ENV as b,PACKAGENAME as w}from"./process-env.mjs";let O=["@app","@moneko","neko-ui",".cache/http/data","@element-plus","ant-design-vue","element-plus","element-ui","ng-zorro-antd","@mui","@du","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design","monaco-editor"];export function getConfig(e){return delete s.cache[e],new Promise(o=>{if(r(e)){let r=s(e).default;return o(p(r)?r(t):r)}return o({})})}let S=await Promise.all([i(b,d,f,[],"true"===t.env.IS_BUILD),getConfig(a.configPath),getConfig(a.customConfigPath)]),I=S[0],y=S[1],M=S[2],D={mode:b,strict:!1,devtool:v?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:"",namespace:w,moduleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]",fallbackModuleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]"},env:I,basename:"/",publicPath:"auto",rem:{designSize:j?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":u(k)},C&&h<18?{"react/package.json":c("react/package.json"),"react/jsx-runtime":c("react/jsx-runtime.js"),"react/jsx-dev-runtime":c("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3,open:!0},htmlPluginOption:{title:w.toLocaleUpperCase(),favicon:o(a.programPath,`${a.corePath}/options/favicon.ico`)},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:m,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:O,js:O,media:O,font:O,wasm:[]},mdx:{jsx:!1,development:v,jsxImportSource:P,providerImportSource:`@moneko/${f}/mdx`},jsxDomExpressions:l,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69",quiet:g},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:!0,bundleId:"com.moneko.bid",bundles:[],stylelint:{},eslint:{lintDirtyModulesOnly:!1},minChunkSize:1e3,compression:"true"!==t.env.IS_BUILD,manifest:{filename:"manifest.json"},corepack:!0,reactJsxRuntime:"automatic"};x&&(D.alias=Object.assign(D.alias,{"@pkg":a.componentsPath,[w]:a.componentsPath}));let z=D;(!1===(z=n(z,y,M)).devtool||!1===z.sourceMap)&&(z.sourceMap=!1,z.devtool=!1),"true"===t.env.CODESPACES&&(z.devServer.https=!1),!1===z.devServer.https&&"darwin"===t.platform&&(z.devServer.open=!1),z.htmlPluginOption&&(z.htmlPluginOption.tags||(z.htmlPluginOption.tags=[]),z.fixBrowserRouter&&z.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}),z.manifest&&z.htmlPluginOption.tags.push({href:e(z.basename,z.manifest.filename).replaceAll(/\\/g,"/"),tag:"link",rel:"manifest"}));export const CONFIG=z;export const PUBLICPATH="auto"===CONFIG.publicPath?"":CONFIG.publicPath;
|
package/lib/dev.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{join as r,relative as i}from"node:path";import n from"node:process";import{URL as s}from"node:url";import{ink as a,print as m,println as l,progressBar as p}from"@moneko/utils";import c from"webpack";import f from"webpack-hot-middleware";import{merge as h}from"webpack-merge";import{diffObject as u}from"./commom/diff-object.mjs";import d,{config_files as g}from"./commom/paths.mjs";import w from"./commom/sigint-exit.mjs";import{devLog as y,PORT as j}from"./dev/config.mjs";import $ from"./dev/generate-progress-html.mjs";import v from"./dev/server.mjs";import b from"./options/reslove.mjs";import{ESLintPlugin as C}from"./plugin/eslint.mjs";import{generateManifest as x}from"./plugin/manifest.mjs";import{StylelintPlugin as _}from"./plugin/stylelint.mjs";import{empty as P}from"./utils/index.mjs";import{commonConfig as S}from"./common.mjs";import{CONFIG as k,getConfig as H}from"./config.mjs";import{outputFileSystem as E}from"./file-system.mjs";import O from"./module.config.mjs";import{isLibrary as T,isReact as B,refresh as I}from"./process-env.mjs";let q=!1,G="/____progress____",L={percentage:0,info:""},N="/__hmr__",R=new URLSearchParams({name:"client",path:N.substring(1),dynamicPublicPath:!0,timeout:2e3,reload:!I,quiet:!0,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),U=h(S,{watchOptions:{stdin:!0,aggregateTimeout:300,ignored:/node_modules\/(?!(@app)\/)/},entry:{main:[`${b.hotMiddlewareClient}?${R}`]},module:O(!1),plugins:[new c.HotModuleReplacementPlugin,new c.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app)\/)/,/\.d\.ts$/]}),new c.ProgressPlugin({handler(e,t,...o){let r=o.length?`[${t}] ${o.join(" ")}`:" ";q||(L.info=r,L.percentage=e,q=1===e);let i=k.bar;if(i){let t=i.name||"Build";i.quiet?n.stdout.write(`${r}
|
|
2
|
-
`):(p(e||0,1,{msg:r,name:t,barColor:i.barColor,nameColor:i.nameColor,barBgColor:i.barBgColor,msgColor:i.msgColor}),1===e&&n.stdout.write("\r\x1b[2K"))}}})]});if(B){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;U.plugins.push(new e({overlay:!1}))}function F(e){let t=e.join(","),o=[i(d.programPath,`${k.alias["@"]}/**/*.{${t}}`).replace(/\\/g,"/")];return T&&o.push(i(d.programPath,`${k.alias["@pkg"]}/**/*.{${t}}`).replace(/\\/g,"/")),o}k.eslint&&U.plugins.push(new C({fix:!0,cache:!0,cacheLocation:`${d.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",files:F(["js","jsx","ts","tsx","json","html","vue"]),...k.eslint})),k.stylelint&&U.plugins.push(new _({fix:!0,cache:!0,cacheLocation:`${d.lintCachePath}/.stylelintcache`,files:F(["css","scss","sass","less","ts","tsx","js","jsx"]),...k.stylelint}));let J=c(U);if(!J)throw Error("无法创建编译器");J.outputFileSystem=E;let M=J.watch(J.options.watchOptions,y);if(!M)throw Error("无法创建监视器");J.hooks.done.tap("client-log",e=>{y(null,e)});let A=`${k.basename}/${N}`.replace(/\/+/g,"/"),K=f(J,{log:!1,path:A,heartbeat:2e3}),W=!!k.manifest&&r(k.basename,k.manifest.filename).replaceAll(/\\/g,"/"),z=await v({port:j,root_dir:J.options.output.path,fileSystem:J.outputFileSystem,headers:k.devServer.headers,https:k.devServer.https,host:k.devServer.host,open:k.devServer.open,basename:k.basename,onRequest(e,t){if(!t.writableEnded){if("GET"===e.method){let o=new s(`${k.devServer.https?"https":"http"}://${e.headers.host}${e.url}`);if(W&&o.pathname===W)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(x({}))),!0;if(o.pathname===G)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(L)),!0;if(!q)return t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end($(G,L)),!0;if(o.pathname===A&&"text/event-stream"===e.headers.accept)return K(e,t,P),!0}return!1}}});function D(){n.exit(0)}z.on("close",()=>{M.close(P),K.close()});let Q=await Promise.all(g.map(H)),V=h(Q[0]||{},Q[1]||{});g.forEach(function(t){o(t,async function(){var o;let[r,i]=await Promise.all(g.map(H)),s=h(r||{},i||{}),p=u(V,s);1===Object.keys(p).length&&"proxy"in p?(m(a(`代理更新中...`,"yellow"),!0),m(a(`代理更新完成...`,"green"),!0),k.proxy=s.proxy,V.proxy=s.proxy,V=s):(V=s,l(a(`检测到工程配置${a(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),o=j,e(X?`netstat -ano | findstr :${o}`:`lsof -i :${o} -t`,(e,t)=>{if(e){l(a(`查找端口 ${o} 时发生错误: ${e.message}`,"red")),l(a("请尝试手动重启程序","yellow"));return}let r=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),i=X?r[0]?.split(/\s+/).pop()?.trim():r[0]?.trim();if(!i)return void l(a(`未找到占用端口 ${o} 的进程, 请尝试手动重启程序`,"yellow"));try{n.kill(Number(i),"SIGHUP")}catch(e){l(a(`终止进程 ${i} 时发生错误: ${e.message}`,"red"))}}))})});let X="win32"===n.platform;n.on("SIGHUP",function(){z.close(P);let e=t(n.argv[0],n.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",D)}),n.on("exit",function(){z.close(P)}),w(D);
|
|
2
|
+
`):(p(e||0,1,{msg:r,name:t,barColor:i.barColor,nameColor:i.nameColor,barBgColor:i.barBgColor,msgColor:i.msgColor}),1===e&&n.stdout.write("\r\x1b[2K"))}}})]});if(B&&I){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;U.plugins.push(new e({overlay:!1}))}function F(e){let t=e.join(","),o=[i(d.programPath,`${k.alias["@"]}/**/*.{${t}}`).replace(/\\/g,"/")];return T&&o.push(i(d.programPath,`${k.alias["@pkg"]}/**/*.{${t}}`).replace(/\\/g,"/")),o}k.eslint&&U.plugins.push(new C({fix:!0,cache:!0,cacheLocation:`${d.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",files:F(["js","jsx","ts","tsx","json","html","vue"]),...k.eslint})),k.stylelint&&U.plugins.push(new _({fix:!0,cache:!0,cacheLocation:`${d.lintCachePath}/.stylelintcache`,files:F(["css","scss","sass","less","ts","tsx","js","jsx"]),...k.stylelint}));let J=c(U);if(!J)throw Error("无法创建编译器");J.outputFileSystem=E;let M=J.watch(J.options.watchOptions,y);if(!M)throw Error("无法创建监视器");J.hooks.done.tap("client-log",e=>{y(null,e)});let A=`${k.basename}/${N}`.replace(/\/+/g,"/"),K=f(J,{log:!1,path:A,heartbeat:2e3}),W=!!k.manifest&&r(k.basename,k.manifest.filename).replaceAll(/\\/g,"/"),z=await v({port:j,root_dir:J.options.output.path,fileSystem:J.outputFileSystem,headers:k.devServer.headers,https:k.devServer.https,host:k.devServer.host,open:k.devServer.open,basename:k.basename,onRequest(e,t){if(!t.writableEnded){if("GET"===e.method){let o=new s(`${k.devServer.https?"https":"http"}://${e.headers.host}${e.url}`);if(W&&o.pathname===W)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(x({}))),!0;if(o.pathname===G)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(L)),!0;if(!q)return t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end($(G,L)),!0;if(o.pathname===A&&"text/event-stream"===e.headers.accept)return K(e,t,P),!0}return!1}}});function D(){n.exit(0)}z.on("close",()=>{M.close(P),K.close()});let Q=await Promise.all(g.map(H)),V=h(Q[0]||{},Q[1]||{});g.forEach(function(t){o(t,async function(){var o;let[r,i]=await Promise.all(g.map(H)),s=h(r||{},i||{}),p=u(V,s);1===Object.keys(p).length&&"proxy"in p?(m(a(`代理更新中...`,"yellow"),!0),m(a(`代理更新完成...`,"green"),!0),k.proxy=s.proxy,V.proxy=s.proxy,V=s):(V=s,l(a(`检测到工程配置${a(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),o=j,e(X?`netstat -ano | findstr :${o}`:`lsof -i :${o} -t`,(e,t)=>{if(e){l(a(`查找端口 ${o} 时发生错误: ${e.message}`,"red")),l(a("请尝试手动重启程序","yellow"));return}let r=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),i=X?r[0]?.split(/\s+/).pop()?.trim():r[0]?.trim();if(!i)return void l(a(`未找到占用端口 ${o} 的进程, 请尝试手动重启程序`,"yellow"));try{n.kill(Number(i),"SIGHUP")}catch(e){l(a(`终止进程 ${i} 时发生错误: ${e.message}`,"red"))}}))})});let X="win32"===n.platform;n.on("SIGHUP",function(){z.close(P);let e=t(n.argv[0],n.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",D)}),n.on("exit",function(){z.close(P)}),w(D);
|