Restart thread pool when Elm code changes to clear import cache.

This commit is contained in:
Dillon Kearns 2023-01-22 13:51:20 -08:00
parent 3622c715ad
commit 2ecbc16eb9
2 changed files with 12 additions and 5 deletions

View File

@ -40,6 +40,17 @@ const __dirname = path.dirname(__filename);
export async function start(options) { export async function start(options) {
let threadReadyQueue = []; let threadReadyQueue = [];
let pool = []; let pool = [];
function restartPool() {
pool.forEach((thread) => thread.worker.terminate());
const poolSize = Math.max(1, cpuCount / 2 - 1);
pool = [];
for (let index = 0; index < poolSize; index++) {
pool.push(initWorker(options.base));
}
}
ensureDirSync(path.join(process.cwd(), ".elm-pages", "http-response-cache")); ensureDirSync(path.join(process.cwd(), ".elm-pages", "http-response-cache"));
const cpuCount = os.cpus().length; const cpuCount = os.cpus().length;
@ -252,6 +263,7 @@ export async function start(options) {
} }
} }
elmMakeRunning = true; elmMakeRunning = true;
restartPool();
if (codegenError) { if (codegenError) {
const errorJson = JSON.stringify({ const errorJson = JSON.stringify({
type: "compile-errors", type: "compile-errors",

View File

@ -43,11 +43,6 @@ async function run({ mode, pathname, serverRequest, portsFilePath }) {
async function requireElm(mode) { async function requireElm(mode) {
let elmImportPath = compiledElmPath; let elmImportPath = compiledElmPath;
if (mode !== "build") {
const { mtimeMs } = await stat(compiledElmPath);
console.log({ mtimeMs });
elmImportPath = `${compiledElmPath}?time=${mtimeMs}`;
}
const warnOriginal = console.warn; const warnOriginal = console.warn;
console.warn = function () {}; console.warn = function () {};
const Elm = (await import(elmImportPath)).default; const Elm = (await import(elmImportPath)).default;