Skip to content

Commit db6b00c

Browse files
authored
Merge compilerOptions env variable with CLI arg (#213)
1 parent cb30cf6 commit db6b00c

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/_bin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import minimist = require('minimist')
77
import chalk = require('chalk')
88
import { diffLines } from 'diff'
99
import { createScript } from 'vm'
10-
import { register, VERSION, getFile, fileExists, TSError } from './index'
10+
import { register, VERSION, getFile, fileExists, TSError, parse } from './index'
1111

1212
interface Argv {
1313
eval?: string
@@ -168,7 +168,7 @@ const service = register({
168168
ignore: typeof argv.ignore === 'boolean' ? argv.ignore : arrify(argv.ignore),
169169
ignoreWarnings: arrify(argv.ignoreWarnings),
170170
disableWarnings: argv.disableWarnings,
171-
compilerOptions: argv.compilerOptions,
171+
compilerOptions: parse(argv.compilerOptions),
172172
getFile: isEval ? getFileEval : getFile,
173173
fileExists: isEval ? fileExistsEval : fileExists
174174
})

src/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const DEFAULTS = {
9898
cacheDirectory: process.env.TS_NODE_CACHE_DIRECTORY,
9999
disableWarnings: yn(process.env.TS_NODE_DISABLE_WARNINGS),
100100
compiler: process.env.TS_NODE_COMPILER,
101-
compilerOptions: process.env.TS_NODE_COMPILER_OPTIONS,
101+
compilerOptions: parse(process.env.TS_NODE_COMPILER_OPTIONS),
102102
project: process.env.TS_NODE_PROJECT,
103103
ignore: split(process.env.TS_NODE_IGNORE),
104104
ignoreWarnings: split(process.env.TS_NODE_IGNORE_WARNINGS),
@@ -108,14 +108,21 @@ const DEFAULTS = {
108108
/**
109109
* Split a string array of values.
110110
*/
111-
function split (value: string | undefined) {
111+
export function split (value: string | undefined) {
112112
return value ? value.split(/ *, */g) : []
113113
}
114114

115+
/**
116+
* Parse a string as JSON.
117+
*/
118+
export function parse (value: string | undefined) {
119+
return value ? JSON.parse(value) : undefined
120+
}
121+
115122
/**
116123
* Replace backslashes with forward slashes.
117124
*/
118-
function slash (value: string): string {
125+
export function slash (value: string): string {
119126
return value.replace(/\\/g, '/')
120127
}
121128

@@ -138,6 +145,7 @@ export function register (options: Options = {}): () => Register {
138145
const fast = !!(options.fast == null ? DEFAULTS.fast : options.fast)
139146
const project = options.project || DEFAULTS.project
140147
const cacheDirectory = options.cacheDirectory || DEFAULTS.cacheDirectory || join(tmpdir(), 'ts-node')
148+
const compilerOptions = extend(DEFAULTS.compilerOptions, options.compilerOptions)
141149
let result: Register
142150

143151
const ignore = (
@@ -146,14 +154,9 @@ export function register (options: Options = {}): () => Register {
146154
(options.ignore === false ? [] : undefined) :
147155
(options.ignore || DEFAULTS.ignore)
148156
) ||
149-
['^node_modules/']
157+
['/node_modules/']
150158
).map(str => new RegExp(str))
151159

152-
// Parse compiler options as JSON.
153-
const compilerOptions = typeof options.compilerOptions === 'string' ?
154-
JSON.parse(options.compilerOptions) :
155-
options.compilerOptions
156-
157160
function load () {
158161
const cache: Cache = { contents: {}, versions: {}, sourceMaps: {} }
159162

0 commit comments

Comments
 (0)