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

Function defaultLoadImpl

lib/internal/modules/cjs/loader.js:1237–1255  ·  view source on GitHub ↗

* Load the source code of a module based on format. * @param {string} filename Filename of the module. * @param {string|undefined|null} format Format of the module. * @returns {string|null}

(filename, format)

Source from the content-addressed store, hash-verified

1235 * @returns {string|null}
1236 */
1237function defaultLoadImpl(filename, format) {
1238 switch (format) {
1239 case undefined:
1240 case null:
1241 case 'module':
1242 case 'commonjs':
1243 case 'json':
1244 case 'module-typescript':
1245 case 'commonjs-typescript':
1246 case 'typescript': {
1247 return fs.readFileSync(filename, 'utf8');
1248 }
1249 case 'builtin':
1250 return null;
1251 default:
1252 // URL is not necessarily necessary/available - convert it on the spot for errors.
1253 throw new ERR_UNKNOWN_MODULE_FORMAT(format, convertCJSFilenameToURL(filename));
1254 }
1255}
1256
1257/**
1258 * Construct a last nextLoad() for load hooks invoked for the CJS loader.

Callers 2

getDefaultLoadFunction · 0.85
loadSourceFunction · 0.85

Calls 2

convertCJSFilenameToURLFunction · 0.85
readFileSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…