-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NotFound Error: Failed to spawn 'stty' during 'opengb dev' command execution #394
Labels
bug
Something isn't working
Comments
The error occurs because the 'stty' command is not available on Windows. To resolve this, add a platform check in the
import { abortable } from "./deps.ts";
import { resolve, SEP } from "../deps.ts";
import { Project } from "../project/mod.ts";
import { loadProject } from "../project/project.ts";
import { info, verbose } from "../term/status.ts";
import { InternalError } from "../error/mod.ts";
import { printError } from "../error/mod.ts";
import { colors } from "../term/deps.ts";
export interface WatchOpts {
disableWatch?: boolean;
fn: (project: Project, signal: AbortSignal) => Promise<void>;
}
export async function watch(initProject: Project, opts: WatchOpts) {
if (opts.disableWatch) {
await opts.fn(initProject, new AbortController().signal);
return;
}
let project = initProject;
let loadProjectSuccess = true;
while (true) {
if (Deno.build.os !== "windows") {
const sttyOutput = await new Deno.Command("stty", {
args: ["sane"],
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
}).output();
if (!sttyOutput.success) {
console.warn("Failed to run `stty sane`. This may cause terminal issues.");
}
}
const { columns } = Deno.consoleSize();
console.log(`\n${colors.dim("�".repeat(columns))}\n`);
let fnAbortController: AbortController | undefined;
if (loadProjectSuccess) {
fnAbortController = new AbortController();
abortable(
wrapWatchFn(project, opts, fnAbortController.signal),
fnAbortController.signal,
).catch((err) => {
if (err.name != "AbortError") throw err;
});
}
let foundEvent = false;
const watchPaths = getWatchPaths(project);
const watcher = Deno.watchFs(watchPaths);
verbose("Watching", watchPaths.join(", "));
for await (const event of watcher) {
const relevantPaths = event.paths.filter(shouldPathTriggerRebuild);
if (relevantPaths.length > 0) {
foundEvent = true;
info("Change detected", `${event.kind}: ${relevantPaths.join(", ")}`);
break;
}
}
if (!foundEvent) {
throw new InternalError("Unreachable: watchFs iterator ended");
}
try {
fnAbortController?.abort("Rebuilding project due to file change.");
} catch (err) {
if (err.name != "AbortError") throw err;
}
try {
project = await loadProject({ path: project.path });
loadProjectSuccess = true;
} catch (err) {
printError(err);
loadProjectSuccess = false;
}
}
}
async function wrapWatchFn(
project: Project,
opts: WatchOpts,
signal: AbortSignal,
) {
try {
await opts.fn(project, signal);
} catch (err) {
printError(err);
}
}
function getWatchPaths(project: Project) {
const paths: string[] = [
resolve(project.path, "backend.json"),
];
for (const module of project.modules.values()) {
if (
!("local" in module.registry.config) ||
module.registry.config.local.isExternal
) continue;
paths.push(module.path);
}
return paths;
}
function shouldPathTriggerRebuild(path: string) {
const pathSplit = path.split(SEP);
if (pathSplit.includes(".opengb") || pathSplit.includes("module.gen.ts")) return false;
const dbIdx = pathSplit.indexOf("db");
if (dbIdx != -1 && pathSplit[dbIdx + 1] == "migrations") return false;
return true;
} References/src/cli/commands/dev.ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Encountered a
NotFound: Failed to spawn 'stty': program not found
error when running theopengb dev
command. Below are the details of my setup and steps taken:Steps to Reproduce:
opengb init
.friends
module.opengb dev
.Error Trace:
Expected Behavior:
The
opengb dev
command should execute without errors.Thank you!
The text was updated successfully, but these errors were encountered: