vba-runner 0.1.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Koji Arai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.ja.md ADDED
@@ -0,0 +1,94 @@
1
+ # vba-runner
2
+
3
+ Excel 不要で VBA コードを実行・テストできる TypeScript 実装の VBA 実行エンジンです。
4
+ テストランナーとして使う場合は TypeScript からVBAファイルをロードして関数を呼び出せます。
5
+ また、静的解析・整形・構文チェックの CLI ツールも同梱しています。
6
+
7
+ ## インストール
8
+
9
+ ```bash
10
+ npm install vba-runner
11
+ ```
12
+
13
+ ## テストの書き方
14
+
15
+ > [!TIP]
16
+ > 実際にコードを書く前に、ブラウザ上で動作を確認したい場合は [Web UI デモサイト](https://vba-web-runner.netlify.app/) をご利用ください。`Debug.Print` の結果や構文チェックを即座に試すことができます。
17
+
18
+ ### 1. `eval`: VBAの式やコード断片をその場で評価する
19
+
20
+ VBAの構文をそのまま文字列として渡し、評価結果を取得します。最も手軽にVBAエンジンを試すことができる方法です。
21
+
22
+ ```typescript
23
+ import { VBARunner } from 'vba-runner';
24
+ const vbaRunner = new VBARunner(); // 空の環境を作成
25
+
26
+ // VBAの計算式を直接評価
27
+ const sum = vbaRunner.eval("1 + 2 + 3"); // => 6
28
+
29
+ // 変数宣言や代入を含む、複数行の処理も実行可能
30
+ vbaRunner.eval("Dim x : x = 10 : Debug.Print x * 2");
31
+ ```
32
+
33
+ ### 2. `run`: ロードしたソース内の関数を実行する
34
+
35
+ 既存のVBAファイル(`.bas`)をロードし、そこに定義されたプロシージャを引数を指定して呼び出します。複雑なビジネスロジックのユニットテストに最適です。
36
+
37
+ ```typescript
38
+ import { VBARunner, assert } from 'vba-runner';
39
+
40
+ // 1. テスト対象のVBAファイルをロード
41
+ const vbaRunner = new VBARunner('src/vba/Sample.bas');
42
+
43
+ // 2. 関数名を指定して実行(第2引数はJavaScriptの配列として引数を渡す)
44
+ const result1 = vbaRunner.run('Add', [1, 2]);
45
+ const result2 = vbaRunner.run('Multiply', [result1, 2]);
46
+
47
+ // 3. 結果をアサート
48
+ assert.strictEqual(result1, 3);
49
+ assert.strictEqual(result2, 6);
50
+ ```
51
+
52
+ ### 3. 複数ソースの一括ロード
53
+
54
+ VBAファイル(`.bas`)を格納したディレクトリを指定すれば、配下のソースファイルをすべて読み込みます。
55
+ 規模の大きなVBAプロジェクトではこの使い方になります。
56
+
57
+ ```typescript
58
+ import { VBARunner, assert } from 'vba-runner';
59
+
60
+ // 1. テスト対象のVBAディレクトリをロード
61
+ const vbaRunner = new VBARunner('src/vba');
62
+
63
+ // 2. 関数名を指定して実行
64
+ const result = vbaRunner.run('CalcTotal', [100, 200, 300]);
65
+ assert.strictEqual(result, 600);
66
+ ```
67
+
68
+ ## CLI ツール
69
+
70
+ `vba-runner` パッケージは以下の CLI ツールを提供します。
71
+
72
+ | コマンド | 説明 |
73
+ |---|---|
74
+ | `vba-run <file.bas>` | VBAファイルを実行し、Debug.Print の出力を表示する |
75
+ | `vba-analyzer <file.bas>` | VBAコードの静的解析(アウトライン・参照数・重複検出など) |
76
+ | `vba-formatter <file.bas>` | VBAコードの整形(インデント・スペースの統一) |
77
+ | `vba-parse-check <file.bas>` | VBAコードの構文チェック(パースエラーの検出) |
78
+
79
+ ```bash
80
+ # VBAファイルの静的解析(アウトライン表示)
81
+ vba-analyzer --outline src/vba/Module1.bas
82
+
83
+ # 重複ブロックの検出
84
+ vba-analyzer --diff src/vba/
85
+
86
+ # 構文チェック
87
+ vba-parse-check src/vba/Module1.bas
88
+ ```
89
+
90
+ ## 詳細ドキュメント
91
+
92
+ - [REFERENCE.md](../../REFERENCE.md) — 型システム・モック登録・Sandbox方針・VFS など詳細仕様
93
+ - [README.md](../../README.md) — プロジェクト概要・クイックスタート
94
+ - [FOR_AI.md](../../FOR_AI.md) — AIによるリファクタリング支援ガイド
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # vba-runner
2
+
3
+ A TypeScript-based VBA execution engine that runs and tests VBA code without Excel.
4
+ Load `.bas` files from TypeScript and call VBA procedures directly, or use the bundled CLI tools for static analysis, formatting, and syntax checking.
5
+
6
+ > 日本語ドキュメントは [README.ja.md](./README.ja.md) をご覧ください。
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install vba-runner
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ > [!TIP]
17
+ > Try it in the browser before writing any code: [Web UI Demo](https://vba-web-runner.netlify.app/) lets you run VBA snippets and check `Debug.Print` output instantly.
18
+
19
+ ### 1. `eval`: Evaluate a VBA expression or code fragment inline
20
+
21
+ Pass VBA syntax as a string and get the result back. The quickest way to try the engine.
22
+
23
+ ```typescript
24
+ import { VBARunner } from 'vba-runner';
25
+ const vbaRunner = new VBARunner(); // create an empty environment
26
+
27
+ // Evaluate a VBA expression directly
28
+ const sum = vbaRunner.eval("1 + 2 + 3"); // => 6
29
+
30
+ // Multi-line code with variable declarations works too
31
+ vbaRunner.eval("Dim x : x = 10 : Debug.Print x * 2");
32
+ ```
33
+
34
+ ### 2. `run`: Call a procedure defined in a loaded VBA file
35
+
36
+ Load an existing `.bas` file and call its procedures with arguments. Ideal for unit-testing complex business logic.
37
+
38
+ ```typescript
39
+ import { VBARunner, assert } from 'vba-runner';
40
+
41
+ // 1. Load the VBA file under test
42
+ const vbaRunner = new VBARunner('src/vba/Sample.bas');
43
+
44
+ // 2. Call a procedure by name (pass arguments as a JavaScript array)
45
+ const result1 = vbaRunner.run('Add', [1, 2]);
46
+ const result2 = vbaRunner.run('Multiply', [result1, 2]);
47
+
48
+ // 3. Assert the results
49
+ assert.strictEqual(result1, 3);
50
+ assert.strictEqual(result2, 6);
51
+ ```
52
+
53
+ ### 3. Load an entire directory
54
+
55
+ Point `VBARunner` at a directory to load all `.bas` files at once. Use this for larger VBA projects with multiple modules.
56
+
57
+ ```typescript
58
+ import { VBARunner, assert } from 'vba-runner';
59
+
60
+ // 1. Load all VBA files in the directory
61
+ const vbaRunner = new VBARunner('src/vba');
62
+
63
+ // 2. Call any procedure defined across those files
64
+ const result = vbaRunner.run('CalcTotal', [100, 200, 300]);
65
+ assert.strictEqual(result, 600);
66
+ ```
67
+
68
+ ## CLI Tools
69
+
70
+ | Command | Description |
71
+ |---|---|
72
+ | `vba-run <file.bas>` | Execute a VBA file and print `Debug.Print` output |
73
+ | `vba-analyzer <file.bas>` | Static analysis: outline, reference counts, duplicate detection |
74
+ | `vba-formatter <file.bas>` | Format VBA code (indentation, spacing) |
75
+ | `vba-parse-check <file.bas>` | Syntax check (detect parse errors) |
76
+
77
+ ```bash
78
+ # Show outline of a VBA file
79
+ vba-analyzer --outline src/vba/Module1.bas
80
+
81
+ # Detect duplicate code blocks
82
+ vba-analyzer --diff src/vba/
83
+
84
+ # Syntax check
85
+ vba-parse-check src/vba/Module1.bas
86
+ ```
87
+
88
+ ## Documentation
89
+
90
+ - [REFERENCE.md](https://github.com/jca02266/vba-runner/blob/main/REFERENCE.md) — Type system, mock registration, Sandbox policy, VFS details
91
+ - [README.md](https://github.com/jca02266/vba-runner/blob/main/README.md) — Project overview and quick start