MCPcopy
hub / github.com/TypeStrong/ts-node / transformSource

Function transformSource

src/esm.ts:373–403  ·  view source on GitHub ↗
(
    source: string | Buffer,
    context: { url: string; format: NodeLoaderHooksFormat },
    defaultTransformSource: typeof transformSource
  )

Source from the content-addressed store, hash-verified

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}

Callers 1

loadFunction · 0.70

Calls 5

deferFunction · 0.85
ignoredMethod · 0.80
compileMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…