@moneko/core 3.30.0-beta.3 → 3.30.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common.mjs +1 -1
- package/lib/config.mjs +1 -1
- package/lib/dev.d.mts +2 -5
- package/lib/dev.mjs +1 -1
- package/lib/plugin/eslint.d.mts +23 -0
- package/lib/plugin/eslint.mjs +1 -0
- package/lib/plugin/stylelint.d.mts +7 -8
- package/lib/plugin/stylelint.mjs +1 -1
- package/lib/plugin/worker/eslint.d.mts +3 -0
- package/lib/plugin/worker/eslint.mjs +1 -1
- package/lib/plugin/worker/stylelint.d.mts +4 -1
- package/lib/plugin/worker/stylelint.mjs +1 -1
- package/package.json +1 -1
- package/typings/global.d.ts +4 -2
package/lib/common.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extname as e,join as t,resolve as o}from"node:path";import s,{config_files as n,CUSTOMCONFIG as a}from"./commom/paths.mjs";import i from"./commom/require.mjs";import r from"./plugin/override-resolve.mjs";import{isObject as l,node_modules as m,resolveProgram as p}from"./utils/index.mjs";import{exampleModuleName as c}from"./vm/example.mjs";import u from"./vm/info.mjs";import{CONFIG as h,PUBLICPATH as d}from"./config.mjs";import f from"./plugins.config.mjs";import{isDev as g,isLibrary as b,NODE_ENV as
|
|
1
|
+
import{extname as e,join as t,resolve as o}from"node:path";import s,{config_files as n,CUSTOMCONFIG as a}from"./commom/paths.mjs";import i from"./commom/require.mjs";import r from"./plugin/override-resolve.mjs";import{isObject as l,node_modules as m,resolveProgram as p}from"./utils/index.mjs";import{exampleModuleName as c}from"./vm/example.mjs";import u from"./vm/info.mjs";import{CONFIG as h,PUBLICPATH as d}from"./config.mjs";import f from"./plugins.config.mjs";import{isDev as g,isLibrary as b,NODE_ENV as j,packageJson as y}from"./process-env.mjs";export const outputConfig={path:p(b?"docs":"dist"),filename:"js/[name].bundle.js",chunkFilename:`js/[${g?"name":"contenthash"}].js`,assetModuleFilename:t=>{let o=e(t.filename||"").substring(1);return`assets/${o}/[name][hash][ext]`},library:{name:`${u.projectName}`,type:"umd",umdNamedDefine:!0},globalObject:"window",chunkLoadingGlobal:`webpackJsonp_${y.name}`,pathinfo:g,clean:!0,publicPath:d,asyncChunks:!0,charset:!0,iife:!0,crossOriginLoading:"anonymous",enabledWasmLoadingTypes:["fetch"],hotUpdateChunkFilename:"[id].[fullhash].hot.js",hotUpdateMainFilename:"[runtime].[fullhash].hot.json"};let v={main:[m("@app/entry")]};if(h.polyfill&&v.main.unshift(t(s.corePath,"./polyfills/replace-children.mjs")),g&&h.refresh&&h.env.injectRemoteReactRefresh&&v.main.unshift(i.resolve("@moneko/react/lib/injectRemoteReactRefresh.js")),h.entry&&("string"==typeof h.entry?v={main:[h.entry]}:Object.keys(h.entry)&&(v=Object.assign(v,h.entry))),"string"==typeof v.main&&(v.main=[v.main]),h.output){if("string"==typeof h.output)outputConfig.path=h.output;else if(Object.keys(h.output)){let e=h.output,t={...outputConfig.library};Object.assign(outputConfig,e),"object"==typeof h.output&&e.library&&(outputConfig.library=Object.assign(t,e.library))}}let C={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:s.webpackCachePath,memoryCacheUnaffected:!0,name:`.${[a,j].filter(Boolean).join("-")}`,version:`${y.version}`,buildDependencies:{config:n}};!1===h.cache?C=!1:l(h.cache)&&(C=Object.assign(C,h.cache));export const commonConfig={name:"client",target:"web",devtool:h.devtool,entry:v,mode:g?"development":"production",stats:"errors-warnings",cache:C,snapshot:{immutablePaths:[/node_modules\/(?!(@app|@moneko)\/)/],managedPaths:[/^@app\/.+/,/^@moneko\/.+/],buildDependencies:{timestamp:!0,hash:!0}},infrastructureLogging:{level:"error"},externalsPresets:h.externalsPresets,plugins:f,node:{global:!1,__filename:!1,__dirname:!1},experiments:{topLevelAwait:!0,asyncWebAssembly:!0,cacheUnaffected:!0,layers:!0,lazyCompilation:h.lazyCompilation&&g&&{imports:!0,entries:!0,test:e=>{let t=e.nameForCondition();return!!(t&&(t.startsWith(m(c))||t.startsWith(m("@app/comment"))||t.startsWith(s.pagesPath)||t.startsWith(s.componentsPath)))}},buildHttp:l(h.buildHttp)?{allowedUris:[],lockfileLocation:o(s.httpCachePath,"http.lock"),cacheLocation:o(s.httpCachePath,"data"),upgrade:!0,...h.buildHttp}:h.buildHttp,backCompat:!0,futureDefaults:!0,css:!1,outputModule:!1},resolve:{extensions:[".mts",".mjs",".ts",".tsx",".js",".jsx",".json",".wasm"],alias:h.alias,modules:[s.nodeModules,s.pnpmNodeModules,s.denoNodeModules],mainFields:["browser","module","main"],mainFiles:["index"],plugins:h.resolvePlugins,preferAbsolute:!0,cache:!0,fallback:{}},externals:h.externals,output:outputConfig};h.overrideResolve&&commonConfig.resolve.plugins.push(new r(Object.assign({original:h.alias["@"],override:a&&p(a)},h.overrideResolve)));
|
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 n from"./commom/paths.mjs";import r from"./commom/require.mjs";import s from"./commom/setup-env.mjs";import i from"./options/jsx-dom-expressions.mjs";import a from"./options/split-chunk.mjs";import{isFunction as l,node_modules as m,resolveProgram as p}from"./utils/index.mjs";import{APPTYPE as c,FRAMEWORK as u,frameworkVersion as d,isDev as f,isLibrary as g,isMobile as h,isReact as x,jsxImportSource as v,mainDirectory as j,NODE_ENV as P,PACKAGENAME as C}from"./process-env.mjs";let b=["@app","@moneko","neko-ui",".cache/http/data","@ant-design","@antv","@antv/x6","@antv/x6-react-components","@element-plus","ant-design-vue","antd","antd-mini","antd-mobile","antd-mobile-icons","element-plus","element-ui","ng-zorro-antd","@antv","@mui","@du","ahooks","rc-queue-anim","umi","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design"];export function getConfig(e){return delete r.cache[e],new Promise(t=>{if(o(e)){let o=r(e).default;return t(l(o)?o(process):o)}return t({})})}let k=await Promise.all([s(P,c,u,[]),getConfig(n.configPath),getConfig(n.customConfigPath)]),w=k[0],O=k[1],y=k[2],I={devtool:f?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:w,basename:"/",publicPath:"/",rem:{designSize:h?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":p(j)},x&&d<18?{"react/package.json":m("react/package.json"),"react/jsx-runtime":m("react/jsx-runtime.js"),"react/jsx-dev-runtime":m("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3},htmlPluginOption:{title:C.toLocaleUpperCase(),favicon:e(n.programPath,`${n.corePath}/options/favicon.ico`)},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:a,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:b,js:b,media:b,font:b,wasm:[]},mdx:{jsx:!1,development:f,jsxImportSource:v,providerImportSource:`@moneko/${u}/mdx`},jsxDomExpressions:i,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69"},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==u,bundleId:"com.moneko.bid",bundles:[],stylelint
|
|
1
|
+
import{relative as e}from"node:path";import{fileExists as o}from"@moneko/utils";import{merge as t}from"webpack-merge";import n from"./commom/paths.mjs";import r from"./commom/require.mjs";import s from"./commom/setup-env.mjs";import i from"./options/jsx-dom-expressions.mjs";import a from"./options/split-chunk.mjs";import{isFunction as l,node_modules as m,resolveProgram as p}from"./utils/index.mjs";import{APPTYPE as c,FRAMEWORK as u,frameworkVersion as d,isDev as f,isLibrary as g,isMobile as h,isReact as x,jsxImportSource as v,mainDirectory as j,NODE_ENV as P,PACKAGENAME as C}from"./process-env.mjs";let b=["@app","@moneko","neko-ui",".cache/http/data","@ant-design","@antv","@antv/x6","@antv/x6-react-components","@element-plus","ant-design-vue","antd","antd-mini","antd-mobile","antd-mobile-icons","element-plus","element-ui","ng-zorro-antd","@antv","@mui","@du","ahooks","rc-queue-anim","umi","@fontsource","@fortawesome","font-pingfang-sc","font-pingfang-tc","katex","react-markdown-editor-lite","react-photo-view","schema-design"];export function getConfig(e){return delete r.cache[e],new Promise(t=>{if(o(e)){let o=r(e).default;return t(l(o)?o(process):o)}return t({})})}let k=await Promise.all([s(P,c,u,[]),getConfig(n.configPath),getConfig(n.customConfigPath)]),w=k[0],O=k[1],y=k[2],I={devtool:f?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:w,basename:"/",publicPath:"/",rem:{designSize:h?375:1920},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":p(j)},x&&d<18?{"react/package.json":m("react/package.json"),"react/jsx-runtime":m("react/jsx-runtime.js"),"react/jsx-dev-runtime":m("react/jsx-dev-runtime.js")}:{}),moduleRules:[],prefixJsLoader:[],cssModules:[],cssModuleDefinition:!0,importOnDemand:{},proxy:{},devServer:{host:"localhost",port:3e3},htmlPluginOption:{title:C.toLocaleUpperCase(),favicon:e(n.programPath,`${n.corePath}/options/favicon.ico`)},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:a,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:b,js:b,media:b,font:b,wasm:[]},mdx:{jsx:!1,development:f,jsxImportSource:v,providerImportSource:`@moneko/${u}/mdx`},jsxDomExpressions:i,bar:{name:"Client",nameColor:"68",msgColor:"242",barBgColor:"15",barColor:"69"},normalizeCss:!0,externalsPresets:{},buildHttp:void 0,virtualModule:{},cssExtract:{},externals:["@swc/core"],lazyCompilation:!1,performance:!1,refresh:"solid"!==u,bundleId:"com.moneko.bid",bundles:[],stylelint:{},eslint:{}};g&&(I.alias=Object.assign(I.alias,{"@pkg":n.componentsPath,[C]:n.componentsPath}));let M=I;(!1===(M=t(M,O,y)).devtool||!1===M.sourceMap)&&(M.sourceMap=!1,M.devtool=!1),M.fixBrowserRouter&&M.htmlPluginOption&&(M.htmlPluginOption.tags||(M.htmlPluginOption.tags=[]),M.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}));export const CONFIG=M;export const PUBLICPATH=CONFIG.publicPath;
|
package/lib/dev.d.mts
CHANGED
|
@@ -11,7 +11,6 @@ import middleware from 'webpack-dev-middleware';
|
|
|
11
11
|
import webpackHotMiddleware, { type ClientOptions } from 'webpack-hot-middleware';
|
|
12
12
|
import { merge } from 'webpack-merge';
|
|
13
13
|
import { diffObject } from './commom/diff-object.mjs';
|
|
14
|
-
import hasPkg from './commom/has-pkg.mjs';
|
|
15
14
|
import paths, { config_files } from './commom/paths.mjs';
|
|
16
15
|
import Rule from './commom/rule.mjs';
|
|
17
16
|
import sigintExit from './commom/sigint-exit.mjs';
|
|
@@ -19,17 +18,15 @@ import { devLog, PORT } from './dev/config.mjs';
|
|
|
19
18
|
import setupMock from './dev/mock.mjs';
|
|
20
19
|
import { type ProxyConfig, setupProxy } from './dev/proxy.mjs';
|
|
21
20
|
import reslove from './options/reslove.mjs';
|
|
21
|
+
import ESLintPlugin from './plugin/eslint.mjs';
|
|
22
22
|
import StylelintPlugin from './plugin/stylelint.mjs';
|
|
23
|
-
import { empty
|
|
23
|
+
import { empty } from './utils/index.mjs';
|
|
24
24
|
import { commonConfig } from './common.mjs';
|
|
25
25
|
import { CONFIG, getConfig, PUBLICPATH } from './config.mjs';
|
|
26
26
|
import type { ConfigType } from './index.mjs';
|
|
27
27
|
import moduleConfig from './module.config.mjs';
|
|
28
28
|
import { isLibrary, isReact, refresh } from './process-env.mjs';
|
|
29
29
|
type WebpackPlugin = new(opt?: object) => WebpackPluginInstance;
|
|
30
|
-
declare const ESLintPlugin: WebpackPlugin;
|
|
31
|
-
declare const eslintExts: string[], eslintExtStr: string;
|
|
32
|
-
declare const lintExclude: string[];
|
|
33
30
|
declare const hmrPath: string;
|
|
34
31
|
declare const clientParams: ClientOptions;
|
|
35
32
|
declare const hotParams: string;
|
package/lib/dev.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{relative as r}from"node:path";import
|
|
1
|
+
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import{relative as r}from"node:path";import s from"@fastify/compress";import{fastifyMiddie as i}from"@fastify/middie";import{ink as l,loadFile as a,print as n,println as m,progressBar as p}from"@moneko/utils";import c from"fastify";import d from"webpack";import u from"webpack-dev-middleware";import h from"webpack-hot-middleware";import{merge as f}from"webpack-merge";import{diffObject as g}from"./commom/diff-object.mjs";import y,{config_files as w}from"./commom/paths.mjs";import x from"./commom/rule.mjs";import v from"./commom/sigint-exit.mjs";import{devLog as C,PORT as $}from"./dev/config.mjs";import k from"./dev/mock.mjs";import{setupProxy as P}from"./dev/proxy.mjs";import b from"./options/reslove.mjs";import j from"./plugin/eslint.mjs";import S from"./plugin/stylelint.mjs";import{empty as A}from"./utils/index.mjs";import{commonConfig as E}from"./common.mjs";import{CONFIG as T,getConfig as I,PUBLICPATH as M}from"./config.mjs";import R from"./module.config.mjs";import{isLibrary as _,isReact as B,refresh as H}from"./process-env.mjs";let O=`${M.endsWith("/")?"":"/"}__hmr__`,q=new URLSearchParams({name:"client",path:O,dynamicPublicPath:!0,timeout:2e3,reload:!H,quiet:!1,noInfo:!0,overlay:!1,autoConnect:!0}).toString(),z=E.output.path,U=f(E,{entry:{main:[`${b.hotMiddlewareClient}?${q}`]},output:{path:z},module:R(!1),optimization:{minimize:!1,concatenateModules:!1,removeAvailableModules:!1,removeEmptyChunks:!0,providedExports:!0,usedExports:!1,sideEffects:!1,splitChunks:{chunks:"all",minChunks:1,minSize:30720,maxSize:51200,maxAsyncRequests:60,maxInitialRequests:50,hidePathInfo:!1,cacheGroups:{vendors:{test:x.node_modules,priority:-10,reuseExistingChunk:!0},default:{minChunks:1,priority:-20,reuseExistingChunk:!0}}}},plugins:[new d.HotModuleReplacementPlugin,new d.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app|@moneko)).+/,/\.d\.ts$/]})]});if(U.plugins||(U.plugins=[]),B){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;U.plugins.push(new e)}if(T.eslint){let e="js,jsx,ts,tsx,json,html,vue";U.plugins.push(new j({fix:!0,cache:!0,cacheLocation:`${y.lintCachePath}/.eslintcache`,cacheStrategy:"metadata",lintDirtyModulesOnly:!0,...T.eslint,files:[r(y.programPath,`${T.alias["@"]}/**/*.{${e}}`).replace(/\\/g,"/"),_&&r(y.programPath,`${T.alias["@pkg"]}/**/*.{${e}}`).replace(/\\/g,"/")].filter(Boolean)}))}if(T.stylelint){let e="css,scss,sass,less,ts,tsx,js,jsx";U.plugins.push(new S({fix:!0,cache:!0,cacheLocation:`${y.lintCachePath}/.stylelintcache`,...T.stylelint,files:[r(y.programPath,`${T.alias["@"]}/**/*.{${e}}`).replace(/\\/g,"/"),_&&r(y.programPath,`${T.alias["@pkg"]}/**/*.{${e}}`).replace(/\\/g,"/")].filter(Boolean)}))}if(T.bar){let e=T.bar,t=e.name||"Build";U.plugins.push(new d.ProgressPlugin({handler(o,r,...s){p(o||0,1,{msg:s.length?`[${r}] ${s.join(" ")}`:"",name:t,barColor:e.barColor,nameColor:e.nameColor,barBgColor:e.barBgColor,msgColor:e.msgColor}),1===o&&process.stdout.write("\r\x1b[2K")}}))}let D=d(U);D.hooks.done.tap("client-log",e=>{C(null,e)});let G={};if(T.devServer.https){let[e,t]=await Promise.all([a(T.devServer.https.key),a(T.devServer.https.cert)]);e||(m(l(`法加载私钥。请检查路径和文件是否存在,并确保路径正确:${T.devServer.https.key}`,"red")),process.exit(1)),t||(m(l(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${T.devServer.https.cert}`,"red")),process.exit(1)),G.http2=!0,G.https={key:e,cert:t}}let L=u(D,{writeToDisk:!1,index:"index.html",headers:e=>({"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",...T.devServer.headers,"Access-Control-Allow-Origin":e.headers.origin||"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"}),serverSideRender:!1,lastModified:!0,publicPath:U.output?.publicPath,cacheControl:!1,cacheImmutable:!1}),W=h(D,{log:!1,path:O,heartbeat:2e3}),N=c({logger:!1,...G});await N.register(i),N.use(L),N.use(O,W),k(N,{directory:y.mockPath}),P(N,T.proxy);let F=`${U.output.path}/index.html`;function K(){process.exit(0)}N.get("*",async(e,t)=>{if(e.headers.accept?.includes("text/html")){let e=L.context.outputFileSystem,o=e?.readFileSync?.(F);if(!t.sent){t.type("text/html").send(o);return}}else if(e.url?.endsWith(O)&&"text/event-stream"===e.headers.accept){e.raw.url=O,W(e.raw,t.raw,A);return}}),N.addHook("onClose",()=>{L.close(A),N.server.close(A)}),await N.register(s,{global:!0}),N.listen({port:$});let X=await Promise.all(w.map(I)),J=f(X[0]||{},X[1]||{});w.forEach(function(t){o(t,async function(){let[o,r]=await Promise.all(w.map(I)),s=f(o||{},r||{}),i=g(J,s);1===Object.keys(i).length&&"proxy"in i?(n(l(`代理更新中...`,"yellow"),!0),await P(N,s.proxy),n(l(`代理更新完成...`,"green"),!0),T.proxy=s.proxy,J.proxy=s.proxy,J=s):(J=s,m(l(`检测到工程配置${l(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e("win32"===process.platform?`netstat -ano | findstr :${$}`:`lsof -i :${$} -t`,(e,t)=>{if(e){m(l(`查找端口 ${$} 时发生错误: ${e.message}`,"red")),m(l("请尝试手动重启程序","yellow"));return}let o=t.trim().split("\n").filter(Boolean),r=Q?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!r){m(l(`未找到占用端口 ${$} 的进程, 请尝试手动重启程序`,"yellow"));return}try{process.kill(Number(r),"SIGHUP")}catch(e){m(l(`终止进程 ${r} 时发生错误: ${e.message}`,"red"))}}))})});let Q="win32"===process.platform;process.on("SIGHUP",function(){N.close(A),function(){let e=t(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",K)}()}),process.on("exit",function(){N.close(A)}),v(K);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { ESLint } from '@moneko/eslint';
|
|
3
|
+
import webpack, { type Compilation, type Compiler } from 'webpack';
|
|
4
|
+
import { Worker } from 'worker_threads';
|
|
5
|
+
import type { ESLintWorkerMessage } from './worker/eslint.mjs';
|
|
6
|
+
declare class ESLintError extends webpack.WebpackError {
|
|
7
|
+
constructor(message: string, error: boolean);
|
|
8
|
+
}
|
|
9
|
+
export interface ESLintOption extends ESLint.Options {
|
|
10
|
+
files: string[];
|
|
11
|
+
lintDirtyModulesOnly?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare class ESLintPlugin {
|
|
14
|
+
private name: string;
|
|
15
|
+
private worker: Worker;
|
|
16
|
+
private options: ESLintOption;
|
|
17
|
+
constructor(options: ESLintOption = {
|
|
18
|
+
files: []
|
|
19
|
+
});
|
|
20
|
+
apply(compiler: Compiler): void;
|
|
21
|
+
private report(compilation: Compilation, lints?: ESLintWorkerMessage);
|
|
22
|
+
}
|
|
23
|
+
export default ESLintPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{fileURLToPath as r}from"node:url";import t from"webpack";import{Worker as e}from"worker_threads";class s extends t.WebpackError{constructor(r,t){super(`[ESLint] ${r.replace(/[^\r\n]*(\r?\n)*$/,"")}`),this.name=t?"ESLintError":"ESLintWarning",this.stack=""}}export default class{constructor(t={files:[]}){this.name="ESLintPlugin",this.options=t,this.worker=new e(r(new URL("./worker/eslint.mjs",import.meta.url)))}apply(r){r.hooks.thisCompilation.tap(this.name,r=>{this.worker.postMessage({options:this.options}),this.worker.once("message",t=>{this.report(r,t)})}),r.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(r,t){t?.length&&r&&(t[0].length&&r.warnings.push(new s(t[0],!1)),t[1].length&&r.errors.push(new s(t[1],!0)))}}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import {
|
|
2
|
+
import type { LinterOptions } from '@moneko/stylelint';
|
|
3
3
|
import webpack, { type Compilation, type Compiler } from 'webpack';
|
|
4
4
|
import { Worker } from 'worker_threads';
|
|
5
|
+
import type { StylelintWorkerMessage } from './worker/stylelint.mjs';
|
|
5
6
|
declare class StylelintError extends webpack.WebpackError {
|
|
6
|
-
constructor(message: string);
|
|
7
|
+
constructor(message: string, error: boolean);
|
|
7
8
|
}
|
|
8
|
-
interface
|
|
9
|
-
threads?: number;
|
|
9
|
+
export interface StylelintOption extends LinterOptions {
|
|
10
10
|
files: string[];
|
|
11
|
-
exclude?: string[];
|
|
12
11
|
}
|
|
13
12
|
declare class StylelintPlugin {
|
|
14
13
|
private name: string;
|
|
15
14
|
private worker: Worker;
|
|
16
|
-
private options:
|
|
17
|
-
constructor(options:
|
|
15
|
+
private options: StylelintOption;
|
|
16
|
+
constructor(options: StylelintOption = {
|
|
18
17
|
files: []
|
|
19
18
|
});
|
|
20
19
|
apply(compiler: Compiler): void;
|
|
21
|
-
private report(
|
|
20
|
+
private report(lints?: StylelintWorkerMessage, compilation?: Compilation);
|
|
22
21
|
}
|
|
23
22
|
export default StylelintPlugin;
|
package/lib/plugin/stylelint.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fileURLToPath as
|
|
1
|
+
import{fileURLToPath as t}from"node:url";import r from"webpack";import{Worker as e}from"worker_threads";class s extends r.WebpackError{constructor(t,r){super(`[Stylelint] ${t.replace(/[^\r\n]*(\r?\n)*$/,"")}`),this.name=r?"StylelintError":"StylelintWarning",this.stack=""}}export default class{constructor(r={files:[]}){this.name="StylelintPlugin",this.options=r,this.worker=new e(t(new URL("./worker/stylelint.mjs",import.meta.url)))}apply(t){t.hooks.thisCompilation.tap(this.name,t=>{this.worker.postMessage({options:this.options}),this.worker.once("message",r=>{this.report(r,t)})}),t.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(t,r){t?.length&&r&&(t[0].length&&r.warnings.push(new s(t[0],!1)),t[1].length&&r.errors.push(new s(t[1],!0)))}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ESLint as
|
|
1
|
+
let e,a;import{ESLint as t}from"@moneko/eslint";import{parentPort as o}from"worker_threads";if(!o)throw Error("This file must be run as a worker");let r=null;o.on("message",async({options:i})=>{r&&clearTimeout(r),r=setTimeout(async()=>{r&&(clearTimeout(r),r=null);try{e||(e=new t({cache:i.cache,cacheLocation:i.cacheLocation,cacheStrategy:i.cacheStrategy,fix:i.fix}),a=await e.loadFormatter("stylish"));let r=i.files.map(e=>e.replace(/\\/g,"/")),s=await e.lintFiles(r),c=[],l=[];i.fix&&await t.outputFixes(s),s.forEach(e=>{e.errorCount?l.push(e):e.warningCount&&c.push(e)});let n=await Promise.all([a.format(c),a.format(l)]);o.postMessage(n)}catch(e){o.postMessage(e)}},4)}),o.on("close",()=>{r&&clearTimeout(r)});
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import { type LinterResult, stylelint } from '@moneko/stylelint';
|
|
1
|
+
import { type Formatter, type LinterResult, type LintResult, stylelint, type Warning } from '@moneko/stylelint';
|
|
2
2
|
import { parentPort } from 'worker_threads';
|
|
3
|
+
export type StylelintWorkerMessage = [warnings: string, errors: string];
|
|
4
|
+
declare let timer: NodeJS.Timeout | null;
|
|
5
|
+
declare const formatter: Formatter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{stylelint as e}from"@moneko/stylelint";import{parentPort as
|
|
1
|
+
import{stylelint as e}from"@moneko/stylelint";import{parentPort as r}from"worker_threads";if(!r)throw Error("This file must be run as a worker");let t=null,i=await e.formatters.string;r.on("message",async({options:a})=>{t&&clearTimeout(t),t=setTimeout(async()=>{t&&(clearTimeout(t),t=null);try{let t=await e.lint({cache:a.cache,cacheLocation:a.cacheLocation,fix:a.fix,files:a.files.map(e=>e.replace(/\\/g,"/")),quietDeprecationWarnings:a.quietDeprecationWarnings,quiet:a.quiet});delete t.output;let n=[],s=[];t.results.forEach(e=>{if(!e.ignored&&(e.errored||e.parseErrors.length||e.invalidOptionWarnings.length||e.deprecations.length)){let r=[],t=[];e.warnings.forEach(e=>{"error"===e.severity?r.push(e):"warning"===e.severity&&t.push(e)}),r.length>0&&n.push({...e,warnings:r}),t.length>0&&s.push({...e,warnings:t})}});let o=[i(s,t),i(n,t)];r.postMessage(o)}catch(e){r.postMessage(e)}},4)}),r.on("close",()=>{t&&clearTimeout(t)});
|
package/package.json
CHANGED
package/typings/global.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ import type { CopyPluginOption } from '../lib/plugin/copy.mjs';
|
|
|
27
27
|
import type { DonePluginOption } from '../lib/plugin/done.mjs';
|
|
28
28
|
|
|
29
29
|
import type { BundleAnalyzerOption } from './bundle-analyzer.d';
|
|
30
|
+
import type { ESLintOption } from '../lib/plugin/eslint.mts';
|
|
31
|
+
import type { StylelintOption } from '../lib/plugin/stylelint.mts';
|
|
30
32
|
|
|
31
33
|
export type { MiniCssExtractPluginOptions, SwcMinifyOptions, TerserMinifyOptions };
|
|
32
34
|
export type MinifierType = 'swc' | 'terser';
|
|
@@ -477,11 +479,11 @@ export declare type ConfigType = {
|
|
|
477
479
|
/** stylelint 配置
|
|
478
480
|
* @description 为 false 时关闭
|
|
479
481
|
*/
|
|
480
|
-
stylelint?: false | StylelintOption
|
|
482
|
+
stylelint?: false | Partial<StylelintOption>;
|
|
481
483
|
/** eslint 配置
|
|
482
484
|
* @description 为 false 时关闭
|
|
483
485
|
*/
|
|
484
|
-
eslint?: false | ESLintOption
|
|
486
|
+
eslint?: false | Partial<ESLintOption>;
|
|
485
487
|
/** 生成 DTS 文件的方式
|
|
486
488
|
* @default 'tsc'
|
|
487
489
|
*/
|