Skip to content

Commit

Permalink
feat(register): try-ts-ext register option
Browse files Browse the repository at this point in the history
  • Loading branch information
calebboyd committed Jun 3, 2021
1 parent cf9f1f4 commit 776d768
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions register/try-ts-ext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require('../dist').register({
tryTsExt: true,
});
13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface ProcessEnv {
TS_NODE_SKIP_PROJECT?: string;
TS_NODE_SKIP_IGNORE?: string;
TS_NODE_PREFER_TS_EXTS?: string;
TS_NODE_TRY_TS_EXT?: string;
TS_NODE_IGNORE_DIAGNOSTICS?: string;
TS_NODE_TRANSPILE_ONLY?: string;
TS_NODE_TYPE_CHECK?: string;
Expand Down Expand Up @@ -280,6 +281,13 @@ export interface RegisterOptions extends CreateOptions {
* @default false
*/
preferTsExts?: boolean;

/**
* Attempt to resolve the typescript file when the js file cannot be found.
*
* @default false
*/
tryTsExt?: boolean
}

/**
Expand Down Expand Up @@ -327,6 +335,7 @@ export const DEFAULTS: RegisterOptions = {
skipProject: yn(env.TS_NODE_SKIP_PROJECT),
skipIgnore: yn(env.TS_NODE_SKIP_IGNORE),
preferTsExts: yn(env.TS_NODE_PREFER_TS_EXTS),
tryTsExt: yn(env.TS_NODE_ESM_COMPAT),
ignoreDiagnostics: split(env.TS_NODE_IGNORE_DIAGNOSTICS),
transpileOnly: yn(env.TS_NODE_TRANSPILE_ONLY),
typeCheck: yn(env.TS_NODE_TYPE_CHECK),
Expand Down Expand Up @@ -441,7 +450,9 @@ export function register(opts: RegisterOptions = {}): Service {
originalJsHandler
);

patchResolveFileName();
if (service.options.tryTsExt) {
patchResolveFileName();
}

// Require specified modules before start-up.
(Module as any)._preloadModules(service.options.require);
Expand Down

0 comments on commit 776d768

Please sign in to comment.