@wrongstack/plugins 0.308.6 → 0.309.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.
- package/dist/accessibility-auditor.js +26 -82
- package/dist/agent-handoff.js +16 -26
- package/dist/auto-i18n-extractor.js +19 -23
- package/dist/branch-guard.js +19 -111
- package/dist/changelog-writer.js +20 -133
- package/dist/code-metrics.js +26 -71
- package/dist/commit-validator.js +16 -14
- package/dist/config-validator.js +18 -22
- package/dist/cost-tracker.js +15 -96
- package/dist/dead-code-detector.js +27 -31
- package/dist/dependency-vulnerability-gate.js +18 -15
- package/dist/diff-summary.js +19 -128
- package/dist/doc-sync-guard.js +24 -39
- package/dist/duplicate-code-detector.js +30 -169
- package/dist/feature-flag-tracker.js +26 -71
- package/dist/file-watcher.js +19 -23
- package/dist/format-on-save.js +25 -214
- package/dist/import-organizer.js +31 -106
- package/dist/index.js +452 -1236
- package/dist/interface-contract-guard.js +26 -71
- package/dist/lint-gate.js +19 -111
- package/dist/migration-planner.js +28 -120
- package/dist/notify-hub.js +18 -28
- package/dist/path-guard.js +27 -102
- package/dist/pr-drafter.js +18 -16
- package/dist/prompt-firewall.js +8 -205
- package/dist/refactor-suggester.js +27 -166
- package/dist/release-notes-generator.js +6 -35
- package/dist/runtime/bounded-map.d.ts +2 -85
- package/dist/runtime/credential-patterns.d.ts +2 -41
- package/dist/runtime/h1-state.d.ts +2 -61
- package/dist/runtime/handles.d.ts +2 -45
- package/dist/runtime/index.d.ts +8 -180
- package/dist/runtime/llm.d.ts +2 -43
- package/dist/runtime/local-bin.d.ts +2 -119
- package/dist/runtime/redos-guard.d.ts +2 -68
- package/dist/runtime/safe-json.d.ts +2 -24
- package/dist/runtime/sandbox.d.ts +2 -58
- package/dist/runtime.js +1 -868
- package/dist/schema-evolution-guard.js +20 -24
- package/dist/secret-scanner.js +22 -146
- package/dist/security-hotspot-scanner.js +24 -154
- package/dist/session-recap.js +16 -14
- package/dist/spec-linker.js +19 -17
- package/dist/template-engine.js +22 -37
- package/dist/test-coverage-gate.js +19 -34
- package/dist/test-generator.js +6 -35
- package/dist/test-runner-gate.js +34 -143
- package/dist/todo-listener.js +17 -38
- package/dist/type-gate.js +23 -311
- package/package.json +4 -3
|
@@ -1,70 +1,25 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
|
|
1
15
|
// src/feature-flag-tracker/index.ts
|
|
2
16
|
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { isAbsolute
|
|
4
|
-
|
|
5
|
-
// src/runtime/index.ts
|
|
6
|
-
import { basename, extname, isAbsolute, relative, resolve } from "node:path";
|
|
7
|
-
|
|
8
|
-
// src/runtime/local-bin.ts
|
|
9
|
-
import { buildWin32CmdShimInvocation, resolveWin32Command } from "@wrongstack/tools/win32";
|
|
17
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
10
18
|
|
|
11
19
|
// src/runtime/index.ts
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
function withinProjectPath(projectRoot, candidate) {
|
|
17
|
-
if (candidate.length === 0 || candidate.length > 4096) return false;
|
|
18
|
-
if (hasLeadingDash(candidate)) return false;
|
|
19
|
-
const resolved = isAbsolute(candidate) ? resolve(candidate) : resolve(projectRoot, candidate);
|
|
20
|
-
const rel = relative(projectRoot, resolved);
|
|
21
|
-
return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
|
|
22
|
-
}
|
|
23
|
-
function withinProject(p) {
|
|
24
|
-
const cwd = process.cwd();
|
|
25
|
-
return withinProjectPath(cwd, p) || relative(cwd, p) === ".";
|
|
26
|
-
}
|
|
27
|
-
var DEFAULT_EXCLUDE_DIRS = ["node_modules", "dist", ".git", "coverage"];
|
|
28
|
-
async function collectSourceFilesAsync(root, opts) {
|
|
29
|
-
const { readdir, stat } = await import("node:fs/promises");
|
|
30
|
-
const files = [];
|
|
31
|
-
try {
|
|
32
|
-
const s = await stat(root);
|
|
33
|
-
if (s.isFile()) {
|
|
34
|
-
if (matchesExtension(root, opts.extensions)) files.push(root);
|
|
35
|
-
return files;
|
|
36
|
-
}
|
|
37
|
-
if (!s.isDirectory()) return files;
|
|
38
|
-
} catch {
|
|
39
|
-
return files;
|
|
40
|
-
}
|
|
41
|
-
const exclude = opts.excludeDirs ?? DEFAULT_EXCLUDE_DIRS;
|
|
42
|
-
const excludeSet = new Set(exclude);
|
|
43
|
-
async function walk(dir, depth) {
|
|
44
|
-
if (opts.maxDepth !== void 0 && depth > opts.maxDepth) return;
|
|
45
|
-
let entries;
|
|
46
|
-
try {
|
|
47
|
-
entries = await readdir(dir, { withFileTypes: true });
|
|
48
|
-
} catch {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
52
|
-
for (const entry of entries) {
|
|
53
|
-
if (excludeSet.has(entry.name)) continue;
|
|
54
|
-
const full = resolve(dir, entry.name);
|
|
55
|
-
if (entry.isDirectory()) {
|
|
56
|
-
await walk(full, depth + 1);
|
|
57
|
-
} else if (entry.isFile() && matchesExtension(full, opts.extensions)) {
|
|
58
|
-
files.push(full);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
await walk(root, 0);
|
|
63
|
-
return files;
|
|
64
|
-
}
|
|
65
|
-
function matchesExtension(p, exts) {
|
|
66
|
-
return exts.includes(extname(p).toLowerCase());
|
|
67
|
-
}
|
|
20
|
+
var runtime_exports = {};
|
|
21
|
+
__reExport(runtime_exports, runtime_star);
|
|
22
|
+
import * as runtime_star from "@wrongstack/plugin-sdk/runtime";
|
|
68
23
|
|
|
69
24
|
// src/feature-flag-tracker/index.ts
|
|
70
25
|
var API_VERSION = "^0.1.10";
|
|
@@ -105,7 +60,7 @@ function toPosix(p) {
|
|
|
105
60
|
return p.replace(/\\/g, "/");
|
|
106
61
|
}
|
|
107
62
|
function relativePath(p) {
|
|
108
|
-
return toPosix(
|
|
63
|
+
return toPosix(relative(process.cwd(), p));
|
|
109
64
|
}
|
|
110
65
|
function compilePatterns(patterns) {
|
|
111
66
|
const out = [];
|
|
@@ -141,9 +96,9 @@ function scanFile(filePath, content, patterns, maxFindings) {
|
|
|
141
96
|
}
|
|
142
97
|
async function scanPath(rawPath, cfg) {
|
|
143
98
|
const root = process.cwd();
|
|
144
|
-
const resolved =
|
|
99
|
+
const resolved = isAbsolute(rawPath) ? resolve(rawPath) : resolve(root, rawPath);
|
|
145
100
|
const exts = normalizeExtensions(cfg.extensions);
|
|
146
|
-
const files = await collectSourceFilesAsync(resolved, { extensions: exts });
|
|
101
|
+
const files = await (0, runtime_exports.collectSourceFilesAsync)(resolved, { extensions: exts });
|
|
147
102
|
const patterns = compilePatterns(cfg.patterns);
|
|
148
103
|
const usages = [];
|
|
149
104
|
let scannedFiles = 0;
|
|
@@ -219,11 +174,11 @@ var plugin = {
|
|
|
219
174
|
const inp = input.toolInput ?? {};
|
|
220
175
|
const sourcePath = inp["path"];
|
|
221
176
|
if (!sourcePath || typeof sourcePath !== "string") return;
|
|
222
|
-
if (!withinProject(sourcePath)) return;
|
|
177
|
+
if (!(0, runtime_exports.withinProject)(sourcePath)) return;
|
|
223
178
|
const exts = normalizeExtensions(cfg.extensions);
|
|
224
|
-
if (!matchesExtension(sourcePath, exts)) return;
|
|
179
|
+
if (!(0, runtime_exports.matchesExtension)(sourcePath, exts)) return;
|
|
225
180
|
state.hookInvocationCount += 1;
|
|
226
|
-
const resolved =
|
|
181
|
+
const resolved = resolve(process.cwd(), sourcePath);
|
|
227
182
|
let content;
|
|
228
183
|
try {
|
|
229
184
|
content = await readFile(resolved, "utf-8");
|
|
@@ -258,7 +213,7 @@ Make sure flag behavior is intentional and consider updating flag inventory/docs
|
|
|
258
213
|
async execute(input) {
|
|
259
214
|
if (!cfg.enabled) return { ok: false, error: "feature-flag-tracker is disabled" };
|
|
260
215
|
const rawPath = typeof input.path === "string" ? input.path : ".";
|
|
261
|
-
if (!withinProject(rawPath)) {
|
|
216
|
+
if (!(0, runtime_exports.withinProject)(rawPath)) {
|
|
262
217
|
return { ok: false, error: "path is outside the project root" };
|
|
263
218
|
}
|
|
264
219
|
state.scanCount += 1;
|
|
@@ -272,7 +227,7 @@ Make sure flag behavior is intentional and consider updating flag inventory/docs
|
|
|
272
227
|
state.flagCount += result.usages.length;
|
|
273
228
|
return {
|
|
274
229
|
ok: true,
|
|
275
|
-
path: relativePath(
|
|
230
|
+
path: relativePath(resolve(process.cwd(), rawPath)),
|
|
276
231
|
scannedFiles: result.scannedFiles,
|
|
277
232
|
discoveredFiles: result.discoveredFiles,
|
|
278
233
|
// Say so when the cap stopped the walk early: a partial scan
|
package/dist/file-watcher.js
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
|
|
1
15
|
// src/file-watcher/index.ts
|
|
2
16
|
import { watch as fsWatch } from "node:fs";
|
|
3
17
|
import { join } from "node:path";
|
|
4
18
|
|
|
5
19
|
// src/runtime/index.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { buildWin32CmdShimInvocation, resolveWin32Command } from "@wrongstack/tools/win32";
|
|
10
|
-
|
|
11
|
-
// src/runtime/index.ts
|
|
12
|
-
var MAX_BUFFER_BYTES = 16 * 1024 * 1024;
|
|
13
|
-
function hasLeadingDash(arg) {
|
|
14
|
-
return arg.length > 0 && arg.startsWith("-");
|
|
15
|
-
}
|
|
16
|
-
function withinProjectPath(projectRoot, candidate) {
|
|
17
|
-
if (candidate.length === 0 || candidate.length > 4096) return false;
|
|
18
|
-
if (hasLeadingDash(candidate)) return false;
|
|
19
|
-
const resolved = isAbsolute(candidate) ? resolve(candidate) : resolve(projectRoot, candidate);
|
|
20
|
-
const rel = relative(projectRoot, resolved);
|
|
21
|
-
return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
|
|
22
|
-
}
|
|
23
|
-
function withinProject(p) {
|
|
24
|
-
const cwd = process.cwd();
|
|
25
|
-
return withinProjectPath(cwd, p) || relative(cwd, p) === ".";
|
|
26
|
-
}
|
|
20
|
+
var runtime_exports = {};
|
|
21
|
+
__reExport(runtime_exports, runtime_star);
|
|
22
|
+
import * as runtime_star from "@wrongstack/plugin-sdk/runtime";
|
|
27
23
|
|
|
28
24
|
// src/file-watcher/index.ts
|
|
29
25
|
var API_VERSION = "^0.1.10";
|
|
@@ -107,7 +103,7 @@ var plugin = {
|
|
|
107
103
|
}
|
|
108
104
|
const autoIndex = api.config.extensions?.["file-watcher"]?.["autoIndex"] ?? false;
|
|
109
105
|
const indexProjectRoot = api.config.extensions?.["file-watcher"]?.["indexProjectRoot"] ?? "";
|
|
110
|
-
const safeIndexRoot = indexProjectRoot !== "" && withinProject(indexProjectRoot) ? indexProjectRoot : "";
|
|
106
|
+
const safeIndexRoot = indexProjectRoot !== "" && (0, runtime_exports.withinProject)(indexProjectRoot) ? indexProjectRoot : "";
|
|
111
107
|
if (indexProjectRoot !== "" && safeIndexRoot === "") {
|
|
112
108
|
api.log.warn(
|
|
113
109
|
"file-watcher: indexProjectRoot is outside the project root \u2014 using watched dirPath instead",
|
|
@@ -252,7 +248,7 @@ var plugin = {
|
|
|
252
248
|
}
|
|
253
249
|
const events = input["events"] ?? ["change", "add", "delete"];
|
|
254
250
|
const recursive = input["recursive"] ?? true;
|
|
255
|
-
const bad = paths.find((p) => !withinProject(p));
|
|
251
|
+
const bad = paths.find((p) => !(0, runtime_exports.withinProject)(p));
|
|
256
252
|
if (bad !== void 0) {
|
|
257
253
|
return {
|
|
258
254
|
ok: false,
|
package/dist/format-on-save.js
CHANGED
|
@@ -1,215 +1,26 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
|
|
1
15
|
// src/format-on-save/index.ts
|
|
2
16
|
import { execFile } from "node:child_process";
|
|
3
17
|
import { createHash } from "node:crypto";
|
|
4
18
|
import { access, readFile, stat } from "node:fs/promises";
|
|
5
19
|
|
|
6
20
|
// src/runtime/index.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { createRequire } from "node:module";
|
|
11
|
-
import { delimiter, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
12
|
-
import { accessSync, constants, readFileSync } from "node:fs";
|
|
13
|
-
import { buildWin32CmdShimInvocation, resolveWin32Command } from "@wrongstack/tools/win32";
|
|
14
|
-
function resolveExecInvocation(command, args = []) {
|
|
15
|
-
const resolved = resolveWin32Command(command);
|
|
16
|
-
const normalizedResolved = resolved.toLowerCase();
|
|
17
|
-
const needsShell = process.platform === "win32" && (normalizedResolved.endsWith(".cmd") || normalizedResolved.endsWith(".bat"));
|
|
18
|
-
if (needsShell) {
|
|
19
|
-
const shim = buildWin32CmdShimInvocation(resolved, args);
|
|
20
|
-
return { cmd: shim.command, args: shim.args, windowsVerbatimArguments: true };
|
|
21
|
-
}
|
|
22
|
-
return { cmd: resolved, args: [...args], windowsVerbatimArguments: false };
|
|
23
|
-
}
|
|
24
|
-
function findOnPath(cmd) {
|
|
25
|
-
if (!cmd) return null;
|
|
26
|
-
const exists = (p) => {
|
|
27
|
-
try {
|
|
28
|
-
accessSync(p, constants.X_OK);
|
|
29
|
-
return true;
|
|
30
|
-
} catch {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
if (cmd.includes("/") || cmd.includes("\\")) {
|
|
35
|
-
return exists(cmd) ? resolve(cmd) : null;
|
|
36
|
-
}
|
|
37
|
-
const suffixes = process.platform === "win32" && extname(cmd) === "" ? (process.env["PATHEXT"] ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
38
|
-
for (const dir of (process.env["PATH"] ?? "").split(delimiter)) {
|
|
39
|
-
if (!dir) continue;
|
|
40
|
-
const base = join(dir, cmd);
|
|
41
|
-
for (const suffix of suffixes) {
|
|
42
|
-
const candidate = `${base}${suffix}`;
|
|
43
|
-
if (exists(candidate)) return candidate;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
function isInside(parent, candidate) {
|
|
49
|
-
const rel = relative(parent, candidate);
|
|
50
|
-
return rel === "" || !rel.startsWith(`..${sep}`) && rel !== ".." && !isAbsolute(rel);
|
|
51
|
-
}
|
|
52
|
-
var binCache = /* @__PURE__ */ new Map();
|
|
53
|
-
var BIN_CACHE_MAX = 64;
|
|
54
|
-
var NEGATIVE_BIN_CACHE_TTL_MS = 5e3;
|
|
55
|
-
function cachePut(key, value) {
|
|
56
|
-
while (binCache.size >= BIN_CACHE_MAX) {
|
|
57
|
-
const oldest = binCache.keys().next().value;
|
|
58
|
-
if (oldest === void 0) break;
|
|
59
|
-
binCache.delete(oldest);
|
|
60
|
-
}
|
|
61
|
-
binCache.set(key, { value, cachedAt: Date.now() });
|
|
62
|
-
return value;
|
|
63
|
-
}
|
|
64
|
-
function clearLocalBinCache() {
|
|
65
|
-
binCache.clear();
|
|
66
|
-
}
|
|
67
|
-
function resolveNodeBin(packageName, binName, cwd, extraArgs = []) {
|
|
68
|
-
const key = `${packageName}|${binName}|${cwd}`;
|
|
69
|
-
const cached = binCache.get(key);
|
|
70
|
-
if (cached !== void 0) {
|
|
71
|
-
if (cached.value !== null || Date.now() - cached.cachedAt < NEGATIVE_BIN_CACHE_TTL_MS) {
|
|
72
|
-
return cached.value === null ? null : { ...cached.value, args: [cached.value.entry, ...extraArgs] };
|
|
73
|
-
}
|
|
74
|
-
binCache.delete(key);
|
|
75
|
-
}
|
|
76
|
-
let resolved = null;
|
|
77
|
-
try {
|
|
78
|
-
const requireFromProject = createRequire(resolve(cwd, "package.json"));
|
|
79
|
-
const packagePath = requireFromProject.resolve(`${packageName}/package.json`);
|
|
80
|
-
const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
|
|
81
|
-
const relativeBin = typeof packageJson.bin === "string" ? packageJson.bin : packageJson.bin?.[binName] ?? Object.values(packageJson.bin ?? {})[0];
|
|
82
|
-
if (relativeBin && !isAbsolute(relativeBin)) {
|
|
83
|
-
const packageDir = dirname(packagePath);
|
|
84
|
-
const entry = resolve(packageDir, relativeBin);
|
|
85
|
-
if (isInside(packageDir, entry)) {
|
|
86
|
-
resolved = { cmd: process.execPath, args: [entry], entry };
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} catch {
|
|
90
|
-
resolved = null;
|
|
91
|
-
}
|
|
92
|
-
cachePut(key, resolved);
|
|
93
|
-
return resolved === null ? null : { ...resolved, args: [resolved.entry, ...extraArgs] };
|
|
94
|
-
}
|
|
95
|
-
function resolveFirstNodeBin(candidates, cwd) {
|
|
96
|
-
for (const c of candidates) {
|
|
97
|
-
const hit = resolveNodeBin(c.packageName, c.binName, cwd, c.args ?? []);
|
|
98
|
-
if (hit) return { ...hit, packageName: c.packageName, binName: c.binName };
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/runtime/bounded-map.ts
|
|
104
|
-
var BoundedMap = class {
|
|
105
|
-
map = /* @__PURE__ */ new Map();
|
|
106
|
-
max;
|
|
107
|
-
ttlMs;
|
|
108
|
-
now;
|
|
109
|
-
/** Entries dropped to stay under `max`. Surfaced by plugin health(). */
|
|
110
|
-
evictions = 0;
|
|
111
|
-
constructor(options) {
|
|
112
|
-
const normalizedMax = Math.floor(options.max);
|
|
113
|
-
this.max = Number.isSafeInteger(normalizedMax) ? Math.max(1, normalizedMax) : 1;
|
|
114
|
-
this.ttlMs = options.ttlMs;
|
|
115
|
-
this.now = options.now ?? Date.now;
|
|
116
|
-
}
|
|
117
|
-
expired(entry) {
|
|
118
|
-
return this.ttlMs !== void 0 && this.now() - entry.storedAt > this.ttlMs;
|
|
119
|
-
}
|
|
120
|
-
get(key) {
|
|
121
|
-
const entry = this.map.get(key);
|
|
122
|
-
if (entry === void 0) return void 0;
|
|
123
|
-
if (this.expired(entry)) {
|
|
124
|
-
this.map.delete(key);
|
|
125
|
-
return void 0;
|
|
126
|
-
}
|
|
127
|
-
this.map.delete(key);
|
|
128
|
-
this.map.set(key, entry);
|
|
129
|
-
return entry.value;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Read without promoting the key to most-recently-used. Use for
|
|
133
|
-
* diagnostics that must not perturb the eviction order.
|
|
134
|
-
*/
|
|
135
|
-
peek(key) {
|
|
136
|
-
const entry = this.map.get(key);
|
|
137
|
-
if (entry === void 0 || this.expired(entry)) return void 0;
|
|
138
|
-
return entry.value;
|
|
139
|
-
}
|
|
140
|
-
has(key) {
|
|
141
|
-
const entry = this.map.get(key);
|
|
142
|
-
if (entry === void 0) return false;
|
|
143
|
-
if (this.expired(entry)) {
|
|
144
|
-
this.map.delete(key);
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
set(key, value) {
|
|
150
|
-
this.map.delete(key);
|
|
151
|
-
this.map.set(key, { value, storedAt: this.now() });
|
|
152
|
-
while (this.map.size > this.max) {
|
|
153
|
-
const coldest = this.map.keys().next().value;
|
|
154
|
-
if (coldest === void 0) break;
|
|
155
|
-
this.map.delete(coldest);
|
|
156
|
-
this.evictions += 1;
|
|
157
|
-
}
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
delete(key) {
|
|
161
|
-
return this.map.delete(key);
|
|
162
|
-
}
|
|
163
|
-
clear() {
|
|
164
|
-
this.map.clear();
|
|
165
|
-
this.evictions = 0;
|
|
166
|
-
}
|
|
167
|
-
get size() {
|
|
168
|
-
return this.map.size;
|
|
169
|
-
}
|
|
170
|
-
/** How many entries have been dropped to respect `max`, since the last clear. */
|
|
171
|
-
get evictionCount() {
|
|
172
|
-
return this.evictions;
|
|
173
|
-
}
|
|
174
|
-
/** Drop every expired entry. Cheap enough to call from a status tool. */
|
|
175
|
-
prune() {
|
|
176
|
-
if (this.ttlMs === void 0) return 0;
|
|
177
|
-
let removed = 0;
|
|
178
|
-
for (const [key, entry] of this.map) {
|
|
179
|
-
if (this.expired(entry)) {
|
|
180
|
-
this.map.delete(key);
|
|
181
|
-
removed += 1;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return removed;
|
|
185
|
-
}
|
|
186
|
-
/** Live (non-expired) entries, coldest first. */
|
|
187
|
-
*entries() {
|
|
188
|
-
for (const [key, entry] of this.map) {
|
|
189
|
-
if (!this.expired(entry)) yield [key, entry.value];
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
[Symbol.iterator]() {
|
|
193
|
-
return this.entries();
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
// src/runtime/index.ts
|
|
198
|
-
var MAX_BUFFER_BYTES = 16 * 1024 * 1024;
|
|
199
|
-
function hasLeadingDash(arg) {
|
|
200
|
-
return arg.length > 0 && arg.startsWith("-");
|
|
201
|
-
}
|
|
202
|
-
function withinProjectPath(projectRoot, candidate) {
|
|
203
|
-
if (candidate.length === 0 || candidate.length > 4096) return false;
|
|
204
|
-
if (hasLeadingDash(candidate)) return false;
|
|
205
|
-
const resolved = isAbsolute2(candidate) ? resolve2(candidate) : resolve2(projectRoot, candidate);
|
|
206
|
-
const rel = relative2(projectRoot, resolved);
|
|
207
|
-
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
208
|
-
}
|
|
209
|
-
function withinProject(p) {
|
|
210
|
-
const cwd = process.cwd();
|
|
211
|
-
return withinProjectPath(cwd, p) || relative2(cwd, p) === ".";
|
|
212
|
-
}
|
|
21
|
+
var runtime_exports = {};
|
|
22
|
+
__reExport(runtime_exports, runtime_star);
|
|
23
|
+
import * as runtime_star from "@wrongstack/plugin-sdk/runtime";
|
|
213
24
|
|
|
214
25
|
// src/format-on-save/index.ts
|
|
215
26
|
var API_VERSION = "^0.1.10";
|
|
@@ -247,7 +58,7 @@ function readConfig(raw) {
|
|
|
247
58
|
skipTtlMs: typeof r["skipTtlMs"] === "number" && r["skipTtlMs"] >= 0 ? r["skipTtlMs"] : DEFAULTS.skipTtlMs
|
|
248
59
|
};
|
|
249
60
|
}
|
|
250
|
-
var recentlyCovered = new BoundedMap({ max: 256 });
|
|
61
|
+
var recentlyCovered = new runtime_exports.BoundedMap({ max: 256 });
|
|
251
62
|
function clearRegistrations() {
|
|
252
63
|
if (state.hookUnregister) {
|
|
253
64
|
try {
|
|
@@ -283,7 +94,7 @@ var FORMATTERS = [
|
|
|
283
94
|
var activeFormatter;
|
|
284
95
|
function resetFormatter() {
|
|
285
96
|
activeFormatter = void 0;
|
|
286
|
-
clearLocalBinCache();
|
|
97
|
+
(0, runtime_exports.clearLocalBinCache)();
|
|
287
98
|
}
|
|
288
99
|
function resolveFormatter() {
|
|
289
100
|
if (activeFormatter !== void 0) return activeFormatter;
|
|
@@ -296,7 +107,7 @@ function resolveFormatter() {
|
|
|
296
107
|
}
|
|
297
108
|
}
|
|
298
109
|
for (const f of FORMATTERS) {
|
|
299
|
-
const onPath = findOnPath(f.binName);
|
|
110
|
+
const onPath = (0, runtime_exports.findOnPath)(f.binName);
|
|
300
111
|
if (!onPath) continue;
|
|
301
112
|
activeFormatter = { cmd: onPath, args: [...f.writeArgs], label: f.label };
|
|
302
113
|
return activeFormatter;
|
|
@@ -305,7 +116,7 @@ function resolveFormatter() {
|
|
|
305
116
|
return null;
|
|
306
117
|
}
|
|
307
118
|
function resolveNodeBinFor(f, cwd) {
|
|
308
|
-
const hit = resolveFirstNodeBin([{ packageName: f.packageName, binName: f.binName }], cwd);
|
|
119
|
+
const hit = (0, runtime_exports.resolveFirstNodeBin)([{ packageName: f.packageName, binName: f.binName }], cwd);
|
|
309
120
|
if (!hit) return null;
|
|
310
121
|
return { cmd: hit.cmd, args: [...hit.args, ...f.writeArgs], label: f.label };
|
|
311
122
|
}
|
|
@@ -320,7 +131,7 @@ async function sha256File(filePath) {
|
|
|
320
131
|
}
|
|
321
132
|
}
|
|
322
133
|
async function formatFile(filePath, timeoutMs) {
|
|
323
|
-
if (!withinProject(filePath)) return null;
|
|
134
|
+
if (!(0, runtime_exports.withinProject)(filePath)) return null;
|
|
324
135
|
try {
|
|
325
136
|
await access(filePath);
|
|
326
137
|
} catch {
|
|
@@ -338,12 +149,12 @@ async function formatFile(filePath, timeoutMs) {
|
|
|
338
149
|
const hashBefore = await sha256File(filePath);
|
|
339
150
|
let invocation;
|
|
340
151
|
try {
|
|
341
|
-
invocation = resolveExecInvocation(formatter.cmd, [...formatter.args, filePath]);
|
|
152
|
+
invocation = (0, runtime_exports.resolveExecInvocation)(formatter.cmd, [...formatter.args, filePath]);
|
|
342
153
|
} catch {
|
|
343
154
|
return null;
|
|
344
155
|
}
|
|
345
156
|
try {
|
|
346
|
-
await new Promise((
|
|
157
|
+
await new Promise((resolve, reject) => {
|
|
347
158
|
execFile(
|
|
348
159
|
invocation.cmd,
|
|
349
160
|
invocation.args,
|
|
@@ -360,7 +171,7 @@ async function formatFile(filePath, timeoutMs) {
|
|
|
360
171
|
const e = err;
|
|
361
172
|
if (e.killed) return reject(err);
|
|
362
173
|
}
|
|
363
|
-
|
|
174
|
+
resolve();
|
|
364
175
|
}
|
|
365
176
|
);
|
|
366
177
|
});
|