all repos — pirc-extension @ 0213d9d083ff5af4f9e64dca61d3311fbdcb16e8

PiRC's pi extension: releases of the pi package (source in PiRC)

loader.js (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
// The published extension's entry point. pi's /reload imports the
// extension again, but Node keeps every JavaScript module it has imported,
// so a bundle updated in place would not run until pi restarted. This file
// imports the bundle beside it by a URL that changes when the file does,
// so a reload after an update runs the new code, and is the same in every
// version, so that its own copy, which Node keeps, is never stale. Not
// index.js: versions before it had their bundle there, which Node would
// still hold after updating from one of them.
import { statSync } from "node:fs";

export default async function (pi) {
  const bundle = new URL("./pirc.js", import.meta.url);
  const { default: factory } = await import(`${bundle.href}?t=${statSync(bundle).mtimeMs}`);
  return factory(pi);
}