@@ -247,14 +247,50 @@ static char *extract_quoted(const char *p, const char *end) {
247247
248248/* ── Language-specific manifest parsers ────────────────────────── */
249249
250- /* Resolve JS/TS entry point from exports["."] object. */
250+ /* A TypeScript source file, not a declaration file (.d.ts / .d.mts / .d.cts). */
251+ static bool is_ts_source_path (const char * p ) {
252+ if (!p ) {
253+ return false;
254+ }
255+ size_t n = strlen (p );
256+ static const char * decl [] = {".d.ts" , ".d.mts" , ".d.cts" , NULL };
257+ for (const char * * d = decl ; * d ; d ++ ) {
258+ size_t dl = strlen (* d );
259+ if (n >= dl && strcmp (p + n - dl , * d ) == 0 ) {
260+ return false;
261+ }
262+ }
263+ static const char * src [] = {".ts" , ".tsx" , ".mts" , ".cts" , NULL };
264+ for (const char * * s = src ; * s ; s ++ ) {
265+ size_t sl = strlen (* s );
266+ if (n > sl && strcmp (p + n - sl , * s ) == 0 ) {
267+ return true;
268+ }
269+ }
270+ return false;
271+ }
272+
273+ /* Resolve the JS/TS target of one exports entry (exports["."] or a subpath).
274+ * A condition that names a TypeScript source file wins: in a source-first
275+ * workspace "types" points at src/ while "import" points at gitignored build
276+ * output that has no graph node (#1732). Otherwise the runtime conditions. */
251277static const char * resolve_exports_dot (yyjson_val * dot ) {
252278 if (yyjson_is_str (dot )) {
253279 return yyjson_get_str (dot );
254280 }
255281 if (!yyjson_is_obj (dot )) {
256282 return NULL ;
257283 }
284+ size_t ci ;
285+ size_t cmax ;
286+ yyjson_val * ck ;
287+ yyjson_val * cv ;
288+ yyjson_obj_foreach (dot , ci , cmax , ck , cv ) {
289+ (void )ck ;
290+ if (yyjson_is_str (cv ) && is_ts_source_path (yyjson_get_str (cv ))) {
291+ return yyjson_get_str (cv );
292+ }
293+ }
258294 static const char * keys [] = {"import" , "default" , "require" };
259295 for (int i = 0 ; i < (int )(sizeof (keys ) / sizeof (keys [0 ])); i ++ ) {
260296 yyjson_val * v = yyjson_obj_get (dot , keys [i ]);
@@ -309,15 +345,43 @@ static void parse_package_json(const char *source, int source_len, const char *r
309345 }
310346
311347 const char * entry = resolve_pkg_entry (root );
312- if ( entry ) {
313- char * dir = path_dirname ( rel_path );
348+ char * dir = path_dirname ( rel_path );
349+ if ( entry && dir ) {
314350 char * resolved = join_and_strip (dir , entry );
315351 if (resolved ) {
316352 pkg_entries_push (entries , strdup (name ), resolved );
317353 }
318- free (dir );
319354 }
320355
356+ /* Subpath exports: `"./xdg-paths": {...}` makes `<name>/xdg-paths` an
357+ * importable specifier with its own target. Without it the subpath was
358+ * glued onto the root entry's QN and named no node. Star patterns are
359+ * left to the existing prefix fallback. */
360+ yyjson_val * exports = yyjson_obj_get (root , "exports" );
361+ if (dir && yyjson_is_obj (exports )) {
362+ size_t ei ;
363+ size_t emax ;
364+ yyjson_val * ek ;
365+ yyjson_val * ev ;
366+ yyjson_obj_foreach (exports , ei , emax , ek , ev ) {
367+ const char * sub = yyjson_get_str (ek );
368+ if (!sub || sub [0 ] != '.' || sub [SKIP_ONE ] != '/' || strchr (sub , '*' )) {
369+ continue ;
370+ }
371+ const char * target = resolve_exports_dot (ev );
372+ if (!target ) {
373+ continue ;
374+ }
375+ char key [PKGMAP_PATH_BUF ];
376+ snprintf (key , sizeof (key ), "%s%s" , name , sub + SKIP_ONE );
377+ char * resolved = join_and_strip (dir , target );
378+ if (resolved ) {
379+ pkg_entries_push (entries , strdup (key ), resolved );
380+ }
381+ }
382+ }
383+ free (dir );
384+
321385 yyjson_doc_free (doc );
322386}
323387
@@ -1819,6 +1883,44 @@ bool cbm_import_symbol_fallback_allowed(CBMLanguage lang) {
18191883 return lang != CBM_LANG_GO ;
18201884}
18211885
1886+ /* A JS/TS import specifier always names a module, never a symbol: the
1887+ * imported names live in local_name. A bare specifier (`path`, `node:fs`,
1888+ * `@scope/pkg/sub`) that Strategy 1 (relative path, tsconfig paths, package
1889+ * manifests) did not resolve is a Node built-in or a dependency outside the
1890+ * graph, and the correct result is NO edge. The name-guess fallbacks instead
1891+ * matched a path segment against any project symbol (`path` -> Router.path(),
1892+ * `@acme/config` -> a test's local `config`), and the import map then sent
1893+ * every call of the imported name there at import_map confidence. */
1894+ static bool js_external_bare_specifier (CBMLanguage lang , const char * module_path ) {
1895+ if (lang != CBM_LANG_JAVASCRIPT && lang != CBM_LANG_TYPESCRIPT && lang != CBM_LANG_TSX ) {
1896+ return false;
1897+ }
1898+ if (!module_path || !module_path [0 ]) {
1899+ return false;
1900+ }
1901+ if (strncmp (module_path , "node:" , strlen ("node:" )) == 0 ) {
1902+ return true;
1903+ }
1904+ /* Only an npm package-name shape: `pkg[/sub]` or `@scope/pkg[/sub]`.
1905+ * Bundler aliases (`@/x`, `~/x`) and `#x` subpath imports keep the
1906+ * fallbacks, since no package name spells them. */
1907+ const char * s = module_path ;
1908+ if (* s == '@' ) {
1909+ s ++ ;
1910+ if (!isalnum ((unsigned char )* s )) {
1911+ return false;
1912+ }
1913+ while (* s && * s != '/' ) {
1914+ s ++ ;
1915+ }
1916+ if (* s != '/' ) {
1917+ return false;
1918+ }
1919+ s ++ ;
1920+ }
1921+ return isalnum ((unsigned char )* s ) != 0 ;
1922+ }
1923+
18221924/* A Python def or class declared inside a function body -- a closure, a
18231925 * decorator's `wrapper`, a test's local class -- is a local of that function:
18241926 * no import can name it. Its QN extends a Function/Method node's
@@ -2414,6 +2516,11 @@ static const cbm_gbuf_node_t *resolve_import_strategies(
24142516 return target ;
24152517 }
24162518
2519+ /* A bare JS/TS specifier Strategy 1 missed is external: no edge. */
2520+ if (js_external_bare_specifier (src_lang , imp -> module_path )) {
2521+ return NULL ;
2522+ }
2523+
24172524 /* Name-guess fallbacks below (Strategy 1b sibling-file, Strategy 3
24182525 * symbol-name) are gated per importing-file language — see
24192526 * cbm_import_symbol_fallback_allowed (#1934). */
0 commit comments