-
-
Save isaacs/a9aacc1efeca7d565f2f7828467d9e6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('c.cjs', { | |
require, | |
__filename, | |
__dirname, | |
module, | |
isMain: require.main === module, | |
}) | |
require('./d.cjs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('d.cjs', { | |
require, | |
__filename, | |
__dirname, | |
module, | |
isMain: require.main === module, | |
}) | |
// ensure cycles are caught | |
require('./c.cjs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// does not continue with default load if return next(spec, context) | |
// require.main is not set | |
import { readFile } from 'node:fs/promises'; | |
import { fileURLToPath } from 'node:url'; | |
export const load = async (spec, context) => { | |
console.log('LOAD', spec, context); | |
const { format } = context; | |
const source = await readFile(fileURLToPath(spec), 'utf8'); | |
console.error('source=', source); | |
// this does not do the default load() apparently? | |
// return next(spec, context) | |
return { | |
format, | |
source, | |
shortCircuit: true, | |
}; | |
}; | |
export const resolve = async (spec, context, next) => { | |
console.log('RESOLVE', spec, context); | |
// this only works for the main file, not modules loaded via require() | |
return next(spec, context); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expect:
Actual: