@lark-apaas/fullstack-cli 1.1.68-alpha.20260920222123 → 1.1.68-alpha.20260930060426
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/package.json
CHANGED
|
@@ -6,57 +6,47 @@ const { spawnSync } = require('node:child_process');
|
|
|
6
6
|
|
|
7
7
|
const SEP = ' ' + '─'.repeat(36);
|
|
8
8
|
|
|
9
|
-
function failAndExit(step, body) {
|
|
9
|
+
function failAndExit(step, body, code) {
|
|
10
10
|
process.stderr.write('\n✗ pre-commit failed: ' + step + '\n');
|
|
11
|
+
process.stderr.write(' command: npm run lint\n');
|
|
11
12
|
process.stderr.write(SEP + '\n');
|
|
12
13
|
if (body && body.length > 0) {
|
|
13
|
-
process.stderr.write(body
|
|
14
|
+
process.stderr.write(body);
|
|
15
|
+
if (!body.endsWith('\n')) process.stderr.write('\n');
|
|
14
16
|
}
|
|
15
17
|
process.stderr.write(SEP + '\n');
|
|
16
|
-
process.stderr.write(
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getStagedFiles() {
|
|
21
|
-
const res = spawnSync(
|
|
22
|
-
'git',
|
|
23
|
-
['diff', '--cached', '--name-only', '--diff-filter=ACMR', '-z'],
|
|
24
|
-
{
|
|
25
|
-
cwd: process.cwd(),
|
|
26
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
27
|
-
encoding: 'utf8',
|
|
28
|
-
},
|
|
18
|
+
process.stderr.write(
|
|
19
|
+
' 修复可编辑代码并重跑 npm run lint(原项目完整检查)。\n'
|
|
29
20
|
);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return (res.stdout || '').split('\0').filter(Boolean);
|
|
21
|
+
process.stderr.write(
|
|
22
|
+
' 命中平台受保护路径时停止反复编辑该文件或检查配置;记录路径、规则和检查原始输出,交有权限的平台维护者修复并复查。\n'
|
|
23
|
+
);
|
|
24
|
+
process.stderr.write(' 检查仍未通过;不得声称检查或提交成功。\n');
|
|
25
|
+
process.exit(code);
|
|
38
26
|
}
|
|
39
27
|
|
|
40
28
|
function runLint() {
|
|
41
29
|
const cwd = process.cwd();
|
|
42
|
-
const
|
|
43
|
-
if (stagedFiles.length === 0) {
|
|
44
|
-
process.stdout.write('[pre-commit] No staged files to lint\n');
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const res = spawnSync('npm', ['run', 'lint', '--', '--files', ...stagedFiles], {
|
|
30
|
+
const res = spawnSync('npm', ['run', 'lint'], {
|
|
49
31
|
cwd,
|
|
50
32
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
51
33
|
env: process.env,
|
|
52
34
|
});
|
|
53
35
|
if (res.error) {
|
|
54
|
-
failAndExit('lint', String(res.error.message || res.error));
|
|
36
|
+
failAndExit('lint', String(res.error.message || res.error), 1);
|
|
55
37
|
}
|
|
56
38
|
if (res.status !== 0) {
|
|
57
39
|
const stdout = res.stdout ? res.stdout.toString() : '';
|
|
58
40
|
const stderr = res.stderr ? res.stderr.toString() : '';
|
|
59
|
-
|
|
41
|
+
const body =
|
|
42
|
+
stdout +
|
|
43
|
+
(stdout && stderr && !stdout.endsWith('\n') ? '\n' : '') +
|
|
44
|
+
stderr;
|
|
45
|
+
failAndExit(
|
|
46
|
+
'lint',
|
|
47
|
+
body + (res.signal ? '\nTerminated by signal: ' + res.signal : ''),
|
|
48
|
+
res.status ?? 1
|
|
49
|
+
);
|
|
60
50
|
}
|
|
61
51
|
}
|
|
62
52
|
|
|
@@ -64,15 +64,6 @@ function parseFilesArg(argv) {
|
|
|
64
64
|
return argv.slice(filesIndex + 1).filter(Boolean);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function parseMode(argv) {
|
|
68
|
-
if (argv.length === 0) return { type: 'default' };
|
|
69
|
-
if (argv.length === 1 && argv[0] === '--typecheck') return { type: 'typecheck' };
|
|
70
|
-
if (argv[0] === '--files' && argv.length > 1 && argv.slice(1).every(arg => !arg.startsWith('--'))) {
|
|
71
|
-
return { type: 'files', files: argv.slice(1) };
|
|
72
|
-
}
|
|
73
|
-
throw new Error('Usage: lint.js [--typecheck | --files <paths...>]');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
67
|
function isEslintTarget(filePath) {
|
|
77
68
|
return /\.(c|m)?(j|t)sx?$/.test(filePath);
|
|
78
69
|
}
|
|
@@ -116,14 +107,6 @@ function canRunStylelint() {
|
|
|
116
107
|
return STYLELINT_CONFIG_FILES.some(file => fs.existsSync(path.join(cwd, file)));
|
|
117
108
|
}
|
|
118
109
|
|
|
119
|
-
function packageScripts() {
|
|
120
|
-
try {
|
|
121
|
-
return JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8')).scripts || {};
|
|
122
|
-
} catch {
|
|
123
|
-
return {};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
110
|
async function runDefaultLint() {
|
|
128
111
|
const taskSpecs = [
|
|
129
112
|
[getBinName('npm'), ['run', 'eslint']],
|
|
@@ -139,19 +122,6 @@ async function runDefaultLint() {
|
|
|
139
122
|
process.exit(await runTasksSerially(taskSpecs));
|
|
140
123
|
}
|
|
141
124
|
|
|
142
|
-
async function runTypeCheck() {
|
|
143
|
-
const scripts = packageScripts();
|
|
144
|
-
const names = ['type:check:server', 'type:check:client'];
|
|
145
|
-
const missing = names.filter(name => !scripts[name]);
|
|
146
|
-
if (missing.length > 0) {
|
|
147
|
-
throw new Error(`Missing required npm scripts: ${missing.join(', ')}`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
process.exit(await runTasksSerially(
|
|
151
|
-
names.map(name => [getBinName('npm'), ['run', name]]),
|
|
152
|
-
));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
125
|
async function runSelectiveLint(inputFiles) {
|
|
156
126
|
const normalizedFiles = Array.from(
|
|
157
127
|
new Set(inputFiles.map(normalizeProjectFile).filter(Boolean)),
|
|
@@ -209,19 +179,18 @@ async function runSelectiveLint(inputFiles) {
|
|
|
209
179
|
}
|
|
210
180
|
|
|
211
181
|
async function main() {
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
await runTypeCheck();
|
|
182
|
+
const files = parseFilesArg(process.argv.slice(2));
|
|
183
|
+
if (files === null) {
|
|
184
|
+
await runDefaultLint();
|
|
216
185
|
return;
|
|
217
186
|
}
|
|
218
187
|
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
188
|
+
if (files.length === 0) {
|
|
189
|
+
console.error('[lint] --files requires at least one file path');
|
|
190
|
+
process.exit(1);
|
|
222
191
|
}
|
|
223
192
|
|
|
224
|
-
await runSelectiveLint(
|
|
193
|
+
await runSelectiveLint(files);
|
|
225
194
|
}
|
|
226
195
|
|
|
227
196
|
main().catch((error) => {
|