@r_masseater/vite-plus-adopt 0.4.1 → 0.6.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 CHANGED
@@ -3,12 +3,6 @@
3
3
  `vpa` は、Betterleaks・actionlint・zizmor・commitlint・textlint・markdownlint・Steiger・fallow を Vite+ に取り込む CLI である。設定と依存の規則を `vite.config.ts` に書くと、そこから読んで動かす。
4
4
  引数なしの `vpa` を 1 回実行すると、設定のある検査をすべて並行して動かし、結果をまとめて出す。
5
5
  TypeScript 7 だけで動く Feature-Sliced Design の Steiger プラグインと @arethetypeswrong/core も同梱する。
6
- 各ツールのための設定ファイルは置かずに済む。
7
- Betterleaks の `.betterleaks.toml`・`.betterleaksignore` と、textlint の `.textlintrc`・`.textlintignore` は要らない。
8
- `.markdownlint-cli2.jsonc`・`.fallowrc.jsonc`・`steiger.config.ts` も要らない。
9
- syncpack の設定と、`package.json` の `commitlint` も要らない。
10
- Betterleaks・actionlint・zizmor のバイナリは、postinstall が固定した版を GitHub のリリースから取り、SHA-256 を照合してパッケージの `vendor/` に置く。実行時には取りに行かない。
11
- 設定は Vite+ の `resolveConfigFromFile` で読み、型は `vite` の `UserConfig` を拡張して付ける。
12
6
 
13
7
  ## 公開先
14
8
 
@@ -55,6 +49,7 @@ export default defineConfig({
55
49
  ```
56
50
 
57
51
  `import type {} from "@r_masseater/vite-plus-adopt"` で、`defineConfig` に上の 8 つのキーの型が付く。
52
+ Steiger は `steiger.paths` に合うディレクトリのうち、直下に FSD のレイヤー(`app`・`pages`・`widgets`・`features`・`entities`・`shared` など)のフォルダを持つものだけを検査する。
58
53
 
59
54
  Git のフックは次のように書く。
60
55
 
@@ -68,10 +63,6 @@ vpa --commit-msg "$1"
68
63
  ## Feature-Sliced Design のプラグイン
69
64
 
70
65
  `@r_masseater/vite-plus-adopt/fsd` は [@feature-sliced/steiger-plugin][fsd-plugin] 0.8.2 を同梱したもので、ルールと `configs.recommended` は元と同じである。
71
- 元のプラグインが使う [@feature-sliced/filesystem][fsd-filesystem] は、import の解決に TypeScript 5 の `ts.resolveModuleName` を使い、TypeScript 7 だけの環境では読み込めない。
72
- 同梱した版では、その解決を TypeScript 7.1 の `typescript/sync` の `createModuleResolver` で行う。
73
- そのため `typescript` 7.1 を依存に持つ。使う側のほかの依存が TypeScript 5 を引き込んでいても、こちらは 7.1 を読む。
74
-
75
66
  steiger 本体も `@feature-sliced/steiger-plugin` に依存し、それが TypeScript 5 を引き込む。
76
67
  vpa は steiger の CLI を使わないので、`pnpm-workspace.yaml` の `overrides` で外せる。
77
68
 
@@ -81,12 +72,10 @@ overrides:
81
72
  ```
82
73
 
83
74
  [fsd-plugin]: https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd
84
- [fsd-filesystem]: https://github.com/feature-sliced/filesystem
85
75
 
86
76
  ## @arethetypeswrong/core の置き換え
87
77
 
88
78
  `@r_masseater/vite-plus-adopt/attw` は [@arethetypeswrong/core][attw] 0.18.5 と同じ API を、TypeScript 7.1 だけで出す。
89
- 元のパッケージは TypeScript 5.6.1-rc を依存に持つので、Vite+ の `pack.attw` をそのまま使うと TypeScript 5 が入る。
90
79
  `pack.attw.module` にこれを渡せば、`@arethetypeswrong/core` を入れずに同じ検査が動く。
91
80
 
92
81
  ```ts
@@ -100,65 +89,8 @@ export default defineConfig({
100
89
  });
101
90
  ```
102
91
 
103
- 元のパッケージの `dist/` を `upstream/attw-core/lib` に置いて同梱し、その中の `typescript` の import を `src/attw/typescript.ts` に向ける。
104
- `src/attw/typescript.ts` は、元のパッケージが呼ぶ `ts.*` だけを持つ。
105
- モジュールの解決、プログラムの組み立て、シンボルの束縛は、TypeScript 5.6.1-rc の処理を TypeScript 7.1 の構文木の上で書き直してある。
106
- 型の問い合わせは、パッケージのファイルを仮想のファイルシステムとして TypeScript 7.1 の型検査器に見せて答える。
107
- 元のパッケージの `internal/multiCompilerHost.js` は、`src/attw/compiler-hosts.ts` に差し替える。
108
- `upstream/attw-core/lib` には `upstream/attw-core/lib.patch` を当ててある。
109
- TypeScript 7 の構文木に無い `escapedText` を `text` に読み替え、型定義の `typescript` の import を `typescript/sync` に向ける。
110
- `typesVersions` は TypeScript 5.6.1-rc として照合し、`ts.version` も `5.6.1-rc` を返す。結果を元のパッケージと揃えるためである。
111
-
112
- ### テスト
113
-
114
- `upstream/attw-core/test` は元のリポのテストを手を入れずに置いたものである。
115
- テストが読む `fixtures` と `snapshots` は `upstream/attw-core/` の直下に、元のパッケージの `src/` は `upstream/attw-core/src` に置く。
116
- `tests/attw` は、本物の @arethetypeswrong/core 0.18.5 と TypeScript 5.6.1-rc の結果と突き合わせる。
117
- 入力は `tests/attw/fixtures.json`、期待する結果は `tests/attw/expected.json` にある。
118
- `tests/attw/expected.json` は、このリポの外の空のディレクトリに `@arethetypeswrong/core@0.18.5` を入れて作る。
119
- `fixtures.json` の `fixtures` は `checkPackage` に渡す。
120
- `hostLookups` は `internal/multiCompilerHost.js` の `CompilerHostWrapper` の `resolveModuleName` に渡す。
121
- `paths` は TypeScript 5.6.1-rc のパスの関数に渡す。渡す先は `getRootLength`・`normalizePath`・`getNormalizedAbsolutePath`・`getDirectoryPath`・`combinePaths`・`getPathComponents` である。
122
- `packageNames` は `mangleScopedPackageName`・`unmangleScopedPackageName`・`getTypesPackageName` に渡す。
123
- 返った値を `JSON.stringify` して書き出す。
124
- TypeScript 5 をこのリポの依存に入れないため、作る仕組みはリポに置かない。
125
-
126
92
  [attw]: https://github.com/arethetypeswrong/arethetypeswrong.github.io/tree/main/packages/core
127
93
 
128
- ## 検査
129
-
130
- | 検査 | 動く条件 | 動き |
131
- | ------------ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
132
- | betterleaks | `betterleaks` セクション | 基準のコミットから `HEAD` までの履歴を、postinstall が置いた Betterleaks で検査する。セクションを TOML にして `BETTERLEAKS_CONFIG_TOML` に入れ、`ignoredSecrets` を `--ignore-file` で渡す |
133
- | commitlint | `commitlint` セクション | 基準のコミットから `HEAD` までを `git log --first-parent` で並べ、各メッセージを検査する |
134
- | actionlint | `.github/workflows` がある | postinstall が置いた actionlint を動かす |
135
- | zizmor | `.github/workflows` がある | postinstall が置いた zizmor で `.github` を検査する。`CLAUDE_CODE_REMOTE` があると `--no-online-audits` を付ける |
136
- | dependencies | `dependencyRules` セクション | `pnpm-workspace.yaml` の各パッケージの `package.json` を読み、禁止した依存と、同じ依存の指定の食い違いを報告する |
137
- | steiger | `steiger` セクション | git が扱うファイルを含むディレクトリのうち `paths` の glob に合うものを、`rules` で検査する |
138
- | textlint | `textlint` セクション | git が扱う `*.md` のうち `ignores` に合わないものを検査する |
139
- | markdownlint | `markdownlint` セクション | git が扱う `*.md` のうち `ignores` に合わないものを、`config` と `customRules` で検査する |
140
- | fallow | `fallow` セクション | セクションを一時ファイルに書いて `-c` で渡し、使う側の `fallow` で全体・`dead-code --no-production`・`dupes`・`security` を検査し、コンポーネントの props の受け渡しの指摘も失敗にする |
141
-
142
- 基準のコミットは環境変数 `VPA_BASE` で渡す。無いときや解決できないときは `origin/main` を使う。
143
- CI の浅い clone や partial clone のように履歴を持たないときは、Betterleaks は `HEAD` のツリーを丸ごと検査する。
144
- `vpa --staged` は `git diff --cached` を Betterleaks に渡し、`vpa --commit-msg <ファイル>` はそのコミットメッセージを `commitlint` セクションで検査する。`#` で始まる行は読まない。
145
- postinstall が動いていないと、Betterleaks・actionlint・zizmor の検査は `allowBuilds` に足すよう告げて失敗する。
146
- バイナリのバージョンは `src/binaries.ts` で固定し、vite-plus-adopt のバージョンを上げて変える。
147
-
148
- ## 設定
149
-
150
- | キー | 書き方 |
151
- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
152
- | `betterleaks.ignoredSecrets` | `betterleaks.ignoredSecrets` は `.betterleaksignore` と同じく秘密の SHA-256 を並べる。それ以外のキーは `.betterleaks.toml` と同じで、通す指摘は `filter` と `prefilter` の式で書く。 |
153
- | `dependencyRules.banned` | `dependencyRules.banned` は、理由ごとに禁止する依存名の glob を並べる。`*` は任意の文字列に合う。 |
154
- | `dependencyRules.allowed` | `dependencyRules.allowed` は、理由ごとに `banned` の例外を書く。`workspaces` のワークスペースの、`dependencies` の名前の glob に合う依存を禁止しない。`fields` を書くと、その欄(`devDependencies` など)の依存だけを例外にする。 |
155
- | `dependencyRules.exactDependencies` | `dependencyRules.exactDependencies` は、理由ごとにワークスペースのディレクトリの glob を並べる。合うワークスペースの `dependencies` は正確なバージョンでなければならず、ほかのワークスペースとの指定の一致は求めない。git の依存として読まれるパッケージのように、カタログを使えないものに使う。 |
156
- | `dependencyRules.peerRanges` | `dependencyRules.peerRanges` を `"intersect"` にすると、`peerDependencies` の範囲は重なれば通る。省くと、ほかの依存と同じく指定の一致を求める。`workspace:` の指定は比べない。 |
157
- | `textlint.ignores` | `textlint.ignores` は git の glob で、それ以外のキーは `.textlintrc` と同じである。規則のパッケージは、リポのルートの `node_modules` から読む。TypeScript のまま置いた規則も、`vpx` と同じく `vite-plus/register` で読み込む。 |
158
- | `markdownlint.config` | `markdownlint.config` は markdownlint の規則の設定で、省くと既定の規則で検査する。`ignores` は git の glob である。 |
159
- | `steiger.paths` | `steiger.paths` は検査するディレクトリの glob、`steiger.rules` は `steiger.config.ts` の中身と同じである。 |
160
- | `fallow` | `fallow` は `.fallowrc.json` と同じキーを書く。fallow は使う側の依存に入れる。 |
161
-
162
94
  ## ライセンス
163
95
 
164
96
  MIT。`dist/fsd.mjs`・`dist/parsers`・`dist/attw.mjs` に同梱した元のパッケージのライセンスは `THIRD-PARTY-NOTICES` にある。