raggrep 0.10.2 → 0.10.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/index.js CHANGED
@@ -11441,6 +11441,7 @@ function getOptimalConcurrency() {
11441
11441
  return optimal;
11442
11442
  }
11443
11443
  var DEFAULT_CONCURRENCY = getOptimalConcurrency();
11444
+ var STAT_CONCURRENCY = Math.max(32, getOptimalConcurrency() * 4);
11444
11445
  async function indexDirectory(rootDir, options = {}) {
11445
11446
  const verbose = options.verbose ?? false;
11446
11447
  const quiet = options.quiet ?? false;
@@ -11558,6 +11559,15 @@ async function resetIndex(rootDir) {
11558
11559
  async function ensureIndexFresh(rootDir, options = {}) {
11559
11560
  const verbose = options.verbose ?? false;
11560
11561
  const quiet = options.quiet ?? false;
11562
+ const showTiming = options.timing ?? false;
11563
+ const startTime = Date.now();
11564
+ let fileDiscoveryMs = 0;
11565
+ let statCheckMs = 0;
11566
+ let indexingMs = 0;
11567
+ let cleanupMs = 0;
11568
+ let filesDiscovered = 0;
11569
+ let filesStatChecked = 0;
11570
+ let filesIndexed = 0;
11561
11571
  const logger = options.logger ? options.logger : quiet ? createSilentLogger() : createLogger({ verbose });
11562
11572
  rootDir = path21.resolve(rootDir);
11563
11573
  const status = await getIndexStatus(rootDir);
@@ -11589,16 +11599,35 @@ async function ensureIndexFresh(rootDir, options = {}) {
11589
11599
  const now = Date.now();
11590
11600
  if (freshnessCache && freshnessCache.rootDir === rootDir && now - freshnessCache.timestamp < FRESHNESS_CACHE_TTL_MS && freshnessCache.manifestMtime === currentManifestMtime) {
11591
11601
  logger.debug("Using cached freshness check result");
11592
- return freshnessCache.result;
11602
+ const cachedResult = { ...freshnessCache.result };
11603
+ if (showTiming) {
11604
+ cachedResult.timing = {
11605
+ totalMs: Date.now() - startTime,
11606
+ fileDiscoveryMs: 0,
11607
+ statCheckMs: 0,
11608
+ indexingMs: 0,
11609
+ cleanupMs: 0,
11610
+ filesDiscovered: 0,
11611
+ filesStatChecked: 0,
11612
+ filesIndexed: 0,
11613
+ fromCache: true
11614
+ };
11615
+ }
11616
+ return cachedResult;
11593
11617
  }
11594
11618
  await registerBuiltInModules();
11595
11619
  const enabledModules = registry.getEnabled(config);
11596
11620
  if (enabledModules.length === 0) {
11597
11621
  return { indexed: 0, removed: 0, unchanged: 0 };
11598
11622
  }
11623
+ const fileDiscoveryStart = Date.now();
11599
11624
  const introspection = new IntrospectionIndex(rootDir);
11600
- await introspection.initialize();
11601
- const currentFiles = await findFiles(rootDir, config);
11625
+ const [, currentFiles] = await Promise.all([
11626
+ introspection.initialize(),
11627
+ findFiles(rootDir, config)
11628
+ ]);
11629
+ fileDiscoveryMs = Date.now() - fileDiscoveryStart;
11630
+ filesDiscovered = currentFiles.length;
11602
11631
  const currentFileSet = new Set(currentFiles.map((f) => path21.relative(rootDir, f)));
11603
11632
  let totalIndexed = 0;
11604
11633
  let totalRemoved = 0;
@@ -11627,20 +11656,21 @@ async function ensureIndexFresh(rootDir, options = {}) {
11627
11656
  filesToRemove.push(filepath);
11628
11657
  }
11629
11658
  }
11659
+ const cleanupStart = Date.now();
11630
11660
  const removedFilepaths = [];
11631
- for (const filepath of filesToRemove) {
11632
- logger.debug(` Removing stale: ${filepath}`);
11633
- const indexFilePath = path21.join(indexPath, filepath.replace(/\.[^.]+$/, ".json"));
11634
- try {
11635
- await fs8.unlink(indexFilePath);
11636
- } catch {}
11637
- const symbolicFilePath = path21.join(indexPath, "symbolic", filepath.replace(/\.[^.]+$/, ".json"));
11638
- try {
11639
- await fs8.unlink(symbolicFilePath);
11640
- } catch {}
11641
- delete manifest.files[filepath];
11642
- removedFilepaths.push(filepath);
11643
- totalRemoved++;
11661
+ if (filesToRemove.length > 0) {
11662
+ await Promise.all(filesToRemove.map(async (filepath) => {
11663
+ logger.debug(` Removing stale: ${filepath}`);
11664
+ const indexFilePath = path21.join(indexPath, filepath.replace(/\.[^.]+$/, ".json"));
11665
+ const symbolicFilePath = path21.join(indexPath, "symbolic", filepath.replace(/\.[^.]+$/, ".json"));
11666
+ await Promise.all([
11667
+ fs8.unlink(indexFilePath).catch(() => {}),
11668
+ fs8.unlink(symbolicFilePath).catch(() => {})
11669
+ ]);
11670
+ delete manifest.files[filepath];
11671
+ removedFilepaths.push(filepath);
11672
+ }));
11673
+ totalRemoved += removedFilepaths.length;
11644
11674
  }
11645
11675
  if (removedFilepaths.length > 0) {
11646
11676
  try {
@@ -11654,6 +11684,7 @@ async function ensureIndexFresh(rootDir, options = {}) {
11654
11684
  await literalIndex.save();
11655
11685
  } catch {}
11656
11686
  }
11687
+ cleanupMs += Date.now() - cleanupStart;
11657
11688
  const ctx = {
11658
11689
  rootDir,
11659
11690
  config,
@@ -11668,21 +11699,51 @@ async function ensureIndexFresh(rootDir, options = {}) {
11668
11699
  },
11669
11700
  getIntrospection: (filepath) => introspection.getFile(filepath)
11670
11701
  };
11671
- const totalFiles = currentFiles.length;
11672
- let completedCount = 0;
11673
- const processIncrementalFile = async (filepath) => {
11702
+ const statCheck = async (filepath) => {
11674
11703
  const relativePath = path21.relative(rootDir, filepath);
11675
11704
  try {
11676
11705
  const stats = await fs8.stat(filepath);
11677
11706
  const lastModified = stats.mtime.toISOString();
11678
11707
  const existingEntry = manifest.files[relativePath];
11679
- if (existingEntry && existingEntry.lastModified === lastModified) {
11680
- completedCount++;
11681
- return { relativePath, status: "unchanged" };
11708
+ if (!existingEntry) {
11709
+ return { filepath, relativePath, lastModified, needsCheck: true, isNew: true };
11682
11710
  }
11711
+ if (existingEntry.lastModified === lastModified) {
11712
+ return { filepath, relativePath, lastModified, needsCheck: false, isNew: false };
11713
+ }
11714
+ return { filepath, relativePath, lastModified, needsCheck: true, isNew: false };
11715
+ } catch {
11716
+ return null;
11717
+ }
11718
+ };
11719
+ const statCheckStart = Date.now();
11720
+ const statResults = await parallelMap(currentFiles, statCheck, STAT_CONCURRENCY);
11721
+ statCheckMs += Date.now() - statCheckStart;
11722
+ filesStatChecked += currentFiles.length;
11723
+ const filesToProcess = [];
11724
+ let unchangedCount = 0;
11725
+ for (const result2 of statResults) {
11726
+ if (!result2.success || !result2.value)
11727
+ continue;
11728
+ if (result2.value.needsCheck) {
11729
+ filesToProcess.push(result2.value);
11730
+ } else {
11731
+ unchangedCount++;
11732
+ }
11733
+ }
11734
+ if (filesToProcess.length === 0) {
11735
+ totalUnchanged += unchangedCount;
11736
+ continue;
11737
+ }
11738
+ let completedCount = 0;
11739
+ const totalToProcess = filesToProcess.length;
11740
+ const processChangedFile = async (statResult) => {
11741
+ const { filepath, relativePath, lastModified, isNew } = statResult;
11742
+ try {
11683
11743
  const content = await fs8.readFile(filepath, "utf-8");
11684
11744
  const contentHash = computeContentHash(content);
11685
- if (existingEntry?.contentHash && existingEntry.contentHash === contentHash) {
11745
+ const existingEntry = manifest.files[relativePath];
11746
+ if (!isNew && existingEntry?.contentHash && existingEntry.contentHash === contentHash) {
11686
11747
  completedCount++;
11687
11748
  return {
11688
11749
  relativePath,
@@ -11692,7 +11753,7 @@ async function ensureIndexFresh(rootDir, options = {}) {
11692
11753
  };
11693
11754
  }
11694
11755
  completedCount++;
11695
- logger.progress(` [${completedCount}/${totalFiles}] Indexing: ${relativePath}`);
11756
+ logger.progress(` [${completedCount}/${totalToProcess}] Indexing: ${relativePath}`);
11696
11757
  introspection.addFile(relativePath, content);
11697
11758
  const fileIndex = await module2.indexFile(relativePath, content, ctx);
11698
11759
  if (!fileIndex) {
@@ -11711,8 +11772,12 @@ async function ensureIndexFresh(rootDir, options = {}) {
11711
11772
  return { relativePath, status: "error", error };
11712
11773
  }
11713
11774
  };
11775
+ const indexingStart = Date.now();
11714
11776
  const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
11715
- const results = await parallelMap(currentFiles, processIncrementalFile, concurrency);
11777
+ const results = await parallelMap(filesToProcess, processChangedFile, concurrency);
11778
+ indexingMs += Date.now() - indexingStart;
11779
+ filesIndexed += filesToProcess.length;
11780
+ totalUnchanged += unchangedCount;
11716
11781
  logger.clearProgress();
11717
11782
  let mtimeUpdates = 0;
11718
11783
  for (const item of results) {
@@ -11773,6 +11838,19 @@ async function ensureIndexFresh(rootDir, options = {}) {
11773
11838
  removed: totalRemoved,
11774
11839
  unchanged: totalUnchanged
11775
11840
  };
11841
+ if (showTiming) {
11842
+ result.timing = {
11843
+ totalMs: Date.now() - startTime,
11844
+ fileDiscoveryMs,
11845
+ statCheckMs,
11846
+ indexingMs,
11847
+ cleanupMs,
11848
+ filesDiscovered,
11849
+ filesStatChecked,
11850
+ filesIndexed,
11851
+ fromCache: false
11852
+ };
11853
+ }
11776
11854
  let finalManifestMtime = currentManifestMtime;
11777
11855
  try {
11778
11856
  const manifestStats = await fs8.stat(globalManifestPath);
@@ -11780,7 +11858,7 @@ async function ensureIndexFresh(rootDir, options = {}) {
11780
11858
  } catch {}
11781
11859
  freshnessCache = {
11782
11860
  rootDir,
11783
- result,
11861
+ result: { indexed: totalIndexed, removed: totalRemoved, unchanged: totalUnchanged },
11784
11862
  timestamp: Date.now(),
11785
11863
  manifestMtime: finalManifestMtime
11786
11864
  };
@@ -11922,16 +12000,13 @@ async function indexWithModule(rootDir, files, module2, config, verbose, introsp
11922
12000
  async function findFiles(rootDir, config) {
11923
12001
  const patterns = config.extensions.map((ext) => `**/*${ext}`);
11924
12002
  const ignorePatterns = config.ignorePaths.map((p) => `**/${p}/**`);
11925
- const files = [];
11926
- for (const pattern of patterns) {
11927
- const matches = await glob(pattern, {
11928
- cwd: rootDir,
11929
- absolute: true,
11930
- ignore: ignorePatterns
11931
- });
11932
- files.push(...matches);
11933
- }
11934
- return [...new Set(files)];
12003
+ const results = await Promise.all(patterns.map((pattern) => glob(pattern, {
12004
+ cwd: rootDir,
12005
+ absolute: true,
12006
+ ignore: ignorePatterns
12007
+ })));
12008
+ const allFiles = results.flat();
12009
+ return [...new Set(allFiles)];
11935
12010
  }
11936
12011
  async function loadModuleManifest(rootDir, moduleId, config) {
11937
12012
  const manifestPath = getModuleManifestPath(rootDir, moduleId, config);
@@ -13509,4 +13584,4 @@ export {
13509
13584
  ConsoleLogger
13510
13585
  };
13511
13586
 
13512
- //# debugId=F14D312160862FA864756E2164756E21
13587
+ //# debugId=EA9D4B791B6DE73764756E2164756E21