Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

fix: add rootDir from tsconfig for plugins that use it #39

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/ts_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const debug = Debug()

export interface TSConfig {
compilerOptions: {
rootDir?: string
rootDirs?: string[]
outDir?: string
target?: string
Expand Down Expand Up @@ -82,12 +83,12 @@ export function tsPath(root: string, orig: string | undefined): string | undefin
registerTSNode(root)
const tsconfig = tsconfigs[root]
if (!tsconfig) return orig
const {rootDirs, outDir} = tsconfig.compilerOptions
const rootDir = (rootDirs || [])[0]
if (!rootDir || !outDir) return orig
const {rootDir, rootDirs, outDir} = tsconfig.compilerOptions
const rootDirPath = rootDir || (rootDirs || [])[0]
if (!rootDirPath || !outDir) return orig
// rewrite path from ./lib/foo to ./src/foo
const lib = path.join(root, outDir) // ./lib
const src = path.join(root, rootDir) // ./src
const src = path.join(root, rootDirPath) // ./src
const relative = path.relative(lib, orig) // ./commands
const out = path.join(src, relative) // ./src/commands
// this can be a directory of commands or point to a hook file
Expand Down