Skip to content

Commit 58f3df3

Browse files
committed
docs: add migrate-to-rstack-cli skill
1 parent 36cd392 commit 58f3df3

7 files changed

Lines changed: 244 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
name: migrate-to-rstack-cli
3+
description: Use when migrating projects from standalone Rsbuild, Rslib, Rstest, Rslint, Rspress, or lint-staged tooling to the unified `rstack` package, `rs` commands, and `rstack.config.*`.
4+
---
5+
6+
# Migrate to Rstack CLI
7+
8+
Rstack CLI is the `rstack` package, exposed through the `rs` binaries. It provides one CLI, one config file, and a consistent workflow for the Rstack JavaScript toolchain.
9+
10+
## Tool References
11+
12+
Read every matching reference before editing. Load only the tools present in the project.
13+
14+
- `@rsbuild/core`, `rsbuild.config.*`, `rsbuild` commands, or Rsbuild types: [rsbuild.mdx](references/rsbuild.mdx)
15+
- `@rslib/core`, `rslib.config.*`, `rslib` commands, or Rslib types: [rslib.mdx](references/rslib.mdx)
16+
- `@rstest/core`, `@rstest/adapter-*`, `rstest.config.*`, `rstest` commands, or test imports: [rstest.mdx](references/rstest.mdx)
17+
- `@rslint/core`, `rslint.config.*`, `rslint` commands, or lint imports: [rslint.mdx](references/rslint.mdx)
18+
- `@rspress/core`, `rspress.config.*`, `rspress` commands, themes, or plugins: [rspress.mdx](references/rspress.mdx)
19+
- `lint-staged`, its dotfile configs, `lint-staged.config.*`, or a `lint-staged` manifest key: [lint-staged.mdx](references/lint-staged.mdx)
20+
21+
## Workflow
22+
23+
1. Inspect manifests, workspace catalogs, lock files, scripts, standalone configs, Git hooks, TypeScript `types`, and source imports.
24+
2. Read the matching references and inventory behavior that must survive: config functions, CLI arguments, plugins, presets, adapters, custom config paths, and chained commands.
25+
3. Check the latest `rstack` version and inspect its Node.js engine and underlying tool versions. Resolve plugin and adapter peer ranges first; upgrade incompatible extensions or stop when no compatible version exists. Add `rstack` using the repository's existing package manager and version convention, usually as a development dependency.
26+
4. Create `rstack.config.ts`. Move each standalone config into its corresponding `define.*` registration.
27+
5. Rewrite commands and imports as directed by the references.
28+
6. Search again for old direct imports, binaries, config paths, manifest entries, and type references. Remove only entries with no remaining direct or runtime use and no unresolved peer compatibility requirement.
29+
7. Delete a standalone config only after its behavior is represented in `rstack.config.*`.
30+
8. Refresh the lockfile with the repository's package manager. Confirm the expected tool version changes and resolve peer dependency warnings.
31+
9. Run the repository's existing migrated scripts and required checks. Compare generated artifacts or runtime behavior where relevant.
32+
33+
Underlying Rsbuild, Rslib, Rstest, and Rslint packages remain transitive dependencies of `rstack`. Do not require their names to disappear from the lockfile; require obsolete direct manifest entries and imports to disappear.
34+
35+
## Configuration Rules
36+
37+
Use one of the default names: `rstack.config.ts`, `.js`, `.mts`, or `.mjs`. Use `rs -c <path>` or `rs --config <path>` for a custom path.
38+
39+
```ts
40+
import { define } from 'rstack';
41+
42+
define.app({
43+
// Rsbuild config
44+
});
45+
46+
define.test({
47+
// Rstest config
48+
});
49+
```
50+
51+
Prefer async config functions and dynamic imports for runtime plugins and presets:
52+
53+
```ts
54+
define.lint(async () => {
55+
const { js, ts } = await import('rstack/lint');
56+
return [js.configs.recommended, ts.configs.recommended];
57+
});
58+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# lint-staged Migration
2+
3+
Read this reference when the project uses the `lint-staged` binary, a lint-staged dotfile config, `lint-staged.config.*`, or a `lint-staged` key in `package.json`.
4+
5+
## Steps
6+
7+
1. Replace direct `lint-staged` script invocations with `rs staged`.
8+
2. Move a plain task map into `define.staged` in `rstack.config.*`.
9+
3. Remove the old manifest key or config file.
10+
4. Remove the direct `lint-staged` dependency only when no script, config, or programmatic API still uses it.
11+
12+
## Config Pattern
13+
14+
```ts
15+
import { define } from 'rstack';
16+
17+
define.staged({
18+
'*.{ts,tsx,js,jsx}': ['rs lint --fix', 'prettier -w'],
19+
'*.{json,md}': 'prettier -w',
20+
});
21+
```
22+
23+
## Unsupported Cases
24+
25+
Do not carry lint-staged CLI flags to `rs staged`; they are not forwarded. Keep standalone lint-staged when the workflow requires function-based configs, CLI options, or behavior outside a plain task map.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Rsbuild Migration
2+
3+
Read this reference when the project uses `@rsbuild/core`, `rsbuild.config.*`, `rsbuild` commands, Rsbuild client types, or `@rsbuild/core/types`.
4+
5+
## Steps
6+
7+
1. Replace `rsbuild dev`, `rsbuild build`, and `rsbuild preview` with `rs dev`, `rs build`, and `rs preview`. Preserve supported arguments after the new command.
8+
2. Move the old config export into `define.app`. Preserve async functions, config parameters, plugins, and all options.
9+
3. Replace custom `--config` paths with the migrated `rstack.config.*` path.
10+
4. Replace Rsbuild client and type references:
11+
- `/// <reference types="@rsbuild/core/types" />` to `/// <reference types="rstack/types" />`
12+
- `"types": ["@rsbuild/core/types"]` to `"types": ["rstack/types"]`
13+
- Type-only imports from `@rsbuild/core/types` to `rstack/types`
14+
5. Keep Rsbuild plugins such as `@rsbuild/plugin-react` and `@rsbuild/plugin-vue`, but verify that their peer ranges support the `@rsbuild/core` version installed through `rstack`. Upgrade incompatible plugins before migrating; retaining an older direct core does not make Rstack use it.
15+
6. Search for remaining direct `@rsbuild/core` imports. Remove the direct dependency when no source or runtime API still needs it.
16+
7. Delete `rsbuild.config.*` after the migrated app commands load equivalent config.
17+
18+
## Config Pattern
19+
20+
```ts
21+
import { define } from 'rstack';
22+
23+
define.app(async () => {
24+
const { pluginReact } = await import('@rsbuild/plugin-react');
25+
return {
26+
plugins: [pluginReact()],
27+
};
28+
});
29+
```
30+
31+
If tests also use Rstest, read [rstest.mdx](rstest.mdx). `rs test` derives an Rsbuild test extension from `define.app` unless `define.test` sets `extends`.
32+
33+
## Validate
34+
35+
Run the migrated app build script. Smoke-test dev or preview when those scripts changed or their behavior is material.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Rslib Migration
2+
3+
Read this reference when the project uses `@rslib/core`, `rslib.config.*`, `rslib` commands, library build config, or Rslib type imports.
4+
5+
## Steps
6+
7+
1. Replace the `rslib` executable prefix with `rs lib`. Preserve supported arguments after `rs lib`.
8+
2. Move the old config export into `define.lib`. Preserve async functions, config parameters, plugins, and all options.
9+
3. Keep build plugins, but verify that Rsbuild plugin peer ranges support the core version installed through `rstack`. Upgrade incompatible plugins before migrating.
10+
4. Replace `@rslib/core/types` references with `rstack/types` where applicable.
11+
5. Replace custom `--config` paths with the migrated `rstack.config.*` path.
12+
6. Search for remaining direct `@rslib/core` imports. Remove the direct dependency only when no source or runtime API still needs it.
13+
7. Delete `rslib.config.*` after the migrated library commands load equivalent config.
14+
15+
## Config Pattern
16+
17+
```ts
18+
import { define } from 'rstack';
19+
20+
define.lib({
21+
lib: [{ dts: true }],
22+
});
23+
```
24+
25+
If tests also use Rstest, read [rstest.mdx](rstest.mdx). `rs test` derives an Rslib test extension from `define.lib` unless `define.test` sets `extends`.
26+
27+
## Validate
28+
29+
Run the migrated library build script and compare its outputs.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Rslint Migration
2+
3+
Read this reference when the project uses `@rslint/core`, `rslint.config.*`, `rslint` commands, or Rslint config imports.
4+
5+
## Steps
6+
7+
1. Replace the `rslint` executable prefix with `rs lint`. For example, replace `rslint --fix` with `rs lint --fix`.
8+
2. Move the old config into `define.lint`. Dynamically import presets from `rstack/lint` inside an async config function.
9+
3. Replace direct config/API imports from `@rslint/core` with exports from `rstack/lint` where available.
10+
4. Replace custom `--config` paths with the migrated `rstack.config.*` path.
11+
5. Remove `@rslint/core` only when no uncovered direct runtime API remains. Delete `rslint.config.*`.
12+
13+
## Config Pattern
14+
15+
```ts
16+
import { define } from 'rstack';
17+
18+
define.lint(async () => {
19+
const { js, ts } = await import('rstack/lint');
20+
return [js.configs.recommended, ts.configs.recommended];
21+
});
22+
```
23+
24+
## Script Pattern
25+
26+
```json
27+
{
28+
"scripts": {
29+
"lint": "rs lint && prettier -c .",
30+
"lint:write": "rs lint --fix && prettier -w ."
31+
}
32+
}
33+
```
34+
35+
## Validate
36+
37+
Run the non-writing lint script.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Rspress Migration
2+
3+
Read this reference when the project uses `@rspress/core`, `rspress.config.*`, `rspress` commands, docs config, themes, or plugins.
4+
5+
## Steps
6+
7+
1. Keep `@rspress/core` installed as a direct dependency. `rs doc` requires this optional Rstack peer dependency.
8+
2. Replace the `rspress` executable prefix with `rs doc`: `rspress dev` to `rs doc`, `rspress build` to `rs doc build`, and `rspress preview` to `rs doc preview`. Preserve supported arguments.
9+
3. Move the old config export into `define.doc`. Preserve async functions, themes, plugins, and all options.
10+
4. Replace custom `--config` paths with the migrated `rstack.config.*` path.
11+
5. Keep Rspress-specific type imports from `@rspress/core`; Rstack does not re-export them.
12+
6. Keep themes, plugins, and docs UI packages. Delete `rspress.config.*` only after the migrated docs commands load equivalent config.
13+
14+
## Config Pattern
15+
16+
```ts
17+
import { define } from 'rstack';
18+
19+
define.doc({
20+
root: 'docs',
21+
title: 'Project docs',
22+
});
23+
```
24+
25+
Use an async config and dynamic imports when plugins or themes require runtime imports.
26+
27+
## Validate
28+
29+
Run the migrated docs build script. Smoke-test dev or preview when those workflows changed.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Rstest Migration
2+
3+
Read this reference when the project uses `@rstest/core`, `@rstest/adapter-rsbuild`, `@rstest/adapter-rslib`, `rstest.config.*`, `rstest` commands, or Rstest imports and types.
4+
5+
## Steps
6+
7+
1. Replace the `rstest` executable prefix with `rs test`. Preserve supported arguments, such as `-w`, after `rs test`.
8+
2. Move test options into `define.test`.
9+
3. When `define.app` or `define.lib` exists, remove standard `withRsbuildConfig()` or `withRslibConfig()` wiring and its adapter dependency. Rstack derives that extension unless `define.test` sets `extends`.
10+
4. Preserve explicit custom `extends` values. Keep any adapter or package still imported by that custom extension.
11+
5. Replace imports and TypeScript `types` entries:
12+
- `@rstest/core` to `rstack/test`
13+
- `@rstest/core/globals` to `rstack/test/globals`
14+
- `@rstest/core/importMeta` to `rstack/test/importMeta`
15+
6. Search for remaining direct core or adapter imports. Remove `@rstest/core` and adapter dependencies only when no direct use remains.
16+
7. Delete `rstest.config.*` after all behavior is represented or intentionally supplied by automatic app/library extension.
17+
18+
## Config Pattern
19+
20+
```ts
21+
import { define } from 'rstack';
22+
23+
define.test({
24+
setupFiles: ['./tests/setup.ts'],
25+
testEnvironment: 'happy-dom',
26+
});
27+
```
28+
29+
## Validate
30+
31+
Run the migrated test script.

0 commit comments

Comments
 (0)