@wrongstack/plugins 0.291.1 → 0.292.0

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.
@@ -1,6 +1,6 @@
1
1
  // src/shell-check/index.ts
2
- import { execFileSync, execSync } from "node:child_process";
3
- import { existsSync, readdirSync } from "node:fs";
2
+ import { execFile } from "node:child_process";
3
+ import { readdir } from "node:fs/promises";
4
4
  import { isAbsolute, join, relative, resolve } from "node:path";
5
5
  var API_VERSION = "^0.1.10";
6
6
  function withinProject(p) {
@@ -21,15 +21,23 @@ var state = {
21
21
  /** Most recent run summary, surfaced by health(). */
22
22
  lastRun: null
23
23
  };
24
- function runShellCheck(files, severity, cwd) {
25
- if (!existsSync("shellcheck")) {
26
- try {
27
- execSync("shellcheck --version", { encoding: "utf-8", stdio: "ignore", windowsHide: true });
28
- } catch {
29
- throw new Error(
30
- "shellcheck is not installed. Install via: apt install shellcheck / brew install shellcheck"
24
+ async function runShellCheck(files, severity, cwd) {
25
+ try {
26
+ await new Promise((resolvePromise, rejectPromise) => {
27
+ execFile(
28
+ "shellcheck",
29
+ ["--version"],
30
+ { encoding: "utf-8", windowsHide: true },
31
+ (err) => {
32
+ if (err) rejectPromise(err);
33
+ else resolvePromise();
34
+ }
31
35
  );
32
- }
36
+ });
37
+ } catch {
38
+ throw new Error(
39
+ "shellcheck is not installed. Install via: apt install shellcheck / brew install shellcheck"
40
+ );
33
41
  }
34
42
  const levelMap = {
35
43
  error: "error",
@@ -41,20 +49,34 @@ function runShellCheck(files, severity, cwd) {
41
49
  const args = ["-f", "json", "-S", severityFlag, ...files];
42
50
  let raw;
43
51
  try {
44
- raw = execFileSync("shellcheck", args, {
45
- encoding: "utf-8",
46
- cwd,
47
- stdio: ["pipe", "pipe", "pipe"],
48
- timeout: 6e4,
49
- windowsHide: true
52
+ raw = await new Promise((resolvePromise, rejectPromise) => {
53
+ execFile(
54
+ "shellcheck",
55
+ args,
56
+ {
57
+ encoding: "utf-8",
58
+ cwd,
59
+ windowsHide: true,
60
+ timeout: 6e4,
61
+ maxBuffer: 16 * 1024 * 1024
62
+ },
63
+ (err, stdout, stderr) => {
64
+ if (err) {
65
+ const e = err;
66
+ const diagnostic = stdout || e.stdout?.toString() || stderr || e.stderr?.toString() || "";
67
+ if (diagnostic.trim()) {
68
+ resolvePromise(diagnostic);
69
+ return;
70
+ }
71
+ rejectPromise(err);
72
+ return;
73
+ }
74
+ resolvePromise(stdout);
75
+ }
76
+ );
50
77
  });
51
- } catch (err) {
52
- const e = err;
53
- if (e.stderr && !e.stderr.includes("shellcheck")) {
54
- raw = e.stderr;
55
- } else {
56
- return [];
57
- }
78
+ } catch {
79
+ return [];
58
80
  }
59
81
  if (!raw.trim()) return [];
60
82
  try {
@@ -71,21 +93,23 @@ function runShellCheck(files, severity, cwd) {
71
93
  return [];
72
94
  }
73
95
  }
74
- function findShellFiles(dir, pattern) {
96
+ async function findShellFiles(dir, pattern) {
75
97
  const results = [];
98
+ let entries;
76
99
  try {
77
- const entries = readdirSync(dir, { withFileTypes: true });
78
- for (const entry of entries) {
79
- const full = join(dir, entry.name);
80
- if (entry.isDirectory() && entry.name !== "node_modules" && entry.name !== ".git") {
81
- results.push(...findShellFiles(full, pattern));
82
- } else if (entry.isFile() && (entry.name.endsWith(".sh") || entry.name === "Dockerfile")) {
83
- if (!pattern || entry.name.includes(pattern)) {
84
- results.push(full);
85
- }
100
+ entries = await readdir(dir, { withFileTypes: true });
101
+ } catch {
102
+ return results;
103
+ }
104
+ for (const entry of entries) {
105
+ const full = join(dir, entry.name);
106
+ if (entry.isDirectory() && entry.name !== "node_modules" && entry.name !== ".git") {
107
+ results.push(...await findShellFiles(full, pattern));
108
+ } else if (entry.isFile() && (entry.name.endsWith(".sh") || entry.name === "Dockerfile")) {
109
+ if (!pattern || entry.name.includes(pattern)) {
110
+ results.push(full);
86
111
  }
87
112
  }
88
- } catch {
89
113
  }
90
114
  return results;
91
115
  }
@@ -186,7 +210,7 @@ var plugin = {
186
210
  if (files && files.length > 0) {
187
211
  checkFiles = files;
188
212
  } else {
189
- checkFiles = findShellFiles(directory, pattern);
213
+ checkFiles = await findShellFiles(directory, pattern);
190
214
  scannedDirectories = true;
191
215
  }
192
216
  if (checkFiles.length === 0) {
@@ -207,7 +231,7 @@ var plugin = {
207
231
  }
208
232
  let issues;
209
233
  try {
210
- issues = runShellCheck(checkFiles, severity);
234
+ issues = await runShellCheck(checkFiles, severity);
211
235
  } catch (err) {
212
236
  const msg = err instanceof Error ? err.message : String(err);
213
237
  return { ok: false, error: msg, issues: [], filesScanned: 0 };