diff --git a/dist/commands/dev/index.js b/dist/commands/dev/index.js index a10be7b..6b2aebd 100644 --- a/dist/commands/dev/index.js +++ b/dist/commands/dev/index.js @@ -2,6 +2,7 @@ import { Command } from "commander"; import path from "path"; import grabDirNames from "../../utils/grab-dir-names"; import writeErrorFile from "../../functions/write-error-file"; +import { existsSync } from "fs"; let retries = 0; let timeout; const MAX_RETRIES = 5; @@ -19,8 +20,12 @@ async function dev() { process.exit(1); } const dev_spawn_file = path.resolve(__dirname, "dev-spawn.ts"); + const dev_spawn_js_file = path.resolve(__dirname, "dev-spawn.js"); + const final_spawn_file = existsSync(dev_spawn_js_file) + ? dev_spawn_js_file + : dev_spawn_file; const spawn_options = { - cmd: ["bun", dev_spawn_file], + cmd: ["bun", final_spawn_file], stdio: ["inherit", "inherit", "inherit"], async onExit(subprocess, exitCode, signalCode, error) { writeErrorFile({ exitCode, error }); diff --git a/dist/commands/start/index.js b/dist/commands/start/index.js index fe06fbb..7abff6e 100644 --- a/dist/commands/start/index.js +++ b/dist/commands/start/index.js @@ -1,6 +1,7 @@ import { Command } from "commander"; import path from "path"; import writeErrorFile from "../../functions/write-error-file"; +import { existsSync } from "fs"; let retries = 0; let timeout; const MAX_RETRIES = 5; @@ -17,9 +18,13 @@ async function start() { console.error(`Production server crashed ${MAX_RETRIES} times. Exiting.`); process.exit(1); } - const dev_spawn_file = path.resolve(__dirname, "prod-spawn.ts"); + const prod_spawn_file = path.resolve(__dirname, "prod-spawn.ts"); + const prod_spawn_js_file = path.resolve(__dirname, "prod-spawn.js"); + const final_spawn_file = existsSync(prod_spawn_js_file) + ? prod_spawn_js_file + : prod_spawn_file; const spawn_options = { - cmd: ["bun", dev_spawn_file], + cmd: ["bun", final_spawn_file], stdio: ["inherit", "inherit", "inherit"], onExit(subprocess, exitCode, signalCode, error) { writeErrorFile({ exitCode, error }); diff --git a/package.json b/package.json index 92ae113..382522b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/bunext", - "version": "1.0.93", + "version": "1.0.94", "main": "dist/index.js", "module": "index.ts", "dependencies": { diff --git a/src/commands/dev/index.ts b/src/commands/dev/index.ts index debb0c8..ac1d2e3 100644 --- a/src/commands/dev/index.ts +++ b/src/commands/dev/index.ts @@ -3,6 +3,7 @@ import path from "path"; import type { BunSpawnOptions } from "../../types"; import grabDirNames from "../../utils/grab-dir-names"; import writeErrorFile from "../../functions/write-error-file"; +import { existsSync } from "fs"; let retries = 0; let timeout: any; @@ -25,9 +26,14 @@ async function dev() { } const dev_spawn_file = path.resolve(__dirname, "dev-spawn.ts"); + const dev_spawn_js_file = path.resolve(__dirname, "dev-spawn.js"); + + const final_spawn_file = existsSync(dev_spawn_js_file) + ? dev_spawn_js_file + : dev_spawn_file; const spawn_options: BunSpawnOptions = { - cmd: ["bun", dev_spawn_file], + cmd: ["bun", final_spawn_file], stdio: ["inherit", "inherit", "inherit"], async onExit(subprocess, exitCode, signalCode, error) { writeErrorFile({ exitCode, error }); diff --git a/src/commands/start/index.ts b/src/commands/start/index.ts index 2146287..454e01a 100644 --- a/src/commands/start/index.ts +++ b/src/commands/start/index.ts @@ -2,6 +2,7 @@ import { Command } from "commander"; import path from "path"; import type { BunSpawnOptions } from "../../types"; import writeErrorFile from "../../functions/write-error-file"; +import { existsSync } from "fs"; let retries = 0; let timeout: any; @@ -19,14 +20,21 @@ async function start() { clearTimeout(timeout); if (retries >= MAX_RETRIES) { - console.error(`Production server crashed ${MAX_RETRIES} times. Exiting.`); + console.error( + `Production server crashed ${MAX_RETRIES} times. Exiting.`, + ); process.exit(1); } - const dev_spawn_file = path.resolve(__dirname, "prod-spawn.ts"); + const prod_spawn_file = path.resolve(__dirname, "prod-spawn.ts"); + const prod_spawn_js_file = path.resolve(__dirname, "prod-spawn.js"); + + const final_spawn_file = existsSync(prod_spawn_js_file) + ? prod_spawn_js_file + : prod_spawn_file; const spawn_options: BunSpawnOptions = { - cmd: ["bun", dev_spawn_file], + cmd: ["bun", final_spawn_file], stdio: ["inherit", "inherit", "inherit"], onExit(subprocess, exitCode, signalCode, error) { writeErrorFile({ exitCode, error });