@moneko/core 3.26.12-beta.0 → 3.26.12-beta.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/mock.d.mts +18 -7
- package/lib/dev/mock.mjs +1 -1
- package/lib/dev/proxy.d.mts +15 -8
- package/lib/dev/proxy.mjs +1 -1
- package/lib/dev.d.mts +17 -14
- package/lib/dev.mjs +1 -1
- package/package.json +5 -6
- package/typings/global.d.ts +1 -4
package/lib/dev/mock.d.mts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
|
-
import { print } from '@moneko/utils';
|
|
2
|
+
import { directoryExists, print } from '@moneko/utils';
|
|
3
3
|
import { watch } from 'chokidar';
|
|
4
|
-
import
|
|
4
|
+
import type { FastifyPluginAsync, FastifyReply, FastifyRequest } from 'fastify';
|
|
5
5
|
import { merge } from 'webpack-merge';
|
|
6
6
|
import log from '../commom/log.mjs';
|
|
7
7
|
import matchPath from '../commom/match-path.mjs';
|
|
8
8
|
import require from '../commom/require.mjs';
|
|
9
9
|
import { jsonSchema } from './json-schema.mjs';
|
|
10
|
-
export interface RequestFormData extends
|
|
11
|
-
files
|
|
10
|
+
export interface RequestFormData extends FastifyRequest {
|
|
11
|
+
files?: {
|
|
12
|
+
fieldname: string;
|
|
13
|
+
originalname: string;
|
|
14
|
+
encoding: string;
|
|
15
|
+
mimetype: string;
|
|
16
|
+
buffer: Buffer;
|
|
17
|
+
size: number;
|
|
18
|
+
}[];
|
|
19
|
+
params: Record<string, string>;
|
|
12
20
|
}
|
|
13
|
-
export type ProxyFuncType = (req:
|
|
21
|
+
export type ProxyFuncType = (req: FastifyRequest, reply: FastifyReply, done: () => void) => void | Promise<void>;
|
|
14
22
|
export type MockConfiguration = Record<string, ProxyFuncType | Record<string, any> | null>;
|
|
15
23
|
declare function clearProxy(iproxy: MockConfiguration, path: string, old: MockConfiguration);
|
|
16
24
|
export type YApiOptionBySchema = {
|
|
@@ -26,5 +34,8 @@ export type YApiOption = {
|
|
|
26
34
|
pathRewrite: string;
|
|
27
35
|
};
|
|
28
36
|
export declare const yApiMock: (req: RequestFormData, yapi: YApiOption) => Promise<Any>;
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
export interface MockPluginOptions {
|
|
38
|
+
directory: string;
|
|
39
|
+
}
|
|
40
|
+
declare const setupMock: FastifyPluginAsync<MockPluginOptions>;
|
|
41
|
+
export default setupMock;
|
package/lib/dev/mock.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:http";import{print as
|
|
1
|
+
import e from"node:http";import{directoryExists as t,print as o}from"@moneko/utils";import{watch as r}from"chokidar";import{merge as a}from"webpack-merge";import n from"../commom/log.mjs";import s from"../commom/match-path.mjs";import c from"../commom/require.mjs";import{jsonSchema as m}from"./json-schema.mjs";function i(e,t,o){if(delete c.cache[t],o[t]){for(let r in o[t])Object.prototype.hasOwnProperty.call(o[t],r)&&(e[r]=null,delete e[r]);o[t]=null,delete o[t]}}export const yApiSchemaMock=(t,o)=>new Promise(r=>{e.get(`${t.host}/api/interface/get?id=${t.id}&token=${t.token}`,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{let e=JSON.parse(t);if(e?.data?.res_body_is_json_schema){let t=JSON.parse(e.data.res_body),n=m(t);void 0!==o?r(a(n,o)):r(n)}}catch(e){n(e)}})})});export const yApiMock=(t,o)=>new Promise((r,a)=>{let s=new URL(o.host),c={hostname:s.hostname,port:s.port,path:t.url.replace(new RegExp(o.pathRewrite),`/mock/${o.projectId}/`),method:t.method,headers:t.headers,query:t.query},m=e.request(c,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{r(JSON.parse(t))}catch(e){n(e)}})});m.on("error",e=>{a(e.message)}),m.write(JSON.stringify(t.body)),m.end()});let p=async(e,a)=>{if(!t(a.directory))return;let m={},p={};r(a.directory).on("all",async function(e,t){if("string"==typeof t){switch(o("Updating mock...",!0),e){case"add":case"change":try{i(p,t,m);let e=c(t).default;m[t]=e,p=Object.assign(p,e)}catch(e){n(e)}break;case"unlink":i(p,t,m)}o("Mock update successful",!0)}}),e.addHook("preHandler",(e,t,o)=>{let r=`${e.method} ${e.url}`,a=Object.keys(p).filter(function(e){return RegExp(`^${e.replace(/(:\w*)[^/]/g,"((?!/).)")}*$`).test(r)});if(p[r]||a&&a.length>0){let n=p[r]||p[a[0]];if("function"==typeof n){let r=s(a[0].split(" ")[1],e.url);r&&e.params&&"object"==typeof e.params&&Object.assign(e.params,r.params),n(e,t,o);return}t.send(n);return}o()})};export default p;
|
package/lib/dev/proxy.d.mts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import type { IncomingHttpHeaders } from 'node:http';
|
|
2
|
+
import httpProxy from '@fastify/http-proxy';
|
|
3
|
+
import type { FastifyInstance } from 'fastify';
|
|
4
|
+
import { empty } from '../utils/index.mjs';
|
|
5
|
+
type ProxyItem = {
|
|
6
|
+
target: string;
|
|
7
|
+
changeOrigin?: boolean;
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
ws?: boolean;
|
|
10
|
+
pathRewrite?: Record<string, string>;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
export type ProxyConfig = Record<string, string | ProxyItem>;
|
|
14
|
+
declare const registeredProxies: Set<string>;
|
|
15
|
+
export declare async function setupProxy(app: FastifyInstance, proxyConfig?: ProxyConfig);
|
package/lib/dev/proxy.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import e from"@fastify/http-proxy";import{empty as t}from"../utils/index.mjs";let r=new Set;export async function setupProxy(s,i){for(let e of r)s.all(`${e}*`,t);if(r.clear(),i)for(let[t,o]of Object.entries(i)){let i="string"==typeof o?{upstream:o}:{upstream:o.target,websocket:o.ws,rewritePrefix:Object.entries(o.pathRewrite||{}).reduce((e,[t,r])=>e.replace(new RegExp(t),r),t),replyOptions:{rewriteRequestHeaders:(e,t)=>({...t,...o.headers,host:new URL(o.target).host})}};s.register(e,{prefix:t,...i}),r.add(t)}}
|
package/lib/dev.d.mts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { exec, spawn } from 'node:child_process';
|
|
2
2
|
import { watchFile } from 'node:fs';
|
|
3
|
-
import type { IncomingMessage
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import multer, { type Multer } from 'multer';
|
|
3
|
+
import type { IncomingMessage } from 'node:http';
|
|
4
|
+
import compress from '@fastify/compress';
|
|
5
|
+
import { fastifyMiddie } from '@fastify/middie';
|
|
6
|
+
import { ink, loadFile, print, println, progressBar } from '@moneko/utils';
|
|
7
|
+
import fastify, { FastifyInstance } from 'fastify';
|
|
9
8
|
import webpack, { type WebpackPluginInstance } from 'webpack';
|
|
10
9
|
import middleware from 'webpack-dev-middleware';
|
|
11
10
|
import webpackHotMiddleware, { type ClientOptions } from 'webpack-hot-middleware';
|
|
@@ -13,10 +12,11 @@ import { merge } from 'webpack-merge';
|
|
|
13
12
|
import { diffObject } from './commom/diff-object.mjs';
|
|
14
13
|
import hasPkg from './commom/has-pkg.mjs';
|
|
15
14
|
import paths, { config_files } from './commom/paths.mjs';
|
|
15
|
+
import Rule from './commom/rule.mjs';
|
|
16
16
|
import sigintExit from './commom/sigint-exit.mjs';
|
|
17
17
|
import { devLog, PORT } from './dev/config.mjs';
|
|
18
|
-
import
|
|
19
|
-
import
|
|
18
|
+
import setupMock from './dev/mock.mjs';
|
|
19
|
+
import { type ProxyConfig, setupProxy } from './dev/proxy.mjs';
|
|
20
20
|
import reslove from './options/reslove.mjs';
|
|
21
21
|
import { empty, resolveProgram } from './utils/index.mjs';
|
|
22
22
|
import { commonConfig } from './common.mjs';
|
|
@@ -39,15 +39,18 @@ declare const bar: ConfigType['bar'];
|
|
|
39
39
|
declare const bar_name: string;
|
|
40
40
|
declare const clientOption: webpack.Configuration;
|
|
41
41
|
declare const compilers: webpack.Compiler;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
interface FastifyOptions {
|
|
43
|
+
http2?: boolean;
|
|
44
|
+
https?: {
|
|
45
|
+
key: string;
|
|
46
|
+
cert: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
declare const fastifyOptions: FastifyOptions;
|
|
45
50
|
declare const devMiddleware: middleware.API<IncomingMessage, middleware.ServerResponse>;
|
|
46
51
|
declare const hotMiddleware: ReturnType<typeof webpackHotMiddleware>;
|
|
52
|
+
declare const app: FastifyInstance;
|
|
47
53
|
declare const baseHtml: string;
|
|
48
|
-
declare let httpsServer: HttpsServer | undefined;
|
|
49
|
-
type Listen = HttpsServer<typeof IncomingMessage, typeof ServerResponse> | HttpServer<typeof IncomingMessage, typeof ServerResponse>;
|
|
50
|
-
declare const listen: Listen;
|
|
51
54
|
declare function exit();
|
|
52
55
|
declare const _prev: ConfigType[];
|
|
53
56
|
declare let prev: ConfigType;
|
package/lib/dev.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import r from"@fastify/compress";import{fastifyMiddie as i}from"@fastify/middie";import{ink as s,loadFile as l,print as n,println as a,progressBar as m}from"@moneko/utils";import c from"fastify";import p from"webpack";import d from"webpack-dev-middleware";import u from"webpack-hot-middleware";import{merge as f}from"webpack-merge";import{diffObject as h}from"./commom/diff-object.mjs";import g from"./commom/has-pkg.mjs";import w,{config_files as y}from"./commom/paths.mjs";import x from"./commom/rule.mjs";import v from"./commom/sigint-exit.mjs";import{devLog as k,PORT as $}from"./dev/config.mjs";import j from"./dev/mock.mjs";import{setupProxy as b}from"./dev/proxy.mjs";import C from"./options/reslove.mjs";import{empty as P,resolveProgram as S}from"./utils/index.mjs";import{commonConfig as A}from"./common.mjs";import{CONFIG as E,getConfig as T,PUBLICPATH as M}from"./config.mjs";import I from"./module.config.mjs";import{isLibrary as _,isReact as O,refresh as R}from"./process-env.mjs";let H=!1!==E.stylelint&&g("stylelint-webpack-plugin")&&(await import("stylelint-webpack-plugin")).default,q=!1!==E.eslint&&g("eslint-webpack-plugin")&&(await import("eslint-webpack-plugin")).default,z=O&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,B=["js","jsx","ts","tsx","json","html","vue"],D=B.join(","),U=["css","scss","sass","less","ts","tsx","js","jsx"],G=U.join(","),L=["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],W=`${M.endsWith("/")?"":"/"}__hmr__`,F=new URLSearchParams({name:"client",path:W,dynamicPublicPath:!0,timeout:2e3,reload:!R,quiet:!0,noInfo:!0,overlay:!0,autoConnect:!0}).toString(),N=A.output.path,K=E.bar.name||"Build",X=f(A,{entry:{main:[`${C.hotMiddlewareClient}?${F}`]},output:{path:N},module:I(!1),optimization:{minimize:!1,concatenateModules:!1,removeAvailableModules:!1,removeEmptyChunks:!0,providedExports:!0,usedExports:!1,sideEffects:!1,splitChunks:{chunks:"all",minChunks:1,minSize:30720,maxSize:0,maxAsyncRequests:60,maxInitialRequests:50,hidePathInfo:!1,cacheGroups:{vendors:{test:x.node_modules,priority:-10,reuseExistingChunk:!0},default:{minChunks:1,priority:-20,reuseExistingChunk:!0}}}},plugins:[new p.HotModuleReplacementPlugin,new p.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app|@moneko)).+/,/\.d\.ts$/]}),z&&new z,q&&new q({fix:!0,threads:!0,files:[`${E.alias["@"]}/**/*.{${D}}`,_&&`${E.alias["@pkg"]}/**/*.{${D}}`].filter(Boolean),extensions:B,exclude:L,cache:!0,cacheLocation:`${w.lintCachePath}/.eslintcache`,lintDirtyModulesOnly:!0,overrideConfigFile:S("eslint.config.mjs"),configType:"flat"}),H&&new H({fix:!0,threads:!0,files:[`${E.alias["@"]}/**/*.{${G}}`,_&&`${E.alias["@pkg"]}/**/*.{${G}}`].filter(Boolean),extensions:U,exclude:L,cache:!0,cacheLocation:`${w.lintCachePath}/.stylelintcache`,lintDirtyModulesOnly:!0}),!!E.bar&&new p.ProgressPlugin({handler(e,t,...o){m(e||0,1,K,o.length?`[${t}] ${o.join(" ")}`:""),1===e&&process.stdout.write("\r\x1b[2K")}})].filter(Boolean)}),J=p(X);J.hooks.done.tap("client-log",e=>{k(null,e)});let Q={};if(E.devServer.https){let[e,t]=await Promise.all([l(E.devServer.https.key),l(E.devServer.https.cert)]);e||(a(s(`法加载私钥。请检查路径和文件是否存在,并确保路径正确:${E.devServer.https.key}`,"red")),process.exit(1)),t||(a(s(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${E.devServer.https.cert}`,"red")),process.exit(1)),Q.http2=!0,Q.https={key:e,cert:t}}let V=d(J,{writeToDisk:!1,index:"index.html",headers:e=>({"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",...E.devServer.headers,"Access-Control-Allow-Origin":e.headers.origin||"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"}),serverSideRender:!1,lastModified:!0,publicPath:X.output?.publicPath,cacheControl:!1,cacheImmutable:!1}),Y=u(J,{log:!1,path:W,heartbeat:2e3}),Z=c({logger:!1,...Q});await Z.register(i),Z.use(V),Z.use(W,Y),j(Z,{directory:w.mockPath}),b(Z,E.proxy);let ee=`${X.output.path}/index.html`;function et(){process.exit(0)}Z.get("*",async(e,t)=>{if(e.headers.accept?.includes("text/html")){let e=V.context.outputFileSystem,o=e?.readFileSync?.(ee);if(!t.sent){t.type("text/html").send(o);return}}else if(e.url?.endsWith(W)&&"text/event-stream"===e.headers.accept){e.raw.url=W,Y(e.raw,t.raw,P);return}}),Z.addHook("onClose",()=>{V.close(P),Z.server.close(P)}),await Z.register(r,{global:!0}),Z.listen({port:$});let eo=await Promise.all(y.map(T)),er=f(eo[0]||{},eo[1]||{});y.forEach(function(t){o(t,async function(){let[o,r]=await Promise.all(y.map(T)),i=f(o||{},r||{}),l=h(er,i);1===Object.keys(l).length&&"proxy"in l?(n(s(`代理更新中...`,"yellow"),!0),await b(Z,i.proxy),n(s(`代理更新完成...`,"green"),!0),E.proxy=i.proxy,er.proxy=i.proxy,er=i):(er=i,a(s(`检测到工程配置${s(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e("win32"===process.platform?`netstat -ano | findstr :${$}`:`lsof -i :${$} -t`,(e,t)=>{if(e){a(s(`查找端口 ${$} 时发生错误: ${e.message}`,"red")),a(s("请尝试手动重启程序","yellow"));return}let o=t.trim().split("\n").filter(Boolean),r=ei?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!r){a(s(`未找到占用端口 ${$} 的进程, 请尝试手动重启程序`,"yellow"));return}try{process.kill(Number(r),"SIGHUP")}catch(e){a(s(`终止进程 ${r} 时发生错误: ${e.message}`,"red"))}}))})});let ei="win32"===process.platform;process.on("SIGHUP",function(){Z.close(P),function(){let e=t(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",et)}()}),process.on("exit",function(){Z.close(P)}),v(et);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.26.12-beta.
|
|
3
|
+
"version": "3.26.12-beta.2",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/core": "7.26.0",
|
|
19
|
+
"@fastify/compress": "7.0.3",
|
|
20
|
+
"@fastify/http-proxy": "9.5.0",
|
|
21
|
+
"@fastify/middie": "8.3.3",
|
|
19
22
|
"@moneko/mdx": "0.1.42",
|
|
20
23
|
"@moneko/transform-imports": "0.6.1",
|
|
21
24
|
"@moneko/utils": "0.1.19",
|
|
@@ -25,15 +28,13 @@
|
|
|
25
28
|
"chokidar": "4.0.2",
|
|
26
29
|
"core-js": "3.39.0",
|
|
27
30
|
"core-js-compat": "3.39.0",
|
|
28
|
-
"
|
|
31
|
+
"fastify": "4.29.0",
|
|
29
32
|
"html-webpack-plugin": "5.6.3",
|
|
30
|
-
"http-proxy-middleware": "3.0.3",
|
|
31
33
|
"less": "4.2.1",
|
|
32
34
|
"less-loader": "12.2.0",
|
|
33
35
|
"lightningcss": "1.28.2",
|
|
34
36
|
"marked-completed": "1.2.14",
|
|
35
37
|
"mini-css-extract-plugin": "2.9.2",
|
|
36
|
-
"multer": "1.4.5-lts.1",
|
|
37
38
|
"style-loader": "4.0.0",
|
|
38
39
|
"swc-loader": "0.2.6",
|
|
39
40
|
"terser-webpack-plugin": "5.3.11",
|
|
@@ -48,8 +49,6 @@
|
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@moneko/css": "1.1.5",
|
|
50
51
|
"@types/babel__core": "7.20.5",
|
|
51
|
-
"@types/express": "5.0.0",
|
|
52
|
-
"@types/multer": "1.4.12",
|
|
53
52
|
"@types/webpack-bundle-analyzer": "4.7.0",
|
|
54
53
|
"@types/webpack-hot-middleware": "2.25.9",
|
|
55
54
|
"eslint-config-neko": "3.0.2",
|
package/typings/global.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { MdxOptions } from '@moneko/mdx';
|
|
2
2
|
import type { Config as SwcConfig, JsMinifyOptions as SwcMinifyOptions } from '@swc/core';
|
|
3
3
|
import type { Options as HtmlWebpackPluginOptions } from 'html-webpack-plugin';
|
|
4
|
-
import type { Options } from 'http-proxy-middleware';
|
|
5
4
|
import type { PluginOptions as MiniCssExtractPluginOptions } from 'mini-css-extract-plugin';
|
|
6
5
|
import type { MinifyOptions as TerserMinifyOptions } from 'terser';
|
|
7
6
|
import type {
|
|
@@ -19,6 +18,7 @@ import type {
|
|
|
19
18
|
JsxDomExpressions,
|
|
20
19
|
OptimizationSplitChunksOptions,
|
|
21
20
|
OverrideResolverOption,
|
|
21
|
+
ProxyConfig,
|
|
22
22
|
VirtualModulePluginOption,
|
|
23
23
|
} from '../lib/index';
|
|
24
24
|
import type { CopyPluginOption } from '../lib/plugin/copy.mjs';
|
|
@@ -30,9 +30,6 @@ export type { MiniCssExtractPluginOptions, SwcMinifyOptions, TerserMinifyOptions
|
|
|
30
30
|
export type MinifierType = 'swc' | 'terser';
|
|
31
31
|
export declare type AppType = 'mobile' | 'site' | 'backstage' | 'micro' | 'library';
|
|
32
32
|
export declare type Framework = 'react' | 'solid';
|
|
33
|
-
export interface ProxyConfig {
|
|
34
|
-
[key: string]: Options;
|
|
35
|
-
}
|
|
36
33
|
|
|
37
34
|
export type HtmlWebpackOption = HtmlWebpackPluginOptions & {
|
|
38
35
|
/**
|