@mnemonica/tactica 0.1.15 → 0.3.0
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 +165 -5
- package/lib/analyzer.d.ts +59 -2
- package/lib/analyzer.js +346 -21
- package/lib/cli.d.ts +4 -1
- package/lib/cli.js +222 -7
- package/lib/creation-graph.d.ts +131 -0
- package/lib/creation-graph.js +568 -0
- package/lib/index.d.ts +8 -2
- package/lib/index.js +11 -3
- package/lib/module-graph.d.ts +109 -0
- package/lib/module-graph.js +690 -0
- package/lib/plugins.d.ts +44 -0
- package/lib/plugins.js +27 -0
- package/lib/scopes.d.ts +113 -0
- package/lib/scopes.js +582 -0
- package/lib/topologica-analyzer.js +13 -10
- package/lib/types.d.ts +320 -0
- package/lib/types.js +1 -1
- package/lib/writer.d.ts +14 -1
- package/lib/writer.js +61 -1
- package/package.json +7 -5
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tactica -
|
|
2
|
+
* Tactica - Type definition generator for Mnemonica
|
|
3
3
|
*
|
|
4
4
|
* Generates type definitions for Mnemonica's dynamic nested constructors,
|
|
5
5
|
* enabling TypeScript to understand runtime type hierarchies created through
|
|
@@ -10,6 +10,12 @@ export { TopologicaAnalyzer } from './topologica-analyzer';
|
|
|
10
10
|
export { TypeGraphImpl } from './graph';
|
|
11
11
|
export { TypesGenerator } from './generator';
|
|
12
12
|
export { TypesWriter } from './writer';
|
|
13
|
-
export
|
|
13
|
+
export { ModuleGraphBuilder } from './module-graph';
|
|
14
|
+
export { LocalScopeWalker } from './scopes';
|
|
15
|
+
export type { ScopeTypeResolver } from './scopes';
|
|
16
|
+
export { CreationGraphBuilder } from './creation-graph';
|
|
17
|
+
export { mergeTacticaPlugins } from './plugins';
|
|
18
|
+
export type { TacticaPlugin, InstrumentationVocabulary } from './plugins';
|
|
19
|
+
export type { TacticaConfig, TypeNode, TypeGraph, PropertyInfo, AnalyzeResult, AnalyzeError, GeneratedTypes, DefinitionInfo, UsageInfo, DefinitionsJson, UsagesJson, InstrumentationKind, InstrumentationScope, InstrumentationPoint, InstrumentationJson, ModuleBindingKind, ModuleImportKind, ModuleBinding, ModuleInfo, CrossModuleUsage, ModuleGraph, ModulesJson, ScopeKind, ScopeInfo, ScopeVariable, ScopeAnalysis, ScopesJson, CreationGraphNode, CreationGraphEdge, CreationAnchor, CreationGraph, } from './types';
|
|
14
20
|
export { main, run, watch, parseArgs } from './cli';
|
|
15
21
|
export declare const VERSION: string;
|
package/lib/index.js
CHANGED
|
@@ -33,10 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.VERSION = exports.parseArgs = exports.watch = exports.run = exports.main = exports.TypesWriter = exports.TypesGenerator = exports.TypeGraphImpl = exports.TopologicaAnalyzer = exports.MnemonicaAnalyzer = void 0;
|
|
36
|
+
exports.VERSION = exports.parseArgs = exports.watch = exports.run = exports.main = exports.mergeTacticaPlugins = exports.CreationGraphBuilder = exports.LocalScopeWalker = exports.ModuleGraphBuilder = exports.TypesWriter = exports.TypesGenerator = exports.TypeGraphImpl = exports.TopologicaAnalyzer = exports.MnemonicaAnalyzer = void 0;
|
|
37
37
|
const pkg = __importStar(require("../package.json"));
|
|
38
38
|
/**
|
|
39
|
-
* Tactica -
|
|
39
|
+
* Tactica - Type definition generator for Mnemonica
|
|
40
40
|
*
|
|
41
41
|
* Generates type definitions for Mnemonica's dynamic nested constructors,
|
|
42
42
|
* enabling TypeScript to understand runtime type hierarchies created through
|
|
@@ -52,6 +52,14 @@ var generator_1 = require("./generator");
|
|
|
52
52
|
Object.defineProperty(exports, "TypesGenerator", { enumerable: true, get: function () { return generator_1.TypesGenerator; } });
|
|
53
53
|
var writer_1 = require("./writer");
|
|
54
54
|
Object.defineProperty(exports, "TypesWriter", { enumerable: true, get: function () { return writer_1.TypesWriter; } });
|
|
55
|
+
var module_graph_1 = require("./module-graph");
|
|
56
|
+
Object.defineProperty(exports, "ModuleGraphBuilder", { enumerable: true, get: function () { return module_graph_1.ModuleGraphBuilder; } });
|
|
57
|
+
var scopes_1 = require("./scopes");
|
|
58
|
+
Object.defineProperty(exports, "LocalScopeWalker", { enumerable: true, get: function () { return scopes_1.LocalScopeWalker; } });
|
|
59
|
+
var creation_graph_1 = require("./creation-graph");
|
|
60
|
+
Object.defineProperty(exports, "CreationGraphBuilder", { enumerable: true, get: function () { return creation_graph_1.CreationGraphBuilder; } });
|
|
61
|
+
var plugins_1 = require("./plugins");
|
|
62
|
+
Object.defineProperty(exports, "mergeTacticaPlugins", { enumerable: true, get: function () { return plugins_1.mergeTacticaPlugins; } });
|
|
55
63
|
// CLI entry point
|
|
56
64
|
var cli_1 = require("./cli");
|
|
57
65
|
Object.defineProperty(exports, "main", { enumerable: true, get: function () { return cli_1.main; } });
|
|
@@ -60,4 +68,4 @@ Object.defineProperty(exports, "watch", { enumerable: true, get: function () { r
|
|
|
60
68
|
Object.defineProperty(exports, "parseArgs", { enumerable: true, get: function () { return cli_1.parseArgs; } });
|
|
61
69
|
// Version from package.json
|
|
62
70
|
exports.VERSION = pkg.version;
|
|
63
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
71
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsWUFBWSxDQUFDOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFFYixxREFBdUM7QUFFdkM7Ozs7OztHQU1HO0FBRUgsdUNBQStDO0FBQXRDLDZHQUFBLGlCQUFpQixPQUFBO0FBQzFCLDZEQUEyRDtBQUFsRCx5SE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W1lbnRhdGlvblNjb3BlLFxuXHRJbnN0cnVtZW50YXRpb25Qb2ludCxcblx0SW5zdHJ1bWVudGF0aW9uSnNvbixcblx0TW9kdWxlQmluZGluZ0tpbmQsXG5cdE1vZHVsZUltcG9ydEtpbmQsXG5cdE1vZHVsZUJpbmRpbmcsXG5cdE1vZHVsZUluZm8sXG5cdENyb3NzTW9kdWxlVXNhZ2UsXG5cdE1vZHVsZUdyYXBoLFxuXHRNb2R1bGVzSnNvbixcblx0U2NvcGVLaW5kLFxuXHRTY29wZUluZm8sXG5cdFNjb3BlVmFyaWFibGUsXG5cdFNjb3BlQW5hbHlzaXMsXG5cdFNjb3Blc0pzb24sXG5cdENyZWF0aW9uR3JhcGhOb2RlLFxuXHRDcmVhdGlvbkdyYXBoRWRnZSxcblx0Q3JlYXRpb25BbmNob3IsXG5cdENyZWF0aW9uR3JhcGgsXG59IGZyb20gJy4vdHlwZXMnO1xuXG4vLyBDTEkgZW50cnkgcG9pbnRcbmV4cG9ydCB7XG5cdG1haW4sIHJ1biwgd2F0Y2gsIHBhcnNlQXJncyBcbn0gZnJvbSAnLi9jbGknO1xuXG4vLyBWZXJzaW9uIGZyb20gcGFja2FnZS5qc29uXG5leHBvcnQgY29uc3QgVkVSU0lPTiA9IHBrZy52ZXJzaW9uO1xuIl19
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { ModuleGraph, ModuleInfo } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Module-scope walker (instrumentation walker plan, Phase 1).
|
|
5
|
+
*
|
|
6
|
+
* Builds the cross-file module graph: every export/import binding (functions,
|
|
7
|
+
* classes, consts, types — not only mnemonica types), resolved with
|
|
8
|
+
* `ts.resolveModuleName` driven by the program's compilerOptions (tsconfig
|
|
9
|
+
* `paths`, extensionless imports, index files). This is module resolution,
|
|
10
|
+
* NOT the type checker — the no-`getTypeChecker()` precedent stays intact.
|
|
11
|
+
*
|
|
12
|
+
* Usage: addFile() per source file during the definitions pass, then
|
|
13
|
+
* build(definedTypesByFile) once definitions are known.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ModuleGraphBuilder {
|
|
16
|
+
private compilerOptions;
|
|
17
|
+
private modules;
|
|
18
|
+
private localDecls;
|
|
19
|
+
private importSites;
|
|
20
|
+
private resolutionCache;
|
|
21
|
+
constructor(program?: ts.Program, compilerOptions?: ts.CompilerOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Track one source file. Re-adding the same file replaces its record,
|
|
24
|
+
* so a builder may safely be reused across passes.
|
|
25
|
+
*/
|
|
26
|
+
addFile(sourceFile: ts.SourceFile): ModuleInfo;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve all specifiers, backfill binding kinds from origin modules,
|
|
29
|
+
* derive dependencies, cross-module mnemonica-type edges, and cycles.
|
|
30
|
+
* `definedTypesByFile` maps absolute file path -> mnemonica type fullPaths
|
|
31
|
+
* defined there (from the analyzer's definitions).
|
|
32
|
+
*/
|
|
33
|
+
build(definedTypesByFile?: Map<string, string[]>): ModuleGraph;
|
|
34
|
+
/**
|
|
35
|
+
* Resolve a specifier to an absolute file path via ts.resolveModuleName
|
|
36
|
+
* with the program's compilerOptions. Returns undefined on failure.
|
|
37
|
+
*/
|
|
38
|
+
private resolveModule;
|
|
39
|
+
/**
|
|
40
|
+
* True for Node.js builtins in both bare and `node:`-prefixed forms
|
|
41
|
+
* ('path', 'node:path', 'fs/promises', 'node:fs/promises', …).
|
|
42
|
+
*/
|
|
43
|
+
private static isBuiltinSpecifier;
|
|
44
|
+
/**
|
|
45
|
+
* Record a builtin import on the module (honesty marker) and skip it
|
|
46
|
+
* entirely: no bindings, no site, no dependency, no edge.
|
|
47
|
+
* Returns true when the specifier was a builtin (caller must return early).
|
|
48
|
+
*/
|
|
49
|
+
private static skipBuiltin;
|
|
50
|
+
/**
|
|
51
|
+
* Chase a binding to the module that actually declares it, following
|
|
52
|
+
* re-export chains (barrels). Cycle-guarded. Returns undefined when the
|
|
53
|
+
* origin is external or the chain loops.
|
|
54
|
+
*/
|
|
55
|
+
private resolveOrigin;
|
|
56
|
+
/**
|
|
57
|
+
* Match a binding against a module's defined mnemonica types.
|
|
58
|
+
* Returns the matched fullPath, or undefined when the binding is not a
|
|
59
|
+
* mnemonica type of that module.
|
|
60
|
+
*/
|
|
61
|
+
private matchDefinedType;
|
|
62
|
+
/**
|
|
63
|
+
* Three-color DFS over project-internal dependencies. Cycles are recorded
|
|
64
|
+
* (mnemonica strictChain:false permits non-linear construction), never
|
|
65
|
+
* treated as errors.
|
|
66
|
+
*/
|
|
67
|
+
private detectCycles;
|
|
68
|
+
/**
|
|
69
|
+
* Rotation-independent cycle key: smallest path first.
|
|
70
|
+
*/
|
|
71
|
+
private static cycleKey;
|
|
72
|
+
/**
|
|
73
|
+
* Pass 1: record every named top-level declaration's kind.
|
|
74
|
+
*/
|
|
75
|
+
private collectLocalDecl;
|
|
76
|
+
/**
|
|
77
|
+
* Classify a variable declaration: arrow/function initializers are
|
|
78
|
+
* 'function' (holder functions the walker follows), class expressions
|
|
79
|
+
* are 'class', everything else is 'const'.
|
|
80
|
+
*/
|
|
81
|
+
private static variableKind;
|
|
82
|
+
/**
|
|
83
|
+
* Pass 2: imports, exports, requires, exported declarations.
|
|
84
|
+
*/
|
|
85
|
+
private processStatement;
|
|
86
|
+
private processImport;
|
|
87
|
+
private processExportDeclaration;
|
|
88
|
+
/**
|
|
89
|
+
* `import foo = require('./y')`
|
|
90
|
+
*/
|
|
91
|
+
private processImportEquals;
|
|
92
|
+
/**
|
|
93
|
+
* `export default <expression>`
|
|
94
|
+
*/
|
|
95
|
+
private processExportAssignment;
|
|
96
|
+
/**
|
|
97
|
+
* `export function/class/const/interface/type …` declarations.
|
|
98
|
+
*/
|
|
99
|
+
private processMaybeExportedDecl;
|
|
100
|
+
/**
|
|
101
|
+
* CommonJS `const x = require('./y')` (JS sources with allowJs).
|
|
102
|
+
*/
|
|
103
|
+
private processRequireCall;
|
|
104
|
+
/**
|
|
105
|
+
* Format a node's position as file.ts:Line:Col (1-based), matching the
|
|
106
|
+
* location format of the other .tactica outputs.
|
|
107
|
+
*/
|
|
108
|
+
private locationOf;
|
|
109
|
+
}
|