Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TypeStrong/ts-node
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: TypeStrong/ts-node
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.1.0
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Jul 21, 2016

  1. Copy the full SHA
    240d4b9 View commit details
  2. Copy the full SHA
    838e1c6 View commit details
  3. v1.1.0

    blakeembrey committed Jul 21, 2016
    Copy the full SHA
    15e6644 View commit details
Showing with 37 additions and 25 deletions.
  1. +1 −0 README.md
  2. +2 −2 package.json
  3. +10 −19 src/_bin.ts
  4. +24 −4 src/index.ts
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@ ts-node --compiler ntypescript --project src --ignoreWarnings 2304 hello-world.t
* **--fast, -F** Use TypeScript's `transpileModule` mode (no type checking, but faster compilation) (also `process.env.TS_NODE_FAST`)
* **--lazy, -L** Lazily defer TypeScript initialization until first `.ts` file
* **--no-cache** Skip hitting the compiled JavaScript cache
* **--cache-directory** Configure the TypeScript cache directory

### Programmatic Usage

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-node",
"version": "1.0.0",
"version": "1.1.0",
"preferGlobal": true,
"description": "TypeScript execution environment and REPL for node",
"main": "dist/index.js",
@@ -53,7 +53,7 @@
"semver": "^5.1.0",
"tslint": "^3.10.2",
"tslint-config-standard": "^1.0.0",
"typescript": "1.8.7",
"typescript": "^1.8.10",
"typings": "^1.0.4"
},
"dependencies": {
29 changes: 10 additions & 19 deletions src/_bin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { join, resolve } from 'path'
import { start } from 'repl'
import { inspect } from 'util'
import arrify = require('arrify')
import extend = require('xtend')
import Module = require('module')
import minimist = require('minimist')
import chalk = require('chalk')
@@ -14,6 +16,7 @@ interface Argv {
fast?: boolean
lazy?: boolean
cache?: boolean
cacheDirectory?: string
version?: boolean
help?: boolean
compiler?: string
@@ -24,7 +27,7 @@ interface Argv {
_: string[]
}

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

const aliases: { [key: string]: string[] } = {
@@ -36,6 +39,7 @@ const aliases: { [key: string]: string[] } = {
print: ['p'],
project: ['P'],
compiler: ['C'],
cacheDirectory: ['cache-directory'],
ignoreWarnings: ['I', 'ignore-warnings'],
disableWarnings: ['D', 'disable-warnings'],
compilerOptions: ['O', 'compiler-options']
@@ -116,13 +120,14 @@ Options:
-e, --eval [code] Evaluate code
-p, --print [code] Evaluate code and print result
-C, --compiler [name] Specify a custom TypeScript compiler
-I, --ignoreWarnings [codes] Ignore TypeScript warnings by diagnostic code
-I, --ignoreWarnings [code] Ignore TypeScript warnings by diagnostic code
-D, --disableWarnings Ignore every TypeScript warning
-P, --project [path] Path to TypeScript project (or \`false\`)
-O, --compilerOptions [opts] JSON compiler options to merge with compilation
-L, --lazy Lazily load TypeScript compilation
-F, --fast Run TypeScript compilation in transpile mode
--no-cache Disable the TypeScript cache
--cache-directory Configure the TypeScript cache directory
`)

process.exit(0)
@@ -149,19 +154,12 @@ const isEval = isEvalScript || stop === process.argv.length
const isPrinted = argv.print != null

// Register the TypeScript compiler instance.
const service = register({
const service = register(extend(argv, {
getFile: isEval ? getFileEval : getFile,
getVersion: isEval ? getVersionEval : getVersion,
fileExists: isEval ? fileExistsEval : fileExists,
fast: argv.fast,
lazy: argv.lazy,
cache: argv.cache,
compiler: argv.compiler,
ignoreWarnings: list(argv.ignoreWarnings),
project: argv.project,
disableWarnings: argv.disableWarnings,
compilerOptions: argv.compilerOptions
})
ignoreWarnings: arrify(argv.ignoreWarnings)
}))

// TypeScript files must always end with `.ts`.
const EVAL_FILENAME = '[eval].ts'
@@ -356,13 +354,6 @@ function replEval (code: string, context: any, filename: string, callback: (err?
callback(err, result)
}

/**
* Split a string of values into an array.
*/
function list (value: string | string[]) {
return String(value).split(/ *, */)
}

/**
* Get the file text, checking for eval first.
*/
28 changes: 24 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { relative, basename, extname, resolve, dirname, sep, join } from 'path'
import { writeFileSync, readFileSync, statSync } from 'fs'
import { readdirSync, writeFileSync, readFileSync, statSync } from 'fs'
import { EOL, tmpdir } from 'os'
import sourceMapSupport = require('source-map-support')
import extend = require('xtend')
@@ -9,8 +9,6 @@ import crypto = require('crypto')
import { BaseError } from 'make-error'
import * as TS from 'typescript'

const TMP_DIR = join(tmpdir(), 'ts-node')

const pkg = require('../package.json')
const oldHandlers: { [key: string]: any } = {}

@@ -62,6 +60,7 @@ export interface Options {
fast?: boolean
lazy?: boolean
cache?: boolean
cacheDirectory?: string
compiler?: string
project?: string
ignoreWarnings?: Array<number | string>
@@ -98,6 +97,7 @@ const DEFAULT_OPTIONS: Options = {
getVersion,
fileExists,
cache: process.env.TS_NODE_CACHE,
cacheDirectory: process.env.TS_NODE_CACHE_DIRECTORY || join(tmpdir(), 'ts-node'),
disableWarnings: process.env.TS_NODE_DISABLE_WARNINGS,
compiler: process.env.TS_NODE_COMPILER,
project: process.env.TS_NODE_PROJECT,
@@ -148,7 +148,7 @@ export function register (opts?: Options): () => Register {
const ts: typeof TS = require(options.compiler)
const config = readConfig(options, cwd, ts)
const configDiagnostics = formatDiagnostics(config.errors, options, cwd, ts)
const cachedir = join(TMP_DIR, getCompilerDigest(ts, options, config))
const cachedir = join(resolve(cwd, options.cacheDirectory), getCompilerDigest(ts, options, config))

// Make sure the temp cache directory exists.
mkdirp.sync(cachedir)
@@ -208,6 +208,8 @@ export function register (opts?: Options): () => Register {

return ts.ScriptSnapshot.fromString(options.getFile(fileName))
},
getDirectories: getDirectories,
directoryExists: directoryExists,
getNewLine: () => EOL,
getCurrentDirectory: () => cwd,
getCompilationSettings: () => config.options,
@@ -505,6 +507,24 @@ export function fileExists (fileName: string): boolean {
}
}

/**
* Get directories within a directory.
*/
export function getDirectories (path: string): string[] {
return readdirSync(path).filter(name => directoryExists(join(path, name)))
}

/**
* Check if a directory exists.
*/
export function directoryExists (path: string): boolean {
try {
return statSync(path).isDirectory()
} catch (err) {
return false
}
}

/**
* Get the file from the file system.
*/