Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build:app": "vite build",
"dev": "node scripts/dev-server.mjs",
"start": "node dist/cli.js serve",
"test": "tsx src/config.test.ts && tsx src/roots.test.ts && tsx src/skills.test.ts && tsx src/workspaces.test.ts && tsx src/review-checkpoints.test.ts",
"test": "node scripts/dev-server.test.mjs && tsx src/config.test.ts && tsx src/roots.test.ts && tsx src/skills.test.ts && tsx src/workspaces.test.ts && tsx src/review-checkpoints.test.ts",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"keywords": [],
Expand Down
36 changes: 27 additions & 9 deletions scripts/dev-server.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { spawn } from "node:child_process";
import { createRequire } from "node:module";
import { readdirSync, statSync, watch } from "node:fs";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

const repoRoot = resolve(fileURLToPath(new URL("..", import.meta.url)));
const scriptPath = fileURLToPath(import.meta.url);
export const repoRoot = resolve(fileURLToPath(new URL("..", import.meta.url)));
const require = createRequire(import.meta.url);
const tsxCliPath = require.resolve("tsx/cli");
const watchRoots = ["src"].map((entry) => join(repoRoot, entry));
const restartDelayMs = 750;
const crashDelayMs = 1500;
Expand All @@ -17,9 +21,17 @@ function log(message) {
console.error(`[devspace:dev] ${message}`);
}

export function createServerCommand() {
return {
command: process.execPath,
args: [tsxCliPath, "src/cli.ts", "serve"],
};
}

function start() {
stoppingForRestart = false;
child = spawn("npx", ["tsx", "src/cli.ts", "serve"], {
const { command, args } = createServerCommand();
child = spawn(command, args, {
cwd: repoRoot,
env: process.env,
stdio: "inherit",
Expand Down Expand Up @@ -108,13 +120,19 @@ function shutdown() {
setTimeout(() => process.exit(1), 3000).unref();
}

for (const signal of ["SIGINT", "SIGTERM"]) {
process.on(signal, shutdown);
}
function main() {
for (const signal of ["SIGINT", "SIGTERM"]) {
process.on(signal, shutdown);
}

for (const root of watchRoots) {
watchDirectory(root);
for (const root of watchRoots) {
watchDirectory(root);
}

log("watching src; server restarts on changes and after crashes");
start();
}

log("watching src; server restarts on changes and after crashes");
start();
if (resolve(process.argv[1] ?? "") === scriptPath) {
main();
}
10 changes: 10 additions & 0 deletions scripts/dev-server.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import assert from "node:assert/strict";
import { createRequire } from "node:module";
import { createServerCommand } from "./dev-server.mjs";

const require = createRequire(import.meta.url);

assert.deepEqual(createServerCommand(), {
command: process.execPath,
args: [require.resolve("tsx/cli"), "src/cli.ts", "serve"],
});