@moneko/core 3.26.13-beta.2 → 3.26.13-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/dev.d.mts +1 -4
- package/lib/dev.mjs +1 -1
- package/lib/plugin/stylelint.d.mts +23 -0
- package/lib/plugin/stylelint.mjs +1 -0
- package/lib/plugin/virtual-module.d.mts +1 -1
- package/lib/plugin/virtual-module.mjs +1 -1
- package/lib/plugin/worker/stylelint.d.mts +2 -0
- package/lib/plugin/worker/stylelint.mjs +1 -0
- package/package.json +2 -2
package/lib/dev.d.mts
CHANGED
|
@@ -18,6 +18,7 @@ import { devLog, PORT } from './dev/config.mjs';
|
|
|
18
18
|
import setupMock from './dev/mock.mjs';
|
|
19
19
|
import { type ProxyConfig, setupProxy } from './dev/proxy.mjs';
|
|
20
20
|
import reslove from './options/reslove.mjs';
|
|
21
|
+
import StylelintPlugin from './plugin/stylelint.mjs';
|
|
21
22
|
import { empty, resolveProgram } from './utils/index.mjs';
|
|
22
23
|
import { commonConfig } from './common.mjs';
|
|
23
24
|
import { CONFIG, getConfig, PUBLICPATH } from './config.mjs';
|
|
@@ -25,12 +26,8 @@ import type { ConfigType } from './index.mjs';
|
|
|
25
26
|
import moduleConfig from './module.config.mjs';
|
|
26
27
|
import { isLibrary, isReact, refresh } from './process-env.mjs';
|
|
27
28
|
type WebpackPlugin = new(opt?: object) => WebpackPluginInstance;
|
|
28
|
-
declare const stylelintPath: string | false;
|
|
29
|
-
declare const StylelintPlugin: WebpackPlugin;
|
|
30
29
|
declare const ESLintPlugin: WebpackPlugin;
|
|
31
|
-
declare const ReactRefresh: WebpackPlugin;
|
|
32
30
|
declare const eslintExts: string[], eslintExtStr: string;
|
|
33
|
-
declare const stylelintExts: string[], stylelintExtStr: string;
|
|
34
31
|
declare const lintExclude: string[];
|
|
35
32
|
declare const hmrPath: string;
|
|
36
33
|
declare const clientParams: ClientOptions;
|
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 i from"@fastify/compress";import{fastifyMiddie as r}from"@fastify/middie";import{ink as s,loadFile as l,print as n,println as a,progressBar as m}from"@moneko/utils";import
|
|
1
|
+
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import i from"@fastify/compress";import{fastifyMiddie as r}from"@fastify/middie";import{ink as s,loadFile as l,print as n,println as a,progressBar as m}from"@moneko/utils";import p from"fastify";import c from"webpack";import d from"webpack-dev-middleware";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/has-pkg.mjs";import w,{config_files as y}from"./commom/paths.mjs";import x from"./commom/rule.mjs";import v from"./commom/sigint-exit.mjs";import{devLog as k,PORT as $}from"./dev/config.mjs";import j from"./dev/mock.mjs";import{setupProxy as C}from"./dev/proxy.mjs";import P from"./options/reslove.mjs";import b from"./plugin/stylelint.mjs";import{empty as S,resolveProgram 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 _ from"./module.config.mjs";import{isLibrary as R,isReact as H,refresh as O}from"./process-env.mjs";let q=T.eslint&&g("eslint-webpack-plugin")&&(await import("eslint-webpack-plugin")).default,z=["js","jsx","ts","tsx","json","html","vue"],U=z.join(","),B=`${M.endsWith("/")?"":"/"}__hmr__`,D=new URLSearchParams({name:"client",path:B,dynamicPublicPath:!0,timeout:2e3,reload:!O,quiet:!0,noInfo:!0,overlay:!0,autoConnect:!0}).toString(),G=E.output.path,L=T.bar.name||"Build",W=h(E,{entry:{main:[`${P.hotMiddlewareClient}?${D}`]},output:{path:G},module:_(!1),optimization:{minimize:!1,concatenateModules:!1,removeAvailableModules:!1,removeEmptyChunks:!0,providedExports:!0,usedExports:!1,sideEffects:!1,splitChunks:{chunks:"all",minChunks:1,minSize:30720,maxSize:0,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 c.HotModuleReplacementPlugin,new c.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app|@moneko)).+/,/\.d\.ts$/]})]});if(W.plugins||(W.plugins=[]),H){let e=(await import("@pmmmwh/react-refresh-webpack-plugin")).default;W.plugins.push(new e)}if(q&&W.plugins.push(new q({fix:!0,threads:!0,files:[`${T.alias["@"]}/**/*.{${U}}`,R&&`${T.alias["@pkg"]}/**/*.{${U}}`].filter(Boolean),extensions:z,exclude:["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],cache:!0,cacheLocation:`${w.lintCachePath}/.eslintcache`,lintDirtyModulesOnly:!0,overrideConfigFile:A("eslint.config.mjs"),configType:"flat"})),T.stylelint){let e="css,scss,sass,less,ts,tsx,js,jsx";W.plugins.push(new b({fix:!0,files:[`${T.alias["@"]}/**/*.{${e}}`,R&&`${T.alias["@pkg"]}/**/*.{${e}}`].filter(Boolean),cache:!0,cacheLocation:`${w.lintCachePath}/.stylelintcache`}))}T.bar&&W.plugins.push(new c.ProgressPlugin({handler(e,t,...o){m(e||0,1,L,o.length?`[${t}] ${o.join(" ")}`:""),1===e&&process.stdout.write("\r\x1b[2K")}}));let F=c(W);F.hooks.done.tap("client-log",e=>{k(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||(a(s(`法加载私钥。请检查路径和文件是否存在,并确保路径正确:${T.devServer.https.key}`,"red")),process.exit(1)),t||(a(s(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${T.devServer.https.cert}`,"red")),process.exit(1)),N.http2=!0,N.https={key:e,cert:t}}let K=d(F,{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:W.output?.publicPath,cacheControl:!1,cacheImmutable:!1}),X=u(F,{log:!1,path:B,heartbeat:2e3}),J=p({logger:!1,...N});await J.register(r),J.use(K),J.use(B,X),j(J,{directory:w.mockPath}),C(J,T.proxy);let Q=`${W.output.path}/index.html`;function V(){process.exit(0)}J.get("*",async(e,t)=>{if(e.headers.accept?.includes("text/html")){let e=K.context.outputFileSystem,o=e?.readFileSync?.(Q);if(!t.sent){t.type("text/html").send(o);return}}else if(e.url?.endsWith(B)&&"text/event-stream"===e.headers.accept){e.raw.url=B,X(e.raw,t.raw,S);return}}),J.addHook("onClose",()=>{K.close(S),J.server.close(S)}),await J.register(i,{global:!0}),J.listen({port:$});let Y=await Promise.all(y.map(I)),Z=h(Y[0]||{},Y[1]||{});y.forEach(function(t){o(t,async function(){let[o,i]=await Promise.all(y.map(I)),r=h(o||{},i||{}),l=f(Z,r);1===Object.keys(l).length&&"proxy"in l?(n(s(`代理更新中...`,"yellow"),!0),await C(J,r.proxy),n(s(`代理更新完成...`,"green"),!0),T.proxy=r.proxy,Z.proxy=r.proxy,Z=r):(Z=r,a(s(`检测到工程配置${s(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e("win32"===process.platform?`netstat -ano | findstr :${$}`:`lsof -i :${$} -t`,(e,t)=>{if(e){a(s(`查找端口 ${$} 时发生错误: ${e.message}`,"red")),a(s("请尝试手动重启程序","yellow"));return}let o=t.trim().split("\n").filter(Boolean),i=ee?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!i){a(s(`未找到占用端口 ${$} 的进程, 请尝试手动重启程序`,"yellow"));return}try{process.kill(Number(i),"SIGHUP")}catch(e){a(s(`终止进程 ${i} 时发生错误: ${e.message}`,"red"))}}))})});let ee="win32"===process.platform;process.on("SIGHUP",function(){J.close(S),function(){let e=t(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",V)}()}),process.on("exit",function(){J.close(S)}),v(V);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { type LinterOptions, type LinterResult, type LintResult, stylelint, type Warning } from '@moneko/stylelint';
|
|
3
|
+
import webpack, { type Compilation, type Compiler } from 'webpack';
|
|
4
|
+
import { Worker } from 'worker_threads';
|
|
5
|
+
declare class StylelintError extends webpack.WebpackError {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
interface StylelintPluginOptions extends LinterOptions {
|
|
9
|
+
threads?: number;
|
|
10
|
+
files: string[];
|
|
11
|
+
exclude?: string[];
|
|
12
|
+
}
|
|
13
|
+
declare class StylelintPlugin {
|
|
14
|
+
private name: string;
|
|
15
|
+
private worker: Worker;
|
|
16
|
+
private options: StylelintPluginOptions;
|
|
17
|
+
constructor(options: StylelintPluginOptions = {
|
|
18
|
+
files: []
|
|
19
|
+
});
|
|
20
|
+
apply(compiler: Compiler): void;
|
|
21
|
+
private report(linter: LinterResult, compilation: Compilation);
|
|
22
|
+
}
|
|
23
|
+
export default StylelintPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{fileURLToPath as r}from"node:url";import{stylelint as t}from"@moneko/stylelint";import e from"webpack";import{Worker as s}from"worker_threads";class o extends e.WebpackError{constructor(r){super(`[Stylelint] ${r.replace(/[^\r\n]*(\r?\n)*$/,"")}`),this.name="StylelintError",this.stack=""}}export default class{constructor(t={files:[]}){this.name="StylelintPlugin",this.options=t,this.worker=new s(r(new URL("./worker/stylelint.mjs",import.meta.url)))}apply(r){r.hooks.thisCompilation.tap(this.name,r=>{this.worker.postMessage({options:this.options}),this.worker.once("message",t=>{let e=JSON.parse(t);this.report(e,r)})}),r.hooks.shutdown.tap(this.name,()=>{this.worker.terminate()})}report(r,e){let s=[],n=[];r.results.forEach(r=>{if(!r.ignored&&(r.errored||r.parseErrors.length||r.invalidOptionWarnings.length||r.deprecations.length)){let t=[],e=[];r.warnings.forEach(r=>{"error"===r.severity?t.push(r):"warning"===r.severity&&e.push(r)}),t.length>0&&s.push({...r,warnings:t}),e.length>0&&n.push({...r,warnings:e})}}),t.formatters.string.then(t=>{e.warnings.push(new o(t(n,r))),e.errors.push(new o(t(s,r)))})}}
|
|
@@ -15,7 +15,7 @@ export interface VirtualModulePluginOption {
|
|
|
15
15
|
}
|
|
16
16
|
declare const PLUGIN_NAME: string;
|
|
17
17
|
export declare class VirtualModuleWebpackPlugin {
|
|
18
|
-
private virtualModules:
|
|
18
|
+
private virtualModules: VirtualModulesPlugin;
|
|
19
19
|
private options: Record<string, string>;
|
|
20
20
|
private init: boolean;
|
|
21
21
|
constructor(options: VirtualModulePluginOption = {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"webpack-virtual-modules";import o from"../commom/parse-module-meta.mjs";import i from"../commom/paths.mjs";import{isLibrary as e}from"../process-env.mjs";import{node_modules as s}from"../utils/index.mjs";import{comment as r,docs as l}from"../vm/docs.mjs";import{examples as m}from"../vm/example.mjs";import{locales as n}from"../vm/locales.mjs";import p from"../vm/modules.mjs";import{route as a}from"../vm/routes.mjs";let f={};for(let t in p)if(Object.prototype.hasOwnProperty.call(p,t)){let{file:i,pkg:e,meta:s}=o(t);f[e]=s,f[i]=p[t]}export class VirtualModuleWebpackPlugin{constructor(i={}){this.
|
|
1
|
+
import t from"webpack-virtual-modules";import o from"../commom/parse-module-meta.mjs";import i from"../commom/paths.mjs";import{isLibrary as e}from"../process-env.mjs";import{node_modules as s}from"../utils/index.mjs";import{comment as r,docs as l}from"../vm/docs.mjs";import{examples as m}from"../vm/example.mjs";import{locales as n}from"../vm/locales.mjs";import p from"../vm/modules.mjs";import{route as a}from"../vm/routes.mjs";let f={};for(let t in p)if(Object.prototype.hasOwnProperty.call(p,t)){let{file:i,pkg:e,meta:s}=o(t);f[e]=s,f[i]=p[t]}export class VirtualModuleWebpackPlugin{constructor(i={}){this.options={},this.init=!1,this.virtualModules=new t(f);let e={};for(let t in i)if(Object.prototype.hasOwnProperty.call(i,t)){let{file:s,pkg:r,meta:l}=o(t),m=i[t],n=m;n=s.endsWith("json")?"string"==typeof m?m:JSON.stringify(m):"string"==typeof m?m:`export default ${JSON.stringify(m)}`,Object.assign(e,{[s]:n,[r]:l})}this.options=e}modify(t,o,e){let r=e||"",l=o.startsWith(i.nodeModules)?o:s(o),m=t.inputFileSystem;for(;m&&m._inputFileSystem;)m=m._inputFileSystem;let n=m?._virtualFiles?.[l];n&&n.contents===r||(this.virtualModules.writeModule(l,r),t.watching?.invalidate())}apply(t){this.virtualModules.apply(t);let o=(o,i)=>{this.modify(t,o,i)};a.on("change",o),n.on("change",o),e&&(m.on("change",o),l.on("change",o),r.on("change",o)),t.hooks.compilation.tap("VirtualModuleWebpackPlugin",()=>{if(!this.init){for(let t in this.init=!0,this.options)Object.prototype.hasOwnProperty.call(this.options,t)&&o(t,this.options[t]);for(let t of m)o(t[0],t[1]);for(let t of l)o(t[0],t[1]);for(let t of r)o(t[0],t[1])}})}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{stylelint as e}from"@moneko/stylelint";import{parentPort as t}from"worker_threads";if(!t)throw Error("This file must be run as a worker");t.on("message",async({options:i})=>{try{let a=await e.lint({cache:i.cache,cacheLocation:i.cacheLocation,fix:i.fix,files:i.files,quietDeprecationWarnings:i.quietDeprecationWarnings,quiet:i.quiet});delete a.output,t.postMessage(JSON.stringify(a))}catch(e){t.postMessage(e)}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.26.13-beta.
|
|
3
|
+
"version": "3.26.13-beta.4",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@fastify/http-proxy": "9.5.0",
|
|
21
21
|
"@fastify/middie": "8.3.3",
|
|
22
22
|
"@moneko/mdx": "0.1.42",
|
|
23
|
-
"@moneko/stylelint": "1.0.
|
|
23
|
+
"@moneko/stylelint": "1.0.1",
|
|
24
24
|
"@moneko/transform-imports": "0.6.1",
|
|
25
25
|
"@moneko/utils": "0.1.19",
|
|
26
26
|
"@swc/cli": "0.5.2",
|