-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathci-tsx.js
More file actions
48 lines (40 loc) · 1.2 KB
/
ci-tsx.js
File metadata and controls
48 lines (40 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// @ts-check
import { spawn } from 'node:child_process';
import { resolve } from 'node:path';
// Determine the workspace root (GITHUB_WORKSPACE or current working directory)
const workspaceRoot = process.env.GITHUB_WORKSPACE || process.cwd();
const tsconfigPath = resolve(workspaceRoot, 'tsconfig.base.json');
// Set up environment variables
const env = {
...process.env,
NODE_OPTIONS: '--import tsx',
TSX_TSCONFIG_PATH: tsconfigPath,
};
// Get the command and its arguments from the command line
const [command, ...args] = process.argv.slice(2);
if (!command) {
console.error('Usage: node ci-tsx.js <command> [args...]');
console.error('Example: node ci-tsx.js nx affected -t test');
process.exit(1);
}
// Log the command being executed
console.log(`> ${command} ${args.join(' ')}`);
// Spawn the command with the configured environment
const child = spawn(command, args, {
env,
stdio: 'inherit',
shell: true,
});
// Forward exit code
child.on('exit', (code, signal) => {
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(code ?? 0);
}
});
// Handle errors
child.on('error', error => {
console.error('Failed to start child process:', error);
process.exit(1);
});