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

Function defaultLoadSync

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

* @param {URL['href']} url * @param {LoadContext} [context] * @returns {LoadReturn}

(url, context = kEmptyObject)

Source from the content-addressed store, hash-verified

134 * @returns {LoadReturn}
135 */
136function defaultLoadSync(url, context = kEmptyObject) {
137 let responseURL = url;
138 const { importAttributes } = context;
139 let {
140 format,
141 source,
142 } = context;
143
144 const urlInstance = new URL(url);
145
146 throwIfUnsupportedURLScheme(urlInstance, false);
147
148 if (urlInstance.protocol === 'node:') {
149 source = null;
150 format ??= 'builtin';
151 } else if (format === 'addon') {
152 // Skip loading addon file content. It must be loaded with dlopen from file system.
153 source = null;
154 } else {
155 if (source == null) {
156 ({ responseURL, source } = getSourceSync(urlInstance, context));
157 context = { __proto__: context, source };
158 }
159
160 // Now that we have the source for the module, run `defaultGetFormat` to detect its format.
161 format ??= defaultGetFormat(urlInstance, context);
162 }
163 validateAttributes(url, format, importAttributes);
164
165 return {
166 __proto__: null,
167 format,
168 responseURL,
169 source,
170 };
171}
172
173
174/**

Callers 1

Calls 4

getSourceSyncFunction · 0.85
defaultGetFormatFunction · 0.85
validateAttributesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…