MCPcopy Create free account
hub / github.com/nodejs/node / load

Function load

test/fixtures/es-module-loaders/loader-load-commonjs-with-source.mjs:4–13  ·  view source on GitHub ↗
(url, context, nextLoad)

Source from the content-addressed store, hash-verified

2import { fileURLToPath } from 'node:url';
3
4export async function load(url, context, nextLoad) {
5 const result = await nextLoad(url, context);
6 if (url.endsWith('/common/index.js')) {
7 result.source = '"use strict";module.exports=require("node:module").createRequire(' +
8 JSON.stringify(url) + ')(' + JSON.stringify(fileURLToPath(url)) + ');\n';
9 } else if (url.startsWith('file:') && (context.format == null || context.format === 'commonjs')) {
10 result.source = await readFile(new URL(url));
11 }
12 return result;
13}

Callers

nothing calls this directly

Calls 2

readFileFunction · 0.90
fileURLToPathFunction · 0.85

Tested by

no test coverage detected