@moneko/core 4.6.0 → 4.6.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/lib/dev.mjs +2 -2
- package/package.json +1 -1
package/lib/dev.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import r from"node:process";import{URL as
|
|
2
|
-
`):(
|
|
1
|
+
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{sep as r}from"node:path";import i from"node:process";import{URL as s}from"node:url";import{ink as n,print as m,println as a,progressBar as l}from"@moneko/utils";import p from"webpack";import c from"webpack-hot-middleware";import{merge as f}from"webpack-merge";import{diffObject as h}from"./commom/diff-object.mjs";import d,{config_files as u}from"./commom/paths.mjs";import{relative as g}from"./commom/posix.mjs";import*as w from"./commom/rule.mjs";import y from"./commom/sigint-exit.mjs";import{devLog as j,PORT as $}from"./dev/config.mjs";import v from"./dev/generate-progress-html.mjs";import b from"./dev/server.mjs";import x from"./options/reslove.mjs";import{ESLintPlugin as C}from"./plugin/eslint.mjs";import{StylelintPlugin as _}from"./plugin/stylelint.mjs";import{empty as P}from"./utils/index.mjs";import{CONFIG as S,getConfig as k}from"./config.mjs";import{createDevelopmentConfiguration as E}from"./create-development-configuration.mjs";import{outputFileSystem as B}from"./file-system.mjs";import{isLibrary as H,refresh as I}from"./process-env.mjs";let O=!1,T="/____progress____",q={percentage:0,info:""},G="/__hmr__",L=new URLSearchParams({name:"client",path:G.substring(1),dynamicPublicPath:!0,timeout:2e3,reload:!I,quiet:!0,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),U=await E({watchOptions:{stdin:!0,aggregateTimeout:300,ignored:w.node_modules},entry:{main:[`${x.hotMiddlewareClient}?${L}`]},plugins:[new p.WatchIgnorePlugin({paths:[w.node_modules,/\.d\.ts$/]}),new p.ProgressPlugin({handler(e,t,...o){let r=o.length?`[${t}] ${o.join(" ")}`:" ";O||(q.info=r,q.percentage=e,O=1===e);let s=S.bar;if(s){let t=s.name||"Build";s.quiet?i.stdout.write(`${r}
|
|
2
|
+
`):(l(e||0,1,{msg:r,name:t,barColor:s.barColor,nameColor:s.nameColor,barBgColor:s.barBgColor,msgColor:s.msgColor}),1===e&&i.stdout.write("\r\x1b[2K"))}}})]});function A(e){let t=e.join(","),o=[g(d.programPath,`${S.alias["@"]}/**/*.{${t}}`).replaceAll(r,"/")];return H&&o.push(g(d.programPath,`${S.alias["@pkg"]}/**/*.{${t}}`).replaceAll(r,"/")),o}S.eslint&&U.plugins.push(new C({fix:!0,cache:!0,cacheLocation:`${d.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",files:A(["js","jsx","ts","tsx","json","html","vue"]),...S.eslint})),S.stylelint&&U.plugins.push(new _({fix:!0,cache:!0,cacheLocation:`${d.lintCachePath}/.stylelintcache`,files:A(["css","scss","sass","less","ts","tsx","js","jsx"]),...S.stylelint}));let F=p(U);if(!F)throw Error("无法创建编译器");F.outputFileSystem=B;let N=F.watch(F.options.watchOptions,j);if(!N)throw Error("无法创建监视器");F.hooks.done.tap("client-log",e=>{j(null,e)});let R=`${S.basename}/${G}`.replace(/\/+/g,"/"),J=c(F,{log:!1,path:R,heartbeat:2e3}),K=await b({port:$,root_dir:F.options.output.path,fileSystem:F.outputFileSystem,headers:S.devServer.headers,https:S.devServer.https,host:S.devServer.host,open:S.devServer.open,basename:S.basename,onRequest(e,t){if(!t.writableEnded){if("GET"===e.method){let o=new s(`${S.devServer.https?"https":"http"}://${e.headers.host}${e.url}`);if(o.pathname===T)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(q)),!0;if(!O)return t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(v(T,q)),!0;if(o.pathname===R&&"text/event-stream"===e.headers.accept)return J(e,t,P),!0}return!1}}});function M(){i.exit(0)}K.on("close",()=>{N.close(P),J.close()});let W=await Promise.all(u.map(k)),z=f(W[0]||{},W[1]||{});u.forEach(function(t){o(t,async function(){var o;let[r,s]=await Promise.all(u.map(k)),l=f(r||{},s||{}),p=h(z,l);1===Object.keys(p).length&&"proxy"in p?(m(n("代理更新中...","yellow"),!0),m(n("代理更新完成...","green"),!0),S.proxy=l.proxy,z.proxy=l.proxy,z=l):(z=l,a(n(`检测到工程配置${n(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),o=$,e(D?`netstat -ano | findstr :${o}`:`lsof -i :${o} -t`,(e,t)=>{if(e){a(n(`查找端口 ${o} 时发生错误: ${e.message}`,"red")),a(n("请尝试手动重启程序","yellow"));return}let r=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),s=D?r[0]?.split(/\s+/).pop()?.trim():r[0]?.trim();if(!s)return void a(n(`未找到占用端口 ${o} 的进程, 请尝试手动重启程序`,"yellow"));try{i.kill(Number(s),"SIGHUP")}catch(e){a(n(`终止进程 ${s} 时发生错误: ${e.message}`,"red"))}}))})});let D="win32"===i.platform;i.on("SIGHUP",function(){let e;K.close(),(e=t(i.argv[0],i.argv.slice(1),{detached:!1,stdio:"inherit"})).unref(),e.on("close",M)}),i.on("exit",function(){K.close()}),y(M);
|