@moneko/core 3.32.1-beta.7 → 3.32.1-beta.8

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.d.mts ADDED
@@ -0,0 +1,51 @@
1
+ import { exec, spawn } from 'node:child_process';
2
+ import { watchFile } from 'node:fs';
3
+ import { extname, relative, sep } from 'node:path';
4
+ import { ink, loadFile, print, println, progressBar } from '@moneko/utils';
5
+ import fastify, { type FastifyInstance } from 'fastify';
6
+ import webpack, { type WebpackPluginInstance } from 'webpack';
7
+ import webpackHotMiddleware, { type ClientOptions } from 'webpack-hot-middleware';
8
+ import { merge } from 'webpack-merge';
9
+ import { diffObject } from './commom/diff-object.mjs';
10
+ import mime from './commom/mime.mjs';
11
+ import paths, { config_files } from './commom/paths.mjs';
12
+ import sigintExit from './commom/sigint-exit.mjs';
13
+ import { devLog, PORT } from './dev/config.mjs';
14
+ import setupMock from './dev/mock.mjs';
15
+ import { type ProxyConfig, setupProxy } from './dev/proxy.mjs';
16
+ import reslove from './options/reslove.mjs';
17
+ import ESLintPlugin from './plugin/eslint.mjs';
18
+ import StylelintPlugin from './plugin/stylelint.mjs';
19
+ import { empty } from './utils/index.mjs';
20
+ import { commonConfig } from './common.mjs';
21
+ import { CONFIG, getConfig, PUBLICPATH } from './config.mjs';
22
+ import type { ConfigType } from './index.mjs';
23
+ import moduleConfig from './module.config.mjs';
24
+ import { isLibrary, isReact, refresh } from './process-env.mjs';
25
+ type WebpackPlugin = new(opt?: object) => WebpackPluginInstance;
26
+ declare const hmrPath: string;
27
+ declare const clientParams: ClientOptions;
28
+ declare const hotParams: string;
29
+ declare const path: string | undefined;
30
+ declare const clientOption: webpack.Configuration;
31
+ declare function getLintFiles(exts: string[]);
32
+ declare const compilers: webpack.Compiler;
33
+ declare const watch: webpack.Watching;
34
+ interface FastifyOptions {
35
+ http2?: boolean;
36
+ https?: {
37
+ key: string;
38
+ cert: string;
39
+ };
40
+ }
41
+ declare const fastifyOptions: FastifyOptions;
42
+ declare const hotMiddleware: ReturnType<typeof webpackHotMiddleware>;
43
+ declare const app: FastifyInstance;
44
+ declare const normalHeaders: Record<string, string>;
45
+ declare function exit();
46
+ declare const _prev: ConfigType[];
47
+ declare let prev: ConfigType;
48
+ declare function watchConfig(filepath: string);
49
+ declare function restart();
50
+ declare const isWindow: boolean;
51
+ declare function killPort(port: number);
package/lib/dev.mjs ADDED
@@ -0,0 +1 @@
1
+ import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{extname as r,relative as s,sep as n}from"node:path";import{ink as i,loadFile as l,print as a,println as m,progressBar as c}from"@moneko/utils";import p from"fastify";import d from"webpack";import u from"webpack-hot-middleware";import{merge as h}from"webpack-merge";import{diffObject as g}from"./commom/diff-object.mjs";import f from"./commom/mime.mjs";import y,{config_files as w}from"./commom/paths.mjs";import $ from"./commom/sigint-exit.mjs";import{devLog as x,PORT as C}from"./dev/config.mjs";import v from"./dev/mock.mjs";import{setupProxy as j}from"./dev/proxy.mjs";import P from"./options/reslove.mjs";import S from"./plugin/eslint.mjs";import b from"./plugin/stylelint.mjs";import{empty as k}from"./utils/index.mjs";import{commonConfig as A}from"./common.mjs";import{CONFIG as T,getConfig as z,PUBLICPATH as E}from"./config.mjs";import H from"./module.config.mjs";import{isLibrary as O,isReact as R,refresh as _}from"./process-env.mjs";let I=`${E.endsWith("/")?"":"/"}__hmr__`,M=new URLSearchParams({name:"client",path:I,dynamicPublicPath:!0,timeout:2e3,reload:!_,quiet:!1,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),F=A.output.path,U=h(A,{entry:{main:[`${P.hotMiddlewareClient}?${M}`]},output:{path:F},module:H(!1),plugins:[new d.HotModuleReplacementPlugin,new d.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app|@moneko)).+/,/\.d\.ts$/]})]});if(U.plugins||(U.plugins=[]),R){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;U.plugins.push(new e({overlay:!1}))}function q(e){let t=e.join(","),o=[s(y.programPath,`${T.alias["@"]}/**/*.{${t}}`).replace(/\\/g,"/")];return O&&o.push(s(y.programPath,`${T.alias["@pkg"]}/**/*.{${t}}`).replace(/\\/g,"/")),o}if(T.eslint&&U.plugins.push(new S({fix:!0,cache:!0,cacheLocation:`${y.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",lintDirtyModulesOnly:!0,...T.eslint,files:q(["js","jsx","ts","tsx","json","html","vue"])})),T.stylelint&&U.plugins.push(new b({fix:!0,cache:!0,cacheLocation:`${y.lintCachePath}/.stylelintcache`,...T.stylelint,files:q(["css","scss","sass","less","ts","tsx","js","jsx"])})),T.bar){let e=T.bar,t=e.name||"Build";U.plugins.push(new d.ProgressPlugin({handler(o,r,...s){c(o||0,1,{msg:s.length?`[${r}] ${s.join(" ")}`:"",name:t,barColor:e.barColor,nameColor:e.nameColor,barBgColor:e.barBgColor,msgColor:e.msgColor}),1===o&&process.stdout.write("\r\x1b[2K")}}))}let B=d(U),L=B.watch({aggregateTimeout:300,poll:!0,ignored:/node_modules\/(?!(@app|@moneko)).+/},(e,t)=>{if(t.hasErrors()||t.hasWarnings())x(null,t);else{let e=setTimeout(()=>{clearTimeout(e),x(null,t)},0)}}),N={};if(T.devServer.https){let[e,t]=await Promise.all([l(T.devServer.https.key),l(T.devServer.https.cert)]);e||(m(i(`法加载私钥。请检查路径和文件是否存在,并确保路径正确:${T.devServer.https.key}`,"red")),process.exit(1)),t||(m(i(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${T.devServer.https.cert}`,"red")),process.exit(1)),N.http2=!0,N.https={key:e,cert:t}}let W=u(B,{log:!1,path:I,heartbeat:2e3}),D=p({logger:!1,...N});v(D,{directory:y.mockPath}),j(D,T.proxy);let G={"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","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0",...T.devServer.headers||{}};function K(){process.exit(0)}D.get(`/${I}`.replace("//","/"),async(e,t)=>{if("text/event-stream"===e.headers.accept){e.raw.url=I,W(e.raw,t.raw,()=>{t.raw.writableEnded&&(t.sent=!0)});return}}),D.addHook("onRequest",(e,t,o)=>{t.headers(G),e.headers.origin&&t.header("Access-Control-Allow-Origin",e.headers.origin);let s=B.outputFileSystem,i=`${U.output.path}${n}${e.url}`;if(s.existsSync?.(i)){let o=e.headers["accept-encoding"],n=o?.includes("gzip"),l=s.existsSync?.(`${i}.gz`);n&&l&&t.header("content-encoding","gzip");let a=s.createReadStream?.(n&&l?`${i}.gz`:i,{autoClose:!0});return a?.on("error",e=>{if(a.destroy(),!t.sent)return t.code(404).type("text/html").send(`File not found: ${e.message}`)}),t.type(f[r(i)]).send(a)}return o()}),D.setNotFoundHandler((e,t)=>{t.headers(G),e.headers.origin&&t.header("Access-Control-Allow-Origin",e.headers.origin);let o=B.outputFileSystem,r=`${U.output.path}${n}index.html`,s=e.headers["accept-encoding"],i=s?.includes("gzip"),l=o.existsSync?.(`${r}.gz`);i&&l&&t.header("content-encoding","gzip");let a=o.createReadStream?.(i&&l?`${r}.gz`:r,{autoClose:!0});return a?.on("error",e=>{if(a.destroy(),!t.sent)return t.code(404).type("text/html").send(`File not found: ${e.message}`)}),t.type("text/html").send(a)}),D.addHook("onClose",()=>{L.close(k),D.server.close(k)}),D.listen({port:C});let X=await Promise.all(w.map(z)),J=h(X[0]||{},X[1]||{});w.forEach(function(t){o(t,async function(){let[o,r]=await Promise.all(w.map(z)),s=h(o||{},r||{}),n=g(J,s);1===Object.keys(n).length&&"proxy"in n?(a(i(`代理更新中...`,"yellow"),!0),await j(D,s.proxy),a(i(`代理更新完成...`,"green"),!0),T.proxy=s.proxy,J.proxy=s.proxy,J=s):(J=s,m(i(`检测到工程配置${i(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e(Q?`netstat -ano | findstr :${C}`:`lsof -i :${C} -t`,(e,t)=>{if(e){m(i(`查找端口 ${C} 时发生错误: ${e.message}`,"red")),m(i("请尝试手动重启程序","yellow"));return}let o=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),r=Q?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!r){m(i(`未找到占用端口 ${C} 的进程, 请尝试手动重启程序`,"yellow"));return}try{process.kill(Number(r),"SIGHUP")}catch(e){m(i(`终止进程 ${r} 时发生错误: ${e.message}`,"red"))}}))})});let Q="win32"===process.platform;process.on("SIGHUP",function(){D.close(k),function(){let e=t(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",K)}()}),process.on("exit",function(){D.close(k)}),$(K);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.32.1-beta.7",
3
+ "version": "3.32.1-beta.8",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",