@moneko/core 3.43.6 → 3.44.0
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/commom/paths.d.mts +2 -1
- package/lib/commom/paths.mjs +1 -1
- package/lib/dev/mock.mjs +1 -1
- package/package.json +1 -1
package/lib/commom/paths.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { tmpdir } from 'node:os';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
-
import { cwd, env } from 'node:process';
|
|
3
|
+
import { argv, cwd, env } from 'node:process';
|
|
4
4
|
import url from 'node:url';
|
|
5
5
|
import { fileExists } from '@moneko/utils';
|
|
6
|
+
import parseArgs from './parse-args.mjs';
|
|
6
7
|
declare const original: string[];
|
|
7
8
|
export declare const __dirname: string;
|
|
8
9
|
export declare const yarnArgv: Record<string, string> & {
|
package/lib/commom/paths.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{tmpdir as o}from"node:os";import{resolve as e}from"node:path";import{
|
|
1
|
+
import{tmpdir as o}from"node:os";import{resolve as e}from"node:path";import{argv as t,cwd as n,env as a}from"node:process";import r from"node:url";import{fileExists as c}from"@moneko/utils";import i from"./parse-args.mjs";let s=JSON.parse(a.npm_config_argv||'{"original":[]}').original;export const __dirname=r.fileURLToPath(new URL("..",import.meta.url));export const yarnArgv={};for(let o=0,e=s.length;o<e;o++){let e=s[o].split("=");Object.assign(yarnArgv,{[e[0]]:e[1]||!0})}export const CUSTOMCONFIG=a.npm_config_config||yarnArgv.config||a.__args__config__||i(t.slice(2)).config;let m=n(),p=e(m,"node_modules");export const TMP_DIR=e(o(),"@moneko");let g={nodeModules:p,pnpmNodeModules:e(p,".pnpm/node_modules"),denoNodeModules:e(p,".deno"),corePath:__dirname,programPath:m,CA_DIR:e(TMP_DIR,".ca"),webpackCachePath:e(p,".cache"),lintCachePath:e(p,".cache"),httpCachePath:e(p,".cache/http"),swcCachePath:e(p,".cache/.swc"),configPath:e(m,"config/index.ts"),customConfigPath:e(m,`config/${CUSTOMCONFIG}.ts`),coveragePath:e(m,"coverage/clover.xml"),pagesPath:e(m,"src/pages"),componentsPath:e(m,"components"),mockPath:e(m,"mock")};export const config_files=[c(g.configPath)&&g.configPath,c(g.customConfigPath)&&g.customConfigPath].filter(Boolean);export const routeDir="library"===a.APPTYPE?g.componentsPath:g.pagesPath;export default g;
|
package/lib/dev/mock.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:http";import{StringDecoder as t}from"node:string_decoder";import{URL as r}from"node:url";import{directoryExists as o,print as n}from"@moneko/utils";import{watch as a}from"chokidar";import{merge as s}from"webpack-merge";import i from"../commom/log.mjs";import c from"../commom/match-path.mjs";import m from"../commom/require.mjs";import{jsonSchema as p}from"./json-schema.mjs";function d(e,t,r){if(delete m.cache[t],r[t]){for(let o in r[t])Object.prototype.hasOwnProperty.call(r[t],o)&&(e[o]=null,delete e[o]);r[t]=null,delete r[t]}}export const yApiSchemaMock=(t,r)=>new Promise(o=>{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=p(t);void 0!==r?o(s(n,r)):o(n)}}catch(e){i(Error(e))}})})});export const yApiMock=(t,o)=>new Promise((n,a)=>{let s=new r(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:Object.fromEntries(s.searchParams)},m=e.request(c,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{n(JSON.parse(t))}catch(e){i(Error(e))}})});m.on("error",e=>{a(e.message)}),m.write(JSON.stringify(t.body)),m.end()});export default(e=>{if(!o(e.directory))return;let s={},
|
|
1
|
+
import e from"node:http";import{StringDecoder as t}from"node:string_decoder";import{URL as r}from"node:url";import{directoryExists as o,print as n}from"@moneko/utils";import{watch as a}from"chokidar";import{merge as s}from"webpack-merge";import i from"../commom/log.mjs";import c from"../commom/match-path.mjs";import m from"../commom/require.mjs";import{jsonSchema as p}from"./json-schema.mjs";function d(e,t,r){if(delete m.cache[t],r[t]){for(let o in r[t])Object.prototype.hasOwnProperty.call(r[t],o)&&(e[o]=null,delete e[o]);r[t]=null,delete r[t]}}export const yApiSchemaMock=(t,r)=>new Promise(o=>{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=p(t);void 0!==r?o(s(n,r)):o(n)}}catch(e){i(Error(e))}})})});export const yApiMock=(t,o)=>new Promise((n,a)=>{let s=new r(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:Object.fromEntries(s.searchParams)},m=e.request(c,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{n(JSON.parse(t))}catch(e){i(Error(e))}})});m.on("error",e=>{a(e.message)}),m.write(JSON.stringify(t.body)),m.end()});export default(e=>{if(!o(e.directory))return;let s=!0,p={},l={};return a(e.directory).on("all",async function(e,t){if("string"==typeof t){switch(n("Updating mock...",!0),e){case"add":case"change":try{d(l,t,p);let e=m(t).default;p[t]=e,l=Object.assign(l,e)}catch(e){i(Error(e))}break;case"unlink":d(l,t,p)}s?s=!1:n("Mock update successful",!0)}}),(e,o)=>{let n=new r(`http://localhost:3000${e.url}`),a=`${e.method} ${n.pathname}`,s=Object.keys(l).filter(function(e){return RegExp(`^${e.replace(/(:\w*)[^/]/g,"((?!/).)")}*$`).test(a)});if(l[a]||s&&s.length>0){let r=l[a]||l[s[0]];if(o.send=e=>o.end("string"==typeof e?e:JSON.stringify(e)),o.writeHead(200,{"Content-Type":e.headers["content-type"]}),"function"==typeof r){let a=c(s[0].split(" ")[1],n.pathname);return n.searchParams&&Object.assign(e,{query:Object.fromEntries(n.searchParams)}),a&&Object.assign(e,{params:a.params}),e.body=new Promise((r,o)=>{if(["GET","HEAD","OPTIONS"].includes(e.method?.toUpperCase()||""))return r(null);let n=e.headers["content-length"],a=e.headers["transfer-encoding"];if(!n&&!a)return r(null);let s=e.headers["content-type"]||"",c=[];e.on("data",e=>{c.push(e)}),e.on("end",()=>{let e=Buffer.concat(c);if(s.includes("application/json"))try{let o=new t("utf-8").write(e);r(JSON.parse(o))}catch(e){i(e)}else s.includes("application/octet-stream")||s.startsWith("image/")?r(e):s.includes("text/")?r(e.toString("utf-8")):s.includes("application/x-www-form-urlencoded")?r(m("querystring").parse(e.toString("utf-8"))):r(e)}),e.on("error",o)}),r(e,o),!0}return o.end("string"==typeof r?r:JSON.stringify(r)),!0}return!1}});
|