Sveltekit Import And Path Simplification
Simplify SvelteKit Import and Path Usage
This codemod simplifies the import statements and path resolution in your SvelteKit project. It replaces the usage of resolvePath
and concatenation with base
by using the resolveRoute
function from $app/paths
. This results in cleaner and more readable code.
Transformations
This codemod performs the following transformations:
-
Import Statement: Transforms:
import { resolvePath } from '@sveltejs/kit';import { base } from '$app/paths';into
import { resolveRoute } from '$app/paths'; -
Path Resolution: Transforms:
const path = base + resolvePath('/blog/[slug]', { slug });into
const path = resolveRoute('/blog/[slug]', { slug });
Usage
To apply this codemod, run the workflow script on your TypeScript files. Ensure you have the necessary dependencies installed and your project is configured to use this codemod.
Example
Before
import { resolvePath } from '@sveltejs/kit';import { base } from '$app/paths';const path = base + resolvePath('/blog/[slug]', { slug });
After
import { resolveRoute } from '$app/paths';const path = resolveRoute('/blog/[slug]', { slug });
Build custom codemods
Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community