Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hono のクライアントの補完を高速化 #19

Merged
merged 3 commits into from
Nov 27, 2024
Merged

Conversation

harsssh
Copy link
Collaborator

@harsssh harsssh commented Nov 21, 2024

Hono のドキュメントにもあるとおり、型を事前にコンパイルするとクライアントの補完が早くなる。
TypeScript の Project References を使う方法を採用した。

https://hono.dev/docs/guides/rpc#compile-your-code-before-using-it-recommended

設定は面倒ですが、これくらい爆速になります。

fast-hono.mov

詳細はコメントで補足します。

@harsssh harsssh requested a review from smatsuodev November 21, 2024 18:21
@@ -11,7 +11,8 @@
"migrate": "drizzle-kit generate && wrangler d1 migrations apply scrap",
"migrate:remote": "drizzle-kit generate && wrangler d1 migrations apply scrap --remote ",
"lint": "biome check",
"lint:fix": "biome check --fix"
"lint:fix": "biome check --fix",
"watch:server-types": "tsc -b -w ./src/server"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ソースコードを更新したら再コンパイルが必要なので、tsc --watch で更新が必要です

Comment on lines +5 to +6
"composite": true,
"declaration": true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "./types",
"rootDir": "../"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

サーバーのコードが src/db など、親ディレクトリのものを参照するので必要です

"paths": {
"@/*": ["./src/*"]
},
"skipLibCheck": true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

依存パッケージで型エラーが起きたりするので、チェックを無効化

},
"noUncheckedIndexedAccess": true
}
"disableSourceOfProjectReferenceRedirect": true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

project reference とこのオプションを有効化すると、型情報はコンパイルした *.d.ts を参照するようになる。

詳しくは以下の PR のコメントを参照。

microsoft/TypeScript#32028 (comment)

@@ -2,7 +2,7 @@
"name": "scrap",
"type": "module",
"scripts": {
"dev": "vite dev",
"dev": "concurrently -r -k yarn:watch:server-types vite",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-r, --raw は余計な prefix などを付けない、-k, --kill-others はどれかが終了したら全て終了させる。

@harsssh
Copy link
Collaborator Author

harsssh commented Nov 25, 2024

concurrently で起動したコマンドが止まらないことがあるかも
後で調査

@harsssh
Copy link
Collaborator Author

harsssh commented Nov 25, 2024

concurrently で起動したコマンドが止まらないことがあるかも

問題なさそう

Base automatically changed from hono-split-routes to main November 27, 2024 14:04
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "./types",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits
build/typesの方がより一般的に感じるのですがどうでしょうか?
生成物かつリポジトリの管理下に置かないコードはbuildディレクトリ以下に置いておくことで、.gitignorebuild/**を無視するようにかけたりもするかなと思いました

@harsssh harsssh merged commit 2c40f21 into main Nov 27, 2024
1 check passed
@harsssh harsssh deleted the perf-hono-client branch November 27, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants