From 57939f3bcb1a3d5356d4c03a9ec0f47a23e230a0 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 11 Jul 2026 09:38:52 +0800 Subject: [PATCH] feat: support function-based staged config --- .../references/lint-staged.mdx | 2 +- packages/rstack/src/config.ts | 5 +---- packages/rstack/src/staged.ts | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.agents/skills/migrate-to-rstack-cli/references/lint-staged.mdx b/.agents/skills/migrate-to-rstack-cli/references/lint-staged.mdx index b347270..2088007 100644 --- a/.agents/skills/migrate-to-rstack-cli/references/lint-staged.mdx +++ b/.agents/skills/migrate-to-rstack-cli/references/lint-staged.mdx @@ -5,7 +5,7 @@ Read this reference when the project uses the `lint-staged` binary, a lint-stage ## Steps 1. Replace direct `lint-staged` script invocations with `rs staged`. -2. Move a plain task map into `define.staged` in `rstack.config.*`. +2. Move the lint-staged config into `define.staged` in `rstack.config.*`. 3. Remove the old manifest key or config file. 4. Remove the direct `lint-staged` dependency only when no script, config, or programmatic API still uses it. diff --git a/packages/rstack/src/config.ts b/packages/rstack/src/config.ts index 1a57dc8..56c7507 100644 --- a/packages/rstack/src/config.ts +++ b/packages/rstack/src/config.ts @@ -4,10 +4,7 @@ import type { RslibConfigDefinition } from '@rslib/core'; import type { RslintConfig } from '@rslint/core'; import type { UserConfig, UserConfigAsyncFn } from '@rspress/core'; import type { RstestConfigExport } from '@rstest/core'; - -export type StagedTask = string | string[]; - -export type StagedConfig = Record; +import type { StagedConfig } from './staged.js'; export type RslintConfigDefinition = RslintConfig | (() => Promise); export type RspressConfigDefinition = UserConfig | UserConfigAsyncFn; diff --git a/packages/rstack/src/staged.ts b/packages/rstack/src/staged.ts index ee47c5b..c45513a 100644 --- a/packages/rstack/src/staged.ts +++ b/packages/rstack/src/staged.ts @@ -2,6 +2,27 @@ import { parseArgs } from 'node:util'; import { color } from 'rslog'; import { loadRstackConfig } from './config.js'; +export type StagedSyncTaskGenerator = (stagedFileNames: readonly string[]) => string | string[]; + +export type StagedAsyncTaskGenerator = ( + stagedFileNames: readonly string[], +) => Promise; + +export type StagedTaskGenerator = StagedSyncTaskGenerator | StagedAsyncTaskGenerator; + +export type StagedFunctionTask = { + title: string; + task: (stagedFileNames: readonly string[]) => void | Promise; +}; + +export type StagedTask = + | string + | StagedFunctionTask + | StagedTaskGenerator + | (string | StagedTaskGenerator)[]; + +export type StagedConfig = Record | StagedTaskGenerator; + const stagedHelpMessage = `Rstack v${RSTACK_VERSION} ${color.cyan('Usage')}: