@lark-apaas/fullstack-cli 1.1.68-alpha.20260920210907 → 1.1.68-alpha.20260920222630
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
|
@@ -17,9 +17,56 @@ function failAndExit(step, body) {
|
|
|
17
17
|
process.exit(1);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
function getStagedFiles() {
|
|
21
|
+
const res = spawnSync(
|
|
22
|
+
'git',
|
|
23
|
+
['diff', '--cached', '--name-status', '--find-renames', '-z'],
|
|
24
|
+
{
|
|
25
|
+
cwd: process.cwd(),
|
|
26
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
27
|
+
encoding: 'utf8',
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
if (res.error) {
|
|
31
|
+
failAndExit('staged files', String(res.error.message || res.error));
|
|
32
|
+
}
|
|
33
|
+
if (res.status !== 0) {
|
|
34
|
+
failAndExit('staged files', `${res.stdout || ''}\n${res.stderr || ''}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const fields = (res.stdout || '').split('\0');
|
|
38
|
+
const files = [];
|
|
39
|
+
for (let index = 0; index < fields.length;) {
|
|
40
|
+
const status = fields[index++];
|
|
41
|
+
if (!status) break;
|
|
42
|
+
const sourcePath = fields[index++];
|
|
43
|
+
if (!sourcePath) failAndExit('staged files', `Malformed git diff output for status ${status}`);
|
|
44
|
+
|
|
45
|
+
if (status.startsWith('R') || status.startsWith('C')) {
|
|
46
|
+
const destinationPath = fields[index++];
|
|
47
|
+
if (!destinationPath) failAndExit('staged files', `Malformed git diff output for status ${status}`);
|
|
48
|
+
// Renames can cross client/server/shared boundaries. Keep both paths so
|
|
49
|
+
// lint.js can select every affected typecheck, while ignoring a missing
|
|
50
|
+
// source path for file-level linters. Copies do not remove the source.
|
|
51
|
+
if (status.startsWith('R')) files.push(sourcePath);
|
|
52
|
+
files.push(destinationPath);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
files.push(sourcePath);
|
|
57
|
+
}
|
|
58
|
+
return files;
|
|
59
|
+
}
|
|
60
|
+
|
|
20
61
|
function runLint() {
|
|
21
62
|
const cwd = process.cwd();
|
|
22
|
-
const
|
|
63
|
+
const stagedFiles = getStagedFiles();
|
|
64
|
+
if (stagedFiles.length === 0) {
|
|
65
|
+
process.stdout.write('[pre-commit] No staged files to lint\n');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const res = spawnSync('npm', ['run', 'lint', '--', '--files', ...stagedFiles], {
|
|
23
70
|
cwd,
|
|
24
71
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
25
72
|
env: process.env,
|
|
@@ -40,12 +40,6 @@ function normalizeProjectFile(filePath) {
|
|
|
40
40
|
const absolutePath = path.isAbsolute(filePath)
|
|
41
41
|
? filePath
|
|
42
42
|
: path.resolve(cwd, filePath);
|
|
43
|
-
|
|
44
|
-
if (!fs.existsSync(absolutePath)) {
|
|
45
|
-
console.warn(`[lint] Skip missing file: ${filePath}`);
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
43
|
const relativePath = path.relative(cwd, absolutePath);
|
|
50
44
|
if (relativePath.startsWith('..')) {
|
|
51
45
|
console.warn(`[lint] Skip file outside project: ${filePath}`);
|
|
@@ -162,8 +156,15 @@ async function runSelectiveLint(inputFiles) {
|
|
|
162
156
|
process.exit(0);
|
|
163
157
|
}
|
|
164
158
|
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
// Deleted files and the source side of renames must still select the
|
|
160
|
+
// affected project typecheck, but must not be passed to file-level linters.
|
|
161
|
+
const existingFiles = normalizedFiles.filter(filePath => {
|
|
162
|
+
const exists = fs.existsSync(path.join(cwd, filePath));
|
|
163
|
+
if (!exists) console.warn(`[lint] Skip missing file-level target: ${filePath}`);
|
|
164
|
+
return exists;
|
|
165
|
+
});
|
|
166
|
+
const eslintFiles = existingFiles.filter(isEslintTarget);
|
|
167
|
+
const stylelintFiles = existingFiles.filter(isStylelintTarget);
|
|
167
168
|
const typeCheckFiles = normalizedFiles.filter(isTypeCheckTarget);
|
|
168
169
|
|
|
169
170
|
const clientTypeFiles = [];
|