@moneko/core 4.0.0-beta.6 → 4.0.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.
- package/lib/common.mjs +1 -1
- package/lib/dev/mock.d.mts +2 -2
- package/lib/dev/mock.mjs +1 -1
- package/package.json +1 -1
package/lib/common.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extname as e,join as t,resolve as o}from"node:path";import{argv as s}from"node:process";import a,{config_files as n,CUSTOMCONFIG as i,TMP_DIR as r}from"./commom/paths.mjs";import l from"./commom/rule.mjs";import{OverrideResolverPlugin as m}from"./plugin/override-resolve.mjs";import{digest as c,isObject as p,resolveProgram as u}from"./utils/index.mjs";import
|
|
1
|
+
import{extname as e,join as t,resolve as o}from"node:path";import{argv as s}from"node:process";import a,{config_files as n,CUSTOMCONFIG as i,TMP_DIR as r}from"./commom/paths.mjs";import l from"./commom/rule.mjs";import{OverrideResolverPlugin as m}from"./plugin/override-resolve.mjs";import{digest as c,isObject as p,resolveProgram as u}from"./utils/index.mjs";import h from"./vm/info.mjs";import{CONFIG as d}from"./config.mjs";import f from"./plugins.config.mjs";import{app_schema as g,isCI as y,isDev as b,isLibrary as j,NODE_ENV as v,packageJson as C}from"./process-env.mjs";export const outputConfig={path:u(j?"docs":"dist"),filename:e=>e.filename?.includes(".worker")?"worker/[name].js":"js/[name].[contenthash].bundle.js",chunkFilename:"js/[contenthash].chunk.js",cssFilename:"style/[contenthash].css",cssChunkFilename:"style/[contenthash].chunk.css",assetModuleFilename:t=>{let o=e(t.filename||"").substring(1);return`assets/${o}/[hash][ext]`},library:{name:`${h.projectName}`,type:"umd",umdNamedDefine:!0},globalObject:"self",chunkLoadingGlobal:`webpackJsonp_${C.name}`,pathinfo:b,clean:!0,publicPath:d.publicPath,asyncChunks:!0,charset:!0,iife:!0,crossOriginLoading:"use-credentials",enabledWasmLoadingTypes:["fetch"],uniqueName:`${h.projectName}`};let P={main:[`${g}:entry`]},k=[t(a.corePath,"./polyfills/public-path.mjs")];if(b&&d.refresh&&d.env.injectRemoteReactRefresh&&k.push(t(a.corePath,"./polyfills/inject-react-refresh.mjs")),d.polyfill&&k.push(t(a.corePath,"./polyfills/replace-children.mjs")),d.entry&&("string"==typeof d.entry?P={...P,main:[d.entry]}:Object.keys(d.entry)&&(P=Object.assign(P,d.entry))),"string"==typeof P.main?P.main=[...k,P.main]:Array.isArray(P.main)&&(P.main=[...k,...P.main]),d.output){if("string"==typeof d.output)outputConfig.path=d.output;else if(Object.keys(d.output)){let e=d.output,t={...outputConfig.library};Object.assign(outputConfig,e),"object"==typeof d.output&&e.library&&(outputConfig.library=Object.assign(t,e.library))}}let x={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:a.webpackCachePath,memoryCacheUnaffected:!b,name:c(`${i}-${v}-${s[2]}`),version:`${C.version}`,buildDependencies:{config:n},maxMemoryGenerations:1};!1===d.cache?x=!1:p(d.cache)&&(x=Object.assign(x,d.cache)),y&&(void 0===d.cache||d.cache&&!d.cache.cacheDirectory)&&(x.cacheDirectory=o(r,C.name));let M={},O={imports:!0,entries:!0,test:e=>{let o=e.nameForCondition();return!!(o&&(/^[a-z][a-z0-9]*:.+$/.test(o)||o?.startsWith(t(a.programPath,"src"))||o?.startsWith(t(a.programPath,"site"))||o?.startsWith(a.componentsPath)))}};d.lazyCompilation&&b&&"true"!==process.env.IS_BUILD?p(d.lazyCompilation)?Object.assign(M,O,d.lazyCompilation):Object.assign(M,O):M=!1;export const commonConfig={name:"client",target:"web",devtool:d.devtool,entry:P,mode:d.mode??"production",cache:x,snapshot:{immutablePaths:[a.pnpmNodeModules,a.denoNodeModules,l.node_modules],managedPaths:[a.pnpmNodeModules,a.denoNodeModules,l.node_modules],resolveBuildDependencies:{timestamp:!0,hash:!0},resolve:{timestamp:!0,hash:!0},module:{timestamp:!0,hash:!0},buildDependencies:{timestamp:!0,hash:!0},contextModule:{timestamp:!0,hash:!0}},stats:"errors-only",infrastructureLogging:{level:"error"},externalsPresets:d.externalsPresets,plugins:f,node:{global:!1,__filename:!1,__dirname:!1},experiments:{asyncWebAssembly:!0,cacheUnaffected:!b,lazyCompilation:M,buildHttp:p(d.buildHttp)?{allowedUris:[],lockfileLocation:o(a.httpCachePath,"http.lock"),cacheLocation:o(a.httpCachePath,"data"),upgrade:!0,...d.buildHttp}:d.buildHttp,backCompat:!0,futureDefaults:!0,css:!0,outputModule:!1},resolve:{extensions:[".mts",".mjs",".ts",".tsx",".js",".jsx",".json",".wasm"],alias:d.alias,modules:[a.nodeModules,a.pnpmNodeModules,a.denoNodeModules],mainFields:["browser","module","main"],mainFiles:["index"],plugins:d.resolvePlugins,preferAbsolute:!0,cache:!0,fallback:{}},externals:d.externals,output:outputConfig,recordsPath:d.recordsPath};d.overrideResolve&&commonConfig.resolve.plugins.push(new m(Object.assign({original:d.alias["@"],override:i&&u(i)},d.overrideResolve)));
|
package/lib/dev/mock.d.mts
CHANGED
|
@@ -54,9 +54,9 @@ export type YApiOption = {
|
|
|
54
54
|
*/
|
|
55
55
|
export declare const yApiMock: (req: RequestFormData, yapi: YApiOption) => Promise<Any>;
|
|
56
56
|
export declare function containMockUrl(url: string): string | undefined;
|
|
57
|
-
declare const setupMock: () => (req: RequestFormData, res: ServerResponse<IncomingMessage> & {
|
|
57
|
+
declare const setupMock: () => ((req: RequestFormData, res: ServerResponse<IncomingMessage> & {
|
|
58
58
|
req: IncomingMessage;
|
|
59
59
|
}) => boolean | (http.ServerResponse<http.IncomingMessage> & {
|
|
60
60
|
req: IncomingMessage;
|
|
61
|
-
});
|
|
61
|
+
})) | undefined;
|
|
62
62
|
export default setupMock;
|
package/lib/dev/mock.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{watch as e}from"node:fs";import t from"node:http";import{join as r}from"node:path";import{StringDecoder as o}from"node:string_decoder";import{URL as n}from"node:url";import{directoryExists as a,ink as i,print as
|
|
1
|
+
import{watch as e}from"node:fs";import t from"node:http";import{join as r}from"node:path";import{StringDecoder as o}from"node:string_decoder";import{URL as n}from"node:url";import{directoryExists as a,ink as i,print as c,scanFolderSync as s}from"@moneko/utils";import{merge as m}from"webpack-merge";import d from"../commom/log.mjs";import l from"../commom/match-path.mjs";import p from"../commom/paths.mjs";import f,{METHOD_COLOR as u}from"../commom/print-log.mjs";import h from"../commom/require.mjs";import g from"../commom/sigint-exit.mjs";import{jsonSchema as y}from"./json-schema.mjs";function b(e){return!["GET","HEAD","OPTIONS"].includes(e.method?.toUpperCase()||"")}export function cacheBody(e){if(!e._bodyCached&&b(e)&&!e.readableEnded){e._bodyCached=!0;try{let t=[],r=e.on.bind(e),o=e.emit.bind(e),n=!1;e.on=function(e,o){return"data"!==e||n||(n=!0,r("data",e=>{t.push(e)})),r(e,o)};let a=!1;e.emit=function(r,...n){return"end"===r&&!a&&(a=!0,t.length>0&&(e._dataChunks=t)),o.call(this,r,...n)}}catch(e){d(e)}}}function k(e,t){try{let r=Buffer.concat(e);if(t.includes("application/json")){let e=new o("utf-8").write(r);return JSON.parse(e)}if(t.includes("application/octet-stream")||t.startsWith("image/"));else if(t.includes("text/"))return r.toString("utf-8");else if(t.includes("application/x-www-form-urlencoded"))return Object.fromEntries(new URLSearchParams(r.toString("utf8")));return r}catch(e){return d(e),null}}async function j(e){return new Promise(t=>{if(!b(e))return void t(null);let r=e.headers["content-type"]||"",o=e.headers["content-length"],n=e.headers["transfer-encoding"],a=[];void 0!==e._dataChunks?t(k(e._dataChunks,r)):o||n?(e.on("data",e=>{a.push(e)}),e.on("end",()=>{t(k(a,r))}),e.on("error",e=>{t(null),d(e)})):t(null)})}export const yApiSchemaMock=(e,r)=>new Promise(o=>{t.get(`${e.host}/api/interface/get?id=${e.id}&token=${e.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=y(t);void 0!==r?o(m(n,r)):o(n)}}catch(e){d(e)}})})});export const yApiMock=(e,r)=>new Promise((o,a)=>{let i=new n(r.host),c={hostname:i.hostname,port:i.port,path:e.url?.replace(new RegExp(r.pathRewrite),`/mock/${r.projectId}/`),method:e.method,headers:e.headers,query:Object.fromEntries(i.searchParams)},s=t.request(c,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{o(JSON.parse(t))}catch(e){d(e)}})});s.on("error",e=>{a(e.message)}),s.write(JSON.stringify(e.body)),s.end()});let w=()=>{if(!a(p.mockPath)){O={};return}let e={},t=s(p.mockPath,["\\.(t|j)s$"]);c(i("Updating mock...","245"),!0),t.forEach(t=>{try{Object.assign(e,h(t).default)}catch(e){d(e)}}),c(i("Mock update successful","245"),!0),O=e},O={};w();export function containMockUrl(e){return Object.keys(O).find(t=>RegExp(`^${t.replace(/(:\w*)[^/]/g,"((?!/).)")}*$`).test(e))}export default(()=>{if(a(p.mockPath))return g(e(p.mockPath,(e,t)=>{if(t){let e=r(p.mockPath,t);delete h.cache[e]}w()}).close),(e,t)=>{if(t.writableEnded)return t;let r=new n(`http://localhost:3000${e.url}`),o=e.method||"GET",a=`${o} ${r.pathname}`,i=containMockUrl(a)||a,c=O[i];if(c){if(f(o,r.pathname,{note:"MOCK",labelAlign:"center",labelLen:8,labelForegroundColor:u[o].fg,labelBackgroundColor:u[o].bg}),t.send=e=>t.end("string"==typeof e?e:JSON.stringify(e)),t.writeHead(200,{"Content-Type":e.headers["content-type"]}),"function"==typeof c){let o=l(i.split(" ")[1],r.pathname);r.searchParams&&Object.assign(e,{query:Object.fromEntries(r.searchParams)}),o&&Object.assign(e,{params:o.params}),e.body=j(e);try{c(e,t)}catch(e){d(e)}return!0}return t.end("string"==typeof c?c:JSON.stringify(c)),!0}return!1}});
|