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

Function load

test/fixtures/es-module-loaders/hooks-input.mjs:58–94  ·  view source on GitHub ↗
(url, context, next)

Source from the content-addressed store, hash-verified

56}
57
58export async function load(url, context, next) {
59 loadCalls++;
60 const source = await readFile(fileURLToPath(url));
61 let format;
62
63 if (loadCalls === 1) {
64 assert.match(url, /json-modules\.mjs$/);
65 assert.deepStrictEqual(context.importAttributes, {});
66 format = 'module';
67 } else if (loadCalls === 2) {
68 assert.match(url, /experimental\.json$/);
69 assert.deepStrictEqual(context.importAttributes, {
70 type: 'json',
71 });
72 format = 'json';
73 }
74
75 assert.ok(new URL(url));
76 // Ensure `context` has all and only the properties it's supposed to
77 assert.deepStrictEqual(Reflect.ownKeys(context), [
78 'format',
79 'importAttributes',
80 'importAssertions',
81 ]);
82 assert.strictEqual(context.format, 'test');
83 assert.strictEqual(typeof next, 'function');
84
85 const returnValue = {
86 source,
87 format,
88 shortCircuit: true,
89 };
90
91 writeSync(1, JSON.stringify(returnValue) + '\n'); // For the test to validate when it parses stdout
92
93 return returnValue;
94}

Callers

nothing calls this directly

Calls 5

readFileFunction · 0.90
fileURLToPathFunction · 0.90
writeSyncFunction · 0.90
matchMethod · 0.65
okMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…