From d120ec1fde3412472a647d0ef18ac241299367f9 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Mon, 30 Apr 2018 17:35:28 -0700 Subject: [PATCH] fix: set cwd to project root when loading ts-node --- src/ts_node.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/ts_node.ts b/src/ts_node.ts index 7503f5c8..b07cdf7c 100644 --- a/src/ts_node.ts +++ b/src/ts_node.ts @@ -33,19 +33,25 @@ function registerTSNode(root: string) { } else { rootDirs.push(`${root}/src`) } - tsNode.register({ - skipProject: true, - transpileOnly: true, - // cache: false, - // typeCheck: true, - compilerOptions: { - target: tsconfig.compilerOptions.target || 'es2017', - module: 'commonjs', - sourceMap: true, - rootDirs, - typeRoots, - } - }) + const cwd = process.cwd() + try { + process.chdir(root) + tsNode.register({ + skipProject: true, + transpileOnly: true, + // cache: false, + // typeCheck: true, + compilerOptions: { + target: tsconfig.compilerOptions.target || 'es2017', + module: 'commonjs', + sourceMap: true, + rootDirs, + typeRoots, + } + }) + } finally { + process.chdir(cwd) + } } function loadTSConfig(root: string): TSConfig | undefined {