Skip to content

Commit

Permalink
Merge pull request #1 from HAKASHUN/feature/node16
Browse files Browse the repository at this point in the history
Changed createScriptRunner.js to work with NodeJS 16
  • Loading branch information
HAKASHUN authored Nov 8, 2022
2 parents f02f9fe + 9344010 commit 56e073c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/navi-scripts/lib/createScriptRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const jsdom = require('jsdom')
* Each call to the returned runner is run in a new VM.
*/
async function createScriptRunner(config) {
const baseUrl = process.env.PUBLIC_URL || "http://localhost:8000/";
let fs = config.fs

let ext = path.extname(config.entry).slice(1)
Expand All @@ -24,9 +25,7 @@ async function createScriptRunner(config) {
}

async fetch(url, fetchOptions) {
if (process.env.PUBLIC_URL) {
url = url.replace(process.env.PUBLIC_URL, '')
}
url = url.replace(baseUrl, "");

let relativePathname = url[0] === '/' ? url.slice(1) : url
let filesystemPath = path.join(config.root, relativePathname)
Expand Down Expand Up @@ -55,6 +54,9 @@ async function createScriptRunner(config) {
virtualConsole: new jsdom.VirtualConsole().sendTo(console),
resources: new ResourceLoader(queue),
runScripts: "dangerously",
// ResourceLoader Not Fetching Relative URLs On 16.2.2 #2932
// https://github.com/jsdom/jsdom/issues/2932
url: baseUrl,
beforeParse(window) {
// Polyfill rAF for react
window.requestAnimationFrame = require('raf')
Expand All @@ -78,6 +80,10 @@ async function createScriptRunner(config) {
},
})

// Resolve queues after DOMContentLoaded has completed.
queue.push(new Promise((resolve) =>
dom.window.document.addEventListener('DOMContentLoaded', () => resolve(dom))));

while (await queue.shift()) {}

return dom
Expand Down

0 comments on commit 56e073c

Please sign in to comment.