@moneko/core 4.5.4 → 4.5.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.mjs CHANGED
@@ -1 +1 @@
1
- import{argv as o,exit as t}from"node:process";import{ink as e,println as s,removeDir as i}from"@moneko/utils";import{join as r}from"../commom/posix.mjs";import m from"../commom/setup-env.mjs";import{cwd as n,swcCachePath as c}from"./utils/config.mjs";import{getSwcOption as l}from"./utils/setup-swcrc.mjs";import{lesscCommonjs as p}from"./lessc.mjs";import d from"./tsc.mjs";export async function build(){let a=o[3],j=o[4],u=o.slice(5);a||(s(e(`type: 无效值 ${e(a,"245")}`,"red")),t(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 o="solid"===j?await import("@moneko/convert/solid"):await import("@moneko/convert"),{CONFIG:t}=await import("../config.mjs"),e="swc"===t.dts,s=[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=s.length;m<a;m++){if(i(r(n,`./${s[m].dir}`)),"react"===j){let t=await l();"es6"===s[m].type&&(t.jsc.target="es2015"),t.jsc.experimental.emitIsolatedDts=_&&e,t.jsc.experimental.cacheRoot=c,t.module.type=s[m].type,o.convert({outDir:s[m].dir,inputDir:"components",ignore:[/^.*\/__*__\//,/\.test\.(js|ts)x?$/,/\.DS_Store/,/\.mdx?$/,/^.*\/examples\//,/\.d\.(cj|mj|j|t|ct|mt)sx?$/],options:t})}else if("solid"===j){let e={jsxOptions:t.jsxDomExpressions,presetEnvOption:{modules:"commonjs"}};"es6"===s[m].type&&(e.presetEnvOption.modules=!1),o.convertSolid({outDir:s[m].dir,inputDir:"components",ignore:[/^.*\/__*__\//,/\.test\.(js|ts)x?$/,/\.DS_Store/,/\.mdx?$/,/^.*\/examples\//,/\.d\.(cj|mj|j|t|ct|mt)sx?$/],options:e})}"commonjs"===s[m].type&&p(),_&&!e&&d(s[m].dir)}}if("library"!==a||f&&"library"===a)try{await import("../build.mjs")}catch(o){s(e(Error(o).message,"red")),t(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 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/lessc.mjs CHANGED
@@ -1 +1 @@
1
- import{exec as e}from"node:child_process";import{loadFile as s,saveFile as o,scanFolderSync as t}from"@moneko/utils";import{join as m}from"../commom/paths.mjs";import l from"../commom/require.mjs";import{runtimePath as r}from"./utils/config.mjs";let i="";function n(s){let o=m(l.resolve("less"),"../bin/lessc");return new Promise((t,m)=>{e(`${r} ${o} --js ${i} ${s} > ${s.replace(/\.less$/g,".css")}`,function(e){if(e)return m(e);t(!0)})})}let a=/\*?\.less/g;async function c(e){let t=await s(e);t&&a.test(t)&&await o(e,t.replace(a,".css"))}export async function lesscCommonjs(){let e=t("lib",["\\.less$"]),s=(await import("../options/modify-vars.mjs")).default;for(let e in s)Object.hasOwnProperty.call(s,e)&&(i+=`--modify-var="${e}=${s[e]}" `);Promise.allSettled(e.map(n)),e.length&&Promise.allSettled(t("lib",["\\.js$"]).map(c))}
1
+ import{exec as e}from"node:child_process";import{join as o}from"node:path/posix";import{loadFile as s,saveFile as t,scanFolderSync as i}from"@moneko/utils";import l from"../commom/require.mjs";import{runtimePath as r}from"./utils/config.mjs";let m="";function n(s){let t=o(l.resolve("less"),"../bin/lessc");return new Promise((o,i)=>{e(`${r} ${t} --js ${m} ${s} > ${s.replace(/\.less$/g,".css")}`,function(e){if(e)return i(e);o(!0)})})}let a=/\*?\.less/g;async function c(e){let o=await s(e);o&&a.test(o)&&await t(e,o.replace(a,".css"))}export async function lesscCommonjs(){let e=i("lib",["\\.less$"]),o=(await import("../options/modify-vars.mjs")).default;for(let e in o)Object.hasOwnProperty.call(o,e)&&(m+=`--modify-var="${e}=${o[e]}" `);Promise.allSettled(e.map(n)),e.length&&Promise.allSettled(i("lib",["\\.js$"]).map(c))}
package/lib/bin/tsc.mjs CHANGED
@@ -1 +1 @@
1
- import{stdout as e}from"node:process";import t from"typescript";import{join as i}from"../commom/paths.mjs";import{cwd as o}from"./utils/config.mjs";async function s(s){return new Promise(n=>{let r=t.parseJsonConfigFileContent({extends:i(o,"tsconfig.json"),compilerOptions:{outDir:s,declaration:!0,emitDeclarationOnly:!0,skipLibCheck:!0,skipDefaultLibCheck:!0,noEmitOnError:!1},include:[i(o,"components"),i(o,"typings")],exclude:[i(o,"components/**/examples/*"),i(o,"components/**/__tests__/*"),i(o,"components/**/__mocks__/*")]},t.sys,o);r.options.incremental&&(r.options.tsBuildInfoFile=r.options.tsBuildInfoFile??i(s,".tsbuildinfo"));let m=t.createProgram(r.fileNames,r.options),a=m.emit();t.getPreEmitDiagnostics(m).concat(a.diagnostics).forEach(i=>{if(e.write("\n"),i.file){let{line:o,character:s}=i.file.getLineAndCharacterOfPosition(i.start),n=t.flattenDiagnosticMessageText(i.messageText,"\n");e.write(`${i.file.fileName} (${o+1},${s+1}): ${n}`)}else e.write(t.flattenDiagnosticMessageText(i.messageText,"\n"))}),n(!0)})}export default s;
1
+ import{join as e}from"node:path";import{stdout as t}from"node:process";import i from"typescript";import{cwd as o}from"./utils/config.mjs";async function n(n){return new Promise(s=>{let r=i.parseJsonConfigFileContent({extends:e(o,"tsconfig.json"),compilerOptions:{outDir:n,declaration:!0,emitDeclarationOnly:!0,skipLibCheck:!0,skipDefaultLibCheck:!0,noEmitOnError:!1},include:[e(o,"components"),e(o,"typings")],exclude:[e(o,"components/**/examples/*"),e(o,"components/**/__tests__/*"),e(o,"components/**/__mocks__/*")]},i.sys,o);r.options.incremental&&(r.options.tsBuildInfoFile=r.options.tsBuildInfoFile??e(n,".tsbuildinfo"));let a=i.createProgram(r.fileNames,r.options),c=a.emit();i.getPreEmitDiagnostics(a).concat(c.diagnostics).forEach(e=>{if(t.write("\n"),e.file){let{line:o,character:n}=e.file.getLineAndCharacterOfPosition(e.start),s=i.flattenDiagnosticMessageText(e.messageText,"\n");t.write(`${e.file.fileName} (${o+1},${n+1}): ${s}`)}else t.write(i.flattenDiagnosticMessageText(e.messageText,"\n"))}),s(!0)})}export default n;
package/lib/build-dev.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import o from"node:process";import{analyzeBundleSize as r,completedInfo as e,ink as t,println as m,progressBar as i}from"@moneko/utils";import a from"webpack";import n from"./commom/log.mjs";import s,{relative as l}from"./commom/paths.mjs";import{CONFIG as p}from"./config.mjs";import{createDevelopmentConfiguration as c}from"./create-development-configuration.mjs";let g=await c({});if(p.bar){let r=p.bar,e=r.name||"Build";g.plugins.push(new a.ProgressPlugin({handler(t,m,...a){let n=a.length?`[${m}] ${a.join(" ")}`:" ";r.quiet?o.stdout.write(`${n}
2
- `):(i(t||0,1,{msg:n,name:e,barColor:r.barColor,nameColor:r.nameColor,barBgColor:r.barBgColor,msgColor:r.msgColor}),1===t&&o.stdout.write("\r\x1b[2K"))}}))}let u=a(g);async function d(){let o=await new Promise((o,r)=>{u?.run((e,t)=>{e&&r(e),t?o(t):r(Error("编译过程中没有生成统计信息"))})});(o.hasErrors()||o.hasWarnings())&&function(o){let{warnings:r,errors:e}=o.compilation,i=[];r.forEach(o=>{o.message.includes("Conflicting order between css ./node_modules/")&&o.message.includes("monaco-editor")?i.push(o.message):m(t(o.message,"178"))}),i.length&&n(i.join("\n")),e.forEach(o=>{m(t(o.message,"red"))})}(o),await new Promise(i=>{o.compilation.compiler.cache.shutdown(a=>{a&&m(t(a.toString(),"red")),r(o.compilation.outputOptions.path,["\\.js$"]),e(~~((o.endTime-o.startTime)/10)/100,l(s.programPath,o.compilation.outputOptions.path)),i()})})}await d();
1
+ import o from"node:process";import{analyzeBundleSize as r,completedInfo as e,ink as m,println as t,progressBar as i}from"@moneko/utils";import s from"webpack";import a from"./commom/log.mjs";import n from"./commom/paths.mjs";import{relative as l}from"./commom/posix.mjs";import{CONFIG as p}from"./config.mjs";import{createDevelopmentConfiguration as c}from"./create-development-configuration.mjs";let g=await c({});if(p.bar){let r=p.bar,e=r.name||"Build";g.plugins.push(new s.ProgressPlugin({handler(m,t,...s){let a=s.length?`[${t}] ${s.join(" ")}`:" ";r.quiet?o.stdout.write(`${a}
2
+ `):(i(m||0,1,{msg:a,name:e,barColor:r.barColor,nameColor:r.nameColor,barBgColor:r.barBgColor,msgColor:r.msgColor}),1===m&&o.stdout.write("\r\x1b[2K"))}}))}let u=s(g);async function d(){let o=await new Promise((o,r)=>{u?.run((e,m)=>{e&&r(e),m?o(m):r(Error("编译过程中没有生成统计信息"))})});(o.hasErrors()||o.hasWarnings())&&function(o){let{warnings:r,errors:e}=o.compilation,i=[];r.forEach(o=>{o.message.includes("Conflicting order between css ./node_modules/")&&o.message.includes("monaco-editor")?i.push(o.message):t(m(o.message,"178"))}),i.length&&a(i.join("\n")),e.forEach(o=>{t(m(o.message,"red"))})}(o),await new Promise(i=>{o.compilation.compiler.cache.shutdown(s=>{s&&t(m(s.toString(),"red")),r(o.compilation.outputOptions.path,["\\.js$"]),e(~~((o.endTime-o.startTime)/10)/100,l(n.programPath,o.compilation.outputOptions.path)),i()})})}await d();
package/lib/build.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import o from"node:process";import{analyzeBundleSize as r,completedInfo as m,ink as e,println as i,progressBar as t}from"@moneko/utils";import s from"webpack";import{merge as n}from"webpack-merge";import a from"./build/common.mjs";import l from"./commom/log.mjs";import p,{relative as u}from"./commom/paths.mjs";import{DonePlugin as g}from"./plugin/done.mjs";import c from"./utils/seo.mjs";import{CONFIG as d}from"./config.mjs";import f from"./module.config.mjs";let h=n(a,{module:f(!1),plugins:[]});if(d.done&&h.plugins.push(new g({done:d.done})),d.bar){let r=d.bar,m=r.name||"Build";h.plugins.push(new s.ProgressPlugin({handler(e,i,...s){let n=s.length?`[${i}] ${s.join(" ")}`:" ";r.quiet?o.stdout.write(`${n}
2
- `):(t(e||0,1,{msg:n,name:m,barColor:r.barColor,nameColor:r.nameColor,barBgColor:r.barBgColor,msgColor:r.msgColor}),1===e&&o.stdout.write("\r\x1b[2K"))}}))}let w=s(h);if(!w)throw Error("无法创建编译器");async function b(){let o=await new Promise((o,r)=>{w?.run((m,e)=>{m&&r(m),e?o(e):r(Error("编译过程中没有生成统计信息"))})});(o.hasErrors()||o.hasWarnings())&&function(o){let{warnings:r,errors:m}=o.compilation,t=[];r.forEach(o=>{o.message.includes("Conflicting order between css ./node_modules/")&&o.message.includes("monaco-editor")?t.push(o.message):i(e(o.message,"178"))}),t.length&&l(t.join("\n")),m.forEach(o=>{i(e(o.message,"red"))})}(o),await new Promise(t=>{o.compilation.compiler.cache.shutdown(s=>{s&&i(e(s.toString(),"red")),r(o.compilation.outputOptions.path,["\\.js$"]),m(~~((o.endTime-o.startTime)/10)/100,u(p.programPath,o.compilation.outputOptions.path)),t()})}),d.seo&&c()}await b();
1
+ import o from"node:process";import{analyzeBundleSize as r,completedInfo as m,ink as e,println as i,progressBar as t}from"@moneko/utils";import s from"webpack";import{merge as n}from"webpack-merge";import a from"./build/common.mjs";import l from"./commom/log.mjs";import p from"./commom/paths.mjs";import{relative as u}from"./commom/posix.mjs";import{DonePlugin as c}from"./plugin/done.mjs";import g from"./utils/seo.mjs";import{CONFIG as d}from"./config.mjs";import f from"./module.config.mjs";let h=n(a,{module:f(!1),plugins:[]});if(d.done&&h.plugins.push(new c({done:d.done})),d.bar){let r=d.bar,m=r.name||"Build";h.plugins.push(new s.ProgressPlugin({handler(e,i,...s){let n=s.length?`[${i}] ${s.join(" ")}`:" ";r.quiet?o.stdout.write(`${n}
2
+ `):(t(e||0,1,{msg:n,name:m,barColor:r.barColor,nameColor:r.nameColor,barBgColor:r.barBgColor,msgColor:r.msgColor}),1===e&&o.stdout.write("\r\x1b[2K"))}}))}let w=s(h);if(!w)throw Error("无法创建编译器");async function b(){let o=await new Promise((o,r)=>{w?.run((m,e)=>{m&&r(m),e?o(e):r(Error("编译过程中没有生成统计信息"))})});(o.hasErrors()||o.hasWarnings())&&function(o){let{warnings:r,errors:m}=o.compilation,t=[];r.forEach(o=>{o.message.includes("Conflicting order between css ./node_modules/")&&o.message.includes("monaco-editor")?t.push(o.message):i(e(o.message,"178"))}),t.length&&l(t.join("\n")),m.forEach(o=>{i(e(o.message,"red"))})}(o),await new Promise(t=>{o.compilation.compiler.cache.shutdown(s=>{s&&i(e(s.toString(),"red")),r(o.compilation.outputOptions.path,["\\.js$"]),m(~~((o.endTime-o.startTime)/10)/100,u(p.programPath,o.compilation.outputOptions.path)),t()})}),d.seo&&g()}await b();
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 i}from"node:url";import{ink as s,print as n,println as a,progressBar as m}from"@moneko/utils";import l from"webpack";import p from"webpack-hot-middleware";import{merge as c}from"webpack-merge";import{diffObject as f}from"./commom/diff-object.mjs";import h,{config_files as u,relative as d}from"./commom/paths.mjs";import*as g from"./commom/rule.mjs";import w from"./commom/sigint-exit.mjs";import{devLog as y,PORT as $}from"./dev/config.mjs";import j from"./dev/generate-progress-html.mjs";import v from"./dev/server.mjs";import b from"./options/reslove.mjs";import{ESLintPlugin as x}from"./plugin/eslint.mjs";import{StylelintPlugin as C}from"./plugin/stylelint.mjs";import{empty as _}from"./utils/index.mjs";import{CONFIG as P,getConfig as S}from"./config.mjs";import{createDevelopmentConfiguration as k}from"./create-development-configuration.mjs";import{outputFileSystem as E}from"./file-system.mjs";import{isLibrary as B,refresh as H}from"./process-env.mjs";let I=!1,O="/____progress____",T={percentage:0,info:""},q="/__hmr__",G=new URLSearchParams({name:"client",path:q.substring(1),dynamicPublicPath:!0,timeout:2e3,reload:!H,quiet:!0,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),L=await k({watchOptions:{stdin:!0,aggregateTimeout:300,ignored:g.node_modules},entry:{main:[`${b.hotMiddlewareClient}?${G}`]},plugins:[new l.WatchIgnorePlugin({paths:[g.node_modules,/\.d\.ts$/]}),new l.ProgressPlugin({handler(e,t,...o){let i=o.length?`[${t}] ${o.join(" ")}`:" ";I||(T.info=i,T.percentage=e,I=1===e);let s=P.bar;if(s){let t=s.name||"Build";s.quiet?r.stdout.write(`${i}
2
- `):(m(e||0,1,{msg:i,name:t,barColor:s.barColor,nameColor:s.nameColor,barBgColor:s.barBgColor,msgColor:s.msgColor}),1===e&&r.stdout.write("\r\x1b[2K"))}}})]});function U(e){let t=e.join(","),o=[d(h.programPath,`${P.alias["@"]}/**/*.{${t}}`)];return B&&o.push(d(h.programPath,`${P.alias["@pkg"]}/**/*.{${t}}`)),o}P.eslint&&L.plugins.push(new x({fix:!0,cache:!0,cacheLocation:`${h.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",files:U(["js","jsx","ts","tsx","json","html","vue"]),...P.eslint})),P.stylelint&&L.plugins.push(new C({fix:!0,cache:!0,cacheLocation:`${h.lintCachePath}/.stylelintcache`,files:U(["css","scss","sass","less","ts","tsx","js","jsx"]),...P.stylelint}));let F=l(L);if(!F)throw Error("无法创建编译器");F.outputFileSystem=E;let N=F.watch(F.options.watchOptions,y);if(!N)throw Error("无法创建监视器");F.hooks.done.tap("client-log",e=>{y(null,e)});let R=`${P.basename}/${q}`.replace(/\/+/g,"/"),J=p(F,{log:!1,path:R,heartbeat:2e3}),K=await v({port:$,root_dir:F.options.output.path,fileSystem:F.outputFileSystem,headers:P.devServer.headers,https:P.devServer.https,host:P.devServer.host,open:P.devServer.open,basename:P.basename,onRequest(e,t){if(!t.writableEnded){if("GET"===e.method){let o=new i(`${P.devServer.https?"https":"http"}://${e.headers.host}${e.url}`);if(o.pathname===O)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(T)),!0;if(!I)return t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(j(O,T)),!0;if(o.pathname===R&&"text/event-stream"===e.headers.accept)return J(e,t,_),!0}return!1}}});function M(){r.exit(0)}K.on("close",()=>{N.close(_),J.close()});let W=await Promise.all(u.map(S)),z=c(W[0]||{},W[1]||{});u.forEach(function(t){o(t,async function(){var o;let[i,m]=await Promise.all(u.map(S)),l=c(i||{},m||{}),p=f(z,l);1===Object.keys(p).length&&"proxy"in p?(n(s("代理更新中...","yellow"),!0),n(s("代理更新完成...","green"),!0),P.proxy=l.proxy,z.proxy=l.proxy,z=l):(z=l,a(s(`检测到工程配置${s(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),o=$,e(A?`netstat -ano | findstr :${o}`:`lsof -i :${o} -t`,(e,t)=>{if(e){a(s(`查找端口 ${o} 时发生错误: ${e.message}`,"red")),a(s("请尝试手动重启程序","yellow"));return}let i=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),n=A?i[0]?.split(/\s+/).pop()?.trim():i[0]?.trim();if(!n)return void a(s(`未找到占用端口 ${o} 的进程, 请尝试手动重启程序`,"yellow"));try{r.kill(Number(n),"SIGHUP")}catch(e){a(s(`终止进程 ${n} 时发生错误: ${e.message}`,"red"))}}))})});let A="win32"===r.platform;r.on("SIGHUP",function(){let e;K.close(),(e=t(r.argv[0],r.argv.slice(1),{detached:!1,stdio:"inherit"})).unref(),e.on("close",M)}),r.on("exit",function(){K.close()}),w(M);
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 i}from"node:url";import{ink as s,print as n,println as m,progressBar as a}from"@moneko/utils";import l from"webpack";import p from"webpack-hot-middleware";import{merge as c}from"webpack-merge";import{diffObject as f}from"./commom/diff-object.mjs";import h,{config_files as u}from"./commom/paths.mjs";import{relative as d}from"./commom/posix.mjs";import*as g from"./commom/rule.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 x}from"./plugin/eslint.mjs";import{StylelintPlugin as C}from"./plugin/stylelint.mjs";import{empty as _}from"./utils/index.mjs";import{CONFIG as P,getConfig as S}from"./config.mjs";import{createDevelopmentConfiguration as k}from"./create-development-configuration.mjs";import{outputFileSystem as E}from"./file-system.mjs";import{isLibrary as B,refresh as H}from"./process-env.mjs";let I=!1,O="/____progress____",T={percentage:0,info:""},q="/__hmr__",G=new URLSearchParams({name:"client",path:q.substring(1),dynamicPublicPath:!0,timeout:2e3,reload:!H,quiet:!0,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),L=await k({watchOptions:{stdin:!0,aggregateTimeout:300,ignored:g.node_modules},entry:{main:[`${b.hotMiddlewareClient}?${G}`]},plugins:[new l.WatchIgnorePlugin({paths:[g.node_modules,/\.d\.ts$/]}),new l.ProgressPlugin({handler(e,t,...o){let i=o.length?`[${t}] ${o.join(" ")}`:" ";I||(T.info=i,T.percentage=e,I=1===e);let s=P.bar;if(s){let t=s.name||"Build";s.quiet?r.stdout.write(`${i}
2
+ `):(a(e||0,1,{msg:i,name:t,barColor:s.barColor,nameColor:s.nameColor,barBgColor:s.barBgColor,msgColor:s.msgColor}),1===e&&r.stdout.write("\r\x1b[2K"))}}})]});function U(e){let t=e.join(","),o=[d(h.programPath,`${P.alias["@"]}/**/*.{${t}}`)];return B&&o.push(d(h.programPath,`${P.alias["@pkg"]}/**/*.{${t}}`)),o}P.eslint&&L.plugins.push(new x({fix:!0,cache:!0,cacheLocation:`${h.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",files:U(["js","jsx","ts","tsx","json","html","vue"]),...P.eslint})),P.stylelint&&L.plugins.push(new C({fix:!0,cache:!0,cacheLocation:`${h.lintCachePath}/.stylelintcache`,files:U(["css","scss","sass","less","ts","tsx","js","jsx"]),...P.stylelint}));let F=l(L);if(!F)throw Error("无法创建编译器");F.outputFileSystem=E;let N=F.watch(F.options.watchOptions,y);if(!N)throw Error("无法创建监视器");F.hooks.done.tap("client-log",e=>{y(null,e)});let R=`${P.basename}/${q}`.replace(/\/+/g,"/"),J=p(F,{log:!1,path:R,heartbeat:2e3}),K=await v({port:j,root_dir:F.options.output.path,fileSystem:F.outputFileSystem,headers:P.devServer.headers,https:P.devServer.https,host:P.devServer.host,open:P.devServer.open,basename:P.basename,onRequest(e,t){if(!t.writableEnded){if("GET"===e.method){let o=new i(`${P.devServer.https?"https":"http"}://${e.headers.host}${e.url}`);if(o.pathname===O)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(T)),!0;if(!I)return t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end($(O,T)),!0;if(o.pathname===R&&"text/event-stream"===e.headers.accept)return J(e,t,_),!0}return!1}}});function M(){r.exit(0)}K.on("close",()=>{N.close(_),J.close()});let W=await Promise.all(u.map(S)),z=c(W[0]||{},W[1]||{});u.forEach(function(t){o(t,async function(){var o;let[i,a]=await Promise.all(u.map(S)),l=c(i||{},a||{}),p=f(z,l);1===Object.keys(p).length&&"proxy"in p?(n(s("代理更新中...","yellow"),!0),n(s("代理更新完成...","green"),!0),P.proxy=l.proxy,z.proxy=l.proxy,z=l):(z=l,m(s(`检测到工程配置${s(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),o=j,e(A?`netstat -ano | findstr :${o}`:`lsof -i :${o} -t`,(e,t)=>{if(e){m(s(`查找端口 ${o} 时发生错误: ${e.message}`,"red")),m(s("请尝试手动重启程序","yellow"));return}let i=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),n=A?i[0]?.split(/\s+/).pop()?.trim():i[0]?.trim();if(!n)return void m(s(`未找到占用端口 ${o} 的进程, 请尝试手动重启程序`,"yellow"));try{r.kill(Number(n),"SIGHUP")}catch(e){m(s(`终止进程 ${n} 时发生错误: ${e.message}`,"red"))}}))})});let A="win32"===r.platform;r.on("SIGHUP",function(){let e;K.close(),(e=t(r.argv[0],r.argv.slice(1),{detached:!1,stdio:"inherit"})).unref(),e.on("close",M)}),r.on("exit",function(){K.close()}),w(M);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "4.5.4",
3
+ "version": "4.5.5",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",