@moneko/core 3.8.3-beta.2 → 3.8.3-beta.4

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.js CHANGED
@@ -1 +1 @@
1
- import{accessSync as e,constants as t}from"fs";import o from"chalk";import{merge as s}from"webpack-merge";import i,{CUSTOMCONFIG as a}from"./paths.js";import{PACKAGENAME as n,coreName as r,isLibrary as l,isMobile as c,jsxImportSource as m,mainDirectory as p}from"./process-env.js";import{isFunction as u,log as h,readConf as d,resolveProgramPath as f}from"./utils.js";let g=["@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={seo:!1,mode:"csr",compiler:"swc",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{js:{},css:{}},sourceMap:{filename:"[file].map",publicPath:""},env:{NODE_ENV:process.env.NODE_ENV},basename:"/",publicPath:"/",rem:{designSize:c?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:{"@":f(p)},moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:[],cacheDirectory:i.webpackCachePath,devServer:{allowedHosts:[".baidu.com"],host:"localhost",port:3e3,https:!1,compress:!1},htmlPluginOption:{template:`node_modules/${r}/template/index.html`,favicon:`node_modules/${r}/template/favicon.ico`,tags:[]},assetHtml:[],routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:{chunks:"all",minSize:1024,minChunks:1,cacheGroups:{route:{test:/[\\/].git[\\/]router/,priority:-10,reuseExistingChunk:!0,name:"route"},example:{test:/[\\/].git[\\/]example/,priority:-10,reuseExistingChunk:!0,name:"example"}}},runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:g,js:g,media:g,font:g,wasm:[]},mdx:{jsxImportSource:m,useDynamicImport:!0,remarkPlugins:[],rehypePlugins:[]},jsxDomExpressions:{moduleName:"solid-js/web",builtIns:["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"],contextToCustomElements:!0,wrapConditionals:!0,generate:"dom",hydratable:!1},bar:{name:"Client",color:"#6f42c1"},virtualModule:{},normalizeCss:!0,externalsPresets:{},buildHttp:{allowedUris:[],lockfileLocation:`${i.httpCachePath}/http.lock`,cacheLocation:`${i.httpCachePath}/data`,upgrade:!0}};l&&(P.alias=Object.assign(P.alias,{"@pkg":i.componentsPath,[n]:i.componentsPath}));let x=P,C={},w={};try{e(i.configPath,t.R_OK);let o=(await d(i.configPath,"index")).default;C=u(o)?o(process):o}catch(e){h(o.red(e))}if(a)try{e(i.customConfigPath,t.R_OK);let o=(await d(i.customConfigPath,a)).default;w=u(o)?o(process):o}catch(e){h(o.red(e))}"tsc"===(x=s(x,C,w)).compiler&&x.minifier&&(x.minifier.js||Object.assign(x.minifier,{js:{type:"terser"}}),x.minifier.css||Object.assign(x.minifier,{css:{type:"cssnano"}})),!1===x.devtool&&(x.sourceMap=!1),!1===x.sourceMap&&(x.devtool=!1),x.fixBrowserRouter&&x.htmlPluginOption&&(x.htmlPluginOption.tags||(x.htmlPluginOption.tags=[]),x.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=x;export const PUBLICPATH=CONFIG.publicPath||"/";global.NEKOCLICONFIG={CONFIG,CUSTOMCONFIG:a,log:h};
1
+ import{accessSync as e,constants as t}from"fs";import o from"chalk";import{merge as s}from"webpack-merge";import i,{CUSTOMCONFIG as a}from"./paths.js";import{FRAMEWORK as n,PACKAGENAME as r,coreName as l,isDev as c,isLibrary as m,isMobile as p,jsxImportSource as u,mainDirectory as d}from"./process-env.js";import{isFunction as h,log as f,readConf as g,resolveProgramPath as x}from"./utils.js";let C=["@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={seo:!1,mode:"csr",compiler:"swc",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{js:{},css:{}},sourceMap:{filename:"[file].map",publicPath:""},env:{NODE_ENV:process.env.NODE_ENV},basename:"/",publicPath:"/",rem:{designSize:p?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:{"@":x(d)},moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:[],cacheDirectory:i.webpackCachePath,devServer:{allowedHosts:[".baidu.com"],host:"localhost",port:3e3,https:!1,compress:!1},htmlPluginOption:{template:`node_modules/${l}/template/index.html`,favicon:`node_modules/${l}/template/favicon.ico`,tags:[]},assetHtml:[],routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:{chunks:"all",minSize:1024,minChunks:1,cacheGroups:{route:{test:/[\\/].git[\\/]router/,priority:-10,reuseExistingChunk:!0,name:"route"},example:{test:/[\\/].git[\\/]example/,priority:-10,reuseExistingChunk:!0,name:"example"}}},runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:C,js:C,media:C,font:C,wasm:[]},mdx:{jsx:!1,development:c,jsxImportSource:u,providerImportSource:`@moneko/${n}/mdx`},jsxDomExpressions:{moduleName:"solid-js/web",builtIns:["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"],contextToCustomElements:!0,wrapConditionals:!0,generate:"dom",hydratable:!1},bar:{name:"Client",color:"#6f42c1"},virtualModule:{},normalizeCss:!0,externalsPresets:{},buildHttp:{allowedUris:[],lockfileLocation:`${i.httpCachePath}/http.lock`,cacheLocation:`${i.httpCachePath}/data`,upgrade:!0}};m&&(P.alias=Object.assign(P.alias,{"@pkg":i.componentsPath,[r]:i.componentsPath}));let w=P,b={},k={};try{e(i.configPath,t.R_OK);let o=(await g(i.configPath,"index")).default;b=h(o)?o(process):o}catch(e){f(o.red(e))}if(a)try{e(i.customConfigPath,t.R_OK);let o=(await g(i.customConfigPath,a)).default;k=h(o)?o(process):o}catch(e){f(o.red(e))}"tsc"===(w=s(w,b,k)).compiler&&w.minifier&&(w.minifier.js||Object.assign(w.minifier,{js:{type:"terser"}}),w.minifier.css||Object.assign(w.minifier,{css:{type:"cssnano"}})),!1===w.devtool&&(w.sourceMap=!1),!1===w.sourceMap&&(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||"/";global.NEKOCLICONFIG={CONFIG,CUSTOMCONFIG:a,log:f};
package/lib/dev.js CHANGED
@@ -1,3 +1,3 @@
1
- import{readdirSync as e}from"fs";import t from"chalk";import o from"webpack";import s from"webpack-dev-server";import{merge as r}from"webpack-merge";import{clientConfig as l}from"./common.js";import{CONFIG as i}from"./config.js";import{hasPkg as n}from"./has-pkg.js";import{getIPv4 as a,getPort as c}from"./net.js";import p from"./paths.js";import{hasEslintConfig as m,hasStylelintConfig as d,isLibrary as f,isReact as u}from"./process-env.js";import{cleanDir as h,isFunction as v,log as w,resolveProgramPath as g}from"./utils.js";let{HotModuleReplacementPlugin:j}=o,{yellow:k,green:y,grey:$,gray:x,bgBlue:b,bgGreenBright:S,blueBright:T,greenBright:C}=t,A=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],B=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],D=e(p.programPath),E=!1,M=!1;for(let e=0,t=D.length;e<t;e++)B.includes(D[e])&&(M=!0),A.includes(D[e])&&(E=!0);E||(E=m),M||(M=d);let O=M?(await import("stylelint-webpack-plugin")).default:null,P=E?(await import("eslint-webpack-plugin")).default:null,_=i.devServer.port||3e3,H=await c(_,65535,i.devServer.host),I=n("@moneko/mock")&&(await import("@moneko/mock")).default,N=u&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,W=!1===i.devtool||i.devtool?i.devtool:"eval-cheap-module-source-map";i.devServer.port=H;let F="/"===i.basename,G=i.devServer.https?"https:":"http:",L=F?"":i.basename,R=i.devServer.port!==H&&x(`Port ${k(_)} is in use, trying ${y(H)} instead.
2
- `);function Y(e){return`${G}//${"local"===e?i.devServer.host:a()}:${H}${L}`}let q=x("You application is running here:"),z=`${b(" Local ")} ${T(Y("local"))}
3
- ${S(" Network ")} ${C(Y("net"))}`,J=["js","md","mdx","jsx","ts","tsx","json","html","vue"],K=J.join(","),Q=["css","scss","sass","less","ts","tsx","js","jsx"],U=Q.join(","),V=["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],X=[P&&new P({fix:!0,threads:!0,files:[`${i.alias["@"]}/**/*.{${K}}`,f&&`${i.alias["@pkg"]}/**/*.{${K}}`].filter(Boolean),extensions:J,exclude:V,cache:!1,lintDirtyModulesOnly:!0}),O&&new O({fix:!0,threads:!0,files:[`${i.alias["@"]}/**/*.{${U}}`,f&&`${i.alias["@pkg"]}/**/*.{${U}}`].filter(Boolean),extensions:Q,exclude:V,cache:!1,lintDirtyModulesOnly:!0}),new j,N&&new N].filter(Boolean),Z={headers:{"Access-Control-Allow-Origin":"*"},compress:i.devServer.compress,host:"0.0.0.0",port:H,historyApiFallback:F||{index:L.endsWith("/")?L:`${L}/`,disableDotRule:!0},https:i.devServer.https,proxy:i.proxy,allowedHosts:i.devServer.allowedHosts,client:{reconnect:!0,progress:!1,logging:"info",overlay:!1,webSocketTransport:"ws"},webSocketServer:"ws",static:{watch:{ignored:e=>e.endsWith(".d.ts")||e.includes("/node_modules/")}},setupMiddlewares:(e,t)=>{if(!t)throw Error("devServer is not defined");return t.app&&v(I)&&I(t.app,g("mock/")),e},open:!1,hot:!0},ee=o(r(l,{devtool:W,mode:"development",plugins:X}));ee.watch({aggregateTimeout:600,ignored:/node_modules/,stdin:!0},(e,t)=>{!e&&t&&(w([q,"",z,"",$(`Compiled successfully in ${y(`${t.endTime-t.startTime}ms`)}`)]),t.compilation.warnings.forEach(e=>w(e.message)),t.compilation.errors.forEach(e=>w(e.message)),R&&w(R))});let et=new s(Z,ee);et.startCallback(e=>{e||w([q,"",z])}),et.stopCallback(e=>{e||h(p.cachePath)}),process.on("exit",function(){ee.close(()=>{}),et.invalidate(),et.stop()}),process.on("SIGINT",()=>{process.exit()});
1
+ import{readdirSync as e}from"fs";import t from"chalk";import o from"webpack";import s from"webpack-dev-server";import{merge as r}from"webpack-merge";import{clientConfig as l}from"./common.js";import{CONFIG as i}from"./config.js";import{hasPkg as n}from"./has-pkg.js";import{getIPv4 as a,getPort as c}from"./net.js";import p from"./paths.js";import{hasEslintConfig as m,hasStylelintConfig as d,isLibrary as u,isReact as f}from"./process-env.js";import{cleanDir as h,isFunction as v,log as w,resolveProgramPath as g}from"./utils.js";let{HotModuleReplacementPlugin:j}=o,{yellow:k,green:y,grey:$,gray:x,bgBlue:b,bgGreenBright:S,blueBright:T,greenBright:C}=t,A=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],B=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],D=e(p.programPath),E=!1,H=!1;for(let e=0,t=D.length;e<t;e++)B.includes(D[e])&&(H=!0),A.includes(D[e])&&(E=!0);E||(E=m),H||(H=d);let M=H?(await import("stylelint-webpack-plugin")).default:null,O=E?(await import("eslint-webpack-plugin")).default:null,P=i.devServer.port||3e3,_=await c(P,65535,i.devServer.host),I=n("@moneko/mock")&&(await import("@moneko/mock")).default,J=f&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,N=!1===i.devtool||i.devtool?i.devtool:"eval-cheap-module-source-map";i.devServer.port=_;let W="/"===i.basename,F=i.devServer.https?"https:":"http:",G=W?"":i.basename,L=i.devServer.port!==_&&x(`Port ${k(P)} is in use, trying ${y(_)} instead.
2
+ `);function R(e){return`${F}//${"local"===e?i.devServer.host:a()}:${_}${G}`}let Y=x("You application is running here:"),q=`${b(" Local ")} ${T(R("local"))}
3
+ ${S(" Network ")} ${C(R("net"))}`,z=["js","md","mdx","jsx","ts","tsx","json","html","vue"],K=z.join(","),Q=["css","scss","sass","less","ts","tsx","js","jsx"],U=Q.join(","),V=["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],X=[O&&new O({fix:!0,threads:!0,files:[`${i.alias["@"]}/**/*.{${K}}`,u&&`${i.alias["@pkg"]}/**/*.{${K}}`].filter(Boolean),extensions:z,exclude:V,cache:!1,lintDirtyModulesOnly:!0}),M&&new M({fix:!0,threads:!0,files:[`${i.alias["@"]}/**/*.{${U}}`,u&&`${i.alias["@pkg"]}/**/*.{${U}}`].filter(Boolean),extensions:Q,exclude:V,cache:!1,lintDirtyModulesOnly:!0}),new j,J&&new J].filter(Boolean),Z={headers:{"Access-Control-Allow-Origin":"*"},compress:i.devServer.compress,host:"0.0.0.0",port:_,historyApiFallback:W||{index:G.endsWith("/")?G:`${G}/`,disableDotRule:!0},https:i.devServer.https,proxy:i.proxy,allowedHosts:i.devServer.allowedHosts,client:{reconnect:!0,progress:!1,logging:"info",overlay:!1,webSocketTransport:"ws"},webSocketServer:"ws",static:{watch:{ignored:e=>e.endsWith(".d.ts")||e.includes("/node_modules/")}},setupMiddlewares:(e,t)=>{if(!t)throw Error("devServer is not defined");return t.app&&v(I)&&I(t.app,g("mock/")),e},open:!1,hot:!0},ee=o(r(l,{devtool:N,mode:"development",plugins:X}));ee.watch({aggregateTimeout:600,ignored:/node_modules/,stdin:!0},(e,t)=>{!e&&t&&(process.stdout.write("\x1b[2J\x1b[3J\x1b[H"),w([Y,"",q,"",$(`Compiled successfully in ${y(`${t.endTime-t.startTime}ms`)}`)]),t.compilation.warnings.forEach(e=>w(e.message)),t.compilation.errors.forEach(e=>w(e.message)),L&&w(L))});let et=new s(Z,ee);et.startCallback(e=>{e||w([Y,"",q])}),et.stopCallback(e=>{e||h(p.cachePath)}),process.on("exit",function(){ee.close(()=>{}),et.invalidate(),et.stop()}),process.on("SIGINT",()=>{process.exit()});
package/lib/index.d.ts CHANGED
@@ -3,5 +3,6 @@ export { FRAMEWORKNAME, PACKAGENAME, PACKAGEVERSION, coreName, isDev, isLibrary,
3
3
  export { realResolve, resolveNodeModulesPath, resolveProgramPath, log } from './utils.js';
4
4
  export { getIPv4, getPort } from './net.js';
5
5
  export { default as osTmpDir } from './os-tmp-dir.js';
6
+ export type { MdxOptions } from '@moneko/mdx';
6
7
  export type { OverrideResolverOption } from './plugin/override-resolve.js';
7
8
  export type * from '../typings/global.d.ts';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return o}});const e=require("@moneko/mdx"),t={react:"react",solid:"solid-js/h"}[process.env.FRAMEWORK];function o(o){let r=this.resourcePath,{development:s=!1}=this.getOptions(),n=(0,e.compileSync)({value:o,filepath:r,development:s,jsx:!0,jsxImportSource:t});return console.log(n.frontmatter),n.code}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return t}});const e=require("@moneko/mdx");function t(t){let n=this.async();(0,e.mdx)({value:t,filepath:this.resourcePath,...this.getOptions()}).then(e=>{n(null,e.code)}).catch(n)}
@@ -1,3 +1,3 @@
1
- import { type CompileOptions } from '@moneko/mdx';
1
+ import { type MdxOptions } from '@moneko/mdx';
2
2
  import type { LoaderContext } from 'webpack';
3
- export default function (this: LoaderContext<CompileOptions>, value: string): string;
3
+ export default function (this: LoaderContext<Omit<MdxOptions, 'value'>>, value: string): void;
package/lib/vm/routes.js CHANGED
@@ -1 +1 @@
1
- let e,t,r;import{accessSync as o,constants as s,readFileSync as n,readdirSync as a,statSync as p}from"fs";import{join as i,relative as l}from"path";import{watch as c}from"chokidar";import{load as m}from"js-yaml";import{CONFIG as u}from"../config.js";import f from"../paths.js";import{FRAMEWORK as d,FRAMEWORKNAME as x,createElement as h,isDev as g,isLibrary as $,isReact as j,isSolid as y}from"../process-env.js";import D,{vmWriteing as N}from"../reactive-object.js";let O=/^---\n([\s\S]+?)\n---\n/;try{o(`${u.alias["@"]}/router/index.ts`,s.R_OK),e=!0}catch(t){e=!1}let T=y?"component":"element";function k(e){return e.replace(/\$/g,":").replace(/^index\.tsx?$/,"/").replace(/^README\.mdx?$/,"/")}function E(e,t){let{regex:r,alia:o,base:s=e,outputSource:c}=t;return a(e).reduce((a,u)=>{let f=i(e,u);if(p(f).isDirectory()){let e=E(f,{...t,base:s});if(e.length>0){let t={},r={path:k(u),key:k(l(s,f))};if(c)Object.assign(t,{children:e});else{let o=e.findIndex(e=>"/"===e.path||r.path===e.path),s=e.splice(o,1)[0];e.length?Object.assign(t,!y&&s,{children:[y&&{...s,path:r.path===s.path?"/":s.path},...e].filter(Boolean)}):Object.assign(t,s)}a.push(Object.assign(t,r))}}else if(r.test(f)){let e=n(f,{encoding:"utf-8"}),t=function(e){let t=e.match(O);return t&&t[1]?t[1].trim():null}(e),r=t?m(t):{},p=l(s,f),u=k(p);a.push(Object.assign({path:u.split("/").slice(-2,-1)?.join("")||"/",key:u.replace(/\/?index.tsx?$/,"/").replace(/\/?README.mdx?$/,"/").split("/").filter(Boolean).join("/"),meta:{...r}},o&&{[T]:`rr(() => import(/* webpackChunkName: '${p}' */'${i(o,p)}'))rr`},c&&{codes:function(e){let t;let r={},o=/```(.+?)\n([\s\S]*?)\n```/g;for(;null!==(t=o.exec(e));){let[,e="jsx",o]=t;r[e.split(" ").pop()||"jsx"]=o.trim()}return Object.keys(r).length?r:{jsx:e}}(e.replace(O,"").replace(/^\n+|\n+$/g,""))}))}return a},[])}export const routesModuleName="@app/routes";export const route=new D({[routesModuleName]:"export default []"});export const exampleModuleName="@app/example";export const examples=new D;let M=`${y?"() => ":""}${h}(SuspenseComp, { comp: $1 })`,S=`import { ${h} } from "${x}";import SuspenseComp from "@app/suspense";${j?'import prefix from "@app/prefix-router";':""}`;e&&(S+='import merge from "@app/merge-router";import customRouter from "@/router";'),["react","solid"].includes(d)||(M="$1",S="");export let routes=[];function b(t){return`${S}const routes = [{ path: "/", children: [${y?'{ path: "/" },':""} ${t}] }];const _routes = ${e?'merge([...routes, ...customRouter], "path")':"routes"};export default ${j?"prefix(_routes)":"_routes"};`}function R(e,t,r,o){N.setData(o,!0);let s=c(e,{ignored:(e,r)=>{if(r)return!r.isDirectory()&&t.test(e)},persistent:!0,ignoreInitial:!1});function n(){s.unwatch(e),s.close(),N.setData(o,!1)}s.on("add",()=>{r()}).on("change",()=>{r()}).on("unlink",()=>{r()}),s.once("ready",()=>{g||n()}),process.on("SIGINT",n)}$?(R(f.componentsPath,/(?<!README\.mdx?)$/,function(){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),routes=E(f.componentsPath,{regex:/README\.mdx?$/,alia:"@pkg"}),route.setData(routesModuleName,b(JSON.stringify(routes).replace(/"rr\((.+?)\)rr"/g,M).slice(1,-1)))},100)},"vm-router"),R(f.componentsPath,/(?<!\/examples\/(.+)\.md)$/,function(){clearTimeout(r),r=setTimeout(()=>{clearTimeout(r),E(f.componentsPath,{regex:/\/examples\/(.+)\.md$/,outputSource:!0}).forEach(e=>{let t=["@app/example",e.key].filter(Boolean).join("/"),r=e.children?.[0].children?.filter(e=>e.codes)?.map(e=>({title:e.path.replace(/.md$/,""),order:0,...e.meta,codes:e.codes})).sort((e,t)=>e.order-t.order)||[];examples.setData(t,`export default ${JSON.stringify(r)};`)})},100)},"vm-examples")):R(f.pagesPath,/(?<!index\.tsx?)$/,function(){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),routes=E(f.pagesPath,{regex:/index\.tsx?$/,alia:"@/pages"}),route.setData(routesModuleName,b(JSON.stringify(routes).replace(/"rr\((.+?)\)rr"/g,M).slice(1,-1)))},100)},"vm-router");
1
+ let e,t,r;import{accessSync as o,constants as s,readFileSync as a,readdirSync as n,statSync as p}from"fs";import{join as i,relative as l}from"path";import{frontmatterSync as m}from"@moneko/mdx";import{watch as c}from"chokidar";import{CONFIG as u}from"../config.js";import f from"../paths.js";import{FRAMEWORK as d,FRAMEWORKNAME as x,createElement as h,isDev as g,isLibrary as $,isReact as j,isSolid as y}from"../process-env.js";import D,{vmWriteing as N}from"../reactive-object.js";try{o(`${u.alias["@"]}/router/index.ts`,s.R_OK),e=!0}catch(t){e=!1}let O=y?"component":"element";function k(e){return e.replace(/\$/g,":").replace(/^index\.tsx?$/,"/").replace(/^README\.mdx?$/,"/")}function T(e,t){let{regex:r,alia:o,base:s=e,outputSource:c}=t;return n(e).reduce((n,u)=>{let f=i(e,u);if(p(f).isDirectory()){let e=T(f,{...t,base:s});if(e.length>0){let t={},r={path:k(u),key:k(l(s,f))};if(c)Object.assign(t,{children:e});else{let o=e.findIndex(e=>"/"===e.path||r.path===e.path),s=e.splice(o,1)[0];e.length?Object.assign(t,!y&&s,{children:[y&&{...s,path:r.path===s.path?"/":s.path},...e].filter(Boolean)}):Object.assign(t,s)}n.push(Object.assign(t,r))}}else if(r.test(f)){let{frontmatter:e,code:t}=m(a(f,{encoding:"utf-8"})),r=l(s,f),p=k(r);n.push(Object.assign({path:p.split("/").slice(-2,-1)?.join("")||"/",key:p.replace(/\/?index.tsx?$/,"/").replace(/\/?README.mdx?$/,"/").split("/").filter(Boolean).join("/"),meta:JSON.parse(e)},o&&{[O]:`rr(() => import(/* webpackChunkName: '${r}' */'${i(o,r)}'))rr`},c&&{codes:function(e){let t;let r={},o=/```(.+?)\n([\s\S]*?)\n```/g;for(;null!==(t=o.exec(e));){let[,e="jsx",o]=t;r[e.split(" ").pop()||"jsx"]=o.trim()}return Object.keys(r).length?r:{jsx:e}}(t.replace(/^\n+|\n+$/g,""))}))}return n},[])}export const routesModuleName="@app/routes";export const route=new D({[routesModuleName]:"export default []"});export const exampleModuleName="@app/example";export const examples=new D;let E=`${y?"() => ":""}${h}(SuspenseComp, { comp: $1 })`,M=`import { ${h} } from "${x}";import SuspenseComp from "@app/suspense";${j?'import prefix from "@app/prefix-router";':""}`;e&&(M+='import merge from "@app/merge-router";import customRouter from "@/router";'),["react","solid"].includes(d)||(E="$1",M="");export let routes=[];function S(t){return`${M}const routes = [{ path: "/", children: [${y?'{ path: "/" },':""} ${t}] }];const _routes = ${e?'merge([...routes, ...customRouter], "path")':"routes"};export default ${j?"prefix(_routes)":"_routes"};`}function b(e,t,r,o){N.setData(o,!0);let s=c(e,{ignored:(e,r)=>{if(r)return!r.isDirectory()&&t.test(e)},persistent:!0,ignoreInitial:!1});function a(){s.unwatch(e),s.close(),N.setData(o,!1)}s.on("add",()=>{r()}).on("change",()=>{r()}).on("unlink",()=>{r()}),s.once("ready",()=>{g||a()}),process.on("SIGINT",a)}$?(b(f.componentsPath,/(?<!README\.mdx?)$/,function(){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),routes=T(f.componentsPath,{regex:/README\.mdx?$/,alia:"@pkg"}),route.setData(routesModuleName,S(JSON.stringify(routes).replace(/"rr\((.+?)\)rr"/g,E).slice(1,-1)))},100)},"vm-router"),b(f.componentsPath,/(?<!\/examples\/(.+)\.md)$/,function(){clearTimeout(r),r=setTimeout(()=>{clearTimeout(r),T(f.componentsPath,{regex:/\/examples\/(.+)\.md$/,outputSource:!0}).forEach(e=>{let t=["@app/example",e.key].filter(Boolean).join("/"),r=e.children?.[0].children?.filter(e=>e.codes)?.map(e=>({title:e.path.replace(/.md$/,""),order:0,...e.meta,codes:e.codes})).sort((e,t)=>e.order-t.order)||[];examples.setData(t,`export default ${JSON.stringify(r)};`)})},100)},"vm-examples")):b(f.pagesPath,/(?<!index\.tsx?)$/,function(){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),routes=T(f.pagesPath,{regex:/index\.tsx?$/,alia:"@/pages"}),route.setData(routesModuleName,S(JSON.stringify(routes).replace(/"rr\((.+?)\)rr"/g,E).slice(1,-1)))},100)},"vm-router");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.8.3-beta.2",
3
+ "version": "3.8.3-beta.4",
4
4
  "description": "core",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -12,8 +12,7 @@
12
12
  "author": "moneko",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@moneko/mdx": "0.0.6",
16
- "@mdx-js/loader": "3.0.0",
15
+ "@moneko/mdx": "0.1.9",
17
16
  "@swc/core": "1.3.99",
18
17
  "@swc/css": "0.0.28",
19
18
  "@swc/helpers": "0.5.3",
@@ -4,7 +4,7 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
4
4
  import WebpackBar from 'webpackbar';
5
5
  import DoneWebpackPlugin from '../lib/plugin/done';
6
6
  import type { OverrideResolverOption } from '../lib/index';
7
- import type { Options as MDXOptions } from '@mdx-js/loader';
7
+ import type { MdxOptions } from '@moneko/mdx';
8
8
  import type { JsMinifyOptions, Config as SwcConfig } from '@swc/core';
9
9
  import type { CssNanoOptionsExtended } from 'css-minimizer-webpack-plugin';
10
10
  import type { MinifyOptions } from 'terser';
@@ -300,7 +300,7 @@ export declare type ConfigType<T extends 'tsc' | 'swc' = 'swc'> = {
300
300
  | false;
301
301
  /** 📦 打包完成 */
302
302
  done?: ConstructorParameters<typeof DoneWebpackPlugin>[0]['done'];
303
- mdx?: MDXOptions;
303
+ mdx?: Omit<MdxOptions, 'value' | 'filepath'>;
304
304
  jsxDomExpressions?: {
305
305
  moduleName?: string;
306
306
  builtIns?: string[];
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return t}});const e=/^---\n([\s\S]+?)\n---\n/,n=/^\n+|\n+$/g;function t(t){return t.replace(e,"").replace(n,"")}
@@ -1 +0,0 @@
1
- export default function (content: string): string;