Repository navigation
refactor: lib subpath imports for kit v3 - #4190
Merged
Merged
Conversation
SvelteKit 3 removes the built-in $lib alias and deprecates kit.alias. Move src/lib imports to package.json#imports while still on Kit 2, so that new code stops adding $lib imports before the Kit 3 migration. - Add "#lib/*": "./src/lib/*" to package.json imports - Rewrite 676 specifiers in 282 files with explicit extensions (.js for TS modules, .svelte for components, .svelte.js for runes modules); the rewrite is script-generated and reproducible - Forbid $lib imports with no-restricted-imports in oxlint (.ts) and ESLint (.svelte), since Kit 2 still resolves $lib silently - Update docs/guides rules to the #lib convention; E2E specs keep relative imports because the Playwright runner cannot map #lib/*.js to the .ts source Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
no-restricted-imports catches import/export declarations and dynamic import() in .ts files, but not vi.mock specifiers or dynamic import() in .svelte files. Document the gap and the rg sweep that covers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Important Review skippedToo many files! This PR contains 290 files, which is 190 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry. ⚙️ Run configuration
📒 Files selected for processing: 290
You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
SvelteKit 3 では組み込みの
$libが削除され、kit.aliasも非推奨になります。Kit 3 へ移行する前に、src/libへの import をpackage.json#importsの#lib/*に置き換えます。現行の Kit 2.70.3 のまま動作します。変更内容
package.jsonに"imports": { "#lib/*": "./src/lib/*" }を追加$lib/...を#lib/...に置換(下記の codemod で生成).js、コンポーネントは.svelte、runes モジュール(実体が.svelte.ts)は.svelte.jsです。$libの import をno-restricted-importsで禁止(.tsは oxlint、.svelteは ESLint)$libをそのまま解決するので、規則が無いと新しいコードの$libに Kit 3 移行まで気付けません。docs/guidesの規約(architecture・testing・testing-e2e・server-cache・prisma-db)を#libに更新手で編集したのは
package.json・.oxlintrc.json・eslint.config.mjsとdocs/guidesの5ファイルです。残りの282ファイルは codemod の出力で、そのうち1ファイル(src/lib/clients/aizu_online_judge/clients.ts)だけpnpm formatが行幅で整形しています。レビューの方法
置換部分は、この PR の base(
dc9f2471)で codemod を再実行すると同じ結果になります。手での確認は、上記の手で編集したファイルに絞れます。確認したこと
pnpm lint、pnpm check(0 errors、警告数は変更前と同じ)、pnpm test:unit(2726件)、pnpm build$libを検出し、#libを通すこと(一時ファイルで確認)lint 規則は
vi.mock('$lib/...')と.svelte内の動的import()を検出しません。specifier をまとめて変えるときはrg -n '\$lib' src e2e prismaで残りを確かめてください(docs/guides/architecture.mdに記載)。作業中の branch がある方へ
この PR のマージ後に rebase すると、
$libの import が残っている箇所は lint で止まります。rebase 後に codemodを再実行すれば、新しく追加したファイルも含めて置換されます。何度実行しても結果は変わりません。python3 -I codemod_subpath_imports.py . lib pnpm formatE2E の spec では
#libを使わず、相対 import のままにしてください。Playwright のランナーは#lib/*.jsを.tsの実体に対応付けられないためです。codemod_subpath_imports.py
featuresモード($features・@/features→#features)は、後続の PR で使います。🤖 Generated with Claude Code