@optave/codegraph 2.0.0 → 2.1.1-dev.00f091c

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/src/resolve.js CHANGED
@@ -31,7 +31,7 @@ function resolveViaAlias(importSource, aliases, _rootDir) {
31
31
  }
32
32
  }
33
33
 
34
- for (const [pattern, targets] of Object.entries(aliases.paths)) {
34
+ for (const [pattern, targets] of Object.entries(aliases.paths || {})) {
35
35
  const prefix = pattern.replace(/\*$/, '');
36
36
  if (!importSource.startsWith(prefix)) continue;
37
37
  const rest = importSource.slice(prefix.length);
@@ -113,12 +113,13 @@ export function resolveImportPath(fromFile, importSource, rootDir, aliases) {
113
113
  const native = loadNative();
114
114
  if (native) {
115
115
  try {
116
- return native.resolveImport(
116
+ const result = native.resolveImport(
117
117
  fromFile,
118
118
  importSource,
119
119
  rootDir,
120
120
  convertAliasesForNative(aliases),
121
121
  );
122
+ return normalizePath(path.normalize(result));
122
123
  } catch {
123
124
  // fall through to JS
124
125
  }
@@ -158,7 +159,7 @@ export function resolveImportsBatch(inputs, rootDir, aliases) {
158
159
  const results = native.resolveImports(nativeInputs, rootDir, convertAliasesForNative(aliases));
159
160
  const map = new Map();
160
161
  for (const r of results) {
161
- map.set(`${r.fromFile}|${r.importSource}`, r.resolvedPath);
162
+ map.set(`${r.fromFile}|${r.importSource}`, normalizePath(path.normalize(r.resolvedPath)));
162
163
  }
163
164
  return map;
164
165
  } catch {
package/src/watcher.js CHANGED
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { EXTENSIONS, IGNORE_DIRS, normalizePath } from './constants.js';
4
4
  import { initSchema, openDb } from './db.js';
5
+ import { appendJournalEntries } from './journal.js';
5
6
  import { info, warn } from './logger.js';
6
7
  import { createParseTreeCache, getActiveEngine, parseFileIncremental } from './parser.js';
7
8
  import { resolveImportPath } from './resolve.js';
@@ -205,6 +206,19 @@ export async function watchProject(rootDir, opts = {}) {
205
206
  }
206
207
  const updates = results;
207
208
 
209
+ // Append processed files to journal for Tier 0 detection on next build
210
+ if (updates.length > 0) {
211
+ const entries = updates.map((r) => ({
212
+ file: r.file,
213
+ deleted: r.deleted || false,
214
+ }));
215
+ try {
216
+ appendJournalEntries(rootDir, entries);
217
+ } catch {
218
+ /* journal write failure is non-fatal */
219
+ }
220
+ }
221
+
208
222
  for (const r of updates) {
209
223
  const nodeDelta = r.nodesAdded - r.nodesRemoved;
210
224
  const nodeStr = nodeDelta >= 0 ? `+${nodeDelta}` : `${nodeDelta}`;
@@ -234,6 +248,17 @@ export async function watchProject(rootDir, opts = {}) {
234
248
  process.on('SIGINT', () => {
235
249
  console.log('\nStopping watcher...');
236
250
  watcher.close();
251
+ // Flush any pending file paths to journal before exit
252
+ if (pending.size > 0) {
253
+ const entries = [...pending].map((filePath) => ({
254
+ file: normalizePath(path.relative(rootDir, filePath)),
255
+ }));
256
+ try {
257
+ appendJournalEntries(rootDir, entries);
258
+ } catch {
259
+ /* best-effort */
260
+ }
261
+ }
237
262
  if (cache) cache.clear();
238
263
  db.close();
239
264
  process.exit(0);