外观
Lint
执行:
全量 lint:
bash
npm run lint1
支持 TASKS 参数
该命令支持通过 TASKS 来指定具体执行哪些任务(不传的话默认执行全部任务)。
该参数支持白名单和黑名单模式,并且支持 * 通配符。注意,白名单和黑名单模式不可混用,以避免歧义。
bash
# 白名单:执行所有 spa: 开头的任务
cross-env TASKS=spa:* npm run <example-command>
# 白名单:混合精确匹配和通配符
cross-env TASKS=clean,ssg:* npm run <example-command>
# 黑名单:排除所有 spa: 开头的任务
cross-env TASKS=-spa:* npm run <example-command>1
2
3
4
5
6
2
3
4
5
6
SPA 类型检查优先使用应用目录中的 tsconfig.app.json,不存在时使用 tsconfig.json。 存在 tsconfig.test.json 时额外检查测试项目,任一项目检查失败都会终止任务。 正式测试集中放在所属工程与源码目录同级的 tests/ 中,禁止混入生产源码目录。确有必要保留测试时,除类型检查外,还必须在对应 lint 流程中实际执行用例,失败时终止任务;只有类型检查不代表测试已经运行。
Android 原生测试遵循 Gradle 的 src/test/ 和 src/androidTest/ 标准源集。本地 JVM 测试纳入 Android lint,设备测试通过对应 Gradle 测试任务执行,需具备真机或模拟器环境,未执行时如实标注。
临时测试与验证文件统一放在根目录 .temp/,使用结束后删除,失败退出也须清理。删除正式测试时,同步清理失效的执行入口和项目引用,不保留空测试项目。
scripts/lint.mts 源码
typescript
import { loadReleaseConfigs } from "#scripts/utils/app-release-config";
import { joinPath, isPathExists, refreshGitIndex } from "nsuite";
import { runCommandInChildProcess } from "#scripts/utils/child-process";
import { useTask } from "#scripts/utils/use-task";
import { checkEnvFilesConsistency } from "#scripts/utils/check-env";
import {
PATH_APPS_HOME,
STANDALONE_SSG_APPS_NAMES,
STANDALONE_SSR_APPS_NAMES,
SUB_APPS_NAMES,
VSIX_APPS_NAMES,
} from "#utils/ConstantUtils";
const { killAllChildProcessWhenSuitable, addTask, runTasksSequentially, printTaskStatisticsInfo } =
useTask({ allowTasks: process.env.TASKS || "" });
loadReleaseConfigs();
killAllChildProcessWhenSuitable();
addTask("check:env", async () => {
await checkEnvFilesConsistency();
});
addTask("server", async (payload) => {
const { progress, taskName } = payload;
const { promise } = runCommandInChildProcess({
appName: `${progress.current}/${progress.total}-${taskName}`,
command: "tsc",
args: `--noEmit --project ./tsconfig.json`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} failed: exitCode=${exitCode}`);
}
});
for (const appName of SUB_APPS_NAMES) {
addTask(`spa:${appName}`, async (payload) => {
const { progress, taskName } = payload;
const appNameDisplay = `${progress.current}/${progress.total}-${taskName}`;
// oxfmt
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxfmt",
args: `-c ../../.oxfmtrc.json --ignore-path ../../.oxfmtignore .`,
env: process.env,
cwd: `./apps/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxfmt) failed: exitCode=${exitCode}`);
}
}
// prettier
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "prettier",
args: `--write --cache --ignore-path ../../.prettierignore-sub .`,
env: process.env,
cwd: `./apps/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (prettier) failed: exitCode=${exitCode}`);
}
}
// oxlint
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxlint",
args: `-c .oxlintrc.json --fix --fix-suggestions ./apps/${appName}/`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxlint) failed: exitCode=${exitCode}`);
}
}
// 分别检查应用与可选的测试项目,避免 solution 配置跳过类型检查。
const appProject = await isPathExists(`./apps/${appName}/tsconfig.app.json`)
? "tsconfig.app.json"
: "tsconfig.json";
const projects = [appProject];
if (await isPathExists(`./apps/${appName}/tsconfig.test.json`)) {
projects.push("tsconfig.test.json");
}
for (const project of projects) {
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "vue-tsc",
args: `--noEmit --project ./${project}`,
env: process.env,
cwd: `./apps/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (vue-tsc ${project}) failed: exitCode=${exitCode}`);
}
}
});
}
/**
* 顺序处理所有 SSG APP(静态:Next.js、Nuxt 静态、VitePress 等)
*/
for (const appName of STANDALONE_SSG_APPS_NAMES) {
addTask(`ssg:${appName}`, async (payload) => {
const { progress, taskName } = payload;
const appNameDisplay = `${progress.current}/${progress.total}-${taskName}`;
// oxfmt
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxfmt",
args: `-c ../../.oxfmtrc.json --ignore-path ../../.oxfmtignore .`,
env: process.env,
cwd: `./apps-home/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxfmt) failed: exitCode=${exitCode}`);
}
}
// prettier
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "prettier",
args: `--write --cache --ignore-path ../../.prettierignore-sub .`,
env: process.env,
cwd: `./apps-home/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (prettier) failed: exitCode=${exitCode}`);
}
}
// oxlint
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxlint",
args: `-c .oxlintrc.json --fix --fix-suggestions ./apps-home/${appName}/`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxlint) failed: exitCode=${exitCode}`);
}
}
// 区分应用类型:Next.js、Nuxt 4 应用、VitePress 2 应用
const pathApp = joinPath(PATH_APPS_HOME, appName);
const pathNuxtConfig = joinPath(pathApp, "nuxt.config.ts");
const pathNextConfig = joinPath(pathApp, "next.config.ts");
const isNext = await isPathExists(pathNextConfig);
const isNuxt = await isPathExists(pathNuxtConfig);
if (isNext) {
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "tsc",
args: "--noEmit --project ./tsconfig.json",
env: process.env,
cwd: `./apps-home/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (next) failed: exitCode=${exitCode}`);
}
return;
}
if (!isNuxt) {
// VitePress 项目,执行 ::: 标记格式修复
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "node",
args: `./apps-home/${appName}/scripts/lint.mts`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (vitepress) failed: exitCode=${exitCode}`);
}
return;
}
// Nuxt 项目,执行类型检查
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "cross-env",
args: `APP_NAME=${appName} nuxt typecheck --cwd=./apps-home/${appName}`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (nuxt typecheck) failed: exitCode=${exitCode}`);
}
});
}
/**
* 顺序处理所有 SSR APP(Nuxt SSR,执行类型检查)
*/
for (const appName of STANDALONE_SSR_APPS_NAMES) {
addTask(`ssr:${appName}`, async (payload) => {
const { progress, taskName } = payload;
const appNameDisplay = `${progress.current}/${progress.total}-${taskName}`;
// oxfmt
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxfmt",
args: `-c ../../.oxfmtrc.json --ignore-path ../../.oxfmtignore .`,
env: process.env,
cwd: `./apps-home/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxfmt) failed: exitCode=${exitCode}`);
}
}
// prettier
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "prettier",
args: `--write --cache --ignore-path ../../.prettierignore-sub .`,
env: process.env,
cwd: `./apps-home/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (prettier) failed: exitCode=${exitCode}`);
}
}
// oxlint
{
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "oxlint",
args: `-c .oxlintrc.json --fix --fix-suggestions ./apps-home/${appName}/`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (oxlint) failed: exitCode=${exitCode}`);
}
}
// Nuxt SSR,执行类型检查
const { promise } = runCommandInChildProcess({
appName: appNameDisplay,
command: "cross-env",
args: `APP_NAME=${appName} nuxt typecheck --cwd=./apps-home/${appName}`,
env: process.env,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (nuxt typecheck) failed: exitCode=${exitCode}`);
}
});
}
/**
* Android 壳检查:委托 client/android 子项目自身的 lint 流水线
* (prettier、eslint、markdownlint、tsc、gradlew lint 与 smoke 测试)
*/
addTask("android", async (payload) => {
const { progress, taskName } = payload;
const { promise } = runCommandInChildProcess({
appName: `${progress.current}/${progress.total}-${taskName}`,
command: "node",
args: "--run lint",
env: process.env,
cwd: "./client/android",
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} failed: exitCode=${exitCode}`);
}
});
/**
* Electron 壳检查:委托 client/electron 子项目自身的 lint 流水线
* (type-check、构建与 node:test)
*/
addTask("electron", async (payload) => {
const { progress, taskName } = payload;
const { promise } = runCommandInChildProcess({
appName: `${progress.current}/${progress.total}-${taskName}`,
command: "node",
args: "--run lint",
env: process.env,
cwd: "./client/electron",
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} failed: exitCode=${exitCode}`);
}
});
/**
* Chrome 扩展检查:脚本与页面类型检查、产品配置与 Manifest 测试
*/
addTask("chrome", async (payload) => {
const { progress, taskName } = payload;
const appNameDisplay = `${progress.current}/${progress.total}-${taskName}`;
// 类型检查:扩展脚本与 Webview 页面
for (const project of ["tsconfig.json", "tsconfig.webview.json"]) {
const { promise } = runCommandInChildProcess({
appName: `${appNameDisplay} (tsc ${project})`,
command: "tsc",
args: `--project ${project}`,
env: process.env,
cwd: "./client/chrome",
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (tsc ${project}) failed: exitCode=${exitCode}`);
}
}
// 单元测试:产品配置与 Manifest
{
const { promise } = runCommandInChildProcess({
appName: `${appNameDisplay} (test)`,
command: "node",
args: `--test "tests/*.test.mts"`,
env: process.env,
cwd: "./client/chrome",
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} (test) failed: exitCode=${exitCode}`);
}
}
});
/**
* VS Code 扩展检查:遍历 client/vsix/ 下所有子项目,各自委托子项目自身的 lint 流水线
* (宿主与 Webview 类型检查、桥接与面板单元测试)
*/
for (const appName of VSIX_APPS_NAMES) {
addTask(`vsix:${appName}`, async (payload) => {
const { progress, taskName } = payload;
const { promise } = runCommandInChildProcess({
appName: `${progress.current}/${progress.total}-${taskName}`,
command: "node",
args: "--run lint",
env: process.env,
cwd: `./client/vsix/${appName}`,
});
const exitCode = await promise;
if (exitCode) {
throw new Error(`Task ${taskName} failed: exitCode=${exitCode}`);
}
});
}
await runTasksSequentially();
printTaskStatisticsInfo();
// 所有检查通过后刷新 git 索引,清除格式化工具重写造成的假差异
const { hasRealChanges, status } = refreshGitIndex();
if (hasRealChanges) {
console.log("刷新完成,剩余真实差异:");
console.log(status);
} else {
console.log("刷新完成,工作区与索引内容一致,无真实差异。");
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387