@moneko/core 4.0.0-bate.1 → 4.0.0-bate.3
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/commom/reactive-object.d.mts +2 -1
- package/lib/commom/reactive-object.mjs +1 -1
- package/lib/commom/rule.d.mts +0 -1
- package/lib/commom/rule.mjs +1 -1
- package/lib/common.mjs +1 -1
- package/lib/config.mjs +1 -1
- package/lib/dev/mock.d.mts +3 -6
- package/lib/dev/mock.mjs +1 -1
- package/lib/dev/server.mjs +1 -1
- package/lib/dev.mjs +2 -2
- package/lib/index.d.mts +1 -0
- package/lib/module.config.mjs +1 -1
- package/lib/options/reslove.d.mts +0 -1
- package/lib/options/reslove.mjs +1 -1
- package/lib/options/split-chunk.mjs +1 -1
- package/lib/plugin/css-module-dts.mjs +1 -1
- package/lib/plugin/virtual-module.d.mts +13 -0
- package/lib/plugin/virtual-module.mjs +1 -0
- package/lib/plugins.config.mjs +1 -1
- package/lib/process-env.d.mts +5 -0
- package/lib/process-env.mjs +1 -1
- package/lib/vm/app.d.mts +3 -0
- package/lib/vm/app.mjs +1 -0
- package/lib/vm/docs.d.mts +3 -4
- package/lib/vm/docs.mjs +1 -1
- package/lib/vm/example.d.mts +3 -2
- package/lib/vm/example.mjs +1 -1
- package/lib/vm/generate-doc.mjs +1 -1
- package/lib/vm/info.d.mts +11 -1
- package/lib/vm/locales.d.mts +1 -4
- package/lib/vm/locales.mjs +2 -2
- package/lib/vm/render-app.d.mts +2 -2
- package/lib/vm/render-app.mjs +8 -8
- package/lib/vm/routes.d.mts +0 -5
- package/lib/vm/routes.mjs +1 -1
- package/lib/vm/scope.d.mts +3 -0
- package/lib/vm/scope.mjs +1 -0
- package/lib/vm/virtual.d.mts +3 -0
- package/lib/vm/virtual.mjs +1 -0
- package/package.json +2 -3
- package/typings/global.d.ts +2 -0
- package/lib/commom/parse-module-meta.d.mts +0 -1
- package/lib/loader/ts-doc.cjs +0 -1
- package/lib/loader/ts-doc.d.cts +0 -7
- package/lib/options/css-extract.d.mts +0 -1
- package/lib/vm/modules.d.mts +0 -5
- package/lib/vm/modules.mjs +0 -1
- package/lib/vm/utils.d.mts +0 -1
- package/lib/vm/utils.mjs +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import EventEmitter from 'node:events';
|
|
2
|
-
declare class ReactiveObject<T extends object = Record<string,
|
|
2
|
+
declare class ReactiveObject<T extends object = Record<string, unknown | undefined>> extends EventEmitter {
|
|
3
3
|
readonly data: T;
|
|
4
4
|
constructor(props?: T);
|
|
5
|
+
has(key: keyof T): boolean;
|
|
5
6
|
setData(key: keyof T, value: T[keyof T]): void;
|
|
6
7
|
getData(key: keyof T): T[keyof T];
|
|
7
8
|
removeData(key: keyof T): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"node:events";class e extends t{constructor(t={}){super(),this.data=t,this.setMaxListeners(0)}setData(t,e){this.data[t]!==e&&(this.data[t]=e,this.emit("change",t,e))}getData(t){return this.data[t]}removeData(t){Object.prototype.hasOwnProperty.call(this.data,t)&&(delete this.data[t],this.emit("change",t,null))}[Symbol.iterator](){let t=Object.keys(this.data),e=0;return{next:()=>{if(e<t.length){let a=t[e++];return{value:[a,this.data[a]],done:!1}}return{value:void 0,done:!0}}}}}export default e;
|
|
1
|
+
import t from"node:events";class e extends t{constructor(t={}){super(),this.data=t,this.setMaxListeners(0)}has(t){return t in this.data}setData(t,e){this.data[t]!==e&&(this.data[t]=e,this.emit("change",t,e))}getData(t){return this.data[t]}removeData(t){Object.prototype.hasOwnProperty.call(this.data,t)&&(delete this.data[t],this.emit("change",t,null))}[Symbol.iterator](){let t=Object.keys(this.data),e=0;return{next:()=>{if(e<t.length){let a=t[e++];return{value:[a,this.data[a]],done:!1}}return{value:void 0,done:!0}}}}}export default e;
|
package/lib/commom/rule.d.mts
CHANGED
package/lib/commom/rule.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default{js:/\.(cj|mj|t|j)s(|x)$/i,css:/\.css$/i,less:/\.less$/i,scss:/\.(sa|sc)ss$/i,wasm:/\.wasm$/i,txt:/\.txt$/i,image:/\.(gif|png|jpe?g|webp|svg|ico)$/i,video:/\.(webm|mp4|ogv)$/i,font:/\.(woff2?|eot|ttf|otf)(\?.*)?$/i,markdown:/\.mdx?$/i,tsdoc:/^(?![._]).*(?<!\.test)\.(tsx?)$/,css_module:/(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i,node_modules_css_module:/(^(?!.*node_modules))(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i,node_modules:/node_modules/,__tests__:/(.+)\/__tests__\/(.+)/,
|
|
1
|
+
export default{js:/\.(cj|mj|t|j)s(|x)$/i,css:/\.css$/i,less:/\.less$/i,scss:/\.(sa|sc)ss$/i,wasm:/\.wasm$/i,txt:/\.txt$/i,image:/\.(gif|png|jpe?g|webp|svg|ico)$/i,video:/\.(webm|mp4|ogv)$/i,font:/\.(woff2?|eot|ttf|otf)(\?.*)?$/i,markdown:/\.mdx?$/i,tsdoc:/^(?![._]).*(?<!\.test)\.(tsx?)$/,css_module:/(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i,node_modules_css_module:/(^(?!.*node_modules))(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i,node_modules:/[\\/]node_modules[\\/]/,__tests__:/(.+)\/__tests__\/(.+)/,extract_func:/"rr\((.+?)\)rr"/g};
|
package/lib/common.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extname as e,join as t,resolve as
|
|
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{isObject as c,md5 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,docs_schema as y,isCI as b,isDev as j,isLibrary as v,NODE_ENV as C,packageJson as P}from"./process-env.mjs";export const outputConfig={path:u(v?"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_${P.name}`,pathinfo:j,clean:!0,publicPath:d.publicPath,asyncChunks:!0,charset:!0,iife:!0,crossOriginLoading:"use-credentials",enabledWasmLoadingTypes:["fetch"],uniqueName:`${h.projectName}`};let k={main:[`${g}:entry`]},x=[t(a.corePath,"./polyfills/public-path.mjs")];if(j&&x.push(`${g}:mock`),j&&d.refresh&&d.env.injectRemoteReactRefresh&&x.push(t(a.corePath,"./polyfills/inject-react-refresh.mjs")),d.polyfill&&x.push(t(a.corePath,"./polyfills/replace-children.mjs")),d.entry&&("string"==typeof d.entry?k={...k,main:[d.entry]}:Object.keys(d.entry)&&(k=Object.assign(k,d.entry))),"string"==typeof k.main?k.main=[...x,k.main]:Array.isArray(k.main)&&(k.main=[...x,...k.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 M={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:a.webpackCachePath,memoryCacheUnaffected:!j,name:p(`${i}-${C}-${s[2]}`),version:`${P.version}`,buildDependencies:{config:n},maxMemoryGenerations:1};!1===d.cache?M=!1:c(d.cache)&&(M=Object.assign(M,d.cache)),b&&(void 0===d.cache||d.cache&&!d.cache.cacheDirectory)&&(M.cacheDirectory=o(r,P.name));let $={},w={imports:!0,entries:!0,test:e=>{let t=e.nameForCondition();return!!(t&&(t.includes(`${y}:example`)||t.includes(`${y}:comment`)||t.startsWith(a.pagesPath)||t.startsWith(a.componentsPath)))}};d.lazyCompilation&&j&&"true"!==process.env.IS_BUILD?c(d.lazyCompilation)?Object.assign($,w,d.lazyCompilation):Object.assign($,w):$=!1;export const commonConfig={name:"client",target:"web",devtool:d.devtool,entry:k,mode:d.mode??"production",stats:"errors-only",cache:M,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}},infrastructureLogging:{level:"error"},externalsPresets:d.externalsPresets,plugins:f,node:{global:!1,__filename:!1,__dirname:!1},experiments:{asyncWebAssembly:!0,cacheUnaffected:!j,lazyCompilation:$,buildHttp:c(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?t(a.programPath,d.recordsPath):t(a.webpackCachePath,"records.json")};d.overrideResolve&&commonConfig.resolve.plugins.push(new m(Object.assign({original:d.alias["@"],override:i&&u(i)},d.overrideResolve)));
|
package/lib/config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as e,relative as o}from"node:path";import t from"node:process";import{merge as a}from"webpack-merge";import n from"./commom/paths.mjs";import s from"./commom/setup-env.mjs";import r from"./options/jsx-dom-expressions.mjs";import i from"./options/split-chunk.mjs";import{getConfigWithTypescript as l,isFunction as m,node_modules as p,resolveProgram as c}from"./utils/index.mjs";import{APPTYPE as u,FRAMEWORK as d,frameworkVersion as f,isCI as h,isDev as g,isLibrary as v,isMobile as x,isReact as P,jsxImportSource as b,mainDirectory as C,NODE_ENV as j,PACKAGENAME as k}from"./process-env.mjs";let w=[/(app|vm):[a-zA-Z_0-9]/,"@moneko","neko-ui",".cache/http/data","@element-plus","ant-design-vue","element-plus","element-ui","ng-zorro-antd","@mui","@du","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design","monaco-editor"];export async function getConfig(e){let o=l(e).default;return(m(o)?await o(t):o)??{}}let I=await s(j,u,d,[],"true"===t.env.IS_BUILD),[O,S]=await Promise.all([getConfig(n.configPath),getConfig(n.customConfigPath)]),y={mode:j,strict:!1,devtool:"true"!==t.env.IS_BUILD&&g?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:"",namespace:k,moduleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]",fallbackModuleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]"},env:I,basename:"/",publicPath:"auto",rem:{designSize:x?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":c(C)},P&&f<18?{"react/package.json":p("react/package.json"),"react/jsx-runtime":p("react/jsx-runtime.js"),"react/jsx-dev-runtime":p("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3,open:!0},htmlPluginOption:{title:k.toLocaleUpperCase(),favicon:o(n.programPath,`${n.corePath}/options/favicon.ico`)},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:i,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:w,js:w,media:w,font:w,wasm:[]},mdx:{jsx:!1,development:g,jsxImportSource:b,providerImportSource:`@moneko/${d}/mdx`},jsxDomExpressions:r,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69",quiet:h},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==d,bundleId:"com.moneko.bid",bundles:[],stylelint:{},eslint:{lintDirtyModulesOnly:!1},minChunkSize:1e3,compression:"true"!==t.env.IS_BUILD,manifest:{filename:"site.webmanifest"},corepack:!0,reactJsxRuntime:"automatic"};v&&(y.alias=Object.assign(y.alias,{"@pkg":n.componentsPath,[k]:n.componentsPath}));let M=y;(!1===(M=a(M,O,S)).devtool||!1===M.sourceMap)&&(M.sourceMap=!1,M.devtool=!1),"true"===t.env.CODESPACES&&(M.devServer.https=!1),!1===M.devServer.https&&"darwin"===t.platform&&(M.devServer.open=!1),M.htmlPluginOption&&(M.htmlPluginOption.tags||(M.htmlPluginOption.tags=[]),M.fixBrowserRouter&&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))"}),M.manifest&&(M.manifest.publicPath||(M.manifest.publicPath=M.basename),M.htmlPluginOption.tags.push({href:e(M.manifest.publicPath,M.manifest.filename).replaceAll(/\\/g,"/"),tag:"link",rel:"manifest"})));export const CONFIG=M;export const PUBLICPATH="auto"===CONFIG.publicPath?"":CONFIG.publicPath;
|
|
1
|
+
import{join as e,relative as o}from"node:path";import t from"node:process";import{merge as a}from"webpack-merge";import n from"./commom/paths.mjs";import s from"./commom/setup-env.mjs";import r from"./options/jsx-dom-expressions.mjs";import i from"./options/split-chunk.mjs";import{getConfigWithTypescript as l,isFunction as m,node_modules as p,resolveProgram as c}from"./utils/index.mjs";import{APPTYPE as u,FRAMEWORK as d,frameworkVersion as f,isCI as h,isDev as g,isLibrary as v,isMobile as x,isReact as P,jsxImportSource as b,mainDirectory as C,NODE_ENV as j,PACKAGENAME as k}from"./process-env.mjs";let w=[/(app|vm|docs|example):[a-zA-Z_0-9]/,"@moneko","neko-ui",".cache/http/data","@element-plus","ant-design-vue","element-plus","element-ui","ng-zorro-antd","@mui","@du","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design","monaco-editor"];export async function getConfig(e){let o=l(e).default;return(m(o)?await o(t):o)??{}}let I=await s(j,u,d,[],"true"===t.env.IS_BUILD),[O,S]=await Promise.all([getConfig(n.configPath),getConfig(n.customConfigPath)]),y={mode:j,strict:!1,devtool:"true"!==t.env.IS_BUILD&&g?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:"",namespace:k,moduleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]",fallbackModuleFilenameTemplate:"moneko://[namespace]/[resource-path]?[loaders]"},env:I,basename:"/",publicPath:"auto",rem:{designSize:x?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":c(C)},P&&f<18?{"react/package.json":p("react/package.json"),"react/jsx-runtime":p("react/jsx-runtime.js"),"react/jsx-dev-runtime":p("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3,open:!0},htmlPluginOption:{title:k.toLocaleUpperCase(),favicon:o(n.programPath,`${n.corePath}/options/favicon.ico`)},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:i,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:w,js:w,media:w,font:w,wasm:[]},mdx:{jsx:!1,development:g,jsxImportSource:b,providerImportSource:`@moneko/${d}/mdx`},jsxDomExpressions:r,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69",quiet:h},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==d,bundleId:"com.moneko.bid",bundles:[],stylelint:{},eslint:{lintDirtyModulesOnly:!1},minChunkSize:1e3,compression:"true"!==t.env.IS_BUILD,manifest:{filename:"site.webmanifest"},corepack:!0,reactJsxRuntime:"automatic"};v&&(y.alias=Object.assign(y.alias,{"@pkg":n.componentsPath,[k]:n.componentsPath}));let M=y;(!1===(M=a(M,O,S)).devtool||!1===M.sourceMap)&&(M.sourceMap=!1,M.devtool=!1),"true"===t.env.CODESPACES&&(M.devServer.https=!1),!1===M.devServer.https&&"darwin"===t.platform&&(M.devServer.open=!1),M.htmlPluginOption&&(M.htmlPluginOption.tags||(M.htmlPluginOption.tags=[]),M.fixBrowserRouter&&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))"}),M.manifest&&(M.manifest.publicPath||(M.manifest.publicPath=M.basename),M.htmlPluginOption.tags.push({href:e(M.manifest.publicPath,M.manifest.filename).replaceAll(/\\/g,"/"),tag:"link",rel:"manifest"})));export const CONFIG=M;export const PUBLICPATH="auto"===CONFIG.publicPath?"":CONFIG.publicPath;
|
package/lib/dev/mock.d.mts
CHANGED
|
@@ -53,13 +53,10 @@ export type YApiOption = {
|
|
|
53
53
|
* @returns {Promise} data
|
|
54
54
|
*/
|
|
55
55
|
export declare const yApiMock: (req: RequestFormData, yapi: YApiOption) => Promise<Any>;
|
|
56
|
-
export
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
export declare const oldMock: MockConfiguration;
|
|
60
|
-
export declare let nextMock: MockConfiguration;
|
|
56
|
+
export declare const updateMocks: () => {} | undefined;
|
|
57
|
+
export declare let mocks: MockConfiguration;
|
|
61
58
|
export declare function containMockUrl(url: string): string | undefined;
|
|
62
|
-
declare const setupMock: (
|
|
59
|
+
declare const setupMock: () => ((req: RequestFormData, res: ServerResponse<IncomingMessage> & {
|
|
63
60
|
req: IncomingMessage;
|
|
64
61
|
}) => boolean | (http.ServerResponse<http.IncomingMessage> & {
|
|
65
62
|
req: IncomingMessage;
|
package/lib/dev/mock.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:http";import{StringDecoder as t}from"node:string_decoder";import{URL as r}from"node:url";import{directoryExists as o,ink as n,print as a}from"@moneko/utils";import{
|
|
1
|
+
import e from"node:http";import{StringDecoder as t}from"node:string_decoder";import{URL as r}from"node:url";import{directoryExists as o,ink as n,print as a,scanFolderSync as c}from"@moneko/utils";import{merge as i}from"webpack-merge";import s from"../commom/log.mjs";import m from"../commom/match-path.mjs";import d from"../commom/paths.mjs";import l,{METHOD_COLOR as p}from"../commom/print-log.mjs";import u from"../commom/require.mjs";import{jsonSchema as f}from"./json-schema.mjs";function h(e){return!["GET","HEAD","OPTIONS"].includes(e.method?.toUpperCase()||"")}export function cacheBody(e){if(!e._bodyCached&&h(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){s(e)}}}function g(e,r){try{let o=Buffer.concat(e);if(r.includes("application/json")){let e=new t("utf-8").write(o);return JSON.parse(e)}if(r.includes("application/octet-stream")||r.startsWith("image/"));else if(r.includes("text/"))return o.toString("utf-8");else if(r.includes("application/x-www-form-urlencoded"))return Object.fromEntries(new URLSearchParams(o.toString("utf8")));return o}catch(e){return s(e),null}}async function y(e){return new Promise(t=>{if(!h(e))return void t(null);let r=e.headers["content-type"]||"",o=e.headers["content-length"],n=e.headers["transfer-encoding"],a=[];return void 0!==e._dataChunks?void t(g(e._dataChunks,r)):o||n?void(e.on("data",e=>{a.push(e)}),e.on("end",()=>{t(g(a,r))}),e.on("error",e=>{t(null),s(e)})):void t(null)})}export const yApiSchemaMock=(t,r)=>new Promise(o=>{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=f(t);void 0!==r?o(i(n,r)):o(n)}}catch(e){s(e)}})})});export const yApiMock=(t,o)=>new Promise((n,a)=>{let c=new r(o.host),i={hostname:c.hostname,port:c.port,path:t.url?.replace(new RegExp(o.pathRewrite),`/mock/${o.projectId}/`),method:t.method,headers:t.headers,query:Object.fromEntries(c.searchParams)},m=e.request(i,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{n(JSON.parse(t))}catch(e){s(e)}})});m.on("error",e=>{a(e.message)}),m.write(JSON.stringify(t.body)),m.end()});export const updateMocks=()=>{if(!o(d.mockPath))return{};let e={},t=c(d.mockPath,["\\.(t|j)s$"]);a(n("Updating mock...","245"),!0),t.forEach(t=>{try{delete u.cache[t],e[t]=u(t).default}catch(e){s(e)}}),a(n("Mock update successful","245"),!0),mocks=e};export let mocks={};export function containMockUrl(e){return Object.keys(mocks).find(t=>RegExp(`^${t.replace(/(:\w*)[^/]/g,"((?!/).)")}*$`).test(e))}export default(()=>{if(o(d.mockPath))return updateMocks(),(e,t)=>{if(t.writableEnded)return t;let o=new r(`http://localhost:3000${e.url}`),n=e.method||"GET",a=`${n} ${o.pathname}`,c=containMockUrl(a)||a,i=mocks[c];if(i){if(l(n,o.pathname,{note:"MOCK",labelAlign:"center",labelLen:8,labelForegroundColor:p[n].fg,labelBackgroundColor:p[n].bg}),t.send=e=>t.end("string"==typeof e?e:JSON.stringify(e)),t.writeHead(200,{"Content-Type":e.headers["content-type"]}),"function"==typeof i){let r=m(c.split(" ")[1],o.pathname);o.searchParams&&Object.assign(e,{query:Object.fromEntries(o.searchParams)}),r&&Object.assign(e,{params:r.params}),e.body=y(e);try{i(e,t)}catch(e){s(e)}return!0}return t.end("string"==typeof i?i:JSON.stringify(i)),!0}return!1}});
|
package/lib/dev/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createServer as e}from"node:http";import{createServer as t}from"node:https";import{platform as o}from"node:os";import{extname as r,join as n,sep as i}from"node:path";import{env as s}from"node:process";import{ink as a,println as m}from"@moneko/utils";import{CA_ORGANIZATION as
|
|
1
|
+
import{createServer as e}from"node:http";import{createServer as t}from"node:https";import{platform as o}from"node:os";import{extname as r,join as n,sep as i}from"node:path";import{env as s}from"node:process";import{ink as a,println as m}from"@moneko/utils";import{CA_ORGANIZATION as l,isCertificateInstalled as p}from"../commom/ca.mjs";import c from"../commom/mime.mjs";import d from"../commom/open.mjs";import{CONFIG as C}from"../config.mjs";import f from"../dev/get-cert.mjs";import{setupProxy as h}from"../dev/proxy.mjs";import u,{cacheBody as A}from"./mock.mjs";let E={"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"Authorization, Content-Type, Accept, X-Requested-With, Origin, DNT, User-Agent, Cache-Control, X-CSRF-Token, X-API-Key, X-Client-Version, X-Device-ID, Content-Language, Accept-Language, X-Custom-Header, X-Mx-ReqToken, Keep-Alive, If-Modified-Since","Access-Control-Allow-Methods":"GET, DELETE, HEAD, OPTIONS, POST, PUT, PATCH, PURGE, LINK, UNLINK, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, REPORT, SEARCH, CONNECT, TRACE","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"};async function y(y){let T=n(y.root_dir,"index.html"),g=u();function w(e,t,o){let n=e.headers["accept-encoding"],i=n?.includes("br"),s=`${o}.${i?"br":"gz"}`,a=y.fileSystem.existsSync(s);a&&t.setHeader("Content-Encoding",i?"br":"gzip");let m=y.fileSystem.createReadStream(a?s:o,{autoClose:!0});m.on("open",()=>{t.writeHead(200,Object.assign({},E,y.headers,{"Access-Control-Allow-Origin":e.headers.origin??"*","Content-Type":c[r(o)]||"application/octet-stream"}))}),m.on("error",e=>{switch(m.readable=!0,e.code){case"ENOENT":t.writeHead(301,{Location:"/index.html"}),t.end();break;case"EACCES":t.writeHead(403,{"Content-Type":"text/plain"}),t.end(`Forbidden: ${e.message}`);break;default:t.writeHead(500,{"Content-Type":"text/plain"}),t.end(`Internal Server Error: ${e.message}`)}}),m.pipe(t)}async function O(e,t){if(A(e),!(y.onRequest&&y.onRequest(e,t))){if(!(C.proxy&&await h(e,t,C.proxy)||t.writableEnded||g&&g(e,t))&&!t.writableEnded){if("GET"===e.method){let o="/"===e.url?T:decodeURIComponent(n(y.root_dir,e.url.replace(y.basename??"/","/")));if(y.fileSystem.existsSync(o))return w(e,t,o)}if(e.headers.accept?.includes("text/html"))return w(e,t,T);t.writeHead(404,{"Content-Type":"text/plain"}),t.end("File Not Found")}}}let x=y.https?t(await f(y.host,!0===y.https?{install:!0}:y.https),O):e(O);if(x.listen(y.port),y.https&&!await p(l)&&"darwin"===o()){let e=s.npm_execpath?.split(i).pop()?.split(".").shift()||"npm",t=s.npm_lifecycle_event??"start",o=`> sudo ${e} ${t}`;m(a("⚠️ 未检测到本地 SSL 证书,请通过以下命令重启项目以安装证书: ","yellow")),m(a(o,"yellow")),m("")}return y.open&&d(`${y.https?"https:":"http:"}//${y.host}:${y.port}${"/"===y.basename?"":y.basename}`),x}export default y;
|
package/lib/dev.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{relative as r}from"node:path";import i from"node:process";import{URL as s}from"node:url";import{ink as n,print as a,println as m,progressBar as l}from"@moneko/utils";import p from"webpack";import c from"webpack-hot-middleware";import{merge as
|
|
2
|
-
`):(l(e||0,1,{msg:r,name:t,barColor:s.barColor,nameColor:s.nameColor,barBgColor:s.barBgColor,msgColor:s.msgColor}),1===e&&i.stdout.write("\r\x1b[2K"))}}})]});function
|
|
1
|
+
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{relative as r}from"node:path";import i from"node:process";import{URL as s}from"node:url";import{ink as n,print as a,println as m,progressBar as l}from"@moneko/utils";import p from"webpack";import c from"webpack-hot-middleware";import{merge as f}from"webpack-merge";import{diffObject as h}from"./commom/diff-object.mjs";import d,{config_files as u}from"./commom/paths.mjs";import g from"./commom/rule.mjs";import w from"./commom/sigint-exit.mjs";import{devLog as y,PORT as $}from"./dev/config.mjs";import j from"./dev/generate-progress-html.mjs";import v from"./dev/server.mjs";import b from"./options/reslove.mjs";import{ESLintPlugin as x}from"./plugin/eslint.mjs";import{StylelintPlugin as C}from"./plugin/stylelint.mjs";import{empty as _}from"./utils/index.mjs";import{CONFIG as P,getConfig as S}from"./config.mjs";import{createDevelopmentConfiguration as k}from"./create-development-configuration.mjs";import{outputFileSystem as E}from"./file-system.mjs";import{isLibrary as B,refresh as H}from"./process-env.mjs";let I=!1,O="/____progress____",T={percentage:0,info:""},q="/__hmr__",G=new URLSearchParams({name:"client",path:q.substring(1),dynamicPublicPath:!0,timeout:2e3,reload:!H,quiet:!0,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),L=await k({watchOptions:{stdin:!0,aggregateTimeout:300,ignored:g.node_modules},entry:{main:[`${b.hotMiddlewareClient}?${G}`]},plugins:[new p.WatchIgnorePlugin({paths:[g.node_modules,/\.d\.ts$/]}),new p.ProgressPlugin({handler(e,t,...o){let r=o.length?`[${t}] ${o.join(" ")}`:" ";I||(T.info=r,T.percentage=e,I=1===e);let s=P.bar;if(s){let t=s.name||"Build";s.quiet?i.stdout.write(`${r}
|
|
2
|
+
`):(l(e||0,1,{msg:r,name:t,barColor:s.barColor,nameColor:s.nameColor,barBgColor:s.barBgColor,msgColor:s.msgColor}),1===e&&i.stdout.write("\r\x1b[2K"))}}})]});function U(e){let t=e.join(","),o=[r(d.programPath,`${P.alias["@"]}/**/*.{${t}}`).replace(/\\/g,"/")];return B&&o.push(r(d.programPath,`${P.alias["@pkg"]}/**/*.{${t}}`).replace(/\\/g,"/")),o}P.eslint&&L.plugins.push(new x({fix:!0,cache:!0,cacheLocation:`${d.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",files:U(["js","jsx","ts","tsx","json","html","vue"]),...P.eslint})),P.stylelint&&L.plugins.push(new C({fix:!0,cache:!0,cacheLocation:`${d.lintCachePath}/.stylelintcache`,files:U(["css","scss","sass","less","ts","tsx","js","jsx"]),...P.stylelint}));let F=p(L);if(!F)throw Error("无法创建编译器");F.outputFileSystem=E;let N=F.watch(F.options.watchOptions,y);if(!N)throw Error("无法创建监视器");F.hooks.done.tap("client-log",e=>{y(null,e)});let R=`${P.basename}/${q}`.replace(/\/+/g,"/"),J=c(F,{log:!1,path:R,heartbeat:2e3}),K=await v({port:$,root_dir:F.options.output.path,fileSystem:F.outputFileSystem,headers:P.devServer.headers,https:P.devServer.https,host:P.devServer.host,open:P.devServer.open,basename:P.basename,onRequest(e,t){if(!t.writableEnded){if("GET"===e.method){let o=new s(`${P.devServer.https?"https":"http"}://${e.headers.host}${e.url}`);if(o.pathname===O)return t.writeHead(200,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),t.end(JSON.stringify(T)),!0;if(!I)return t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(j(O,T)),!0;if(o.pathname===R&&"text/event-stream"===e.headers.accept)return J(e,t,_),!0}return!1}}});function M(){i.exit(0)}K.on("close",()=>{N.close(_),J.close()});let W=await Promise.all(u.map(S)),z=f(W[0]||{},W[1]||{});u.forEach(function(t){o(t,async function(){var o;let[r,s]=await Promise.all(u.map(S)),l=f(r||{},s||{}),p=h(z,l);1===Object.keys(p).length&&"proxy"in p?(a(n(`代理更新中...`,"yellow"),!0),a(n(`代理更新完成...`,"green"),!0),P.proxy=l.proxy,z.proxy=l.proxy,z=l):(z=l,m(n(`检测到工程配置${n(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),o=$,e(A?`netstat -ano | findstr :${o}`:`lsof -i :${o} -t`,(e,t)=>{if(e){m(n(`查找端口 ${o} 时发生错误: ${e.message}`,"red")),m(n("请尝试手动重启程序","yellow"));return}let r=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),s=A?r[0]?.split(/\s+/).pop()?.trim():r[0]?.trim();if(!s)return void m(n(`未找到占用端口 ${o} 的进程, 请尝试手动重启程序`,"yellow"));try{i.kill(Number(s),"SIGHUP")}catch(e){m(n(`终止进程 ${s} 时发生错误: ${e.message}`,"red"))}}))})});let A="win32"===i.platform;i.on("SIGHUP",function(){K.close(_);let e=t(i.argv[0],i.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",M)}),i.on("exit",function(){K.close(_)}),w(M);
|
package/lib/index.d.mts
CHANGED
|
@@ -19,6 +19,7 @@ export type { CompressionPluginOptions } from './plugin/compression.mjs';
|
|
|
19
19
|
export type { HtmlMeta, HtmlPluginOption } from './plugin/html-plugin.mjs';
|
|
20
20
|
export * from './plugin/manifest/index.mjs';
|
|
21
21
|
export type { OverrideResolverOption } from './plugin/override-resolve.mjs';
|
|
22
|
+
export type { VirtualModules } from './plugin/virtual-module.mjs';
|
|
22
23
|
export { APPTYPE, coreName, FRAMEWORK, isCI, isDev, isLibrary, isMicro, mainDirectory, packageJson, PACKAGENAME, } from './process-env.mjs';
|
|
23
24
|
export { type AlgorithmIdentifier, digest, md5, node_modules, resolveProgram, toCamelCase, } from './utils/index.mjs';
|
|
24
25
|
export * from '@moneko/mdx';
|
package/lib/module.config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let e;import{join as s,sep as o}from"node:path";import t,{CUSTOMCONFIG as r}from"./commom/paths.mjs";import a from"./commom/require.mjs";import n from"./commom/rule.mjs";import i from"./options/modify-vars.mjs";import l from"./options/reslove.mjs";import m from"./options/swcrc.mjs";import{getLightningCssTargets as c}from"./polyfills/targets.mjs";import{node_modules as p,resolveProgram as d}from"./utils/index.mjs";import u from"./utils/svg-to-data-uri.mjs";import{
|
|
1
|
+
let e;import{join as s,sep as o}from"node:path";import t,{CUSTOMCONFIG as r}from"./commom/paths.mjs";import a from"./commom/require.mjs";import n from"./commom/rule.mjs";import i from"./options/modify-vars.mjs";import l from"./options/reslove.mjs";import m from"./options/swcrc.mjs";import{getLightningCssTargets as c}from"./polyfills/targets.mjs";import{node_modules as p,resolveProgram as d}from"./utils/index.mjs";import u from"./utils/svg-to-data-uri.mjs";import{outputConfig as f}from"./common.mjs";import{CONFIG as h}from"./config.mjs";import{app_schema as y,FRAMEWORK as j,isDev as x,virtual_schema as g}from"./process-env.mjs";let v={loader:s(t.corePath,"/loader/lightning-css.cjs"),options:{sourceMap:!!h.sourceMap,targets:c(),rem:!!h.rem,importLoaders:2}},w={loader:l.lessLoader,options:{sourceMap:!!h.sourceMap,lessOptions:{modifyVars:i,javascriptEnabled:!0}}},M=new Map,P=["components","example","mock","site","src","server"].map(d);function L(e){return new Promise(s=>{s([...P,t.corePath,...h.rulesInclude?.[e]?.map(e=>"string"==typeof e?function(e){if(M.has(e))return M.get(e);try{let s,t=a.resolve(e).split(o),r=t.lastIndexOf("node_modules");return s=-1!==r?t.slice(0,r).join(o):t.join(o),M.set(e,[s]),[s]}catch{try{let s=a.resolve(`${e}${o}package.json`).replace(`${o}package.json`,"");M.set(e,[s])}catch{M.set(e,[p(e),p(`.pnpm/${e}`)])}return M.get(e)}}(e):e).flat()||[]])})}r&&P.push(d(r)),h.overrideResolve&&h.overrideResolve.override&&P.push(h.overrideResolve.override);let C=await Promise.all([L("css"),L("js"),L("media"),L("wasm"),L("font")]),I=C[0],O=C[1],_=C[2],b=C[3],N=C[4];l.sassLoader&&(e={loader:l.sassLoader,options:{implementation:await import("sass"),sassOptions:{}}});let $=f.library?.type==="umd"&&!1===h.htmlPluginOption,k=[{resourceQuery:/raw/i,type:"asset/source"},{resourceQuery:/url/i,type:"asset/resource",generator:{filename(e){let s=e.filename;return s&&s.toLocaleLowerCase().endsWith("wasm?url")?"wasm/[hash][ext]":"assets/[hash][ext]"}}},{test:n.wasm,type:"webassembly/async",include:b},{test:n.txt,type:"asset/source"},{test:n.image,type:"asset",dependency:{not:["url"]},parser:{dataUrlCondition:$?()=>!0:{maxSize:4096}},generator:{filename:e=>e.filename?.toLocaleLowerCase().endsWith(".svg")?"assets/svg/[hash][ext]":"assets/images/[hash][ext]",dataUrl:(e,s)=>s.filename.toLocaleLowerCase().endsWith(".svg")?u(e.toString()):e},include:_},{test:n.video,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/video/[hash][ext]"},include:_},{test:n.font,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/fonts/[hash][ext]"},include:N}],B=h.prefixJsLoader.filter(Boolean)||[];"react"===j&&h.reactCompiler&&B.unshift({loader:s(t.corePath,"/loader/react-compiler.cjs"),options:{...h.reactCompiler,panicThreshold:x?void 0:"NONE"}}),h.cssInJs&&"object"==typeof h.cssInJs.minify&&B.unshift({loader:s(t.corePath,"/loader/css-in-js-minify.cjs"),options:Object.assign({moduleName:"@moneko/css",allowFuncs:["css","injectGlobal"]},h.cssInJs.minify)});export default(o=>{let r={react:{loader:l.swcLoader,options:m(o)},solid:{loader:s(t.corePath,"/loader/solid.cjs"),options:{jsxOptions:h.jsxDomExpressions,refresh:h.refresh}}}[j];return{generator:{"css/auto":{exportsOnly:!1,exportsConvention:"camel-case-only",localIdentName:"[uniqueName]_[id]_[local]",esModule:!0},"css/module":{exportsOnly:!1,exportsConvention:"camel-case-only",localIdentName:"[uniqueName]_[id]_[local]",esModule:!0}},parser:{javascript:{commonjsMagicComments:!0,dynamicImportMode:"lazy",dynamicImportPrefetch:!1,dynamicImportPreload:!1,importMeta:!0,importMetaContext:!0},css:{import:!0,namedExports:!0,url:!0},json:{exportsDepth:1}},noParse:h.noParse,rules:[{oneOf:[...k,{test:n.js,use:[...B,r].filter(Boolean),include:O,extractSourceMap:!0},...h.cssModules.map(e=>({test:s=>n.node_modules_css_module.test(s)&&s.includes(e),use:[v],type:"css/module"})),{test:n.css,use:[v],type:"css/auto",include:I},e&&{test:n.scss,use:[v,e],type:"css/auto",include:I},{test:n.less,use:[v,w],type:"css/auto",include:I},{test:n.markdown,use:[...B,{loader:s(t.corePath,"/loader/mdx.cjs"),options:h.mdx}].filter(Boolean),exclude:[n.node_modules,e=>e.startsWith(`${y}:`)||e.startsWith(`${g}:`)]}].filter(Boolean)},...h.moduleRules].filter(Boolean)}});
|
package/lib/options/reslove.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import o from"../commom/has-pkg.mjs";import e from"../commom/require.mjs";let r={sassLoader:o("sass-loader"),lessLoader:e.resolve("less-loader"),swcLoader:e.resolve("swc-loader"),transformImports:o("@moneko/transform-imports"),rawImport:o("@moneko/raw-import"),hotMiddlewareClient:e.resolve("webpack-hot-middleware/client.js")};export default r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let
|
|
1
|
+
import e from"../commom/rule.mjs";let n=function(){let e={priority:-10,reuseExistingChunk:!0};return function(n){return{...e,test:n}}}(),i={chunks:"all",minChunks:1,minSize:2e4,maxSize:25e4,enforceSizeThreshold:5e4,maxAsyncRequests:30,maxInitialRequests:30,minRemainingSize:0,hidePathInfo:!0,cacheGroups:{json:{type:"json"},CHANGELOG:n(/CHANGELOG\.md/),site:n(/site/),vendors:{test:e.node_modules,priority:-10,reuseExistingChunk:!0},"monaco-editor":{test:/[\\/]node_modules[\\/]monaco-editor/,name:"monaco-editor",chunks:"all"},common:{minChunks:2,priority:-20,reuseExistingChunk:!0}}};export default i;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{saveFileSync as
|
|
1
|
+
import{saveFileSync as s}from"@moneko/utils";import{toCamelCase as e}from"../utils/index.mjs";export class CssModuleDtsPlugin{apply(o){o.hooks.compilation.tap(this.name,o=>{o.hooks.succeedModule.tap(this.name,o=>{if(o.buildMeta?.isCSSModule){let t=o.dependencies.map(s=>"name"in s?`export const ${e(s.name)}: string;`:"").join("\n");s(`${o.resource}.d.ts`,t)}})})}constructor(){this.name="CssModuleDtsPlugin"}}
|
|
@@ -1 +1,14 @@
|
|
|
1
|
+
import { type Compiler, type experiments } from 'webpack';
|
|
2
|
+
import type ReactiveObject from '../commom/reactive-object.mjs';
|
|
3
|
+
type VirtualModule = ConstructorParameters<typeof experiments.schemes.VirtualUrlPlugin>[0];
|
|
4
|
+
export interface VirtualModules extends VirtualModule {
|
|
5
|
+
[key: string]: VirtualModules[keyof VirtualModules];
|
|
6
|
+
}
|
|
7
|
+
export declare class VirtualModulePlugin {
|
|
8
|
+
private vm;
|
|
9
|
+
private modules;
|
|
10
|
+
private schema;
|
|
11
|
+
constructor(modules: ReactiveObject<VirtualModules>, schema: string);
|
|
12
|
+
apply(compiler: Compiler): void;
|
|
13
|
+
}
|
|
1
14
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"webpack";let s=e.experiments.schemes.VirtualUrlPlugin;export class VirtualModulePlugin{constructor(e,t){this.modules=e,this.schema=t,this.vm=new s(this.modules.data,this.schema)}apply(e){this.vm.apply(e),this.modules.on("change",(e,s)=>{var t,i;this.vm.modules=Object.assign(this.vm.modules,(t={[e]:s},i=this.schema,Object.keys(t).reduce((e,s)=>{var o,r,m;return e[r=s,m=i,`${m}:${r}`]="string"==typeof(o=t[s])?{type:"",source:()=>o}:"function"==typeof o?{type:"",source:o}:o,e},{})))})}}
|
package/lib/plugins.config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"webpack";import{CompressionPlugin as t}from"./plugin/compression.mjs";import{CopyPlugin as
|
|
1
|
+
import e from"webpack";import{CompressionPlugin as t}from"./plugin/compression.mjs";import{CopyPlugin as o}from"./plugin/copy.mjs";import{CssModuleDtsPlugin as i}from"./plugin/css-module-dts.mjs";import{HtmlPlugin as r}from"./plugin/html-plugin.mjs";import{ManifestPlugin as p}from"./plugin/manifest/index.mjs";import n from"./plugin/module-federation.mjs";import{VirtualModulePlugin as s}from"./plugin/virtual-module.mjs";import{app_vm as l}from"./vm/app.mjs";import{docs_vm as m}from"./vm/docs.mjs";import{example_vm as a}from"./vm/example.mjs";import{scope_vm as c}from"./vm/scope.mjs";import{virtual_vm as h}from"./vm/virtual.mjs";import{CONFIG as f}from"./config.mjs";import{app_schema as u,docs_schema as g,example_schema as d,isLibrary as w,packageJson as j,scope_schema as v,virtual_schema as b}from"./process-env.mjs";let y="object"==typeof f.compression?f.compression:{},x=[...n,new s(l,u),w&&new s(m,g),w&&new s(a,d),w&&new s(c,v),f.virtualModule&&new s(h,b),new o(f.copy),new e.DefinePlugin({"process.env":JSON.stringify(f.env)}),new e.IgnorePlugin({resourceRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),new i,...f.plugins].filter(Boolean);if(f.compression&&x.push(new t({algorithm:f.devServer.https?"brotli":"gzip",test:/\.(js|css|html|svg|ttf|woff|woff2|png|jpg|jpeg)$/,...y})),f.manifest&&x.push(new p(f.manifest)),f.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:j.description,keywords:Array.isArray(j.keywords)?j.keywords.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};f.seo&&(e.relCanonical={rel:"canonical",href:`https://${f.seo.domain}${f.basename}`}),f.htmlPluginOption.meta&&Object.assign(e,f.htmlPluginOption.meta),x.push(new r({...f.htmlPluginOption,meta:e}))}if(f.fixBrowserRouter){let e=f.basename.split("/").filter(Boolean).length,t=`${Array(e).fill("..").join("/")+(e?"/":"")}404.html`,o=f.fixBrowserRouter.pathSegmentsToKeep??e;x.push(new r({filename:f.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>`}))}f.sourceMap&&x.push(new e.SourceMapDevToolPlugin(f.sourceMap));export default x;
|
package/lib/process-env.d.mts
CHANGED
|
@@ -9,6 +9,11 @@ export declare const isMobile: boolean;
|
|
|
9
9
|
export declare const isReact: boolean;
|
|
10
10
|
export declare const isSolid: boolean;
|
|
11
11
|
export declare const SSR: boolean;
|
|
12
|
+
export declare const app_schema = "app";
|
|
13
|
+
export declare const virtual_schema = "vm";
|
|
14
|
+
export declare const docs_schema = "docs";
|
|
15
|
+
export declare const example_schema = "example";
|
|
16
|
+
export declare const scope_schema = "scope";
|
|
12
17
|
/** 项目主要文件夹 */
|
|
13
18
|
export declare const mainDirectory: 'site' | 'src';
|
|
14
19
|
export declare const jsxImportSource: string;
|
package/lib/process-env.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"node:process";import
|
|
1
|
+
import o from"node:process";import e from"./commom/has-pkg.mjs";import r from"./commom/is-ci-environment.mjs";import s from"./commom/require.mjs";export const IS_WINDOW="win32"===o.platform;export const APPTYPE=o.env.APPTYPE;export const FRAMEWORK=o.env.FRAMEWORK;export const NODE_ENV=o.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"===o.env.SSR;export const app_schema="app";export const virtual_schema="vm";export const docs_schema="docs";export const example_schema="example";export const scope_schema="scope";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=framework?s(`${framework}/package.json`).version:19;export const frameworkVersion=parseFloat(frameworkVersionStr);export const packageJson=s(`${o.cwd()}/package.json`);delete packageJson.scripts;export const PACKAGENAME=packageJson.name;export const coreName="@moneko/core";export const isDev="development"===NODE_ENV;export const refresh=!!(isDev&&(e("solid-refresh")||e("react-refresh")));export const isCI=r();
|
package/lib/vm/app.d.mts
ADDED
package/lib/vm/app.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{join as e}from"node:path";import{getAppEntry as o,getAppFallback as r,getAppMergeRouter as t,getAppNormalizeCss as m,getAppPrefixRouter as s,getAppRem as n,getAppSuspense as a}from"@moneko/mdx";import{updateFileSync as p}from"@moneko/utils";import i,{routeDir as c}from"../commom/paths.mjs";import l from"../commom/reactive-object.mjs";import u from"../commom/require.mjs";import{CONFIG as d}from"../config.mjs";import{updateMocks as f}from"../dev/mock.mjs";import j from"../plugin/module-federation.mjs";import{app_schema as x,APPTYPE as y,FRAMEWORK as k}from"../process-env.mjs";import g from"../utils/create-types.mjs";import{generateDeclaration as h}from"../utils/dts.mjs";import{node_modules as v,transformModule as D}from"../utils/index.mjs";import $ from"./info.mjs";import{generateLocales as b}from"./locales.mjs";import C from"./render-app.mjs";import{getRouter as z}from"./routes.mjs";let P=new l({});P.on("change",()=>{p(v(`@types/$${x}/index.d.ts`),Object.values(P.data).join("\n"))});export const app_vm=new l({mock:{source:e=>(e.addContextDependency(i.mockPath),f(),"export default null;")},env:{source:()=>{let e=`${x}:env`,o=D(d.env);return P.setData(e,g(e,h(o,e))),o}},info:{source:o=>{let r=`${x}:info`,t=e(i.programPath,"package.json");o.addDependency(t),delete u.cache[t];let m=D({...u(t),...$});return P.setData(r,g(r,h(m,r))),m}},render:{type:".tsx",source:()=>"react"===k?C:""},entry:{type:".tsx",source:()=>{let r=`${x}:entry`,t=o(e(d.alias["@"],"./index.ts"),!!j.length,!!d.rem,!!d.normalizeCss,y,k);return P.setData(r,g(r,h(t,r))),t}},fallback:{source:()=>{let e=`${x}:fallback`,o=r(d.fallbackCompPath);return P.setData(e,g(e,h(o,e))),o}},"merge-router":t(),"prefix-router":s(),suspense:{type:".tsx",source:()=>a(y,k)},routes:{source:e=>(e.addContextDependency(c),z())},locals:{source:o=>{let r=e(d.alias["@"],"./locales");return o.addContextDependency(r),b()}},normalize:{type:".css",source:m},rem:n(d.rem?.designSize||1680)});
|
package/lib/vm/docs.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import ReactiveObject from '../commom/reactive-object.mjs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}>;
|
|
5
|
-
export declare const comment: ReactiveObject<Record<string, string>>;
|
|
2
|
+
import type { VirtualModules } from '../plugin/virtual-module.mjs';
|
|
3
|
+
export declare const docs_vm: ReactiveObject<VirtualModules>;
|
|
6
4
|
export declare const getCommentPath: (file: string) => string;
|
|
5
|
+
export declare const getDocs: (comments: string[]) => string;
|
package/lib/vm/docs.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{sep as
|
|
1
|
+
import{join as e,sep as t}from"node:path";import{loadFile as o,scanFolderSync as r}from"@moneko/utils";import m from"../commom/paths.mjs";import n from"../commom/reactive-object.mjs";import c from"../commom/rule.mjs";import{CONFIG as s}from"../config.mjs";import{app_schema as a,docs_schema as p,FRAMEWORK as l,framework as i,isLibrary as d,isReact as u,isSolid as f}from"../process-env.mjs";import $ from"./coverage.mjs";import{generatorExample as g}from"./example.mjs";import h from"./generate-doc.mjs";let x={react:"createElement",solid:"createComponent"}[l],j=()=>d?r(s.alias["@pkg"],["\\.tsx?$"]).filter(e=>!/(^|\/)\.[^\\/\\.]|\.test\./i.test(e)).map(e=>{let t=getCommentPath(e),r=t.replace(`${p}:`,"");return docs_vm.has(r)||docs_vm.setData(r,{type:".txt",source:async t=>{let r=await o(e);return t.addDependency(e),h(r,e)}}),t}):[];export const docs_vm=new n({coverage:{source:e=>(e.addDependency(m.coveragePath),$(m.coveragePath))},docs:{source:async e=>{e.addContextDependency(m.componentsPath);let t=j();return getDocs(t)}},example:{source:e=>(e.addContextDependency(m.componentsPath),g())}});export const getCommentPath=function(){let t=s.alias["@pkg"]?.length;return o=>e(`${p}:comment`,o.substring(t)).replace(/\\/g,"/")}();export const getDocs=e=>{let o=`import { ${x}${f?",Dynamic":""} } from "${i}${f?"/web":""}";import SuspenseComp from "${a}:suspense";function call_then(res) {return {default: ${u?"() =>":""}${x}(${f?"Dynamic":"'div'"}, {${f?"innerHTML: res.default, component: 'div', class: 'n-md-box' ":"dangerouslySetInnerHTML: {__html:res.default}, className: 'n-md-box'"} })};}`,r={};e.forEach(e=>{let o=e.replace(/docs:comment[/\\]/,"").split(t),m=o.pop(),n=o.join("/");r[n]||(r[n]={}),r[n][m]=`rr(() => ${x}(SuspenseComp, { comp: () => import(/* webpackChunkName: '${e}' */ '${e}').then(call_then)}))rr`});let m={};for(let e in r)Object.hasOwn(r,e)&&(m[e]=Object.values(r[e]));return`${o}export default ${JSON.stringify(m).replace(c.extract_func,"$1")}`};j();
|
package/lib/vm/example.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import ReactiveObject from '../commom/reactive-object.mjs';
|
|
2
|
-
|
|
3
|
-
export declare
|
|
2
|
+
import type { VirtualModules } from '../plugin/virtual-module.mjs';
|
|
3
|
+
export declare const example_vm: ReactiveObject<VirtualModules>;
|
|
4
|
+
export declare function generatorExample(): string;
|
package/lib/vm/example.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{generateExample as e}from"@moneko/mdx";import
|
|
1
|
+
import{generateExample as e}from"@moneko/mdx";import o from"../commom/paths.mjs";import r from"../commom/reactive-object.mjs";import t from"../commom/rule.mjs";import{CONFIG as m}from"../config.mjs";import{example_schema as n,isLibrary as p}from"../process-env.mjs";export const example_vm=new r({});export function generatorExample(){if(!p)return"export default {}";let r=p&&!1!==m.htmlPluginOption?JSON.parse(e(o.componentsPath,`${n}:`,"6")):{},a={};for(let e in r)Object.hasOwn(r,e)&&(example_vm.setData(e.replace(`${n}:`,""),{source:t=>(t.addContextDependency(o.componentsPath),r[e])}),Object.assign(a,{[e]:`rr(() => import('${e}'))rr`}));return`export default ${JSON.stringify(a).replace(t.extract_func,"$1")}`}generatorExample();
|
package/lib/vm/generate-doc.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dirname as e}from"node:path";import t from"typescript";import{CONFIG as n}from"../config.mjs";import r from"../options/md-to-html.mjs";let
|
|
1
|
+
import{dirname as e}from"node:path";import t from"typescript";import{CONFIG as n}from"../config.mjs";import r from"../options/md-to-html.mjs";import{md5 as l}from"../utils/index.mjs";let o=t.ScriptKind,i=t.ScriptTarget,a=t.SyntaxKind,c=t.createSourceFile,s=t.forEachChild,u=t.getLeadingCommentRanges,f=t.isInterfaceDeclaration,m=t.isQuestionToken,p=t.isPropertySignature,g=t.isFunctionTypeNode,$=t.isUnionTypeNode,d=t.isMethodSignature,h={};function b(e){let t=u(e.getSourceFile().text,e.pos);if(t){let n=e.getSourceFile().text.slice(t[0].pos,t[0].end).match(/\/\*\*([\s\S]*?)\*\//);if(n)return n[1].replaceAll(/^\s*\* ?/gm,"").replace(/\s+$/,"").trim()}}function y(e){if(!e)return;let t=e.match(/@since\s+([^\n]+)/);return t?t[1].trim():void 0}function x(e){if(!e)return;let t=e.match(/@author (\w+)\s*(?:<([^>]+)>)?/);if(t&&t.length>0){let e=t[1].trim(),n=t[2]?.trim(),r=/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(n);return n?r&&(n=`mailto:${n}`):n=`https://github.com/${e}`,`[${e}](${n})`}}function j(e){if(!e)return;let t=e.match(/@ignore\s+([^\n]+)/);return t?t[1].trim():void 0}let A=/(?<!['"])(unknown|any|void|bigint|object|undefined|null|boolean|number|string|symbol)(?!['"])/g;function S(e,t){if(!e)return;let r=e.replaceAll(/\b([A-Z][a-zA-Z0-9]*)\b/g,e=>{if(h[e]){let r=`/${[n.basename,h[e]].join("/").split("/").filter(Boolean).join("/")}`;return t?`[\\color{#009688}{${e}}](${r})`:`[${e}](${r})`}return t?`\\color{#009688}{${e}}`:e});return t&&(r=r.replaceAll(A,e=>`\\color{#009688}{${e}}`)),r}function T(e){if(e)return(function(e){let t;if(!e)return;let n=[];for(;t=/\\color{([^|}]*)\|?([^|}]*)\|?([^|}]*)\|?([^}]*)}{([^}]*)}/g.exec(e);)n.push(t[0]);return e.replaceAll(/[{}[\]()=>]|keyof|typeof|true|false/g,e=>n.some(t=>t.includes(e))?e:`\\color{#569cd6}{${e}}`)})(e)?.replaceAll(/^\s*\|\s*|\s*\|\s*$/gm,"").replaceAll(/\n/g,"<br/>").replaceAll(/\*/g,"\\*").replaceAll(/\|/g,"\\|").replaceAll(/(['"])((?:(?!\1).)*)\1/g,"\\color{#ce9178}{$1$2$1}")}function k(e){if(e)return e.replaceAll(/@example\s*([\s\S]*?)(?=@[a-zA-Z]|\n*$)/g,"").replaceAll(/^@[a-z].+/gm,"").replaceAll(/(\n\s+)+/g,"<br />").replaceAll(/\n/g,"<br />").replaceAll(/(<br \/>)$/g,"")}let v=new WeakMap;export default function w(u,A){let w=[l(u)],B=v.get(w);if(B)return B;let z=c(A,u,i.Latest,!0,o.TS),F="";s(z,r=>{f(r)?F+=function(r){let l=r.name.text;Object.assign(h,{[r.name.text]:e(r.getSourceFile().fileName).replace(n.alias["@pkg"],"")});let o=b(r),i=y(o),c=k(o),s=j(o)?.split("|")||[],u=s.includes("comment"),f=s.includes("initial"),A=s.includes("optional"),v=s.includes("version"),w=s.includes("author"),B=c?`\\color{|4||0.45}{${l}}`:l,z=(function(e){let n=[];if(e.heritageClauses){for(let r of e.heritageClauses)if(r.token===t.SyntaxKind.ExtendsKeyword)for(let e of r.types)n.push(e.getText())}return n})(r)?.map(e=>`<n-tag color="#4c81db" css=".tag{gap:0px;}">${S(T(e))}</n-tag>`),F=[c,B,i&&`\\color{#52c11b|1||0.9}{${i}}`,z.length>0&&`<sub>\`extends\`</sub> ${z.join(" ")}`].filter(Boolean).join(" "),N=`## ${F}`,K=r.members.filter(e=>p(e)&&e.type?.kind!==a.NeverKeyword||d(e)),C=[];if(K.length>0){for(let e=0,t=K.length;e<t;e++){let t=K[e],n=S(T(d(t)?`(${t.parameters.map(e=>`${e.name.getText()}: ${e.type?.getText()||"any"}`).join(", ")}): ${t.type?.getText()||"any"}`:t.type?.getText()||"any"),!0),r=b(t),l=T(t.name.getText());l&&!l.startsWith("\\color")&&(d(t)||function(e){if(e.type){if(!$(e.type))return g(e.type);else for(let t of e.type.types)if(g(t))return!0}return!1}(t)||n?.includes("=>")?l=`\\color{#f9a913}{${l}}`:/^["'](.+)["']$/.test(l)||(l=`\\color{#4c81db}{${l}}`));let i=t.questionToken&&m(t.questionToken);C.push([l,!A&&`\\color{${i?"#f9a913":"#52c11b"}\\|\\|\\|0.9}{${i?"✘":"✔"}}`,!u&&T(k(r)),n,!f&&T(function(e){if(!e)return;let t=e.match(/@default\s+([^\n]+)/);return t?t[1].trim():void 0}(r)),!v&&T(y(r)),!w&&(x(r)||x(o)),function(e){if(!e)return;let t=e.match(/@example\s*([\s\S]*?)(?=@[a-zA-Z]|\n*$)/);return t?t[1].trim():void 0}(r)])}let e=!1,t=!1,n=!1,r=!1;for(let l=0,o=C.length;l<o;l++){let o=C[l];!u&&o[2]&&(r=!0),!f&&o[4]&&(n=!0),!v&&o[5]&&(t=!0),!w&&o[6]&&(e=!0)}N+="\n";let l=["属性",!A&&"必要",r&&"说明","类型",n&&"默认值",t&&"版本",e&&"作者"].filter(Boolean).join("|");N+=`|${l}|`;let i=[":-",!A&&":-",r&&":-",":-",n&&":-",t&&":-",e&&":-"].filter(Boolean);N+="\n";let a=i.join("|");N+=`|${a}|`;for(let l=0,o=C.length;l<o;l++){let o=C[l];N+="\n";let i=[(o[7]?`<n-popover arrow="true" trigger="click" content=${JSON.stringify(`<n-md css=.n-md-body{margin-bottom:0;padding:0.5rem;background-color:transparent;backdrop-filter:none;box-shadow:none;}>${o[7]}</n-md>`)}><n-button size="small" type="primary" circle="true" style="margin-right:8px;">?</n-button></n-popover>`:"")+(o[0]||"-"),!A&&(o[1]||"-"),r&&(o[2]||"-"),o[3]||"-",n&&(o[4]||"-"),t&&(o[5]||"-"),e&&(o[6]||"-")].filter(Boolean).join("|");N+=`|${i}|`}N+="\n"}return N+"\n"}(r):t.isEnumDeclaration(r)&&(F+=function(r){let l=r.name.text,o=b(r),i=k(o),a=y(o);Object.assign(h,{[r.name.text]:e(r.getSourceFile().fileName).replace(n.alias["@pkg"],"")});let c=i?`\\color{|4||0.45}{${l}}`:l,s=[i,c,a&&`\\color{#52c11b|1||0.9}{${a}}`].filter(Boolean).join(" "),u=j(o)?.split("|")||[],f=u.includes("comment"),m=u.includes("version"),p=u.includes("author"),g=`## ${s}`;if(r.members.length>0){let e=[];for(let n=0,l=r.members.length;n<l;n++){let l=r.members[n],i=T(l.name.getText()),a=b(l),c=T(function(e){let n=e.initializer;if(n&&t.isStringLiteral(n))return` '${n.text}'`}(l)),s=T(y(a)),u=T(k(a));!i||i.startsWith("\\color")||/^["'](.+)["']$/.test(i)||(i=`\\color{#4c81db}{${i}}`),e.push([i,!f&&u,c,!m&&s,!p&&(x(a)||x(o))])}let n=!1,l=!1,i=!1;for(let t=0,r=e.length;t<r;t++){let r=e[t];!f&&r[1]&&(i=!0),!m&&r[3]&&(l=!0),!p&&r[4]&&(n=!0)}g+="\n";let a=["属性",i&&"说明","值",l&&"版本",n&&"作者"].filter(Boolean).join("|");g+=`|${a}|`;let c=[":-",i&&":-",":-",l&&":-",n&&":-"].filter(Boolean);g+="\n";let s=c.join("|");g+=`|${s}|`;for(let t=0,r=e.length;t<r;t++){let r=e[t];g+="\n";let o=[r[0]||"-",i&&(r[1]||"-"),r[2]||"-",l&&(r[3]||"-"),n&&(r[4]||"-")].filter(Boolean).join("|");g+=`|${o}|`}}return g+"\n\n"}(r))});let N=r(F);return v.set(w,N),N}
|
package/lib/vm/info.d.mts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
declare const app:
|
|
1
|
+
declare const app: {
|
|
2
|
+
projectName: string;
|
|
3
|
+
ssr: boolean;
|
|
4
|
+
base: string;
|
|
5
|
+
type: import("../index.mjs").AppType;
|
|
6
|
+
routerMode: "browser" | "hash" | "memory";
|
|
7
|
+
prefixCls: string | undefined;
|
|
8
|
+
theme: import("../index.mjs").Theme | undefined;
|
|
9
|
+
frameworkVersion: string;
|
|
10
|
+
framework: "react" | "solid-js";
|
|
11
|
+
};
|
|
2
12
|
export default app;
|
package/lib/vm/locales.d.mts
CHANGED
package/lib/vm/locales.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{basename as e,join as t}from"node:path";import{directoryExists as a,scanFolderSync as o}from"@moneko/utils";import
|
|
2
|
-
export function template(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);${
|
|
1
|
+
import{basename as e,join as t}from"node:path";import{directoryExists as a,scanFolderSync as o}from"@moneko/utils";import l from"../commom/log.mjs";import r from"../commom/require.mjs";import{CONFIG as n}from"../config.mjs";import{FRAMEWORK as c}from"../process-env.mjs";export function generateLocales(){let s=t(n.alias["@"],"./locales"),g={react:'import sso from "shared-store-object";',solid:'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'},i={react:'let storageKey="localizable.language",language=localStorage.getItem(storageKey)||navigator.language,{translation:a,...defaultLocale}=Object.assign({title:"简体中文",language:navigator.language,translation:{}},resources[language]||resources[navigator.language]),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)||navigator.language,{translation:l,...o}=Object.assign({title:"简体中文",language:navigator.language,translation:{}},resources[a]||resources[navigator.language]),[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;'}[c];function u(e,t){return`${g[c]}
|
|
2
|
+
export function template(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);${i}`}if(a(s)&&!1!==n.htmlPluginOption){let t={};o(s,[".ts$"]).filter(e=>!/^\..*|\.d\.ts$/.test(e)).forEach(a=>{let o=e(a).replace(/\.[^.]+$/,"");try{delete r.cache[a],Object.assign(t,{[o]:r(a).default})}catch(e){Object.assign(t,{[o]:{}}),l(e)}});let a=[],n={};for(let e in t){if(!Object.hasOwn(t,e))continue;let{language:o=e,title:l=o,icon:r,translation:c={}}=t[e];a.push({language:o,title:l,icon:r}),n[o]={language:o,title:l,icon:r,translation:c}}return u(a,n)}return u([],{})}
|
package/lib/vm/render-app.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const code: string;
|
|
2
|
+
export default code;
|
package/lib/vm/render-app.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{CONFIG as e}from"../config.mjs";import{
|
|
2
|
-
import ReactDOM from '${
|
|
1
|
+
import{CONFIG as e}from"../config.mjs";import{app_schema as r,APPTYPE as t,frameworkVersion as o,isDev as n}from"../process-env.mjs";let a=o<18,c="hash"===e.routerMode,s=c?"HashRouter":"BrowserRouter",m=e.strict?"StrictMode":"",p=`<${m}><${s} basename={${c?'"/"':"basename"}} window={window}><ErrorBoundary><App /></ErrorBoundary></${s}></${m}>`,i=n&&e.refresh&&e.env.injectRemoteReactRefresh?"window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject(ReactDOM);":"",u=`
|
|
2
|
+
import ReactDOM from '${a?"react-dom":"react-dom/client"}';
|
|
3
3
|
import React, { StrictMode, type ReactElement } from 'react';
|
|
4
4
|
import { ErrorBoundary } from '@moneko/react';
|
|
5
|
-
import routes from '
|
|
6
|
-
import { ${
|
|
5
|
+
import routes from '${r}:routes';
|
|
6
|
+
import { ${s}, useRoutes } from 'react-router-dom';
|
|
7
7
|
|
|
8
|
-
${
|
|
8
|
+
${i}
|
|
9
9
|
type RenderAppProps = {
|
|
10
10
|
container?: HTMLElement;
|
|
11
11
|
basename?: string;
|
|
@@ -23,8 +23,8 @@ export function App(props: RenderAppProps) {
|
|
|
23
23
|
function renderApp(props: RenderAppProps = {}) {
|
|
24
24
|
const { container, basename = "${e.basename}", language, ...args } = props;
|
|
25
25
|
const _container = container?.querySelector('#root') || document.getElementById('root');
|
|
26
|
-
${"micro"===
|
|
27
|
-
${
|
|
26
|
+
${"micro"===t?"window.mainApp = { ...args, container: _container as HTMLElement };":""}
|
|
27
|
+
${a?`ReactDOM.${n?"render":"hydrate"}(${p}, _container);return () => ReactDOM.unmountComponentAtNode(_container as Element);`:`const instance = ReactDOM.createRoot(_container as HTMLElement);instance.render(${p});return instance.unmount;`}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export default renderApp;`;export default
|
|
30
|
+
export default renderApp;`;export default u;
|
package/lib/vm/routes.d.mts
CHANGED
package/lib/vm/routes.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{generateRouter as o}from"@moneko/mdx";import{routeDir as
|
|
1
|
+
import{generateRouter as o}from"@moneko/mdx";import{routeDir as m}from"../commom/paths.mjs";import{CONFIG as r}from"../config.mjs";import{FRAMEWORK as t,isLibrary as e}from"../process-env.mjs";let i=e?"@pkg":"@/pages";export function getRouter(){return!1===r.htmlPluginOption?"":o(m,`${r.alias["@"]}/router/index.ts`,t,i,e,"6")}
|
package/lib/vm/scope.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{join as o}from"node:path";import{getAppScope as m}from"@moneko/mdx";import e from"../commom/has-pkg.mjs";import t from"../commom/reactive-object.mjs";import{CONFIG as r}from"../config.mjs";export const scope_vm=new t({components:{source:()=>{let t=!1,s=o(r.alias["@"],"./scope.tsx"),p=o(r.alias["@"],"./scope.ts");return e(s)?t=s:e(p)&&(t=p),t?m(t,"@/scope"):"export defatlu {}"}}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{updateFileSync as t}from"@moneko/utils";import m from"../commom/reactive-object.mjs";import{CONFIG as o}from"../config.mjs";import{virtual_schema as r}from"../process-env.mjs";import e from"../utils/create-types.mjs";import{generateDeclaration as i}from"../utils/dts.mjs";import{node_modules as s,transformModule as l}from"../utils/index.mjs";export const virtual_vm=new m({});o.virtualModule&&t(s(`@types/$${r}/index.d.ts`),Object.keys(o.virtualModule).map(t=>{let m=l(o.virtualModule[t]);virtual_vm.setData(t,m);let s=`${r}:${t}`;return e(s,i(m,s))}).join("\n"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "4.0.0-bate.
|
|
3
|
+
"version": "4.0.0-bate.3",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
"dependencies": {
|
|
131
131
|
"@moneko/convert": "1.1.3",
|
|
132
132
|
"@moneko/eslint": "1.9.14",
|
|
133
|
-
"@moneko/mdx": "1.0.
|
|
133
|
+
"@moneko/mdx": "1.0.2",
|
|
134
134
|
"@moneko/raw-import": "1.1.1",
|
|
135
135
|
"@moneko/request": "1.6.2",
|
|
136
136
|
"@moneko/stylelint": "1.6.0",
|
|
@@ -138,7 +138,6 @@
|
|
|
138
138
|
"@moneko/utils": "0.3.3",
|
|
139
139
|
"@swc/core": "1.13.5",
|
|
140
140
|
"browserslist": "4.27.0",
|
|
141
|
-
"chokidar": "4.0.3",
|
|
142
141
|
"core-js": "3.46.0",
|
|
143
142
|
"core-js-compat": "3.46.0",
|
|
144
143
|
"husky": "9.1.7",
|
package/typings/global.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
WebpackPluginInstance,
|
|
14
14
|
SourceMapDevToolPlugin,
|
|
15
15
|
RuleSetConditionAbsolute,
|
|
16
|
+
experiments,
|
|
16
17
|
} from 'webpack';
|
|
17
18
|
|
|
18
19
|
import type { CopyPluginOption } from '../lib/plugin/copy.mjs';
|
|
@@ -31,6 +32,7 @@ import type { ProxyConfig } from '../lib/dev/proxy.mjs';
|
|
|
31
32
|
import type { OverrideResolverOption } from '../lib/plugin/override-resolve.mjs';
|
|
32
33
|
import type { OptimizationSplitChunksOptions } from '../lib/options/split-chunk.mjs';
|
|
33
34
|
import type { HtmlPluginOption } from '../lib/plugin/html-plugin.mjs';
|
|
35
|
+
|
|
34
36
|
export interface VirtualModulePluginOption {
|
|
35
37
|
[key: string]: string | object;
|
|
36
38
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/loader/ts-doc.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e;Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return i}});const t=require("fs"),r=(e=require("../commom/log.mjs"))&&e.__esModule?e:{default:e},s={};function i(e){let i=this.resourcePath;if(i.endsWith(".d.ts"))return e;this.cacheable&&this.cacheable();try{let r=(0,t.statSync)(i).mtime.getTime();if(s[i]!==r){Object.assign(s,{[i]:r});let{comment:t,generateDoc:a,getCommentPath:c}=this.getOptions();t.setData(c(i),a(e,i))}}catch(e){(0,r.default)(e)}return e}
|
package/lib/loader/ts-doc.d.cts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { LoaderContext } from 'webpack';
|
|
2
|
-
import type ReactiveObject from '../commom/reactive-object.mjs';
|
|
3
|
-
export default function (this: LoaderContext<{
|
|
4
|
-
comment: ReactiveObject<Record<string, string>>;
|
|
5
|
-
generateDoc(content: string, path: string): string;
|
|
6
|
-
getCommentPath(filepath: string): string;
|
|
7
|
-
}>, value: string): string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/vm/modules.d.mts
DELETED
package/lib/vm/modules.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{join as e}from"node:path";import{getAppEntry as t,getAppFallback as o,getAppMdxScope as r,getAppMergeRouter as m,getAppNormalizeCss as s,getAppPrefixRouter as a,getAppRem as p,getAppSuspense as c}from"@moneko/mdx";import{updateFileSync as l}from"@moneko/utils";import i from"../commom/has-pkg.mjs";import n from"../commom/paths.mjs";import u from"../commom/reactive-object.mjs";import f from"../commom/require.mjs";import{CONFIG as d}from"../config.mjs";import v from"../plugin/module-federation.mjs";import{APPTYPE as j,FRAMEWORK as x,isLibrary as g}from"../process-env.mjs";import y from"../utils/create-types.mjs";import{generateDeclaration as D}from"../utils/dts.mjs";import{node_modules as h,transformModule as k}from"../utils/index.mjs";import b from"./coverage.mjs";import{comment as M,docs as P}from"./docs.mjs";import{examples as z}from"./example.mjs";import C from"./info.mjs";import{locales as O}from"./locales.mjs";import w from"./render-app.mjs";import{route as V}from"./routes.mjs";let $=i(e(d.alias["@"],"./mdx-scope.tsx"))||i(e(d.alias["@"],"./mdx-scope.ts")),q=new u({});q.on("change",()=>{l(h("@types/$vm/index.d.ts"),Object.values(q.data).join("\n"))});export const vm={env:{source:()=>{let e="app:env",t=k(d.env);return q.setData(e,y(e,D(t,e))),t}},info:{source:t=>{let o="app:info",r=e(n.programPath,"package.json");t.addDependency(r),delete f.cache[r];let m=k({...f(r),...C});return q.setData(o,y(o,D(m,o))),m}},render:{type:".tsx",source:()=>"react"===x?w:""},entry:{type:".tsx",source:()=>{let o="app:entry",r=t(e(d.alias["@"],"./index.ts"),!!v.length,!!d.rem,!!d.normalizeCss,j,x);return q.setData(o,y(o,D(r,o))),r}},fallback:{source:()=>{let e="app:fallback",t=o(d.fallbackCompPath);return q.setData(e,y(e,D(t,e))),t}},"merge-router":m(),"prefix-router":a(),suspense:{type:".tsx",source:()=>c(j,x)},routes:{type:".ts",source:e=>(e.addContextDependency(n.pagesPath),V.getData("app:routes"))},locals:{type:".ts",source:()=>O.getData("app:locales")}};if(d.normalizeCss&&(vm.normalize={type:".css",source:s}),d.rem&&(vm.rem=p(d.rem?.designSize||1680)),g){for(let e of(vm.coverage={source:e=>(e.addDependency(n.coveragePath),b(n.coveragePath))},vm["mdx-scope"]={type:".ts",source:()=>{let e="app:mdx-scope",t=$?r($):"export default {}";return q.setData(e,y(e,D(t,e))),t}},vm.docs={source:()=>P.getData("app:docs")},z))vm[e[0].replace("app:","")]={type:".tsx",source:()=>z.getData(e[0])};for(let e of P)vm[e[0].replace("app:","")]={type:".tsx",source:()=>P.getData(e[0])};for(let e of M)vm[e[0].replace("app:","")]={type:".txt",source:()=>M.getData(e[0])}}export const customVirtualModules={};for(let e in d.virtualModule){if(!Object.hasOwn(d.virtualModule,e))continue;let t=k(d.virtualModule[e]);customVirtualModules[e]=t;let o=`vm:${e}`;q.setData(o,y(o,D(t,o)))}
|
package/lib/vm/utils.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function watchFiles(root: string, ignored?: RegExp, call?: VoidFunction): void;
|
package/lib/vm/utils.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{watch as i}from"chokidar";import o from"../commom/sigint-exit.mjs";import{empty as t}from"../utils/index.mjs";export function watchFiles(n,r,e=t){let m=i(n,{ignored:(i,o)=>{if(o)return!o.isDirectory()&&r?.test(i)},persistent:!0,ignoreInitial:!0});m.on("add",e).on("change",e).on("unlink",e),o(function(){m.unwatch(n),m.close()})}
|