turborepo/scripts/server.js
Sakina 9ed9b33b6e
fix: Validate missing <cwd-path> argument in test-codemod server script (#11166)
Adds a simple validation to scripts/test-codemod/server.js to handle the
case where the required <cwd-path> argument is missing. This prevents
unclear spawn() errors and provides a clear usage message instead.

Testing Instructions:

Run node scripts/test-codemod/server.js → should show a clear
missing-argument error.
Run with a valid path → script should behave normally.

Fixes #11165
2025-12-01 23:53:38 +00:00

48 lines
1,005 B
JavaScript
Executable file

#!/usr/bin/env node
const { spawn } = require("child_process");
const { platform } = require("process");
const path = process.argv[2];
if (!path) {
console.error("Error: Missing required argument <cwd-path>.");
console.error("Usage: node server.js <path-to-project>");
process.exit(1);
}
async function main() {
let errored = false;
await new Promise((resolve) => {
const command = platform === "win32" ? "pnpm.cmd" : "pnpm";
const server = spawn(command, ["run", "start"], { cwd: path });
server.stdout.on("data", (data) => {
console.log("stdout:");
console.log(`${data}`);
// Stable for 5s.
setTimeout(() => {
server.kill();
}, 5000);
});
server.stderr.on("data", (data) => {
console.log("stderr:");
console.log(`${data}`);
errored = true;
server.kill();
});
server.on("exit", () => {
console.log(`exit: ${+errored}`);
resolve();
});
});
process.exit(errored);
}
main();