Skip to content

Commit

Permalink
fix race condition in initialization file on latest node (#4942)
Browse files Browse the repository at this point in the history
  • Loading branch information
rochdev authored Nov 26, 2024
1 parent 7f292a0 commit 66f115c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions initialize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import { isMainThread } from 'worker_threads'

import * as Module from 'node:module'
import { fileURLToPath } from 'node:url'
import {
load as origLoad,
Expand Down Expand Up @@ -49,12 +50,9 @@ export async function getSource (...args) {
}

if (isMainThread) {
// Need this IIFE for versions of Node.js without top-level await.
(async () => {
await import('./init.js')
const { register } = await import('node:module')
if (register) {
register('./loader-hook.mjs', import.meta.url)
}
})()
const require = Module.createRequire(import.meta.url)
require('./init.js')
if (Module.register) {
Module.register('./loader-hook.mjs', import.meta.url)
}
}

0 comments on commit 66f115c

Please sign in to comment.