MCPcopy Index your code
hub / github.com/nodejs/node / getSourceSync

Function getSourceSync

lib/internal/modules/esm/load.js:32–53  ·  view source on GitHub ↗

* @param {URL} url URL to the module * @param {LoadContext} context used to decorate error messages * @returns {{ responseURL: string, source: string | BufferView }}

(url, context)

Source from the content-addressed store, hash-verified

30 * @returns {{ responseURL: string, source: string | BufferView }}
31 */
32function 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/**

Callers 3

defaultLoadFunction · 0.85
defaultLoadSyncFunction · 0.85
createCJSModuleWrapFunction · 0.85

Calls 2

dataURLProcessorFunction · 0.50
readFileSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…