@akanjs/language 3.2.0-rc.18 → 3.2.0-rc.19

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.
@@ -40,6 +40,7 @@ interface ModuleExports {
40
40
  fileName: string;
41
41
  }) | null;
42
42
  stars: string[];
43
+ isLocal: boolean;
43
44
  }
44
45
  interface Declaration {
45
46
  source: TS.SourceFile;
@@ -59,6 +60,7 @@ export declare class GuardResolver {
59
60
  declarationOf(owner: string, name: string, near: string | null, depth?: number): Declaration | null;
60
61
  starExportsOf(owner: string, near: string): StarExports;
61
62
  exportsAt(path: string, name: string): ModuleExports;
63
+ mentionsAlong(path: string, name: string): boolean;
62
64
  declares(owner: string, name: string): boolean;
63
65
  declaresAt(path: string, name: string): boolean;
64
66
  inOwner(fileName: string, owner: string | null): string;
package/index.cjs CHANGED
@@ -474,7 +474,7 @@ var ownerOf = (relativePath) => {
474
474
  const [root, name] = relativePath.split("/");
475
475
  return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
476
476
  };
477
- var createFactReader = (ts, ast) => {
477
+ var syntaxReaderOf = (ts, ast) => {
478
478
  const spanOf = (source, node) => {
479
479
  const start = node.getStart(source);
480
480
  const end = node.getEnd();
@@ -532,6 +532,74 @@ var createFactReader = (ts, ast) => {
532
532
  const node = keyName(property);
533
533
  return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
534
534
  });
535
+ const verbReaderOf = (parameter) => {
536
+ const verbs = new Map;
537
+ if (parameter && ts.isObjectBindingPattern(parameter.name))
538
+ for (const element of parameter.name.elements) {
539
+ const verb = element.propertyName ?? element.name;
540
+ if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
541
+ verbs.set(element.name.text, verb.text);
542
+ }
543
+ const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
544
+ return (callee) => {
545
+ if (callee && ts.isIdentifier(callee))
546
+ return verbs.get(callee.text) ?? null;
547
+ if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
548
+ return callee.name.text;
549
+ return null;
550
+ };
551
+ };
552
+ return {
553
+ spanOf,
554
+ extentOf,
555
+ unwrap,
556
+ moduleRefOf,
557
+ returnedObject,
558
+ builderOf,
559
+ guardNameOf,
560
+ optionObjectOf,
561
+ chainOf,
562
+ keyName,
563
+ objectKeys,
564
+ verbReaderOf
565
+ };
566
+ };
567
+ var sourceReaderOf = (ts) => {
568
+ const importsOf = (statement) => {
569
+ const { importClause, moduleSpecifier } = statement;
570
+ if (!importClause || !ts.isStringLiteral(moduleSpecifier))
571
+ return [];
572
+ const from = moduleSpecifier.text;
573
+ const bindings = importClause.namedBindings;
574
+ return [
575
+ ...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
576
+ ...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
577
+ ...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
578
+ name: element.name.text,
579
+ imported: (element.propertyName ?? element.name).text,
580
+ from
581
+ })) : []
582
+ ];
583
+ };
584
+ const docOf = (source, node) => {
585
+ const { text } = source;
586
+ const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
587
+ const comments = [];
588
+ let end = node.getStart(source);
589
+ for (const range of [...ranges].reverse()) {
590
+ if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
591
+ break;
592
+ comments.unshift(text.slice(range.pos, range.end));
593
+ end = range.pos;
594
+ }
595
+ const lines = comments.flatMap((comment) => comment.split(`
596
+ `)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
597
+ return lines.length ? lines.join(" ") : null;
598
+ };
599
+ const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
600
+ return { docOf, importsIn };
601
+ };
602
+ var signalKeyReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, optionObjectOf, chainOf, verbReaderOf }, guardsIn) => {
535
603
  const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
536
604
  if (!ts.isPropertyAssignment(property))
537
605
  return [];
@@ -550,23 +618,30 @@ var createFactReader = (ts, ast) => {
550
618
  }
551
619
  ];
552
620
  });
553
- const verbReaderOf = (parameter) => {
554
- const verbs = new Map;
555
- if (parameter && ts.isObjectBindingPattern(parameter.name))
556
- for (const element of parameter.name.elements) {
557
- const verb = element.propertyName ?? element.name;
558
- if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
559
- verbs.set(element.name.text, verb.text);
560
- }
561
- const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
562
- return (callee) => {
563
- if (callee && ts.isIdentifier(callee))
564
- return verbs.get(callee.text) ?? null;
565
- if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
566
- return callee.name.text;
567
- return null;
568
- };
621
+ const endpointKeysOf = (source, builder, made, model) => {
622
+ const verbOf = verbReaderOf(builder?.parameters[0]);
623
+ return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
624
+ if (!ts.isPropertyAssignment(property))
625
+ return [];
626
+ const name = ast.nodeName(property.name);
627
+ if (!name)
628
+ return [];
629
+ const { root, methods } = chainOf(property.initializer);
630
+ return [
631
+ {
632
+ name,
633
+ span: spanOf(source, property.name),
634
+ extent: extentOf(source, property),
635
+ verb: root ? verbOf(root.expression) : null,
636
+ guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
637
+ argCount: methods.filter((method) => argMethods.has(method)).length
638
+ }
639
+ ];
640
+ });
569
641
  };
642
+ return { sliceKeysOf, endpointKeysOf };
643
+ };
644
+ var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
570
645
  const numberOf = (expression) => {
571
646
  const value = unwrap(expression);
572
647
  if (ts.isNumericLiteral(value))
@@ -639,6 +714,9 @@ var createFactReader = (ts, ast) => {
639
714
  ];
640
715
  });
641
716
  };
717
+ return { internalKeysOf };
718
+ };
719
+ var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
642
720
  const plugsOf = (source, builder) => {
643
721
  const verbOf = verbReaderOf(builder?.parameters[0]);
644
722
  return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
@@ -664,27 +742,17 @@ var createFactReader = (ts, ast) => {
664
742
  visit(source);
665
743
  return bindings;
666
744
  };
667
- const endpointKeysOf = (source, builder, made, model) => {
668
- const verbOf = verbReaderOf(builder?.parameters[0]);
669
- return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
670
- if (!ts.isPropertyAssignment(property))
671
- return [];
672
- const name = ast.nodeName(property.name);
673
- if (!name)
674
- return [];
675
- const { root, methods } = chainOf(property.initializer);
676
- return [
677
- {
678
- name,
679
- span: spanOf(source, property.name),
680
- extent: extentOf(source, property),
681
- verb: root ? verbOf(root.expression) : null,
682
- guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
683
- argCount: methods.filter((method) => argMethods.has(method)).length
684
- }
685
- ];
686
- });
687
- };
745
+ const methodsOf = (source, statement) => statement.members.flatMap((member) => {
746
+ if (!ts.isMethodDeclaration(member) || !member.body)
747
+ return [];
748
+ const name = ast.nodeName(member.name);
749
+ if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
750
+ return [];
751
+ return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
752
+ });
753
+ return { plugsOf, adaptorBindingsIn, methodsOf };
754
+ };
755
+ var constantReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, keyName, objectKeys }) => {
688
756
  const filterQueriesOf = (source, builder) => {
689
757
  const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
690
758
  return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
@@ -722,48 +790,18 @@ var createFactReader = (ts, ast) => {
722
790
  return [];
723
791
  return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
724
792
  };
725
- const methodsOf = (source, statement) => statement.members.flatMap((member) => {
726
- if (!ts.isMethodDeclaration(member) || !member.body)
727
- return [];
728
- const name = ast.nodeName(member.name);
729
- if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
730
- return [];
731
- return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
732
- });
733
- const importsOf = (statement) => {
734
- const { importClause, moduleSpecifier } = statement;
735
- if (!importClause || !ts.isStringLiteral(moduleSpecifier))
736
- return [];
737
- const from = moduleSpecifier.text;
738
- const bindings = importClause.namedBindings;
739
- return [
740
- ...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
741
- ...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
742
- ...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
743
- name: element.name.text,
744
- imported: (element.propertyName ?? element.name).text,
745
- from
746
- })) : []
747
- ];
748
- };
749
- const docOf = (source, node) => {
750
- const { text } = source;
751
- const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
752
- const comments = [];
753
- let end = node.getStart(source);
754
- for (const range of [...ranges].reverse()) {
755
- if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
756
- break;
757
- comments.unshift(text.slice(range.pos, range.end));
758
- end = range.pos;
759
- }
760
- const lines = comments.flatMap((comment) => comment.split(`
761
- `)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
762
- return lines.length ? lines.join(" ") : null;
763
- };
793
+ return { constantOf, enumValuesOf, filterQueriesOf };
794
+ };
795
+ var createFactReader = (ts, ast) => {
796
+ const syntax = syntaxReaderOf(ts, ast);
797
+ const { spanOf, extentOf, unwrap, moduleRefOf, returnedObject, builderOf, chainOf, objectKeys } = syntax;
798
+ const { docOf, importsIn } = sourceReaderOf(ts);
764
799
  const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
800
+ const { sliceKeysOf, endpointKeysOf } = signalKeyReaderOf(ts, ast, syntax, guardsIn);
801
+ const { internalKeysOf } = jobKeyReaderOf(ts, ast, syntax);
802
+ const { plugsOf, adaptorBindingsIn, methodsOf } = serviceReaderOf(ts, ast, syntax);
803
+ const { constantOf, enumValuesOf, filterQueriesOf } = constantReaderOf(ts, ast, syntax);
765
804
  const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
766
- const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
767
805
  const read = (source, owner) => {
768
806
  const imports = importsIn(source);
769
807
  const madeInPlace = [];
@@ -865,6 +903,7 @@ var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
865
903
  var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
866
904
  var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
867
905
  var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
906
+ var exportMentioningPatternOf = (name) => new RegExp(`export\\s[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
868
907
  var declaringPatternOf = (name, isAnyBinding) => {
869
908
  const escaped = escapeRegExp(name);
870
909
  const braced = "\\{(?:[^}]*?[\\s,])?";
@@ -887,6 +926,8 @@ class GuardResolver {
887
926
  #declarations = new Map;
888
927
  #starExports = new Map;
889
928
  #moduleExports = new Map;
929
+ #fileStars = new Map;
930
+ #starReach = new Map;
890
931
  #ownerFiles = null;
891
932
  #modules = null;
892
933
  #barrels = null;
@@ -1244,27 +1285,78 @@ ${name}`;
1244
1285
  const cached = this.#moduleExports.get(key);
1245
1286
  if (cached)
1246
1287
  return cached;
1247
- const found = { named: null, stars: this.#barrelAt(path) ?? [] };
1248
- const exporting = exportingPatternOf(name);
1288
+ const found = { named: null, stars: [], isLocal: false };
1289
+ const stars = new Set(this.#barrelAt(path));
1249
1290
  for (const fileName of this.#modulesAt(path)) {
1250
1291
  const text = this.#source.readText(fileName);
1251
1292
  if (text === undefined)
1252
1293
  continue;
1253
- const named = identifierPattern.test(name) && exporting.test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name) : null;
1294
+ const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name) : null;
1254
1295
  if (named) {
1255
1296
  found.named = { ...named, fileName };
1256
- found.stars = [];
1257
1297
  break;
1258
1298
  }
1259
- for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
1260
- const target = this.pathOfSpecifier(fileName, specifier);
1261
- if (target !== null && !found.stars.includes(target))
1262
- found.stars.push(target);
1299
+ if (text.includes(name) && exportMentioningPatternOf(name).test(text) && this.#exportsLocally(this.#source.parse(fileName, text), name)) {
1300
+ found.isLocal = true;
1301
+ break;
1263
1302
  }
1303
+ for (const target of this.#starsIn(fileName, text))
1304
+ stars.add(target);
1264
1305
  }
1306
+ if (!found.named && !found.isLocal)
1307
+ found.stars = [...stars];
1265
1308
  this.#moduleExports.set(key, found);
1266
1309
  return found;
1267
1310
  }
1311
+ #exportsLocally(source, name) {
1312
+ const { ts } = this.#source;
1313
+ const binds = (node) => ts.isIdentifier(node) ? node.text === name : node.elements.some((element) => !ts.isOmittedExpression(element) && binds(element.name));
1314
+ return source.statements.some((statement) => {
1315
+ if (ts.isExportDeclaration(statement))
1316
+ return !statement.moduleSpecifier && !statement.isTypeOnly && !!statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.some((element) => !element.isTypeOnly && element.name.text === name);
1317
+ const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
1318
+ if (!modifiers.some(({ kind }) => kind === ts.SyntaxKind.ExportKeyword) || modifiers.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword))
1319
+ return false;
1320
+ if (ts.isVariableStatement(statement))
1321
+ return statement.declarationList.declarations.some((declaration) => binds(declaration.name));
1322
+ return (ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement) || ts.isEnumDeclaration(statement) || ts.isModuleDeclaration(statement) || ts.isImportEqualsDeclaration(statement)) && !!statement.name && ts.isIdentifier(statement.name) && statement.name.text === name;
1323
+ });
1324
+ }
1325
+ mentionsAlong(path, name) {
1326
+ return this.#starReachOf(path).some((text) => text.includes(name));
1327
+ }
1328
+ #starReachOf(path) {
1329
+ const cached = this.#starReach.get(path);
1330
+ if (cached)
1331
+ return cached;
1332
+ const paths = new Set([path]);
1333
+ const texts = [];
1334
+ for (const at of paths) {
1335
+ for (const next of this.#barrelAt(at) ?? [])
1336
+ paths.add(next);
1337
+ for (const fileName of this.#modulesAt(at)) {
1338
+ const text = this.#source.readText(fileName) ?? "";
1339
+ texts.push(text);
1340
+ for (const next of this.#starsIn(fileName, text))
1341
+ paths.add(next);
1342
+ }
1343
+ }
1344
+ this.#starReach.set(path, texts);
1345
+ return texts;
1346
+ }
1347
+ #starsIn(fileName, text) {
1348
+ const cached = this.#fileStars.get(fileName);
1349
+ if (cached)
1350
+ return cached;
1351
+ const found = [];
1352
+ for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
1353
+ const target = this.pathOfSpecifier(fileName, specifier);
1354
+ if (target !== null)
1355
+ found.push(target);
1356
+ }
1357
+ this.#fileStars.set(fileName, found);
1358
+ return found;
1359
+ }
1268
1360
  #modulesAt(path) {
1269
1361
  if (!this.#modules) {
1270
1362
  this.#modules = new Map;
@@ -1356,6 +1448,9 @@ ${name}`;
1356
1448
  var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
1357
1449
  var packageKeyOf = ({ name, from }) => `${packageOf(from)}
1358
1450
  ${name}`;
1451
+ var exportedKeyOf = (item) => ("fact" in item) ? item.id : ("local" in item) ? `${item.local}
1452
+ ` : packageKeyOf(item);
1453
+ var isPackageExport = (item) => ("from" in item);
1359
1454
 
1360
1455
  class AdaptorResolver {
1361
1456
  #source;
@@ -1364,6 +1459,7 @@ class AdaptorResolver {
1364
1459
  #adaptors = new Map;
1365
1460
  #plugs = new Map;
1366
1461
  #serviceFields = new Set;
1462
+ #exported = new Map;
1367
1463
  constructor(source, resolver, sink) {
1368
1464
  this.#source = source;
1369
1465
  this.#resolver = resolver;
@@ -1446,33 +1542,66 @@ ${field}`))
1446
1542
  return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
1447
1543
  if (own.length === 1)
1448
1544
  return first;
1449
- const exported = this.#exportedAt(name, path, new Set).filter((item) => first || ("fact" in item));
1545
+ const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
1450
1546
  const [only] = exported;
1451
1547
  if (only)
1452
- return exported.length === 1 ? only : null;
1548
+ return exported.length === 1 && !("local" in only) ? only : null;
1453
1549
  return first ? null : undefined;
1454
1550
  }
1455
- #exportedAt(name, path, seen) {
1551
+ #exportedAt(name, path) {
1456
1552
  const key = `${path}
1457
1553
  ${name}`;
1458
- if (seen.has(key))
1554
+ const cached = this.#exported.get(key);
1555
+ if (cached)
1556
+ return cached;
1557
+ if (!this.#resolver.mentionsAlong(path, name)) {
1558
+ this.#exported.set(key, []);
1459
1559
  return [];
1460
- seen.add(key);
1461
- const here = (this.#adaptors.get(name) ?? []).filter((adaptor) => {
1462
- const module2 = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
1463
- return module2 === path || module2 === `${path}/index`;
1464
- });
1560
+ }
1561
+ const reached = new Map;
1562
+ const seen = new Set;
1563
+ const pending = [[name, path]];
1564
+ for (let next = pending.pop();next; next = pending.pop()) {
1565
+ const [wanted, at] = next;
1566
+ if (seen.has(`${at}
1567
+ ${wanted}`))
1568
+ continue;
1569
+ seen.add(`${at}
1570
+ ${wanted}`);
1571
+ for (const item of this.#bindingAt(wanted, at, pending))
1572
+ reached.set(exportedKeyOf(item), item);
1573
+ }
1574
+ const found = [...reached.values()];
1575
+ this.#exported.set(key, found);
1576
+ return found;
1577
+ }
1578
+ #bindingAt(name, path, pending) {
1579
+ const here = this.#declaredAt(name, path);
1465
1580
  if (here.length)
1466
1581
  return here;
1467
- const { named, stars } = this.#resolver.exportsAt(path, name);
1468
- if (named?.from && this.#resolver.pathOfSpecifier(named.fileName, named.from) === null)
1469
- return [{ name: named.name === "default" ? name : named.name, from: named.from }];
1582
+ const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
1583
+ if (isLocal)
1584
+ return [{ local: path }];
1585
+ if (named?.from === null) {
1586
+ const local = this.#declaredAt(named.name, path);
1587
+ return local.length ? local : [{ local: path }];
1588
+ }
1470
1589
  if (named) {
1471
- const target = named.from === null ? path : this.#resolver.pathOfSpecifier(named.fileName, named.from);
1472
- return target === null ? [] : this.#exportedAt(named.name, target, seen);
1590
+ const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
1591
+ if (target === null)
1592
+ return [{ name: named.name === "default" ? name : named.name, from: named.from }];
1593
+ pending.push([named.name, target]);
1594
+ return [];
1473
1595
  }
1474
- const reached = stars.flatMap((star) => this.#exportedAt(name, star, seen));
1475
- return [...new Map(reached.map((item) => ["fact" in item ? item.id : packageKeyOf(item), item])).values()];
1596
+ for (const star of stars)
1597
+ pending.push([name, star]);
1598
+ return [];
1599
+ }
1600
+ #declaredAt(name, path) {
1601
+ return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
1602
+ const module2 = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
1603
+ return module2 === path || module2 === `${path}/index`;
1604
+ });
1476
1605
  }
1477
1606
  #packageAdaptorOf(name, specifier) {
1478
1607
  if (frameworkPattern.test(specifier))
@@ -1483,14 +1612,15 @@ ${name}`;
1483
1612
  #packageShimOf(owner, name, near) {
1484
1613
  if (!near)
1485
1614
  return null;
1486
- const shims = this.#exportedAt(name, near, new Set).filter((item) => !("fact" in item));
1615
+ const shims = this.#exportedAt(name, near).filter(isPackageExport);
1487
1616
  const [shim] = shims;
1488
1617
  if (shim)
1489
1618
  return shims.length === 1 ? shim : null;
1490
1619
  const { packages, paths } = this.#resolver.starExportsOf(owner, near);
1491
1620
  const [only] = packages;
1492
- const isDeclared = paths.some((path) => this.#resolver.declaresAt(path, name));
1493
- return only && new Set(packages.map(packageOf)).size === 1 && !isDeclared ? { name, from: only } : null;
1621
+ if (!only || new Set(packages.map(packageOf)).size !== 1)
1622
+ return null;
1623
+ return paths.some((path) => this.#resolver.declaresAt(path, name)) ? null : { name, from: only };
1494
1624
  }
1495
1625
  #nodeOf({ fact, owner, fileName, id }) {
1496
1626
  const detail = fact.refName ? [fact.refName] : [];