Skip to content

fix(cli): pass through flags#7222

Open
JuicyBenjamin wants to merge 5 commits intorefinedev:mainfrom
JuicyBenjamin:fix/cli-pass-through-flags
Open

fix(cli): pass through flags#7222
JuicyBenjamin wants to merge 5 commits intorefinedev:mainfrom
JuicyBenjamin:fix/cli-pass-through-flags

Conversation

@JuicyBenjamin
Copy link
Contributor

@JuicyBenjamin JuicyBenjamin commented Jan 20, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

When users try to pass command-line flags to the underlying build tools (Vite, Next.js, Remix, etc.) using refine dev, refine start, or refine build, the flags are not passed through.

Example:

npm run dev -- --host  # Flags are ignored, --host never reaches Vite

This happens because:

  1. Commander.js with .allowUnknownOption(true) accepts the flags but doesn't capture them in the variadic [args...] parameter
  2. Users need to use the awkward npm run dev -- --host syntax (double dash)
  3. Even with double dash, the flags weren't being passed through due to missing .passThroughOptions() configuration

What is the new behavior?

Users can now pass flags directly to the underlying build tools with improved UX:

# Works cleanly (thanks to package.json scripts ending with --)
npm run dev --host
npm run dev --port 3001
npm run build --sourcemap

# Manual double dash also still works
npm run dev -- --host

Changes made:

Part 1: CLI Code (4 files)

  • Added .passThroughOptions() to dev, start, and build commands in packages/cli/src/commands/runner/{dev,start,build}/index.ts
  • Added .enablePositionalOptions() to parent command in packages/cli/src/cli.ts
  • This ensures Commander.js properly captures and passes unknown flags to the underlying tools

Part 2: Package.json Scripts (198 examples + 1 utility script)

  • Updated all example package.json files: "dev": "refine dev""dev": "refine dev --"
  • By adding -- at the end of the script, npm automatically treats everything after as arguments to pass through
  • Created scripts/update-refine-scripts.js for future maintenance

Why both changes are needed:

  1. CLI fix alone = flags pass through, but users still need npm run dev -- --host
  2. Package.json fix alone = doesn't work without the CLI fix (flags wouldn't be captured)
  3. Both together = users can simply do npm run dev --host

Notes for reviewers

Testing completed locally:

  • ✅ Manually tested with Vite project using --host flag - confirmed network exposure works
  • ✅ CLI builds successfully
  • ✅ Lint-staged checks passed

Pending CI verification:

  • All automated tests pass
  • No breaking changes detected

Security: No concerns - this only affects argument passing to already-trusted build tools (vite, next, remix) resolved from node_modules/.bin. Arguments are properly escaped by execa.

Example flags this enables:

  • Vite: --host, --port, --open, --strictPort
  • Next.js: --turbo, --port, --hostname
  • Build tools: --sourcemap, --minify, --watch

@changeset-bot
Copy link

changeset-bot bot commented Jan 20, 2026

🦋 Changeset detected

Latest commit: 985be11

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@refinedev/cli Patch
@refinedev/devtools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…uild commands)

Fixes issue where flags like --host were not being passed through to Vite, Next.js, and other build tools.

Changes:
- Added .passThroughOptions() to dev, start, and build commands
- Added .enablePositionalOptions() to parent command (required for passThroughOptions)
- Flags like --host, --port, --open now correctly passed to underlying tools

Example usage:
  npm run dev -- --host
  npm run dev -- --port 3001
  npm run build -- --sourcemap
Updates all 198 example package.json files to include -- after refine commands.
This allows users to pass flags without needing the double dash separator.

Before: npm run dev -- --host
After:  npm run dev --host

Also adds a utility script to automate these updates in the future.
@JuicyBenjamin JuicyBenjamin force-pushed the fix/cli-pass-through-flags branch from e8b52b0 to 8f65585 Compare January 20, 2026 11:48
@JuicyBenjamin JuicyBenjamin marked this pull request as ready for review January 20, 2026 12:43
@JuicyBenjamin JuicyBenjamin requested a review from a team as a code owner January 20, 2026 12:43
Copy link
Member

@alicanerdurmaz alicanerdurmaz left a comment

Choose a reason for hiding this comment

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

I believe we can remove this scripts/update-refine-scripts.js

@alicanerdurmaz
Copy link
Member

I can already pass arguments to Vite and others without .passThroughOptions(). I don't understand what does this actually do?


In Refine project:
image

image image image

In Refine monorepo:
image


@BatuhanW BatuhanW changed the title Fix/cli pass through flags fix(cli): pass through flags Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants