@moneko/core 3.17.44 → 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=await 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 t from"http";import{watch as e}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(t,e,o){if(o[e]){for(let r in o[e])Object.prototype.hasOwnProperty.call(o[e],r)&&delete t[r];o[e]=null,delete o[e]}}export const yApiSchemaMock=(e,o)=>new Promise((s,n)=>{t.get(`${e.host}/api/interface/get?id=${e.id}&token=${e.token}`,t=>{t.setEncoding("utf8");let e="";t.on("data",t=>{e+=t}),t.on("end",()=>{try{let t=JSON.parse(e);if(t?.data?.res_body_is_json_schema){let e=JSON.parse(t.data.res_body),n=r(e);void 0!==o?s(a(n,o)):s(n)}}catch(t){n(t)}})})});export const yApiMock=(e,o)=>new Promise((r,a)=>{let s=new URL(o.host),n={hostname:s.hostname,port:s.port,path:e.path.replace(new RegExp(o.pathRewrite),`/mock/${o.projectId}/`),method:e.method,headers:e.headers,query:e.query},i=t.request(n,t=>{t.setEncoding("utf8");let e="";t.on("data",t=>{e+=t}),t.on("end",()=>{try{r(JSON.parse(e))}catch(t){a(t)}})});i.on("error",t=>{a(t.message)}),i.write(JSON.stringify(e.body)),i.end()});export default(t=>{let r={},a={};return e(t).on("all",async function(t,e){switch(process.stdout.write("update mock..."),t){case"add":case"change":c(a,e,r),r[e]=await i(e),a=Object.assign(a,r[e]);break;case"unlink":c(a,e,r)}s("update mock success")}),function(t,e,r){let s=`${t.method} ${t.path}`,i=Object.keys(a).filter(function(t){return RegExp(`^${t.replace(/(:\w*)[^/]/g,"((?!/).)")}*$`).test(s)});if(!a[s]&&(!i||!(i.length>0)))return r();{let c;let p=t.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(t,e,function(){let o=a[s]||a[i[0]];if("function"==typeof o){let a=n(i[0].split(" ")[1],t.url);a&&Object.assign(t.params,a.params),o(t,e,r)}else e.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): Promise<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 r}from"vm";let o={inputSourceMap:!1,sourceMaps:!1,module:{type:"commonjs"},jsc:{target:"es2015",parser:{syntax:"typescript"},loose:!1}};export async function vts(s,n=!1){let p=e(s,o),a={exports:{default:null},async require(e){try{if(e)return await import(e)}catch(e){throw e}}};return(r(a),new t(p.code,{filename:s}).runInNewContext(a),n)?a.exports:a.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}
@@ -1,2 +1,2 @@
1
1
  import{basename as e,join as t}from"path";import{watch as o}from"chokidar";import{CONFIG as a}from"../config.mjs";import{FRAMEWORK as l,isDev as r}from"../process-env.mjs";import n from"../utils/reactive-object.mjs";import s from"../utils/sigint-exit.mjs";import{directoryExists as c,scanFolderSync as i}from"@moneko/utils";import{vts as g}from"../utils/vts.mjs";let u={react:'import sso from "shared-store-object";',solid:'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'},f={react:'let storageKey="localizable.language",language=localStorage.getItem(storageKey)||"zh_CN",{translation:a,...defaultLocale}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[language]||resources.zh_CN),localizable=sso({lang:defaultLocale,t:a});export function setLang(a){let{translation:e,...l}=resources[a]||{};e&&(localizable.lang=l,localizable.t=e,localStorage.setItem(storageKey,l.language))}export default localizable;',solid:'let locale=createRoot(()=>{let e="localizable.language",a=localStorage.getItem(e)||"zh_CN",{translation:l,...o}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[a]||resources.zh_CN),[n,c]=createStore({lang:o,t:l});return createEffect(()=>{let a=resources[n.lang.language]?.translation;a&&(c("t",a),localStorage.setItem(e,n.lang.language))}),{localizable:n,setLocalizable:c,setLang:function(e){let{translation:a,...l}=resources[e]||{};a&&c("lang",l)}}},getOwner());export const setLocalizable=locale.setLocalizable;export const t=locale.localizable.t;export const lang=locale.localizable.lang;export const setLang=locale.setLang;'}[l];function p(e,t){return`${u[l]}
2
- export function interpolateString(r,n){return r.replace(/\\\${\\w+}/g,function(r){var t=r.slice(2,-1);var e=n[t];return e!==void 0?e.toString():""})}function deepFreeze(o) { const p = Reflect.ownKeys(o);for (const k of p) {const v = o[k];if ((v && typeof v === "object") || typeof v === "function") {deepFreeze(v);}}return Object.freeze(o);}export const locales = ${JSON.stringify(e)};const _res = ${JSON.stringify(t)};const resources = deepFreeze(_res);${f}`}export const localesModuleName="@app/locales";export const locales=new n({[localesModuleName]:p([],{})});let m={};async function d(t,o){let a=e(t).replace(/\.[^.]+$/,"");"deleted"===o?delete m[a]:Object.assign(m,{[a]:await g(t)});let l=[],r={};for(let e in m)if(Object.prototype.hasOwnProperty.call(m,e)){let{language:t=a,title:o=t,icon:n,translation:s={}}=m[e];l.push({language:t,title:o,icon:n}),r[t]={language:t,title:o,icon:n,translation:s}}locales.setData(localesModuleName,p(l,r))}let z=t(a.alias["@"],"./locales");if(c(z)&&!1!==a.htmlPluginOption){let e=i(z,[".ts$"]).filter(e=>!/^\..*|\.d\.ts$/.test(e));await Promise.all(e.map(e=>d(e,"added"))),r&&function(e,t){let a=o(e,{ignored:t,persistent:!0,ignoreInitial:!0});function l(){a.unwatch(e),a.close()}a.on("add",e=>{d(e,"added")}),a.on("change",e=>{d(e,"change")}),a.on("unlink",e=>{d(e,"deleted")}),a.once("ready",()=>{r||l()}),s(l)}(z,[/^\..*/,/!\.ts$/,/\.d\.ts$/])}
2
+ export function interpolateString(r,n){return r.replace(/\\\${\\w+}/g,function(r){var t=r.slice(2,-1);var e=n[t];return e!==void 0?e.toString():""})}function deepFreeze(o) { const p = Reflect.ownKeys(o);for (const k of p) {const v = o[k];if ((v && typeof v === "object") || typeof v === "function") {deepFreeze(v);}}return Object.freeze(o);}export const locales = ${JSON.stringify(e)};const _res = ${JSON.stringify(t)};const resources = deepFreeze(_res);${f}`}export const localesModuleName="@app/locales";export const locales=new n({[localesModuleName]:p([],{})});let m={};async function d(t,o){let a=e(t).replace(/\.[^.]+$/,"");"deleted"===o?delete m[a]:Object.assign(m,{[a]:g(t)});let l=[],r={};for(let e in m)if(Object.prototype.hasOwnProperty.call(m,e)){let{language:t=a,title:o=t,icon:n,translation:s={}}=m[e];l.push({language:t,title:o,icon:n}),r[t]={language:t,title:o,icon:n,translation:s}}locales.setData(localesModuleName,p(l,r))}let z=t(a.alias["@"],"./locales");if(c(z)&&!1!==a.htmlPluginOption){let e=i(z,[".ts$"]).filter(e=>!/^\..*|\.d\.ts$/.test(e));await Promise.all(e.map(e=>d(e,"added"))),r&&function(e,t){let a=o(e,{ignored:t,persistent:!0,ignoreInitial:!0});function l(){a.unwatch(e),a.close()}a.on("add",e=>{d(e,"added")}),a.on("change",e=>{d(e,"change")}),a.on("unlink",e=>{d(e,"deleted")}),a.once("ready",()=>{r||l()}),s(l)}(z,[/^\..*/,/!\.ts$/,/\.d\.ts$/])}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.17.44",
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",