|
| 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 | +``` |
0 commit comments