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 1 commit
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 = (rootDirs || (rootDir && [rootDir]) || [])[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we instead make this const rootDirPath = rootDir || (rootDirs || [])[0]? I think rootDir should be the default if it is defined. We could improve this with _.castArray(), but we can't use lodash here unfortunately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh yeah, that is a lot better. Let me update.

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