@apdesign/code-style-react 1.1.6 → 1.1.7

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apdesign/code-style-react",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "scripts": {},
5
5
  "bin": {
6
6
  "apdesign-code-style": "cli.js"
@@ -5,26 +5,23 @@ let path;
5
5
  let fs;
6
6
  let os;
7
7
  let glob;
8
- let ESLint;
9
8
 
10
9
  async function runEslint() {
11
10
  try {
12
11
  if (typeof require !== 'undefined') {
13
12
  // CommonJS
14
- spawnSync = require('child_process').spawnSync;
13
+ ({ spawnSync, spawn } = require('child_process'));
15
14
  path = require('path');
16
15
  fs = require('fs');
17
16
  os = require('os');
18
17
  glob = require('glob');
19
- ESLint = require('eslint').ESLint;
20
18
  } else {
21
19
  // ESM
22
- spawnSync = await import('node:child_process').spawnSync;
20
+ ({ spawnSync, spawn } = await import('node:child_process'));
23
21
  path = await import('node:path');
24
22
  fs = await import('node:fs');
25
23
  os = await import('node:os');
26
24
  glob = (await import('glob')).default;
27
- ESLint = (await import('eslint')).ESLint;
28
25
  }
29
26
 
30
27
  // 参数解析
@@ -167,25 +164,41 @@ async function runEslint() {
167
164
  console.log(`🔍 检查目录: ${eslintTarget}`);
168
165
  }
169
166
 
170
- const eslint = new ESLint({ cwd: rootDir, threads: maxWorkers || undefined });
171
- const files = glob.sync('**/*.{js,jsx,ts,tsx}', { cwd: eslintTarget, absolute: true });
172
- if (files.length === 0) {
167
+ const allFiles = glob.sync('**/*.{js,jsx,ts,tsx}', { cwd: eslintTarget, absolute: true });
168
+ if (!allFiles.length) {
173
169
  console.log('- 没有需要检查的文件');
174
170
  return;
175
171
  }
176
172
 
173
+ const cpuCount = os.cpus().length;
174
+ const workers = maxWorkers || cpuCount;
175
+ const chunkSize = Math.ceil(allFiles.length / workers);
176
+ const chunks = [];
177
+ for (let i = 0; i < allFiles.length; i += chunkSize) {
178
+ chunks.push(allFiles.slice(i, i + chunkSize));
179
+ }
180
+
177
181
  console.log(`[ESLint 执行]`);
178
182
  console.log(`文件总数: ${files.length}`);
179
183
  console.log('');
180
184
  console.log('🚀 开始执行 ESLint ...\n');
181
185
 
182
- const results = await eslint.lintFiles(files);
183
- const formatter = await eslint.loadFormatter('stylish');
184
- const resultText = formatter.format(results);
185
- console.log(resultText);
186
+ let finished = 0;
187
+ let hasError = false;
188
+
189
+ chunks.forEach((chunk) => {
190
+ const eslintProcess = require('child_process').spawn(
191
+ 'npx',
192
+ ['eslint', ...chunk, '--ext', 'js,jsx,ts,tsx', '--report-unused-disable-directives'],
193
+ { cwd: rootDir, stdio: 'inherit', shell: true },
194
+ );
186
195
 
187
- const hasError = results.some((r) => r.errorCount > 0);
188
- process.exit(hasError ? 1 : 0);
196
+ eslintProcess.on('close', (code) => {
197
+ if (code !== 0) hasError = true;
198
+ finished++;
199
+ if (finished === chunks.length) process.exit(hasError ? 1 : 0);
200
+ });
201
+ });
189
202
  } catch (err) {
190
203
  console.error('❌ 脚本执行出错:', err);
191
204
  process.exit(1);