Platform-aware script runner for Node.js projects.
Set a script body to target-run, then define platform/arch variants:
{
"scripts": {
"test": "target-run",
"test:darwin:arm64": "jest --config jest.apple-silicon.config.ts",
"test:linux:x64": "jest --config jest.linux.config.ts",
"test:default": "jest"
}
}Candidates are resolved in order:
<script>:<platform>:<arch><script>:<platform><script>:<arch><script>:default
Platform values come from os.platform() and arch from os.arch().
Example
Given this package.json on a Linux x64 machine:
{
"scripts": {
"build": "target-run",
"build:linux:x64": "node dist/index-linux-x64.js",
"build:darwin:arm64": "node dist/index-darwin-arm64.js",
"build:default": "node dist/index.js"
}
}$ pnpm build # linux/x64 → node dist/index-linux-x64.js # darwin/arm64 → node dist/index-darwin-arm64.js # win32/x64 → node dist/index.js (fallback)
CLI options
| Flag | Description |
|---|---|
--dry-run |
Print the resolved key without executing |
--verbose |
Print platform, arch, resolved key and runner |
--optional |
Exit 0 silently when no match is found |
--required |
Exit 1 when no match is found |
--script <name> |
Override the base script name1 |
--cwd <path> |
Set the working directory for package.json lookup |
-
Useful when invoking
target-runoutside of an npm lifecycle, e.g.target-run --script buildin a shell script or CI step wherenpm_lifecycle_eventis not set. ↩