Skip to content

Commit 54a6cef

Browse files
committed
chore: 更新 @winner-fed/unplugin-check-syntax 依赖版本至 1.0.1,并在 pnpm-lock.yaml 中同步更新。增加对 HTML 文件的语法检查功能。
1 parent 9309b0f commit 54a6cef

File tree

4 files changed

+97
-9
lines changed

4 files changed

+97
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"typescript": "^5.7.2"
4141
},
4242
"dependencies": {
43-
"@winner-fed/unplugin-check-syntax": "^1.0.0"
43+
"@winner-fed/unplugin-check-syntax": "^1.0.1"
4444
},
4545
"peerDependencies": {
4646
"@rsbuild/core": "1.x",

playground/.winrc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ export default defineConfig({
1111
checkSyntax: {
1212
ecmaVersion: 5, // 只配置 ecmaVersion,targets 应该使用默认值
1313
},
14-
rsbuild: {},
14+
// rsbuild: {},
1515
});

pnpm-lock.yaml

Lines changed: 65 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { join } from 'node:path';
12
import type { CheckSyntaxOptions } from '@winner-fed/unplugin-check-syntax';
3+
import { CheckSyntax, printErrors } from '@winner-fed/unplugin-check-syntax';
24
import checkSyntaxRspack from '@winner-fed/unplugin-check-syntax/rspack';
35
import checkSyntaxVite from '@winner-fed/unplugin-check-syntax/vite';
46
import checkSyntaxWebpack from '@winner-fed/unplugin-check-syntax/webpack';
7+
import { winPath } from '@winner-fed/utils';
58
import type { IApi } from '@winner-fed/winjs';
69

7-
export type CheckSyntax = boolean | CheckSyntaxOptions;
8-
910
export default (api: IApi) => {
1011
api.describe({
1112
key: 'checkSyntax',
@@ -117,4 +118,31 @@ export default (api: IApi) => {
117118
]);
118119
return config;
119120
});
121+
122+
// 增加检测 html 文件类型的功能
123+
api.onBuildHtmlComplete(async (html: any) => {
124+
const htmlFiles = html?.htmlFiles || [];
125+
if (api.env === 'development' || htmlFiles.length === 0) {
126+
return;
127+
}
128+
129+
const targets = api.config.targets;
130+
const checkerOptions = getCheckSyntaxOptions(targets);
131+
const checker = new CheckSyntax({
132+
rootPath: api.paths.absOutputPath,
133+
ecmaVersion: 2015 as const, // 默认ES2015
134+
...checkerOptions,
135+
});
136+
137+
// 获取 dist 目录下的所有 html 文件
138+
// 遍历 html 文件,检测是否存在语法错误
139+
for (const htmlFile of htmlFiles) {
140+
const htmlFilePath = winPath(
141+
join(api.paths.absOutputPath, htmlFile.path),
142+
);
143+
await checker.check(htmlFilePath);
144+
}
145+
146+
printErrors(checker.errors, checker.ecmaVersion, checker.excludeErrorLogs);
147+
});
120148
};

0 commit comments

Comments
 (0)