@g3nomaly/analyze 0.1.4 → 0.1.6

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.
@@ -1,6 +1,7 @@
1
1
  import { type SymbolKind } from '../../model';
2
2
  import type { Node, Query } from 'web-tree-sitter';
3
- import { type RawCall } from './calls';
3
+ import { type BodyReferences } from './calls';
4
+ import { type FileExports } from './exports';
4
5
  import type { ImportRequest } from './imports';
5
6
  import type { LanguageSpec } from './language';
6
7
  /**
@@ -41,6 +42,8 @@ export interface RawField {
41
42
  * @brief One definition as found in the syntax tree, before rendering.
42
43
  *
43
44
  * @property kind - Kind of the symbol, such as `function`, `method`, `class` or `enum`.
45
+ * @property line - Line of the file where the declaration starts.
46
+ * @property endLine - Line of the file where the declaration ends.
44
47
  * @property signature - Declaration head. Empty when `inferred`.
45
48
  * @property modifiers - Keywords in front of the name, such as `export` or `static`.
46
49
  * @property comment - Cleaned doc comment text, or `null`.
@@ -54,13 +57,16 @@ export interface RawField {
54
57
  * @property returnsValue - True when a call to the symbol yields a value.
55
58
  * @property inferred - True for an owner type that is not declared in this file.
56
59
  * @property internal - True for a function only its own file can call, as the spec's `isInternal` decides.
60
+ * @property accessor - True for a getter or a setter, such as `get size()` or a Python `@property`. Reading it runs it.
57
61
  * @property calls - For a function or method: the calls in its body, each once.
62
+ * @property passes - For a function or method: the names its body passes on as values, each once.
58
63
  * @property children - Members nested under this symbol.
59
64
  */
60
- export interface RawSymbol {
65
+ export interface RawSymbol extends BodyReferences {
61
66
  kind: SymbolKind;
62
67
  readonly name: string;
63
68
  readonly line: number;
69
+ readonly endLine: number;
64
70
  readonly signature: string;
65
71
  readonly modifiers: readonly string[];
66
72
  readonly annotations: readonly string[];
@@ -76,7 +82,7 @@ export interface RawSymbol {
76
82
  returnsValue: boolean;
77
83
  readonly inferred: boolean;
78
84
  readonly internal: boolean;
79
- readonly calls: readonly RawCall[];
85
+ readonly accessor: boolean;
80
86
  readonly children: RawSymbol[];
81
87
  }
82
88
  /**
@@ -85,11 +91,13 @@ export interface RawSymbol {
85
91
  * @property symbols - Top-level symbols of the file, each with its members nested under it.
86
92
  * @property packageName - Package or namespace the file declares, or `null` when the language has none.
87
93
  * @property imports - The files the file imports, as it writes them. Empty for a language without `imports`.
94
+ * @property exports - The names the file exports. Empty for a language whose imports do not read exports.
88
95
  */
89
96
  export interface ExtractedFile {
90
97
  readonly symbols: RawSymbol[];
91
98
  readonly packageName: string | null;
92
99
  readonly imports: readonly ImportRequest[];
100
+ readonly exports: FileExports;
93
101
  }
94
102
  /**
95
103
  * @brief Turns a parsed file into a tree of {@link RawSymbol}s, driven by a {@link LanguageSpec}.
@@ -1,5 +1,6 @@
1
1
  import type { Node } from 'web-tree-sitter';
2
2
  import type { NodeRef } from '../../model';
3
+ import { type FileExports } from './exports';
3
4
  /**
4
5
  * @brief One import of a file: the paths it can stand for, most specific first. The first one that names a
5
6
  * file of the scan wins.
@@ -21,6 +22,13 @@ export interface ImportSyntax {
21
22
  * @returns One request per import, as the file writes it.
22
23
  */
23
24
  read(root: Node): ImportRequest[];
25
+ /**
26
+ * @brief Reads the names a parsed file exports, for a language whose packages export names from an entry file.
27
+ *
28
+ * @param root - Root node of the parsed file.
29
+ * @returns The names it declares and exports, and the files it re-exports from.
30
+ */
31
+ readExports?(root: Node): FileExports;
24
32
  /**
25
33
  * @brief Finds the file an import names.
26
34
  *
@@ -43,6 +51,7 @@ export interface ImportSyntax {
43
51
  * @property entries - Each file by display path.
44
52
  * @property byName - Display paths of the files with each file name.
45
53
  * @property packages - Directory of each package of the scan, by the name its manifest gives.
54
+ * @property entryPoints - The subpaths each package is imported by, by the name its manifest gives.
46
55
  * @property resolved - Display paths each file imports, resolved on first use.
47
56
  * @property seen - Display paths each file sees, computed on first use.
48
57
  */
@@ -50,6 +59,7 @@ export declare class SourceFileIndex {
50
59
  private readonly entries;
51
60
  private readonly byName;
52
61
  private packages;
62
+ private entryPoints;
53
63
  private readonly resolved;
54
64
  private readonly seen;
55
65
  /**
@@ -59,8 +69,9 @@ export declare class SourceFileIndex {
59
69
  * @param ref - Node of the file.
60
70
  * @param syntax - How its language names imports, or `null` when its imports are not read.
61
71
  * @param requests - Its imports, as the file writes them.
72
+ * @param exports - The names it exports, from `readExports` of its language.
62
73
  */
63
- add(path: string, ref: NodeRef, syntax: ImportSyntax | null, requests: readonly ImportRequest[]): void;
74
+ add(path: string, ref: NodeRef, syntax: ImportSyntax | null, requests: readonly ImportRequest[], exports: FileExports): void;
64
75
  /**
65
76
  * @brief Tells the index where each package of the scan is, so an import of a package by name finds its files.
66
77
  *
@@ -68,7 +79,15 @@ export declare class SourceFileIndex {
68
79
  */
69
80
  usePackages(packages: ReadonlyMap<string, {
70
81
  readonly packageName: string;
82
+ readonly entryPoints: readonly string[];
71
83
  }>): void;
84
+ /**
85
+ * @brief The subpaths a package is imported by.
86
+ *
87
+ * @param name - Name its manifest gives, such as `@g3nomaly/core`.
88
+ * @returns `''` for the name itself, then subpaths such as `hash`. `['']` for a package the scan does not have.
89
+ */
90
+ entryPointsOf(name: string): readonly string[];
72
91
  /**
73
92
  * @brief Directory of the package with a name.
74
93
  *
@@ -76,6 +95,28 @@ export declare class SourceFileIndex {
76
95
  * @returns Display path of its directory, `''` for the root, or `undefined` when the scan has no such package.
77
96
  */
78
97
  packageDirectory(name: string): string | undefined;
98
+ /**
99
+ * @brief Names the package a file is in: the package of the scan whose directory holds it most closely.
100
+ *
101
+ * @param path - Display path of a file.
102
+ * @returns The name its manifest gives, such as `@g3nomaly/core`, or `null` when no package holds the file.
103
+ */
104
+ packageOf(path: string): string | null;
105
+ /**
106
+ * @brief Finds the file one import of a file names, with the import syntax of that file's language.
107
+ *
108
+ * @param specifier - The import as written, such as `./hash` or `@g3nomaly/core`.
109
+ * @param from - Display path of the importing file.
110
+ * @returns Display path of the file, or `null` when the scan has none or the file's imports are not read.
111
+ */
112
+ resolveImport(specifier: string, from: string): string | null;
113
+ /**
114
+ * @brief The names a file exports.
115
+ *
116
+ * @param path - Display path of a file.
117
+ * @returns Its exports, empty for a file the scan does not have.
118
+ */
119
+ exportsOf(path: string): FileExports;
79
120
  /**
80
121
  * @brief Node of the source file at `path`.
81
122
  *
@@ -1,5 +1,6 @@
1
1
  import type { SymbolKind } from '../../model';
2
2
  import type { Node } from 'web-tree-sitter';
3
+ import type { PackageImport } from './exports';
3
4
  import type { ImportSyntax } from './imports';
4
5
  /**
5
6
  * @brief Doc comment dialect, which decides how the scanner reads doc comments.
@@ -35,6 +36,8 @@ export interface DefinitionFacts {
35
36
  * @property kind - Kind of that outermost symbol.
36
37
  * @property modifiers - Keywords in front of the name, such as `export` or `default`.
37
38
  * @property packageName - Package or namespace the file declares with a statement, e.g. `a.b` for Java's `package a.b;`, or `null`.
39
+ * @property packageImport - For a symbol the entry file of its package exports, the package name and the name it is
40
+ * exported under, as code outside the package imports it. `null` when no package of the scan exports it.
38
41
  */
39
42
  export interface ImportContext {
40
43
  readonly filePath: string;
@@ -42,6 +45,7 @@ export interface ImportContext {
42
45
  readonly kind: SymbolKind;
43
46
  readonly modifiers: readonly string[];
44
47
  readonly packageName: string | null;
48
+ readonly packageImport: PackageImport | null;
45
49
  }
46
50
  /**
47
51
  * How a language spells a call. Drives generated examples.
@@ -88,8 +88,8 @@ export declare class SymbolPlanner {
88
88
  */
89
89
  private symbolContent;
90
90
  /**
91
- * @brief Records the `calls` edges of a function, with its parameters and the fields of its type as the
92
- * variables a call can go through.
91
+ * @brief Records the `calls` and `passes` edges of a function, with its parameters and the fields of its type as
92
+ * the variables a call can go through. A parameter passed on by name is a value, never a function of the scan.
93
93
  *
94
94
  * @param symbol - The calling function.
95
95
  * @param scope - Where the function sits in the file.
@@ -58,7 +58,9 @@ export declare class RepoFileLister implements FileLister {
58
58
  */
59
59
  private isExcluded;
60
60
  /**
61
- * @brief Lists the tracked and untracked files git does not ignore.
61
+ * @brief Lists the tracked and untracked files git does not ignore, without symlinks and files whose real path
62
+ * leaves `root`. A path missing from disk stays in the list. Turns off `core.fsmonitor`, so the repository's
63
+ * config cannot make git run a command.
62
64
  *
63
65
  * @param root - Absolute directory.
64
66
  * @returns Root-relative paths, or `null` when `root` is not in a git work tree or git fails.
@@ -3,8 +3,9 @@ import type { CommunityIndex, Edge, GraphNode } from '../../model';
3
3
  * @brief Splits the nodes of a scan into communities: groups whose nodes link to each other more than to the rest.
4
4
  *
5
5
  * Every page and entry is one unit: a file, a class, a function, a term, a table. A parameter or field counts
6
- * as the entry it belongs to. A section, folder or package belongs to no community. Every edge between two
7
- * units links them, and so does each unit with the unit it is in, such as a method with its class.
6
+ * as the entry it belongs to. A section, folder or package belongs to no community, and nor does a unit that would
7
+ * be alone in one. Every edge between two units links them, and so does each unit with the unit it is in, such as a
8
+ * method with its class.
8
9
  *
9
10
  * The split maximises modularity with the Louvain method: nodes move to the community of a neighbour while
10
11
  * that raises modularity, then each community becomes one node and the next level starts. It walks the nodes
@@ -1,4 +1,4 @@
1
- export { CallLinker, type CallContext, type CallVia, type RawCall, readCalls } from './code/calls';
1
+ export { type BodyReferences, CallLinker, type CallContext, type CallVia, type RawCall, readReferences } from './code/calls';
2
2
  export { type ExtractedFile, type RawField, type RawParameter, type RawSymbol, SymbolExtractor } from './code/extract';
3
3
  export { GrammarLoader } from './code/grammar';
4
4
  export { C_INCLUDES, ECMASCRIPT_IMPORTS, type ImportRequest, type ImportSyntax, PYTHON_IMPORTS, SourceFileIndex, } from './code/imports';
@@ -8,6 +8,9 @@ import type { Source } from './files';
8
8
  * @property manifest - Display path of the manifest that marks the package, such as `packages/core/package.json`.
9
9
  * @property version - Version the manifest gives, or `null`.
10
10
  * @property description - Description the manifest gives, or `''`.
11
+ * @property entryPoints - The subpaths code outside the package imports it by, `''` for the package name itself,
12
+ * such as `['', 'hash']` for `@g3nomaly/core` and `@g3nomaly/core/hash`. The `exports` of a `package.json` lists
13
+ * them; any other manifest has `['']`.
11
14
  */
12
15
  export interface PackageInfo {
13
16
  readonly packageName: string;
@@ -15,6 +18,7 @@ export interface PackageInfo {
15
18
  readonly manifest: string;
16
19
  readonly version: string | null;
17
20
  readonly description: string;
21
+ readonly entryPoints: readonly string[];
18
22
  }
19
23
  /**
20
24
  * @brief Finds the packages of a set of sources: every directory below a root with a manifest that one of the readers understands.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g3nomaly/analyze",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Turns a repository into one offline HTML documentation site, and queries the same linked model from the terminal and from hooks.",
5
5
  "keywords": [
6
6
  "documentation",
@@ -40,7 +40,7 @@
40
40
  "docs": "bun run build && bun dist/cli.js create_docs"
41
41
  },
42
42
  "dependencies": {
43
- "@g3nomaly/core": "^0.3.5",
43
+ "@g3nomaly/core": "^0.3.7",
44
44
  "@t3-oss/env-core": "^0.13.11",
45
45
  "hast-util-to-string": "^3.0.1",
46
46
  "rehype-parse": "^9.0.1",
@@ -58,7 +58,7 @@
58
58
  "zod": "^4.6.5"
59
59
  },
60
60
  "devDependencies": {
61
- "@g3nomaly/ui": "^0.3.6",
61
+ "@g3nomaly/ui": "^0.3.8",
62
62
  "@tanstack/react-router": "^1.170.41",
63
63
  "@tanstack/react-store": "^0.11.2",
64
64
  "@tree-sitter-grammars/tree-sitter-kotlin": "^1.1.0",