@moneko/core 3.17.43 → 3.17.45-beta.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/config.mjs CHANGED
@@ -1 +1 @@
1
- import{merge as e}from"webpack-merge";import o from"./options/jsx-dom-expressions.mjs";import t from"./options/split-chunk.mjs";import s,{CUSTOMCONFIG as i}from"./paths.mjs";import{APPTYPE as n,FRAMEWORK as r,NODE_ENV as a,PACKAGENAME as l,isDev as m,isLibrary as p,isMobile as c,jsxImportSource as u,mainDirectory as d}from"./process-env.mjs";import{isFunction as f,resolveProgram as h}from"./utils/index.mjs";import x from"./utils/setup-env.mjs";import{fileExists as g}from"@moneko/utils";import{vts as v}from"./utils/vts.mjs";let P=["@moneko","neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app",".cache/http/data"],j={devtool:m?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:x(a,n,r),basename:"/",publicPath:"auto",rem:{designSize:c?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:{"@":h(d)},moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3},htmlPluginOption:{},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:t,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:P,js:P,media:P,font:P,wasm:[]},mdx:{jsx:!1,development:m,jsxImportSource:u,providerImportSource:`@moneko/${r}/mdx`},jsxDomExpressions:o,bar:{name:"Client",color:"#6f42c1"},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:{maxAssetSize:256e3,maxEntrypointSize:256e3,assetFilter:e=>e.endsWith(".js")}};async function w(e,o){if(o&&g(e)){let o=v(e);return f(o)?o(process):o}return{}}p&&(j.alias=Object.assign(j.alias,{"@pkg":s.componentsPath,[l]:s.componentsPath}));let k=j;(!1===(k=e(k,await w(s.configPath,"index"),await w(s.customConfigPath,i))).devtool||!1===k.sourceMap)&&(k.sourceMap=!1,k.devtool=!1),k.fixBrowserRouter&&k.htmlPluginOption&&(k.htmlPluginOption.tags||(k.htmlPluginOption.tags=[]),k.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}));export const CONFIG=k;export const PUBLICPATH=CONFIG.publicPath||"auto";
1
+ import{merge as e}from"webpack-merge";import o from"./options/jsx-dom-expressions.mjs";import t from"./options/split-chunk.mjs";import s from"./paths.mjs";import{APPTYPE as i,FRAMEWORK as r,NODE_ENV as n,PACKAGENAME as a,isDev as l,isLibrary as m,isMobile as p,jsxImportSource as c,mainDirectory as u}from"./process-env.mjs";import{isFunction as d,resolveProgram as f}from"./utils/index.mjs";import h from"./utils/setup-env.mjs";import{fileExists as g}from"@moneko/utils";import{tempConfig as x}from"./utils/temp.mjs";let v=["@moneko","neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app",".cache/http/data"],P={devtool:l?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:h(n,i,r),basename:"/",publicPath:"auto",rem:{designSize:p?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:{"@":f(u)},moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3},htmlPluginOption:{},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:t,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:v,js:v,media:v,font:v,wasm:[]},mdx:{jsx:!1,development:l,jsxImportSource:c,providerImportSource:`@moneko/${r}/mdx`},jsxDomExpressions:o,bar:{name:"Client",color:"#6f42c1"},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:{maxAssetSize:256e3,maxEntrypointSize:256e3,assetFilter:e=>e.endsWith(".js")}};async function j(e){if(g(e)){let o=await x(e);return d(o)?o(process):o}return{}}m&&(P.alias=Object.assign(P.alias,{"@pkg":s.componentsPath,[a]:s.componentsPath}));let w=P,[k,C]=await Promise.all([j(s.configPath),j(s.customConfigPath)]);(!1===(w=e(w,k,C)).devtool||!1===w.sourceMap)&&(w.sourceMap=!1,w.devtool=!1),w.fixBrowserRouter&&w.htmlPluginOption&&(w.htmlPluginOption.tags||(w.htmlPluginOption.tags=[]),w.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}));export const CONFIG=w;export const PUBLICPATH=CONFIG.publicPath||"auto";
package/lib/dev/mock.mjs CHANGED
@@ -1 +1 @@
1
- import e from"http";import{watch as t}from"chokidar";import o from"express";import{mock as r}from"mock-json-schema";import{merge as a}from"webpack-merge";import s from"../utils/log.mjs";import n from"../utils/match-path.mjs";import{vts as i}from"../utils/vts.mjs";function c(e,t,o){if(o[t]){for(let r in o[t])Object.prototype.hasOwnProperty.call(o[t],r)&&delete e[r];o[t]=null,delete o[t]}}export const yApiSchemaMock=(t,o)=>new Promise((s,n)=>{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=r(t);void 0!==o?s(a(n,o)):s(n)}}catch(e){n(e)}})})});export const yApiMock=(t,o)=>new Promise((r,a)=>{let s=new URL(o.host),n={hostname:s.hostname,port:s.port,path:t.path.replace(new RegExp(o.pathRewrite),`/mock/${o.projectId}/`),method:t.method,headers:t.headers,query:t.query},i=e.request(n,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{r(JSON.parse(t))}catch(e){a(e)}})});i.on("error",e=>{a(e.message)}),i.write(JSON.stringify(t.body)),i.end()});export default(e=>{let r={},a={};return t(e).on("all",async function(e,t){switch(process.stdout.write("update mock..."),e){case"add":case"change":c(a,t,r),r[t]=i(t),a=Object.assign(a,r[t]);break;case"unlink":c(a,t,r)}s("update mock success")}),function(e,t,r){let s=`${e.method} ${e.path}`,i=Object.keys(a).filter(function(e){return RegExp(`^${e.replace(/(:\w*)[^/]/g,"((?!/).)")}*$`).test(s)});if(!a[s]&&(!i||!(i.length>0)))return r();{let c;let p=e.get("Content-Type");switch(p){case"text/plain":c=o.raw({type:"text/plain"});break;case"text/html":c=o.text({type:"text/html"});break;case"application/x-www-form-urlencoded":c=o.urlencoded({extended:!1});break;default:c=o.json()}p?.startsWith("multipart/form-data;")&&(c=o.static("./public")),c(e,t,function(){let o=a[s]||a[i[0]];if("function"==typeof o){let a=n(i[0].split(" ")[1],e.url);a&&Object.assign(e.params,a.params),o(e,t,r)}else t.json(o)})}}});
1
+ import e from"http";import{watch as t}from"chokidar";import o from"express";import{mock as r}from"mock-json-schema";import{merge as a}from"webpack-merge";import s from"../utils/log.mjs";import n from"../utils/match-path.mjs";import{tempMock as i}from"../utils/temp.mjs";function c(e,t,o){if(o[t]){for(let r in o[t])Object.prototype.hasOwnProperty.call(o[t],r)&&delete e[r];o[t]=null,delete o[t]}}export const yApiSchemaMock=(t,o)=>new Promise((s,n)=>{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=r(t);void 0!==o?s(a(n,o)):s(n)}}catch(e){n(e)}})})});export const yApiMock=(t,o)=>new Promise((r,a)=>{let s=new URL(o.host),n={hostname:s.hostname,port:s.port,path:t.path.replace(new RegExp(o.pathRewrite),`/mock/${o.projectId}/`),method:t.method,headers:t.headers,query:t.query},i=e.request(n,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{r(JSON.parse(t))}catch(e){a(e)}})});i.on("error",e=>{a(e.message)}),i.write(JSON.stringify(t.body)),i.end()});export default(e=>{let r={},a={};return t(e).on("all",async function(e,t){switch(process.stdout.write("update mock..."),e){case"add":case"change":c(a,t,r);let o=await i(t);r[t]=o,a=Object.assign(a,o);break;case"unlink":c(a,t,r)}s("update mock success")}),function(e,t,r){let s=`${e.method} ${e.path}`,i=Object.keys(a).filter(function(e){return RegExp(`^${e.replace(/(:\w*)[^/]/g,"((?!/).)")}*$`).test(s)});if(!a[s]&&(!i||!(i.length>0)))return r();{let c;let p=e.get("Content-Type");switch(p){case"text/plain":c=o.raw({type:"text/plain"});break;case"text/html":c=o.text({type:"text/html"});break;case"application/x-www-form-urlencoded":c=o.urlencoded({extended:!1});break;default:c=o.json()}p?.startsWith("multipart/form-data;")&&(c=o.static("./public")),c(e,t,function(){let o=a[s]||a[i[0]];if("function"==typeof o){let a=n(i[0].split(" ")[1],e.url);a&&Object.assign(e.params,a.params),o(e,t,r)}else t.json(o)})}}});
package/lib/paths.d.mts CHANGED
@@ -29,6 +29,7 @@ declare const paths: {
29
29
  componentsPath: string;
30
30
  mockPath: string;
31
31
  vfsDtsPath: string;
32
+ tempPath: string;
32
33
  };
33
34
  export declare const routeDir: string;
34
35
  export default paths;
package/lib/paths.mjs CHANGED
@@ -1 +1 @@
1
- import e from"url";import{dirname as o,resolve as t}from"path";let a=JSON.parse(process.env.npm_config_argv||'{"original":[]}').original;export const __filename=e.fileURLToPath(import.meta.url);export const __dirname=o(__filename);export const yarnArgv={};for(let e=0,o=a.length;e<o;e++){let o=a[e].split("=");Object.assign(yarnArgv,{[o[0]]:o[1]||!0})}export const CUSTOMCONFIG=process.env.npm_config_config||yarnArgv.config;let c=process.cwd(),n=t(c,"./node_modules"),r={__dirname,__filename,nodeModules:n,pnpmNodeModules:t(n,"./.pnpm/node_modules"),corePath:e.fileURLToPath(new URL(".",import.meta.url)),programPath:c,webpackCachePath:t(n,"./.temp_cache"),lineCachePath:t(n,"./.cache"),httpCachePath:t(n,"./.cache/http"),swcCachePath:t(n,"./.cache/.swc"),configPath:t(c,"./config/index.ts"),customConfigPath:t(c,`./config/${CUSTOMCONFIG}.ts`),coveragePath:t(c,"./coverage/clover.xml"),pagesPath:t(c,"./src/pages"),componentsPath:t(c,"./components"),mockPath:t(c,"./mock"),vfsDtsPath:t(n,"./@app")};export const routeDir="library"===process.env.APPTYPE?r.componentsPath:r.pagesPath;export default r;
1
+ import e from"url";import{dirname as t,resolve as o}from"path";let a=JSON.parse(process.env.npm_config_argv||'{"original":[]}').original;export const __filename=e.fileURLToPath(import.meta.url);export const __dirname=t(__filename);export const yarnArgv={};for(let e=0,t=a.length;e<t;e++){let t=a[e].split("=");Object.assign(yarnArgv,{[t[0]]:t[1]||!0})}export const CUSTOMCONFIG=process.env.npm_config_config||yarnArgv.config;let n=process.cwd(),c=o(n,"./node_modules"),r={__dirname,__filename,nodeModules:c,pnpmNodeModules:o(c,"./.pnpm/node_modules"),corePath:e.fileURLToPath(new URL(".",import.meta.url)),programPath:n,webpackCachePath:o(c,"./.temp_cache"),lineCachePath:o(c,"./.cache"),httpCachePath:o(c,"./.cache/http"),swcCachePath:o(c,"./.cache/.swc"),configPath:o(n,"./config/index.ts"),customConfigPath:o(n,`./config/${CUSTOMCONFIG}.ts`),coveragePath:o(n,"./coverage/clover.xml"),pagesPath:o(n,"./src/pages"),componentsPath:o(n,"./components"),mockPath:o(n,"./mock"),vfsDtsPath:o(c,"./@app"),tempPath:o(__dirname,".temp")};export const routeDir="library"===process.env.APPTYPE?r.componentsPath:r.pagesPath;export default r;
@@ -0,0 +1,2 @@
1
+ export declare function tempConfig(src: string): Promise<any>;
2
+ export declare function tempMock(src: string): Promise<any>;
@@ -0,0 +1 @@
1
+ import{transformFileSync as t}from"@swc/core";import{loadFileSync as o,updateFileSync as e}from"@moneko/utils";import r from"../paths.mjs";import{sep as p,join as m}from"path";import i from"ts-node";let s={inputSourceMap:!1,sourceMaps:!1,module:{type:"es6"},jsc:{parser:{syntax:"typescript"},loose:!1}};function n(t){return t.split(p).pop()?.replace(/\.(j|t)sx?$/,".mjs")}export async function tempConfig(p){let c=m(r.tempPath,`/config/${n(p)}`);return console.log(i.register({transpileOnly:!0}).compile(o(p),p)),e(c,t(p,s).code),await import(c)}export async function tempMock(o){let p=m(r.tempPath,`/mock/${n(o)}`);return e(p,t(o,s).code),await import(p)}
@@ -1,6 +1,11 @@
1
+ interface VfsOptions {
2
+ namedExport?: boolean;
3
+ modules: Record<string, any>;
4
+ }
1
5
  /**
2
6
  * 运行 ts 代码
3
7
  * @param {String} filepath 文件名
4
8
  * @returns {String} declaration
5
9
  */
6
- export declare function vts<T>(filepath: string, namedExport?: boolean): T;
10
+ export declare function vts<T>(filepath: string, options?: VfsOptions): T;
11
+ export {};
package/lib/utils/vts.mjs CHANGED
@@ -1 +1 @@
1
- import{transformFileSync as e}from"@swc/core";import{Script as t,createContext as o}from"vm";let r={inputSourceMap:!1,sourceMaps:!1,module:{type:"commonjs"},jsc:{target:"es2015",parser:{syntax:"typescript"},loose:!1}};export function vts(s,p=!1){let n=new t(e(s,r).code),u={exports:{default:null}};return(o(u),n.runInContext(u),p)?u.exports:u.exports.default}
1
+ import{transformFileSync as e}from"@swc/core";import{Script as o,createContext as r}from"vm";import*as t from"../index.mjs";import s from"./require.mjs";let m={inputSourceMap:!1,sourceMaps:!1,module:{type:"commonjs"},jsc:{target:"es2015",parser:{syntax:"typescript"},loose:!1}};export function vts(p,n){let u=e(p,m),i={exports:{default:null},require:e=>n?.modules[e]?n.modules[e]:"@moneko/core"===e?t:e.startsWith(".")?void 0:s(s.resolve(e))};return(r(i),new o(u.code,{filename:p}).runInNewContext(i),n?.namedExport)?i.exports:i.exports.default}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.17.43",
3
+ "version": "3.17.45-beta.0",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",
@@ -37,6 +37,7 @@
37
37
  "style-loader": "4.0.0",
38
38
  "swc-loader": "0.2.6",
39
39
  "terser-webpack-plugin": "5.3.10",
40
+ "ts-node": "^10.9.2",
40
41
  "typescript": "5.4.5",
41
42
  "webpack": "5.92.0",
42
43
  "webpack-bundle-analyzer": "4.10.2",