From e7690b966a69255d2daa9895912cbe4aebc4e2e0 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Sat, 14 Dec 2019 00:28:22 -0500 Subject: [PATCH] Revert "Remove ability to specify "requires" in tsconfig" This reverts commit 700a90fb483df86753c0da9d76bd76ca4af73e6c. --- src/bin.ts | 4 +++- src/index.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 38523a9dd..976234114 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -87,7 +87,7 @@ export function main (argv: string[]) { '--help': help = false, '--script-mode': scriptMode = false, '--version': version = 0, - '--require': requires = [], + '--require': argsRequire = [], '--eval': code = undefined, '--print': print = false, '--interactive': interactive = false, @@ -190,6 +190,8 @@ export function main (argv: string[]) { : undefined }) + const requires = argsRequire.length !== 0 ? argsRequire : service.options.requires || [] + // Output project information. if (version >= 2) { console.log(`ts-node v${VERSION}`) diff --git a/src/index.ts b/src/index.ts index b0346bb94..8891351a3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -166,7 +166,9 @@ export interface TsConfigOptions | 'skipProject' | 'project' | 'dir' - > {} + > { + requires?: Array +} /** * Like Object.assign or splatting, but never overwrites with `undefined`. @@ -789,6 +791,14 @@ function readConfig ( useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames }, basePath, undefined, configFileName)) + if (tsconfigOptions.requires) { + // Relative paths are relative to the tsconfig's parent directory, not the `dir` option + tsconfigOptions.requires = tsconfigOptions.requires.map((path: string) => { + if (path.startsWith('.')) return resolve(configFileName!, '..', path) + return path + }) + } + return { config: fixedConfig, options: tsconfigOptions } }