@moneko/core 3.34.7 → 3.35.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.
@@ -1,2 +1,2 @@
1
- import{spawn as o}from"node:child_process";import{argv as e}from"node:process";import{ink as l,print as t}from"@moneko/utils";export default function s(){let s=l("githooks","cyan");t(`${s}: ${l("Runing...","yellow")}`,!0);let i="node_modules/.husky",n=e.slice(3).map(o=>{let e=o.split("=");return`echo ${e[1]} > ${i}/${e[0]}`}).join(" && ");o(`git init && husky ${i} && ${n}`,{stdio:[null],shell:!0}).on("close",function(o){let e=0!==o;t(`${s}: ${l(`✨ ${e?"Error":"Successfully"}!
1
+ import{spawn as o}from"node:child_process";import{argv as e}from"node:process";import{ink as i,print as l}from"@moneko/utils";export default function s(){let s=i("githooks","cyan");l(`${s}: ${i("Runing...","yellow")}`,!0);let t="node_modules/.husky",n=e.slice(3).map(o=>{let e=o.split("=");return`echo ${e[1]} > ${t}/${e[0]}`}).join(" && ");o(`git init && git config core.ignorecase false && husky ${t} && ${n}`,{stdio:[null],shell:!0}).on("close",function(o){let e=0!==o;l(`${s}: ${i(`✨ ${e?"Error":"Successfully"}!
2
2
  `,e?"red":"green")}`,!0),process.exit(o)})}
@@ -1,10 +1,11 @@
1
+ #!/usr/bin/env node
1
2
  import { spawnSync, type SpawnSyncReturns } from 'node:child_process';
2
- import { readFile } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
4
  import { argv } from 'node:process';
5
5
  import { ESLint } from '@moneko/eslint';
6
6
  import { stylelint as Stylelint } from '@moneko/stylelint';
7
- declare function parseArgs<T>(args: string[]): T;
7
+ import { loadFile } from '@moneko/utils';
8
+ import parseArgs from '../commom/parse-args.mjs';
8
9
  type Args = {
9
10
  fix?: boolean;
10
11
  cache?: boolean;
@@ -24,6 +25,6 @@ declare const vueRegExp: RegExp;
24
25
  declare const styleRegExp: RegExp;
25
26
  declare const child: SpawnSyncReturns<Buffer>;
26
27
  declare const lintFiles: string[];
27
- export declare async function eslint();
28
+ declare async function eslint();
28
29
  declare const styleFiles: string[];
29
- export declare async function stylelint();
30
+ declare async function stylelint();
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{spawnSync as t}from"node:child_process";import{join as e}from"node:path";import{argv as o}from"node:process";import{ESLint as i}from"@moneko/eslint";import{stylelint as n}from"@moneko/stylelint";import{loadFile as r}from"@moneko/utils";import s from"../commom/parse-args.mjs";let l=s(o.slice(2)),c=l.fix,a=l.cache||!0,m=e(process.cwd(),"node_modules/.cache"),d={ci:["diff","--name-only","HEAD^","HEAD"],commit:["diff","--cached","--name-only","--diff-filter=ACMR"]},f=/.*(?<!\.d)\.(j|t|mj|mt|cj|ct)sx?$/,p=/.*(?<!\.d)\.vue$/,u=/.*(?<!\.d)\.(c|sc|sa|le)ss$/,h=t("git",d[l.mode||"ci"]||d.ci).stdout.toString().trim().split("\n");async function y(){console.log("ESLint runing...");try{console.time("ESLint");let t=h.filter(t=>f.test(t)||p.test(t));if(0===t.length){console.timeEnd("ESLint");return}let e=new i({cache:a,cacheLocation:`${m}/.eslintcache`,fix:c}),o=await e.lintFiles(t),n=await e.loadFormatter("stylish"),r=await n.format(o);c&&await i.outputFixes(o),r&&process.stdout.write(r);let s=o.some(t=>t.errorCount>0);console.timeEnd("ESLint"),s&&process.exit(1)}catch(t){console.error(t)}}let w=h.filter(t=>u.test(t)||p.test(t));async function g(){if(console.log("Stylelint runing..."),console.time("Stylelint"),0===w.length){console.timeEnd("Stylelint");return}let t=await Promise.all(w.map(async t=>{let e=await r(t);return await n.lint({codeFilename:t,code:e,cache:a,cacheLocation:`${m}/.stylelintcache`,fix:c,formatter:"string"}).catch(console.log)})),e=!1;t.forEach(t=>{t&&(t.report&&process.stdout.write(t.report),t.errored&&(e=!!t.errored))}),console.timeEnd("Stylelint"),e&&process.exit(1)}await Promise.all([y(),g()]);
package/lib/build.mjs CHANGED
@@ -1 +1,2 @@
1
- import{relative as o}from"node:path";import{analyzeBundleSize as r,completedInfo as m,ink as t,println as e,progressBar as i}from"@moneko/utils";import s from"webpack";import{merge as n}from"webpack-merge";import a from"./build/common.mjs";import p from"./commom/paths.mjs";import l from"./plugin/done.mjs";import{empty as u}from"./utils/index.mjs";import c from"./utils/seo.mjs";import{CONFIG as g}from"./config.mjs";import f from"./module.config.mjs";let d=n(a,{module:f(!1),plugins:[]});if(g.done&&d.plugins.push(new l({done:g.done})),g.bar){let o=g.bar,r=o.name||"Build";d.plugins.push(new s.ProgressPlugin({handler(m,t,...e){let s=e.length?`[${t}] ${e.join(" ")}`:"";o.quiet?process.stdout.write(s):(i(m||0,1,{msg:s,name:r,barColor:o.barColor,nameColor:o.nameColor,barBgColor:o.barBgColor,msgColor:o.msgColor}),1===m&&process.stdout.write("\r\x1b[2K"))}}))}let h=s(d);async function w(){let i=await new Promise((o,r)=>{h.run((m,t)=>{m&&r(m),t?o(t):r(Error("编译过程中没有生成统计信息"))})});(i.hasErrors()||i.hasWarnings())&&function(o){let{warnings:r,errors:m}=o.compilation;r.forEach(o=>{e(t(o.message,"178"))}),m.forEach(o=>{e(t(o.message,"red"))})}(i),await new Promise(s=>{i.compilation.compiler.cache.shutdown(n=>{n&&e(t(n.toString(),"red")),r(i.compilation.outputOptions.path,["\\.js$"]),m(~~((i.endTime-i.startTime)/10)/100,o(p.programPath,i.compilation.outputOptions.path)),s()})}),g.seo&&c()}process.on("exit",u),await w();
1
+ import{relative as o}from"node:path";import{analyzeBundleSize as r,completedInfo as m,ink as t,println as e,progressBar as i}from"@moneko/utils";import s from"webpack";import{merge as n}from"webpack-merge";import a from"./build/common.mjs";import p from"./commom/paths.mjs";import l from"./plugin/done.mjs";import{empty as u}from"./utils/index.mjs";import c from"./utils/seo.mjs";import{CONFIG as g}from"./config.mjs";import f from"./module.config.mjs";let d=n(a,{module:f(!1),plugins:[]});if(g.done&&d.plugins.push(new l({done:g.done})),g.bar){let o=g.bar,r=o.name||"Build";d.plugins.push(new s.ProgressPlugin({handler(m,t,...e){let s=e.length?`[${t}] ${e.join(" ")}`:"";o.quiet?process.stdout.write(`${s}
2
+ `):(i(m||0,1,{msg:s,name:r,barColor:o.barColor,nameColor:o.nameColor,barBgColor:o.barBgColor,msgColor:o.msgColor}),1===m&&process.stdout.write("\r\x1b[2K"))}}))}let h=s(d);async function w(){let i=await new Promise((o,r)=>{h.run((m,t)=>{m&&r(m),t?o(t):r(Error("编译过程中没有生成统计信息"))})});(i.hasErrors()||i.hasWarnings())&&function(o){let{warnings:r,errors:m}=o.compilation;r.forEach(o=>{e(t(o.message,"178"))}),m.forEach(o=>{e(t(o.message,"red"))})}(i),await new Promise(s=>{i.compilation.compiler.cache.shutdown(n=>{n&&e(t(n.toString(),"red")),r(i.compilation.outputOptions.path,["\\.js$"]),m(~~((i.endTime-i.startTime)/10)/100,o(p.programPath,i.compilation.outputOptions.path)),s()})}),g.seo&&c()}process.on("exit",u),await w();
@@ -0,0 +1,2 @@
1
+ declare function isCIEnvironment(): boolean;
2
+ export default isCIEnvironment;
@@ -0,0 +1 @@
1
+ export default function(){if("true"===process.env.CI||"1"===process.env.CI)return!0;let I=["CI","CONTINUOUS_INTEGRATION","BUILD_NUMBER","RUN_ID","GITHUB_ACTIONS","GITLAB_CI","TRAVIS","CIRCLECI","JENKINS_URL","TF_BUILD","APPVEYOR","BITBUCKET_BUILD_NUMBER","CODEBUILD_BUILD_ID","TEAMCITY_VERSION","BAMBOO_BUILDKEY","BUILDKITE","DRONE","SEMAPHORE","NETLIFY","VERCEL","NOW_BUILDER","HEROKU_TEST_RUN_ID","CODEBUILD_BUILD_ID","HUDSON_URL","TASK_ID","GO_PIPELINE_NAME","CI_NAME","CI_WORKER_ID"].some(I=>void 0!==process.env[I]&&""!==process.env[I]),e="true"===process.env.NETLIFY||"true"===process.env.VERCEL||"production"===process.env.NODE_ENV&&!!process.env.HEROKU_APP_ID||"codeship"===process.env.CI_NAME||"true"===process.env.BUDDY||"true"===process.env.SCRUTINIZER||void 0!==process.env.CF_BUILD_ID;return I||e}
@@ -1,2 +1,2 @@
1
- declare function parseArgs(args: string[]);
1
+ declare function parseArgs<T>(args: string[]): T;
2
2
  export default parseArgs;
package/lib/config.d.mts CHANGED
@@ -8,7 +8,7 @@ import jsxDomExpressions from './options/jsx-dom-expressions.mjs';
8
8
  import splitChunk from './options/split-chunk.mjs';
9
9
  import { isFunction, node_modules, resolveProgram } from './utils/index.mjs';
10
10
  import type { ConfigType } from './index.mjs';
11
- import { APPTYPE, FRAMEWORK, frameworkVersion, isDev, isLibrary, isMobile, isReact, jsxImportSource, mainDirectory, NODE_ENV, PACKAGENAME } from './process-env.mjs';
11
+ import { APPTYPE, FRAMEWORK, frameworkVersion, isCI, isDev, isLibrary, isMobile, isReact, jsxImportSource, mainDirectory, NODE_ENV, PACKAGENAME } from './process-env.mjs';
12
12
  declare const includeModule: readonly [string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string];
13
13
  export declare function getConfig(path: string): Promise<ConfigType>;
14
14
  type EnvType = {
package/lib/config.mjs CHANGED
@@ -1 +1 @@
1
- import{relative as e}from"node:path";import{fileExists as o}from"@moneko/utils";import{merge as t}from"webpack-merge";import r from"./commom/paths.mjs";import s from"./commom/require.mjs";import n from"./commom/setup-env.mjs";import i from"./options/jsx-dom-expressions.mjs";import a from"./options/split-chunk.mjs";import{isFunction as l,node_modules as m,resolveProgram as p}from"./utils/index.mjs";import{APPTYPE as c,FRAMEWORK as u,frameworkVersion as d,isDev as f,isLibrary as g,isMobile as h,isReact as x,jsxImportSource as j,mainDirectory as v,NODE_ENV as P,PACKAGENAME as C}from"./process-env.mjs";let b=["@app","@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 function getConfig(e){return delete s.cache[e],new Promise(t=>{if(o(e)){let o=s(e).default;return t(l(o)?o(process):o)}return t({})})}let k=await Promise.all([n(P,c,u,[]),getConfig(r.configPath),getConfig(r.customConfigPath)]),w=k[0],y=k[1],O=k[2],M={strict:!1,devtool:f?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:w,basename:"/",publicPath:"/",rem:{designSize:h?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":p(v)},x&&d<18?{"react/package.json":m("react/package.json"),"react/jsx-runtime":m("react/jsx-runtime.js"),"react/jsx-dev-runtime":m("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3},htmlPluginOption:{title:C.toLocaleUpperCase(),favicon:e(r.programPath,`${r.corePath}/options/favicon.ico`)},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:a,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:b,js:b,media:b,font:b,wasm:[]},mdx:{jsx:!1,development:f,jsxImportSource:j,providerImportSource:`@moneko/${u}/mdx`},jsxDomExpressions:i,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69"},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==u,bundleId:"com.moneko.bid",bundles:[],stylelint:{},eslint:{lintDirtyModulesOnly:!1}};g&&(M.alias=Object.assign(M.alias,{"@pkg":r.componentsPath,[C]:r.componentsPath}));let I=M;(!1===(I=t(I,y,O)).devtool||!1===I.sourceMap)&&(I.sourceMap=!1,I.devtool=!1),I.fixBrowserRouter&&I.htmlPluginOption&&(I.htmlPluginOption.tags||(I.htmlPluginOption.tags=[]),I.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=I;export const PUBLICPATH=CONFIG.publicPath;
1
+ import{relative as e}from"node:path";import{fileExists as o}from"@moneko/utils";import{merge as t}from"webpack-merge";import r from"./commom/paths.mjs";import s from"./commom/require.mjs";import n from"./commom/setup-env.mjs";import i from"./options/jsx-dom-expressions.mjs";import a from"./options/split-chunk.mjs";import{isFunction as l,node_modules as m,resolveProgram as p}from"./utils/index.mjs";import{APPTYPE as c,FRAMEWORK as u,frameworkVersion as d,isCI as f,isDev as g,isLibrary as h,isMobile as x,isReact as j,jsxImportSource as v,mainDirectory as P,NODE_ENV as C,PACKAGENAME as b}from"./process-env.mjs";let k=["@app","@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 function getConfig(e){return delete s.cache[e],new Promise(t=>{if(o(e)){let o=s(e).default;return t(l(o)?o(process):o)}return t({})})}let w=await Promise.all([n(C,c,u,[]),getConfig(r.configPath),getConfig(r.customConfigPath)]),y=w[0],O=w[1],M=w[2],I={strict:!1,devtool:g?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:y,basename:"/",publicPath:"/",rem:{designSize:x?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":p(P)},j&&d<18?{"react/package.json":m("react/package.json"),"react/jsx-runtime":m("react/jsx-runtime.js"),"react/jsx-dev-runtime":m("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3},htmlPluginOption:{title:b.toLocaleUpperCase(),favicon:e(r.programPath,`${r.corePath}/options/favicon.ico`)},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:a,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:k,js:k,media:k,font:k,wasm:[]},mdx:{jsx:!1,development:g,jsxImportSource:v,providerImportSource:`@moneko/${u}/mdx`},jsxDomExpressions:i,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69",quiet:f},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==u,bundleId:"com.moneko.bid",bundles:[],stylelint:{},eslint:{lintDirtyModulesOnly:!1}};h&&(I.alias=Object.assign(I.alias,{"@pkg":r.componentsPath,[b]:r.componentsPath}));let z=I;(!1===(z=t(z,O,M)).devtool||!1===z.sourceMap)&&(z.sourceMap=!1,z.devtool=!1),z.fixBrowserRouter&&z.htmlPluginOption&&(z.htmlPluginOption.tags||(z.htmlPluginOption.tags=[]),z.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=z;export const PUBLICPATH=CONFIG.publicPath;
package/lib/dev.mjs CHANGED
@@ -1 +1,2 @@
1
- import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{extname as r,relative as s,sep as i}from"node:path";import{ink as n,loadFile as l,print as a,println as m,progressBar as p}from"@moneko/utils";import c from"fastify";import d from"webpack";import u from"webpack-hot-middleware";import{merge as h}from"webpack-merge";import{diffObject as f}from"./commom/diff-object.mjs";import g from"./commom/mime.mjs";import y,{config_files as w}from"./commom/paths.mjs";import $ from"./commom/sigint-exit.mjs";import{devLog as x,PORT as v}from"./dev/config.mjs";import C from"./dev/mock.mjs";import{setupProxy as j}from"./dev/proxy.mjs";import P from"./options/reslove.mjs";import S from"./plugin/eslint.mjs";import k from"./plugin/stylelint.mjs";import{empty as b}from"./utils/index.mjs";import{commonConfig as A}from"./common.mjs";import{CONFIG as T,getConfig as H,PUBLICPATH as O}from"./config.mjs";import{outputFileSystem as E}from"./file-system.mjs";import I from"./module.config.mjs";import{isLibrary as R,isReact as _,refresh as U}from"./process-env.mjs";let q=`${O.endsWith("/")?"":"/"}__hmr__`,z=new URLSearchParams({name:"client",path:q,dynamicPublicPath:!0,timeout:2e3,reload:!U,quiet:!0,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),F=h(A,{watchOptions:{ignored:/node_modules\/(?!(@app|@moneko)).+/},entry:{main:[`${P.hotMiddlewareClient}?${z}`]},module:I(!1),plugins:[new d.HotModuleReplacementPlugin,new d.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app|@moneko)).+/,/\.d\.ts$/]})]});if(F.plugins||(F.plugins=[]),_){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;F.plugins.push(new e({overlay:!1}))}function M(e){let t=e.join(","),o=[s(y.programPath,`${T.alias["@"]}/**/*.{${t}}`).replace(/\\/g,"/")];return R&&o.push(s(y.programPath,`${T.alias["@pkg"]}/**/*.{${t}}`).replace(/\\/g,"/")),o}if(T.eslint&&F.plugins.push(new S({fix:!0,cache:!0,cacheLocation:`${y.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",files:M(["js","jsx","ts","tsx","json","html","vue"]),...T.eslint})),T.stylelint&&F.plugins.push(new k({fix:!0,cache:!0,cacheLocation:`${y.lintCachePath}/.stylelintcache`,files:M(["css","scss","sass","less","ts","tsx","js","jsx"]),...T.stylelint})),T.bar){let e=T.bar,t=e.name||"Build";F.plugins.push(new d.ProgressPlugin({handler(o,r,...s){let i=s.length?`[${r}] ${s.join(" ")}`:"";e.quiet?process.stdout.write(i):(p(o||0,1,{msg:i,name:t,barColor:e.barColor,nameColor:e.nameColor,barBgColor:e.barBgColor,msgColor:e.msgColor}),1===o&&process.stdout.write("\r\x1b[2K"))}}))}let B=d(F);B.outputFileSystem=E;let L=B.watch(B.options.watchOptions,x);B.hooks.done.tap("client-log",e=>{x(null,e)});let N={};if(T.devServer.https){let[e,t]=await Promise.all([l(T.devServer.https.key),l(T.devServer.https.cert)]);e||(m(n(`法加载私钥。请检查路径和文件是否存在,并确保路径正确:${T.devServer.https.key}`,"red")),process.exit(1)),t||(m(n(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${T.devServer.https.cert}`,"red")),process.exit(1)),N.http2=!0,N.https={key:e,cert:t}}let G=u(B,{log:!1,path:q,heartbeat:2e3}),W=c({logger:!1,...N});C(W,{directory:y.mockPath}),j(W,T.proxy);let D={"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization","Access-Control-Allow-Methods":"GET, POST, OPTIONS, DELETE, PATCH, PUT","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0",...T.devServer.headers||{}};function K(e,t,o){t.headers(D),e.headers.origin&&t.header("Access-Control-Allow-Origin",e.headers.origin);let s=B.outputFileSystem,i=e.headers["accept-encoding"],n=i?.includes("gzip"),l=s.existsSync?.(`${o}.gz`);n&&l&&t.header("content-encoding","gzip");let a=s.createReadStream?.(n&&l?`${o}.gz`:o,{autoClose:!0});a?.on("error",e=>{if(a.destroy(),!t.sent)return t.code(404).type("text/html").send(`File not found: ${e.message}`)});let m=g[r(o)];return m&&t.header("content-type",m),t.send(a)}function X(){process.exit(0)}W.get(`/${q}`.replace("//","/"),async(e,t)=>{if("text/event-stream"===e.headers.accept){e.raw.url=q,G(e.raw,t.raw,()=>{t.raw.writableEnded&&(t.sent=!0)});return}}),W.addHook("onRequest",(e,t,o)=>{let r=decodeURIComponent(`${B.options.output.path}${i}${"/"===e.url?"index.html":e.url}`);return B.outputFileSystem?.existsSync?.(r)?K(e,t,r):o()}),W.setNotFoundHandler((e,t)=>K(e,t,`${B.options.output.path}${i}index.html`)),W.addHook("onClose",()=>{L.close(b),W.server.close(b)}),W.listen({port:v});let J=await Promise.all(w.map(H)),Q=h(J[0]||{},J[1]||{});w.forEach(function(t){o(t,async function(){let[o,r]=await Promise.all(w.map(H)),s=h(o||{},r||{}),i=f(Q,s);1===Object.keys(i).length&&"proxy"in i?(a(n(`代理更新中...`,"yellow"),!0),await j(W,s.proxy),a(n(`代理更新完成...`,"green"),!0),T.proxy=s.proxy,Q.proxy=s.proxy,Q=s):(Q=s,m(n(`检测到工程配置${n(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e(V?`netstat -ano | findstr :${v}`:`lsof -i :${v} -t`,(e,t)=>{if(e){m(n(`查找端口 ${v} 时发生错误: ${e.message}`,"red")),m(n("请尝试手动重启程序","yellow"));return}let o=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),r=V?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!r){m(n(`未找到占用端口 ${v} 的进程, 请尝试手动重启程序`,"yellow"));return}try{process.kill(Number(r),"SIGHUP")}catch(e){m(n(`终止进程 ${r} 时发生错误: ${e.message}`,"red"))}}))})});let V="win32"===process.platform;process.on("SIGHUP",function(){W.close(b),function(){let e=t(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",X)}()}),process.on("exit",function(){W.close(b)}),$(X);
1
+ import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{extname as r,relative as s,sep as i}from"node:path";import{ink as n,loadFile as l,print as a,println as m,progressBar as p}from"@moneko/utils";import c from"fastify";import d from"webpack";import u from"webpack-hot-middleware";import{merge as h}from"webpack-merge";import{diffObject as f}from"./commom/diff-object.mjs";import g from"./commom/mime.mjs";import y,{config_files as w}from"./commom/paths.mjs";import $ from"./commom/sigint-exit.mjs";import{devLog as x,PORT as v}from"./dev/config.mjs";import C from"./dev/mock.mjs";import{setupProxy as j}from"./dev/proxy.mjs";import P from"./options/reslove.mjs";import S from"./plugin/eslint.mjs";import k from"./plugin/stylelint.mjs";import{empty as b}from"./utils/index.mjs";import{commonConfig as A}from"./common.mjs";import{CONFIG as T,getConfig as H,PUBLICPATH as O}from"./config.mjs";import{outputFileSystem as E}from"./file-system.mjs";import I from"./module.config.mjs";import{isLibrary as R,isReact as _,refresh as U}from"./process-env.mjs";let q=`${O.endsWith("/")?"":"/"}__hmr__`,z=new URLSearchParams({name:"client",path:q,dynamicPublicPath:!0,timeout:2e3,reload:!U,quiet:!0,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),F=h(A,{watchOptions:{ignored:/node_modules\/(?!(@app|@moneko)).+/},entry:{main:[`${P.hotMiddlewareClient}?${z}`]},module:I(!1),plugins:[new d.HotModuleReplacementPlugin,new d.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app|@moneko)).+/,/\.d\.ts$/]})]});if(F.plugins||(F.plugins=[]),_){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;F.plugins.push(new e({overlay:!1}))}function M(e){let t=e.join(","),o=[s(y.programPath,`${T.alias["@"]}/**/*.{${t}}`).replace(/\\/g,"/")];return R&&o.push(s(y.programPath,`${T.alias["@pkg"]}/**/*.{${t}}`).replace(/\\/g,"/")),o}if(T.eslint&&F.plugins.push(new S({fix:!0,cache:!0,cacheLocation:`${y.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",files:M(["js","jsx","ts","tsx","json","html","vue"]),...T.eslint})),T.stylelint&&F.plugins.push(new k({fix:!0,cache:!0,cacheLocation:`${y.lintCachePath}/.stylelintcache`,files:M(["css","scss","sass","less","ts","tsx","js","jsx"]),...T.stylelint})),T.bar){let e=T.bar,t=e.name||"Build";F.plugins.push(new d.ProgressPlugin({handler(o,r,...s){let i=s.length?`[${r}] ${s.join(" ")}`:"";e.quiet?process.stdout.write(`${i}
2
+ `):(p(o||0,1,{msg:i,name:t,barColor:e.barColor,nameColor:e.nameColor,barBgColor:e.barBgColor,msgColor:e.msgColor}),1===o&&process.stdout.write("\r\x1b[2K"))}}))}let B=d(F);B.outputFileSystem=E;let L=B.watch(B.options.watchOptions,x);B.hooks.done.tap("client-log",e=>{x(null,e)});let N={};if(T.devServer.https){let[e,t]=await Promise.all([l(T.devServer.https.key),l(T.devServer.https.cert)]);e||(m(n(`法加载私钥。请检查路径和文件是否存在,并确保路径正确:${T.devServer.https.key}`,"red")),process.exit(1)),t||(m(n(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${T.devServer.https.cert}`,"red")),process.exit(1)),N.http2=!0,N.https={key:e,cert:t}}let G=u(B,{log:!1,path:q,heartbeat:2e3}),W=c({logger:!1,...N});C(W,{directory:y.mockPath}),j(W,T.proxy);let D={"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization","Access-Control-Allow-Methods":"GET, POST, OPTIONS, DELETE, PATCH, PUT","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0",...T.devServer.headers||{}};function K(e,t,o){t.headers(D),e.headers.origin&&t.header("Access-Control-Allow-Origin",e.headers.origin);let s=B.outputFileSystem,i=e.headers["accept-encoding"],n=i?.includes("gzip"),l=s.existsSync?.(`${o}.gz`);n&&l&&t.header("content-encoding","gzip");let a=s.createReadStream?.(n&&l?`${o}.gz`:o,{autoClose:!0});a?.on("error",e=>{if(a.destroy(),!t.sent)return t.code(404).type("text/html").send(`File not found: ${e.message}`)});let m=g[r(o)];return m&&t.header("content-type",m),t.send(a)}function X(){process.exit(0)}W.get(`/${q}`.replace("//","/"),async(e,t)=>{if("text/event-stream"===e.headers.accept){e.raw.url=q,G(e.raw,t.raw,()=>{t.raw.writableEnded&&(t.sent=!0)});return}}),W.addHook("onRequest",(e,t,o)=>{let r=decodeURIComponent(`${B.options.output.path}${i}${"/"===e.url?"index.html":e.url}`);return B.outputFileSystem?.existsSync?.(r)?K(e,t,r):o()}),W.setNotFoundHandler((e,t)=>K(e,t,`${B.options.output.path}${i}index.html`)),W.addHook("onClose",()=>{L.close(b),W.server.close(b)}),W.listen({port:v});let J=await Promise.all(w.map(H)),Q=h(J[0]||{},J[1]||{});w.forEach(function(t){o(t,async function(){let[o,r]=await Promise.all(w.map(H)),s=h(o||{},r||{}),i=f(Q,s);1===Object.keys(i).length&&"proxy"in i?(a(n(`代理更新中...`,"yellow"),!0),await j(W,s.proxy),a(n(`代理更新完成...`,"green"),!0),T.proxy=s.proxy,Q.proxy=s.proxy,Q=s):(Q=s,m(n(`检测到工程配置${n(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e(V?`netstat -ano | findstr :${v}`:`lsof -i :${v} -t`,(e,t)=>{if(e){m(n(`查找端口 ${v} 时发生错误: ${e.message}`,"red")),m(n("请尝试手动重启程序","yellow"));return}let o=t.trim().replace(/\r\n/g,"\n").split("\n").filter(Boolean),r=V?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!r){m(n(`未找到占用端口 ${v} 的进程, 请尝试手动重启程序`,"yellow"));return}try{process.kill(Number(r),"SIGHUP")}catch(e){m(n(`终止进程 ${r} 时发生错误: ${e.message}`,"red"))}}))})});let V="win32"===process.platform;process.on("SIGHUP",function(){W.close(b),function(){let e=t(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",X)}()}),process.on("exit",function(){W.close(b)}),$(X);
package/lib/index.d.mts CHANGED
@@ -13,6 +13,6 @@ export { type OptimizationSplitChunksOptions, default as splitChunk } from './op
13
13
  export type { HtmlMeta, HtmlPluginOption } from './plugin/html-plugin.mjs';
14
14
  export type { OverrideResolverOption } from './plugin/override-resolve.mjs';
15
15
  export type { VirtualModulePluginOption } from './plugin/virtual-module.mjs';
16
- export { APPTYPE, coreName, FRAMEWORK, isDev, isLibrary, isMicro, mainDirectory, packageJson, PACKAGENAME } from './process-env.mjs';
16
+ export { APPTYPE, coreName, FRAMEWORK, isCI, isDev, isLibrary, isMicro, mainDirectory, packageJson, PACKAGENAME } from './process-env.mjs';
17
17
  export { resolveProgram, toCamelCase } from './utils/index.mjs';
18
18
  export type { MdxOptions } from '@moneko/mdx';
package/lib/index.mjs CHANGED
@@ -1 +1 @@
1
- export{default as hasPkg}from"./commom/has-pkg.mjs";export{getIPv4,getPort}from"./commom/net.mjs";export{CUSTOMCONFIG,default as paths,routeDir,yarnArgv}from"./commom/paths.mjs";export{default as require}from"./commom/require.mjs";export{default as Rule}from"./commom/rule.mjs";export{yApiMock,yApiSchemaMock}from"./dev/mock.mjs";export{default as jsxDomExpressions}from"./options/jsx-dom-expressions.mjs";export{default as splitChunk}from"./options/split-chunk.mjs";export{APPTYPE,coreName,FRAMEWORK,isDev,isLibrary,isMicro,mainDirectory,packageJson,PACKAGENAME}from"./process-env.mjs";export{resolveProgram,toCamelCase}from"./utils/index.mjs";
1
+ export{default as hasPkg}from"./commom/has-pkg.mjs";export{getIPv4,getPort}from"./commom/net.mjs";export{CUSTOMCONFIG,default as paths,routeDir,yarnArgv}from"./commom/paths.mjs";export{default as require}from"./commom/require.mjs";export{default as Rule}from"./commom/rule.mjs";export{yApiMock,yApiSchemaMock}from"./dev/mock.mjs";export{default as jsxDomExpressions}from"./options/jsx-dom-expressions.mjs";export{default as splitChunk}from"./options/split-chunk.mjs";export{APPTYPE,coreName,FRAMEWORK,isCI,isDev,isLibrary,isMicro,mainDirectory,packageJson,PACKAGENAME}from"./process-env.mjs";export{resolveProgram,toCamelCase}from"./utils/index.mjs";
@@ -1,5 +1,6 @@
1
1
  import { platform } from 'node:process';
2
2
  import hasPkg from './commom/has-pkg.mjs';
3
+ import isCIEnvironment from './commom/is-ci-environment.mjs';
3
4
  import require from './commom/require.mjs';
4
5
  import type { AppType, Framework } from './index.mjs';
5
6
  export declare const IS_WINDOW: boolean;
@@ -22,3 +23,4 @@ export declare const PACKAGENAME: string;
22
23
  export declare const coreName: string;
23
24
  export declare const isDev: boolean;
24
25
  export declare const refresh: boolean;
26
+ export declare const isCI: boolean;
@@ -1 +1 @@
1
- import{platform as o}from"node:process";import e from"./commom/has-pkg.mjs";import r from"./commom/require.mjs";export const IS_WINDOW="win32"===o;export const APPTYPE=process.env.APPTYPE;export const FRAMEWORK=process.env.FRAMEWORK;export const NODE_ENV=process.env.NODE_ENV;export const isLibrary="library"===APPTYPE;export const isMicro="micro"===APPTYPE;export const isMobile="mobile"===APPTYPE;export const isReact="react"===FRAMEWORK;export const isSolid="solid"===FRAMEWORK;export const SSR="true"===process.env.SSR;export const mainDirectory=isLibrary?"site":"src";export const jsxImportSource={react:"react",solid:"solid-js/h"}[FRAMEWORK];export const framework={react:"react",solid:"solid-js"}[FRAMEWORK];export const frameworkVersionStr=r(`${framework}/package.json`).version;export const frameworkVersion=parseFloat(frameworkVersionStr);export const packageJson=r(`${process.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")));
1
+ import{platform as o}from"node:process";import r from"./commom/has-pkg.mjs";import e from"./commom/is-ci-environment.mjs";import s from"./commom/require.mjs";export const IS_WINDOW="win32"===o;export const APPTYPE=process.env.APPTYPE;export const FRAMEWORK=process.env.FRAMEWORK;export const NODE_ENV=process.env.NODE_ENV;export const isLibrary="library"===APPTYPE;export const isMicro="micro"===APPTYPE;export const isMobile="mobile"===APPTYPE;export const isReact="react"===FRAMEWORK;export const isSolid="solid"===FRAMEWORK;export const SSR="true"===process.env.SSR;export const mainDirectory=isLibrary?"site":"src";export const jsxImportSource={react:"react",solid:"solid-js/h"}[FRAMEWORK];export const framework={react:"react",solid:"solid-js"}[FRAMEWORK];export const frameworkVersionStr=s(`${framework}/package.json`).version;export const frameworkVersion=parseFloat(frameworkVersionStr);export const packageJson=s(`${process.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&&(r("solid-refresh")||r("react-refresh")));export const isCI=e();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.34.7",
3
+ "version": "3.35.0",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",
@@ -9,7 +9,8 @@
9
9
  "prepublishOnly": "npm run build"
10
10
  },
11
11
  "bin": {
12
- "mo": "./lib/bin/index.mjs"
12
+ "mo": "./lib/bin/index.mjs",
13
+ "pure-lint": "./lib/bin/pure-lint.mjs"
13
14
  },
14
15
  "keywords": [],
15
16
  "author": "moneko",
@@ -1 +0,0 @@
1
- import{spawnSync as t}from"node:child_process";import{readFile as e}from"node:fs/promises";import{join as o}from"node:path";import{argv as i}from"node:process";import{ESLint as r}from"@moneko/eslint";import{stylelint as s}from"@moneko/stylelint";let n=Object.fromEntries(i.slice(2).map(function(t){let e=t.split("="),o=e[1];return void 0===o||"true"===o?o=!0:"false"===o?o=!1:/-?\d+(\.\d+)?([eE][+-]?\d+)?/.test(o)&&(o=parseFloat(o)),[e[0].replace(/^--/,""),o]})),c=n.fix,l=n.cache||!0,a=o(process.cwd(),"node_modules/.cache"),m={ci:["diff","--name-only","HEAD^","HEAD"],commit:["diff","--cached","--name-only","--diff-filter=ACMR"]},d=/.*(?<!\.d)\.(j|t|mj|mt|cj|ct)sx?$/,f=/.*(?<!\.d)\.vue$/,p=/.*(?<!\.d)\.(c|sc|sa|le)ss$/,u=t("git",m[n.mode||"ci"]||m.ci).stdout.toString().trim().split("\n");export async function eslint(){console.log("ESLint runing...");try{console.time("ESLint");let t=new r({cache:l,cacheLocation:`${a}/.eslintcache`,fix:c}),e=u.filter(t=>d.test(t)||f.test(t)),o=await t.lintFiles(e),i=await t.loadFormatter("stylish"),s=await i.format(o);c&&await r.outputFixes(o),s&&process.stdout.write(s);let n=o.some(t=>t.errorCount>0);console.timeEnd("ESLint"),n&&process.exit(1)}catch(t){console.error(t)}}let y=u.filter(t=>p.test(t)||f.test(t));export async function stylelint(){console.log("Stylelint runing..."),console.time("Stylelint");let t=await Promise.all(y.map(async t=>{let o=await e(t,{encoding:"utf-8"});return await s.lint({codeFilename:t,code:o,cache:l,cacheLocation:`${a}/.stylelintcache`,fix:c,formatter:"string"}).catch(console.log)})),o=!1;t.forEach(t=>{t&&(t.report&&process.stdout.write(t.report),t.errored&&(o=!!t.errored))}),console.timeEnd("Stylelint"),o&&process.exit(1)}