diff --git a/packages/remix-dev/compiler/compiler.ts b/packages/remix-dev/compiler/compiler.ts index d3c504dff1c..4a1f6016960 100644 --- a/packages/remix-dev/compiler/compiler.ts +++ b/packages/remix-dev/compiler/compiler.ts @@ -25,8 +25,6 @@ export let create = async (ctx: Context): Promise => { manifest: undefined as unknown as Channel.Type, }; - console.log(ctx.options); - let subcompiler = { css: await CSS.createCompiler(ctx), js: await JS.createCompiler(ctx, channels), diff --git a/packages/remix-dev/devServer_unstable/index.ts b/packages/remix-dev/devServer_unstable/index.ts index 552bc60cbe0..c488b8a59a4 100644 --- a/packages/remix-dev/devServer_unstable/index.ts +++ b/packages/remix-dev/devServer_unstable/index.ts @@ -34,9 +34,6 @@ export let serve = async ( } = {}; let startAppServer = (command: string) => { - console.log({ - cwd: process.cwd(), - }); return execa.command(command, { stdio: "inherit", env: { @@ -61,7 +58,7 @@ export let serve = async ( onInitialBuild: (durationMs, manifest) => { console.info(`💿 Built in ${prettyMs(durationMs)}`); state.prevManifest = manifest; - if (options.command) { + if (options.command && manifest) { console.log(`starting: ${options.command}`); state.appServer = startAppServer(options.command); } @@ -74,10 +71,11 @@ export let serve = async ( if (!manifest) return; websocket.log(`Rebuilt in ${prettyMs(durationMs)}`); + // TODO: should we restart the app server when build failed? state.latestBuildHash = manifest.version; state.buildHashChannel = Channel.create(); console.log(`Waiting (${state.latestBuildHash})`); - if (options.restart) { + if (state.appServer === undefined || options.restart) { console.log(`restarting: ${options.command}`); state.appServer?.kill(); if (options.command) { diff --git a/packages/remix-dev/devServer_unstable/ping.ts b/packages/remix-dev/devServer_unstable/ping.ts new file mode 100644 index 00000000000..052f9e61d11 --- /dev/null +++ b/packages/remix-dev/devServer_unstable/ping.ts @@ -0,0 +1,16 @@ +import type { ServerBuild } from "@remix-run/server-runtime"; + +export let ping = (build: ServerBuild) => { + let httpPort = Number(process.env.REMIX_DEV_HTTP_PORT); + if (!httpPort) throw Error("REMIX_DEV_HTTP_PORT not set"); + if (isNaN(httpPort)) + throw Error(`REMIX_DEV_HTTP_PORT must be a number. Got: ${httpPort}`); + + fetch(`http://localhost:${httpPort}/ping`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ buildHash: build.assets.version }), + }); +}; diff --git a/packages/remix-dev/index.ts b/packages/remix-dev/index.ts index 70796298feb..28e02a58a8e 100644 --- a/packages/remix-dev/index.ts +++ b/packages/remix-dev/index.ts @@ -7,3 +7,5 @@ export { createApp } from "./cli/create"; export { type Manifest as AssetsManifest } from "./manifest"; export { getDependenciesToBundle } from "./dependencies"; + +export { ping } from "./devServer_unstable/ping";