Script Execution
This page covers how Miso executes scripts, including interpreter detection and argument passing.
Shebang Detection
Miso reads the first line of each script to detect shebangs (the #! directive). If a shebang is present, Miso uses the specified interpreter:
#!/usr/bin/env node
// Your JavaScript code here
console.log("Running with Node.js");#!/usr/bin/env python3
# Your Python code here
print("Running with Python")The shebang takes precedence over extension-based detection, giving you full control over script execution.
Extension-Based Interpreter Selection
If no shebang is present, Miso automatically selects an interpreter based on the file extension:
| Extension | Interpreter | Notes |
|---|---|---|
.sh, .bash | sh | POSIX shell |
.zsh | zsh | Z shell |
.js, .mjs | node | Node.js |
.ts | ts-node | TypeScript (requires ts-node) |
.py | python3 | Python 3 |
.rb | ruby | Ruby |
.pl | perl | Perl |
.lua | lua | Lua |
.php | php | PHP |
Requirements
Make sure the required interpreter is installed and available in your PATH:
# Check if an interpreter is available
which node
which python3
which rubyFor TypeScript scripts, you’ll need to install ts-node:
npm install -g ts-node
# or
pnpm add -g ts-nodePassing Arguments to Scripts
Pass arguments to scripts after the script name:
miso build --production
miso deploy staging --verbose
miso test unit --watchHow Arguments Are Passed
The way arguments are passed depends on where the script is located:
Scripts Folder Scripts
Arguments are passed directly to the script:
# scripts/deploy.sh
#!/bin/sh
ENVIRONMENT=$1
FLAGS=${@:2}
echo "Deploying to $ENVIRONMENT with flags: $FLAGS"miso deploy staging --dry-run
# Output: Deploying to staging with flags: --dry-runPackage.json Scripts
Arguments are forwarded to the package manager’s run command:
{
"scripts": {
"dev": "vite"
}
}miso dev --port 3000
# Executes: pnpm run dev --port 3000Accessing Arguments in Different Languages
Shell Scripts
#!/bin/sh
# $1, $2, etc. for positional arguments
# $@ for all arguments
echo "First argument: $1"
echo "All arguments: $@"JavaScript/Node.js
#!/usr/bin/env node
// process.argv contains all arguments
const args = process.argv.slice(2);
console.log("Arguments:", args);Python
#!/usr/bin/env python3
import sys
# sys.argv[1:] contains script arguments
args = sys.argv[1:]
print(f"Arguments: {args}")TypeScript
#!/usr/bin/env ts-node
const args = process.argv.slice(2);
console.log("Arguments:", args);Error Handling
If a script exits with a non-zero status code, Miso will display the error and exit with the same code:
#!/bin/sh
if [ -z "$1" ]; then
echo "Error: Environment required"
exit 1
fiThis ensures proper error propagation in CI/CD pipelines and build tools.