| 371 | } |
| 372 | |
| 373 | async function transformSource( |
| 374 | source: string | Buffer, |
| 375 | context: { url: string; format: NodeLoaderHooksFormat }, |
| 376 | defaultTransformSource: typeof transformSource |
| 377 | ): Promise<{ source: string | Buffer }> { |
| 378 | if (source === null || source === undefined) { |
| 379 | throw new Error('No source'); |
| 380 | } |
| 381 | |
| 382 | const defer = () => |
| 383 | defaultTransformSource(source, context, defaultTransformSource); |
| 384 | |
| 385 | const sourceAsString = |
| 386 | typeof source === 'string' ? source : source.toString('utf8'); |
| 387 | |
| 388 | const { url } = context; |
| 389 | const parsed = parseUrl(url); |
| 390 | |
| 391 | if (!isFileUrlOrNodeStyleSpecifier(parsed)) { |
| 392 | return defer(); |
| 393 | } |
| 394 | const nativePath = fileURLToPath(url); |
| 395 | |
| 396 | if (tsNodeService.ignored(nativePath)) { |
| 397 | return defer(); |
| 398 | } |
| 399 | |
| 400 | const emittedJs = tsNodeService.compile(sourceAsString, nativePath); |
| 401 | |
| 402 | return { source: emittedJs }; |
| 403 | } |
| 404 | |
| 405 | return hooksAPI; |
| 406 | } |