Skip to content

Commit

Permalink
wip: app server pings with updated manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Apr 22, 2023
1 parent e18ac76 commit 0394264
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 0 additions & 2 deletions packages/remix-dev/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export let create = async (ctx: Context): Promise<Compiler> => {
manifest: undefined as unknown as Channel.Type<Manifest>,
};

console.log(ctx.options);

let subcompiler = {
css: await CSS.createCompiler(ctx),
js: await JS.createCompiler(ctx, channels),
Expand Down
8 changes: 3 additions & 5 deletions packages/remix-dev/devServer_unstable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ export let serve = async (
} = {};

let startAppServer = (command: string) => {
console.log({
cwd: process.cwd(),
});
return execa.command(command, {
stdio: "inherit",
env: {
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions packages/remix-dev/devServer_unstable/ping.ts
Original file line number Diff line number Diff line change
@@ -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 }),
});
};
2 changes: 2 additions & 0 deletions packages/remix-dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 0394264

Please # to comment.