(
url: string,
context: {
format: NodeLoaderHooksFormat | null | undefined;
importAssertions?: NodeLoaderHooksAPI2.NodeImportAssertions;
},
defaultLoad: typeof load
)
| 226 | |
| 227 | // `load` from new loader hook API (See description at the top of this file) |
| 228 | async function load( |
| 229 | url: string, |
| 230 | context: { |
| 231 | format: NodeLoaderHooksFormat | null | undefined; |
| 232 | importAssertions?: NodeLoaderHooksAPI2.NodeImportAssertions; |
| 233 | }, |
| 234 | defaultLoad: typeof load |
| 235 | ): Promise<{ |
| 236 | format: NodeLoaderHooksFormat; |
| 237 | source: string | Buffer | undefined; |
| 238 | }> { |
| 239 | return addShortCircuitFlag(async () => { |
| 240 | // If we get a format hint from resolve() on the context then use it |
| 241 | // otherwise call the old getFormat() hook using node's old built-in defaultGetFormat() that ships with ts-node |
| 242 | const format = |
| 243 | context.format ?? |
| 244 | ( |
| 245 | await getFormat( |
| 246 | url, |
| 247 | context, |
| 248 | nodeGetFormatImplementation.defaultGetFormat |
| 249 | ) |
| 250 | ).format; |
| 251 | |
| 252 | let source = undefined; |
| 253 | if (format !== 'builtin' && format !== 'commonjs') { |
| 254 | // Call the new defaultLoad() to get the source |
| 255 | const { source: rawSource } = await defaultLoad( |
| 256 | url, |
| 257 | { |
| 258 | ...context, |
| 259 | format, |
| 260 | }, |
| 261 | defaultLoad |
| 262 | ); |
| 263 | |
| 264 | if (rawSource === undefined || rawSource === null) { |
| 265 | throw new Error( |
| 266 | `Failed to load raw source: Format was '${format}' and url was '${url}''.` |
| 267 | ); |
| 268 | } |
| 269 | |
| 270 | // Emulate node's built-in old defaultTransformSource() so we can re-use the old transformSource() hook |
| 271 | const defaultTransformSource: typeof transformSource = async ( |
| 272 | source, |
| 273 | _context, |
| 274 | _defaultTransformSource |
| 275 | ) => ({ source }); |
| 276 | |
| 277 | // Call the old hook |
| 278 | const { source: transformedSource } = await transformSource( |
| 279 | rawSource, |
| 280 | { url, format }, |
| 281 | defaultTransformSource |
| 282 | ); |
| 283 | source = transformedSource; |
| 284 | } |
| 285 |
nothing calls this directly
no test coverage detected
searching dependent graphs…