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

Function register

src/index.ts:584–615  ·  view source on GitHub ↗
(
  serviceOrOpts: Service | RegisterOptions | undefined
)

Source from the content-addressed store, hash-verified

582 */
583export function register(service: Service): Service;
584export function register(
585 serviceOrOpts: Service | RegisterOptions | undefined
586): Service {
587 // Is this a Service or a RegisterOptions?
588 let service = serviceOrOpts as Service;
589 if (!(serviceOrOpts as Service)?.[TS_NODE_SERVICE_BRAND]) {
590 // Not a service; is options
591 service = create((serviceOrOpts ?? {}) as RegisterOptions);
592 }
593
594 const originalJsHandler = require.extensions['.js'];
595
596 // Expose registered instance globally.
597 process[REGISTER_INSTANCE] = service;
598
599 // Register the extensions.
600 registerExtensions(
601 service.options.preferTsExts,
602 service.extensions.compiled,
603 service,
604 originalJsHandler
605 );
606
607 installCommonjsResolveHooksIfNecessary(service);
608
609 // Require specified modules before start-up.
610 (Module as ModuleConstructorWithInternals)._preloadModules(
611 service.options.require
612 );
613
614 return service;
615}
616
617/**
618 * Create TypeScript compiler instance.

Callers 3

phase4Function · 0.90
loader.mjsFile · 0.85

Calls 3

registerExtensionsFunction · 0.85
createFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…