@atlisp/lint 0.2.6 → 0.2.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/dist/runner.js CHANGED
@@ -235,7 +235,7 @@ function lintFilesParallel(files, config, rootDir) {
235
235
  (0, locale_1.setLocale)(config.locale || 'zh');
236
236
  return new Promise(resolve => {
237
237
  const allIssues = [];
238
- let completed = 0;
238
+ const completed = new Set();
239
239
  const maxWorkers = Math.min(os.cpus().length, files.length);
240
240
  let nextIndex = 0;
241
241
  function startWorker() {
@@ -248,14 +248,18 @@ function lintFilesParallel(files, config, rootDir) {
248
248
  workerData: { filepath, relPath, config },
249
249
  });
250
250
  worker.on('message', (msg) => {
251
+ if (completed.has(idx))
252
+ return;
253
+ completed.add(idx);
251
254
  allIssues.push(...msg.issues);
252
- completed++;
253
- worker.terminate();
254
255
  startWorker();
255
- if (completed >= files.length)
256
+ if (completed.size >= files.length)
256
257
  resolve(allIssues);
257
258
  });
258
259
  worker.on('error', (err) => {
260
+ if (completed.has(idx))
261
+ return;
262
+ completed.add(idx);
259
263
  allIssues.push({
260
264
  file: relPath,
261
265
  line: 1,
@@ -263,13 +267,14 @@ function lintFilesParallel(files, config, rootDir) {
263
267
  rule: 'worker',
264
268
  message: err.message,
265
269
  });
266
- completed++;
267
- worker.terminate();
268
270
  startWorker();
269
- if (completed >= files.length)
271
+ if (completed.size >= files.length)
270
272
  resolve(allIssues);
271
273
  });
272
274
  worker.on('exit', code => {
275
+ if (completed.has(idx))
276
+ return;
277
+ completed.add(idx);
273
278
  if (code !== 0) {
274
279
  allIssues.push({
275
280
  file: relPath,
@@ -278,11 +283,10 @@ function lintFilesParallel(files, config, rootDir) {
278
283
  rule: 'worker',
279
284
  message: `Worker exited with code ${code}`,
280
285
  });
281
- completed++;
282
- startWorker();
283
- if (completed >= files.length)
284
- resolve(allIssues);
285
286
  }
287
+ startWorker();
288
+ if (completed.size >= files.length)
289
+ resolve(allIssues);
286
290
  });
287
291
  }
288
292
  for (let i = 0; i < maxWorkers; i++) {
package/dist/worker.js CHANGED
@@ -4,17 +4,26 @@ const worker_threads_1 = require("worker_threads");
4
4
  const fs_1 = require("fs");
5
5
  const locale_1 = require("./locale");
6
6
  const runner_1 = require("./runner");
7
+ function sendMessage(output) {
8
+ if (!worker_threads_1.parentPort)
9
+ return;
10
+ try {
11
+ worker_threads_1.parentPort.postMessage(output);
12
+ }
13
+ catch {
14
+ // Port already closed, nothing we can do
15
+ }
16
+ }
7
17
  if (worker_threads_1.parentPort && worker_threads_1.workerData) {
8
18
  const input = worker_threads_1.workerData;
9
19
  (0, locale_1.setLocale)(input.config.locale || 'zh');
10
20
  try {
11
21
  const content = (0, fs_1.readFileSync)(input.filepath, 'utf-8');
12
22
  const issues = (0, runner_1.runChecks)(content, input.relPath, input.config);
13
- const output = { filepath: input.filepath, issues };
14
- worker_threads_1.parentPort.postMessage(output);
23
+ sendMessage({ filepath: input.filepath, issues });
15
24
  }
16
25
  catch {
17
- const output = {
26
+ sendMessage({
18
27
  filepath: input.filepath,
19
28
  issues: [
20
29
  {
@@ -25,8 +34,7 @@ if (worker_threads_1.parentPort && worker_threads_1.workerData) {
25
34
  message: 'Cannot read file',
26
35
  },
27
36
  ],
28
- };
29
- worker_threads_1.parentPort.postMessage(output);
37
+ });
30
38
  }
31
39
  }
32
40
  //# sourceMappingURL=worker.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlisp/lint",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "AutoLISP static analysis tool — parens, security, conventions, SBCL syntax validation",
5
5
  "keywords": [
6
6
  "CAD",