Skip to content

Commit

Permalink
feat(cli): update a touchfile upon successful (re)build in watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbrey committed Oct 2, 2022
1 parent 715d6a3 commit 2df0e92
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,19 @@ export async function watch(
broadcast({ type: "LOG", message });
}

// Whenever a (re)build finishes in "watch" mode we update a "touchfile"
// which external processes can use as a signal of successful builds
// without having to watch all of the same files that remix is
// already watching - e.g. nodemon watching just this touchfile can
// know when to restart a dev server
function touch() {
fse.writeFileSync(
path.join(config.cacheDirectory, ".watch-touch"),
`last successful watch build: ${Date.now()}`,
{ encoding: "utf-8" }
);
}

let closeWatcher = await compiler.watch(config, {
mode,
onInitialBuild,
Expand All @@ -230,6 +243,7 @@ export async function watch(
onRebuildFinish() {
log(`Rebuilt in ${prettyMs(Date.now() - start)}`);
broadcast({ type: "RELOAD" });
touch();
},
onFileCreated(file) {
log(`File created: ${path.relative(process.cwd(), file)}`);
Expand All @@ -243,6 +257,7 @@ export async function watch(
});

console.log(`💿 Built in ${prettyMs(Date.now() - start)}`);
touch();

let resolve: () => void;
exitHook(() => {
Expand Down

0 comments on commit 2df0e92

Please sign in to comment.