Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable --fast CLI flag for transpile mode only #130

Merged
merged 1 commit into from
Jun 11, 2016
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ ts-node --compiler ntypescript --project src --ignoreWarnings 2304 hello-world.t
* **--ignoreWarnings, -i** Set an array of TypeScript diagnostic codes to ignore (also `process.env.TS_NODE_IGNORE_WARNINGS`)
* **--disableWarnings, -d** Ignore all TypeScript errors (also `process.env.TS_NODE_DISABLE_WARNINGS`)
* **--compilerOptions, -o** Set compiler options using JSON (E.g. `--compilerOptions '{"target":"es6"}'`) (also `process.env.TS_NODE_COMPILER_OPTIONS`)
* **--fast, -f** Use TypeScript's `transpileModule` mode (no type checking, but faster compilation) (also `process.env.TS_NODE_FAST`)

### Programmatic Usage

Expand Down
20 changes: 18 additions & 2 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import minimist = require('minimist')
import chalk = require('chalk')
import { diffLines } from 'diff'
import { createScript } from 'vm'
import { register, VERSION, getFile, getVersion, TSError } from './index'
import { register, VERSION, getFile, getVersion, getFileExists, TSError } from './index'

interface Argv {
eval?: string
print?: string
fast?: boolean
version?: boolean
help?: boolean
compiler?: string
Expand All @@ -25,10 +26,11 @@ interface Argv {
}

const strings = ['eval', 'print', 'compiler', 'project', 'ignoreWarnings']
const booleans = ['help', 'version', 'disableWarnings', 'noProject']
const booleans = ['help', 'fast', 'version', 'disableWarnings', 'noProject']

const aliases: { [key: string]: string[] } = {
help: ['h'],
fast: ['f'],
version: ['v'],
eval: ['e'],
print: ['p'],
Expand All @@ -45,6 +47,11 @@ let stop = process.argv.length
function isFlagOnly (arg: string) {
const name = arg.replace(/^--?/, '')

// The value is part of this argument.
if (/=/.test(name)) {
return true
}

for (const bool of booleans) {
if (name === bool) {
return true
Expand Down Expand Up @@ -139,6 +146,8 @@ const isPrinted = argv.print != null
const service = register({
getFile: isEval ? getFileEval : getFile,
getVersion: isEval ? getVersionEval : getVersion,
getFileExists: isEval ? getFileExistsEval : getFileExists,
fast: argv.fast,
compiler: argv.compiler,
ignoreWarnings: list(argv.ignoreWarnings),
project: argv.project,
Expand Down Expand Up @@ -360,3 +369,10 @@ function getFileEval (fileName: string) {
function getVersionEval (fileName: string) {
return fileName === EVAL_PATH ? String(evalFile.version) : getVersion(fileName)
}

/**
* Get whether the file exists.
*/
function getFileExistsEval (fileName: string) {
return fileName === EVAL_PATH ? true : getFileExists(fileName)
}
Loading