Execute scripts defined in the scripts section of package.json.
Usage
ant run <script> [args...]
Parameters
Name of the script defined in package.json scripts section.
Arguments to pass to the script. Can be preceded by -- for clarity.
Options
Examples
List available scripts
Output:
Usage: ant run <script> [args...]
Run a script from package.json
Available scripts:
start ant index.js
dev ant --watch src/index.js
build tsc && esbuild src/index.ts --bundle
test jest
Run a script
Output:
$ tsc && esbuild src/index.ts --bundle
Built successfully!
Run with arguments
ant run test -- --coverage --verbose
Output:
$ jest --coverage --verbose
Test Suites: 3 passed, 3 total
Tests: 15 passed, 15 total
Run dev script
Output:
$ ant --watch src/index.js
Server started on port 3000
Script Definition
Define scripts in package.json:
{
"scripts": {
"start": "ant index.js",
"dev": "ant --watch src/index.js",
"build": "tsc",
"test": "jest",
"lint": "eslint src/**/*.js",
"format": "prettier --write ."
}
}
Script Environment
node_modules/.bin in PATH
Scripts automatically have access to binaries in node_modules/.bin:
{
"scripts": {
"build": "tsc", // Uses node_modules/.bin/tsc
"lint": "eslint src" // Uses node_modules/.bin/eslint
}
}
Environment Variables
Scripts have access to:
npm_package_* variables with package.json values
PATH includes node_modules/.bin
Exit Codes
The exit code from the script is propagated:
ant run test
# Exit code matches the test runner's exit code
Shorthand
You can also run scripts without the run command:
ant start
# Equivalent to: ant run start
This works when the script name doesn’t conflict with Ant commands.
Script Not Found
Output:
Error: script 'nonexistent' not found in package.json
Try 'ant run' to list available scripts.
- ant exec - Run commands from node_modules/.bin
- ant file - Run JavaScript files directly