codebrief 1.0.0 → 1.1.1
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/index.js +50 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -79,6 +79,7 @@ var init_utils = __esm({
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
// src/index.ts
|
|
82
|
+
init_utils();
|
|
82
83
|
import path8 from "path";
|
|
83
84
|
import * as p4 from "@clack/prompts";
|
|
84
85
|
import pc3 from "picocolors";
|
|
@@ -305,7 +306,10 @@ async function detectContext(rootDir, onProgress) {
|
|
|
305
306
|
"**/vendor/**",
|
|
306
307
|
"**/__pycache__/**",
|
|
307
308
|
"**/venv/**",
|
|
308
|
-
"**/.venv/**"
|
|
309
|
+
"**/.venv/**",
|
|
310
|
+
"**/.Trash/**",
|
|
311
|
+
"**/Library/**",
|
|
312
|
+
"**/.git/**"
|
|
309
313
|
],
|
|
310
314
|
stats: true
|
|
311
315
|
}
|
|
@@ -859,21 +863,34 @@ function computePageRank(files, edges, iterations = 5, damping = 0.85) {
|
|
|
859
863
|
}
|
|
860
864
|
async function buildImportGraph(rootDir, language, onProgress) {
|
|
861
865
|
const globs = getSourceGlob(language);
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
866
|
+
let files;
|
|
867
|
+
try {
|
|
868
|
+
files = await fg2(globs, {
|
|
869
|
+
cwd: rootDir,
|
|
870
|
+
ignore: [
|
|
871
|
+
"**/node_modules/**",
|
|
872
|
+
"**/dist/**",
|
|
873
|
+
"**/build/**",
|
|
874
|
+
"**/.next/**",
|
|
875
|
+
"**/target/**",
|
|
876
|
+
"**/vendor/**",
|
|
877
|
+
"**/__pycache__/**",
|
|
878
|
+
"**/venv/**",
|
|
879
|
+
"**/.venv/**",
|
|
880
|
+
"**/.Trash/**",
|
|
881
|
+
"**/Library/**",
|
|
882
|
+
"**/.git/**"
|
|
883
|
+
],
|
|
884
|
+
absolute: false
|
|
885
|
+
});
|
|
886
|
+
} catch (err) {
|
|
887
|
+
const code = err.code;
|
|
888
|
+
if (code === "EPERM" || code === "EACCES") {
|
|
889
|
+
onProgress?.("Warning: permission error scanning files \u2014 returning empty graph");
|
|
890
|
+
return { edges: [], inDegree: /* @__PURE__ */ new Map(), centrality: /* @__PURE__ */ new Map(), externalImportCounts: /* @__PURE__ */ new Map() };
|
|
891
|
+
}
|
|
892
|
+
throw err;
|
|
893
|
+
}
|
|
877
894
|
onProgress?.(`Found ${files.length} source files to analyze`);
|
|
878
895
|
const fileSet = new Set(files);
|
|
879
896
|
const edges = [];
|
|
@@ -1401,7 +1418,10 @@ async function generateSnapshot(ctx, customPaths, graph, maxTokens, onProgress,
|
|
|
1401
1418
|
"**/build/**",
|
|
1402
1419
|
"**/*.test.*",
|
|
1403
1420
|
"**/*.spec.*",
|
|
1404
|
-
"**/__tests__/**"
|
|
1421
|
+
"**/__tests__/**",
|
|
1422
|
+
"**/.Trash/**",
|
|
1423
|
+
"**/Library/**",
|
|
1424
|
+
"**/.git/**"
|
|
1405
1425
|
],
|
|
1406
1426
|
absolute: false
|
|
1407
1427
|
});
|
|
@@ -3395,6 +3415,19 @@ async function main() {
|
|
|
3395
3415
|
const maxTokens = maxTokensArg ? parseInt(maxTokensArg.split("=")[1], 10) : void 0;
|
|
3396
3416
|
const targetDir = args.find((a) => !a.startsWith("-") && a !== "-v") ?? process.cwd();
|
|
3397
3417
|
const rootDir = path8.resolve(targetDir);
|
|
3418
|
+
const PROJECT_MARKERS = ["package.json", "go.mod", "Cargo.toml", "pyproject.toml", "requirements.txt"];
|
|
3419
|
+
const hasProjectMarker = (await Promise.all(
|
|
3420
|
+
PROJECT_MARKERS.map((f) => fileExists(path8.join(rootDir, f)))
|
|
3421
|
+
)).some(Boolean);
|
|
3422
|
+
if (!hasProjectMarker) {
|
|
3423
|
+
console.log("");
|
|
3424
|
+
p4.intro(pc3.bold(" codebrief "));
|
|
3425
|
+
p4.log.error(`No project found at ${pc3.cyan(rootDir)}`);
|
|
3426
|
+
p4.log.info(`Run ${pc3.bold("npx codebrief")} from a project directory, or pass a path:
|
|
3427
|
+
${pc3.dim("npx codebrief ./my-project")}`);
|
|
3428
|
+
p4.outro("");
|
|
3429
|
+
process.exit(1);
|
|
3430
|
+
}
|
|
3398
3431
|
const verboseLog = (msg) => {
|
|
3399
3432
|
if (verbose) p4.log.info(pc3.dim(msg));
|
|
3400
3433
|
};
|