Write compiled Elm CLI output with .cjs extension to make it compatible with "type": "module" in package.json file.

This commit is contained in:
Dillon Kearns 2023-01-23 16:03:52 -08:00
parent e835b494c9
commit 645dd4e5dd
2 changed files with 5 additions and 2 deletions

View File

@ -83,7 +83,7 @@ function _HtmlAsJson_toJson(html) {
`;
await fsPromises.writeFile(
readFrom,
readFrom.replace(/\.js$/, ".cjs"),
elmFileContent
.replace(
/return \$elm\$json\$Json\$Encode\$string\(.REPLACE_ME_WITH_JSON_STRINGIFY.\)/g,

View File

@ -4,7 +4,6 @@ import * as fs from "./dir-helpers.js";
import { readFileSync, writeFileSync } from "fs";
import { stat } from "fs/promises";
import { parentPort, threadId, workerData } from "worker_threads";
const compiledElmPath = path.join(process.cwd(), "elm-stuff/elm-pages/elm.js");
async function run({ mode, pathname, serverRequest, portsFilePath }) {
console.time(`${threadId} ${pathname}`);
@ -42,6 +41,10 @@ async function run({ mode, pathname, serverRequest, portsFilePath }) {
}
async function requireElm(mode) {
const compiledElmPath = path.join(
process.cwd(),
"elm-stuff/elm-pages/elm.cjs"
);
let elmImportPath = compiledElmPath;
const warnOriginal = console.warn;
console.warn = function () {};