* @param {URL} url URL to the module * @param {LoadContext} context used to decorate error messages * @returns {{ responseURL: string, source: string | BufferView }}
(url, context)
| 30 | * @returns {{ responseURL: string, source: string | BufferView }} |
| 31 | */ |
| 32 | function getSourceSync(url, context) { |
| 33 | const { protocol, href } = url; |
| 34 | const responseURL = href; |
| 35 | let source; |
| 36 | if (protocol === 'file:') { |
| 37 | // If you are reading this code to figure out how to patch Node.js module loading |
| 38 | // behavior - DO NOT depend on the patchability in new code: Node.js |
| 39 | // internals may stop going through the JavaScript fs module entirely. |
| 40 | // Prefer module.registerHooks() or other more formal fs hooks released in the future. |
| 41 | source = fs.readFileSync(url); |
| 42 | } else if (protocol === 'data:') { |
| 43 | const result = dataURLProcessor(url); |
| 44 | if (result === 'failure') { |
| 45 | throw new ERR_INVALID_URL(responseURL); |
| 46 | } |
| 47 | source = BufferFrom(result.body); |
| 48 | } else { |
| 49 | const supportedSchemes = ['file', 'data']; |
| 50 | throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(url, supportedSchemes); |
| 51 | } |
| 52 | return { __proto__: null, responseURL, source }; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /** |
no test coverage detected
searching dependent graphs…