-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
122 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default { | ||
motivation: { title: 'Why need to use?' }, | ||
usage: { title: 'Usage' }, | ||
'--- Codemods': { | ||
type: 'separator', | ||
title: 'Codemods', | ||
}, | ||
tanstackQueryImport: { title: 'Migrate TanStack Query imports' }, | ||
} |
46 changes: 46 additions & 0 deletions
46
docs/suspensive.org/src/pages/en/docs/codemods/motivation.mdx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Steps } from 'nextra/components' | ||
import { Callout } from '@/components' | ||
|
||
# Why need to use? | ||
|
||
<Callout type='experimental'> | ||
|
||
`@suspensive/codemods` is an experimental feature, so this interface may change. | ||
|
||
</Callout> | ||
|
||
Codemods are powerful tools that automate repetitive and large-scale tasks within a codebase, making code updates more efficient. They allow for fast and safe updates without the need to manually review numerous changes. | ||
|
||
Suspensive provides codemods to help manage API updates and deprecated APIs seamlessly. | ||
|
||
<Steps> | ||
|
||
### Handle Large-Scale API Changes Quickly and Easily | ||
|
||
Projects using Suspensive packages often have these packages utilized globally across the codebase. Manually locating and modifying all usages is not only time-consuming but also prone to errors. | ||
|
||
```shell | ||
npx @suspensive/codemods | ||
✔ Which transform would you like to apply? > tanstack-query-import | ||
✔ On which files or directory should the codemods be applied? … . | ||
Processing 130 files... | ||
Spawning 10 workers... | ||
Sending 13 files to free worker... | ||
Sending 13 files to free worker... | ||
... | ||
All done. | ||
Results: | ||
0 errors | ||
31 unmodified | ||
0 skipped | ||
99 ok | ||
Time elapsed: 2.980 seconds | ||
``` | ||
|
||
The log above shows the result of running the [`tanstack-query-import`](/docs/codemods/tanstackQueryImport) codemod to automatically migrate the deprecated `@suspensive/react-query` API to `@tanstack/react-query` v5 in a `@suspensive/react-query` & `@tanstack/react-query` environment. Out of 130 files, 99 were transformed in just 2.980 seconds. | ||
|
||
## Update Suspensive Packages Easily and Safely | ||
|
||
Major updates to packages often introduce breaking changes that complicate code migration. Suspensive plans to thoroughly support these breaking changes through codemods, making management simpler. By using codemods, you can upgrade to new versions and features quickly and securely. | ||
|
||
</Steps> |
31 changes: 31 additions & 0 deletions
31
docs/suspensive.org/src/pages/en/docs/codemods/tanstackQueryImport.mdx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Callout } from '@/components' | ||
|
||
# Migrate TanStack Query imports | ||
|
||
<Callout type='info'> | ||
|
||
This codemod is recommended for updating `@suspensive/react-query` & `@tanstack/react-query` from v4 to v5. | ||
|
||
</Callout> | ||
|
||
In the `@suspensive/react-query` & `@tanstack/react-query` v5 environment, Suspense Hooks and queryOptions provided by `@suspensive/react-query` are marked as deprecated. This is because `@suspensive/react-query` offers the same APIs (Suspense Hooks and queryOptions) that are available in `@tanstack/react-query` v5. The purpose is to encourage developers to use the v5 API from `@tanstack/react-query` directly. | ||
|
||
```shell | ||
npx @suspensive/codemods tanstack-query-import . | ||
``` | ||
|
||
This codemod automatically transforms import paths from `@suspensive/react-query` to `@tanstack/react-query` v5. | ||
|
||
Example: | ||
|
||
```tsx | ||
import { queryOptions } from '@suspensive/react-query' | ||
import { useSuspenseQuery } from '@suspensive/react-query-5' // The versioned package is also transformed! | ||
``` | ||
After transformation: | ||
```tsx | ||
import { queryOptions } from '@tanstack/react-query' | ||
import { useSuspenseQuery } from '@tanstack/react-query' | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Callout } from '@/components' | ||
|
||
# Usage | ||
|
||
<Callout type='experimental'> | ||
|
||
`@suspensive/codemods` is an experimental feature, so this interface may change. | ||
|
||
</Callout> | ||
|
||
You can run Suspensive's Codemods with a single command, easily using npx without the need to install it as a dependency. | ||
|
||
Navigate to your project folder in the terminal and run the following command: | ||
|
||
[![npm version](https://img.shields.io/npm/v/@suspensive/codemods?color=000&labelColor=000&logo=npm)](https://www.npmjs.com/package/@suspensive/codemods) | ||
|
||
```shell | ||
npx @suspensive/codemods <transform> <path> | ||
``` | ||
|
||
Adjust `<transform>` and `<path>` to match the environment where you want to apply the codemod. | ||
|
||
- `<transform>`: name of transform | ||
- `<path>`: files or directory to transform |
This file contains 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
This file contains 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