Skip to main content
The run command executes scripts defined in your package.json or runs binaries from node_modules/.bin.

Usage

refine run [command] [args...]

Arguments

command
string
The script name from package.json or a binary from node_modules/.bin. If omitted, lists all available scripts.
args...
string[]
Additional arguments passed to the command
refine run test --watch

How It Works

The run command:
  1. Checks if a command is provided
  2. If no command: Lists all available scripts from package.json
  3. If command exists in package.json: Runs it with your package manager
  4. If command not in package.json: Looks for the binary in node_modules/.bin and runs it directly

Examples

List Available Scripts

Run without arguments to see all available scripts:
refine run
Output
Available via `refine run`:

  dev
    refine dev

  build
    refine build

  start
    refine start

  test
    vitest run

  lint
    eslint src/

  format
    prettier --write "src/**/*.{ts,tsx}"

Run Package Scripts

Execute scripts defined in package.json:
refine run test
refine run lint
refine run format

Run with Arguments

Pass additional arguments to the script:
refine run test --watch
refine run lint --fix
refine run build --mode production

Run Node Modules Binaries

Run binaries directly from node_modules/.bin:
refine run tsc --noEmit
refine run prettier --check "src/**/*.tsx"
refine run eslint src/ --ext .ts,.tsx

Common Scripts

Testing

Run your test suite:
refine run test
Run tests in watch mode:
refine run test --watch
Run tests with coverage:
refine run test:coverage

Linting

Check for linting errors:
refine run lint
Fix linting errors automatically:
refine run lint --fix

Formatting

Format code with Prettier:
refine run format
Check formatting without making changes:
refine run format:check

Type Checking

Run TypeScript type checking:
refine run type-check
refine run tsc --noEmit

Package Manager Detection

The run command automatically detects your package manager:
  • npm - Runs npm run [script]
  • yarn - Runs yarn [script]
  • pnpm - Runs pnpm run [script]
This ensures compatibility with your project’s package manager.

Package.json Configuration

Define custom scripts in your package.json:
package.json
{
  "scripts": {
    "dev": "refine dev",
    "build": "refine build",
    "start": "refine start",
    "test": "vitest run",
    "test:watch": "vitest",
    "test:coverage": "vitest run --coverage",
    "lint": "eslint src/",
    "lint:fix": "eslint src/ --fix",
    "format": "prettier --write \"src/**/*.{ts,tsx}\"",
    "format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
    "type-check": "tsc --noEmit"
  }
}

Advanced Usage

Chaining Commands

Run multiple commands sequentially:
package.json
{
  "scripts": {
    "validate": "npm run type-check && npm run lint && npm run test"
  }
}
refine run validate

Pre and Post Scripts

npm automatically runs pre and post scripts:
package.json
{
  "scripts": {
    "prebuild": "npm run lint",
    "build": "refine build",
    "postbuild": "npm run analyze"
  }
}

Environment-Specific Scripts

package.json
{
  "scripts": {
    "build:dev": "NODE_ENV=development refine build",
    "build:staging": "NODE_ENV=staging refine build",
    "build:prod": "NODE_ENV=production refine build"
  }
}

Comparison with Package Managers

Direct Package Manager Usage

npm run test

Using Refine CLI

refine run test
Benefits:
  • Package manager agnostic
  • Consistent command across projects
  • Can run binaries directly from node_modules/.bin

Common Use Cases

CI/CD Pipeline

.github/workflows/test.yml
name: Test

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
      - run: npm ci
      - run: npx refine run lint
      - run: npx refine run type-check
      - run: npx refine run test

Pre-commit Hook

package.json
{
  "husky": {
    "hooks": {
      "pre-commit": "refine run lint:fix && refine run format"
    }
  }
}

Development Workflow

# Check code quality before committing
refine run lint
refine run type-check
refine run test

Troubleshooting

Script Not Found

If a script isn’t found:
  1. Check your package.json for the script name
  2. Verify the script is spelled correctly
  3. For binaries, ensure the package is installed

Permission Errors

On Unix systems, you may need to make scripts executable:
chmod +x node_modules/.bin/[binary]

Arguments Not Passed Correctly

Ensure arguments come after the command:
# Correct
refine run test --watch

# Incorrect
refine run --watch test

Next Steps

Build docs developers (and LLMs) love