From 0a33b2c11102873970421816c08003125a6bce99 Mon Sep 17 00:00:00 2001 From: Pedro Cattori Date: Wed, 30 Aug 2023 13:42:23 -0400 Subject: [PATCH] write build version to `version.txt` alongside the server build (#7299) --- .changeset/pretty-ears-vanish.md | 5 +++++ packages/remix-dev/compiler/compiler.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .changeset/pretty-ears-vanish.md diff --git a/.changeset/pretty-ears-vanish.md b/.changeset/pretty-ears-vanish.md new file mode 100644 index 00000000000..0d332cd0e02 --- /dev/null +++ b/.changeset/pretty-ears-vanish.md @@ -0,0 +1,5 @@ +--- +"@remix-run/dev": patch +--- + +internal: write a version.txt sentinel file _after_ server build is completely written diff --git a/packages/remix-dev/compiler/compiler.ts b/packages/remix-dev/compiler/compiler.ts index 8859d27183b..4a0f7eea7a1 100644 --- a/packages/remix-dev/compiler/compiler.ts +++ b/packages/remix-dev/compiler/compiler.ts @@ -1,3 +1,4 @@ +import * as fs from "node:fs"; import * as path from "node:path"; import type { Context } from "./context"; @@ -119,7 +120,16 @@ export let create = async (ctx: Context): Promise => { let server = await tasks.server; if (!server.ok) throw error ?? server.error; // artifacts/server - writes.server = Server.write(ctx.config, server.value); + writes.server = Server.write(ctx.config, server.value).then(() => { + // write the version to a sentinel file _after_ the server has been written + // this allows the app server to watch for changes to `version.txt` + // avoiding race conditions when the app server would attempt to reload a partially written server build + let versionTxt = path.join( + path.dirname(ctx.config.serverBuildPath), + "version.txt" + ); + fs.writeFileSync(versionTxt, manifest.version); + }); await Promise.all(Object.values(writes)); return manifest;