technical-debt-radar 1.1.3 → 1.2.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.
Files changed (2) hide show
  1. package/dist/index.js +61 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10797,7 +10797,7 @@ var require_volume_estimator = __commonJS({
10797
10797
  };
10798
10798
  })();
10799
10799
  Object.defineProperty(exports2, "__esModule", { value: true });
10800
- exports2.estimateVolumes = estimateVolumes2;
10800
+ exports2.estimateVolumes = estimateVolumes3;
10801
10801
  exports2.parseTypeORMEntities = parseTypeORMEntities;
10802
10802
  exports2.parsePrismaModels = parsePrismaModels;
10803
10803
  exports2.parseDrizzleTables = parseDrizzleTables;
@@ -10828,7 +10828,7 @@ var require_volume_estimator = __commonJS({
10828
10828
  size: "S"
10829
10829
  }
10830
10830
  ];
10831
- async function estimateVolumes2(projectPath) {
10831
+ async function estimateVolumes3(projectPath) {
10832
10832
  const prismaVolumes = await estimatePrismaVolumes(projectPath);
10833
10833
  if (Object.keys(prismaVolumes).length > 0)
10834
10834
  return prismaVolumes;
@@ -19293,6 +19293,12 @@ var RadarApiClient = class _RadarApiClient {
19293
19293
  body: JSON.stringify(data)
19294
19294
  });
19295
19295
  }
19296
+ async pushPolicyConfig(data) {
19297
+ await this.fetch("/cli/push-config", {
19298
+ method: "POST",
19299
+ body: JSON.stringify(data)
19300
+ });
19301
+ }
19296
19302
  };
19297
19303
 
19298
19304
  // src/commands/scan.ts
@@ -19320,6 +19326,30 @@ function buildTopHotspots(violations) {
19320
19326
  }
19321
19327
  return Array.from(byFile.entries()).map(([file, data]) => ({ file, ...data })).sort((a, b) => b.debtPoints - a.debtPoints).slice(0, 10);
19322
19328
  }
19329
+ async function detectDataVolumes(projectRoot, filePaths, existingVolumes) {
19330
+ let estimated = {};
19331
+ try {
19332
+ estimated = await (0, import_policy_engine.estimateVolumes)(projectRoot);
19333
+ } catch {
19334
+ }
19335
+ const volumes = { ...existingVolumes };
19336
+ for (const [entity, size] of Object.entries(estimated)) {
19337
+ if (!volumes[entity]) {
19338
+ volumes[entity] = size;
19339
+ }
19340
+ }
19341
+ const entityPattern = /\.(?:schema|entity|model)\.(ts|js)$/;
19342
+ for (const fp of filePaths) {
19343
+ if (!entityPattern.test(fp)) continue;
19344
+ const basename2 = path2.basename(fp);
19345
+ const entityName = basename2.replace(/\.(schema|entity|model)\.(ts|js)$/, "");
19346
+ if (!entityName || entityName === "index") continue;
19347
+ if (!volumes[entityName]) {
19348
+ volumes[entityName] = volumes["default"] ?? "S";
19349
+ }
19350
+ }
19351
+ return volumes;
19352
+ }
19323
19353
  var ANON_SCAN_DIR = path2.join(os2.homedir(), ".radar");
19324
19354
  var ANON_SCAN_FILE = path2.join(ANON_SCAN_DIR, ".anonymous-scan");
19325
19355
  function checkAnonymousScanAllowed() {
@@ -19394,7 +19424,9 @@ async function enforceAuth(allowAnonymous = false) {
19394
19424
  async function scanCommand(targetPath, options) {
19395
19425
  const { client, isAnonymous } = await enforceAuth(true);
19396
19426
  const scanStart = Date.now();
19397
- const policy = await loadPolicy(options.config, options.rules);
19427
+ const loaded = await loadPolicy(options.config, options.rules);
19428
+ if (!loaded) return;
19429
+ const policy = loaded.compiled;
19398
19430
  const files = await collectTsFiles(targetPath);
19399
19431
  if (files.length === 0) {
19400
19432
  console.log(import_chalk.default.yellow("No .ts/.tsx/.js/.jsx files found."));
@@ -19532,6 +19564,19 @@ async function scanCommand(targetPath, options) {
19532
19564
  };
19533
19565
  try {
19534
19566
  await client.reportScan(reportData);
19567
+ const enrichedConfig = { ...loaded.parsedConfig };
19568
+ enrichedConfig.data_volumes = await detectDataVolumes(
19569
+ path2.resolve(targetPath),
19570
+ files,
19571
+ enrichedConfig.data_volumes ?? {}
19572
+ );
19573
+ await client.pushPolicyConfig({
19574
+ repoName: path2.basename(path2.resolve(targetPath)),
19575
+ radarYaml: loaded.radarYaml,
19576
+ rulesYaml: loaded.rulesYaml,
19577
+ parsedConfig: enrichedConfig
19578
+ }).catch(() => {
19579
+ });
19535
19580
  console.log(import_chalk.default.green(" \u2713 Results synced to dashboard: https://www.technicaldebtradar.com/dashboard"));
19536
19581
  } catch {
19537
19582
  console.log(import_chalk.default.yellow(" \u26A0\uFE0F Could not sync results to dashboard. Check your connection."));
@@ -19552,7 +19597,7 @@ async function scanCommand(targetPath, options) {
19552
19597
  }
19553
19598
  async function checkCommand(filePath, options) {
19554
19599
  const { isAnonymous } = await enforceAuth(true);
19555
- const policy = await loadPolicy(options.config, options.rules);
19600
+ const { compiled: policy } = await loadPolicy(options.config, options.rules);
19556
19601
  const absolutePath = path2.resolve(filePath);
19557
19602
  let content;
19558
19603
  try {
@@ -19602,9 +19647,10 @@ async function loadPolicy(configPath, rulesPath) {
19602
19647
  const config = (0, import_policy_engine.parsePolicy)(yamlContent);
19603
19648
  const rulesFile = rulesPath ?? path2.join(path2.dirname(resolved), "rules.yml");
19604
19649
  let rulesConfig = null;
19650
+ let rulesYaml;
19605
19651
  try {
19606
- const rulesContent = await fs2.readFile(path2.resolve(rulesFile), "utf-8");
19607
- rulesConfig = (0, import_policy_engine.parseRulesYml)(rulesContent);
19652
+ rulesYaml = await fs2.readFile(path2.resolve(rulesFile), "utf-8");
19653
+ rulesConfig = (0, import_policy_engine.parseRulesYml)(rulesYaml);
19608
19654
  } catch {
19609
19655
  if (rulesPath) {
19610
19656
  console.error(import_chalk.default.red(`Could not read rules file: ${rulesFile}`));
@@ -19632,7 +19678,12 @@ async function loadPolicy(configPath, rulesPath) {
19632
19678
  process.exit(1);
19633
19679
  return void 0;
19634
19680
  }
19635
- return (0, import_policy_engine.compilePolicy)(config);
19681
+ return {
19682
+ compiled: (0, import_policy_engine.compilePolicy)(config),
19683
+ radarYaml: yamlContent,
19684
+ rulesYaml,
19685
+ parsedConfig: config
19686
+ };
19636
19687
  }
19637
19688
  async function collectTsFiles(targetPath) {
19638
19689
  const resolved = path2.resolve(targetPath);
@@ -20665,7 +20716,7 @@ function applyFix(filePath, fix) {
20665
20716
  fsSync2.writeFileSync(filePath, lines.join("\n"), "utf-8");
20666
20717
  }
20667
20718
  async function runScan(targetPath, options) {
20668
- const policy = await loadPolicy(options.config, options.rules);
20719
+ const { compiled: policy } = await loadPolicy(options.config, options.rules);
20669
20720
  let files = await collectTsFiles(targetPath);
20670
20721
  if (options.file) {
20671
20722
  const target = path5.resolve(options.file);
@@ -20693,7 +20744,7 @@ async function runScan(targetPath, options) {
20693
20744
  };
20694
20745
  }
20695
20746
  async function runTextOnlyFix(targetPath, options) {
20696
- const policy = await loadPolicy(options.config, options.rules);
20747
+ const { compiled: policy } = await loadPolicy(options.config, options.rules);
20697
20748
  const files = await collectTsFiles(targetPath);
20698
20749
  if (files.length === 0) {
20699
20750
  console.log(import_chalk4.default.yellow("No .ts/.tsx files found."));
@@ -20970,7 +21021,7 @@ async function runCommand(targetPath, options) {
20970
21021
  process.exit(1);
20971
21022
  }
20972
21023
  const isTTY = process.stdout.isTTY ?? false;
20973
- const policy = await loadPolicy(options.config, options.rules);
21024
+ const { compiled: policy } = await loadPolicy(options.config, options.rules);
20974
21025
  const files = await collectTsFiles(targetPath);
20975
21026
  if (files.length === 0) {
20976
21027
  console.log("No .ts/.tsx files found.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "technical-debt-radar",
3
- "version": "1.1.3",
3
+ "version": "1.2.1",
4
4
  "description": "Stop Node.js production crashes before merge. 47 detection patterns across 5 categories.",
5
5
  "bin": {
6
6
  "radar": "dist/index.js",