@basemachina/bm-action-dep-parser 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, BaseMachina
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # bm-action-dep-parser
2
+
3
+ BaseMachina アクション依存関係解析ツール
4
+
5
+ ## 概要
6
+
7
+ このツールは、BaseMachinaのJavaScriptアクションとビューのコードを静的解析して、各ファイルがどのアクションに依存しているかを特定します。
8
+
9
+ > **注意**: このプロジェクトは、ビューやJavaScriptアクションが構造化されたディレクトリに配置されていることを想定しています。例えば以下のようなディレクトリ構造を前提としています。
10
+ > 必ずしもこちらと同じにする必要はありませんが、ビューやJavaScriptアクションのエントリーポイントが明確になるようにしてください。
11
+ >
12
+ > ```
13
+ > project/
14
+ > ├── actions/
15
+ > │ └── js/
16
+ > | └── sampleAction.js
17
+ > └── views/
18
+ > ├── components/
19
+ > │ └── SortableForm.tsx
20
+ > └── pages/
21
+ > ├── SortableFormPage.tsx
22
+ > └── paginatedTable/
23
+ > └── index.tsx
24
+ > ```
25
+
26
+ ## 機能
27
+
28
+ - 解析対象(JSアクションかビューか)と対象ディレクトリを指定可能
29
+ - 各ファイルごとに依存しているアクションの識別子をリストアップ
30
+ - アクション呼び出し関数(`executeAction`, `useExecuteAction`, `useExecuteActionLazy`)を検出
31
+ - 変数に格納されたアクション識別子も検出
32
+ - JSON形式で結果を出力
33
+ - **ビューのエントリーポイント分析**: ビューのエントリーポイントから直接・間接的に依存しているすべてのアクションを可視化(ビューは常にエントリーポイント分析モード)
34
+ - **カスタムエントリーポイントパターン**: エントリーポイントを柔軟に指定可能(デフォルトは `pages/**/*.{tsx,jsx,ts,js}`)
35
+
36
+ ## 使用方法
37
+
38
+ ### CLIツールとして使用
39
+
40
+ ```bash
41
+ npx bm-action-dep-parser action ./packages/actions/js
42
+ npx bm-action-dep-parser view ./packages/views
43
+ ```
44
+
45
+ ### オプション
46
+
47
+ ```bash
48
+ # 出力形式を指定(text または json)
49
+ npx bm-action-dep-parser action ./packages/actions/js --format json
50
+
51
+ # カスタムエントリーポイントパターンを指定(ビューの場合のみ)
52
+ npx bm-action-dep-parser view ./packages/views --entry-point-patterns "**/*.tsx"
53
+
54
+ # ヘルプを表示
55
+ npx bm-action-dep-parser --help
56
+ ```
57
+
58
+ ### ローカルでの実行
59
+
60
+ ```bash
61
+ npx ts-node analyze-action-dependencies.ts action ./packages/actions/js
62
+ npx ts-node analyze-action-dependencies.ts view ./packages/views
63
+ ```
64
+
65
+ ## 技術詳細
66
+
67
+ このツールは以下のモジュールで構成されています:
68
+
69
+ 1. **index.ts**: メインエントリーポイント
70
+ 2. **cli.ts**: コマンドラインインターフェース
71
+ 3. **lib/file-finder.ts**: ファイル検索モジュール
72
+ 4. **lib/code-analyzer.ts**: コード解析モジュール
73
+ 5. **lib/dependency-extractor.ts**: 依存関係抽出モジュール
74
+ 6. **lib/result-formatter.ts**: 結果出力モジュール
75
+ 7. **lib/dependency-graph-builder.ts**: 依存関係グラフ構築モジュール
76
+ 8. **lib/entry-point-analyzer.ts**: エントリーポイント解析モジュール
77
+
78
+ TypeScriptのコンパイラAPIを使用してコードを解析し、アクション呼び出しを検出しています。エントリーポイント分析モードでは、ファイル間の依存関係も解析して、間接的なアクション依存関係も検出します。
@@ -0,0 +1,26 @@
1
+ export type TargetType = 'action' | 'view';
2
+ /**
3
+ * JavaScriptアクションの依存関係を表す型
4
+ */
5
+ export interface JavaScriptActionDependency {
6
+ entrypoint: string;
7
+ dependencies: string[];
8
+ }
9
+ /**
10
+ * ビューの依存関係を表す型
11
+ */
12
+ export interface ViewDependency {
13
+ entrypoint: string;
14
+ dependencies: {
15
+ direct: string[];
16
+ indirect: Record<string, string[]>;
17
+ };
18
+ }
19
+ /**
20
+ * アクション依存関係を解析する関数
21
+ * @param targetType 解析対象のタイプ ('action' または 'view')
22
+ * @param targetDir 対象ディレクトリ
23
+ * @param entryPointPatterns エントリーポイントのパターン(viewの場合のみ使用)
24
+ * @returns 解析結果のオブジェクト
25
+ */
26
+ export declare function analyzeActionDependencies(targetType: TargetType, targetDir: string, entryPointPatterns?: string[]): Promise<JavaScriptActionDependency[] | ViewDependency[]>;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.analyzeActionDependencies = analyzeActionDependencies;
37
+ const path = __importStar(require("path"));
38
+ const file_finder_1 = require("./lib/file-finder");
39
+ const code_analyzer_1 = require("./lib/code-analyzer");
40
+ const dependency_extractor_1 = require("./lib/dependency-extractor");
41
+ const dependency_graph_builder_1 = require("./lib/dependency-graph-builder");
42
+ const entry_point_analyzer_1 = require("./lib/entry-point-analyzer");
43
+ /**
44
+ * アクション依存関係を解析する関数
45
+ * @param targetType 解析対象のタイプ ('action' または 'view')
46
+ * @param targetDir 対象ディレクトリ
47
+ * @param entryPointPatterns エントリーポイントのパターン(viewの場合のみ使用)
48
+ * @returns 解析結果のオブジェクト
49
+ */
50
+ async function analyzeActionDependencies(targetType, targetDir, entryPointPatterns = entry_point_analyzer_1.defaultEntryPointPatterns) {
51
+ try {
52
+ // ファイル検索
53
+ const files = await (0, file_finder_1.findFiles)(targetDir, targetType);
54
+ // 各ファイルの解析と依存関係の抽出
55
+ const dependencies = {};
56
+ for (const file of files) {
57
+ try {
58
+ const ast = await (0, code_analyzer_1.analyzeFile)(file);
59
+ const fileDependencies = (0, dependency_extractor_1.extractDependencies)(ast, targetType);
60
+ dependencies[file] = fileDependencies;
61
+ }
62
+ catch (error) {
63
+ console.error(`ファイル ${file} の解析中にエラーが発生しました:`, error);
64
+ dependencies[file] = [];
65
+ }
66
+ }
67
+ // アクションの場合
68
+ if (targetType === 'action') {
69
+ // 新しい形式に変換
70
+ const result = [];
71
+ for (const [file, deps] of Object.entries(dependencies)) {
72
+ if (deps.length === 0) {
73
+ continue;
74
+ }
75
+ // コマンドで指定したディレクトリからの相対パスに変換
76
+ const relativePath = path.relative(targetDir, file);
77
+ result.push({
78
+ entrypoint: relativePath,
79
+ dependencies: deps
80
+ });
81
+ }
82
+ return result;
83
+ }
84
+ // ビューの場合
85
+ if (targetType === 'view') {
86
+ // 依存関係グラフの構築
87
+ const dependencyGraph = new dependency_graph_builder_1.ViewDependencyGraph(targetDir);
88
+ for (const file of files) {
89
+ await dependencyGraph.addFile(file);
90
+ }
91
+ // エントリーポイントからの依存関係を解析
92
+ const entryPointDependencies = await (0, entry_point_analyzer_1.analyzeEntryPoints)(targetDir, dependencyGraph, entryPointPatterns);
93
+ // 新しい形式に変換
94
+ const result = [];
95
+ for (const [entryPoint, deps] of Object.entries(entryPointDependencies)) {
96
+ result.push({
97
+ entrypoint: entryPoint,
98
+ dependencies: deps
99
+ });
100
+ }
101
+ return result;
102
+ }
103
+ return [];
104
+ }
105
+ catch (error) {
106
+ throw error;
107
+ }
108
+ }
109
+ //# sourceMappingURL=analyze-action-dependencies.js.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;gBACX,CAAC;gBAED,4BAA4B;gBAC5B,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;gBAEpD,MAAM,CAAC,IAAI,CAAC;oBACV,UAAU,EAAE,YAAY;oBACxB,YAAY,EAAE,IAAI;iBACnB,CAAC,CAAC;YACL,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,SAAS;QACT,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;YAC1B,aAAa;YACb,MAAM,eAAe,GAAG,IAAI,8CAAmB,CAAC,SAAS,CAAC,CAAC;YAC3D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACtC,CAAC;YAED,sBAAsB;YACtB,MAAM,sBAAsB,GAAG,MAAM,IAAA,yCAAkB,EAAC,SAAS,EAAE,eAAe,EAAE,kBAAkB,CAAC,CAAC;YAExG,WAAW;YACX,MAAM,MAAM,GAAqB,EAAE,CAAC;YAEpC,KAAK,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,EAAE,CAAC;gBACxE,MAAM,CAAC,IAAI,CAAC;oBACV,UAAU,EAAE,UAAU;oBACtB,YAAY,EAAE,IAAI;iBACnB,CAAC,CAAC;YACL,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const analyze_action_dependencies_1 = require("./analyze-action-dependencies");
5
+ // コマンドライン引数の解析
6
+ const args = process.argv.slice(2);
7
+ // ヘルプメッセージの表示
8
+ if (args.includes('--help') || args.includes('-h') || args.length === 0) {
9
+ console.log(`
10
+ bm-action-dep-parser - BaseMachina アクション依存関係解析ツール
11
+
12
+ 使用方法:
13
+ bm-action-dep-parser <action|view> <directory> [options]
14
+
15
+ オプション:
16
+ --entry-point-patterns <patterns> エントリーポイントのパターンをカンマ区切りで指定 (デフォルト: pages/**/*.{tsx,jsx,ts,js})
17
+ --help, -h ヘルプメッセージを表示
18
+
19
+ 例:
20
+ bm-action-dep-parser action ./packages/actions/js
21
+ bm-action-dep-parser view ./packages/views
22
+ bm-action-dep-parser view ./packages/views --entry-point-patterns "pages/*.tsx,components/**/*.tsx"
23
+ `);
24
+ process.exit(0);
25
+ }
26
+ // 引数の検証
27
+ const targetType = args[0];
28
+ const targetDir = args[1];
29
+ if (!targetType || !targetDir) {
30
+ console.error('エラー: 解析対象と対象ディレクトリを指定してください');
31
+ console.error('使用方法: bm-action-dep-parser <action|view> <directory> [options]');
32
+ console.error('詳細は --help オプションを参照してください');
33
+ process.exit(1);
34
+ }
35
+ // オプションの解析
36
+ let entryPointPatterns = ["pages/**/*.{tsx,jsx,ts,js}"];
37
+ for (let i = 2; i < args.length; i++) {
38
+ const arg = args[i];
39
+ if (arg === '--entry-point-patterns' && i + 1 < args.length) {
40
+ entryPointPatterns = args[i + 1].split(',');
41
+ i++;
42
+ }
43
+ }
44
+ // 解析の実行
45
+ (0, analyze_action_dependencies_1.analyzeActionDependencies)(targetType, targetDir, entryPointPatterns)
46
+ .then(result => {
47
+ console.log(JSON.stringify(result, null, 2));
48
+ })
49
+ .catch(error => {
50
+ console.error('エラーが発生しました:', error);
51
+ process.exit(1);
52
+ });
53
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../cli.ts"],"names":[],"mappings":";;;AAEA,+EAAsF;AAGtF,eAAe;AACf,MAA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AAE,SAAS,EAAE,kBAAkB,CAAC;KAC/D,IAAI,CAAC,MAAM,CAAC,EAAE;IACX,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC,CAAC;KACD,KAAK,CAAC,KAAK,CAAC,EAAE;IACX,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { analyzeActionDependencies } from './analyze-action-dependencies';
2
+ export type { TargetType, JavaScriptActionDependency, ViewDependency } from './analyze-action-dependencies';
3
+ export { findFiles } from './lib/file-finder';
4
+ export { analyzeFile } from './lib/code-analyzer';
5
+ export { extractDependencies } from './lib/dependency-extractor';
6
+ export { formatJavaScriptActionDependencyAnalysisResult, formatViewDependencyAnalysisResult } from './lib/result-formatter';
7
+ export { ViewDependencyGraph } from './lib/dependency-graph-builder';
8
+ export { analyzeEntryPoints } from './lib/entry-point-analyzer';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.analyzeEntryPoints = exports.ViewDependencyGraph = exports.formatViewDependencyAnalysisResult = exports.formatJavaScriptActionDependencyAnalysisResult = exports.extractDependencies = exports.analyzeFile = exports.findFiles = exports.analyzeActionDependencies = void 0;
4
+ // index.ts の新しい内容
5
+ var analyze_action_dependencies_1 = require("./analyze-action-dependencies");
6
+ Object.defineProperty(exports, "analyzeActionDependencies", { enumerable: true, get: function () { return analyze_action_dependencies_1.analyzeActionDependencies; } });
7
+ // ライブラリとしてのエクスポート
8
+ var file_finder_1 = require("./lib/file-finder");
9
+ Object.defineProperty(exports, "findFiles", { enumerable: true, get: function () { return file_finder_1.findFiles; } });
10
+ var code_analyzer_1 = require("./lib/code-analyzer");
11
+ Object.defineProperty(exports, "analyzeFile", { enumerable: true, get: function () { return code_analyzer_1.analyzeFile; } });
12
+ var dependency_extractor_1 = require("./lib/dependency-extractor");
13
+ Object.defineProperty(exports, "extractDependencies", { enumerable: true, get: function () { return dependency_extractor_1.extractDependencies; } });
14
+ var result_formatter_1 = require("./lib/result-formatter");
15
+ Object.defineProperty(exports, "formatJavaScriptActionDependencyAnalysisResult", { enumerable: true, get: function () { return result_formatter_1.formatJavaScriptActionDependencyAnalysisResult; } });
16
+ Object.defineProperty(exports, "formatViewDependencyAnalysisResult", { enumerable: true, get: function () { return result_formatter_1.formatViewDependencyAnalysisResult; } });
17
+ var dependency_graph_builder_1 = require("./lib/dependency-graph-builder");
18
+ Object.defineProperty(exports, "ViewDependencyGraph", { enumerable: true, get: function () { return dependency_graph_builder_1.ViewDependencyGraph; } });
19
+ var entry_point_analyzer_1 = require("./lib/entry-point-analyzer");
20
+ Object.defineProperty(exports, "analyzeEntryPoints", { enumerable: true, get: function () { return entry_point_analyzer_1.analyzeEntryPoints; } });
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,kBAAkB;AAClB,6EAEuC;AADrC,wIAAA,yBAAyB,OAAA;AAS3B,kBAAkB;AAClB,iDAA8C;AAArC,wGAAA,SAAS,OAAA;AAClB,qDAAkD;AAAzC,4GAAA,WAAW,OAAA;AACpB,mEAAiE;AAAxD,2HAAA,mBAAmB,OAAA;AAC5B,2DAGgC;AAF9B,kJAAA,8CAA8C,OAAA;AAC9C,sIAAA,kCAAkC,OAAA;AAEpC,2EAAqE;AAA5D,+HAAA,mBAAmB,OAAA;AAC5B,mEAAgE;AAAvD,0HAAA,kBAAkB,OAAA"}
@@ -0,0 +1,7 @@
1
+ import * as ts from 'typescript';
2
+ /**
3
+ * ファイルを解析してASTを生成する
4
+ * @param filePath 解析対象のファイルパス
5
+ * @returns TypeScriptのソースファイル(AST)
6
+ */
7
+ export declare function analyzeFile(filePath: string): Promise<ts.SourceFile>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.analyzeFile = analyzeFile;
40
+ const ts = __importStar(require("typescript"));
41
+ const promises_1 = __importDefault(require("fs/promises"));
42
+ /**
43
+ * ファイルを解析してASTを生成する
44
+ * @param filePath 解析対象のファイルパス
45
+ * @returns TypeScriptのソースファイル(AST)
46
+ */
47
+ async function analyzeFile(filePath) {
48
+ try {
49
+ const content = await promises_1.default.readFile(filePath, 'utf-8');
50
+ // TypeScriptのパーサーを使用してASTを生成
51
+ const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
52
+ return sourceFile;
53
+ }
54
+ catch (error) {
55
+ console.error(`Error analyzing file ${filePath}:`, error);
56
+ throw error;
57
+ }
58
+ }
59
+ //# sourceMappingURL=code-analyzer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-analyzer.js","sourceRoot":"","sources":["../../lib/code-analyzer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,kCAiBC;AAzBD,+CAAiC;AACjC,2DAA6B;AAE7B;;;;GAIG;AACI,KAAK,UAAU,WAAW,CAAC,QAAgB;IAChD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAErD,6BAA6B;QAC7B,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CACpC,QAAQ,EACR,OAAO,EACP,EAAE,CAAC,YAAY,CAAC,MAAM,EACtB,IAAI,CACL,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,wBAAwB,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ import * as ts from 'typescript';
2
+ import { TargetType } from '../analyze-action-dependencies';
3
+ /**
4
+ * ASTからアクション依存関係を抽出する
5
+ * @param sourceFile TypeScriptのソースファイル(AST)
6
+ * @param targetType 解析対象のタイプ ('action' または 'view')
7
+ * @returns 依存しているアクションの識別子の配列
8
+ */
9
+ export declare function extractDependencies(sourceFile: ts.SourceFile, targetType: TargetType): string[];
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.extractDependencies = extractDependencies;
37
+ const ts = __importStar(require("typescript"));
38
+ /**
39
+ * 引数から依存関係を抽出する共通関数
40
+ * @param arg 関数の引数
41
+ * @param variableMap 変数名とその値のマッピング
42
+ * @returns 依存関係の文字列(存在する場合)
43
+ */
44
+ function extractDependencyFromArgument(arg, variableMap) {
45
+ if (ts.isStringLiteral(arg)) {
46
+ // 文字列リテラルの場合
47
+ return arg.text;
48
+ }
49
+ else if (ts.isIdentifier(arg)) {
50
+ // 変数の場合
51
+ return variableMap.get(arg.text) || null;
52
+ }
53
+ return null;
54
+ }
55
+ /**
56
+ * ASTからアクション依存関係を抽出する
57
+ * @param sourceFile TypeScriptのソースファイル(AST)
58
+ * @param targetType 解析対象のタイプ ('action' または 'view')
59
+ * @returns 依存しているアクションの識別子の配列
60
+ */
61
+ function extractDependencies(sourceFile, targetType) {
62
+ const dependencies = new Set();
63
+ const variableMap = new Map(); // 変数名とその値のマッピング
64
+ // 検出対象の関数名
65
+ const targetFunctions = ['executeAction'];
66
+ // ビューのコードの場合は、追加の関数も検出
67
+ if (targetType === 'view') {
68
+ targetFunctions.push('useExecuteAction', 'useExecuteActionLazy');
69
+ }
70
+ // ASTを走査して、アクション呼び出しを検出
71
+ function visit(node) {
72
+ // 変数宣言を検出して、文字列リテラルが代入されている場合は記録
73
+ if (ts.isVariableDeclaration(node) &&
74
+ node.initializer &&
75
+ ts.isStringLiteral(node.initializer) &&
76
+ ts.isIdentifier(node.name)) {
77
+ variableMap.set(node.name.text, node.initializer.text);
78
+ }
79
+ // 対象関数の呼び出しを検出
80
+ if (ts.isCallExpression(node) &&
81
+ ts.isIdentifier(node.expression) &&
82
+ targetFunctions.includes(node.expression.text)) {
83
+ const firstArg = node.arguments[0];
84
+ if (firstArg) {
85
+ const dependency = extractDependencyFromArgument(firstArg, variableMap);
86
+ if (dependency) {
87
+ dependencies.add(dependency);
88
+ }
89
+ }
90
+ }
91
+ // 子ノードを再帰的に走査
92
+ ts.forEachChild(node, visit);
93
+ }
94
+ visit(sourceFile);
95
+ return Array.from(dependencies);
96
+ }
97
+ //# sourceMappingURL=dependency-extractor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-extractor.js","sourceRoot":"","sources":["../../lib/dependency-extractor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,kDA2CC;AAtED,+CAAiC;AAIjC;;;;;EAKE;AACF,SAAS,6BAA6B,CAAC,GAAY,EAAE,WAAgC;IACnF,IAAI,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,a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S,CAAC,CAAC,CAAC,CAAC;YACnC,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,UAAU,GAAG,6BAA6B,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;gBACxE,IAAI,UAAU,EAAE,CAAC;oBACf,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC;QACH,CAAC;QAED,cAAc;QACd,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,CAAC;IAElB,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * ファイル間の依存関係を表すグラフ
3
+ */
4
+ export declare class ViewDependencyGraph {
5
+ private graph;
6
+ private directActionDependencies;
7
+ private normalizedPaths;
8
+ private baseDir;
9
+ constructor(baseDir: string);
10
+ /**
11
+ * ファイルを解析してグラフに追加
12
+ * @param filePath ファイルパス
13
+ */
14
+ addFile(filePath: string): Promise<void>;
15
+ /**
16
+ * インポート文からファイルの依存関係を抽出
17
+ * @param sourceFile TypeScriptのソースファイル
18
+ * @param basePath インポートパスの解決に使用するベースパス
19
+ * @returns 依存先ファイルパスの配列
20
+ */
21
+ private extractImports;
22
+ /**
23
+ * JSXコンポーネントの使用からファイルの依存関係を抽出
24
+ * @param sourceFile TypeScriptのソースファイル
25
+ * @param basePath インポートパスの解決に使用するベースパス
26
+ * @returns 依存先ファイルパスの配列
27
+ */
28
+ private extractJsxComponents;
29
+ /**
30
+ * インポートパスを絶対パスに解決
31
+ * @param importPath インポートパス
32
+ * @param basePath インポートパスの解決に使用するベースパス
33
+ * @returns 解決されたファイルパス
34
+ */
35
+ private resolveImportPath;
36
+ /**
37
+ * ファイルパスを正規化(絶対パスに変換)
38
+ * @param filePath ファイルパス
39
+ * @returns 正規化されたファイルパス
40
+ */
41
+ private normalizePath;
42
+ /**
43
+ * エントリーポイントから到達可能なすべてのアクション依存関係を取得
44
+ * @param entryPoint エントリーポイントのファイルパス
45
+ * @returns 直接依存するアクションと間接依存するアクション(ファイルパスごと)
46
+ */
47
+ getReachableActionDependencies(entryPoint: string): {
48
+ direct: string[];
49
+ indirect: Map<string, string[]>;
50
+ };
51
+ /**
52
+ * 依存関係グラフの統計情報を取得
53
+ * @returns 統計情報
54
+ */
55
+ getStats(): {
56
+ totalFiles: number;
57
+ totalDependencies: number;
58
+ filesWithActionDependencies: number;
59
+ totalActionDependencies: number;
60
+ };
61
+ }