target-run
v1.0.0
Published
OS & architecture-aware script dispatcher
Maintainers
Readme
target-run
Platform-aware script runner for Node.js projects.
pnpm add -D target-runSet 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 name[^1] |
| --cwd <path> | Set the working directory for package.json lookup |
[^1]: Useful when invoking target-run outside of an npm lifecycle, e.g. target-run --script build in a shell script or CI step where npm_lifecycle_event is not set.
