@moneko/core 3.2.1 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/app.js CHANGED
@@ -1,2 +1 @@
1
- import{readFileSync as e}from"fs";import{CONFIG as r}from"./config.js";import{APPTYPE as o,PACKAGENAME as p,PACKAGEVERSION as s}from"./process-env.js";import{resolveProgramPath as t,toUpperCaseString as a}from"./utils.js";let n={name:p,projectName:JSON.stringify(a(p).replace(/-/g," ")),version:s,base:r.basename,type:o,routerMode:r.routerMode,prefixCls:r.prefixCls,theme:r.theme,description:process.env.npm_package_description,author:{name:process.env.npm_package_author_name,email:process.env.npm_package_author_email,url:process.env.npm_package_author_url},repository:{type:process.env.npm_package_repository_type,url:process.env.npm_package_repository_url,directory:process.env.npm_package_repository_directory}};// node 16
2
- if(parseInt(process.versions.node)>14){let r=e(t("package.json"),{encoding:"utf-8"}),{description:o,author:p,repository:s}=JSON.parse(r);n.author="string"==typeof p?{name:p}:p,n.repository="string"==typeof p?{url:s}:s,n.description=o}export default n;
1
+ import{readFileSync as e}from"fs";import{CONFIG as r}from"./config.js";import{APPTYPE as o,PACKAGENAME as p,PACKAGEVERSION as s}from"./process-env.js";import{resolveProgramPath as t,toUpperCaseString as a}from"./utils.js";let n={name:p,projectName:JSON.stringify(a(p).replace(/-/g," ")),version:s,base:r.basename,type:o,routerMode:r.routerMode,prefixCls:r.prefixCls,theme:r.theme,description:process.env.npm_package_description,author:{name:process.env.npm_package_author_name,email:process.env.npm_package_author_email,url:process.env.npm_package_author_url},repository:{type:process.env.npm_package_repository_type,url:process.env.npm_package_repository_url,directory:process.env.npm_package_repository_directory}};if(parseInt(process.versions.node)>14){let r=e(t("package.json"),{encoding:"utf-8"}),{description:o,author:p,repository:s}=JSON.parse(r);n.author="string"==typeof p?{name:p}:p,n.repository="string"==typeof p?{url:s}:s,n.description=o}export default n;
package/lib/cleanup.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export declare function cleanDir(folderPath: string): void;
package/lib/cleanup.js CHANGED
@@ -1 +1 @@
1
- import{existsSync as o,readdirSync as t,rmdirSync as r,statSync as i,unlinkSync as c}from"fs";import{join as f}from"path";import m from"./paths.js";process.on("exit",function(){!function m(p){o(p)&&(t(p).forEach(o=>{let t=f(p,o);i(t).isDirectory()?m(t):c(t)}),r(p))}(m.cachePath)});
1
+ import{existsSync as r,readdirSync as o,rmdirSync as i,statSync as t,unlinkSync as c}from"fs";import{join as e}from"path";export function cleanDir(f){r(f)&&(o(f).forEach(r=>{let o=e(f,r);t(o).isDirectory()?cleanDir(o):c(o)}),i(f))}
package/lib/common.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import './cleanup.js';
2
1
  import type { WebpackConfiguration } from 'webpack-dev-server';
3
2
  export declare const outputConfig: WebpackConfiguration['output'];
4
3
  export declare const clientConfig: WebpackConfiguration;
package/lib/common.js CHANGED
@@ -1 +1 @@
1
- import e from"fs";import t from"add-asset-html-webpack-plugin";import s from"html-webpack-plugin";import l from"webpack";import o from"webpackbar";import"./cleanup.js";import{CONFIG as n,PUBLICPATH as r}from"./config.js";import i from"./done.js";import a from"./html-add-entry-attr.js";import p from"./html-plugin-option.js";import{moduleFederation as c}from"./module-federation.js";import m from"./module.config.js";import u from"./paths.js";import{CUSTOMCONFIG as f,PACKAGENAME as d,PACKAGEVERSION as h,hasEslintConfig as j,hasStylelintConfig as y,isDev as b,isLibrary as g,isMicro as w}from"./process-env.js";import{seo as x}from"./seo.js";import{resolveNodeModulesPath as k,resolveProgramPath as v}from"./utils.js";import C from"./virtual-module-plugin.js";import $ from"./virtual-modules.js";let{AutomaticPrefetchPlugin:O,DefinePlugin:P,SourceMapDevToolPlugin:M,WatchIgnorePlugin:B}=l,D=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],A=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],H=e.readdirSync(u.programPath),K=!1,L=!1;for(let e=0,t=H.length;e<t;e++)A.includes(H[e])&&(L=!0),D.includes(H[e])&&(K=!0);K||(K=j),L||(L=y);let F=L?(await import("stylelint-webpack-plugin")).default:null,J=K?(await import("eslint-webpack-plugin")).default:null,R=n.assetHtml.map(e=>({publicPath:"",...e}));export const outputConfig={path:v(g?"docs":"dist"),filename:"js/[name].bundle.js",chunkFilename:`js/[${b?"name":"chunkhash"}].js`,assetModuleFilename:e=>{let t=e.filename;return t&&t.endsWith("?url")&&/(?:webworker|worker)(\.|\b).*\.(js|ts)\b/.test(t.replace("?url",""))?"worker/[name][ext]":"assets/[name][hash][ext]"},library:{name:d,type:"window"},globalObject:"window",chunkLoadingGlobal:`webpackJsonp_${d}`,pathinfo:b,clean:!0,publicPath:r,asyncChunks:!0,charset:!0};let S={main:k("@app/entry")};n.polyfill&&Object.assign(S,{"dom-polyfills":[`${u.corePath}/polyfills/replace-children.js`]}),n.entry&&("string"==typeof n.entry?S={main:n.entry}:Object.keys(n.entry)&&Object.assign(S,n.entry)),n.output&&("string"==typeof n.output?outputConfig.path=n.output:Object.keys(n.output)&&Object.assign(outputConfig,n.output));let U=n.basename.split("/").filter(Boolean).length,W=`${Array(U).fill("..").join("/")+(U?"/":"")}404.html`,{pathSegmentsToKeep:_=U,path:z=W}=n.fixBrowserRouter||{},G=!1;n.cacheDirectory&&(G={type:"filesystem",store:"pack",allowCollectingMemory:!0,cacheDirectory:n.cacheDirectory,memoryCacheUnaffected:!0,name:`${f||"default"}-${b?"development":"production"}`,version:h});export const clientConfig={entry:S,stats:"errors-only",cache:G,infrastructureLogging:{level:"none"},target:"web",externalsPresets:n.externalsPresets,plugins:[new O,...c,J&&new J({fix:!0,threads:!0,extensions:["js","md","mdx","cjs","ejs","mjs","jsx","ts","tsx","json","html","coffee","vue"]}),F&&new F({fix:!0,threads:!0,extensions:["css","scss","sass","less","ts","tsx","js","jsx"],exclude:["node_modules/","es/","lib/","docs/","coverage/","dist/"]}),n.htmlPluginOption&&new s(p),n.fixBrowserRouter&&new s({filename:z,inject:!1,templateContent:()=>`<html lang="en"><head><title>${p.title}</title><script>const pathKeep = ${_||U};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>`}),new t(R),w&&new a(e=>!!(e.match(/main\.(.*)\.bundle.js$/)||e.match("main.bundle.js"))),new P({"process.env":JSON.stringify(n.env)}),new B({paths:[/\.d\.ts$/]}),n.sourceMap&&new M(n.sourceMap),n.bar&&new o(n.bar),new i({done:()=>{!b&&n.seo&&x(),n.done?.(),b||setTimeout(()=>{process.exit(0)},2e3)}}),new C($),...n.plugins].filter(Boolean),experiments:{topLevelAwait:!0,asyncWebAssembly:!0,cacheUnaffected:!0,layers:!0,lazyCompilation:b&&{imports:!1,entries:!1},buildHttp:n.buildHttp,backCompat:!0,futureDefaults:!1,css:!1,outputModule:!1},resolve:{extensions:[".tsx",".ts",".js",".jsx",".wasm"],alias:n.alias,fallback:{path:!1,fs:!1,crypto:!1,assert:!1}},module:m,externals:n.externals,output:outputConfig};
1
+ import e from"add-asset-html-webpack-plugin";import t from"html-webpack-plugin";import o from"webpack";import r from"webpackbar";import{CONFIG as s,PUBLICPATH as l}from"./config.js";import n from"./done.js";import a from"./html-add-entry-attr.js";import i from"./html-plugin-option.js";import{moduleFederation as p}from"./module-federation.js";import m from"./module.config.js";import c,{CUSTOMCONFIG as u}from"./paths.js";import{PACKAGENAME as f,PACKAGEVERSION as h,isDev as d,isLibrary as b,isMicro as y}from"./process-env.js";import{seo as j}from"./seo.js";import{resolveNodeModulesPath as g,resolveProgramPath as w}from"./utils.js";import k from"./virtual-module-plugin.js";import x from"./virtual-modules.js";let{AutomaticPrefetchPlugin:C,DefinePlugin:v,SourceMapDevToolPlugin:$,WatchIgnorePlugin:O}=o,P=s.assetHtml.map(e=>({publicPath:"",...e}));export const outputConfig={path:w(b?"docs":"dist"),filename:"js/[name].bundle.js",chunkFilename:`js/[${d?"name":"chunkhash"}].js`,assetModuleFilename:e=>{let t=e.filename;return t&&t.endsWith("?url")&&/(?:webworker|worker)(\.|\b).*\.(js|ts)\b/.test(t.replace("?url",""))?"worker/[name][ext]":"assets/[name][hash][ext]"},library:{name:f,type:"window"},globalObject:"window",chunkLoadingGlobal:`webpackJsonp_${f}`,pathinfo:d,clean:!0,publicPath:l,asyncChunks:!0,charset:!0};let M={main:g("@app/entry")};s.polyfill&&Object.assign(M,{"dom-polyfills":[`${c.corePath}/polyfills/replace-children.js`]}),s.entry&&("string"==typeof s.entry?M={main:s.entry}:Object.keys(s.entry)&&Object.assign(M,s.entry)),s.output&&("string"==typeof s.output?outputConfig.path=s.output:Object.keys(s.output)&&Object.assign(outputConfig,s.output));let D=s.basename.split("/").filter(Boolean).length,A=`${Array(D).fill("..").join("/")+(D?"/":"")}404.html`,{pathSegmentsToKeep:B=D,path:H=A}=s.fixBrowserRouter||{},K=!1;s.cacheDirectory&&(K={type:"filesystem",store:"pack",allowCollectingMemory:!0,cacheDirectory:s.cacheDirectory,memoryCacheUnaffected:!0,name:`${u||"default"}-${d?"development":"production"}`,version:h});let L=[new C,...p,s.htmlPluginOption&&new t(i),s.fixBrowserRouter&&new t({filename:H,inject:!1,templateContent:()=>`<html lang="en"><head><title>${i.title}</title><script>const pathKeep = ${B||D};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>`}),new e(P),y&&new a(e=>!!(e.match(/main\.(.*)\.bundle.js$/)||e.match("main.bundle.js"))),new v({"process.env":JSON.stringify(s.env)}),new O({paths:[/\.d\.ts$/]}),s.sourceMap&&new $(s.sourceMap),s.bar&&new r(s.bar),new n({done:()=>{!d&&s.seo&&j(),s.done?.(),d||setTimeout(()=>{process.exit(0)},2e3)}}),new k(x),...s.plugins].filter(e=>!!e);export const clientConfig={entry:M,stats:"errors-only",cache:K,infrastructureLogging:{level:"error"},target:"web",externalsPresets:s.externalsPresets,plugins:L,experiments:{topLevelAwait:!0,asyncWebAssembly:!0,cacheUnaffected:!0,layers:!0,lazyCompilation:d&&{imports:!1,entries:!1},buildHttp:s.buildHttp,backCompat:!0,futureDefaults:!1,css:!1,outputModule:!1},resolve:{extensions:[".tsx",".ts",".js",".jsx"],alias:s.alias,fallback:{path:!1,fs:!1,crypto:!1,assert:!1}},module:m,externals:s.externals,output:outputConfig};
package/lib/config.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import type { ConfigType } from '.';
2
- export declare const log: (msg: string) => void;
3
- export declare const isTsc: boolean;
2
+ export declare function initConfig(): Promise<void>;
4
3
  export declare const CONFIG: ConfigType;
5
4
  export declare const PUBLICPATH: string;
6
- export declare let hasCustomRouter: boolean;
package/lib/config.js CHANGED
@@ -1 +1 @@
1
- import{accessSync as e,constants as t}from"fs";import o from"readline";import s from"chalk";import{merge as r}from"webpack-merge";import i from"./paths.js";import{APPTYPE as a,CUSTOMCONFIG as n,FRAMEWORK as l,PACKAGENAME as c,coreName as m,jsxImportSource as p}from"./process-env.js";import{isFunction as u,readConf as d,resolveProgramPath as h}from"./utils.js";let f=["@moneko/core",`@moneko/${l}`,"neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app",".cache/http/data"],g={library:{"@":h("site"),"@pkg":h("components"),[c]:h("components")},mobile:{},site:{},backstage:{},micro:{}},x={seo:!1,mode:"csr",compiler:"swc",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{js:{},css:{}},sourceMap:{filename:"[file].map",publicPath:""},env:{NODE_ENV:process.env.NODE_ENV},basename:"/",publicPath:"/",rem:{designSize:"mobile"===a?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":h("src")},g[a]),moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:[],cacheDirectory:i.webpackCachePath,devServer:{allowedHosts:[".baidu.com"],host:"localhost",port:3e3,https:!1,compress:!1},htmlPluginOption:{template:`node_modules/${m}/template/index.html`,favicon:`node_modules/${m}/template/favicon.ico`,tags:[]},assetHtml:[],routerMode:"browser",fixBrowserRouter:!1,plugins:[],splitChunk:{chunks:"all",minSize:1024,minChunks:1,cacheGroups:{route:{test:/[\\/].git[\\/]router/,priority:-10,reuseExistingChunk:!0,name:"route"},example:{test:/[\\/].git[\\/]example/,priority:-10,reuseExistingChunk:!0,name:"example"}}},runtimeChunk:"single",moduleFederation:[],rulesInclude:{less:f,css:f,js:f,media:f,fonts:f,wasm:[]},mdx:{jsxImportSource:p,useDynamicImport:!0,remarkPlugins:[],rehypePlugins:[]},jsxDomExpressions:{moduleName:"solid-js/web",builtIns:["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"],contextToCustomElements:!0,wrapConditionals:!0,generate:"dom",hydratable:!1},bar:{name:"编译中",color:"#6f42c1"},virtualModule:{},normalizeCss:!0,externalsPresets:{},buildHttp:{allowedUris:[],lockfileLocation:`${i.httpCachePath}/http.lock`,cacheLocation:`${i.httpCachePath}/data`,upgrade:!0}};export const log=e=>{o.cursorTo(process.stdout,0),process.stdout.write(e)};let C=x,w=null,b={},y={};try{w=i.defaultConfigPath,e(w,t.R_OK)}catch(e){w=null}if(w)try{let e=(await d(w,"index")).default;b=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}if(n){let o=null;try{o=`${i.programPath}/config/${n}.ts`,e(o,t.R_OK)}catch(e){o=null}if(null!==o)try{let e=(await d(o,n)).default;y=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}}C=r(C,b,y);export const isTsc="tsc"===C.compiler;isTsc&&C.minifier&&(C.minifier.js||Object.assign(C.minifier,{js:{type:"terser"}}),C.minifier.css||Object.assign(C.minifier,{css:{type:"cssnano"}})),!1===C.devtool&&(C.sourceMap=!1),!1===C.sourceMap&&(C.devtool=!1),C.fixBrowserRouter&&C.htmlPluginOption&&(C.htmlPluginOption.tags||(C.htmlPluginOption.tags=[]),C.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=C;export const PUBLICPATH=CONFIG.publicPath||"/";export let hasCustomRouter;try{e(`${CONFIG.alias["@"]}/router/index.ts`,t.R_OK),hasCustomRouter=!0}catch(e){hasCustomRouter=!1}global.NEKOCLICONFIG={CONFIG,log};
1
+ import{accessSync as e,constants as t}from"fs";import o from"chalk";import{merge as i}from"webpack-merge";import s,{CUSTOMCONFIG as a}from"./paths.js";import{APPTYPE as n,PACKAGENAME as r,coreName as l,jsxImportSource as c}from"./process-env.js";import{isFunction as m,log as p,readConf as u,resolveProgramPath as d}from"./utils.js";let h=["@moneko","neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app",".cache/http/data"],f={seo:!1,mode:"csr",compiler:"swc",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{js:{},css:{}},sourceMap:{filename:"[file].map",publicPath:""},env:{NODE_ENV:process.env.NODE_ENV},basename:"/",publicPath:"/",rem:{designSize:"mobile"===n?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":d("src")},{library:{"@":d("site"),"@pkg":d("components"),[r]:d("components")},mobile:{},site:{},backstage:{},micro:{}}[n]),moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:[],cacheDirectory:s.webpackCachePath,devServer:{allowedHosts:[".baidu.com"],host:"localhost",port:3e3,https:!1,compress:!1},htmlPluginOption:{template:`node_modules/${l}/template/index.html`,favicon:`node_modules/${l}/template/favicon.ico`,tags:[]},assetHtml:[],routerMode:"browser",fixBrowserRouter:!1,plugins:[],splitChunk:{chunks:"all",minSize:1024,minChunks:1,cacheGroups:{route:{test:/[\\/].git[\\/]router/,priority:-10,reuseExistingChunk:!0,name:"route"},example:{test:/[\\/].git[\\/]example/,priority:-10,reuseExistingChunk:!0,name:"example"}}},runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:h,js:h,media:h,font:h,wasm:[]},mdx:{jsxImportSource:c,useDynamicImport:!0,remarkPlugins:[],rehypePlugins:[]},jsxDomExpressions:{moduleName:"solid-js/web",builtIns:["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"],contextToCustomElements:!0,wrapConditionals:!0,generate:"dom",hydratable:!1},bar:{name:"Client",color:"#6f42c1"},virtualModule:{},normalizeCss:!0,externalsPresets:{},buildHttp:{allowedUris:[],lockfileLocation:`${s.httpCachePath}/http.lock`,cacheLocation:`${s.httpCachePath}/data`,upgrade:!0}},g=f,C={},x={};export async function initConfig(){g=f;try{e(s.configPath,t.R_OK);let o=(await u(s.configPath,"index")).default;C=m(o)?o(process):o}catch(e){p(o.red(e))}if(a)try{e(s.customConfigPath,t.R_OK);let o=(await u(s.customConfigPath,a)).default;x=m(o)?o(process):o}catch(e){p(o.red(e))}"tsc"===(g=i(g,C,x)).compiler&&g.minifier&&(g.minifier.js||Object.assign(g.minifier,{js:{type:"terser"}}),g.minifier.css||Object.assign(g.minifier,{css:{type:"cssnano"}})),!1===g.devtool&&(g.sourceMap=!1),!1===g.sourceMap&&(g.devtool=!1),g.fixBrowserRouter&&g.htmlPluginOption&&(g.htmlPluginOption.tags||(g.htmlPluginOption.tags=[]),g.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))"}))}await initConfig();export const CONFIG=g;export const PUBLICPATH=CONFIG.publicPath||"/";global.NEKOCLICONFIG={CONFIG,CUSTOMCONFIG:a,log:p};
package/lib/coverage.js CHANGED
@@ -1,2 +1 @@
1
- import{accessSync as e,constants as r,readFileSync as c}from"fs";import{Parser as o}from"xml2js";import t from"./paths.js";import{PACKAGENAME as a,isLibrary as s}from"./process-env.js";export const coverage={};if(s)try{e(t.coveragePath,r.R_OK);let s=new o({explicitArray:!1,async:!1}).parseString,i=c(t.coveragePath,{encoding:"utf-8"});s(i,(e,r)=>{if(!e){let e=r.coverage.project.metrics.$,c=r.coverage.project.package;Object.assign(coverage,{[a]:e}),c.forEach(e=>{Object.assign(coverage,{[e.$.name]:e.metrics.$})})}})}catch(e){// error
2
- }
1
+ import{accessSync as e,constants as r,readFileSync as c}from"fs";import{Parser as o}from"xml2js";import t from"./paths.js";import{PACKAGENAME as a,isLibrary as s}from"./process-env.js";export const coverage={};if(s)try{e(t.coveragePath,r.R_OK);let s=new o({explicitArray:!1,async:!1}).parseString,i=c(t.coveragePath,{encoding:"utf-8"});s(i,(e,r)=>{if(!e){let e=r.coverage.project.metrics.$,c=r.coverage.project.package;Object.assign(coverage,{[a]:e}),c.forEach(e=>{Object.assign(coverage,{[e.$.name]:e.metrics.$})})}})}catch(e){}
package/lib/dev.d.ts CHANGED
@@ -1,3 +1 @@
1
- import webpack from 'webpack';
2
- declare const _default: webpack.Configuration[];
3
- export default _default;
1
+ export {};
package/lib/dev.js CHANGED
@@ -1,6 +1,3 @@
1
- import e from"@soda/friendly-errors-webpack-plugin";import o from"chalk";import r from"webpack";import{merge as t}from"webpack-merge";import{clientConfig as s}from"./common.js";import{CONFIG as p}from"./config.js";import{hasPkg as i}from"./has-pkg.js";import{getIPv4 as a,getPort as m}from"./net.js";import{isReact as n}from"./process-env.js";import{isFunction as l,resolveProgramPath as d}from"./utils.js";let{HotModuleReplacementPlugin:c}=r,{yellow:v,green:f}=o,h=a(),w=p.devServer.port||3e3,u=await m(w,65535,p.devServer.host),g=p.devServer.port!==u,k=i("@moneko/mock"),$=k&&(await import("@moneko/mock")).default,S=n&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,b=!1===p.devtool||p.devtool?p.devtool:"eval-cheap-module-source-map";p.devServer.port=u;let y="/"===p.basename,j=p.devServer.https?"https:":"http:",x=y?"":p.basename,A=t(s,{devtool:b,mode:"development",devServer:{headers:{"Access-Control-Allow-Origin":"*"},compress:p.devServer.compress,host:"0.0.0.0",port:u,historyApiFallback:y||{index:x.endsWith("/")?x:`${x}/`,disableDotRule:!0},https:p.devServer.https,proxy:p.proxy,allowedHosts:p.devServer.allowedHosts,client:{// 在浏览器中以百分比显示编译进度。
2
- progress:!1,logging:"info",// 当出现编译错误或警告时,在浏览器中显示全屏覆盖。
3
- overlay:!1},static:{watch:{ignored:e=>e.endsWith(".d.ts")||/\/node_modules\//.test(e)}},setupMiddlewares:(e,o)=>{if(!o)throw Error("webpack-dev-server is not defined");return o.app&&l($)&&$(o.app,d("mock/")),e},open:!1,hot:!0},plugins:[new c,S&&new S,new e({compilationSuccessInfo:{messages:[`You application is running here:
4
-
5
- Local: ${o.cyan(`${j}//${p.devServer.host}:${u}${x}`)}
6
- Network: ${o.cyan(`${j}//${h}:${u}${x}`)}`],notes:g?[`Port ${v(w)} is in use, trying ${f(u)} instead`]:[]},clearConsole:!0})].filter(Boolean)});export default[A];
1
+ import{readdirSync as e}from"fs";import t from"chalk";import o from"webpack";import s from"webpack-dev-server";import{merge as r}from"webpack-merge";import{cleanDir as l}from"./cleanup.js";import{clientConfig as i}from"./common.js";import{CONFIG as n}from"./config.js";import{hasPkg as a}from"./has-pkg.js";import{getIPv4 as c,getPort as m}from"./net.js";import d from"./paths.js";import{hasEslintConfig as p,hasStylelintConfig as u,isReact as f}from"./process-env.js";import{isFunction as h,log as v,resolveProgramPath as w}from"./utils.js";let{HotModuleReplacementPlugin:g}=o,{yellow:j,green:y,grey:b,gray:k,bgBlue:x,bgGreenBright:S,blueBright:$,greenBright:C}=t,T=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],_=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],A=e(d.programPath),D=!1,E=!1;for(let e=0,t=A.length;e<t;e++)_.includes(A[e])&&(E=!0),T.includes(A[e])&&(D=!0);D||(D=p),E||(E=u);let H=E?(await import("stylelint-webpack-plugin")).default:null,M=D?(await import("eslint-webpack-plugin")).default:null,O=n.devServer.port||3e3,P=await m(O,65535,n.devServer.host),J=a("@moneko/mock"),W=J&&(await import("@moneko/mock")).default,B=f&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,F=!1===n.devtool||n.devtool?n.devtool:"eval-cheap-module-source-map";n.devServer.port=P;let L="/"===n.basename,N=n.devServer.https?"https:":"http:",R=L?"":n.basename,Y=n.devServer.port!==P&&k(`Port ${j(O)} is in use, trying ${y(P)} instead.
2
+ `);function q(e){return`${N}//${"local"===e?n.devServer.host:c()}:${P}${R}`}let z=k("You application is running here:"),G=`${x(" Local ")} ${$(q("local"))}
3
+ ${S(" Network ")} ${C(q("net"))}`,I=[new g,B&&new B,M&&new M({fix:!0,threads:!0,extensions:["js","md","mdx","cjs","ejs","mjs","jsx","ts","tsx","json","html","coffee","vue"],exclude:["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],cache:!1,cacheStrategy:"content",lintDirtyModulesOnly:!0}),H&&new H({fix:!0,threads:!0,extensions:["css","scss","sass","less","ts","tsx","js","jsx"],exclude:["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],cache:!1,cacheStrategy:"content",lintDirtyModulesOnly:!0})].filter(Boolean),K={headers:{"Access-Control-Allow-Origin":"*"},compress:n.devServer.compress,host:"0.0.0.0",port:P,historyApiFallback:L||{index:R.endsWith("/")?R:`${R}/`,disableDotRule:!0},https:n.devServer.https,proxy:n.proxy,allowedHosts:n.devServer.allowedHosts,client:{reconnect:!0,progress:!1,logging:"info",overlay:!1,webSocketTransport:"ws"},webSocketServer:"ws",static:{watch:{ignored:e=>e.endsWith(".d.ts")||e.includes("/node_modules/")}},setupMiddlewares:(e,t)=>{if(!t)throw Error("devServer is not defined");return t.app&&h(W)&&W(t.app,w("mock/")),e},open:!1,hot:!0},Q=o(r(i,{devtool:F,mode:"development",plugins:I}));Q.watch({aggregateTimeout:600,ignored:/node_modules/,stdin:!0},(e,t)=>{!e&&t&&(process.stdout.write("\x1b[2J\x1b[3J\x1b[H"),v([z,"",G,"",b(`Compiled successfully in ${y(`${t.endTime-t.startTime}ms`)}`)]),t.compilation.warnings.forEach(e=>v(e.message)),t.compilation.errors.forEach(e=>v(e.message)),Y&&v(Y))});let U=new s(K,Q);U.startCallback(e=>{e||v([z,"",G])}),U.stopCallback(e=>{e||l(d.cachePath)}),process.on("exit",function(){Q.close(()=>{}),U.invalidate(),U.stop()});
package/lib/docs.js CHANGED
@@ -1,2 +1 @@
1
- import{statSync as e}from"fs";import{dirname as t,join as o}from"path";import{watch as r}from"chokidar";import{CONFIG as i}from"./config.js";import n from"./generate-api.js";import{FRAMEWORK as s,FRAMEWORKNAME as p,createElement as a,isLibrary as l,isReact as c,isSolid as d}from"./process-env.js";import m from"./reactive-object.js";import{resolveProgramPath as f}from"./utils.js";let u="@app/comment";export const docs=new m;let $={[u]:{}},g=`() => ${a}(SuspenseComp, { comp: $1 })`,b=`import { ${a}${d?",Dynamic":""} } from "${p}${d?"/web":""}";import SuspenseComp from "@app/suspense";`;// 要执行的函数
2
- function h(e,r){let s=e.replace(RegExp(`^${i.alias["@pkg"]}`),""),p=t(s).replace(/^\//,""),l=[u,p].join("/"),m=s.split("/").pop()?.replace(/\.tsx?/,".md");if(!m)return;$[u][p]||($[u][p]={});let f=o(l,m);if("deleted"===r)$[u][p][m]&&delete $[u][p][m];else{let t=n(e);$[f]=t,t?$[u][p][m]=`rr(() => import(/* webpackChunkName: '${f}' */'${f}?raw').then((res) => ({default: ${c?"() =>":""}${a}(${d?"Dynamic":"'n-md'"}, {text: res.default, ${d?"component: 'n-md', ":""}css: 'table td a {display:inline-flex;align-items:center;gap:2px;}table td a n-img{display:inline-block;overflow:hidden;border-radius:var(--border-radius);inline-size:18px;block-size:18px;}'})})))rr`:$[u][p][m]&&delete $[u][p][m]}let h={};for(let e in $)if(Object.prototype.hasOwnProperty.call($,e)){let t=$[e];if(e===u)for(let e in t)Object.prototype.hasOwnProperty.call(t,e)&&(h[e]=Object.values(t[e]));else docs.setData(e,t)}docs.setData("@app/docs",`${b}export default ${JSON.stringify(h).replace(/"rr\((.+?)\)rr"/g,g)}`)}["react","solid"].includes(s)||(g="$1",b=""),l&&function(){let t=[],o=r(f("components"),{ignored:[/(^|\/)\../,/(^|\/)__tests__(\/|$)/],persistent:!0,ignoreInitial:!1});function i(t){return/\.tsx?$/.test(t)&&e(t).isFile()}o.on("add",e=>{i(e)&&(h(e,"added"),t.push(e))}),o.on("change",e=>{i(e)&&h(e,"change")}),o.on("unlink",e=>{i(e)&&(h(e,"deleted"),t.splice(t.indexOf(e),1))}),o.on("ready",()=>{t.forEach(e=>{h(e,"change")})}),process.on("SIGINT",function(){o.close()})}();
1
+ import{stat as e}from"fs";import{dirname as t,join as o}from"path";import{watch as r}from"chokidar";import{CONFIG as n}from"./config.js";import i from"./generate-api.js";import{FRAMEWORK as s,FRAMEWORKNAME as p,createElement as a,isLibrary as l,isReact as c,isSolid as d}from"./process-env.js";import m from"./reactive-object.js";import{resolveProgramPath as f}from"./utils.js";let u="@app/comment";export const docs=new m;let $={[u]:{}},g=`() => ${a}(SuspenseComp, { comp: $1 })`,b=`import { ${a}${d?",Dynamic":""} } from "${p}${d?"/web":""}";import SuspenseComp from "@app/suspense";`;function h(e,r){let s=e.replace(RegExp(`^${n.alias["@pkg"]}`),""),p=t(s).replace(/^\//,""),l=[u,p].join("/"),m=s.split("/").pop()?.replace(/\.tsx?/,".md");if(!m)return;$[u][p]||($[u][p]={});let f=o(l,m);function h(){let e={};for(let t in $)if(Object.prototype.hasOwnProperty.call($,t)){let o=$[t];if(t===u)for(let t in o)Object.prototype.hasOwnProperty.call(o,t)&&(e[t]=Object.values(o[t]));else docs.setData(t,o)}docs.setData("@app/docs",`${b}export default ${JSON.stringify(e).replace(/"rr\((.+?)\)rr"/g,g)}`)}"deleted"===r?($[u][p][m]&&delete $[u][p][m],h()):i(e,e=>{$[f]=e,e?$[u][p][m]=`rr(() => import(/* webpackChunkName: '${f}' */'${f}?raw').then((res) => ({default: ${c?"() =>":""}${a}(${d?"Dynamic":"'n-md'"}, {text: res.default, ${d?"component: 'n-md', ":""}css: 'table td a {display:inline-flex;align-items:center;gap:2px;}table td a n-img{display:inline-block;overflow:hidden;border-radius:var(--border-radius);inline-size:18px;block-size:18px;}'})})))rr`:$[u][p][m]&&delete $[u][p][m],h()})}["react","solid"].includes(s)||(g="$1",b=""),l&&function(){let t=[],o=r(f("components"),{ignored:[/(^|\/)\../,/(^|\/)__tests__(\/|$)/],persistent:!0,ignoreInitial:!1});function n(e,t){return/\.tsx?$/.test(e)&&t.isFile()}o.on("add",o=>{e(o,(e,r)=>{!e&&n(o,r)&&(h(o,"added"),t.push(o))})}),o.on("change",t=>{e(t,(e,o)=>{!e&&n(t,o)&&h(t,"change")})}),o.on("unlink",o=>{e(o,(e,r)=>{!e&&n(o,r)&&(h(o,"deleted"),t.splice(t.indexOf(o),1))})}),o.on("ready",()=>{t.forEach(e=>{h(e,"change")})}),process.on("SIGINT",function(){o.close()})}();
@@ -1 +1 @@
1
- export default function generateApi(path: string): string;
1
+ export default function generateApi(path: string, call: (data: string) => void): void;
@@ -1,3 +1 @@
1
- import{readFileSync as e}from"fs";import{dirname as t}from"path";import n from"typescript";import{CONFIG as r}from"./config.js";let{ScriptKind:l,ScriptTarget:o,SyntaxKind:i,createSourceFile:a,forEachChild:c,getLeadingCommentRanges:u,isInterfaceDeclaration:s,isQuestionToken:f,isPropertySignature:p,isFunctionTypeNode:m,isUnionTypeNode:g,isMethodSignature:$}=n,h={};function b(e){let t=u(e.getSourceFile().text,e.pos);if(t){let n=e.getSourceFile().text.substring(t[0].pos,t[0].end),r=n.match(/\/\*\*([\s\S]*?)\*\//);if(r)return r[1].replace(/^\s*\* ?/gm,"").replace(/\s+$/,"").trim()}return null}function d(e){if(!e)return null;let t=e.match(/@since\s+([^\n]+)/);return t?t[1].trim():null}function y(e){if(!e)return null;let t=e.match(/@author (\w+)\s*(?:<([^>]+)>)?/);if(t?.length){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}](https://avatars.githubusercontent.com/${e}?s=64)${e}](${n})`}return null}function x(e){if(!e)return null;let t=e.match(/@ignore\s+([^\n]+)/);return t?t[1].trim():null}let j=/(?<!['"])(unknown|any|void|bigint|object|undefined|null|boolean|number|string|symbol)(?!['"])/g;function T(e,t){if(!e)return null;let n=e.replace(/\b([A-Z][a-zA-Z0-9]*)\b/g,e=>{if(h[e]){let n=`/${[r.basename,h[e]].join("/").split("/").filter(Boolean).join("/")}`;return t?`[\\color{#009688}{${e}}](${n})`:`[${e}](${n})`}return t?`\\color{#009688}{${e}}`:e});return t&&(n=n.replace(j,e=>`\\color{#009688}{${e}}`)),n}function B(e){return(function(e){let t;if(!e)return null;let n=[];for(;t=/\\color{([^|}]*)\|?([^|}]*)\|?([^|}]*)\|?([^}]*)}{([^}]*)}/g.exec(e);)n.push(t[0]);return e.replace(/[{}[\]()=>]|keyof|typeof|true|false/g,e=>n.some(t=>t.includes(e))?e:`\\color{#569cd6}{${e}}`)})(e)?.replace(/^\s*\|\s*|\s*\|\s*$/gm,"").replace(/\n/g,"<br/>").replace(/\*/g,"\\*").replace(/\|/g,"\\|").replace(/(['"])((?:(?!\1).)*)\1/g,"\\color{#ce9178}{$1$2$1}")}function k(e){return e?e.replace(/^@[a-z].+/gm,"").replace(/(\n\s+)+/g,"<br />").replace(/\n/g,"<br />").replace(/(<br \/>)$/g,""):null}export default function w(u){let j=e(u,"utf-8"),w=a(u,j,o.Latest,!0,l.TS),E="";return c(w,e=>{s(e)?E+=function(e){let l=e.name.text;Object.assign(h,{[e.name.text]:t(e.getSourceFile().fileName).replace(r.alias["@pkg"],"")});let o=b(e),a=d(o),c=k(o),u=x(o)?.split("|")||[],s=u.includes("comment"),j=u.includes("initial"),w=u.includes("optional"),E=u.includes("version"),S=u.includes("author"),v=c?`\\color{|4||0.45}{${l}}`:l,F=(function(e){let t=[];if(e.heritageClauses){for(let r of e.heritageClauses)if(r.token===n.SyntaxKind.ExtendsKeyword)for(let e of r.types)t.push(e.getText())}return t})(e)?.map(e=>`<n-tag color="#4c81db" css=".tag{gap:0px;}">${T(B(e))}</n-tag>`),z=[c,v,a&&`\\color{#52c11b|1||0.9}{${a}}`,F.length>0&&`<sub>\`extends\`</sub> ${F.join(" ")}`].filter(Boolean).join(" "),K=`## ${z}`,N=e.members.filter(// 排除 never
2
- e=>p(e)&&e.type?.kind!==i.NeverKeyword||$(e)),q=[];if(N.length){N.forEach(e=>{let t=T(B($(e)?`(${e.parameters.map(e=>`${e.name.getText()}: ${e.type?.getText()||"any"}`).join(", ")}): ${e.type?.getText()||"any"}`:e.type?.getText()||"any"),!0),n=b(e),r=B(e.name.getText());!r||r.startsWith("\\color")||($(e)||function(e){if(e.type){if(!g(e.type))return m(e.type);for(let t of e.type.types)if(m(t))return!0}return!1}(e)||t?.includes("=>")?r=`\\color{#f9a913}{${r}}`:/^["'](.+)["']$/.test(r)||(r=`\\color{#4c81db}{${r}}`));let l=e.questionToken&&f(e.questionToken);q.push([r,!w&&`\\color{${l?"#f9a913":"#52c11b"}\\|\\|\\|0.9}{${l?"✘":"✔"}}`,!s&&B(k(n)),t,!j&&B(function(e){if(!e)return null;let t=e.match(/@default\s+([^\n]+)/);return t?t[1].trim():null}(n)),!E&&B(d(n)),!S&&(y(n)||y(o))])});let e=!1,t=!1,n=!1,r=!1;q.forEach(l=>{!s&&l[2]&&(r=!0),!j&&l[4]&&(n=!0),!E&&l[5]&&(t=!0),!S&&l[6]&&(e=!0)}),K+="\n";let l=["属性",!w&&"必要",r&&"说明","类型",n&&"默认值",t&&"版本",e&&"作者"].filter(Boolean).join("|");K+=`|${l}|`;let i=[":-",!w&&":-",r&&":-",":-",n&&":-",t&&":-",e&&":-"].filter(Boolean);K+="\n";let a=i.join("|");K+=`|${a}|`,q.forEach(l=>{K+="\n";let o=[l[0]||"-",!w&&(l[1]||"-"),r&&(l[2]||"-"),l[3]||"-",n&&(l[4]||"-"),t&&(l[5]||"-"),e&&(l[6]||"-")].filter(Boolean).join("|");K+=`|${o}|`}),K+="\n"}return K+="\n"}(e):n.isEnumDeclaration(e)&&(E+=function(e){let l=e.name.text,o=b(e),i=k(o),a=d(o);Object.assign(h,{[e.name.text]:t(e.getSourceFile().fileName).replace(r.alias["@pkg"],"")});let c=i?`\\color{|4||0.45}{${l}}`:l,u=[i,c,a&&`\\color{#52c11b|1||0.9}{${a}}`].filter(Boolean).join(" "),s=x(o)?.split("|")||[],f=s.includes("comment"),p=s.includes("version"),m=s.includes("author"),g=`## ${u}`;if(e.members.length){let t=[];e.members.forEach(e=>{let r=B(e.name.getText()),l=b(e),i=B(function(e){let t=e.initializer;return t&&n.isStringLiteral(t)?` '${t.text}'`:null}(e)),a=B(d(l)),c=B(k(l));!r||r.startsWith("\\color")||/^["'](.+)["']$/.test(r)||(r=`\\color{#4c81db}{${r}}`),t.push([r,!f&&c,i,!p&&a,!m&&(y(l)||y(o))]);// markdownContent += `| ${name} | ${comment} | ${value} | ${version} |`;
3
- });let r=!1,l=!1,i=!1;t.forEach(e=>{!f&&e[1]&&(i=!0),!p&&e[3]&&(l=!0),!m&&e[4]&&(r=!0)}),g+="\n";let a=["属性",i&&"说明","值",l&&"版本",r&&"作者"].filter(Boolean).join("|");g+=`|${a}|`;let c=[":-",i&&":-",":-",l&&":-",r&&":-"].filter(Boolean);g+="\n";let u=c.join("|");g+=`|${u}|`,t.forEach(e=>{g+="\n";let t=[e[0]||"-",i&&(e[1]||"-"),e[2]||"-",l&&(e[3]||"-"),r&&(e[4]||"-")].filter(Boolean).join("|");g+=`|${t}|`})}return g+="\n\n"}(e))}),E}
1
+ import{readFile as e}from"fs";import{dirname as t}from"path";import n from"typescript";import{CONFIG as r}from"./config.js";let{ScriptKind:l,ScriptTarget:o,SyntaxKind:i,createSourceFile:c,forEachChild:a,getLeadingCommentRanges:u,isInterfaceDeclaration:s,isQuestionToken:f,isPropertySignature:p,isFunctionTypeNode:m,isUnionTypeNode:g,isMethodSignature:$}=n,h={};function b(e){let t=u(e.getSourceFile().text,e.pos);if(t){let n=e.getSourceFile().text.substring(t[0].pos,t[0].end),r=n.match(/\/\*\*([\s\S]*?)\*\//);if(r)return r[1].replace(/^\s*\* ?/gm,"").replace(/\s+$/,"").trim()}return null}function d(e){if(!e)return null;let t=e.match(/@since\s+([^\n]+)/);return t?t[1].trim():null}function y(e){if(!e)return null;let t=e.match(/@author (\w+)\s*(?:<([^>]+)>)?/);if(t?.length){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}](https://avatars.githubusercontent.com/${e}?s=64)${e}](${n})`}return null}function x(e){if(!e)return null;let t=e.match(/@ignore\s+([^\n]+)/);return t?t[1].trim():null}let j=/(?<!['"])(unknown|any|void|bigint|object|undefined|null|boolean|number|string|symbol)(?!['"])/g;function T(e,t){if(!e)return null;let n=e.replace(/\b([A-Z][a-zA-Z0-9]*)\b/g,e=>{if(h[e]){let n=`/${[r.basename,h[e]].join("/").split("/").filter(Boolean).join("/")}`;return t?`[\\color{#009688}{${e}}](${n})`:`[${e}](${n})`}return t?`\\color{#009688}{${e}}`:e});return t&&(n=n.replace(j,e=>`\\color{#009688}{${e}}`)),n}function B(e){return(function(e){let t;if(!e)return null;let n=[];for(;t=/\\color{([^|}]*)\|?([^|}]*)\|?([^|}]*)\|?([^}]*)}{([^}]*)}/g.exec(e);)n.push(t[0]);return e.replace(/[{}[\]()=>]|keyof|typeof|true|false/g,e=>n.some(t=>t.includes(e))?e:`\\color{#569cd6}{${e}}`)})(e)?.replace(/^\s*\|\s*|\s*\|\s*$/gm,"").replace(/\n/g,"<br/>").replace(/\*/g,"\\*").replace(/\|/g,"\\|").replace(/(['"])((?:(?!\1).)*)\1/g,"\\color{#ce9178}{$1$2$1}")}function k(e){return e?e.replace(/^@[a-z].+/gm,"").replace(/(\n\s+)+/g,"<br />").replace(/\n/g,"<br />").replace(/(<br \/>)$/g,""):null}export default function w(u,j){e(u,{encoding:"utf-8"},(e,w)=>{if(!e){let e=c(u,w,o.Latest,!0,l.TS),E="";a(e,e=>{s(e)?E+=function(e){let l=e.name.text;Object.assign(h,{[e.name.text]:t(e.getSourceFile().fileName).replace(r.alias["@pkg"],"")});let o=b(e),c=d(o),a=k(o),u=x(o)?.split("|")||[],s=u.includes("comment"),j=u.includes("initial"),w=u.includes("optional"),E=u.includes("version"),S=u.includes("author"),v=a?`\\color{|4||0.45}{${l}}`:l,F=(function(e){let t=[];if(e.heritageClauses){for(let r of e.heritageClauses)if(r.token===n.SyntaxKind.ExtendsKeyword)for(let e of r.types)t.push(e.getText())}return t})(e)?.map(e=>`<n-tag color="#4c81db" css=".tag{gap:0px;}">${T(B(e))}</n-tag>`),z=[a,v,c&&`\\color{#52c11b|1||0.9}{${c}}`,F.length>0&&`<sub>\`extends\`</sub> ${F.join(" ")}`].filter(Boolean).join(" "),K=`## ${z}`,N=e.members.filter(e=>p(e)&&e.type?.kind!==i.NeverKeyword||$(e)),q=[];if(N.length){N.forEach(e=>{let t=T(B($(e)?`(${e.parameters.map(e=>`${e.name.getText()}: ${e.type?.getText()||"any"}`).join(", ")}): ${e.type?.getText()||"any"}`:e.type?.getText()||"any"),!0),n=b(e),r=B(e.name.getText());!r||r.startsWith("\\color")||($(e)||function(e){if(e.type){if(!g(e.type))return m(e.type);for(let t of e.type.types)if(m(t))return!0}return!1}(e)||t?.includes("=>")?r=`\\color{#f9a913}{${r}}`:/^["'](.+)["']$/.test(r)||(r=`\\color{#4c81db}{${r}}`));let l=e.questionToken&&f(e.questionToken);q.push([r,!w&&`\\color{${l?"#f9a913":"#52c11b"}\\|\\|\\|0.9}{${l?"✘":"✔"}}`,!s&&B(k(n)),t,!j&&B(function(e){if(!e)return null;let t=e.match(/@default\s+([^\n]+)/);return t?t[1].trim():null}(n)),!E&&B(d(n)),!S&&(y(n)||y(o))])});let e=!1,t=!1,n=!1,r=!1;q.forEach(l=>{!s&&l[2]&&(r=!0),!j&&l[4]&&(n=!0),!E&&l[5]&&(t=!0),!S&&l[6]&&(e=!0)}),K+="\n";let l=["属性",!w&&"必要",r&&"说明","类型",n&&"默认值",t&&"版本",e&&"作者"].filter(Boolean).join("|");K+=`|${l}|`;let i=[":-",!w&&":-",r&&":-",":-",n&&":-",t&&":-",e&&":-"].filter(Boolean);K+="\n";let c=i.join("|");K+=`|${c}|`,q.forEach(l=>{K+="\n";let o=[l[0]||"-",!w&&(l[1]||"-"),r&&(l[2]||"-"),l[3]||"-",n&&(l[4]||"-"),t&&(l[5]||"-"),e&&(l[6]||"-")].filter(Boolean).join("|");K+=`|${o}|`}),K+="\n"}return K+="\n"}(e):n.isEnumDeclaration(e)&&(E+=function(e){let l=e.name.text,o=b(e),i=k(o),c=d(o);Object.assign(h,{[e.name.text]:t(e.getSourceFile().fileName).replace(r.alias["@pkg"],"")});let a=i?`\\color{|4||0.45}{${l}}`:l,u=[i,a,c&&`\\color{#52c11b|1||0.9}{${c}}`].filter(Boolean).join(" "),s=x(o)?.split("|")||[],f=s.includes("comment"),p=s.includes("version"),m=s.includes("author"),g=`## ${u}`;if(e.members.length){let t=[];e.members.forEach(e=>{let r=B(e.name.getText()),l=b(e),i=B(function(e){let t=e.initializer;return t&&n.isStringLiteral(t)?` '${t.text}'`:null}(e)),c=B(d(l)),a=B(k(l));!r||r.startsWith("\\color")||/^["'](.+)["']$/.test(r)||(r=`\\color{#4c81db}{${r}}`),t.push([r,!f&&a,i,!p&&c,!m&&(y(l)||y(o))])});let r=!1,l=!1,i=!1;t.forEach(e=>{!f&&e[1]&&(i=!0),!p&&e[3]&&(l=!0),!m&&e[4]&&(r=!0)}),g+="\n";let c=["属性",i&&"说明","值",l&&"版本",r&&"作者"].filter(Boolean).join("|");g+=`|${c}|`;let a=[":-",i&&":-",":-",l&&":-",r&&":-"].filter(Boolean);g+="\n";let u=a.join("|");g+=`|${u}|`,t.forEach(e=>{g+="\n";let t=[e[0]||"-",i&&(e[1]||"-"),e[2]||"-",l&&(e[3]||"-"),r&&(e[4]||"-")].filter(Boolean).join("|");g+=`|${t}|`})}return g+="\n\n"}(e))}),j(E)}})}
@@ -1,18 +1 @@
1
- export default /**
2
- * 向 html-webpack-plugin 导出的 HTML 模板 script 添加属性
3
- * ```javascript
4
- * // 假设输出 main chunk 为 main.[hash].chunk.js。
5
- * // 提示:输出 chunk 的名称规范化可以在 output.filename 中配置
6
- * new AddEntryAttributeWebpackPlugin((src => {
7
- * return !!(src.match(/main\.(.*)\.bundle.js$/) || src.match('main.bundle.js'));
8
- * })),
9
- * ```
10
- */class{// eslint-disable-next-line no-unused-vars
11
- constructor(t){this.entryMatchCallback=t}apply(t){t.hooks.compilation.tap("AddEntryAttributeWebpackPlugin",a=>{// 通过最终的 webpack 配置的 plugins 属性,根据插件的 constructor.name 拿到 html-webpack-plugin 实例
12
- let e=t.options.plugins.map(({constructor:t})=>t).find(t=>t&&"HtmlWebpackPlugin"===t.name);// .find(
13
- // (plugin) => plugin instanceof HtmlWebpackPlugin,
14
- // ) as typeof HtmlWebpackPlugin;
15
- if(e){// 获取 html-webpack-plugin 所有的 hooks
16
- let t=e.getHooks(a);// 在插入标签之前做些什么
17
- t.alterAssetTagGroups.tap("AddEntryAttributeWebpackPlugin",t=>(// 拿到所有的标签,如果是 script 标签,并且满足我们的匹配函数,则将其 attributes['entry'] 设为 true
18
- t.headTags.forEach(t=>{"script"===t.tagName&&this.entryMatchCallback(t.attributes.src)&&(t.attributes.entry=!0)}),t))}})}}
1
+ export default class{constructor(t){this.entryMatchCallback=t}apply(t){t.hooks.compilation.tap("AddEntryAttributeWebpackPlugin",a=>{let e=t.options.plugins.map(({constructor:t})=>t).find(t=>t&&"HtmlWebpackPlugin"===t.name);if(e){let t=e.getHooks(a);t.alterAssetTagGroups.tap("AddEntryAttributeWebpackPlugin",t=>(t.headTags.forEach(t=>{"script"===t.tagName&&this.entryMatchCallback(t.attributes.src)&&(t.attributes.entry=!0)}),t))}})}}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { default as paths } from './paths.js';
2
- export { CUSTOMCONFIG, FRAMEWORKNAME, PACKAGENAME, PACKAGEVERSION, coreName, isDev, isLibrary, isMicro, } from './process-env.js';
3
- export { realResolve, resolveNodeModulesPath, resolveProgramPath } from './utils.js';
1
+ export { default as paths, CUSTOMCONFIG } from './paths.js';
2
+ export { FRAMEWORKNAME, PACKAGENAME, PACKAGEVERSION, coreName, isDev, isLibrary, isMicro, } from './process-env.js';
3
+ export { realResolve, resolveNodeModulesPath, resolveProgramPath, log } from './utils.js';
4
4
  export { getNetworkAdress, getIPv4, getPort } from './net.js';
5
5
  export type * from '../typings/global.d.ts';
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- export{default as paths}from"./paths.js";export{CUSTOMCONFIG,FRAMEWORKNAME,PACKAGENAME,PACKAGEVERSION,coreName,isDev,isLibrary,isMicro}from"./process-env.js";export{realResolve,resolveNodeModulesPath,resolveProgramPath}from"./utils.js";export{getNetworkAdress,getIPv4,getPort}from"./net.js";
1
+ export{default as paths,CUSTOMCONFIG}from"./paths.js";export{FRAMEWORKNAME,PACKAGENAME,PACKAGEVERSION,coreName,isDev,isLibrary,isMicro}from"./process-env.js";export{realResolve,resolveNodeModulesPath,resolveProgramPath,log}from"./utils.js";export{getNetworkAdress,getIPv4,getPort}from"./net.js";
package/lib/locales.js CHANGED
@@ -1,3 +1,2 @@
1
- import{existsSync as e}from"fs";import{basename as t,join as o}from"path";import{watch as a}from"chokidar";import{CONFIG as l}from"./config.js";import r from"./esm.js";import{FRAMEWORK as n,isLibrary as s}from"./process-env.js";import c from"./reactive-object.js";import{empty as i,resolveProgramPath as g,tfc as f}from"./utils.js";let p={react:'import sso from "shared-store-object";',solid:'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'},u={react:'let storageKey="localizable.language",language=localStorage.getItem(storageKey)||"zh_CN",{translation:a,...defaultLocale}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[language]||resources.zh_CN),localizable=sso({lang:defaultLocale,t:a});export function setLang(a){let{translation:e,...l}=resources[a]||{};e&&(localizable.lang=l,localizable.t=e,localStorage.setItem(storageKey,l.language))}export default localizable;',solid:'let locale=createRoot(()=>{let e="localizable.language",a=localStorage.getItem(e)||"zh_CN",{translation:l,...o}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[a]||resources.zh_CN),[n,c]=createStore({lang:o,t:l});return createEffect(()=>{let a=resources[n.lang.language]?.translation;a&&(c("t",a),localStorage.setItem(e,n.lang.language))}),{localizable:n,setLocalizable:c,setLang:function(e){let{translation:a,...l}=resources[e]||{};a&&c("lang",l)}}},getOwner());export const setLocalizable=locale.setLocalizable;export const t=locale.localizable.t;export const lang=locale.localizable.lang;export const setLang=locale.setLang;'}[n];function d(e,t){return`${p[n]}
2
- export function interpolateString(r,n){return r.replace(/\\\${\\w+}/g,function(r){var t=r.slice(2,-1);var e=n[t];return e!==void 0?e.toString():""})}function deepFreeze(o) { const p = Reflect.ownKeys(o);for (const k of p) {const v = o[k];if ((v && typeof v === "object") || typeof v === "function") {deepFreeze(v);}}return Object.freeze(o);}export const locales = ${JSON.stringify(e)};const _res = ${JSON.stringify(t)};const resources = deepFreeze(_res);${u}`}export const localesModuleName="@app/locales";export const locales=new c({[localesModuleName]:d([],{})});let m={};// 要执行的函数
3
- async function z(e,o){let a=t(e).replace(/\.[^.]+$/,"");if("deleted"===o)delete m[a];else{let t=await import(r`${f(e)}`);Object.assign(m,{[a]:t.default})}let l=[],n={};for(let e in m)if(Object.prototype.hasOwnProperty.call(m,e)){let t=m[e],{language:o=a,title:r=o,icon:s,translation:c={}}=t;l.push({language:o,title:r,icon:s}),n[o]={language:o,title:r,icon:s,translation:c}}locales.setData(localesModuleName,d(l,n))}e(o(l.alias["@"],"./locales"))&&function(e,t){let o=[],l=a(e,{ignored:t,persistent:!0,ignoreInitial:!1});l.on("add",e=>{o.push(e),z(e,"added").finally(i)}),l.on("change",e=>{z(e,"change").finally(i)}),l.on("unlink",e=>{o.splice(o.indexOf(e),1),z(e,"deleted").finally(i)}),l.on("ready",()=>{o.forEach(e=>{z(e,"change").finally(i)})}),process.on("SIGINT",function(){l.close()})}(g(s?"site/locales":"src/locales"),[/^\..*/,/!\.ts$/,/\.d\.ts$/]);
1
+ import{stat as e}from"fs";import{basename as t,join as o}from"path";import{watch as a}from"chokidar";import{CONFIG as l}from"./config.js";import r from"./esm.js";import{FRAMEWORK as n,isLibrary as s}from"./process-env.js";import c from"./reactive-object.js";import{empty as i,resolveProgramPath as g,tfc as f}from"./utils.js";let p={react:'import sso from "shared-store-object";',solid:'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'},u={react:'let storageKey="localizable.language",language=localStorage.getItem(storageKey)||"zh_CN",{translation:a,...defaultLocale}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[language]||resources.zh_CN),localizable=sso({lang:defaultLocale,t:a});export function setLang(a){let{translation:e,...l}=resources[a]||{};e&&(localizable.lang=l,localizable.t=e,localStorage.setItem(storageKey,l.language))}export default localizable;',solid:'let locale=createRoot(()=>{let e="localizable.language",a=localStorage.getItem(e)||"zh_CN",{translation:l,...o}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[a]||resources.zh_CN),[n,c]=createStore({lang:o,t:l});return createEffect(()=>{let a=resources[n.lang.language]?.translation;a&&(c("t",a),localStorage.setItem(e,n.lang.language))}),{localizable:n,setLocalizable:c,setLang:function(e){let{translation:a,...l}=resources[e]||{};a&&c("lang",l)}}},getOwner());export const setLocalizable=locale.setLocalizable;export const t=locale.localizable.t;export const lang=locale.localizable.lang;export const setLang=locale.setLang;'}[n];function d(e,t){return`${p[n]}
2
+ export function interpolateString(r,n){return r.replace(/\\\${\\w+}/g,function(r){var t=r.slice(2,-1);var e=n[t];return e!==void 0?e.toString():""})}function deepFreeze(o) { const p = Reflect.ownKeys(o);for (const k of p) {const v = o[k];if ((v && typeof v === "object") || typeof v === "function") {deepFreeze(v);}}return Object.freeze(o);}export const locales = ${JSON.stringify(e)};const _res = ${JSON.stringify(t)};const resources = deepFreeze(_res);${u}`}export const localesModuleName="@app/locales";export const locales=new c({[localesModuleName]:d([],{})});let m={};async function z(e,o){let a=t(e).replace(/\.[^.]+$/,"");if("deleted"===o)delete m[a];else{let t=await import(r`${f(e)}`);Object.assign(m,{[a]:t.default})}let l=[],n={};for(let e in m)if(Object.prototype.hasOwnProperty.call(m,e)){let t=m[e],{language:o=a,title:r=o,icon:s,translation:c={}}=t;l.push({language:o,title:r,icon:s}),n[o]={language:o,title:r,icon:s,translation:c}}locales.setData(localesModuleName,d(l,n))}e(o(l.alias["@"],"./locales"),(e,t)=>{!e&&t.isDirectory()&&function(e,t){let o=[],l=a(e,{ignored:t,persistent:!0,ignoreInitial:!1});l.on("add",e=>{o.push(e),z(e,"added").finally(i)}),l.on("change",e=>{z(e,"change").finally(i)}),l.on("unlink",e=>{o.splice(o.indexOf(e),1),z(e,"deleted").finally(i)}),l.on("ready",()=>{o.forEach(e=>{z(e,"change").finally(i)})}),process.on("SIGINT",function(){l.close()})}(g(s?"site/locales":"src/locales"),[/^\..*/,/!\.ts$/,/\.d\.ts$/])});
package/lib/minify.js CHANGED
@@ -1,2 +1 @@
1
- import e from"terser-webpack-plugin";import{merge as o}from"webpack-merge";import{swcMinifyOption as r}from"./swcrc.js";export const minify={terser:{minify:e.terserMinify,terserOptions:{ecma:2015,parse:{},compress:{global_defs:{"@alert":"console.log"},drop_console:!0,drop_debugger:!0,pure_funcs:["console.log","console.warn","console.error","console.info"]},toplevel:!1,mangle:!0,module:!1,format:{comments:!1},// nameCache: null,
2
- ie8:!1,keep_classnames:void 0,keep_fnames:!1,safari10:!1},extractComments:!1},swc:{minify:e.swcMinify,terserOptions:r}};export const getMinifyOption=(e,r={})=>{let s=minify[e];return Object.assign(s,{terserOptions:o(s.terserOptions,r)})};
1
+ import e from"terser-webpack-plugin";import{merge as o}from"webpack-merge";import{swcMinifyOption as r}from"./swcrc.js";export const minify={terser:{minify:e.terserMinify,terserOptions:{ecma:2015,parse:{},compress:{global_defs:{"@alert":"console.log"},drop_console:!0,drop_debugger:!0,pure_funcs:["console.log","console.warn","console.error","console.info"]},toplevel:!1,mangle:!0,module:!1,format:{comments:!1},ie8:!1,keep_classnames:void 0,keep_fnames:!1,safari10:!1},extractComments:!1},swc:{minify:e.swcMinify,terserOptions:r}};export const getMinifyOption=(e,r={})=>{let s=minify[e];return Object.assign(s,{terserOptions:o(s.terserOptions,r)})};
@@ -1,3 +1 @@
1
- import e from"mini-css-extract-plugin";import s from"mini-svg-data-uri";import{CONFIG as t,PUBLICPATH as o,isTsc as r}from"./config.js";import{hasPkg as l}from"./has-pkg.js";import a from"./modify-vars.js";import i from"./paths.js";import{FRAMEWORK as n,isDev as m,isLibrary as c,isMicro as d}from"./process-env.js";import p from"./swcrc.js";import u from"./tsloader.config.js";import{resolveNodeModulesPath as f,resolveProgramPath as y}from"./utils.js";let x={loader:`${i.corePath}/loader/css-unicode.cjs`},$=d?o:"../",g={loader:e.loader,options:{publicPath:"/"!==$?$:"../"}},j=l("@moneko/postcss")&&{loader:"postcss-loader",options:{postcssOptions:await import("@moneko/postcss")}};m&&(g="style-loader");let w=[...t.cssModules,`@moneko/${n}`,"neko-ui"].map(f),v=[...["src/styles/variables.less","src/styles/mixins.less","site/styles/variables.less","site/styles/mixins.less"].map(y)],b=["components","example","mock","site","src","server"].map(y),h=[g,m&&{loader:"@teamsupercell/typings-for-css-modules-loader",options:{verifyOnly:!m}},{loader:"css-loader",options:{modules:{// 根据文件名觉得是否启用cssModules | 排除 node_modules *global.css *global.less
2
- auto:e=>{for(let s=0,t=w.length;s<t;s++)if(e&&e?.includes(w[s]))return/(.*(?<!\.?global\.(le|c)ss)$)/i.test(e);return/(^(?!.*node_modules))(.*(?<!\.?global\.(le|c)ss)$)/i.test(e)},// localIdentName: isDev ? '[path][name]__[local]' : '[hash:base64]',
3
- localIdentName:"[path][name]__[local]",exportLocalsConvention:"dashesOnly"},importLoaders:2}},j,x,{loader:"less-loader",options:{sourceMap:!!t.sourceMap,lessOptions:{modifyVars:a,javascriptEnabled:!0}}},{loader:"style-resources-loader",options:{patterns:v}}].filter(Boolean),k={loader:r?"ts-loader":"swc-loader",options:r?u:p(m)};function O(e){return b.concat(t.rulesInclude?.[e]?.map(f)||[])}let B=O("media"),L={rules:[c&&{test:/\.mdx?$/i,include:[y("components")],exclude:[/(.+)\/examples\/(.+).mdx?$/i],enforce:"pre",use:[{loader:`${i.corePath}/loader/frontmatter.cjs`}]},{oneOf:[{resourceQuery:/raw/i,type:"asset/source"},{resourceQuery:/url/i,type:"asset/resource",generator:{filename:e=>{let s=e.filename;return s&&s.endsWith("wasm?url")?"wasm/[name][ext]":"assets/[name][ext]"}}},{test:/\.wasm$/i,type:"webassembly/async",include:O("wasm")},{test:/\.txt$/i,type:"asset/source"},{test:/\.ico$/i,type:"asset/inline",include:B},{test:/\.svg$/i,type:"asset/inline",generator:{dataUrl:e=>s(e.toString())},include:B},{test:/\.(gif|png|jpe?g|mp4)$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/images/[name][ext]"},include:B},{test:/\.(eot|ttf|otf|woff|woff2)$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/fonts/[name][ext]"},include:O("fonts")},{test:/\.less$/i,use:h,include:O("less")},{test:/\.css$/i,use:[g,"css-loader",j,x].filter(Boolean),include:O("css")},{test:/\.(cj|mj|t|j)s(|x)$/i,use:[...t.prefixJsLoader,k].filter(Boolean),include:O("js")},{test:/\.mdx?$/i,use:[...t.prefixJsLoader,k,{loader:"@mdx-js/loader",options:t.mdx}].filter(Boolean),include:b,exclude:[/(.+)\/examples\/(.+).mdx?$/i]},{test:/\.mdx?$/i,type:"asset/source",include:[/(.+)\/examples\/(.+).mdx?$/i]},{type:"asset/source",include:[/(.+)\/examples\/(.+).*?$/i]}]},...t.moduleRules].filter(e=>"object"==typeof e)};export default L;
1
+ import e from"mini-css-extract-plugin";import s from"mini-svg-data-uri";import{CONFIG as t,PUBLICPATH as o}from"./config.js";import{hasPkg as r}from"./has-pkg.js";import a from"./modify-vars.js";import l from"./paths.js";import{FRAMEWORK as i,isDev as n,isLibrary as c,isMicro as m}from"./process-env.js";import d from"./swcrc.js";import p from"./tsloader.config.js";import{resolveNodeModulesPath as u,resolveProgramPath as f}from"./utils.js";let y={loader:`${l.corePath}/loader/css-unicode.cjs`},x=m?o:"../",$={loader:e.loader,options:{publicPath:"/"!==x?x:"../"}},g=r("@moneko/postcss")&&{loader:"postcss-loader",options:{postcssOptions:(await import("@moneko/postcss")).default}};n&&($="style-loader");let j=[...t.cssModules,`@moneko/${i}`,"neko-ui"].map(u),w=[...["src/styles/variables.less","src/styles/mixins.less","site/styles/variables.less","site/styles/mixins.less"].map(f)],v=["components","example","mock","site","src","server"].map(f),b={loader:"css-loader",options:{modules:{auto:e=>{for(let s=0,t=j.length;s<t;s++)if(e&&e?.includes(j[s]))return/(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i.test(e);return/(^(?!.*node_modules))(.*(?<!\.?global\.(le|c|sc|sa)ss)$)/i.test(e)},localIdentName:"[path][name]__[local]",exportLocalsConvention:"dashesOnly"},importLoaders:2}},h=n&&{loader:"@teamsupercell/typings-for-css-modules-loader",options:{verifyOnly:!n}},k=[$,h,b,g,y,{loader:"less-loader",options:{sourceMap:!!t.sourceMap,lessOptions:{modifyVars:a,javascriptEnabled:!0}}},{loader:"style-resources-loader",options:{patterns:w}}].filter(Boolean),O={loader:"tsc"===t.compiler?"ts-loader":"swc-loader",options:"tsc"===t.compiler?p:d(n)};function B(e){return v.concat(t.rulesInclude?.[e]?.map(u)||[])}let L=B("media"),M={rules:[c&&{test:/\.mdx?$/i,include:[f("components")],exclude:[/(.+)\/examples\/(.+).mdx?$/i],enforce:"pre",use:[{loader:`${l.corePath}/loader/frontmatter.cjs`}]},{oneOf:[{resourceQuery:/raw/i,type:"asset/source"},{resourceQuery:/url/i,type:"asset/resource",generator:{filename:e=>{let s=e.filename;return s&&s.endsWith("wasm?url")?"wasm/[name][ext]":"assets/[name][ext]"}}},{test:/\.wasm$/i,type:"webassembly/async",include:B("wasm")},{test:/\.txt$/i,type:"asset/source"},{test:/\.ico$/i,type:"asset/inline",include:L},{test:/\.svg$/i,type:"asset/inline",generator:{dataUrl:e=>s(e.toString())},include:L},{test:/\.(gif|png|jpe?g|webp)$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/images/[name][ext]"},include:L},{test:/\.(webm|mp4|ogv)$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/video/[name][ext]"},include:L},{test:/\.(woff2?|eot|ttf|otf)(\?.*)?$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/fonts/[name][ext]"},include:B("font")},{test:/\.(sa|sc)ss$/i,use:[$,h,b,g,y,{loader:"sass-loader",options:{implementation:await import("sass"),sassOptions:{}}}].filter(Boolean),include:B("css")},{test:/\.less$/i,use:k,include:B("css")},{test:/\.css$/i,use:[$,"css-loader",g,y].filter(Boolean),include:B("css")},{test:/\.(cj|mj|t|j)s(|x)$/i,use:[...t.prefixJsLoader,O].filter(Boolean),include:B("js")},{test:/\.mdx?$/i,use:[...t.prefixJsLoader,O,{loader:"@mdx-js/loader",options:t.mdx}].filter(Boolean),include:v,exclude:[/(.+)\/examples\/(.+).mdx?$/i]},{test:/\.mdx?$/i,type:"asset/source",include:[/(.+)\/examples\/(.+).mdx?$/i]},{type:"asset/source",include:[/(.+)\/examples\/(.+).*?$/i]}]},...t.moduleRules].filter(e=>"object"==typeof e)};export default M;
package/lib/paths.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ /** 附加启动配置名称
2
+ * @example
3
+ * 当通过以下命令启动时, 此时 CUSTOMCONFIG 为 test
4
+ * ```sh
5
+ * npm run start --config=test
6
+ * ```
7
+ */
8
+ export declare const CUSTOMCONFIG: string | undefined;
1
9
  declare const _default: {
2
10
  corePath: string;
3
11
  programPath: string;
@@ -5,7 +13,8 @@ declare const _default: {
5
13
  cachePath: string;
6
14
  httpCachePath: string;
7
15
  swcCachePath: string;
8
- defaultConfigPath: string;
16
+ configPath: string;
17
+ customConfigPath: string;
9
18
  coveragePath: string;
10
19
  pagesPath: string;
11
20
  componentsPath: string;
package/lib/paths.js CHANGED
@@ -1 +1 @@
1
- import{existsSync as e,mkdirSync as o}from"fs";import a from"url";let t=process.cwd(),c=`${t}/node_modules/.cache/.mo`;e(c)||o(c,{recursive:!0});export default{corePath:a.fileURLToPath(new URL(".",import.meta.url)),programPath:t,webpackCachePath:`${t}/node_modules/.temp_cache`,cachePath:c,httpCachePath:`${t}/node_modules/.cache/http`,swcCachePath:`${t}/node_modules/.swc`,defaultConfigPath:`${t}/config/index.ts`,coveragePath:`${t}/coverage/clover.xml`,pagesPath:`${t}/src/pages`,componentsPath:`${t}/components`};
1
+ import{existsSync as e,mkdirSync as o}from"fs";import c from"url";import t from"./yarn-argv.js";export const CUSTOMCONFIG=process.env.npm_config_config||t.config;let a=process.cwd(),r=`${a}/node_modules/.cache/.mo`;e(r)||o(r,{recursive:!0});export default{corePath:c.fileURLToPath(new URL(".",import.meta.url)),programPath:a,webpackCachePath:`${a}/node_modules/.temp_cache`,cachePath:r,httpCachePath:`${a}/node_modules/.cache/http`,swcCachePath:`${a}/node_modules/.swc`,configPath:`${a}/config/index.ts`,customConfigPath:`${a}/config/${CUSTOMCONFIG}.ts`,coveragePath:`${a}/coverage/clover.xml`,pagesPath:`${a}/src/pages`,componentsPath:`${a}/components`};
@@ -1,3 +1 @@
1
- function e(...t){/**
2
- * @ts-ignore */// eslint-disable-next-line consistent-this, no-invalid-this, @typescript-eslint/no-this-alias
3
- let o=this,r=t.length,l=Array(r);for(let e=0;e<r;e++)l[e]=t[e];for(;o.firstChild;)o.removeChild(o.firstChild);l.forEach(function(e){"string"==typeof e?o.appendChild(document.createTextNode(e)):o.appendChild(e)})}Element.prototype.replaceChildren||(Element.prototype.replaceChildren=e),ShadowRoot.prototype.replaceChildren||(ShadowRoot.prototype.replaceChildren=e);
1
+ function e(...t){let o=this,r=t.length,l=Array(r);for(let e=0;e<r;e++)l[e]=t[e];for(;o.firstChild;)o.removeChild(o.firstChild);l.forEach(function(e){"string"==typeof e?o.appendChild(document.createTextNode(e)):o.appendChild(e)})}Element.prototype.replaceChildren||(Element.prototype.replaceChildren=e),ShadowRoot.prototype.replaceChildren||(ShadowRoot.prototype.replaceChildren=e);
package/lib/polyfills.js CHANGED
@@ -1,3 +1 @@
1
- import r from"browserslist";import t from"core-js-compat";import o from"./paths.js";export default function(){return t({// 从项目的根目录自动寻找 browserslistrc 配置
2
- targets:r(void 0,{path:o.programPath,env:process.env.NODE_ENV}).filter(r=>!r.endsWith(" TP")),// 须指定 core-js 前两位具体版本,如 `3.20`,否则 polyfill 会不全
3
- version:"3.32.2"}).list}
1
+ import r from"browserslist";import t from"core-js-compat";import o from"./paths.js";export default function(){return t({targets:r(void 0,{path:o.programPath,env:process.env.NODE_ENV}).filter(r=>!r.endsWith(" TP")),version:"3.32.2"}).list}
@@ -17,13 +17,5 @@ export declare const PACKAGEVERSION: string;
17
17
  export declare const coreName: string;
18
18
  /** 是否为本地开发环境 */
19
19
  export declare const isDev: boolean;
20
- /** 附加启动配置名称
21
- * @example
22
- * 当通过以下命令启动时, 此时 CUSTOMCONFIG 为 test
23
- * ```sh
24
- * npm run start --config=test
25
- * ```
26
- */
27
- export declare const CUSTOMCONFIG: string | undefined;
28
20
  export declare const hasEslintConfig: boolean;
29
21
  export declare const hasStylelintConfig: boolean;
@@ -1,7 +1 @@
1
- import{readFileSync as e}from"fs";import o from"./paths.js";import t from"./yarn-argv.js";export const APPTYPE=process.env.APPTYPE;export const FRAMEWORK=process.env.FRAMEWORK;export const isLibrary="library"===APPTYPE;export const isMicro="micro"===APPTYPE;export const isReact="react"===FRAMEWORK;export const isSolid="solid"===FRAMEWORK;export const jsxImportSource={react:"react",solid:"solid-js/h"}[FRAMEWORK];export const createElement={react:"createElement",solid:"createComponent"}[FRAMEWORK];/** 框架名称 */export const FRAMEWORKNAME={react:"react",solid:"solid-js"}[FRAMEWORK];/** 应用名称 */export const PACKAGENAME=process.env.npm_package_name;/** 版本号 */export const PACKAGEVERSION=process.env.npm_package_version;let s=e(`${o.corePath}/../package.json`,{encoding:"utf-8"});/** core 包名 */export const coreName=JSON.parse(s).name;/** 是否为本地开发环境 */export const isDev="development"===process.env.NODE_ENV;/** 附加启动配置名称
2
- * @example
3
- * 当通过以下命令启动时, 此时 CUSTOMCONFIG 为 test
4
- * ```sh
5
- * npm run start --config=test
6
- * ```
7
- */export const CUSTOMCONFIG=process.env.npm_config_config||t.config;let n=Object.keys(process.env);export const hasEslintConfig=-1!==n.findIndex(e=>e.startsWith("npm_package_eslintConfig_"));export const hasStylelintConfig=-1!==n.findIndex(e=>e.startsWith("npm_package_stylelint_"));
1
+ import{readFileSync as e}from"fs";import t from"./paths.js";export const APPTYPE=process.env.APPTYPE;export const FRAMEWORK=process.env.FRAMEWORK;export const isLibrary="library"===APPTYPE;export const isMicro="micro"===APPTYPE;export const isReact="react"===FRAMEWORK;export const isSolid="solid"===FRAMEWORK;export const jsxImportSource={react:"react",solid:"solid-js/h"}[FRAMEWORK];export const createElement={react:"createElement",solid:"createComponent"}[FRAMEWORK];export const FRAMEWORKNAME={react:"react",solid:"solid-js"}[FRAMEWORK];export const PACKAGENAME=process.env.npm_package_name;export const PACKAGEVERSION=process.env.npm_package_version;let o=e(`${t.corePath}/../package.json`,{encoding:"utf-8"});export const coreName=JSON.parse(o).name;export const isDev="development"===process.env.NODE_ENV;let s=Object.keys(process.env);export const hasEslintConfig=-1!==s.findIndex(e=>e.startsWith("npm_package_eslintConfig_"));export const hasStylelintConfig=-1!==s.findIndex(e=>e.startsWith("npm_package_stylelint_"));
package/lib/prod.d.ts CHANGED
@@ -1,3 +1 @@
1
- import webpack from 'webpack';
2
- declare const _default: webpack.Configuration[];
3
- export default _default;
1
+ export {};
package/lib/prod.js CHANGED
@@ -1,5 +1 @@
1
- import e from"css-minimizer-webpack-plugin";import i from"mini-css-extract-plugin";import m from"terser-webpack-plugin";import n from"webpack";import{BundleAnalyzerPlugin as o}from"webpack-bundle-analyzer";import{merge as s}from"webpack-merge";import{clientConfig as r}from"./common.js";import{CONFIG as t}from"./config.js";import{getMinifyOption as p}from"./minify.js";let{optimize:{MinChunkSizePlugin:l}}=n,{cssnanoMinify:u,swcMinify:a}=e,c="swc"===t.compiler,f=[];t.minifier&&(t.minifier.js&&f.push(new m(p(t.minifier.js?.type||(c?"swc":"terser"),t.minifier.js?.options))),t.minifier.css&&f.push(new e({minify:{swc:a,cssnano:u}[t.minifier.css?.type||(c?"swc":"cssnano")],minimizerOptions:t.minifier.css?.options})));let d={splitChunks:t.splitChunk,runtimeChunk:t.runtimeChunk,chunkIds:"named",moduleIds:"named",// parent chunk中解决了的chunk会被删除
2
- removeAvailableModules:!0,// 删除空的chunks
3
- removeEmptyChunks:!0,// 合并重复的chunk
4
- mergeDuplicateChunks:!0,mangleWasmImports:!0,minimize:!0,minimizer:f},k=s(r,{devtool:!1===t.devtool||t.devtool?t.devtool:"cheap-module-source-map",mode:"production",optimization:d,plugins:[// 压缩 css
5
- new i({filename:"style/[name].bundle.css",chunkFilename:"style/[name].chunk.css",experimentalUseImportModule:!0}),t.bundleAnalyzer&&new o(t.bundleAnalyzer),t.splitChunk&&new l({minChunkSize:1e4})].filter(Boolean)});export default[k];
1
+ import e from"css-minimizer-webpack-plugin";import i from"mini-css-extract-plugin";import n from"terser-webpack-plugin";import m from"webpack";import{BundleAnalyzerPlugin as o}from"webpack-bundle-analyzer";import{merge as s}from"webpack-merge";import{clientConfig as r}from"./common.js";import{CONFIG as t}from"./config.js";import{getMinifyOption as p}from"./minify.js";let{optimize:{MinChunkSizePlugin:l}}=m,{cssnanoMinify:c,swcMinify:u}=e,a="swc"===t.compiler,f=[];t.minifier&&(t.minifier.js&&f.push(new n(p(t.minifier.js?.type||(a?"swc":"terser"),t.minifier.js?.options))),t.minifier.css&&f.push(new e({minify:{swc:u,cssnano:c}[t.minifier.css?.type||(a?"swc":"cssnano")],minimizerOptions:t.minifier.css?.options})));let d={splitChunks:t.splitChunk,runtimeChunk:t.runtimeChunk,chunkIds:"named",moduleIds:"named",removeAvailableModules:!0,removeEmptyChunks:!0,mergeDuplicateChunks:!0,mangleWasmImports:!0,minimize:!0,minimizer:f},k=s(r,{devtool:!1===t.devtool||t.devtool?t.devtool:"cheap-module-source-map",mode:"production",optimization:d,plugins:[new i({filename:"style/[name].bundle.css",chunkFilename:"style/[name].chunk.css",experimentalUseImportModule:!0}),t.bundleAnalyzer&&new o(t.bundleAnalyzer),t.splitChunk&&new l({minChunkSize:1e4})].filter(Boolean)}),h=m(k);h.run(()=>{}),process.on("exit",function(){h.close(()=>{})});
@@ -1,8 +1 @@
1
- import t from"events";class e extends t{constructor(t={}){super(),this.data=t}setData(t,e){e!==this.data[t]&&(this.data[t]=e,this.emit("change",t,e))}getData(t){return this.data[t]}// removeData(key: keyof T) {
2
- // if (Object.prototype.hasOwnProperty.call(this.data, key)) {
3
- // delete this.data[key];
4
- // this.emit('change', key, null);
5
- // }
6
- // }
7
- // 实现迭代器接口
8
- [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"events";class e extends t{constructor(t={}){super(),this.data=t}setData(t,e){e!==this.data[t]&&(this.data[t]=e,this.emit("change",t,e))}getData(t){return this.data[t]}[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/routes.js CHANGED
@@ -1,4 +1 @@
1
- let e,t;import{readFileSync as r,readdirSync as o,statSync as s}from"fs";import{join as n,relative as p}from"path";import{watch as i}from"chokidar";import{load as a}from"js-yaml";import{hasCustomRouter as l}from"./config.js";import c from"./paths.js";import{FRAMEWORK as m,FRAMEWORKNAME as u,createElement as f,isLibrary as d,isReact as x,isSolid as h}from"./process-env.js";import g from"./reactive-object.js";let $=/^---\n([\s\S]+?)\n---\n/,j=h?"component":"element";function y(e){return e.replace(/\$/g,":").replace(/^index\.tsx?$/,"/").replace(/^README\.mdx?$/,"/")}function N(e,t){let{regex:i,alia:l,base:c=e,outputSource:m}=t,u=o(e);return u.reduce((o,u)=>{let f=n(e,u),d=s(f);if(d.isDirectory()){let e=N(f,{...t,base:c});if(e.length>0){let t={},r={path:y(u),key:y(p(c,f))};if(m)Object.assign(t,{children:e});else{let o=e.findIndex(e=>"/"===e.path||r.path===e.path),s=e.splice(o,1)[0];e.length?Object.assign(t,!h&&s,{children:[h&&{...s,path:r.path===s.path?"/":s.path},...e].filter(Boolean)}):Object.assign(t,s)}o.push(Object.assign(t,r))}}else if(i.test(f)){let e=r(f,{encoding:"utf-8"}),t=function(e){let t=e.match($);return t&&t[1]?t[1].trim():null}(e),s=t?a(t):{},i=p(c,f),u=y(i);o.push(Object.assign({path:u.split("/").slice(-2,-1)?.join("")||"/",key:u.replace(/\/?index.tsx?$/,"/").replace(/\/?README.mdx?$/,"/").split("/").filter(Boolean).join("/"),meta:{...s}},l&&{[j]:`rr(() => import(/* webpackChunkName: '${i}' */'${n(l,i)}'))rr`},m&&{codes:function(e){let t;let r={},o=/```(.+?)\n([\s\S]*?)\n```/g;for(;null!==(t=o.exec(e));){let[,e="jsx",o]=t,s=e.split(" ").pop()||"jsx";r[s]=o.trim()}return Object.keys(r).length?r:{jsx:e}}(e.replace($,"").replace(/^\n+|\n+$/g,""))}))}return o},[])}export const routesModuleName="@app/routes";export const route=new g({[routesModuleName]:"export default []"});export const exampleModuleName="@app/example";export const examples=new g;let T=`${h?"() => ":""}${f}(SuspenseComp, { comp: $1 })`,k=`import { ${f} } from "${u}";import SuspenseComp from "@app/suspense";${x?'import prefix from "@app/prefix-router";':""}`;l&&(k+='import merge from "@app/merge-router";import customRouter from "@/router";'),["react","solid"].includes(m)||(T="$1",k="");export let routes=[];function D(e){return`${k}const routes = [{ path: "/", children: [${h?'{ path: "/" },':""} ${e}] }];const _routes = ${l?'merge([...routes, ...customRouter], "path")':"routes"};export default ${x?"prefix(_routes)":"_routes"};`}function E(e,t,r){let o=i(e,{ignored:(e,r)=>{if(r)return!r.isDirectory()&&t.test(e)},persistent:!0,ignoreInitial:!1});o.on("add",()=>{r()}).on("change",()=>{r()}).on("unlink",()=>{r()}),process.on("SIGINT",function(){o.close()})}d?(// router
2
- E(c.componentsPath,/(?<!README\.mdx?)$/,function(){clearTimeout(e),e=setTimeout(()=>{clearTimeout(e),routes=N(c.componentsPath,{regex:/README\.mdx?$/,alia:"@pkg"}),route.setData(routesModuleName,D(JSON.stringify(routes).replace(/"rr\((.+?)\)rr"/g,T).slice(1,-1)))},100)}),// demos
3
- E(c.componentsPath,/(?<!\/examples\/(.+)\.md)$/,function(){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),N(c.componentsPath,{regex:/\/examples\/(.+)\.md$/,outputSource:!0}).forEach(e=>{let t=["@app/example",e.key].filter(Boolean).join("/"),r=e.children?.[0].children?.filter(e=>e.codes)?.map(e=>({title:e.path.replace(/.md$/,""),order:0,...e.meta,codes:e.codes})).sort((e,t)=>e.order-t.order)||[];examples.setData(t,`export default ${JSON.stringify(r)};`)})},100)})):// router
4
- E(c.pagesPath,/(?<!index\.tsx?)$/,function(){clearTimeout(e),e=setTimeout(()=>{clearTimeout(e),routes=N(c.pagesPath,{regex:/index\.tsx?$/,alia:"@/pages"}),route.setData(routesModuleName,D(JSON.stringify(routes).replace(/"rr\((.+?)\)rr"/g,T).slice(1,-1)))},100)});
1
+ let e,t,r;import{accessSync as o,constants as s,readFileSync as n,readdirSync as i,statSync as p}from"fs";import{join as a,relative as l}from"path";import{watch as c}from"chokidar";import{load as m}from"js-yaml";import{CONFIG as u}from"./config.js";import f from"./paths.js";import{FRAMEWORK as d,FRAMEWORKNAME as x,createElement as h,isLibrary as g,isReact as $,isSolid as j}from"./process-env.js";import y from"./reactive-object.js";let N=/^---\n([\s\S]+?)\n---\n/;try{o(`${u.alias["@"]}/router/index.ts`,s.R_OK),e=!0}catch(t){e=!1}let O=j?"component":"element";function T(e){return e.replace(/\$/g,":").replace(/^index\.tsx?$/,"/").replace(/^README\.mdx?$/,"/")}function k(e,t){let{regex:r,alia:o,base:s=e,outputSource:c}=t,u=i(e);return u.reduce((i,u)=>{let f=a(e,u),d=p(f);if(d.isDirectory()){let e=k(f,{...t,base:s});if(e.length>0){let t={},r={path:T(u),key:T(l(s,f))};if(c)Object.assign(t,{children:e});else{let o=e.findIndex(e=>"/"===e.path||r.path===e.path),s=e.splice(o,1)[0];e.length?Object.assign(t,!j&&s,{children:[j&&{...s,path:r.path===s.path?"/":s.path},...e].filter(Boolean)}):Object.assign(t,s)}i.push(Object.assign(t,r))}}else if(r.test(f)){let e=n(f,{encoding:"utf-8"}),t=function(e){let t=e.match(N);return t&&t[1]?t[1].trim():null}(e),r=t?m(t):{},p=l(s,f),u=T(p);i.push(Object.assign({path:u.split("/").slice(-2,-1)?.join("")||"/",key:u.replace(/\/?index.tsx?$/,"/").replace(/\/?README.mdx?$/,"/").split("/").filter(Boolean).join("/"),meta:{...r}},o&&{[O]:`rr(() => import(/* webpackChunkName: '${p}' */'${a(o,p)}'))rr`},c&&{codes:function(e){let t;let r={},o=/```(.+?)\n([\s\S]*?)\n```/g;for(;null!==(t=o.exec(e));){let[,e="jsx",o]=t,s=e.split(" ").pop()||"jsx";r[s]=o.trim()}return Object.keys(r).length?r:{jsx:e}}(e.replace(N,"").replace(/^\n+|\n+$/g,""))}))}return i},[])}export const routesModuleName="@app/routes";export const route=new y({[routesModuleName]:"export default []"});export const exampleModuleName="@app/example";export const examples=new y;let D=`${j?"() => ":""}${h}(SuspenseComp, { comp: $1 })`,E=`import { ${h} } from "${x}";import SuspenseComp from "@app/suspense";${$?'import prefix from "@app/prefix-router";':""}`;e&&(E+='import merge from "@app/merge-router";import customRouter from "@/router";'),["react","solid"].includes(d)||(D="$1",E="");export let routes=[];function M(t){return`${E}const routes = [{ path: "/", children: [${j?'{ path: "/" },':""} ${t}] }];const _routes = ${e?'merge([...routes, ...customRouter], "path")':"routes"};export default ${$?"prefix(_routes)":"_routes"};`}function S(e,t,r){let o=c(e,{ignored:(e,r)=>{if(r)return!r.isDirectory()&&t.test(e)},persistent:!0,ignoreInitial:!1});o.on("add",()=>{r()}).on("change",()=>{r()}).on("unlink",()=>{r()}),process.on("SIGINT",function(){o.close()})}g?(S(f.componentsPath,/(?<!README\.mdx?)$/,function(){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),routes=k(f.componentsPath,{regex:/README\.mdx?$/,alia:"@pkg"}),route.setData(routesModuleName,M(JSON.stringify(routes).replace(/"rr\((.+?)\)rr"/g,D).slice(1,-1)))},100)}),S(f.componentsPath,/(?<!\/examples\/(.+)\.md)$/,function(){clearTimeout(r),r=setTimeout(()=>{clearTimeout(r),k(f.componentsPath,{regex:/\/examples\/(.+)\.md$/,outputSource:!0}).forEach(e=>{let t=["@app/example",e.key].filter(Boolean).join("/"),r=e.children?.[0].children?.filter(e=>e.codes)?.map(e=>({title:e.path.replace(/.md$/,""),order:0,...e.meta,codes:e.codes})).sort((e,t)=>e.order-t.order)||[];examples.setData(t,`export default ${JSON.stringify(r)};`)})},100)})):S(f.pagesPath,/(?<!index\.tsx?)$/,function(){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),routes=k(f.pagesPath,{regex:/index\.tsx?$/,alia:"@/pages"}),route.setData(routesModuleName,M(JSON.stringify(routes).replace(/"rr\((.+?)\)rr"/g,D).slice(1,-1)))},100)});
package/lib/seo.js CHANGED
@@ -1,2 +1 @@
1
- import{existsSync as t,mkdirSync as o,writeFileSync as r}from"fs";import{join as i}from"path";import{outputConfig as s}from"./common.js";import{CONFIG as e}from"./config.js";import{routes as m}from"./routes.js";import{resolveProgramPath as n}from"./utils.js";function p(t,o){try{r(t,o,"utf-8")}catch(t){//
2
- }}export const seo=()=>{let{domain:r,nojekyll:f,path:a}=e.seo||{},c=a&&n(a)||s?.path;if(!r||!c)return;t(c)||o(c);let h=e.basename,l=h.endsWith("/")?h:`${h}/`;p(i(c,"CNAME"),r),p(i(c,"robots"),`Sitemap: https://${r}${l}sitemap.txt`);let u=[];!function t(o){o.forEach(o=>{u.push(`https://${r}${l}${o.key}`),Array.isArray(o.children)&&t(o.children)})}(m),p(i(c,"sitemap.txt"),u.join("\n")),f&&p(i(c,".nojekyll"),"")};
1
+ import{existsSync as t,mkdirSync as o,writeFileSync as r}from"fs";import{join as i}from"path";import{outputConfig as s}from"./common.js";import{CONFIG as e}from"./config.js";import{routes as m}from"./routes.js";import{resolveProgramPath as n}from"./utils.js";function p(t,o){try{r(t,o,"utf-8")}catch(t){}}export const seo=()=>{let{domain:r,nojekyll:f,path:a}=e.seo||{},c=a&&n(a)||s?.path;if(!r||!c)return;t(c)||o(c);let h=e.basename,l=h.endsWith("/")?h:`${h}/`;p(i(c,"CNAME"),r),p(i(c,"robots"),`Sitemap: https://${r}${l}sitemap.txt`);let u=[];!function t(o){o.forEach(o=>{u.push(`https://${r}${l}${o.key}`),Array.isArray(o.children)&&t(o.children)})}(m),p(i(c,"sitemap.txt"),u.join("\n")),f&&p(i(c,".nojekyll"),"")};
package/lib/swcrc.js CHANGED
@@ -1,2 +1 @@
1
- import{merge as e}from"webpack-merge";import{CONFIG as o}from"./config.js";import r from"./paths.js";import s from"./polyfills.js";import{isReact as t,isSolid as n,jsxImportSource as c}from"./process-env.js";export const swcMinifyOption={compress:{top_retain:[],keep_infinity:!0,global_defs:{"@alert":"console.log"},pure_funcs:["console.log","console.warn","console.error","console.info"],toplevel:!1,drop_console:!0,drop_debugger:!0,module:!1,ecma:2015,ie8:!1,keep_classnames:void 0,keep_fnames:!1},mangle:!0};export default((a=!1)=>{let l={module:{type:"es6",resolveFully:!0},jsc:{parser:{syntax:"typescript",tsx:!0,decorators:!0,dynamicImport:!0},loose:!0,target:"es2017",externalHelpers:!0,transform:{legacyDecorator:!0,decoratorMetadata:!0,react:{runtime:"automatic",throwIfNamespace:!0,refresh:t&&a,development:a,importSource:c},optimizer:{simplify:!1}},experimental:{emitAssertForImportAttributes:!0,cacheRoot:r.swcCachePath,plugins:[["swc-plugin-another-transform-imports",function(e){for(let o=0,r=Object.keys(e),s=r.length;o<s;o++)e[r[o]].transform=`${r[o]}/${e[r[o]].transform}`,e[r[o]].style&&(e[r[o]].style=`${r[o]}/${e[r[o]].style}`);return e}(o.importOnDemand||{})],n&&["@moneko/jsx-dom-expressions",o.jsxDomExpressions||{}]].filter(Boolean)}},sourceMaps:!0,parseMap:!0};return(o.polyfill&&(l.jsc.target=void 0,// swc polyfill,会复用 babel 链路,但效率比 babel 低
2
- l.env={include:s(),mode:"usage",coreJs:"3.32.2"}),o.swcrc)?e(l,"function"==typeof o.swcrc?o.swcrc(a):o.swcrc):l});
1
+ import{merge as e}from"webpack-merge";import{CONFIG as o}from"./config.js";import r from"./paths.js";import s from"./polyfills.js";import{isReact as t,isSolid as n,jsxImportSource as c}from"./process-env.js";export const swcMinifyOption={compress:{top_retain:[],keep_infinity:!0,global_defs:{"@alert":"console.log"},pure_funcs:["console.log","console.warn","console.error","console.info"],toplevel:!1,drop_console:!0,drop_debugger:!0,module:!1,ecma:2015,ie8:!1,keep_classnames:void 0,keep_fnames:!1},mangle:!0};export default((a=!1)=>{let l={module:{type:"es6",resolveFully:!0},jsc:{parser:{syntax:"typescript",tsx:!0,decorators:!0,dynamicImport:!0},loose:!0,target:"es2017",externalHelpers:!0,transform:{legacyDecorator:!0,decoratorMetadata:!0,react:{runtime:"automatic",throwIfNamespace:!0,refresh:t&&a,development:a,importSource:c},optimizer:{simplify:!1}},experimental:{emitAssertForImportAttributes:!0,cacheRoot:r.swcCachePath,plugins:[["swc-plugin-another-transform-imports",function(e){for(let o=0,r=Object.keys(e),s=r.length;o<s;o++)e[r[o]].transform=`${r[o]}/${e[r[o]].transform}`,e[r[o]].style&&(e[r[o]].style=`${r[o]}/${e[r[o]].style}`);return e}(o.importOnDemand||{})],n&&["@moneko/jsx-dom-expressions",o.jsxDomExpressions||{}]].filter(Boolean)}},sourceMaps:!0,parseMap:!0};return(o.polyfill&&(l.jsc.target=void 0,l.env={include:s(),mode:"usage",coreJs:"3.32.2"}),o.swcrc)?e(l,"function"==typeof o.swcrc?o.swcrc(a):o.swcrc):l});
@@ -1,2 +1 @@
1
- import t from"fs";import r from"ts-import-plugin";import o from"webpack-merge";import{CONFIG as e}from"./config.js";import{isFunction as s,readConf as m,resolveProgramPath as a}from"./utils.js";let i=[];Array.isArray(e.importOnDemand)&&Object.assign(i,e.importOnDemand.map(t=>r(t)));let n=[...i],p={transpileOnly:!0,getCustomTransformers:()=>({before:n})};try{let r=a("tsloader.config.ts");t.accessSync(r,t.constants.R_OK);let e=(await m(r,"tsloader.config")).default;p=o(p,s(e)?e(process):e);// eslint-disable-next-line no-empty
2
- }catch(t){}export default p;
1
+ import t from"fs";import r from"ts-import-plugin";import o from"webpack-merge";import{CONFIG as e}from"./config.js";import{isFunction as s,readConf as m,resolveProgramPath as a}from"./utils.js";let i=[];Array.isArray(e.importOnDemand)&&Object.assign(i,e.importOnDemand.map(t=>r(t)));let n=[...i],p={transpileOnly:!0,getCustomTransformers:()=>({before:n})};try{let r=a("tsloader.config.ts");t.accessSync(r,t.constants.R_OK);let e=(await m(r,"tsloader.config")).default;p=o(p,s(e)?e(process):e)}catch(t){}export default p;
package/lib/utils.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * @returns {string[]} 包含的标识
4
4
  */
5
5
  export declare function getExportTokens(path: string): string[];
6
+ export declare function log(msg: string | string[]): void;
6
7
  export declare function tfc(filepath: string): string;
7
8
  export declare function readConf(src: string, name: string): Promise<any>;
8
9
  export declare function toUpperCaseString(string: string): string;
package/lib/utils.js CHANGED
@@ -1,15 +1,2 @@
1
- import{readFileSync as t,writeFileSync as e}from"fs";import{resolve as o}from"path";import{transformFileSync as r}from"@swc/core";import n from"./paths.js";import c from"./resolver-sync.js";let p=/export\s+(?:async\s+)?(?:function|const)\s+(\w+)/g;/** 获取导出标识
2
- * @param {string} path 文件地址
3
- * @returns {string[]} 包含的标识
4
- */export function getExportTokens(e){let o;let r=t(e,{encoding:"utf-8"}),n=[];for(;o=p.exec(r);)n.includes(o[1])||n.push(o[1]);return n}let s={inputSourceMap:!1,sourceMaps:!1,module:{type:"es6"},jsc:{parser:{syntax:"typescript"},loose:!1}};export function tfc(t){return r(t,s).code||"{}"}export function readConf(t,o){let r=`${n.cachePath}/${o}.mjs`;return e(r,tfc(t),"utf-8"),import(r)}export function toUpperCaseString(t){return t?.replace(/\b\w/g,t=>t.toUpperCase()).replace(/\./g," ")}/** 位于项目根目录下的位置
5
- * @param {string} src 路径
6
- * @returns {string} 位于项目根目录下的位置
7
- */export function resolveProgramPath(t){return o(n.programPath,`./${t}`)}/** 位于项目根目录node_modules下的位置
8
- * @param {string} src 路径
9
- * @returns {string} 位于项目根目录node_modules下的位置
10
- */export const resolveNodeModulesPath=t=>resolveProgramPath(`node_modules/${t}`);/** 获取模块真实入口位置
11
- * @param {string} url 路径
12
- * @returns {string} 模块真实入口路径
13
- */export const realResolve=t=>c.resolveSync({},n.programPath,t)||t;export function isObject(t){let e=typeof t;return null!==t&&("object"==e||"function"==e)}// eslint-disable-next-line no-unused-vars
14
- export function isFunction(t){if(!isObject(t))return!1;let e=Object.prototype.toString.call(t);return"[object Function]"==e||"[object AsyncFunction]"==e||"[object GeneratorFunction]"==e||"[object Proxy]"==e}export function empty(){// empty void
15
- }
1
+ import{readFileSync as t,writeFileSync as o}from"fs";import{resolve as e}from"path";import r from"readline";import{transformFileSync as n}from"@swc/core";import c from"./paths.js";import s from"./resolver-sync.js";let p=/export\s+(?:async\s+)?(?:function|const)\s+(\w+)/g;export function getExportTokens(o){let e;let r=t(o,{encoding:"utf-8"}),n=[];for(;e=p.exec(r);)n.includes(e[1])||n.push(e[1]);return n}let u={inputSourceMap:!1,sourceMaps:!1,module:{type:"es6"},jsc:{parser:{syntax:"typescript"},loose:!1}};export function log(t){Array.isArray(t)?t.forEach(t=>{log(`${t}
2
+ `)}):(r.cursorTo(process.stdout,0),process.stdout.write(t))}export function tfc(t){return n(t,u).code||"{}"}export function readConf(t,e){let r=`${c.cachePath}/${e}.mjs`;return o(r,tfc(t),"utf-8"),import(r)}export function toUpperCaseString(t){return t?.replace(/\b\w/g,t=>t.toUpperCase()).replace(/\./g," ")}export function resolveProgramPath(t){return e(c.programPath,`./${t}`)}export const resolveNodeModulesPath=t=>resolveProgramPath(`node_modules/${t}`);export const realResolve=t=>s.resolveSync({},c.programPath,t)||t;export function isObject(t){let o=typeof t;return null!==t&&("object"==o||"function"==o)}export function isFunction(t){if(!isObject(t))return!1;let o=Object.prototype.toString.call(t);return"[object Function]"==o||"[object AsyncFunction]"==o||"[object GeneratorFunction]"==o||"[object Proxy]"==o}export function empty(){}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.2.1",
3
+ "version": "3.4.0",
4
4
  "description": "core",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "build": "swc src -d lib -C module.type=nodenext -C jsc.target=esnext -C jsc.loose=true -C jsc.minify.mangle=true -C jsc.minify.compress=true -C minify=true -D",
8
+ "build": "swc src -d lib -D",
9
9
  "prebuild": "rm -rf ./lib && tsc"
10
10
  },
11
11
  "keywords": [],
@@ -19,8 +19,8 @@
19
19
  "@swc/helpers": "0.5.3",
20
20
  "@teamsupercell/typings-for-css-modules-loader": "2.5.2",
21
21
  "add-asset-html-webpack-plugin": "6.0.0",
22
- "core-js": "3.33.1",
23
- "core-js-compat": "3.33.1",
22
+ "core-js": "3.33.2",
23
+ "core-js-compat": "3.33.2",
24
24
  "cross-env": "7.0.3",
25
25
  "css-loader": "6.8.1",
26
26
  "css-minimizer-webpack-plugin": "5.0.1",
@@ -30,6 +30,8 @@
30
30
  "less-loader": "11.1.3",
31
31
  "mini-css-extract-plugin": "2.7.6",
32
32
  "mini-svg-data-uri": "1.4.4",
33
+ "sass": "1.69.5",
34
+ "sass-loader": "13.3.2",
33
35
  "style-loader": "3.3.3",
34
36
  "style-resources-loader": "1.5.0",
35
37
  "swc-loader": "0.2.3",
@@ -1,6 +1,7 @@
1
1
  import { Options as AssetHtmlOptions } from 'add-asset-html-webpack-plugin';
2
2
  import { Options as HtmlWebpackPluginOptions } from 'html-webpack-plugin';
3
3
  import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
4
+ import WebpackBar from 'webpackbar';
4
5
  import type { Options as MDXOptions } from '@mdx-js/loader';
5
6
  import type { JsMinifyOptions, Config as SwcConfig } from '@swc/core';
6
7
  import type { CssNanoOptionsExtended } from 'css-minimizer-webpack-plugin';
@@ -13,8 +14,7 @@ import type {
13
14
  ProxyConfigMap,
14
15
  WebpackConfiguration,
15
16
  } from 'webpack-dev-server';
16
- import type { State } from 'webpackbar';
17
-
17
+ export type WebpackBarOptions = ConstructorParameters<typeof WebpackBar>[0];
18
18
  export type MinifierType = 'swc' | 'terser';
19
19
  export declare type AppType = 'mobile' | 'site' | 'backstage' | 'micro' | 'library';
20
20
  export declare type Framework = 'react' | 'solid';
@@ -30,11 +30,10 @@ export type HtmlWebpackOption = HtmlWebpackPluginOptions & {
30
30
  export type CssMinify = 'swc' | 'cssnano';
31
31
 
32
32
  export type RulesInclude = {
33
- less?: string[];
34
33
  css?: string[];
35
34
  js?: string[];
36
35
  media?: string[];
37
- fonts?: string[];
36
+ font?: string[];
38
37
  wasm?: string[];
39
38
  };
40
39
  export interface Theme {
@@ -261,7 +260,7 @@ export declare type ConfigType<T extends 'tsc' | 'swc' = 'swc'> = {
261
260
  generate?: 'ssr' | 'dom';
262
261
  hydratable?: boolean;
263
262
  };
264
- bar?: Partial<State> | false;
263
+ bar?: Partial<WebpackBarOptions> | false;
265
264
  /** 虚拟模块
266
265
  * @example
267
266
  * const conf = {