* Load module source for a url, through a hooks chain if it exists. * @param {string} url * @param {string|undefined} originalFormat * @param {ImportAttributes|undefined} importAttributes * @param {string[]} conditions * @param {(url: string, context: ModuleLoadContext) => ModuleLoadResult} def
(url, originalFormat, importAttributes, conditions, defaultLoad, validateLoad)
| 363 | * @returns {ModuleLoadResult} |
| 364 | */ |
| 365 | function loadWithHooks(url, originalFormat, importAttributes, conditions, defaultLoad, validateLoad) { |
| 366 | debug('loadWithHooks', url, originalFormat); |
| 367 | const context = new ModuleLoadContext(originalFormat, importAttributes, conditions); |
| 368 | if (loadHooks.length === 0) { |
| 369 | return defaultLoad(url, context); |
| 370 | } |
| 371 | |
| 372 | const runner = buildHooks(loadHooks, 'load', defaultLoad, validateLoad, context); |
| 373 | |
| 374 | const result = runner(url, context); |
| 375 | const { source, format } = result; |
| 376 | if (!isAnyArrayBuffer(source) && !isArrayBufferView(source)) { |
| 377 | return result; |
| 378 | } |
| 379 | |
| 380 | switch (format) { |
| 381 | // Text formats: |
| 382 | case undefined: |
| 383 | case 'module': |
| 384 | case 'commonjs': |
| 385 | case 'json': |
| 386 | case 'module-typescript': |
| 387 | case 'commonjs-typescript': |
| 388 | case 'typescript': { |
| 389 | decoder ??= new (require('internal/encoding').TextDecoder)(); |
| 390 | result.source = decoder.decode(source); |
| 391 | break; |
| 392 | } |
| 393 | default: |
| 394 | break; |
| 395 | } |
| 396 | return result; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Resolve module request to a url, through a hooks chain if it exists. |
no test coverage detected
searching dependent graphs…