|
1 |
| -import fs from 'node:fs/promises' |
| 1 | +import fs from 'node:fs' |
2 | 2 | import module from 'node:module'
|
3 | 3 | import process from 'process'
|
4 | 4 | import esmockErr from './esmockErr.js'
|
@@ -33,6 +33,10 @@ const moduleIdReCreate = (moduleid, treeid) => new RegExp(
|
33 | 33 | const mockKeys = global.mockKeys = (global.mockKeys || {})
|
34 | 34 | const mockKeysSource = global.mockKeysSource = (global.mockKeysSource || {})
|
35 | 35 |
|
| 36 | +// use fs when logging from hooks, console.log async unpredictable |
| 37 | +const log = (...args) => ( |
| 38 | + fs.writeSync(1, JSON.stringify(args, null, ' ').slice(2, -1))) |
| 39 | + |
36 | 40 | // node v20.0-v20.6
|
37 | 41 | const globalPreload = !module.register && (({ port }) => (
|
38 | 42 | port.addEventListener('message', ev => (
|
@@ -170,7 +174,7 @@ const load = async (url, context, nextLoad) => {
|
170 | 174 | const sourceIsNullLike = (
|
171 | 175 | nextLoadRes.source === null || nextLoadRes.source === undefined)
|
172 | 176 | const source = sourceIsNullLike
|
173 |
| - ? String(await fs.readFile(new URL(url))) |
| 177 | + ? String(fs.readFileSync(new URL(url))) |
174 | 178 | : String(nextLoadRes.source)
|
175 | 179 | const hbang = (source.match(hashbangRe) || [])[0] || ''
|
176 | 180 | const sourcesafe = hbang ? source.replace(hashbangRe, '') : source
|
|
0 commit comments