Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/rstack/src/staged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Runs lint-staged with tasks from define.staged in rstack.config.
Options:
--allow-empty Allow empty commits when tasks revert all staged changes
-p, --concurrent <number|boolean> The number of tasks to run concurrently, or false for serial
--cwd <path> Working directory to run all tasks in
--no-stash Disable the backup stash. Implies "--no-revert".
-q, --quiet Disable lint-staged's own console output
-r, --relative Pass relative filepaths to tasks
Expand All @@ -24,6 +25,7 @@ export async function runStagedCLI(args: string[]): Promise<void> {
'allow-empty': { type: 'boolean' },
allowEmpty: { type: 'boolean' },
concurrent: { type: 'string', short: 'p' },
cwd: { type: 'string' },
help: { type: 'boolean', short: 'h' },
'no-stash': { type: 'boolean' },
quiet: { type: 'boolean', short: 'q' },
Expand Down Expand Up @@ -55,6 +57,7 @@ export async function runStagedCLI(args: string[]): Promise<void> {
allowEmpty: values['allow-empty'] ?? values.allowEmpty ?? false,
concurrent: values.concurrent === undefined ? true : JSON.parse(values.concurrent),
config: stagedConfig,
cwd: values.cwd,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve staged config from the requested cwd

cwd is only passed to lint-staged after loadRstackConfig() has already discovered rstack.config.* from the original process directory (see packages/rstack/src/config.ts:110-121). For rs staged --cwd packages/app where packages/app/rstack.config.ts defines define.staged, this still throws No define.staged config found or uses a parent config unless the user also supplies --config, even though lint-staged documents --cwd as running tasks in a specific directory. Please resolve config discovery relative to values.cwd when no explicit --config is set, or make the required --config coupling explicit.

Useful? React with 👍 / 👎.

quiet: values.quiet ?? false,
relative: values.relative ?? false,
stash: !values['no-stash'],
Expand Down
12 changes: 12 additions & 0 deletions packages/rstack/test/cli/staged/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ test('should display the staged help message', ({ execCli, expect }) => {
expect(output).toContain('Usage:\n $ rs staged [options]');
expect(output).toContain('Runs lint-staged with tasks from define.staged in rstack.config.');
expect(output).toContain('--allow-empty');
expect(output).toContain('--cwd <path>');
expect(output).toContain('--no-stash');
expect(output).toContain('-q, --quiet');
expect(output).toContain('-r, --relative');
Expand Down Expand Up @@ -133,3 +134,14 @@ for (const option of ['--relative', '-r']) {
});
});
}

test('should run staged tasks in the specified cwd', async ({ execCli, expect }) => {
await withGitFixture((cwd) => {
const configPath = path.join(cwd, 'rstack.config.ts');
const output = execCli(
`--config ${JSON.stringify(configPath)} staged --allow-empty --cwd ${JSON.stringify(cwd)} --relative --verbose`,
{ cwd: path.dirname(cwd) },
);
expect(output).toContain('staged file: file.txt');
});
});