( serviceOrOpts: Service | RegisterOptions | undefined )
| 582 | */ |
| 583 | export function register(service: Service): Service; |
| 584 | export 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. |
no test coverage detected
searching dependent graphs…