layermap 0.1.47 → 0.1.48

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/README.md CHANGED
@@ -226,6 +226,7 @@ npx layermap refs src/billing/tax.ts calculateTax
226
226
  npx layermap check --base main
227
227
  npx layermap check test/billing.test.ts # also: what of the change this test does not run
228
228
  npx layermap check --json # as JSON: related tests by rank, what the map cannot follow, the imports and calls it changes between files
229
+ npx layermap imports --json # every import of the project as it is now, test files apart: file and line, the file imported, and why the rest reach no file
229
230
  ```
230
231
 
231
232
  ## FAQ
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -14755,7 +14755,6 @@ process.once(
14755
14755
  operation: message.operation,
14756
14756
  files: message.files,
14757
14757
  release: message.release,
14758
- tests: message.tests,
14759
14758
  lombok: path3.join(path3.dirname(message.compilerPath), "lombok.jar"),
14760
14759
  ...message.targets ? { targets: message.targets } : {},
14761
14760
  ...message.incremental ? { incremental: message.incremental } : {}
@@ -120972,10 +120972,9 @@ function docstring(statements) {
120972
120972
  return inner.length === 1 && inner[0]?.nodeType === 48 /* StringList */ ? inner[0] : void 0;
120973
120973
  }
120974
120974
  var Extraction = class {
120975
- constructor(source, evaluator, tests) {
120975
+ constructor(source, evaluator) {
120976
120976
  this.source = source;
120977
120977
  this.evaluator = evaluator;
120978
- this.tests = tests;
120979
120978
  this.facts = { files: [], objects: [], relations: [], notes: [], typeErrors: 0 };
120980
120979
  // Objects by the start of their declaring name, per file.
120981
120980
  this.byName = /* @__PURE__ */ new Map();
@@ -121055,9 +121054,6 @@ var Extraction = class {
121055
121054
  end: end(node)
121056
121055
  });
121057
121056
  }
121058
- isTest(path3) {
121059
- return this.tests.has(path3);
121060
- }
121061
121057
  // Declarations a name refers to, with imports followed to what they import. An import that
121062
121058
  // resolves nowhere stays an alias declaration.
121063
121059
  declarations(name) {
@@ -121852,8 +121848,12 @@ var Relater = class extends ParseTreeWalker {
121852
121848
  }
121853
121849
  imports(module, site, from) {
121854
121850
  const specifier = `${".".repeat(module.d.leadingDots)}${module.d.nameParts.map((part) => part.d.value).join(".")}`;
121855
- const kind = this.x.isTest(this.path) ? "TEST_IMPORTS" : "IMPORTS";
121856
- const fact = { kind, from: this.top(this.executing), start: site.start, end: end(site) };
121851
+ const fact = {
121852
+ kind: "IMPORTS",
121853
+ from: this.top(this.executing),
121854
+ start: site.start,
121855
+ end: end(site)
121856
+ };
121857
121857
  const result = getImportInfo(module, this.x.source.program.analyzerNodeInfoReader);
121858
121858
  const resolved2 = result?.isImportFound ? result.resolvedUris.at(-1) : void 0;
121859
121859
  const path3 = resolved2 && !resolved2.isEmpty() ? this.x.source.pathOf(resolved2) : void 0;
@@ -121945,10 +121945,10 @@ function implementations(x2) {
121945
121945
  }
121946
121946
  }
121947
121947
  }
121948
- function extractPython(source, tests) {
121948
+ function extractPython(source) {
121949
121949
  const evaluator = source.program.evaluator;
121950
121950
  if (!evaluator) throw new Error("PROJECT_MAP_ANALYSIS_FAILED");
121951
- const x2 = new Extraction(source, evaluator, tests);
121951
+ const x2 = new Extraction(source, evaluator);
121952
121952
  const modules = [];
121953
121953
  for (const path3 of source.paths) {
121954
121954
  const uri = source.uriOf(path3);
@@ -122118,7 +122118,7 @@ process.once(
122118
122118
  process.send?.({ result: findPythonReferences(source, message.targets) });
122119
122119
  } else {
122120
122120
  trace.phase = "TRAVERSAL";
122121
- process.send?.({ result: extractPython(source, new Set(message.tests)) });
122121
+ process.send?.({ result: extractPython(source) });
122122
122122
  }
122123
122123
  } finally {
122124
122124
  trace.phase = "DISPOSE";
@@ -30122,8 +30122,7 @@ var MapRelationKindSchema = external_exports.enum([
30122
30122
  "IMPLEMENTS",
30123
30123
  // A member that implements or overrides the target member, so calls to it may dispatch here.
30124
30124
  "OVERRIDES",
30125
- "DECORATED_BY",
30126
- "TEST_IMPORTS"
30125
+ "DECORATED_BY"
30127
30126
  ]);
30128
30127
  var MapObjectLocatorSchema = external_exports.object({
30129
30128
  path: external_exports.string().min(1),
@@ -30185,7 +30184,6 @@ var MAP_RELATION_PRIORITY = Object.freeze({
30185
30184
  CALLS: 0,
30186
30185
  WRITES: 0,
30187
30186
  IMPORTS: 0,
30188
- TEST_IMPORTS: 0,
30189
30187
  EXTENDS: 0,
30190
30188
  IMPLEMENTS: 0,
30191
30189
  OVERRIDES: 0,
@@ -31991,7 +31989,6 @@ function isMapWrite(node) {
31991
31989
 
31992
31990
  // src/project-map-extract.ts
31993
31991
  var key = (node) => `${node.getSourceFile().fileName}:${node.pos}:${node.kind}`;
31994
- var IMPORT_RELATIONS = /* @__PURE__ */ new Set(["IMPORTS", "TEST_IMPORTS"]);
31995
31992
  var declares = (node) => Boolean(mapExecutionDeclaration(node) || mapDeclarationKind(node, true) && mapDeclarationName(node));
31996
31993
  var declarationName = (node) => {
31997
31994
  const execution = mapExecutionDeclaration(node);
@@ -32225,7 +32222,7 @@ async function extractProjectMap(project, input, trace, read, installed) {
32225
32222
  reference = {
32226
32223
  node,
32227
32224
  lookup: moduleSpecifier,
32228
- kind: /(?:^|[/.])(?:test|spec|tests)(?:[/.]|$)/u.test(path10) ? "TEST_IMPORTS" : "IMPORTS",
32225
+ kind: "IMPORTS",
32229
32226
  target: moduleSpecifier.text
32230
32227
  };
32231
32228
  } else if (isCallExpression(node) || isNewExpression(node)) {
@@ -32667,7 +32664,7 @@ async function extractProjectMap(project, input, trace, read, installed) {
32667
32664
  if (name) notInstalled.add(name);
32668
32665
  }
32669
32666
  for (const relation of output.relations) {
32670
- if (!IMPORT_RELATIONS.has(relation.kind) || relation.unresolvedReason !== "SYMBOL_NOT_RESOLVED")
32667
+ if (relation.kind !== "IMPORTS" || relation.unresolvedReason !== "SYMBOL_NOT_RESOLVED")
32671
32668
  continue;
32672
32669
  const name = mapPackageOf(relation.target);
32673
32670
  if (name && !installed(relation.anchor.path, name)) notInstalled.add(name);
package/dist/cli.mjs CHANGED
@@ -15955,8 +15955,7 @@ var MapRelationKindSchema = external_exports.enum([
15955
15955
  "IMPLEMENTS",
15956
15956
  // A member that implements or overrides the target member, so calls to it may dispatch here.
15957
15957
  "OVERRIDES",
15958
- "DECORATED_BY",
15959
- "TEST_IMPORTS"
15958
+ "DECORATED_BY"
15960
15959
  ]);
15961
15960
  var MapObjectLocatorSchema = external_exports.object({
15962
15961
  path: external_exports.string().min(1),
@@ -16018,7 +16017,6 @@ var MAP_RELATION_PRIORITY = Object.freeze({
16018
16017
  CALLS: 0,
16019
16018
  WRITES: 0,
16020
16019
  IMPORTS: 0,
16021
- TEST_IMPORTS: 0,
16022
16020
  EXTENDS: 0,
16023
16021
  IMPLEMENTS: 0,
16024
16022
  OVERRIDES: 0,
@@ -16855,7 +16853,6 @@ var relationWeight = {
16855
16853
  WRITES: 1200,
16856
16854
  READS: 900,
16857
16855
  IMPORTS: 800,
16858
- TEST_IMPORTS: 700,
16859
16856
  EXTENDS: 900,
16860
16857
  IMPLEMENTS: 900,
16861
16858
  OVERRIDES: 900,
@@ -16863,6 +16860,7 @@ var relationWeight = {
16863
16860
  REFERENCES: 500,
16864
16861
  CONTAINS: 250
16865
16862
  };
16863
+ var TEST_IMPORT_WEIGHT = 700;
16866
16864
  function mapSearchFocus(store, version2, refs, scope, signal) {
16867
16865
  const found = /* @__PURE__ */ new Map();
16868
16866
  if (!refs.length) return found;
@@ -16873,7 +16871,7 @@ function mapSearchFocus(store, version2, refs, scope, signal) {
16873
16871
  throw new ProjectEvidenceError("PROJECT_MAP_OBJECT_NOT_FOUND", false);
16874
16872
  for (const ref of refs) found.set(ref, { distance: 0, score: 1800 });
16875
16873
  let frontier = new Set(refs);
16876
- const edges = store.database.prepare(`SELECT r.from_ref, r.to_ref,
16874
+ const edges = store.database.prepare(`SELECT r.from_ref, r.to_ref, r.path,
16877
16875
  json_extract(r.relation_json, '$.kind') AS kind
16878
16876
  FROM project_map_relations r
16879
16877
  JOIN project_map_objects f ON f.version_ref = r.version_ref AND f.entity_ref = r.from_ref
@@ -16893,7 +16891,8 @@ function mapSearchFocus(store, version2, refs, scope, signal) {
16893
16891
  assertMapSearchActive(signal);
16894
16892
  const from = String(row.from_ref);
16895
16893
  const to = String(row.to_ref);
16896
- const weight = relationWeight[String(row.kind)];
16894
+ const kind = String(row.kind);
16895
+ const weight = kind === "IMPORTS" && mapTestPath(String(row.path)) ? TEST_IMPORT_WEIGHT : relationWeight[kind];
16897
16896
  if (weight === void 0)
16898
16897
  throw new ProjectEvidenceError("PROJECT_EVIDENCE_STORE_CORRUPT", false);
16899
16898
  for (const [parent, neighbor] of [
@@ -17306,6 +17305,36 @@ function mapPageFrontier(frontier, rows2) {
17306
17305
  return frontier.filter(({ entityRef }) => visible.has(entityRef)).map((node) => ({ ...node }));
17307
17306
  }
17308
17307
 
17308
+ // src/project-map-imports.ts
17309
+ function loadMapImports(store, version2) {
17310
+ return store.database.prepare(`SELECT DISTINCT r.path AS source, t.path AS target,
17311
+ json_extract(r.relation_json, '$.anchor.startLine') AS line,
17312
+ json_extract(r.relation_json, '$.target') AS specifier,
17313
+ json_extract(r.relation_json, '$.unresolvedReason') AS reason
17314
+ FROM project_map_relations r NOT INDEXED
17315
+ ${MAP_RELATION_TARGET_JOIN}
17316
+ WHERE r.version_ref = ? AND json_extract(r.relation_json, '$.kind') = 'IMPORTS'
17317
+ ORDER BY source, line, target, specifier`).all(version2).map((row) => {
17318
+ const site = {
17319
+ source: String(row.source),
17320
+ line: Number(row.line),
17321
+ specifier: String(row.specifier)
17322
+ };
17323
+ return row.target === null ? { ...site, target: null, reason: String(row.reason) } : { ...site, target: String(row.target) };
17324
+ });
17325
+ }
17326
+ function mapProjectImports(rows2) {
17327
+ const imports = [];
17328
+ const unresolved = [];
17329
+ for (const row of rows2) {
17330
+ if (mapTestPath(row.source)) continue;
17331
+ const { source: from, line, specifier } = row;
17332
+ if (row.target === null) unresolved.push({ from, line, specifier, reason: row.reason });
17333
+ else if (row.target !== from) imports.push({ from, line, to: row.target, specifier });
17334
+ }
17335
+ return { imports, unresolved };
17336
+ }
17337
+
17309
17338
  // src/project-map-language-go.ts
17310
17339
  import { existsSync as existsSync4 } from "node:fs";
17311
17340
  import { posix } from "node:path";
@@ -18113,7 +18142,7 @@ var goModule = /(?:^|\/)go\.mod$/u;
18113
18142
  var goWork = /(?:^|\/)go\.work$/u;
18114
18143
  var codeHosts = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org"]);
18115
18144
  var GO_MAP_LANGUAGE = Object.freeze({
18116
- id: "go-1.24-map-v10",
18145
+ id: "go-1.24-map-v11",
18117
18146
  claims: (path19) => path19.endsWith(".go"),
18118
18147
  reads: (path19) => goModule.test(path19) || goWork.test(path19),
18119
18148
  // A module path, or the standard library, whose first path element has no dot.
@@ -18326,7 +18355,7 @@ var nameOf = (path19) => path19.slice(path19.lastIndexOf("/") + 1);
18326
18355
  var DEFAULT_RELEASE = 21;
18327
18356
  var platformPackage = /^(?:java|jdk|sun|com\.sun|javax\.(?:annotation\.processing|crypto|imageio|lang\.model|management|naming|net|print|script|security|sound|sql|swing|tools|transaction\.xa|xml))(?:\.|$)/u;
18328
18357
  var JAVA_MAP_LANGUAGE = Object.freeze({
18329
- id: "javac-lombok-1.18.48-map-v9",
18358
+ id: "javac-lombok-1.18.48-map-v10",
18330
18359
  claims: (path19) => path19.endsWith(".java"),
18331
18360
  reads: (path19) => buildFile.test(path19),
18332
18361
  // A package of the Java platform, or a library named by its first two package segments.
@@ -18415,15 +18444,14 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18415
18444
  observe?.({ ...event, phase: "FINISHED", elapsedMs: performance.now() - start });
18416
18445
  }
18417
18446
  }
18418
- // The worker's request for a context: the Java sources, the release and which are tests.
18447
+ // The worker's request for a context: the Java sources and the release.
18419
18448
  request(input, buildTexts) {
18420
18449
  const files = /* @__PURE__ */ Object.create(null);
18421
18450
  for (const [path19, text] of Object.entries(input.files))
18422
18451
  if (this.claims(path19)) files[path19] = text;
18423
18452
  return {
18424
18453
  files,
18425
- release: javaRelease(buildTexts, this.resources.runtimeVersion),
18426
- tests: Object.keys(files).filter((path19) => mapTestPath(path19))
18454
+ release: javaRelease(buildTexts, this.resources.runtimeVersion)
18427
18455
  };
18428
18456
  }
18429
18457
  // The build files of a context's root directory, which declare its Java version.
@@ -18507,7 +18535,6 @@ var JavaMapAnalyzer = class _JavaMapAnalyzer {
18507
18535
  {
18508
18536
  configPath: configPath || null,
18509
18537
  release: request.release,
18510
- tests: request.tests,
18511
18538
  runtime,
18512
18539
  built: existsSync5(this.resources.compilerPath),
18513
18540
  lombokConfig
@@ -18881,7 +18908,7 @@ var pythonConfig = /(?:^|\/)(?:pyrightconfig\.json|pyproject\.toml|setup\.cfg)$/
18881
18908
  var directoryOf2 = (path19) => path19.slice(0, path19.lastIndexOf("/") + 1);
18882
18909
  var DEFAULT_PYTHON = { major: 3, minor: 13 };
18883
18910
  var PYTHON_MAP_LANGUAGE = Object.freeze({
18884
- id: "pyright-1.1.414-map-v13",
18911
+ id: "pyright-1.1.414-map-v14",
18885
18912
  claims: (path19) => /\.pyi?$/u.test(path19),
18886
18913
  reads: (path19) => pythonConfig.test(path19),
18887
18914
  // An absolute import names the standard library or a distribution's top-level package.
@@ -18934,8 +18961,7 @@ var PythonMapAnalyzer = class {
18934
18961
  request(input) {
18935
18962
  return {
18936
18963
  root: input.configPath ? directoryOf2(input.configPath).replace(/\/$/u, "") : "",
18937
- pythonVersion: pythonVersion(input.files, input.configPath),
18938
- tests: Object.keys(input.files).filter((path19) => this.claims(path19) && mapTestPath(path19))
18964
+ pythonVersion: pythonVersion(input.files, input.configPath)
18939
18965
  };
18940
18966
  }
18941
18967
  async analyze(session, signal) {
@@ -19071,7 +19097,7 @@ var miniprogramEventOf = (target) => {
19071
19097
 
19072
19098
  // src/project-map-language-typescript.ts
19073
19099
  var TYPESCRIPT_MAP_LANGUAGE = Object.freeze({
19074
- id: "typescript-7.0.2-map-v33",
19100
+ id: "typescript-7.0.2-map-v34",
19075
19101
  claims: (path19) => /\.[cm]?[jt]sx?$/u.test(path19),
19076
19102
  readsRequests: true,
19077
19103
  reads: (path19) => path19.endsWith(".json") || path19.endsWith(".wxml") || path19 === "pnpm-workspace.yaml",
@@ -19575,19 +19601,6 @@ function mapProjectModules(entries) {
19575
19601
  return module && moduleLabel(module);
19576
19602
  };
19577
19603
  }
19578
- function loadImports(store, version2) {
19579
- return store.database.prepare(`SELECT r.path AS source, t.path AS target,
19580
- json_extract(r.relation_json, '$.target') AS specifier, count(*) AS count
19581
- FROM project_map_relations r NOT INDEXED
19582
- ${MAP_RELATION_TARGET_JOIN}
19583
- WHERE r.version_ref = ? AND json_extract(r.relation_json, '$.kind') IN ('IMPORTS', 'TEST_IMPORTS')
19584
- GROUP BY source, target, specifier`).all(version2).map((row) => ({
19585
- source: String(row.source),
19586
- target: row.target === null ? null : String(row.target),
19587
- specifier: String(row.specifier),
19588
- count: Number(row.count)
19589
- }));
19590
- }
19591
19604
  function loadDirectoryFacts(store, version2) {
19592
19605
  const files = /* @__PURE__ */ new Map();
19593
19606
  const declarations2 = [];
@@ -19656,7 +19669,6 @@ function loadDirectoryFacts(store, version2) {
19656
19669
  ]);
19657
19670
  }
19658
19671
  for (const list of exported.values()) list.sort((left, right) => left.start - right.start);
19659
- const imports = loadImports(store, version2);
19660
19672
  const calls = /* @__PURE__ */ new Map();
19661
19673
  for (const row of store.database.prepare(`SELECT path, count(*) AS total, sum(to_ref IS NOT NULL) AS resolved,
19662
19674
  sum(to_ref IS NULL AND json_extract(relation_json, '$.unresolvedReason')
@@ -19672,7 +19684,7 @@ function loadDirectoryFacts(store, version2) {
19672
19684
  unresolved: Number(row.total) - resolved - external
19673
19685
  });
19674
19686
  }
19675
- return { files, calls, exported, imports };
19687
+ return { files, calls, exported };
19676
19688
  }
19677
19689
  var MEMBER_NAME = /\.([A-Za-z_$][\w$]*)$/u;
19678
19690
  var memberKey = (language, name) => `${language}\0${name}`;
@@ -19764,7 +19776,7 @@ function loadCoverageNotes(store, version2) {
19764
19776
  }
19765
19777
  var MapViewCache = class {
19766
19778
  facts = new VersionCache(loadDirectoryFacts);
19767
- importRows = new VersionCache(loadImports);
19779
+ importRows = new VersionCache(loadMapImports);
19768
19780
  calls = new VersionCache(loadMemberCalls);
19769
19781
  coverage = new VersionCache(loadCoverageNotes);
19770
19782
  directoryFacts(store, version2) {
@@ -19786,7 +19798,7 @@ var MapViewCache = class {
19786
19798
  this.coverage.clear();
19787
19799
  }
19788
19800
  };
19789
- function directoryView(facts, coverage, entries, input, directory, prefixes) {
19801
+ function directoryView(facts, imports, coverage, entries, input, directory, prefixes) {
19790
19802
  const showTests = input.includeTests === true || mapTestPath(`${directory}/`);
19791
19803
  const inScope = entries.filter(
19792
19804
  (entry) => within(entry.path, directory) && mapPathAllowed(entry.path, prefixes)
@@ -19805,20 +19817,19 @@ function directoryView(facts, coverage, entries, input, directory, prefixes) {
19805
19817
  const moduleImports = /* @__PURE__ */ new Map();
19806
19818
  const external = /* @__PURE__ */ new Map();
19807
19819
  let unresolvedLocal = 0;
19808
- for (const row of facts.imports) {
19809
- const { source, target, specifier, count } = row;
19820
+ for (const { source, target, specifier } of imports) {
19810
19821
  const from = visiblePaths.has(source) ? moduleOf(source) : void 0;
19811
19822
  if (!from) continue;
19812
19823
  if (target === null) {
19813
- if (specifier.startsWith(".") || specifier.startsWith("/")) unresolvedLocal += count;
19814
- else increment(external, mapExternalImport(source, specifier), count);
19824
+ if (specifier.startsWith(".") || specifier.startsWith("/")) unresolvedLocal++;
19825
+ else increment(external, mapExternalImport(source, specifier));
19815
19826
  continue;
19816
19827
  }
19817
19828
  if (!mapPathAllowed(target, prefixes) || !showTests && mapTestPath(target)) continue;
19818
19829
  const to = within(target, directory) ? moduleOf(target) : void 0;
19819
19830
  if (to === from) continue;
19820
19831
  const edges = moduleImports.get(moduleLabel(from)) ?? /* @__PURE__ */ new Map();
19821
- increment(edges, to ? moduleLabel(to) : outside(target), count);
19832
+ increment(edges, to ? moduleLabel(to) : outside(target));
19822
19833
  moduleImports.set(moduleLabel(from), edges);
19823
19834
  }
19824
19835
  const blocks = [];
@@ -19974,8 +19985,7 @@ var OUTGOING = {
19974
19985
  CALLS: "calls",
19975
19986
  REFERENCES: "uses as value",
19976
19987
  WRITES: "writes",
19977
- IMPORTS: "imports",
19978
- TEST_IMPORTS: "test imports"
19988
+ IMPORTS: "imports"
19979
19989
  };
19980
19990
  var INCOMING = {
19981
19991
  CALLS: "called by",
@@ -19985,7 +19995,6 @@ var INCOMING = {
19985
19995
  IMPLEMENTS: "implemented by",
19986
19996
  DECORATED_BY: "decorates"
19987
19997
  };
19988
- var IMPORT_KINDS = /* @__PURE__ */ new Set(["IMPORTS", "TEST_IMPORTS"]);
19989
19998
  var shows = (relation) => relation.kind === "REFERENCES" && mapMiniprogramTemplate(relation.anchor.path);
19990
19999
  var callerCoverage = (textSearch) => `Calls through dependency injection, framework routing, reflection or computed names are not mapped, so a complete view is not a complete caller list; confirm impact with project_find_references or ${textSearch}.`;
19991
20000
  var SPECIAL_METHOD = /^__\w+__$/u;
@@ -20086,7 +20095,7 @@ var DeclarationGroups = class {
20086
20095
  stops.set(key, value);
20087
20096
  if (relation.to === void 0) continue;
20088
20097
  }
20089
- if (IMPORT_KINDS.has(relation.kind) && mapIsModule(graph.object(relation.from))) continue;
20098
+ if (relation.kind === "IMPORTS" && mapIsModule(graph.object(relation.from))) continue;
20090
20099
  if (relation.to === void 0) {
20091
20100
  if (relation.kind === "DECORATED_BY")
20092
20101
  tags.push(decoratorTag(relation.target, relation.argument, relation.route));
@@ -20116,7 +20125,7 @@ var DeclarationGroups = class {
20116
20125
  else
20117
20126
  add(
20118
20127
  "\u2192",
20119
- relation.event ? `calls via ${relation.event} event` : shows(relation) ? "shows" : OUTGOING[relation.kind] ?? relation.kind.toLowerCase(),
20128
+ relation.event ? `calls via ${relation.event} event` : shows(relation) ? "shows" : relation.kind === "IMPORTS" && mapTestPath(relation.anchor.path) ? "test imports" : OUTGOING[relation.kind] ?? relation.kind.toLowerCase(),
20120
20129
  other,
20121
20130
  relation.anchor.startLine,
20122
20131
  relation.argument
@@ -20134,7 +20143,7 @@ var DeclarationGroups = class {
20134
20143
  );
20135
20144
  continue;
20136
20145
  }
20137
- if (!incoming || relation.kind === "CONTAINS" || IMPORT_KINDS.has(relation.kind)) continue;
20146
+ if (!incoming || relation.kind === "CONTAINS" || relation.kind === "IMPORTS") continue;
20138
20147
  const other = graph.object(graph.owner(relation.from));
20139
20148
  if (owned.has(other.id)) continue;
20140
20149
  if (!this.visible(relation.anchor.path)) {
@@ -20307,7 +20316,7 @@ function fileView(store, coverage, graph, input, path19, prefixes) {
20307
20316
  const external = /* @__PURE__ */ new Set();
20308
20317
  const fileObjects = graph.objectsAt(path19).map((object2) => object2.id);
20309
20318
  for (const relation of graph.relationsFrom(fileObjects)) {
20310
- if (!IMPORT_KINDS.has(relation.kind)) continue;
20319
+ if (relation.kind !== "IMPORTS") continue;
20311
20320
  if (relation.to === void 0) external.add(relation.target);
20312
20321
  else {
20313
20322
  const target = graph.object(relation.to).anchor.path;
@@ -20319,7 +20328,7 @@ function fileView(store, coverage, graph, input, path19, prefixes) {
20319
20328
  const imported = mapImportTarget(path19);
20320
20329
  const packageModules = imported === path19 ? [module.id] : store.listEntries(input.version).filter((entry2) => mapImportTarget(entry2.path) === imported).flatMap((entry2) => graph.objectsAt(entry2.path).filter((object2) => mapIsModule(object2))).map((object2) => object2.id);
20321
20330
  for (const relation of graph.relationsTo(packageModules)) {
20322
- if (!IMPORT_KINDS.has(relation.kind)) continue;
20331
+ if (relation.kind !== "IMPORTS") continue;
20323
20332
  const source = relation.anchor.path;
20324
20333
  if (!mapPathAllowed(source, prefixes)) continue;
20325
20334
  (!showTests && mapTestPath(source) ? testImporters : importers).add(source);
@@ -20425,6 +20434,7 @@ function mapView(store, input, cache = new MapViewCache()) {
20425
20434
  const coverage = cache.coverageNotes(store, input.version);
20426
20435
  return entry ? fileView(store, coverage, graph, input, input.path, prefixes) : directoryView(
20427
20436
  cache.directoryFacts(store, input.version),
20437
+ cache.imports(store, input.version),
20428
20438
  coverage,
20429
20439
  store.listEntries(input.version),
20430
20440
  input,
@@ -23280,7 +23290,6 @@ var USED_BY = {
23280
23290
  OVERRIDES: "overridden"
23281
23291
  };
23282
23292
  var runsTarget = (relation) => CALLER_KINDS.has(relation.kind) && !relation.event;
23283
- var IMPORT_KINDS2 = /* @__PURE__ */ new Set(["IMPORTS", "TEST_IMPORTS"]);
23284
23293
  var changeUnits = (graph, path19) => mapMiniprogramTemplate(path19) ? graph.objectsAt(path19).filter((object2) => mapIsModule(object2) && object2.parsing === "PARSED") : graph.declarationsAt(path19);
23285
23294
  function changedUnits(graph, path19, lines) {
23286
23295
  const refs = /* @__PURE__ */ new Set();
@@ -23863,7 +23872,7 @@ function linksOf(side, path19) {
23863
23872
  for (const relation of graph.relationsFrom(graph.objectsAt(path19).map((object2) => object2.id))) {
23864
23873
  const line = relation.anchor.startLine;
23865
23874
  if (relation.to === void 0 || !side.counts(path19, line)) continue;
23866
- if (IMPORT_KINDS2.has(relation.kind)) {
23875
+ if (relation.kind === "IMPORTS") {
23867
23876
  const target = graph.object(relation.to).anchor.path;
23868
23877
  if (target === path19) continue;
23869
23878
  const to = side.pathNow(target);
@@ -24106,7 +24115,7 @@ function importerTests(graph, objects2, tracer, importers) {
24106
24115
  const unread = modules.filter((module) => !importers.has(module));
24107
24116
  for (const module of unread) importers.set(module, []);
24108
24117
  for (const relation of graph.relationsTo(unread)) {
24109
- if (!IMPORT_KINDS2.has(relation.kind) || !relation.to) continue;
24118
+ if (relation.kind !== "IMPORTS" || !relation.to) continue;
24110
24119
  const importer = graph.object(relation.from);
24111
24120
  importers.get(relation.to)?.push({
24112
24121
  path: relation.anchor.path,
@@ -25205,10 +25214,9 @@ async function similarCode(store, working, base, files, read) {
25205
25214
  }
25206
25215
 
25207
25216
  // src/project-map-changes.ts
25208
- async function mapChangeImpact(store, working, base, changes, links, shapes, until, project, tests) {
25217
+ async function mapChangeImpact(store, views, working, base, changes, links, shapes, until, project, tests) {
25209
25218
  const graph = new MapViewGraph(store, working);
25210
- const cache = new MapViewCache();
25211
- const memberCalls = cache.memberCalls(store, working);
25219
+ const memberCalls = views.memberCalls(store, working);
25212
25220
  const tracer = new Tracer(
25213
25221
  graph,
25214
25222
  memberCalls,
@@ -25350,7 +25358,7 @@ async function mapChangeImpact(store, working, base, changes, links, shapes, unt
25350
25358
  supportTests(store, working, tracer);
25351
25359
  const taken = base ? await mapRemovedImpact({
25352
25360
  store,
25353
- cache,
25361
+ cache: views,
25354
25362
  base,
25355
25363
  graph,
25356
25364
  tracer,
@@ -25390,7 +25398,7 @@ async function mapChangeImpact(store, working, base, changes, links, shapes, unt
25390
25398
  unmapped,
25391
25399
  removedRoutes: taken?.removedRoutes ?? [],
25392
25400
  uncalled: taken?.uncalled ?? [],
25393
- dependencies: newModuleDependencies(store, cache, working, changes.files, links.files),
25401
+ dependencies: newModuleDependencies(store, views, working, changes.files, links.files),
25394
25402
  ...untested ? { untested } : {},
25395
25403
  truncated: tracer.truncated
25396
25404
  };
@@ -25503,8 +25511,10 @@ async function checkMapChanges(input, signal) {
25503
25511
  };
25504
25512
  const until = mapShapeDeadline();
25505
25513
  const links = mapChangeLinks(index.store, working, base, changes.files);
25514
+ const views = new MapViewCache();
25506
25515
  const impact = await mapChangeImpact(
25507
25516
  index.store,
25517
+ views,
25508
25518
  working,
25509
25519
  base,
25510
25520
  changes,
@@ -25527,6 +25537,7 @@ async function checkMapChanges(input, signal) {
25527
25537
  await mapRouteClients(project, index.store, working, impact, signal),
25528
25538
  reusable(
25529
25539
  index.store,
25540
+ views,
25530
25541
  working,
25531
25542
  await similarCode(
25532
25543
  index.store,
@@ -25536,13 +25547,13 @@ async function checkMapChanges(input, signal) {
25536
25547
  (file2) => readFile3(path13.join(project, file2), "utf8").catch(() => void 0)
25537
25548
  )
25538
25549
  ),
25539
- changes.files.length ? await compileBreaks(input, changes, base, until, signal) : void 0
25550
+ changes.files.length ? await compileBreaks(input, views, changes, base, until, signal) : void 0
25540
25551
  )
25541
25552
  };
25542
25553
  }
25543
- function reusable(store, working, similar) {
25554
+ function reusable(store, views, working, similar) {
25544
25555
  if (!similar.length) return [];
25545
- const importsFor = mapReuseImports(store, new MapViewCache(), working);
25556
+ const importsFor = mapReuseImports(store, views, working);
25546
25557
  return similar.flatMap((item) => {
25547
25558
  const imports = importsFor(item.path, item.like.path);
25548
25559
  return imports ? [{ ...item, imports }] : [];
@@ -25564,7 +25575,7 @@ async function mapRouteClients(project, store, working, impact, signal) {
25564
25575
  if (!routes.length) return { routes: [] };
25565
25576
  return routeClients(routes, registrations, git, gitOptions(project, signal));
25566
25577
  }
25567
- async function compileBreaks(input, changes, base, until, signal) {
25578
+ async function compileBreaks(input, views, changes, base, until, signal) {
25568
25579
  const { index, working } = input;
25569
25580
  const present = changes.files.filter((file2) => file2.status !== "DELETED").map((file2) => file2.path);
25570
25581
  const gone2 = changes.files.flatMap((file2) => file2.basePath ? [file2.basePath] : []);
@@ -25583,7 +25594,6 @@ async function compileBreaks(input, changes, base, until, signal) {
25583
25594
  signal
25584
25595
  );
25585
25596
  const missing = new Set(after.contexts.flatMap((context) => context.missing));
25586
- const views = new MapViewCache();
25587
25597
  const { notInstalled } = views.coverageNotes(index.store, working);
25588
25598
  if (notInstalled.length) {
25589
25599
  for (const { source, target, specifier } of views.imports(index.store, working))
@@ -25992,6 +26002,12 @@ var LayerMap = class _LayerMap {
25992
26002
  )
25993
26003
  );
25994
26004
  }
26005
+ /** Every import of the directory as it is now, by file of the project, test files apart. */
26006
+ imports(signal) {
26007
+ return this.using(
26008
+ async (hold) => mapProjectImports(loadMapImports(this.store, await this.current(signal, hold)))
26009
+ );
26010
+ }
25995
26011
  /**
25996
26012
  * What the working tree's changes against a commit (HEAD by default) affect: the changed and
25997
26013
  * removed declarations, the entry points and tests their callers reach, and what the map cannot
@@ -27002,6 +27018,9 @@ Usage:
27002
27018
  and what of them the test files given do not run; --json
27003
27019
  prints the related tests by rank and what the map cannot
27004
27020
  follow, for a program choosing which tests to run
27021
+ layermap imports [--json] every import of the project as it is now, test files
27022
+ apart: the file and line importing, the file imported,
27023
+ and the imports with no file of the project, with why
27005
27024
 
27006
27025
  The project is the Git work tree around the current directory unless --project names one; the MCP
27007
27026
  server also maps any other repository a tool call's path names.
@@ -27056,7 +27075,7 @@ async function main(argv) {
27056
27075
  return 0;
27057
27076
  }
27058
27077
  if (values.help || !command) return usage(command ? 0 : 1);
27059
- if (values.json && command !== "check") return usage(1);
27078
+ if (values.json && command !== "check" && command !== "imports") return usage(1);
27060
27079
  const { directory: project, git: git2 } = await projectDirectory(values.project ?? process.cwd());
27061
27080
  const cache = cacheDirectory();
27062
27081
  const open3 = async (directory) => {
@@ -27112,6 +27131,22 @@ async function main(argv) {
27112
27131
  `);
27113
27132
  return 0;
27114
27133
  }
27134
+ if (command === "imports") {
27135
+ const imports = await map2.imports(signal);
27136
+ process.stdout.write(
27137
+ values.json ? `${JSON.stringify(imports)}
27138
+ ` : [
27139
+ `IMPORTS (${imports.imports.length})`,
27140
+ ...imports.imports.map((item) => `${item.from}:${item.line} \u2192 ${item.to}`),
27141
+ `UNRESOLVED IMPORTS (${imports.unresolved.length})`,
27142
+ ...imports.unresolved.map(
27143
+ (item) => `${item.from}:${item.line} ${item.specifier} ${item.reason}`
27144
+ ),
27145
+ ""
27146
+ ].join("\n")
27147
+ );
27148
+ return 0;
27149
+ }
27115
27150
  const call = {
27116
27151
  explore: [
27117
27152
  MAP_TOOL_NAMES.explore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "layermap",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "mcpName": "io.github.coffeecoproject/layermap",
5
5
  "description": "A layered map of a codebase for coding agents: directories, modules and call chains across TypeScript, JavaScript, Go, Python and Java.",
6
6
  "license": "Apache-2.0",
package/pi/layermap.mjs CHANGED
@@ -293,7 +293,7 @@ function layermap(pi) {
293
293
  if (server && !server.dead) return server;
294
294
  starting ??= (async () => {
295
295
  const next = new MapServer(cwd);
296
- const tools = await next.start("0.1.47");
296
+ const tools = await next.start("0.1.48");
297
297
  for (const tool of tools) {
298
298
  if (registered.has(tool.name)) continue;
299
299
  registered.add(tool.name);