@eventra_dev/eventra-cli 0.2.4 → 0.3.2

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.
Files changed (89) hide show
  1. package/README.md +143 -32
  2. package/dist/analysis/cache/evaluationCache.js +21 -0
  3. package/dist/analysis/cache/resolvedCallCache.js +21 -0
  4. package/dist/analysis/cache/resolvedExportCache.js +21 -0
  5. package/dist/analysis/cache/semanticDependencyGraph.js +25 -0
  6. package/dist/analysis/cache/symbolInvalidation.js +20 -0
  7. package/dist/analysis/extractor/extractor.js +47 -0
  8. package/dist/analysis/extractor/propagationExtractor.js +52 -0
  9. package/dist/analysis/pipeline/semanticPass.js +2 -0
  10. package/dist/analysis/resolver/callResolver.js +125 -0
  11. package/dist/analysis/resolver/exportResolver.js +75 -0
  12. package/dist/analysis/resolver/resolver.js +133 -0
  13. package/dist/analysis/scanner/analyzer/propagationAnalyzer.js +193 -0
  14. package/dist/analysis/scanner/analyzer/returnPropagationAnalyzer.js +105 -0
  15. package/dist/analysis/scanner/scanner.js +117 -0
  16. package/dist/analysis/scanner/sinkDetector.js +91 -0
  17. package/dist/analysis/shared/evaluationContext.js +9 -0
  18. package/dist/analysis/shared/propagation.js +3 -0
  19. package/dist/analysis/shared/returnPropagation.js +2 -0
  20. package/dist/analysis/shared/types.js +2 -0
  21. package/dist/analysis/shared/utils.js +62 -0
  22. package/dist/analysis/symbols/symbolUtils.js +68 -0
  23. package/dist/analysis/symbols/wrapperRegistry.js +55 -0
  24. package/dist/cli/check.js +73 -0
  25. package/dist/{commands → cli}/init.js +1 -1
  26. package/dist/{commands → cli}/send.js +1 -1
  27. package/dist/cli/sync.js +56 -0
  28. package/dist/{commands → cli}/watch.js +41 -25
  29. package/dist/compiler/compilerContext.js +204 -0
  30. package/dist/compiler/documentRegistry.js +78 -0
  31. package/dist/compiler/importGraph.js +83 -0
  32. package/dist/compiler/scheduler.js +29 -0
  33. package/dist/core/EventraEngine.js +234 -0
  34. package/dist/core/projectScanner.js +73 -0
  35. package/dist/{utils → filesystem}/getVirtualFile.js +1 -3
  36. package/dist/filesystem/processFile.js +38 -0
  37. package/dist/index.js +5 -5
  38. package/dist/shared/buildSyntheticTsx.js +20 -0
  39. package/dist/shared/templateExpressionExtractor.js +22 -0
  40. package/package.json +32 -9
  41. package/.github/workflows/release.yml +0 -43
  42. package/ARCHITECTURE.md +0 -88
  43. package/assets/eventra-icon-animated.svg +0 -19
  44. package/dist/commands/check.js +0 -78
  45. package/dist/commands/sync.js +0 -79
  46. package/dist/engine/boundary.js +0 -14
  47. package/dist/engine/callResolver.js +0 -58
  48. package/dist/engine/engine.js +0 -154
  49. package/dist/engine/exportResolver.js +0 -46
  50. package/dist/engine/functionAnalyzer.js +0 -71
  51. package/dist/engine/graph.js +0 -168
  52. package/dist/engine/languageService.js +0 -152
  53. package/dist/engine/resolver.js +0 -149
  54. package/dist/engine/scanner.js +0 -230
  55. package/dist/utils/processFile.js +0 -28
  56. package/dist/utils/universal.js +0 -190
  57. package/src/commands/check.ts +0 -91
  58. package/src/commands/init.ts +0 -174
  59. package/src/commands/send.ts +0 -213
  60. package/src/commands/sync.ts +0 -106
  61. package/src/commands/watch.ts +0 -144
  62. package/src/engine/boundary.ts +0 -12
  63. package/src/engine/callResolver.ts +0 -65
  64. package/src/engine/engine.ts +0 -227
  65. package/src/engine/exportResolver.ts +0 -56
  66. package/src/engine/functionAnalyzer.ts +0 -81
  67. package/src/engine/graph.ts +0 -193
  68. package/src/engine/hash.ts +0 -5
  69. package/src/engine/languageService.ts +0 -197
  70. package/src/engine/resolver.ts +0 -177
  71. package/src/engine/scanner.ts +0 -298
  72. package/src/index.ts +0 -49
  73. package/src/types.ts +0 -35
  74. package/src/utils/config.ts +0 -53
  75. package/src/utils/getVirtualFile.ts +0 -5
  76. package/src/utils/processFile.ts +0 -29
  77. package/src/utils/universal.ts +0 -249
  78. package/tests/fixtures/backend/express/app.ts +0 -233
  79. package/tests/fixtures/backend/nest/service.ts +0 -70
  80. package/tests/fixtures/backend/node/index.ts +0 -63
  81. package/tests/fixtures/frontend/next/page.tsx +0 -101
  82. package/tests/fixtures/frontend/react/App.tsx +0 -104
  83. package/tests/fixtures/frontend/vue/App.vue +0 -83
  84. package/tests/fixtures/wrappers/component/test.tsx +0 -62
  85. package/tests/fixtures/wrappers/function/test.ts +0 -60
  86. package/tests/run.ts +0 -106
  87. package/tsconfig.json +0 -14
  88. /package/dist/{utils → config}/config.js +0 -0
  89. /package/dist/{engine → shared}/hash.js +0 -0
@@ -2,7 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getVirtualFile = getVirtualFile;
4
4
  function getVirtualFile(file) {
5
- return /\.(vue|svelte|astro|html)$/i.test(file)
6
- ? file + ".tsx"
7
- : file;
5
+ return file;
8
6
  }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.processFile = processFile;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ function getScriptKind(fileName) {
9
+ if (fileName.endsWith(".tsx")) {
10
+ return typescript_1.default.ScriptKind.TSX;
11
+ }
12
+ if (fileName.endsWith(".ts")) {
13
+ return typescript_1.default.ScriptKind.TS;
14
+ }
15
+ if (fileName.endsWith(".jsx")) {
16
+ return typescript_1.default.ScriptKind.JSX;
17
+ }
18
+ return typescript_1.default.ScriptKind.JS;
19
+ }
20
+ async function processFile(fileName, content) {
21
+ const scriptKind = getScriptKind(fileName);
22
+ const source = typescript_1.default.createSourceFile(fileName, content, typescript_1.default.ScriptTarget.Latest, true, scriptKind);
23
+ const dependencies = [];
24
+ for (const statement of source.statements) {
25
+ if ((typescript_1.default.isImportDeclaration(statement)
26
+ || typescript_1.default.isExportDeclaration(statement))
27
+ && statement.moduleSpecifier
28
+ && typescript_1.default.isStringLiteral(statement.moduleSpecifier)) {
29
+ dependencies.push(statement.moduleSpecifier.text);
30
+ }
31
+ }
32
+ return {
33
+ fileName,
34
+ scriptKind,
35
+ content,
36
+ dependencies,
37
+ };
38
+ }
package/dist/index.js CHANGED
@@ -43,33 +43,33 @@ program
43
43
  program
44
44
  .command("init")
45
45
  .action(async () => {
46
- const { init } = await Promise.resolve().then(() => __importStar(require("./commands/init")));
46
+ const { init } = await Promise.resolve().then(() => __importStar(require("./cli/init")));
47
47
  await init();
48
48
  });
49
49
  program
50
50
  .command("sync")
51
51
  .action(async () => {
52
- const { sync } = await Promise.resolve().then(() => __importStar(require("./commands/sync")));
52
+ const { sync } = await Promise.resolve().then(() => __importStar(require("./cli/sync")));
53
53
  await sync();
54
54
  });
55
55
  program
56
56
  .command("check")
57
57
  .option("--fix", "auto fix issues")
58
58
  .action(async (opts) => {
59
- const { check } = await Promise.resolve().then(() => __importStar(require("./commands/check")));
59
+ const { check } = await Promise.resolve().then(() => __importStar(require("./cli/check")));
60
60
  await check({ fix: opts.fix });
61
61
  });
62
62
  program
63
63
  .command("watch")
64
64
  .description("Watch files and detect events in real-time")
65
65
  .action(async () => {
66
- const { watch } = await Promise.resolve().then(() => __importStar(require("./commands/watch")));
66
+ const { watch } = await Promise.resolve().then(() => __importStar(require("./cli/watch")));
67
67
  await watch();
68
68
  });
69
69
  program
70
70
  .command("send")
71
71
  .action(async () => {
72
- const { send } = await Promise.resolve().then(() => __importStar(require("./commands/send")));
72
+ const { send } = await Promise.resolve().then(() => __importStar(require("./cli/send")));
73
73
  await send();
74
74
  });
75
75
  program.parse();
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildSyntheticTsx = buildSyntheticTsx;
4
+ const templateExpressionExtractor_1 = require("./templateExpressionExtractor");
5
+ function buildSyntheticTsx(template) {
6
+ const expressions = (0, templateExpressionExtractor_1.extractTemplateExpressions)(template);
7
+ const body = expressions
8
+ .map((expression, index) => {
9
+ return `
10
+ const __eventra_expr_${index} =
11
+ (() => (${expression}))();
12
+ `;
13
+ })
14
+ .join("\n");
15
+ return `
16
+ export function __EVENTRA_TEMPLATE__() {
17
+ ${body}
18
+ }
19
+ `;
20
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractTemplateExpressions = extractTemplateExpressions;
4
+ function extractTemplateExpressions(template) {
5
+ const expressions = [];
6
+ // Vue
7
+ const vue = /[:@]?[a-zA-Z0-9_-]+\s*=\s*"([^"]+)"/g;
8
+ for (const match of template.matchAll(vue)) {
9
+ expressions.push(match[1]);
10
+ }
11
+ // Svelte
12
+ const svelte = /\{([^}]+)\}/g;
13
+ for (const match of template.matchAll(svelte)) {
14
+ expressions.push(match[1]);
15
+ }
16
+ // Astro
17
+ const astro = /\{([^}]+)\}/g;
18
+ for (const match of template.matchAll(astro)) {
19
+ expressions.push(match[1]);
20
+ }
21
+ return expressions;
22
+ }
package/package.json CHANGED
@@ -1,22 +1,32 @@
1
1
  {
2
2
  "name": "@eventra_dev/eventra-cli",
3
- "version": "0.2.4",
4
- "description": "Eventra CLI",
3
+ "version": "0.3.2",
4
+ "description": "Static analytics event extraction CLI powered by the TypeScript compiler API",
5
+ "license": "MIT",
5
6
  "type": "commonjs",
6
7
  "bin": {
7
8
  "eventra": "./dist/index.js"
8
9
  },
9
- "access": "public",
10
+ "main": "./dist/index.js",
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
10
16
  "repository": {
11
17
  "type": "git",
12
18
  "url": "https://github.com/and-1991/eventra-cli"
13
19
  },
20
+
14
21
  "homepage": "https://eventra.dev",
15
- "license": "MIT",
22
+ "engines": {
23
+ "node": ">=18"
24
+ },
16
25
  "scripts": {
17
- "build": "tsc",
26
+ "build": "tsc -p tsconfig.json",
18
27
  "dev": "tsx src/index.ts",
19
- "test": "tsx tests/run.ts"
28
+ "test": "tsx tests/run.ts",
29
+ "clean": "rm -rf dist"
20
30
  },
21
31
  "dependencies": {
22
32
  "chalk": "^4.1.2",
@@ -25,14 +35,27 @@
25
35
  "fast-glob": "^3.3.3",
26
36
  "fs-extra": "^11.2.0",
27
37
  "inquirer": "^8.2.7",
28
- "ts-morph": "^27.0.2"
38
+ "typescript": "^5.3.0"
29
39
  },
30
40
  "devDependencies": {
31
41
  "@types/fs-extra": "^11.0.4",
32
42
  "@types/inquirer": "^9.0.9",
33
43
  "@types/node": "^20.0.0",
34
44
  "cross-spawn": "^7.0.6",
35
- "tsx": "^4.7.0",
36
- "typescript": "^5.3.0"
45
+ "tsx": "^4.7.0"
46
+ },
47
+ "keywords": [
48
+ "analytics",
49
+ "event-tracking",
50
+ "static-analysis",
51
+ "typescript",
52
+ "compiler-api",
53
+ "ast",
54
+ "cli",
55
+ "telemetry",
56
+ "eventra"
57
+ ],
58
+ "publishConfig": {
59
+ "access": "public"
37
60
  }
38
61
  }
@@ -1,43 +0,0 @@
1
- name: Release CLI
2
-
3
- on:
4
- push:
5
- branches: [main]
6
-
7
- concurrency:
8
- group: npm-publish
9
- cancel-in-progress: true
10
-
11
- jobs:
12
- publish:
13
- runs-on: ubuntu-latest
14
-
15
- permissions:
16
- contents: read
17
- id-token: write
18
-
19
- steps:
20
- - uses: actions/checkout@v4
21
-
22
- - uses: pnpm/action-setup@v4
23
- with:
24
- version: 10
25
-
26
- - uses: actions/setup-node@v4
27
- with:
28
- node-version: 20
29
- registry-url: https://registry.npmjs.org/
30
-
31
- - run: pnpm install --no-frozen-lockfile
32
-
33
- - name: Build CLI
34
- run: pnpm build
35
-
36
- - name: Run tests
37
- run: pnpm test
38
-
39
- - name: Publish to npm
40
- run: npm publish --access public
41
- env:
42
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
43
- EVENTRA_ENDPOINT: ${{ secrets.EVENTRA_ENDPOINT }}
package/ARCHITECTURE.md DELETED
@@ -1,88 +0,0 @@
1
- # Eventra CLI Architecture
2
-
3
- ## High-Level Flow
4
-
5
- FILES → parseUniversal → TSService → scanSource → Engine → CLI
6
-
7
- ---
8
-
9
- ## Diagram
10
-
11
- ```
12
- +-------------------+
13
- | Source Files |
14
- +---------+---------+
15
- |
16
- v
17
- +-------------------+
18
- | parseUniversal |
19
- | (normalize input) |
20
- +---------+---------+
21
- |
22
- v
23
- +-------------------+
24
- | TSService |
25
- | (AST + Types) |
26
- +---------+---------+
27
- |
28
- v
29
- +-------------------+
30
- | scanSource |
31
- | (core analyzer) |
32
- +----+------+-------+
33
- | |
34
- | |
35
- v v
36
- +----------------+----------------+
37
- | |
38
- +-------------------+ +-----------------------+
39
- | Function Wrappers | | Component Wrappers |
40
- +-------------------+ +-----------------------+
41
- | |
42
- +---------------+-----------------+
43
- |
44
- v
45
- +-------------------+
46
- | resolveNodeValue |
47
- | (extract values) |
48
- +---------+---------+
49
- |
50
- v
51
- +-------------------+
52
- | EventraEngine |
53
- | (orchestration) |
54
- +---------+---------+
55
- |
56
- v
57
- +-------------------+
58
- | CLI (sync/check) |
59
- +-------------------+
60
- ```
61
-
62
- ---
63
-
64
- ## Modules
65
-
66
- ### Parser
67
- Extracts JS from any framework (Vue, Svelte, Astro, HTML).
68
-
69
- ### TSService
70
- Provides TypeScript AST and type resolution.
71
-
72
- ### Scanner
73
- Finds:
74
- - track() calls
75
- - wrappers
76
- - values
77
-
78
- ### Engine
79
- Handles:
80
- - caching
81
- - dependency graph
82
- - incremental updates
83
-
84
- ---
85
-
86
- ## Goal
87
-
88
- Static analytics extraction without runtime.
@@ -1,19 +0,0 @@
1
- <svg width="512" height="512" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
2
- <defs>
3
- <linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
4
- <stop offset="0%" stop-color="#4F7CFF"/>
5
- <stop offset="100%" stop-color="#6366F1"/>
6
- </linearGradient>
7
- </defs>
8
- <rect width="512" height="512" rx="120" fill="url(#g)"/>
9
- <polyline points="140,310 230,220 280,260 380,140"
10
- fill="none"
11
- stroke="white"
12
- stroke-width="32"
13
- stroke-linecap="round"
14
- stroke-linejoin="round"
15
- stroke-dasharray="600"
16
- stroke-dashoffset="600">
17
- <animate attributeName="stroke-dashoffset" from="600" to="0" dur="1.2s" fill="freeze"/>
18
- </polyline>
19
- </svg>
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.check = check;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const fast_glob_1 = __importDefault(require("fast-glob"));
9
- const promises_1 = __importDefault(require("fs/promises"));
10
- const path_1 = __importDefault(require("path"));
11
- const config_1 = require("../utils/config");
12
- const engine_1 = require("../engine/engine");
13
- const processFile_1 = require("../utils/processFile");
14
- const getVirtualFile_1 = require("../utils/getVirtualFile");
15
- async function check({ fix = false }) {
16
- const config = await (0, config_1.loadConfig)();
17
- if (!config) {
18
- console.log(chalk_1.default.red("eventra.json not found"));
19
- process.exit(1);
20
- }
21
- console.log(chalk_1.default.blue("Checking events..."));
22
- const files = await (0, fast_glob_1.default)(config.sync.include, {
23
- ignore: config.sync.exclude,
24
- absolute: true,
25
- });
26
- const engine = new engine_1.EventraEngine(process.cwd());
27
- const cache = new Map();
28
- const toScan = new Set();
29
- // COLLECT
30
- for (const file of files) {
31
- try {
32
- const raw = await promises_1.default.readFile(file, "utf-8");
33
- if (raw.length > 2_000_000)
34
- continue;
35
- const parsed = (0, processFile_1.processFile)(file, raw);
36
- cache.set(file, parsed);
37
- toScan.add(file);
38
- parsed.deps.forEach(dep => toScan.add(path_1.default.resolve(dep)));
39
- }
40
- catch { }
41
- }
42
- // PRELOAD
43
- for (const file of toScan) {
44
- try {
45
- const parsed = cache.get(file);
46
- if (!parsed)
47
- continue;
48
- engine.preloadFile((0, getVirtualFile_1.getVirtualFile)(file), parsed.content);
49
- }
50
- catch { }
51
- }
52
- // SCAN
53
- for (const file of toScan) {
54
- try {
55
- const parsed = cache.get(file);
56
- if (!parsed)
57
- continue;
58
- engine.scanFile((0, getVirtualFile_1.getVirtualFile)(file), parsed.content, config);
59
- }
60
- catch { }
61
- }
62
- const found = new Set(engine.getAllEvents());
63
- const known = new Set(config.events ?? []);
64
- const added = [...found].filter(e => !known.has(e));
65
- const removed = [...known].filter(e => !found.has(e));
66
- if (fix) {
67
- config.events = [...found].sort();
68
- await (0, config_1.saveConfig)(config);
69
- console.log(chalk_1.default.green("Synced"));
70
- return;
71
- }
72
- if (added.length || removed.length) {
73
- added.forEach(e => console.log(chalk_1.default.red(`+ ${e}`)));
74
- removed.forEach(e => console.log(chalk_1.default.yellow(`- ${e}`)));
75
- process.exit(1);
76
- }
77
- console.log(chalk_1.default.green("All good"));
78
- }
@@ -1,79 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sync = sync;
7
- const fast_glob_1 = __importDefault(require("fast-glob"));
8
- const promises_1 = __importDefault(require("fs/promises"));
9
- const chalk_1 = __importDefault(require("chalk"));
10
- const path_1 = __importDefault(require("path"));
11
- const config_1 = require("../utils/config");
12
- const engine_1 = require("../engine/engine");
13
- const processFile_1 = require("../utils/processFile");
14
- const getVirtualFile_1 = require("../utils/getVirtualFile");
15
- async function sync() {
16
- const config = await (0, config_1.loadConfig)();
17
- if (!config)
18
- return;
19
- console.log(chalk_1.default.blue("Scanning..."));
20
- const files = await (0, fast_glob_1.default)(config.sync.include, {
21
- ignore: config.sync.exclude,
22
- absolute: true,
23
- });
24
- const engine = new engine_1.EventraEngine(process.cwd());
25
- const cache = new Map();
26
- const toScan = new Set();
27
- // COLLECT
28
- for (const file of files) {
29
- try {
30
- const raw = await promises_1.default.readFile(file, "utf-8");
31
- if (raw.length > 2_000_000)
32
- continue;
33
- const parsed = (0, processFile_1.processFile)(file, raw);
34
- cache.set(file, parsed);
35
- toScan.add(file);
36
- parsed.deps.forEach(dep => toScan.add(path_1.default.resolve(dep)));
37
- }
38
- catch { }
39
- }
40
- // PRELOAD
41
- for (const file of toScan) {
42
- try {
43
- let parsed = cache.get(file);
44
- if (!parsed) {
45
- const raw = await promises_1.default.readFile(file, "utf-8");
46
- parsed = (0, processFile_1.processFile)(file, raw);
47
- cache.set(file, parsed);
48
- }
49
- engine.preloadFile((0, getVirtualFile_1.getVirtualFile)(file), parsed.content);
50
- }
51
- catch { }
52
- }
53
- // SCAN
54
- const detectedFn = new Set();
55
- const detectedCmp = new Map();
56
- for (const file of toScan) {
57
- try {
58
- const parsed = cache.get(file);
59
- if (!parsed)
60
- continue;
61
- const res = engine.scanFile((0, getVirtualFile_1.getVirtualFile)(file), parsed.content, config);
62
- res.detectedFunctionWrappers.forEach(w => detectedFn.add(w));
63
- res.detectedComponentWrappers.forEach((v, k) => detectedCmp.set(k, v));
64
- }
65
- catch { }
66
- }
67
- // RESULT
68
- const events = engine.getAllEvents().sort();
69
- config.events = events;
70
- config.functionWrappers = mergeUnique(config.functionWrappers ?? [], [...detectedFn].map(name => ({ name })), w => w.name);
71
- config.wrappers = mergeUnique(config.wrappers ?? [], [...detectedCmp.entries()].map(([name, prop]) => ({ name, prop })), w => `${w.name}:${w.prop}`);
72
- await (0, config_1.saveConfig)(config);
73
- console.log(chalk_1.default.green(`Found ${events.length} events`));
74
- }
75
- function mergeUnique(a, b, key) {
76
- const map = new Map();
77
- [...b, ...a].forEach(item => map.set(key(item), item));
78
- return [...map.values()];
79
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isExternalFile = isExternalFile;
7
- const path_1 = __importDefault(require("path"));
8
- function isExternalFile(file) {
9
- const normalized = path_1.default.resolve(file);
10
- return (normalized.includes(`${path_1.default.sep}node_modules${path_1.default.sep}`) ||
11
- normalized.includes(`${path_1.default.sep}dist${path_1.default.sep}`) ||
12
- normalized.includes(`${path_1.default.sep}build${path_1.default.sep}`) ||
13
- normalized.endsWith(".d.ts"));
14
- }
@@ -1,58 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveFunctionFromCall = resolveFunctionFromCall;
7
- const typescript_1 = __importDefault(require("typescript"));
8
- function isFn(node) {
9
- return (typescript_1.default.isFunctionDeclaration(node) ||
10
- typescript_1.default.isMethodDeclaration(node) ||
11
- typescript_1.default.isFunctionExpression(node) ||
12
- typescript_1.default.isArrowFunction(node));
13
- }
14
- function resolveFromSymbol(symbol, checker, seen = new Set()) {
15
- if (seen.has(symbol))
16
- return null;
17
- seen.add(symbol);
18
- if (symbol.flags & typescript_1.default.SymbolFlags.Alias) {
19
- return resolveFromSymbol(checker.getAliasedSymbol(symbol), checker, seen);
20
- }
21
- for (const d of symbol.getDeclarations() ?? []) {
22
- if (isFn(d))
23
- return d;
24
- if (typescript_1.default.isVariableDeclaration(d) && d.initializer) {
25
- if (isFn(d.initializer))
26
- return d.initializer;
27
- const s = checker.getSymbolAtLocation(d.initializer);
28
- if (s) {
29
- const r = resolveFromSymbol(s, checker, seen);
30
- if (r)
31
- return r;
32
- }
33
- }
34
- }
35
- return null;
36
- }
37
- function resolveFunctionFromCall(expr, checker) {
38
- // foo.bar()
39
- if (typescript_1.default.isPropertyAccessExpression(expr)) {
40
- const s = checker.getSymbolAtLocation(expr.name);
41
- if (s) {
42
- const r = resolveFromSymbol(s, checker);
43
- if (r)
44
- return r;
45
- }
46
- }
47
- // direct call
48
- const type = checker.getTypeAtLocation(expr);
49
- for (const sig of type.getCallSignatures()) {
50
- const d = sig.getDeclaration();
51
- if (d && isFn(d))
52
- return d;
53
- }
54
- const s = checker.getSymbolAtLocation(expr);
55
- if (s)
56
- return resolveFromSymbol(s, checker);
57
- return null;
58
- }