feat(core): Add cwd option and child-process execution for custom working directory; implement signal-forwarding child runner; update docs and bump package version to 1.4.0

This commit is contained in:
2025-10-16 20:49:03 +00:00
parent e9ae00f5e9
commit 7fb2389e3a
5 changed files with 114 additions and 5 deletions

View File

@@ -67,6 +67,8 @@ await runCli('./myScript.ts');
🎯 **TypeScript Native** - Full TypeScript support with excellent IntelliSense.
🔀 **Custom Working Directory** - Execute scripts with different cwds for parallel multi-project workflows.
## Why tsrun?
Sometimes you just want to run a TypeScript file without setting up a build pipeline, configuring webpack, or waiting for `tsc` to compile. That's where tsrun shines:
@@ -141,6 +143,35 @@ for (const script of scripts) {
}
```
### Running with Custom Working Directory
Execute TypeScript files with a different working directory using the `cwd` option. This is especially useful for parallel execution across multiple projects:
```typescript
import { runPath } from '@git.zone/tsrun';
// Run with custom cwd
await runPath('./build.ts', undefined, { cwd: '/path/to/project-a' });
// Parallel execution with different cwds (safe and isolated)
await Promise.all([
runPath('./deploy.ts', undefined, { cwd: '/projects/frontend' }),
runPath('./deploy.ts', undefined, { cwd: '/projects/backend' }),
runPath('./deploy.ts', undefined, { cwd: '/projects/api' })
]);
```
**How it works:**
- When `cwd` is provided, the script executes in a **child process** for complete isolation
- Without `cwd`, execution happens **in-process** (faster, less overhead)
- Child processes inherit all environment variables and stdio connections
- Perfect for running the same script across multiple project directories
**Notes:**
- Output from parallel executions may interleave on the console
- Each child process runs with its own isolated working directory
- Exit codes and signals are properly forwarded
## Package Information
- **npmjs**: [@git.zone/tsrun](https://www.npmjs.com/package/@git.zone/tsrun)