zonefence 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024
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,165 @@
1
+ # zonefence
2
+
3
+ TypeScriptプロジェクト向けのフォルダ単位アーキテクチャ・ガードレール
4
+
5
+ ## インストール
6
+
7
+ ```bash
8
+ npm install -D zonefence
9
+ # または
10
+ pnpm add -D zonefence
11
+ ```
12
+
13
+ ## 使い方
14
+
15
+ ### ルールファイルの作成
16
+
17
+ 保護したいフォルダに `zonefence.yaml` を配置します:
18
+
19
+ ```yaml
20
+ version: 1
21
+
22
+ description: "Domain層 - 外部依存を持たない純粋なビジネスロジック"
23
+
24
+ imports:
25
+ allow:
26
+ - from: "./**" # 同フォルダ内のimportを許可
27
+ - from: "@/shared/**" # 共有モジュールを許可
28
+ deny:
29
+ - from: "axios"
30
+ message: "Domain層は外部HTTPライブラリに依存してはいけません"
31
+ - from: "../infrastructure/**"
32
+ message: "Domain層からInfrastructure層への依存は禁止です"
33
+ ```
34
+
35
+ ### チェックの実行
36
+
37
+ ```bash
38
+ npx zonefence check ./src
39
+ ```
40
+
41
+ ## ルールスキーマ
42
+
43
+ ```yaml
44
+ version: 1
45
+
46
+ description: "このフォルダの設計意図を説明"
47
+
48
+ scope:
49
+ apply: descendants # "self" | "descendants"
50
+ exclude:
51
+ - "**/*.test.ts"
52
+ - "**/*.spec.ts"
53
+
54
+ imports:
55
+ allow:
56
+ - from: "./**" # 同フォルダ内
57
+ - from: "@/shared/**" # 共有モジュール
58
+ deny:
59
+ - from: "../infrastructure/**"
60
+ message: "Domain層からInfrastructure層への依存は禁止"
61
+ mode: allow-first # デフォルト
62
+ ```
63
+
64
+ ### 設定オプション
65
+
66
+ | オプション | 説明 | デフォルト |
67
+ |-----------|------|-----------|
68
+ | `version` | スキーマバージョン(現在は1のみ) | 必須 |
69
+ | `description` | フォルダの設計意図の説明 | - |
70
+ | `scope.apply` | ルールの適用範囲(`self`: 自フォルダのみ、`descendants`: 子孫フォルダにも適用) | `descendants` |
71
+ | `scope.exclude` | チェック対象から除外するファイルパターン | `[]` |
72
+ | `imports.allow` | 許可するimportパターンのリスト | `[]` |
73
+ | `imports.deny` | 禁止するimportパターンのリスト | `[]` |
74
+ | `imports.mode` | 評価モード(`allow-first`: 許可リスト優先、`deny-first`: 禁止リスト優先) | `allow-first` |
75
+
76
+ ### 評価モード
77
+
78
+ #### `allow-first`(デフォルト)
79
+
80
+ 1. `deny`ルールにマッチしたらエラー
81
+ 2. `allow`ルールが定義されている場合、いずれかにマッチしなければエラー
82
+
83
+ #### `deny-first`
84
+
85
+ 1. `allow`ルールにマッチしたら許可
86
+ 2. `deny`ルールにマッチしたらエラー
87
+ 3. どちらにもマッチしなければ許可
88
+
89
+ ## パスのマッチング
90
+
91
+ ### 解決済みパス
92
+
93
+ 相対パス(`../shared/utils`)とエイリアス(`@/shared/utils`)が同じファイルを指す場合、ts-morphで解決した絶対パスに対してマッチングを行います。これにより、書き方に関係なく同じルールが適用されます。
94
+
95
+ ### 外部パッケージ
96
+
97
+ 解決できないモジュール(外部パッケージ)は、元のモジュール指定子でマッチングします。
98
+
99
+ ```yaml
100
+ imports:
101
+ allow:
102
+ - from: "**/shared/**" # 解決後パスにマッチ
103
+ - from: "lodash" # 外部パッケージは指定子そのまま
104
+ ```
105
+
106
+ ## ルールの継承
107
+
108
+ 親フォルダのルールは子フォルダに継承されます。子フォルダで定義したルールは親のルールとマージされます。
109
+
110
+ ```
111
+ src/
112
+ ├── zonefence.yaml # 親ルール(scope.apply: descendants)
113
+ └── domain/
114
+ └── zonefence.yaml # 子ルール(親ルールを継承+追加)
115
+ ```
116
+
117
+ `scope.apply: self` を指定すると、そのルールは自フォルダのみに適用され、子フォルダには継承されません。
118
+
119
+ ## エラー出力例
120
+
121
+ ```
122
+ src/domain/user/UserService.ts
123
+ 12:1 error Import from "axios" is not allowed (import-boundary)
124
+ Design intent: Domain層は外部依存を持たない純粋な層です
125
+ Rule: src/domain/zonefence.yaml
126
+
127
+ ✖ 1 error in 1 file
128
+ ```
129
+
130
+ ## CLI オプション
131
+
132
+ ```bash
133
+ npx zonefence check [path] [options]
134
+ ```
135
+
136
+ | オプション | 説明 |
137
+ |-----------|------|
138
+ | `-c, --config <path>` | tsconfig.jsonのパス |
139
+ | `--no-color` | カラー出力を無効化 |
140
+
141
+ ## 開発
142
+
143
+ ```bash
144
+ # 依存関係のインストール
145
+ pnpm install
146
+
147
+ # ビルド
148
+ pnpm run build
149
+
150
+ # 開発モード(ウォッチ)
151
+ pnpm run dev
152
+
153
+ # lint
154
+ pnpm run lint
155
+
156
+ # 型チェック
157
+ pnpm run typecheck
158
+
159
+ # テスト
160
+ pnpm test
161
+ ```
162
+
163
+ ## ライセンス
164
+
165
+ MIT
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # zonefence
2
+
3
+ Folder-based architecture guardrails for TypeScript projects.
4
+
5
+ [日本語版 README](./README.ja.md)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install -D zonefence
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Create a rule file
16
+
17
+ Create a `zonefence.yaml` file in any folder you want to protect:
18
+
19
+ ```yaml
20
+ version: 1
21
+
22
+ description: "Domain layer - no external dependencies allowed"
23
+
24
+ imports:
25
+ allow:
26
+ - from: "./**"
27
+ - from: "@/shared/**"
28
+ deny:
29
+ - from: "axios"
30
+ message: "Domain layer should not depend on external HTTP libraries"
31
+ ```
32
+
33
+ ### Run the check
34
+
35
+ ```bash
36
+ npx zonefence check ./src
37
+ ```
38
+
39
+ ## Rule Schema
40
+
41
+ ```yaml
42
+ version: 1
43
+
44
+ description: "Description of this folder's design intent"
45
+
46
+ scope:
47
+ apply: descendants # "self" | "descendants"
48
+ exclude:
49
+ - "**/*.test.ts"
50
+ - "**/*.spec.ts"
51
+
52
+ imports:
53
+ allow:
54
+ - from: "./**" # Same folder
55
+ - from: "@/shared/**" # Shared modules
56
+ deny:
57
+ - from: "../infrastructure/**"
58
+ message: "Domain layer cannot depend on Infrastructure layer"
59
+ mode: allow-first # default
60
+ ```
61
+
62
+ ## License
63
+
64
+ MIT
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import "../dist/cli/index.js";