From d63ce72018197268e707787f0c70c22ceab8bc57 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 23 Mar 2021 22:28:00 -0700 Subject: [PATCH] Use __dirname to resolve path. --- examples/docs/functions/render/index.js | 7 +++++-- generator/src/render.js | 12 +++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/docs/functions/render/index.js b/examples/docs/functions/render/index.js index 38c081ad..4294af8d 100644 --- a/examples/docs/functions/render/index.js +++ b/examples/docs/functions/render/index.js @@ -1,13 +1,16 @@ -// const path = require("path"); +const path = require("path"); exports.handler = async function (event, context) { console.log(JSON.stringify(event)); // process.chdir(path.join(__dirname, "../../")); // process.chdir("../"); + + // const compiledElmPath = path.join(process.cwd(), "elm-pages-cli.js"); + const compiledElmPath = path.join(__dirname, "elm-pages-cli.js"); const renderer = require("../../../../generator/src/render"); console.log("pwd", process.cwd()); return { - body: (await renderer()).htmlString, + body: (await renderer(compiledElmPath)).htmlString, statusCode: 200, }; }; diff --git a/generator/src/render.js b/generator/src/render.js index 6025e4f7..cb00c306 100755 --- a/generator/src/render.js +++ b/generator/src/render.js @@ -15,14 +15,17 @@ process.on("unhandledRejection", (error) => { process.exit(1); }); -module.exports = async function run() { +module.exports = async function run(/** @type {string} */ compiledElmPath) { XMLHttpRequest = require("xhr2"); console.log("RENDER NEW"); - const result = await runElmApp(); + const result = await runElmApp(compiledElmPath); return result; }; -function runElmApp() { +/** + * @param {string} compiledElmPath + */ +function runElmApp(compiledElmPath) { process.on("beforeExit", (code) => { if (foundErrors) { process.exit(1); @@ -32,10 +35,9 @@ function runElmApp() { }); return new Promise((resolve, _) => { - const ELM_FILE_PATH = path.join(process.cwd(), "elm-pages-cli.js"); const mode /** @type { "dev" | "prod" } */ = "elm-to-html-beta"; const staticHttpCache = {}; - const app = require(ELM_FILE_PATH).Elm.Main.init({ + const app = require(compiledElmPath).Elm.Main.init({ flags: { secrets: process.env, mode, staticHttpCache }, });