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: v0.9.3
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.0.0
Choose a head ref
  • 7 commits
  • 7 files changed
  • 3 contributors

Commits on Jun 28, 2016

  1. Copy the full SHA
    4c0fcb5 View commit details

Commits on Jul 7, 2016

  1. Copy the full SHA
    a407d7a View commit details

Commits on Jul 18, 2016

  1. Chane outDir so that its on the same level as the typescript project

    Mickael Burguet authored and blakeembrey committed Jul 18, 2016
    Copy the full SHA
    5914a10 View commit details
  2. Convert sourceMap.sources to absolute path

    Mickael Burguet authored and blakeembrey committed Jul 18, 2016
    Copy the full SHA
    85745f5 View commit details

Commits on Jul 19, 2016

  1. Copy the full SHA
    f219c6b View commit details

Commits on Jul 20, 2016

  1. Copy the full SHA
    c249b9b View commit details
  2. v1.0.0

    blakeembrey committed Jul 20, 2016
    Copy the full SHA
    14b4edc View commit details
Showing with 381 additions and 216 deletions.
  1. +9 −8 README.md
  2. +2 −2 package.json
  3. +3 −1 register.js
  4. +32 −23 src/_bin.ts
  5. +10 −10 src/index.spec.ts
  6. +323 −170 src/index.ts
  7. +2 −2 typings.json
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ echo "console.log('Hello, world!')" | ts-node
### Mocha

```sh
mocha --require ts-node/register [...args]
mocha --compilers ts:ts-node/register --compilers tsx:ts-node/register [...args]
```

### Tape
@@ -76,13 +76,14 @@ You can set options by passing them in before the script.
ts-node --compiler ntypescript --project src --ignoreWarnings 2304 hello-world.ts
```

* **--project, -P** Location to resolve `tsconfig.json` from (also `process.env.TS_NODE_PROJECT`)
* **--noProject, -n** Disable loading `tsconfig.json` (also `process.env.TS_NODE_NO_PROJECT`)
* **--compiler, -c** Use a custom, require-able TypeScript compiler compatible with `typescript@>=1.5.0-alpha` (also `process.env.TS_NODE_COMPILER`)
* **--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`)
* **--project, -P** Path to resolve `tsconfig.json` from (or `false`) (also `process.env.TS_NODE_PROJECT`)
* **--compiler, -C** Use a custom, require-able TypeScript compiler compatible with `typescript@>=1.5.0-alpha` (also `process.env.TS_NODE_COMPILER`)
* **--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`)
* **--lazy, -L** Lazily defer TypeScript initialization until first `.ts` file
* **--no-cache** Skip hitting the compiled JavaScript cache

### 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": "0.9.3",
"version": "1.0.0",
"preferGlobal": true,
"description": "TypeScript execution environment and REPL for node",
"main": "dist/index.js",
@@ -62,8 +62,8 @@
"diff": "^2.1.1",
"make-error": "^1.1.1",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"source-map-support": "^0.4.0",
"tsconfig": "^3.0.0",
"xtend": "^4.0.0"
}
}
4 changes: 3 additions & 1 deletion register.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
require('./').register()
require('./').register({
lazy: true
})
55 changes: 32 additions & 23 deletions src/_bin.ts
Original file line number Diff line number Diff line change
@@ -6,38 +6,39 @@ import minimist = require('minimist')
import chalk = require('chalk')
import { diffLines } from 'diff'
import { createScript } from 'vm'
import { register, VERSION, getFile, getVersion, getFileExists, TSError } from './index'
import { register, VERSION, getFile, getVersion, fileExists, TSError } from './index'

interface Argv {
eval?: string
print?: string
fast?: boolean
lazy?: boolean
cache?: boolean
version?: boolean
help?: boolean
compiler?: string
project?: string
ignoreWarnings?: string | string[]
disableWarnings?: boolean
noProject?: boolean
compilerOptions?: any
_: string[]
}

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

const aliases: { [key: string]: string[] } = {
help: ['h'],
fast: ['f'],
fast: ['F'],
lazy: ['L'],
version: ['v'],
eval: ['e'],
print: ['p'],
project: ['P'],
compiler: ['c'],
ignoreWarnings: ['i', 'ignore-warnings'],
disableWarnings: ['d', 'disable-warnings'],
noProject: ['n', 'no-project'],
compilerOptions: ['o', 'compiler-options']
compiler: ['C'],
ignoreWarnings: ['I', 'ignore-warnings'],
disableWarnings: ['D', 'disable-warnings'],
compilerOptions: ['O', 'compiler-options']
}

let stop = process.argv.length
@@ -55,7 +56,7 @@ function isFlagOnly (arg: string) {
return true
}

const alias = aliases[name]
const alias = aliases[bool]

if (alias) {
for (const other of alias) {
@@ -94,11 +95,15 @@ for (let i = 2; i < process.argv.length; i++) {
const argv = minimist<Argv>(process.argv.slice(2, stop), {
string: strings,
boolean: booleans,
alias: aliases
alias: aliases,
default: {
cache: true
}
})

if (argv.version) {
console.log(VERSION)
console.log(`ts-node v${VERSION}`)
console.log(`node ${process.version}`)
process.exit(0)
}

@@ -110,11 +115,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
-d, --disableWarnings Ignore every TypeScript warning
-n, --noProject Ignore the "tsconfig.json" project file
-P, --project [path] Specify the path to the TypeScript project
-C, --compiler [name] Specify a custom TypeScript compiler
-I, --ignoreWarnings [codes] 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
`)

process.exit(0)
@@ -144,13 +152,14 @@ const isPrinted = argv.print != null
const service = register({
getFile: isEval ? getFileEval : getFile,
getVersion: isEval ? getVersionEval : getVersion,
getFileExists: isEval ? getFileExistsEval : getFileExists,
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,
noProject: argv.noProject,
compilerOptions: argv.compilerOptions
})

@@ -246,7 +255,7 @@ function _eval (code: string, context: any) {

// Undo on TypeScript compilation errors.
try {
output = service.compile(EVAL_PATH)
output = service().compile(EVAL_PATH)
} catch (error) {
evalFile.input = undo

@@ -311,7 +320,7 @@ function startRepl () {
evalFile.input += identifier
evalFile.version++

const { name, comment } = service.getTypeInfo(EVAL_PATH, evalFile.input.length)
const { name, comment } = service().getTypeInfo(EVAL_PATH, evalFile.input.length)

;(repl as any).outputStream.write(`${chalk.bold(name)}\n${comment ? `${comment}\n` : ''}`)
;(repl as any).displayPrompt()
@@ -371,6 +380,6 @@ function getVersionEval (fileName: string) {
/**
* Get whether the file exists.
*/
function getFileExistsEval (fileName: string) {
return fileName === EVAL_PATH ? true : getFileExists(fileName)
function fileExistsEval (fileName: string) {
return fileName === EVAL_PATH ? true : fileExists(fileName)
}
20 changes: 10 additions & 10 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from 'chai'
import { exec } from 'child_process'
import { join, normalize } from 'path'
import { join } from 'path'
import semver = require('semver')
import ts = require('typescript')
import proxyquire = require('proxyquire')
import { register, VERSION } from './index'

const cwd = join(__dirname, '../tests')
const testDir = join(__dirname, '../tests')
const EXEC_PATH = join(__dirname, '../dist/bin')
const BIN_EXEC = `node ${EXEC_PATH} --project "${cwd}"`
const BIN_EXEC = `node ${EXEC_PATH}`

describe('ts-node', function () {
this.timeout(10000)
@@ -28,7 +28,7 @@ describe('ts-node', function () {
})

it('should execute cli with absolute path', function (done) {
exec(`${BIN_EXEC} "${join(cwd, '../tests/hello-world')}"`, function (err, stdout) {
exec(`${BIN_EXEC} "${join(testDir, 'hello-world')}"`, function (err, stdout) {
expect(err).to.not.exist
expect(stdout).to.equal('Hello, world!\n')

@@ -50,7 +50,7 @@ describe('ts-node', function () {
exec(
[
BIN_EXEC,
'-o "{\\\"allowJs\\\":true}"',
'-O "{\\\"allowJs\\\":true}"',
'-p "import { main } from \'./tests/allow-js/run\';main()"'
].join(' '),
function (err, stdout) {
@@ -101,7 +101,7 @@ describe('ts-node', function () {
it('should work with source maps', function (done) {
exec(`${BIN_EXEC} tests/throw`, function (err) {
expect(err.message).to.contain([
`${normalize('../../tests/throw.ts')}:3`,
`${join(__dirname, '../tests/throw.ts')}:3`,
' bar () { throw new Error(\'this is a demo\') }',
' ^',
'Error: this is a demo'
@@ -114,7 +114,7 @@ describe('ts-node', function () {
it('eval should work with source maps', function (done) {
exec(`${BIN_EXEC} -p "import './tests/throw'"`, function (err) {
expect(err.message).to.contain([
`${normalize('../../tests/throw.ts')}:3`,
`${join(__dirname, '../tests/throw.ts')}:3`,
' bar () { throw new Error(\'this is a demo\') }',
' ^',
'Error: this is a demo'
@@ -125,7 +125,7 @@ describe('ts-node', function () {
})

it('should ignore all warnings', function (done) {
exec(`${BIN_EXEC} -d -p "x"`, function (err) {
exec(`${BIN_EXEC} -D -p "x"`, function (err) {
expect(err.message).to.contain('ReferenceError: x is not defined')

return done()
@@ -161,7 +161,7 @@ describe('ts-node', function () {
})

describe('register', function () {
register({ project: cwd })
register({ project: join(testDir, '..') })

it('should be able to require typescript', function () {
const m = require('../tests/module')
@@ -189,7 +189,7 @@ describe('ts-node', function () {
} catch (error) {
expect(error.stack).to.contain([
'Error: this is a demo',
` at Foo.bar (${normalize('../../tests/throw.ts')}:3:18)`
` at Foo.bar (${join(__dirname, '../tests/throw.ts')}:3:18)`
].join('\n'))

done()
493 changes: 323 additions & 170 deletions src/index.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions typings.json
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@
"diff": "registry:npm/diff#2.0.0+20160211003958",
"make-error": "registry:npm/make-error#1.0.0+20160211003958",
"minimist": "registry:npm/minimist#1.0.0+20160229232932",
"mkdirp": "registry:npm/mkdirp#0.5.0+20160222053049",
"proxyquire": "registry:npm/proxyquire#1.0.0+20160211003958",
"source-map-support": "registry:npm/source-map-support#0.3.0+20160211003958",
"tsconfig": "npm:tsconfig",
"source-map-support": "registry:npm/source-map-support#0.3.0+20160413183746",
"xtend": "registry:npm/xtend#4.0.0+20160211003958"
},
"globalDependencies": {