Skip to Content
ScriptingScript Overrides

Script Overrides

Scripts in your scripts folder or package.json can override built-in Miso commands. This powerful feature lets you customize behavior for commands like install, add, remove, dev, init, or version.

How It Works

When you run a command, Miso checks in this order:

  1. Scripts folder - If a matching script exists, it runs instead of the built-in command
  2. Package.json scripts - If no scripts folder match, package.json is checked
  3. Built-in command - If no script override exists, the built-in command runs

This means your custom scripts always take precedence over built-in functionality.

Common Use Cases

Custom Install Process

Create scripts/install.sh to run custom logic before or after installing dependencies:

#!/bin/sh echo "Running pre-install checks..." # Check Node version NODE_VERSION=$(node -v) echo "Node version: $NODE_VERSION" # Install dependencies pnpm install # Run post-install setup echo "Running post-install setup..." ./scripts/setup.sh # Generate types echo "Generating types..." pnpm run codegen echo "Installation complete!"

Now miso install runs your custom script instead of the built-in install command.

Custom Dev Command

Override the dev command with additional setup or parallel processes:

#!/bin/sh # scripts/dev.sh # Start multiple services in parallel concurrently \ "pnpm --filter web dev" \ "pnpm --filter api dev" \ "pnpm run watch:types"

Or use package.json:

{ "scripts": { "dev": "concurrently 'vite' 'tsc --watch'" } }

Now miso dev runs your custom development setup.

Environment-Aware Build

Create a build script that handles different environments:

#!/bin/sh # scripts/build.sh ENV=${1:-production} echo "Building for $ENV environment..." if [ "$ENV" = "production" ]; then NODE_ENV=production pnpm run build echo "Running production optimizations..." pnpm run optimize elif [ "$ENV" = "staging" ]; then NODE_ENV=staging pnpm run build else echo "Unknown environment: $ENV" exit 1 fi echo "Build complete!"

Usage:

miso build # defaults to production miso build staging # builds for staging

Custom Version Command

Override the version command to show additional project information:

#!/bin/sh # scripts/version.sh echo "Project Information" echo "===================" echo "" echo "Miso version: $(miso --version)" echo "Node version: $(node -v)" echo "Package manager: pnpm" echo "Pnpm version: $(pnpm -v)" echo "" echo "Project version: $(jq -r .version package.json)" echo "Project name: $(jq -r .name package.json)"

Enhanced Add Command

Create a wrapper around add that updates related configuration:

#!/bin/sh # scripts/add.sh # Add the package using built-in functionality # Note: Call the package manager directly since we're overriding 'add' pnpm add "$@" # Update related files if echo "$@" | grep -q "@types"; then echo "Type definitions added. Rebuilding types..." pnpm run types fi # Update documentation echo "Updating dependency documentation..." ./scripts/update-deps-docs.sh

Accessing Built-in Functionality

When you override a command, you lose direct access to the built-in functionality. To work around this:

Call the Package Manager Directly

#!/bin/sh # scripts/install.sh # Do pre-install work echo "Pre-install checks..." # Call package manager directly pnpm install "$@" # Do post-install work echo "Post-install setup..."

Create Helper Scripts

Keep the built-in functionality accessible via a different name:

scripts/ install.sh # Your custom install _builtin/ install.sh # Calls package manager

Best Practices

1. Document Your Overrides

Always add comments explaining what the override does and why:

#!/bin/sh # Custom install script for MyProject # Overrides: miso install # # This script adds: # - Node version checking # - Post-install code generation # - Dependency documentation updates

2. Preserve Original Behavior

Make sure your override still does what the built-in command would do:

#!/bin/sh # scripts/add.sh # Call the package manager to add dependencies (preserve original behavior) pnpm add "$@" # Add custom behavior ./scripts/custom-setup.sh

3. Handle Arguments

Pass through arguments to maintain flexibility:

#!/bin/sh # scripts/dev.sh # Pass all arguments to the underlying command pnpm dev "$@"

4. Provide Helpful Output

Give users clear feedback about what’s happening:

#!/bin/sh # scripts/install.sh echo "🔍 Running pre-install checks..." # ... checks ... echo "📦 Installing dependencies..." pnpm install echo "🔧 Running post-install setup..." # ... setup ... echo "✅ Installation complete!"

5. Exit on Errors

Use proper error handling to fail fast:

#!/bin/sh set -e # Exit on any error # Your script here

Removing Overrides

To restore built-in functionality, simply remove or rename the overriding script:

# Remove the override rm scripts/install.sh # Or rename it mv scripts/install.sh scripts/custom-install.sh

After removing the override, miso install will use the built-in command again.

Viewing Active Overrides

Use miso scripts to see which commands are overridden:

miso scripts

This lists all available scripts and their sources, making it easy to identify overrides.

Last updated on