@moneko/core 4.7.2 → 4.7.3-beta.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.
@@ -6,6 +6,7 @@ type ProxyItem = {
6
6
  ws?: boolean;
7
7
  pathRewrite?: Record<string, string>;
8
8
  headers?: Record<string, string>;
9
+ /** 抓取上游响应数据用于初始化 Mock 数据 */ harvester?: boolean;
9
10
  };
10
11
  export type ProxyConfig = Record<string, string | ProxyItem>;
11
12
  type IServerResponse = ServerResponse<IncomingMessage> & {
package/lib/dev/proxy.mjs CHANGED
@@ -1 +1 @@
1
- import{request as e}from"node:http";import{request as t}from"node:https";import{URL as r}from"node:url";import o from"../commom/log.mjs";import{containMockUrl as p}from"./mock.mjs";export async function setupProxy(n,i,a){if(i.writableEnded)return i;let s=n.url,h=Object.keys(a).find(e=>new RegExp(e).test(s));if(!h)return!1;let m="string"==typeof a[h]?{target:a[h],pathRewrite:void 0,changeOrigin:!0,secure:!0,ws:!1}:a[h],d=new r(m.target),l=s;if(m.pathRewrite&&"object"==typeof m.pathRewrite)for(let e in m.pathRewrite)Object.prototype.hasOwnProperty.call(m.pathRewrite,e)&&(l=s.replace(new RegExp(e),m.pathRewrite[e]));let w="https:"===d.protocol,c={method:n.method,hostname:d.hostname,port:d.port||(w?443:80),path:l,headers:{...n.headers},protocol:d.protocol};m.changeOrigin&&(c.headers.host=d.host);let f=w?t:e;return new Promise(e=>{let t=f(c,t=>{let o=t.statusCode||404,a=o>=400,s=!!p(`${n.method||"GET"} ${new r(`${d.origin}${n.url}`).pathname}`);if(a&&s)return e(!1);i.writeHead(o,t.headers),t.pipe(i),e(i)});t.on("error",t=>(o(t),i.headersSent?i.end():(i.writeHead(502,{"Content-Type":"text/plain"}),i.end(`Proxy Error: ${t.message}`)),e(!1))),n.pipe(t)})}
1
+ import{request as e}from"node:http";import{request as t}from"node:https";import{URL as o}from"node:url";import r from"../commom/log.mjs";import{containMockUrl as n}from"./mock.mjs";export async function setupProxy(p,a,i){if(a.writableEnded)return a;let s=p.url,h=Object.keys(i).find(e=>new RegExp(e).test(s));if(!h)return!1;let m="string"==typeof i[h]?{target:i[h],pathRewrite:void 0,changeOrigin:!0,secure:!0,ws:!1}:i[h],c=new o(m.target),d=s;if(m.pathRewrite&&"object"==typeof m.pathRewrite)for(let e in m.pathRewrite)Object.prototype.hasOwnProperty.call(m.pathRewrite,e)&&(d=s.replace(new RegExp(e),m.pathRewrite[e]));let l="https:"===c.protocol,f={method:p.method,hostname:c.hostname,port:c.port||(l?443:80),path:d,headers:{...p.headers},protocol:c.protocol};m.changeOrigin&&(f.headers.host=c.host);let u=l?t:e;return new Promise(e=>{let t=u(f,r=>{let i=r.statusCode||404,s=i>=400,h=`${p.method||"GET"} ${new o(`${c.origin}${p.url}`).pathname}`,d=!!n(h);if(s&&d)return e(!1);if(a.writeHead(i,r.headers),!s&&!d&&m.harvester){let e=[];t.on("data",t=>e.push(t)),t.on("end",()=>{let t={" /":"➯","/":">",":":"◍"};updateFile(join(paths.mockPath,`${h.replace(/[\s/:]/g,e=>t[e]||e)}.ts`),`import type { MockConfiguration } from '@moneko/core';const conf: MockConfiguration = {'${h}': ${Buffer.concat(e).toString()}};export default conf;`)})}r.pipe(a),e(a)});t.on("error",t=>(r(t),a.headersSent?a.end():(a.writeHead(502,{"Content-Type":"text/plain"}),a.end(`Proxy Error: ${t.message}`)),e(!1))),p.pipe(t)})}
@@ -1 +1 @@
1
- import{merge as e}from"webpack-merge";import r from"../commom/paths.mjs";import{swcImportOnDemandConfig as o}from"../commom/transfer-import-on-demand.mjs";import{CONFIG as t}from"../config.mjs";import m,{coreJsVersion as s}from"../polyfills/polyfills.mjs";import{isDev as p,isReact as a,jsxImportSource as i}from"../process-env.mjs";import c from"./reslove.mjs";let l={include:m(),mode:"entry",coreJs:s};export default((m,s={})=>e({module:{type:"es6",resolveFully:!0},sync:!0,jsc:{parser:{syntax:"typescript",tsx:a,decorators:!0,dynamicImport:!0},loose:!0,target:t.polyfill?void 0:"es2017",externalHelpers:!1,transform:{legacyDecorator:!0,decoratorMetadata:!0,react:{runtime:t.reactJsxRuntime||"automatic",throwIfNamespace:!0,refresh:a&&p,development:p,importSource:i},optimizer:{simplify:!1}},experimental:{emitAssertForImportAttributes:!0,cacheRoot:r.swcCachePath,plugins:[!!(t.importOnDemand&&Object.keys(t.importOnDemand).length)&&[c.transformImports,o(t.importOnDemand)]].filter(Boolean)}},env:t.polyfill?l:void 0,sourceMaps:!0,parseMap:!0},"function"==typeof t.swcrc?t.swcrc(p):t.swcrc||{},s));
1
+ import{merge as e}from"webpack-merge";import r from"../commom/paths.mjs";import{swcImportOnDemandConfig as o}from"../commom/transfer-import-on-demand.mjs";import{CONFIG as t}from"../config.mjs";import m,{coreJsVersion as s}from"../polyfills/polyfills.mjs";import{isDev as p,isReact as a,jsxImportSource as i}from"../process-env.mjs";import c from"./reslove.mjs";let l={include:m(),mode:"entry",coreJs:s};export default((m,s={})=>e({module:{type:"es6",resolveFully:!0},sync:!0,jsc:{parser:{syntax:"typescript",tsx:a,decorators:!0,dynamicImport:!0},loose:!0,target:t.polyfill?void 0:"es2017",externalHelpers:!1,keepClassNames:!0,transform:{legacyDecorator:!0,decoratorMetadata:!0,react:{runtime:t.reactJsxRuntime||"automatic",throwIfNamespace:!0,refresh:a&&p,development:p,importSource:i},optimizer:{simplify:!1}},experimental:{emitAssertForImportAttributes:!0,cacheRoot:r.swcCachePath,plugins:[!!(t.importOnDemand&&Object.keys(t.importOnDemand).length)&&[c.transformImports,o(t.importOnDemand)]].filter(Boolean)}},env:t.polyfill?l:void 0,sourceMaps:!0,parseMap:!0},"function"==typeof t.swcrc?t.swcrc(p):t.swcrc||{},s));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "4.7.2",
3
+ "version": "4.7.3-beta.1",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",
@@ -160,5 +160,5 @@
160
160
  "lib",
161
161
  "typings"
162
162
  ],
163
- "packageManager": "pnpm@10.30.1"
163
+ "packageManager": "pnpm@10.30.2"
164
164
  }