@r_masseater/vite-plus-adopt 0.2.0 → 0.3.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/README.md +69 -51
- package/dist/{attempt-5nU57gc3.mjs → attempt-B93fjWiJ.mjs} +5 -2
- package/dist/{attempt-5nU57gc3.mjs.map → attempt-B93fjWiJ.mjs.map} +1 -1
- package/dist/attw.mjs +518 -411
- package/dist/attw.mjs.map +1 -1
- package/dist/cli.mjs +429 -165
- package/dist/cli.mjs.map +1 -1
- package/dist/{config-C8pUNPt5.mjs → config-BdAPwzCc.mjs} +6 -12
- package/dist/config-BdAPwzCc.mjs.map +1 -0
- package/dist/fsd.d.mts +1 -1
- package/dist/fsd.mjs +5 -4
- package/dist/fsd.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/{run-cli-DspfTYgh.mjs → install-COdnLosP.mjs} +46 -37
- package/dist/install-COdnLosP.mjs.map +1 -0
- package/dist/json-D-rhjlSM.mjs +9 -0
- package/dist/json-D-rhjlSM.mjs.map +1 -0
- package/dist/postinstall.mjs +6 -4
- package/dist/postinstall.mjs.map +1 -1
- package/dist/{types-BtHVwMCx.d.mts → types-LygeEwCK.d.mts} +21 -4
- package/package.json +10 -10
- package/dist/config-C8pUNPt5.mjs.map +0 -1
- package/dist/run-cli-DspfTYgh.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# vite-plus-adopt
|
|
2
2
|
|
|
3
|
-
Betterleaks・actionlint・zizmor・commitlint・textlint・Steiger を Vite+
|
|
3
|
+
`vpa` は、Betterleaks・actionlint・zizmor・commitlint・textlint・markdownlint・Steiger・fallow を Vite+ に取り込む CLI である。設定と依存の規則を `vite.config.ts` に書くと、そこから読んで動かす。
|
|
4
|
+
引数なしの `vpa` を 1 回実行すると、設定のある検査をすべて並行して動かし、結果をまとめて出す。
|
|
4
5
|
TypeScript 7 だけで動く Feature-Sliced Design の Steiger プラグインと @arethetypeswrong/core も同梱する。
|
|
5
|
-
|
|
6
|
+
各ツールのための設定ファイルは置かずに済む。
|
|
7
|
+
Betterleaks の `.betterleaks.toml`・`.betterleaksignore` と、textlint の `.textlintrc`・`.textlintignore` は要らない。
|
|
8
|
+
`.markdownlint-cli2.jsonc`・`.fallowrc.jsonc`・`steiger.config.ts` も要らない。
|
|
9
|
+
syncpack の設定と、`package.json` の `commitlint` も要らない。
|
|
6
10
|
Betterleaks・actionlint・zizmor のバイナリは、postinstall が固定した版を GitHub のリリースから取り、SHA-256 を照合してパッケージの `vendor/` に置く。実行時には取りに行かない。
|
|
7
11
|
設定は Vite+ の `resolveConfigFromFile` で読み、型は `vite` の `UserConfig` を拡張して付ける。
|
|
8
12
|
|
|
@@ -39,24 +43,27 @@ export default defineConfig({
|
|
|
39
43
|
filter: 'matchesAny(finding.line, [`\\bCF_BEACON_TOKEN = "[0-9a-f]{32}"`])',
|
|
40
44
|
ignoredSecrets: ["<秘密の SHA-256>"],
|
|
41
45
|
},
|
|
42
|
-
steiger: [...fsd.configs.recommended],
|
|
46
|
+
steiger: { paths: ["apps/*/src"], rules: [...fsd.configs.recommended] },
|
|
43
47
|
textlint: {
|
|
44
48
|
ignores: ["CHANGELOG.md"],
|
|
45
49
|
rules: { "preset-ja-technical-writing": true },
|
|
46
50
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
betterleaks: "vpa betterleaks git . --redact --no-banner",
|
|
51
|
-
dependencies: "vpa dependencies",
|
|
52
|
-
steiger: "vpa steiger apps/*/src",
|
|
53
|
-
textlint: "vpa textlint '*.md'",
|
|
54
|
-
},
|
|
55
|
-
},
|
|
51
|
+
markdownlint: { ignores: ["CHANGELOG.md"] },
|
|
52
|
+
fallow: { production: true, rules: { "unused-files": "error" } },
|
|
53
|
+
run: { tasks: { vpa: { command: "vpa", cache: false } } },
|
|
56
54
|
});
|
|
57
55
|
```
|
|
58
56
|
|
|
59
|
-
`import type {} from "@r_masseater/vite-plus-adopt"` で、`defineConfig` に上の
|
|
57
|
+
`import type {} from "@r_masseater/vite-plus-adopt"` で、`defineConfig` に上の 8 つのキーの型が付く。
|
|
58
|
+
|
|
59
|
+
Git のフックは次のように書く。
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
# .vite-hooks/pre-commit
|
|
63
|
+
vpa --staged
|
|
64
|
+
# .vite-hooks/commit-msg
|
|
65
|
+
vpa --commit-msg "$1"
|
|
66
|
+
```
|
|
60
67
|
|
|
61
68
|
## Feature-Sliced Design のプラグイン
|
|
62
69
|
|
|
@@ -93,53 +100,64 @@ export default defineConfig({
|
|
|
93
100
|
});
|
|
94
101
|
```
|
|
95
102
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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` を返す。結果を元のパッケージと揃えるためである。
|
|
104
111
|
|
|
105
112
|
### テスト
|
|
106
113
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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 をこのリポの依存に入れないため、作る仕組みはリポに置かない。
|
|
116
125
|
|
|
117
126
|
[attw]: https://github.com/arethetypeswrong/arethetypeswrong.github.io/tree/main/packages/core
|
|
118
127
|
|
|
119
|
-
##
|
|
120
|
-
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
127
|
-
|
|
|
128
|
-
| `
|
|
129
|
-
| `
|
|
130
|
-
| `
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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 のバージョンを上げて変える。
|
|
134
147
|
|
|
135
148
|
## 設定
|
|
136
149
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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` から読む。 |
|
|
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 は使う側の依存に入れる。 |
|
|
143
161
|
|
|
144
162
|
## ライセンス
|
|
145
163
|
|
|
@@ -22,7 +22,10 @@ const toolFailed = (tool) => (cause) => VpToolsError.make({
|
|
|
22
22
|
message: `${tool} failed: ${String(cause)}`
|
|
23
23
|
});
|
|
24
24
|
// src/attempt.ts
|
|
25
|
-
const attempt = (tool) => (run) => Effect.tryPromise(
|
|
25
|
+
const attempt = (tool) => (run) => Effect.tryPromise({
|
|
26
|
+
try: run,
|
|
27
|
+
catch: toolFailed(tool)
|
|
28
|
+
});
|
|
26
29
|
export { toolFailed as a, configMissing as i, VpToolsError as n, checksFailed as r, attempt as t };
|
|
27
30
|
|
|
28
|
-
//# sourceMappingURL=attempt-
|
|
31
|
+
//# sourceMappingURL=attempt-B93fjWiJ.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attempt-
|
|
1
|
+
{"version":3,"file":"attempt-B93fjWiJ.mjs","names":[],"sources":["../src/errors.ts","../src/attempt.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nconst taggedError = Schema.TaggedError;\n\nclass VpToolsError extends taggedError<VpToolsError, { readonly brand: unique symbol }>()(\n \"VpToolsError\",\n {\n kind: Schema.Literals([\"config-missing\", \"tool-failed\", \"checks-failed\"]),\n message: Schema.String,\n },\n) {}\n\nconst configMissing = (message: string): VpToolsError =>\n VpToolsError.make({ kind: \"config-missing\", message });\n\nconst checksFailed = (message: string): VpToolsError =>\n VpToolsError.make({ kind: \"checks-failed\", message });\n\nconst toolFailed =\n (tool: string) =>\n (cause: unknown): VpToolsError =>\n VpToolsError.make({ kind: \"tool-failed\", message: `${tool} failed: ${String(cause)}` });\n\nexport { VpToolsError, checksFailed, configMissing, toolFailed };\n","import { Effect } from \"effect\";\n\nimport { toolFailed } from \"./errors.ts\";\nimport type { VpToolsError } from \"./errors.ts\";\n\nconst attempt =\n (tool: string) =>\n <Value>(run: () => PromiseLike<Value>): Effect.Effect<Value, VpToolsError> =>\n Effect.tryPromise({ try: run, catch: toolFailed(tool) });\n\nexport { attempt };\n"],"mappings":";;AAEA,MAAM,cAAc,OAAO;AAE3B,IAAM,eAAN,cAA2B,YAA6D,CAAC,CACvF,gBACA;CACE,MAAM,OAAO,SAAS;EAAC;EAAkB;EAAe;CAAe,CAAC;CACxE,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;AAEH,MAAM,iBAAiB,YACrB,aAAa,KAAK;CAAE,MAAM;CAAkB;AAAQ,CAAC;AAEvD,MAAM,gBAAgB,YACpB,aAAa,KAAK;CAAE,MAAM;CAAiB;AAAQ,CAAC;AAEtD,MAAM,cACH,UACA,UACC,aAAa,KAAK;CAAE,MAAM;CAAe,SAAS,GAAG,KAAK,WAAW,OAAO,KAAK;AAAI,CAAC;;AChB1F,MAAM,WACH,UACO,QACN,OAAO,WAAW;CAAE,KAAK;CAAK,OAAO,WAAW,IAAI;AAAE,CAAC"}
|