@moneko/core 3.27.6-beta.0 → 3.27.6-beta.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/config.d.mts +3 -2
- package/lib/config.mjs +1 -1
- package/lib/entry/react.d.mts +13 -0
- package/lib/entry/react.mjs +41 -0
- package/lib/module.config.mjs +2 -2
- package/lib/options/modify-vars.d.mts +2 -0
- package/lib/options/modify-vars.mjs +1 -1
- package/lib/options/swcrc.d.mts +7 -0
- package/lib/plugins.config.mjs +1 -1
- package/lib/process-env.d.mts +3 -0
- package/lib/process-env.mjs +1 -1
- package/lib/vm/docs.d.mts +1 -2
- package/lib/vm/docs.mjs +1 -1
- package/lib/vm/info.d.mts +2 -5
- package/lib/vm/info.mjs +1 -1
- package/lib/vm/modules.d.mts +1 -0
- package/lib/vm/modules.mjs +1 -1
- package/lib/vm/render-app.d.mts +8 -0
- package/lib/vm/render-app.mjs +41 -0
- package/package.json +1 -1
package/lib/config.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { relative } from 'node:path';
|
|
1
2
|
import { fileExists } from '@moneko/utils';
|
|
2
3
|
import { merge } from 'webpack-merge';
|
|
3
4
|
import paths from './commom/paths.mjs';
|
|
@@ -5,9 +6,9 @@ import require from './commom/require.mjs';
|
|
|
5
6
|
import setupEnv from './commom/setup-env.mjs';
|
|
6
7
|
import jsxDomExpressions from './options/jsx-dom-expressions.mjs';
|
|
7
8
|
import splitChunk from './options/split-chunk.mjs';
|
|
8
|
-
import { isFunction, resolveProgram } from './utils/index.mjs';
|
|
9
|
+
import { isFunction, node_modules, resolveProgram } from './utils/index.mjs';
|
|
9
10
|
import type { ConfigType } from './index.mjs';
|
|
10
|
-
import { APPTYPE,
|
|
11
|
+
import { APPTYPE, FRAMEWORK, frameworkVersion, isDev, isLibrary, isMobile, isReact, jsxImportSource, mainDirectory, NODE_ENV, PACKAGENAME } from './process-env.mjs';
|
|
11
12
|
declare const includeModule: readonly [string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string];
|
|
12
13
|
export declare function getConfig(path: string): Promise<ConfigType>;
|
|
13
14
|
type EnvType = {
|
package/lib/config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{relative as e}from"node:path";import{fileExists as o}from"@moneko/utils";import{merge as t}from"webpack-merge";import n from"./commom/paths.mjs";import r from"./commom/require.mjs";import s from"./commom/setup-env.mjs";import i from"./options/jsx-dom-expressions.mjs";import a from"./options/split-chunk.mjs";import{isFunction as l,node_modules as m,resolveProgram as p}from"./utils/index.mjs";import{APPTYPE as c,FRAMEWORK as u,frameworkVersion as d,isDev as f,isLibrary as g,isMobile as h,isReact as x,jsxImportSource as v,mainDirectory as j,NODE_ENV as P,PACKAGENAME as C}from"./process-env.mjs";let b=["@app","@moneko","neko-ui",".cache/http/data","@ant-design","@antv","@antv/x6","@antv/x6-react-components","@element-plus","ant-design-vue","antd","antd-mini","antd-mobile","antd-mobile-icons","element-plus","element-ui","ng-zorro-antd","@antv","@mui","@du","ahooks","rc-queue-anim","umi","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design"];export function getConfig(e){return delete r.cache[e],new Promise(t=>{if(o(e)){let o=r(e).default;return t(l(o)?o(process):o)}return t({})})}let k=await Promise.all([s(P,c,u,[]),getConfig(n.configPath),getConfig(n.customConfigPath)]),w=k[0],O=k[1],y=k[2],I={devtool:f?"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:w,basename:"/",publicPath:"/",rem:{designSize:h?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":p(j)},x&&d<18?{"react/package.json":m("react/package.json"),"react/jsx-runtime":m("react/jsx-runtime.js"),"react/jsx-dev-runtime":m("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3},htmlPluginOption:{title:C.toLocaleUpperCase(),favicon:e(n.programPath,`${n.corePath}/options/favicon.ico`)},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:a,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:b,js:b,media:b,font:b,wasm:[]},mdx:{jsx:!1,development:f,jsxImportSource:v,providerImportSource:`@moneko/${u}/mdx`},jsxDomExpressions:i,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69"},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==u,bundleId:"com.moneko.bid",bundles:[],stylelint:!0,eslint:!0};g&&(I.alias=Object.assign(I.alias,{"@pkg":n.componentsPath,[C]:n.componentsPath}));let M=I;(!1===(M=t(M,O,y)).devtool||!1===M.sourceMap)&&(M.sourceMap=!1,M.devtool=!1),M.fixBrowserRouter&&M.htmlPluginOption&&(M.htmlPluginOption.tags||(M.htmlPluginOption.tags=[]),M.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=M;export const PUBLICPATH=CONFIG.publicPath;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { transformSync } from '@swc/core';
|
|
2
|
+
import swcrc, { SwcOption } from '../options/swcrc.mjs';
|
|
3
|
+
import { isDev } from '../process-env.mjs';
|
|
4
|
+
import info from '../vm/info.mjs';
|
|
5
|
+
declare const version: number;
|
|
6
|
+
declare const ReactDomPath: string;
|
|
7
|
+
declare const isHashRouter: boolean;
|
|
8
|
+
declare const v7Future: Record<string, boolean | undefined>;
|
|
9
|
+
declare const createRouter: string;
|
|
10
|
+
declare const code: string;
|
|
11
|
+
declare const swcOption: SwcOption;
|
|
12
|
+
declare const reactRenderApp: string;
|
|
13
|
+
export default reactRenderApp;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import{transformSync as e}from"@swc/core";import r from"../options/swcrc.mjs";import{isDev as t}from"../process-env.mjs";import o from"../vm/info.mjs";let a=parseFloat(o.frameworkVersion),n="hash"===o.routerMode,s=Object.assign({v7_relativeSplatPath:!1},"browser"===o.routerMode?{v7_fetcherPersist:!1,v7_normalizeFormMethod:!1,v7_partialHydration:o.ssr,v7_skipActionErrorRevalidation:!1}:{}),c=n?"createHashRouter":"createBrowserRouter",p=`import React, { StrictMode, useRef, type ReactElement } from 'react';
|
|
2
|
+
import Fallback from '@app/fallback';
|
|
3
|
+
import routes from '@app/routes';
|
|
4
|
+
import ReactDOM from '${a<18?"react-dom":"react-dom/client"}';
|
|
5
|
+
import { RouterProvider, ${c} } from 'react-router-dom';
|
|
6
|
+
|
|
7
|
+
type RenderAppProps = {
|
|
8
|
+
container?: HTMLElement;
|
|
9
|
+
basename?: string;
|
|
10
|
+
fallback?: ReactElement;
|
|
11
|
+
language?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function App(props: RenderAppProps) {
|
|
15
|
+
const v7Future = useRef(${JSON.stringify(s)});
|
|
16
|
+
return (
|
|
17
|
+
<StrictMode>
|
|
18
|
+
<RouterProvider
|
|
19
|
+
router={${c}(routes, {
|
|
20
|
+
basename: ${n?"/":"props.basename"},
|
|
21
|
+
window: window,
|
|
22
|
+
future: v7Future.current,
|
|
23
|
+
})}
|
|
24
|
+
future={{
|
|
25
|
+
/** 这使用 useTransition 而不是 useState 来更新路由器状态 */
|
|
26
|
+
v7_startTransition: false,
|
|
27
|
+
}}
|
|
28
|
+
fallbackElement={Fallback && <Fallback />}
|
|
29
|
+
/>
|
|
30
|
+
</StrictMode>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function renderApp(props: RenderAppProps = {}) {
|
|
35
|
+
const { container, basename = "${o.base}", language, ...args } = props;
|
|
36
|
+
const _container = container?.querySelector('#root') || document.getElementById('root');
|
|
37
|
+
${"micro"===o.type?"window.mainApp = { ...args, container: _container as HTMLElement };":""}
|
|
38
|
+
${a<18?`ReactDOM.${t?"render":"hydrate"}(<App basename={basename} language={language} />, _container);return () => ReactDOM.unmountComponentAtNode(_container as Element);`:"const instance = ReactDOM.createRoot(_container as HTMLElement);instance.render(<App basename={basename} language={language} />);return instance.unmount;"}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default renderApp;`,i=r(o.ssr);delete i.sync,delete i.parseMap;let m=e(p,i).code;console.log(m);export default m;
|
package/lib/module.config.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let e;import{join as o,sep as s}from"node:path";import{saveFileSync as t}from"@moneko/utils";import r,{CUSTOMCONFIG as a}from"./commom/paths.mjs";import m from"./commom/reactive-object.mjs";import n from"./commom/require.mjs";import i from"./commom/rule.mjs";import l from"./options/css-extract.mjs";import c from"./options/modify-vars.mjs";import d from"./options/reslove.mjs";import p from"./options/swcrc.mjs";import{getLightningCssTargets as u}from"./polyfills/targets.mjs";import{node_modules as f,resolveProgram as
|
|
2
|
-
`)}:void 0},importLoaders:2}},k={loader:d.lessLoader,options:{sourceMap:!!w.sourceMap,lessOptions:{modifyVars:c,javascriptEnabled:!0}}},C=new Map;function O(e){if(C.has(e))return C.get(e);try{let o;let t=n.resolve(e).split(s),r=t.lastIndexOf("node_modules");return o=-1!==r?t.slice(0,r).join(s):t.join(s),C.set(e,o),o}catch{let o=f(e);return C.set(e,o),o}}let I=[...w.cssModules,`@moneko/${L}`,"neko-ui"].map(O),b=["components","example","mock","site","src","server"].map(
|
|
1
|
+
let e;import{join as o,sep as s}from"node:path";import{saveFileSync as t}from"@moneko/utils";import r,{CUSTOMCONFIG as a}from"./commom/paths.mjs";import m from"./commom/reactive-object.mjs";import n from"./commom/require.mjs";import i from"./commom/rule.mjs";import l from"./options/css-extract.mjs";import c from"./options/modify-vars.mjs";import d from"./options/reslove.mjs";import p from"./options/swcrc.mjs";import{getLightningCssTargets as u}from"./polyfills/targets.mjs";import{node_modules as f,resolveProgram as h,toCamelCase as j}from"./utils/index.mjs";import v from"./utils/svg-to-data-uri.mjs";import{comment as g,getCommentPath as x}from"./vm/docs.mjs";import y from"./vm/generate-doc.mjs";import{CONFIG as w}from"./config.mjs";import{FRAMEWORK as L,isDev as P,isLibrary as M}from"./process-env.mjs";let _={loader:o(r.corePath,"/loader/lightning-css/loader.cjs"),options:{sourceMap:!!w.sourceMap,targets:u(),rem:!!w.rem,esModule:!0,modules:{auto(e){if(e){if(e.endsWith(".css")&&!e.endsWith("module.css"))return!1;for(let o=0,s=I.length;o<s;o++)if(e.includes(I[o]))return i.css_module.test(e)}return i.node_modules_css_module.test(e)},localIdentName:"[name][hash]_[local]",namedExport:!0,exportLocalsConvention:"dashesOnly",exportOnlyLocals:!1,getJSON:w.cssModuleDefinition?function(e){Q.setData(`${e.resourcePath}.d.ts`,`${e.exports.map(({name:e,value:o})=>`export const ${j(e)}: '${o}';`).join("\n")}
|
|
2
|
+
`)}:void 0},importLoaders:2}},k={loader:d.lessLoader,options:{sourceMap:!!w.sourceMap,lessOptions:{modifyVars:c,javascriptEnabled:!0}}},C=new Map;function O(e){if(C.has(e))return C.get(e);try{let o;let t=n.resolve(e).split(s),r=t.lastIndexOf("node_modules");return o=-1!==r?t.slice(0,r).join(s):t.join(s),C.set(e,o),o}catch{let o=f(e);return C.set(e,o),o}}let I=[...w.cssModules,`@moneko/${L}`,"neko-ui"].map(O),b=["components","example","mock","site","src","server"].map(h);function W(e){return new Promise(o=>{o([...b,r.corePath,...w.rulesInclude?.[e]?.map(O)||[]])})}a&&b.push(h(a)),w.overrideResolve&&w.overrideResolve.override&&b.push(w.overrideResolve.override);let $=await Promise.all([W("css"),W("js"),W("media"),W("wasm"),W("font")]),R=$[0],B=$[1],S=$[2],z=$[3],D=$[4];d.sassLoader&&(e={loader:d.sassLoader,options:{implementation:await import("sass"),sassOptions:{}}});let E=M&&P&&{test:i.tsdoc,include:w.alias["@pkg"],exclude:[/node_modules\/(?!(@app|@moneko)).+/,i.__tests__],enforce:"pre",loader:o(r.corePath,"/loader/ts-doc.cjs"),options:{comment:g,generateDoc:y,getCommentPath:x}},J=[{resourceQuery:/raw/i,type:"asset/source"},{resourceQuery:/url/i,type:"asset/resource",generator:{filename(e){let o=e.filename;return o&&o.toLocaleLowerCase().endsWith("wasm?url")?"wasm/[name][ext]":"assets/[name][ext]"}}},{test:i.wasm,type:"webassembly/async",include:z},{test:i.txt,type:"asset/source"},{test:i.image,type:"asset",dependency:{not:["url"]},parser:{dataUrlCondition:{maxSize:4096}},generator:{filename:e=>e.filename?.toLocaleLowerCase().endsWith(".svg")?"assets/svg/[name][ext]":"assets/images/[name][ext]",dataUrl:(e,o)=>o.filename.toLocaleLowerCase().endsWith(".svg")?v(e.toString()):e},include:S},{test:i.video,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/video/[name][ext]"},include:S},{test:i.font,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/fonts/[name][ext]"},include:D}],N=w.prefixJsLoader.filter(Boolean)||[];switch(L){case"react":w.reactCompiler&&N.unshift({loader:o(r.corePath,"/loader/react-compiler.cjs"),options:w.reactCompiler});break;case"solid":w.refresh=!1}let Q=new m({});Q.on("change",(e,o)=>{t(e,o)});export default(s=>{let t={loader:d.swcLoader,options:p(s)};return{parser:{javascript:{commonjsMagicComments:!0,dynamicImportMode:"lazy",dynamicImportPrefetch:!1,dynamicImportPreload:!1,importMeta:!0,importMetaContext:!0}},noParse:w.noParse,rules:[!1!==w.htmlPluginOption&&E,{oneOf:[...J,{test:i.js,use:[...N,t],include:B},{test:i.css,use:[l,_],include:R},e&&{test:i.scss,use:[l,_,e],include:R},{test:i.less,use:[l,_,k],include:R},{test:i.markdown,use:[...N,{loader:o(r.corePath,"/loader/mdx.cjs"),options:w.mdx}],exclude:[/node_modules\/(?!(@app|@moneko)).+/]}].filter(Boolean)},...w.moduleRules].filter(Boolean)}});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { CONFIG } from '../config.mjs';
|
|
2
|
+
import type { HtmlPluginOption } from '../plugin/html-plugin.mjs';
|
|
2
3
|
declare const prefixCls: string;
|
|
4
|
+
declare const favicon: string;
|
|
3
5
|
declare const modifyVars: Record<string, string | false | undefined>;
|
|
4
6
|
export default modifyVars;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CONFIG as i}from"../config.mjs";let f=i.prefixCls||"n",n={"@prefix-cls":f,"@ant-prefix":f,"@iconfont-css-prefix":`${f}-icon`,"@favicon":i.
|
|
1
|
+
import{CONFIG as i}from"../config.mjs";let f=i.prefixCls||"n",n=i.htmlPluginOption?.favicon||"favicon.ico",o={"@prefix-cls":f,"@ant-prefix":f,"@iconfont-css-prefix":`${f}-icon`,"@favicon":JSON.stringify(`${i.publicPath||""}${n}`)};Object.assign(o,i.modifyVars);export default o;
|
package/lib/options/swcrc.d.mts
CHANGED
|
@@ -9,6 +9,13 @@ import reslove from './reslove.mjs';
|
|
|
9
9
|
declare function transformConfigs(config: SwcImportOnDemandTransform);
|
|
10
10
|
declare const importOnDemand: SwcImportOnDemandTransform;
|
|
11
11
|
declare const env: EnvConfig;
|
|
12
|
+
export type SwcOption = SwcConfig & {
|
|
13
|
+
module?: {
|
|
14
|
+
resolveFully: boolean;
|
|
15
|
+
};
|
|
16
|
+
parseMap?: boolean;
|
|
17
|
+
sync?: boolean;
|
|
18
|
+
};
|
|
12
19
|
declare const _dts_1: (ssr: boolean, other: {
|
|
13
20
|
}) => any;
|
|
14
21
|
export default _dts_1;
|
package/lib/plugins.config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";import{CopyPlugin as t}from"./plugin/copy.mjs";import{HtmlPlugin as i}from"./plugin/html-plugin.mjs";import o from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as l}from"./plugin/virtual-module.mjs";import{CONFIG as
|
|
1
|
+
import e from"webpack";import{CopyPlugin as t}from"./plugin/copy.mjs";import{HtmlPlugin as i}from"./plugin/html-plugin.mjs";import o from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as l}from"./plugin/virtual-module.mjs";import{CONFIG as r}from"./config.mjs";import{description as n,keywords as p}from"./process-env.mjs";let a=[...o,new l(r.virtualModule),new t(r.copy),new e.DefinePlugin({"process.env":JSON.stringify(r.env)}),new e.IgnorePlugin({resourceRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),...r.plugins].filter(Boolean);if(r.htmlPluginOption){let e={charset:"UTF-8","X-UA-Compatible":{"http-equiv":"X-UA-Compatible",content:"IE=edge,Chrome=1"},HandheldFriendly:"true",MobileOptimized:"320","screen-orientation":"portrait","x5-orientation":"portrait",browsermode:"application","x5-page-mode":"app","msapplication-tap-highlight":"no","mobile-web-app-capable":"yes",renderer:"webkit",description:n,keywords:Array.isArray(p)?p.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};r.seo&&(e.relCanonical={rel:"canonical",href:`https://${r.seo.domain}${r.basename}`}),r.htmlPluginOption.meta&&Object.assign(e,r.htmlPluginOption.meta),a.push(new i({...r.htmlPluginOption,meta:e}))}if(r.fixBrowserRouter){let e=r.basename.split("/").filter(Boolean).length,t=`${Array(e).fill("..").join("/")+(e?"/":"")}404.html`,o=r.fixBrowserRouter.pathSegmentsToKeep??e;a.push(new i({filename:r.fixBrowserRouter.path??t,inject:!1,templateContent:()=>`<html lang="en"><head><title>Redirect</title><script>const pathKeep = ${o};const l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}))}r.sourceMap&&a.push(new e.SourceMapDevToolPlugin(r.sourceMap));export default a;
|
package/lib/process-env.d.mts
CHANGED
|
@@ -12,6 +12,9 @@ export declare const isSolid: boolean;
|
|
|
12
12
|
export declare const SSR: boolean;
|
|
13
13
|
export declare const mainDirectory: 'site' | 'src';
|
|
14
14
|
export declare const jsxImportSource: string;
|
|
15
|
+
export declare const framework: 'react' | 'solid-js';
|
|
16
|
+
export declare const frameworkVersionStr: string;
|
|
17
|
+
export declare const frameworkVersion: number;
|
|
15
18
|
declare const info: Record<string, unknown>;
|
|
16
19
|
export declare const description: string;
|
|
17
20
|
export declare const author: string | Record<string, string>;
|
package/lib/process-env.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"./commom/has-pkg.mjs";import r from"./commom/require.mjs";export const APPTYPE=process.env.APPTYPE;export const FRAMEWORK=process.env.FRAMEWORK;export const NODE_ENV=process.env.NODE_ENV;export const isLibrary="library"===APPTYPE;export const isMicro="micro"===APPTYPE;export const isMobile="mobile"===APPTYPE;export const isReact="react"===FRAMEWORK;export const isSolid="solid"===FRAMEWORK;export const SSR="true"===process.env.SSR;export const mainDirectory=isLibrary?"site":"src";export const jsxImportSource={react:"react",solid:"solid-js/h"}[FRAMEWORK];let e=r(`${process.cwd()}/package.json`);export const description=e.description;export const author=e.author;export const repository=e.repository;export const keywords=e.keywords;export const PACKAGENAME=e.name;export const PACKAGEVERSION=e.version;export const coreName="@moneko/core";export const isDev="development"===NODE_ENV;export const refresh=!!(isDev&&(o("solid-refresh")||o("react-refresh")));
|
|
1
|
+
import o from"./commom/has-pkg.mjs";import r from"./commom/require.mjs";export const APPTYPE=process.env.APPTYPE;export const FRAMEWORK=process.env.FRAMEWORK;export const NODE_ENV=process.env.NODE_ENV;export const isLibrary="library"===APPTYPE;export const isMicro="micro"===APPTYPE;export const isMobile="mobile"===APPTYPE;export const isReact="react"===FRAMEWORK;export const isSolid="solid"===FRAMEWORK;export const SSR="true"===process.env.SSR;export const mainDirectory=isLibrary?"site":"src";export const jsxImportSource={react:"react",solid:"solid-js/h"}[FRAMEWORK];export const framework={react:"react",solid:"solid-js"}[FRAMEWORK];export const frameworkVersionStr=r(`${framework}/package.json`).version;export const frameworkVersion=parseFloat(frameworkVersionStr);let e=r(`${process.cwd()}/package.json`);export const description=e.description;export const author=e.author;export const repository=e.repository;export const keywords=e.keywords;export const PACKAGENAME=e.name;export const PACKAGEVERSION=e.version;export const coreName="@moneko/core";export const isDev="development"===NODE_ENV;export const refresh=!!(isDev&&(o("solid-refresh")||o("react-refresh")));
|
package/lib/vm/docs.d.mts
CHANGED
|
@@ -5,10 +5,9 @@ import paths from '../commom/paths.mjs';
|
|
|
5
5
|
import ReactiveObject from '../commom/reactive-object.mjs';
|
|
6
6
|
import Rule from '../commom/rule.mjs';
|
|
7
7
|
import { CONFIG } from '../config.mjs';
|
|
8
|
-
import { FRAMEWORK, isLibrary, isReact, isSolid } from '../process-env.mjs';
|
|
8
|
+
import { FRAMEWORK, framework, isLibrary, isReact, isSolid } from '../process-env.mjs';
|
|
9
9
|
import generateDoc from './generate-doc.mjs';
|
|
10
10
|
declare const createElement: string;
|
|
11
|
-
declare const FRAMEWORKNAME: string;
|
|
12
11
|
declare const moduleMeta: ModuleMeta;
|
|
13
12
|
export declare const docsModuleName: string;
|
|
14
13
|
export declare const docsModulePkgJson: string;
|
package/lib/vm/docs.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{relative as e,sep as t}from"node:path";import{loadFile as o,scanFolderSync as m}from"@moneko/utils";import a from"../commom/parse-module-meta.mjs";import
|
|
1
|
+
import{relative as e,sep as t}from"node:path";import{loadFile as o,scanFolderSync as m}from"@moneko/utils";import a from"../commom/parse-module-meta.mjs";import n from"../commom/paths.mjs";import r from"../commom/reactive-object.mjs";import s from"../commom/rule.mjs";import{CONFIG as l}from"../config.mjs";import{FRAMEWORK as c,framework as p,isLibrary as i,isReact as d,isSolid as f}from"../process-env.mjs";import u from"./generate-doc.mjs";let g={react:"createElement",solid:"createComponent"}[c],h=a("@app/docs");export const docsModuleName=h.file;export const docsModulePkgJson=h.pkg;export const docsModuleMeta=h.meta;export const docs=new r({[docsModuleName]:"export default {}",[docsModulePkgJson]:docsModuleMeta});export const comment=new r({});export const getCommentPath=function(){let e=/\/(.+?)\.tsx?$/,t=l.alias["@pkg"]?.length;return o=>o.substring(t).replace(/\\/g,"/").replace(e,"@app/comment/$1.md")}();if(i&&!1!==l.htmlPluginOption){let r={},c=`import { ${g}${f?",Dynamic":""} } from "${p}${f?"/web":""}";import SuspenseComp from "@app/suspense";function call_then(res) {return {default: ${d?"() =>":""}${g}(${f?"Dynamic":"'div'"}, {${f?"innerHTML: res.default, component: 'div', class: 'n-md-box' ":"dangerouslySetInnerHTML: {__html:res.default}, className: 'n-md-box'"} })};}`,i=(e,o)=>{if(!e.endsWith("package.json")){let m=e.replace(/@app[/\\]comment[/\\]/,"").split(t),a=m.pop(),n=m.join("/");r[n]||(r[n]={}),o?r[n][a]&&delete r[n][a]:r[n][a]=`rr(() => ${g}(SuspenseComp, { comp: () => import(/* webpackChunkName: '${e}' */ '${e}?raw').then(call_then)}))rr`;let l={};for(let e in r)Object.prototype.hasOwnProperty.call(r,e)&&(l[e]=Object.values(r[e]));docs.setData(docsModuleName,`${c}export default ${JSON.stringify(l).replace(s.extract_func,"$1")}`)}};comment.on("change",(t,o)=>{i(e(n.nodeModules,t),o?.length<0)});let h=m(l.alias["@pkg"],["\\.tsx?$"]).filter(e=>!/(^|\/)\.[^\\/\\.]|\.test\./i.test(e));await Promise.all(h.map(async e=>({data:await o(e),file:e}))).then(e=>{for(let t=0;t<e.length;t++){let o=e[t];if(o.data){let{file:e,pkg:t,meta:m}=a(getCommentPath(o.file));comment.setData(e,u(o.data,o.file)),comment.setData(t,m)}}})}
|
package/lib/vm/info.d.mts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import require from '../commom/require.mjs';
|
|
2
1
|
import { CONFIG } from '../config.mjs';
|
|
3
|
-
import { APPTYPE, author, description,
|
|
2
|
+
import { APPTYPE, author, description, framework, frameworkVersionStr, PACKAGENAME, PACKAGEVERSION, repository, SSR } from '../process-env.mjs';
|
|
4
3
|
import { convertToCamelCase } from '../utils/index.mjs';
|
|
5
|
-
declare const framework: 'react' | 'solid-js';
|
|
6
|
-
declare const frameworkVersion: string;
|
|
7
4
|
declare const iStr: boolean;
|
|
8
5
|
declare const app: {
|
|
9
6
|
readonly name;
|
|
@@ -19,6 +16,6 @@ declare const app: {
|
|
|
19
16
|
readonly author;
|
|
20
17
|
readonly repository;
|
|
21
18
|
readonly frameworkVersion;
|
|
22
|
-
readonly
|
|
19
|
+
readonly framework;
|
|
23
20
|
};
|
|
24
21
|
export default app;
|
package/lib/vm/info.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{CONFIG as e}from"../config.mjs";import{APPTYPE as r,author as o,description as t,framework as m,frameworkVersionStr as s,PACKAGENAME as i,PACKAGEVERSION as p,repository as a,SSR as f}from"../process-env.mjs";import{convertToCamelCase as n}from"../utils/index.mjs";let l="string"==typeof o,u={name:i,projectName:n(i),ssr:f,version:p,base:e.basename,type:r,routerMode:e.routerMode,prefixCls:e.prefixCls,theme:e.theme,description:t,author:l?{name:o}:o,repository:l?{url:a}:a,frameworkVersion:s,framework:m};export default u;
|
package/lib/vm/modules.d.mts
CHANGED
|
@@ -16,6 +16,7 @@ import getCoverage from './coverage.mjs';
|
|
|
16
16
|
import { docs, docsModuleName } from './docs.mjs';
|
|
17
17
|
import info from './info.mjs';
|
|
18
18
|
import { locales, localesModuleName } from './locales.mjs';
|
|
19
|
+
import renderApp from './render-app.mjs';
|
|
19
20
|
import { route, routesModuleName } from './routes.mjs';
|
|
20
21
|
declare const mdxScope: string | false;
|
|
21
22
|
declare const normalModules: Record<string, string>;
|
package/lib/vm/modules.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as
|
|
1
|
+
import{join as m}from"node:path";import{getAppEntry as o,getAppFallback as p,getAppMdxScope as e,getAppMergeRouter as t,getAppNormalizeCss as r,getAppPrefixRouter as s,getAppRem as a,getAppSuspense as i}from"@moneko/mdx";import{updateFileSync as n}from"@moneko/utils";import f from"../commom/has-pkg.mjs";import l from"../commom/parse-module-meta.mjs";import d from"../commom/paths.mjs";import c from"../commom/rule.mjs";import{CONFIG as x}from"../config.mjs";import u from"../plugin/module-federation.mjs";import{APPTYPE as j,FRAMEWORK as g}from"../process-env.mjs";import y from"../utils/create-types.mjs";import{generateDeclaration as v}from"../utils/dts.mjs";import{node_modules as h}from"../utils/index.mjs";import k from"./coverage.mjs";import{docs as O,docsModuleName as S}from"./docs.mjs";import b from"./info.mjs";import{locales as z,localesModuleName as D}from"./locales.mjs";import J from"./render-app.mjs";import{route as N,routesModuleName as $}from"./routes.mjs";let C=f(m(x.alias["@"],"./mdx-scope.tsx"))||f(m(x.alias["@"],"./mdx-scope.ts")),P={"@app/env.ts":`export default ${JSON.stringify(x.env)}`,"@app/info.ts":`export default ${JSON.stringify(b)}`,"@app/render.tsx":"react"===g?J:"","@app/entry.ts":o(m(x.alias["@"],"./index.ts"),!!u.length,!!x.rem,!!x.normalizeCss,j,g),"@app/rem":a(x.rem?.designSize||1680),"@app/fallback":p(x.fallbackCompPath),"@app/coverage":k(d.coveragePath),"@app/merge-router":t(),"@app/prefix-router":s(),"@app/normalize/index.css":r(),"@app/suspense/index.tsx":i(j,g),"@app/mdx-scope.tsx":C?e(C):"export default {}","@app/routes":N.getData($),"@app/locales":z.getData(D),"@app/docs":O.getData(S)};n(h("@types/@app/index.d.ts"),["@app/env.ts","@app/info.ts","@app/entry.ts","@app/mdx-scope.tsx"].map(m=>y(m.replace(c.js,""),v(P[m],m))).join("\n"));let M=h("@types/@vm/index.d.ts"),q=x.virtualModule||{};n(M,Object.keys(q).map(m=>{let o=q[m],{file:p}=l(m);return y(m,v("string"==typeof o?o:`export default ${JSON.stringify(o)}`,p))}).join("\n"));export default P;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CONFIG } from '../config.mjs';
|
|
2
|
+
import { APPTYPE, frameworkVersion, isDev, SSR } from '../process-env.mjs';
|
|
3
|
+
declare const ReactDomPath: string;
|
|
4
|
+
declare const isHashRouter: boolean;
|
|
5
|
+
declare const v7Future: Record<string, boolean | undefined>;
|
|
6
|
+
declare const createRouter: string;
|
|
7
|
+
declare const renderApp: string;
|
|
8
|
+
export default renderApp;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import{CONFIG as e}from"../config.mjs";import{APPTYPE as r,frameworkVersion as t,isDev as a,SSR as n}from"../process-env.mjs";let o="hash"===e.routerMode,s=Object.assign({v7_relativeSplatPath:!1},"browser"===e.routerMode?{v7_fetcherPersist:!1,v7_normalizeFormMethod:!1,v7_partialHydration:n,v7_skipActionErrorRevalidation:!1}:{}),c=o?"createHashRouter":"createBrowserRouter",i=`import React, { StrictMode, useRef, type ReactElement } from 'react';
|
|
2
|
+
import Fallback from '@app/fallback';
|
|
3
|
+
import routes from '@app/routes';
|
|
4
|
+
import ReactDOM from '${t<18?"react-dom":"react-dom/client"}';
|
|
5
|
+
import { RouterProvider, ${c} } from 'react-router-dom';
|
|
6
|
+
|
|
7
|
+
type RenderAppProps = {
|
|
8
|
+
container?: HTMLElement;
|
|
9
|
+
basename?: string;
|
|
10
|
+
fallback?: ReactElement;
|
|
11
|
+
language?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function App(props: RenderAppProps) {
|
|
15
|
+
const v7Future = useRef(${JSON.stringify(s)});
|
|
16
|
+
return (
|
|
17
|
+
<StrictMode>
|
|
18
|
+
<RouterProvider
|
|
19
|
+
router={${c}(routes, {
|
|
20
|
+
basename: ${o?"/":"props.basename"},
|
|
21
|
+
window: window,
|
|
22
|
+
future: v7Future.current,
|
|
23
|
+
})}
|
|
24
|
+
future={{
|
|
25
|
+
/** 这使用 useTransition 而不是 useState 来更新路由器状态 */
|
|
26
|
+
v7_startTransition: false,
|
|
27
|
+
}}
|
|
28
|
+
fallbackElement={Fallback && <Fallback />}
|
|
29
|
+
/>
|
|
30
|
+
</StrictMode>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function renderApp(props: RenderAppProps = {}) {
|
|
35
|
+
const { container, basename = "${e.basename}", language, ...args } = props;
|
|
36
|
+
const _container = container?.querySelector('#root') || document.getElementById('root');
|
|
37
|
+
${"micro"===r?"window.mainApp = { ...args, container: _container as HTMLElement };":""}
|
|
38
|
+
${t<18?`ReactDOM.${a?"render":"hydrate"}(<App basename={basename} language={language} />, _container);return () => ReactDOM.unmountComponentAtNode(_container as Element);`:"const instance = ReactDOM.createRoot(_container as HTMLElement);instance.render(<App basename={basename} language={language} />);return instance.unmount;"}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default renderApp;`;export default i;
|