slopbrick 0.18.2 → 0.18.4
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/engine/worker.cjs +24 -14
- package/dist/engine/worker.js +24 -14
- package/dist/index.cjs +380 -231
- package/dist/index.js +243 -94
- package/package.json +1 -1
package/dist/engine/worker.cjs
CHANGED
|
@@ -26,6 +26,7 @@ __export(worker_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(worker_exports);
|
|
27
27
|
var import_node_worker_threads = require("worker_threads");
|
|
28
28
|
var import_node_path11 = require("path");
|
|
29
|
+
var import_node_path12 = require("path");
|
|
29
30
|
|
|
30
31
|
// ../engine/dist/index.js
|
|
31
32
|
var import_promises = require("fs/promises");
|
|
@@ -4290,10 +4291,10 @@ function parseSvelte(source) {
|
|
|
4290
4291
|
const ast = parseScriptContent(script.content, isTypeScriptScript(script.openTag));
|
|
4291
4292
|
return { ast, source };
|
|
4292
4293
|
}
|
|
4293
|
-
function
|
|
4294
|
+
function legacyCacheEnabled() {
|
|
4294
4295
|
return process.env.SLOP_AUDIT_CACHE === "1" || process.env.SLOP_AUDIT_CACHE === "true";
|
|
4295
4296
|
}
|
|
4296
|
-
function
|
|
4297
|
+
function legacyCacheRoot() {
|
|
4297
4298
|
const override = process.env.SLOP_AUDIT_CACHE_ROOT;
|
|
4298
4299
|
if (override) return override;
|
|
4299
4300
|
return (0, import_path.join)(process.cwd(), ".slopbrick", "cache", "ast");
|
|
@@ -4301,11 +4302,11 @@ function cacheRoot() {
|
|
|
4301
4302
|
function hashContent(content) {
|
|
4302
4303
|
return (0, import_crypto.createHash)("md5").update(content, "utf-8").digest("hex");
|
|
4303
4304
|
}
|
|
4304
|
-
function
|
|
4305
|
-
return (0, import_path.join)(
|
|
4305
|
+
function cachePathWithRoot(content, root) {
|
|
4306
|
+
return (0, import_path.join)(root, `${hashContent(content)}.json`);
|
|
4306
4307
|
}
|
|
4307
|
-
async function
|
|
4308
|
-
const path =
|
|
4308
|
+
async function readCacheWithRoot(filePath, content, root) {
|
|
4309
|
+
const path = cachePathWithRoot(content, root);
|
|
4309
4310
|
try {
|
|
4310
4311
|
await (0, import_promises.access)(path);
|
|
4311
4312
|
const raw = await (0, import_promises.readFile)(path, "utf8");
|
|
@@ -4318,8 +4319,8 @@ async function readCache(filePath, content) {
|
|
|
4318
4319
|
}
|
|
4319
4320
|
return void 0;
|
|
4320
4321
|
}
|
|
4321
|
-
async function
|
|
4322
|
-
const path =
|
|
4322
|
+
async function writeCacheWithRoot(content, result, root) {
|
|
4323
|
+
const path = cachePathWithRoot(content, root);
|
|
4323
4324
|
await (0, import_promises.mkdir)((0, import_path.dirname)(path), { recursive: true });
|
|
4324
4325
|
await (0, import_promises.writeFile)(path, JSON.stringify(result), "utf8");
|
|
4325
4326
|
}
|
|
@@ -4350,15 +4351,17 @@ function parseSource(source, filePath) {
|
|
|
4350
4351
|
return parseWithSwc(source, filePath);
|
|
4351
4352
|
}
|
|
4352
4353
|
}
|
|
4353
|
-
async function parseFile(filePath) {
|
|
4354
|
+
async function parseFile(filePath, opts) {
|
|
4354
4355
|
const source = await (0, import_promises.readFile)(filePath, "utf-8");
|
|
4355
|
-
|
|
4356
|
-
|
|
4356
|
+
const useCache = opts?.cache?.enabled ?? legacyCacheEnabled();
|
|
4357
|
+
const cacheDir = opts?.cache?.root ?? legacyCacheRoot();
|
|
4358
|
+
if (useCache) {
|
|
4359
|
+
const cached = await readCacheWithRoot(filePath, source, cacheDir);
|
|
4357
4360
|
if (cached) return cached;
|
|
4358
4361
|
}
|
|
4359
4362
|
const result = parseSource(source, filePath);
|
|
4360
|
-
if (
|
|
4361
|
-
await
|
|
4363
|
+
if (useCache) {
|
|
4364
|
+
await writeCacheWithRoot(source, result, cacheDir);
|
|
4362
4365
|
}
|
|
4363
4366
|
return result;
|
|
4364
4367
|
}
|
|
@@ -40711,6 +40714,12 @@ function loadSignalStrength() {
|
|
|
40711
40714
|
}
|
|
40712
40715
|
|
|
40713
40716
|
// src/engine/worker.ts
|
|
40717
|
+
function buildParserCacheConfig(cwd) {
|
|
40718
|
+
const envVal = process.env.SLOP_AUDIT_CACHE;
|
|
40719
|
+
const enabled = envVal === "1" || envVal === "true";
|
|
40720
|
+
const root = process.env.SLOP_AUDIT_CACHE_ROOT ?? (0, import_node_path12.join)(cwd, ".slopbrick", "cache", "ast");
|
|
40721
|
+
return { enabled, root };
|
|
40722
|
+
}
|
|
40714
40723
|
function applyRuleOverrides(issues, rules) {
|
|
40715
40724
|
const result = [];
|
|
40716
40725
|
for (const issue of issues) {
|
|
@@ -40725,6 +40734,7 @@ function applyRuleOverrides(issues, rules) {
|
|
|
40725
40734
|
return result;
|
|
40726
40735
|
}
|
|
40727
40736
|
async function scanFile(filePath, config, registry, cwd = process.cwd()) {
|
|
40737
|
+
const cache = buildParserCacheConfig(cwd);
|
|
40728
40738
|
const ext = (0, import_node_path11.extname)(filePath).toLowerCase();
|
|
40729
40739
|
const UNSUPPORTED_LANGS = /* @__PURE__ */ new Set([
|
|
40730
40740
|
".swift",
|
|
@@ -40755,7 +40765,7 @@ async function scanFile(filePath, config, registry, cwd = process.cwd()) {
|
|
|
40755
40765
|
};
|
|
40756
40766
|
}
|
|
40757
40767
|
try {
|
|
40758
|
-
const { ast, source } = await parseFile(filePath);
|
|
40768
|
+
const { ast, source } = await parseFile(filePath, { cache });
|
|
40759
40769
|
const facts = extractFacts(filePath, ast, source, config.supportsRsc ?? true, config.framework ?? "react", config);
|
|
40760
40770
|
const activeRegistry = registry ?? new RuleRegistry();
|
|
40761
40771
|
if (!registry) {
|
package/dist/engine/worker.js
CHANGED
|
@@ -7,6 +7,7 @@ var __export = (target, all) => {
|
|
|
7
7
|
// src/engine/worker.ts
|
|
8
8
|
import { isMainThread, parentPort, workerData } from "worker_threads";
|
|
9
9
|
import { extname as extname6 } from "path";
|
|
10
|
+
import { join as join12 } from "path";
|
|
10
11
|
|
|
11
12
|
// ../engine/dist/index.js
|
|
12
13
|
import { readFile, writeFile, mkdir, access } from "fs/promises";
|
|
@@ -4271,10 +4272,10 @@ function parseSvelte(source) {
|
|
|
4271
4272
|
const ast = parseScriptContent(script.content, isTypeScriptScript(script.openTag));
|
|
4272
4273
|
return { ast, source };
|
|
4273
4274
|
}
|
|
4274
|
-
function
|
|
4275
|
+
function legacyCacheEnabled() {
|
|
4275
4276
|
return process.env.SLOP_AUDIT_CACHE === "1" || process.env.SLOP_AUDIT_CACHE === "true";
|
|
4276
4277
|
}
|
|
4277
|
-
function
|
|
4278
|
+
function legacyCacheRoot() {
|
|
4278
4279
|
const override = process.env.SLOP_AUDIT_CACHE_ROOT;
|
|
4279
4280
|
if (override) return override;
|
|
4280
4281
|
return join(process.cwd(), ".slopbrick", "cache", "ast");
|
|
@@ -4282,11 +4283,11 @@ function cacheRoot() {
|
|
|
4282
4283
|
function hashContent(content) {
|
|
4283
4284
|
return createHash("md5").update(content, "utf-8").digest("hex");
|
|
4284
4285
|
}
|
|
4285
|
-
function
|
|
4286
|
-
return join(
|
|
4286
|
+
function cachePathWithRoot(content, root) {
|
|
4287
|
+
return join(root, `${hashContent(content)}.json`);
|
|
4287
4288
|
}
|
|
4288
|
-
async function
|
|
4289
|
-
const path =
|
|
4289
|
+
async function readCacheWithRoot(filePath, content, root) {
|
|
4290
|
+
const path = cachePathWithRoot(content, root);
|
|
4290
4291
|
try {
|
|
4291
4292
|
await access(path);
|
|
4292
4293
|
const raw = await readFile(path, "utf8");
|
|
@@ -4299,8 +4300,8 @@ async function readCache(filePath, content) {
|
|
|
4299
4300
|
}
|
|
4300
4301
|
return void 0;
|
|
4301
4302
|
}
|
|
4302
|
-
async function
|
|
4303
|
-
const path =
|
|
4303
|
+
async function writeCacheWithRoot(content, result, root) {
|
|
4304
|
+
const path = cachePathWithRoot(content, root);
|
|
4304
4305
|
await mkdir(dirname(path), { recursive: true });
|
|
4305
4306
|
await writeFile(path, JSON.stringify(result), "utf8");
|
|
4306
4307
|
}
|
|
@@ -4331,15 +4332,17 @@ function parseSource(source, filePath) {
|
|
|
4331
4332
|
return parseWithSwc(source, filePath);
|
|
4332
4333
|
}
|
|
4333
4334
|
}
|
|
4334
|
-
async function parseFile(filePath) {
|
|
4335
|
+
async function parseFile(filePath, opts) {
|
|
4335
4336
|
const source = await readFile(filePath, "utf-8");
|
|
4336
|
-
|
|
4337
|
-
|
|
4337
|
+
const useCache = opts?.cache?.enabled ?? legacyCacheEnabled();
|
|
4338
|
+
const cacheDir = opts?.cache?.root ?? legacyCacheRoot();
|
|
4339
|
+
if (useCache) {
|
|
4340
|
+
const cached = await readCacheWithRoot(filePath, source, cacheDir);
|
|
4338
4341
|
if (cached) return cached;
|
|
4339
4342
|
}
|
|
4340
4343
|
const result = parseSource(source, filePath);
|
|
4341
|
-
if (
|
|
4342
|
-
await
|
|
4344
|
+
if (useCache) {
|
|
4345
|
+
await writeCacheWithRoot(source, result, cacheDir);
|
|
4343
4346
|
}
|
|
4344
4347
|
return result;
|
|
4345
4348
|
}
|
|
@@ -40692,6 +40695,12 @@ function loadSignalStrength() {
|
|
|
40692
40695
|
}
|
|
40693
40696
|
|
|
40694
40697
|
// src/engine/worker.ts
|
|
40698
|
+
function buildParserCacheConfig(cwd) {
|
|
40699
|
+
const envVal = process.env.SLOP_AUDIT_CACHE;
|
|
40700
|
+
const enabled = envVal === "1" || envVal === "true";
|
|
40701
|
+
const root = process.env.SLOP_AUDIT_CACHE_ROOT ?? join12(cwd, ".slopbrick", "cache", "ast");
|
|
40702
|
+
return { enabled, root };
|
|
40703
|
+
}
|
|
40695
40704
|
function applyRuleOverrides(issues, rules) {
|
|
40696
40705
|
const result = [];
|
|
40697
40706
|
for (const issue of issues) {
|
|
@@ -40706,6 +40715,7 @@ function applyRuleOverrides(issues, rules) {
|
|
|
40706
40715
|
return result;
|
|
40707
40716
|
}
|
|
40708
40717
|
async function scanFile(filePath, config, registry, cwd = process.cwd()) {
|
|
40718
|
+
const cache = buildParserCacheConfig(cwd);
|
|
40709
40719
|
const ext = extname6(filePath).toLowerCase();
|
|
40710
40720
|
const UNSUPPORTED_LANGS = /* @__PURE__ */ new Set([
|
|
40711
40721
|
".swift",
|
|
@@ -40736,7 +40746,7 @@ async function scanFile(filePath, config, registry, cwd = process.cwd()) {
|
|
|
40736
40746
|
};
|
|
40737
40747
|
}
|
|
40738
40748
|
try {
|
|
40739
|
-
const { ast, source } = await parseFile(filePath);
|
|
40749
|
+
const { ast, source } = await parseFile(filePath, { cache });
|
|
40740
40750
|
const facts = extractFacts(filePath, ast, source, config.supportsRsc ?? true, config.framework ?? "react", config);
|
|
40741
40751
|
const activeRegistry = registry ?? new RuleRegistry();
|
|
40742
40752
|
if (!registry) {
|