Skip to content

Commit

Permalink
Merge compilerOptions env variable with CLI arg (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey authored Oct 7, 2016
1 parent cb30cf6 commit db6b00c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/_bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import minimist = require('minimist')
import chalk = require('chalk')
import { diffLines } from 'diff'
import { createScript } from 'vm'
import { register, VERSION, getFile, fileExists, TSError } from './index'
import { register, VERSION, getFile, fileExists, TSError, parse } from './index'

interface Argv {
eval?: string
Expand Down Expand Up @@ -168,7 +168,7 @@ const service = register({
ignore: typeof argv.ignore === 'boolean' ? argv.ignore : arrify(argv.ignore),
ignoreWarnings: arrify(argv.ignoreWarnings),
disableWarnings: argv.disableWarnings,
compilerOptions: argv.compilerOptions,
compilerOptions: parse(argv.compilerOptions),
getFile: isEval ? getFileEval : getFile,
fileExists: isEval ? fileExistsEval : fileExists
})
Expand Down
21 changes: 12 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const DEFAULTS = {
cacheDirectory: process.env.TS_NODE_CACHE_DIRECTORY,
disableWarnings: yn(process.env.TS_NODE_DISABLE_WARNINGS),
compiler: process.env.TS_NODE_COMPILER,
compilerOptions: process.env.TS_NODE_COMPILER_OPTIONS,
compilerOptions: parse(process.env.TS_NODE_COMPILER_OPTIONS),
project: process.env.TS_NODE_PROJECT,
ignore: split(process.env.TS_NODE_IGNORE),
ignoreWarnings: split(process.env.TS_NODE_IGNORE_WARNINGS),
Expand All @@ -108,14 +108,21 @@ const DEFAULTS = {
/**
* Split a string array of values.
*/
function split (value: string | undefined) {
export function split (value: string | undefined) {
return value ? value.split(/ *, */g) : []
}

/**
* Parse a string as JSON.
*/
export function parse (value: string | undefined) {
return value ? JSON.parse(value) : undefined
}

/**
* Replace backslashes with forward slashes.
*/
function slash (value: string): string {
export function slash (value: string): string {
return value.replace(/\\/g, '/')
}

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

const ignore = (
Expand All @@ -146,14 +154,9 @@ export function register (options: Options = {}): () => Register {
(options.ignore === false ? [] : undefined) :
(options.ignore || DEFAULTS.ignore)
) ||
['^node_modules/']
['/node_modules/']
).map(str => new RegExp(str))

// Parse compiler options as JSON.
const compilerOptions = typeof options.compilerOptions === 'string' ?
JSON.parse(options.compilerOptions) :
options.compilerOptions

function load () {
const cache: Cache = { contents: {}, versions: {}, sourceMaps: {} }

Expand Down

0 comments on commit db6b00c

Please sign in to comment.