@moneko/core 3.20.1 → 3.20.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.
package/lib/dev.mjs CHANGED
@@ -1 +1 @@
1
- let e;import t from"express";import o from"https";import r from"multer";import i from"webpack";import s from"webpack-dev-middleware";import l from"webpack-hot-middleware";import{merge as n}from"webpack-merge";import m from"./build/server.mjs";import{commonConfig as a}from"./common.mjs";import{CONFIG as c,PUBLICPATH as p}from"./config.mjs";import{PORT as u,devLog as d}from"./dev/config.mjs";import f from"./dev/mock.mjs";import h from"./dev/proxy.mjs";import w from"./module.config.mjs";import g,{CUSTOMCONFIG as v}from"./paths.mjs";import{SSR as x,isLibrary as $,isReact as k}from"./process-env.mjs";import j from"./utils/has-pkg.mjs";import{empty as y,resolveProgram as b}from"./utils/index.mjs";import P from"./utils/progress.mjs";import S from"./utils/sigint-exit.mjs";import A from"./options/reslove.mjs";import{watchFile as C}from"fs";import{join as T}from"path";import{spawn as E,exec as M}from"child_process";import O from"./utils/log.mjs";import _ from"chalk";import{directoryExists as D,loadFile as I,loadFileSync as U}from"@moneko/utils";let{HotModuleReplacementPlugin:B,ProgressPlugin:G,WatchIgnorePlugin:H}=i,L=j("stylelint-webpack-plugin")&&(await import("stylelint-webpack-plugin")).default,R=j("eslint-webpack-plugin")&&(await import("eslint-webpack-plugin")).default,q=k&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,N=["js","jsx","ts","tsx","json","html","vue"],W=N.join(","),F=["css","scss","sass","less","ts","tsx","js","jsx"],X=F.join(","),z=["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],K=j("solid-refresh")||j("react-refresh"),J=`${p.endsWith("/")?"":"/"}__hmr__`,Q=new URLSearchParams({name:"client",path:J,dynamicPublicPath:!0,timeout:2e3,reload:!K,quiet:!0,noInfo:!0,overlay:!0}).toString(),V=a.output.path;x&&(V=b(`${$?"docs":"dist"}/client`));let Y=!!c.bar,Z=n(a,{entry:{main:[`${A.hotMiddlewareClient}?${Q}`]},output:{path:V},module:w(!1),plugins:[new B,new H({paths:[/\.d\.ts$/]}),q&&new q,R&&new R({fix:!0,threads:!0,files:[`${c.alias["@"]}/**/*.{${W}}`,$&&`${c.alias["@pkg"]}/**/*.{${W}}`].filter(Boolean),extensions:N,exclude:z,cache:!0,cacheLocation:`${g.lineCachePath}/.eslintcache`,lintDirtyModulesOnly:!0}),L&&new L({fix:!0,threads:!0,files:[`${c.alias["@"]}/**/*.{${X}}`,$&&`${c.alias["@pkg"]}/**/*.{${X}}`].filter(Boolean),extensions:F,exclude:z,cache:!0,cacheLocation:`${g.lineCachePath}/.stylelintcache`,lintDirtyModulesOnly:!0}),new G({handler(e,t,...o){let r=c.bar||{};P({showBar:Y,percentage:e,title:r.name||"Build",color:r.color,info:o.length?`[${t}] ${o.join(" ")}`:"",output:Z.output?.path})}})].filter(Boolean)}),ee=[Z];x&&ee.push(n(a,m));let et=i(ee);et.compilers[0].hooks.done.tap("client-log",e=>{d(null,e)});let eo=t(),er=r(),ei=s(et,{writeToDisk:!1,index:"index.html",headers:e=>({"Access-Control-Allow-Origin":e.headers.origin||"*","Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization","Access-Control-Allow-Methods":"GET, POST, OPTIONS, DELETE, PATCH, PUT",...c.devServer.headers}),serverSideRender:x,lastModified:!0,publicPath:Z.output?.publicPath}),es=l(et,{log:!1,path:J,heartbeat:2e3});if(eo.use(ei),eo.use(es),eo.use(t.static(T(g.programPath,"./public"))),c.proxy&&h(eo,c.proxy),D(g.mockPath)){let e=f(g.mockPath);eo.use(e)}let el=`${Z.output.path}/index.html`;if(eo.all("/*",er.any(),function(e,t,o){if("GET"!==e.method)return o();{let r=e.get("Accept");if(r?.includes("text/html")){let e=ei.context.outputFileSystem,o=e?.readFileSync?.(el);t.end(o)}else if("text/event-stream"===r&&e.url.endsWith(J))return e.url=J,es(e,t,o);else return o()}}),c.devServer.https){let[t,r]=await Promise.all([I(c.devServer.https.key),I(c.devServer.https.cert)]);if(!t)throw Error(`无法加载私钥。请检查路径和文件是否存在,并确保路径正确:${c.devServer.https.key}`);if(!r)throw Error(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${c.devServer.https.cert}`);e=o.createServer({key:t,cert:r},eo)}let en=(e||eo).listen(u,"0.0.0.0",()=>{});function em(){process.exit(0)}function ea(e,t){let o=U(e);t&&null!==o&&C(e,async function(){let r=U(e);o.trim().replace(/^\s*[\r\n]/gm,"")!==r?.trim().replace(/^\s*[\r\n]/gm,"")?(O(_.yellow(`检测到工程配置${_.blue(`[${t}]`)}变更, 程序即将重启...`)),M("win32"===process.platform?`netstat -ano | findstr :${u}`:`lsof -i :${u}`,(e,t,o)=>{let r=ec?t.split(/\s+/).pop():t.split("\n")[1]?.split(/\s+/)[1];r?process.kill(Number(r),"SIGHUP"):O(`未找到占用端口 ${u} 的进程`)})):O(_.gray(`未变更`))})}ea(g.configPath,"index"),ea(g.customConfigPath,v);let ec="win32"===process.platform;process.on("SIGHUP",function(){ei.close(y),en.close(y),en.closeAllConnections(),function(){let e=E(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",em)}()}),process.on("exit",function(){ei.close(y),en.close(y),en.closeAllConnections()}),S(em);
1
+ let e;import t from"express";import o from"https";import r from"multer";import i from"webpack";import s from"webpack-dev-middleware";import l from"webpack-hot-middleware";import{merge as n}from"webpack-merge";import m from"./build/server.mjs";import{commonConfig as a}from"./common.mjs";import{CONFIG as c,PUBLICPATH as p}from"./config.mjs";import{PORT as u,devLog as d}from"./dev/config.mjs";import f from"./dev/mock.mjs";import h from"./dev/proxy.mjs";import g from"./module.config.mjs";import w,{CUSTOMCONFIG as v}from"./paths.mjs";import{SSR as x,isLibrary as $,isReact as k}from"./process-env.mjs";import j from"./utils/has-pkg.mjs";import{empty as y,resolveProgram as b}from"./utils/index.mjs";import P from"./utils/progress.mjs";import S from"./utils/sigint-exit.mjs";import A from"./options/reslove.mjs";import{watchFile as C}from"fs";import{join as T}from"path";import{spawn as M,exec as B}from"child_process";import O from"./utils/log.mjs";import _ from"chalk";import{directoryExists as D,loadFile as E,loadFileSync as I}from"@moneko/utils";let{HotModuleReplacementPlugin:U,ProgressPlugin:G,WatchIgnorePlugin:H}=i,L=j("stylelint-webpack-plugin")&&(await import("stylelint-webpack-plugin")).default,R=j("eslint-webpack-plugin")&&(await import("eslint-webpack-plugin")).default,q=k&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,N=["js","jsx","ts","tsx","json","html","vue"],W=N.join(","),F=["css","scss","sass","less","ts","tsx","js","jsx"],X=F.join(","),z=["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],K=j("solid-refresh")||j("react-refresh"),J=`${p.endsWith("/")?"":"/"}__hmr__`,Q=new URLSearchParams({name:"client",path:J,dynamicPublicPath:!0,timeout:2e3,reload:!K,quiet:!0,noInfo:!0,overlay:!0}).toString(),V=a.output.path;x&&(V=b(`${$?"docs":"dist"}/client`));let Y=!!c.bar,Z=n(a,{entry:{main:[`${A.hotMiddlewareClient}?${Q}`]},output:{path:V},module:g(!1),plugins:[new U,new H({paths:[/\.d\.ts$/]}),q&&new q,R&&new R({fix:!0,threads:!0,files:[`${c.alias["@"]}/**/*.{${W}}`,$&&`${c.alias["@pkg"]}/**/*.{${W}}`].filter(Boolean),extensions:N,exclude:z,cache:!0,cacheLocation:`${w.lineCachePath}/.eslintcache`,lintDirtyModulesOnly:!0}),L&&new L({fix:!0,threads:!0,files:[`${c.alias["@"]}/**/*.{${X}}`,$&&`${c.alias["@pkg"]}/**/*.{${X}}`].filter(Boolean),extensions:F,exclude:z,cache:!0,cacheLocation:`${w.lineCachePath}/.stylelintcache`,lintDirtyModulesOnly:!0}),new G({handler(e,t,...o){let r=c.bar||{};P({showBar:Y,percentage:e,title:r.name||"Build",color:r.color,info:o.length?`[${t}] ${o.join(" ")}`:"",output:Z.output?.path})}})].filter(Boolean)}),ee=[Z];x&&ee.push(n(a,m));let et=i(ee);et.compilers[0].hooks.done.tap("client-log",e=>{d(null,e)});let eo=t(),er=r(),ei=s(et,{writeToDisk:!1,index:"index.html",headers:e=>({"Access-Control-Allow-Origin":e.headers.origin||"*","Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization","Access-Control-Allow-Methods":"GET, POST, OPTIONS, DELETE, PATCH, PUT",...c.devServer.headers}),serverSideRender:x,lastModified:!0,publicPath:Z.output?.publicPath}),es=l(et,{log:!1,path:J,heartbeat:2e3});if(eo.use(ei),eo.use(es),eo.use(t.static(T(w.programPath,"./public"))),c.proxy&&h(eo,c.proxy),D(w.mockPath)){let e=f(w.mockPath);eo.use(e)}let el=`${Z.output.path}/index.html`;if(eo.all("/*",er.any(),function(e,t,o){if("GET"!==e.method)return o();{let r=e.get("Accept");if(r?.includes("text/html")){let e=ei.context.outputFileSystem,o=e?.readFileSync?.(el);t.end(o)}else if("text/event-stream"===r&&e.url.endsWith(J))return e.url=J,es(e,t,o);else return o()}}),c.devServer.https){let[t,r]=await Promise.all([E(c.devServer.https.key),E(c.devServer.https.cert)]);t||(O(_.redBright(`无法加载私钥。请检查路径和文件是否存在,并确保路径正确:${c.devServer.https.key}`)),process.exit(1)),r||(O(_.redBright(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${c.devServer.https.cert}`)),process.exit(1)),e=o.createServer({key:t,cert:r},eo)}let en=(e||eo).listen(u,"0.0.0.0",()=>{});function em(){process.exit(0)}function ea(e,t){let o=I(e);t&&null!==o&&C(e,async function(){let r=I(e);o.trim().replace(/^\s*[\r\n]/gm,"")!==r?.trim().replace(/^\s*[\r\n]/gm,"")?(O(_.yellow(`检测到工程配置${_.blue(`[${t}]`)}变更, 程序即将重启...`)),B("win32"===process.platform?`netstat -ano | findstr :${u}`:`lsof -i :${u}`,(e,t,o)=>{let r=ec?t.split(/\s+/).pop():t.split("\n")[1]?.split(/\s+/)[1];r?process.kill(Number(r),"SIGHUP"):O(`未找到占用端口 ${u} 的进程`)})):O(_.gray(`未变更`))})}ea(w.configPath,"index"),ea(w.customConfigPath,v);let ec="win32"===process.platform;process.on("SIGHUP",function(){ei.close(y),en.close(y),en.closeAllConnections(),function(){let e=M(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",em)}()}),process.on("exit",function(){ei.close(y),en.close(y),en.closeAllConnections()}),S(em);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.20.1",
3
+ "version": "3.20.2",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",
@@ -246,8 +246,47 @@ export declare type ConfigType = {
246
246
  headers?: Record<string, string>;
247
247
  host?: string;
248
248
  port?: number;
249
+ /**
250
+ * 使用 HTTPS 服务器作为开发服务器
251
+ * @description
252
+ * 配置 HTTPS 开发服务器的密钥和证书路径。
253
+ *
254
+ * `key` 和 `cert` 参数指定了私钥和证书文件的位置。
255
+ * 请确保文件路径正确,并且文件存在于指定位置。
256
+ *
257
+ * 如果私钥或证书加载失败,请检查以下事项:
258
+ * 1. 文件路径是否正确。
259
+ * 2. 文件是否存在并具有正确的权限。
260
+ * 3. 文件内容是否有效。
261
+ *
262
+ * @example
263
+ * import type { ConfigType } from '@moneko/core';
264
+ * const conf: Partial<ConfigType> = {
265
+ * devServer: {
266
+ * https: {
267
+ * key: 'config/server.key',
268
+ * cert: 'config/server.cert',
269
+ * },
270
+ * },
271
+ * };
272
+ * export default conf;
273
+ */
249
274
  https?: {
275
+ /** 私钥文件的位置
276
+ * @example
277
+ * // 表示加载当前项目 config 目录下的 server.key
278
+ * 'config/server.key'
279
+ * // 表示加载当前项目根目录下的 server.key
280
+ * 'server.key'
281
+ */
250
282
  key: string;
283
+ /** 证书文件的位置
284
+ * @example
285
+ * // 表示加载当前项目 config 目录下的 server.cert
286
+ * 'config/server.cert'
287
+ * // 表示加载当前项目根目录下的 server.cert
288
+ * 'server.key'
289
+ */
251
290
  cert: string;
252
291
  };
253
292
  };
@@ -264,7 +303,7 @@ export declare type ConfigType = {
264
303
  * dirs: ['static']
265
304
  * }
266
305
  * };
267
- *
306
+ *
268
307
  * export default conf;
269
308
  * ```
270
309
  */