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.2.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.3.0
Choose a head ref
  • 3 commits
  • 5 files changed
  • 1 contributor

Commits on Aug 20, 2016

  1. Override module._compile for compilation (#180)

    * Refactor project to use file caching (used for in-memory compilation from other extension override)
    * Remove file versioning based on filename and auto-increment instead
    blakeembrey authored Aug 20, 2016
    Copy the full SHA
    44c389e View commit details
  2. Copy the full SHA
    8c4da24 View commit details
  3. v1.3.0

    blakeembrey committed Aug 20, 2016
    Copy the full SHA
    0e51402 View commit details
Showing with 87 additions and 86 deletions.
  1. +6 −1 custom_typings/node.d.ts
  2. +1 −1 package.json
  3. +12 −11 src/_bin.ts
  4. +9 −0 src/index.spec.ts
  5. +59 −73 src/index.ts
7 changes: 6 additions & 1 deletion custom_typings/node.d.ts
Original file line number Diff line number Diff line change
@@ -9,12 +9,17 @@ declare module 'module' {
static runMain (): void
static wrap (code: string): string
static _nodeModulePaths (path: string): string[]
static _load (request: string, parent?: Module, isMain?: boolean): any
static _resolveFilename (request: string, parent?: Module, isMain?: boolean): string
static _extensions: { [ext: string]: (m: Module, fileName: string) => any }

constructor (filename: string)
constructor (filename: string, parent?: Module)

parent: Module
filename: string
paths: string[]
exports: any
loaded: boolean
require (module: string): any
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-node",
"version": "1.2.3",
"version": "1.3.0",
"preferGlobal": true,
"description": "TypeScript execution environment and REPL for node",
"main": "dist/index.js",
23 changes: 12 additions & 11 deletions src/_bin.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import minimist = require('minimist')
import chalk = require('chalk')
import { diffLines } from 'diff'
import { createScript } from 'vm'
import { register, VERSION, getFile, getVersion, fileExists, TSError } from './index'
import { register, VERSION, getFile, fileExists, TSError } from './index'

interface Argv {
eval?: string
@@ -21,13 +21,14 @@ interface Argv {
help?: boolean
compiler?: string
project?: string
require?: string | string[]
ignoreWarnings?: string | string[]
disableWarnings?: boolean
compilerOptions?: any
_: string[]
}

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

const aliases: { [key: string]: string[] } = {
@@ -39,6 +40,7 @@ const aliases: { [key: string]: string[] } = {
print: ['p'],
project: ['P'],
compiler: ['C'],
require: ['r'],
cacheDirectory: ['cache-directory'],
ignoreWarnings: ['I', 'ignore-warnings'],
disableWarnings: ['D', 'disable-warnings'],
@@ -119,6 +121,7 @@ Options:
-e, --eval [code] Evaluate code
-p, --print [code] Evaluate code and print result
-r, --require [path] Require a node module for execution
-C, --compiler [name] Specify a custom TypeScript compiler
-I, --ignoreWarnings [code] Ignore TypeScript warnings by diagnostic code
-D, --disableWarnings Ignore every TypeScript warning
@@ -156,7 +159,6 @@ const isPrinted = argv.print != null
// Register the TypeScript compiler instance.
const service = register(extend(argv, {
getFile: isEval ? getFileEval : getFile,
getVersion: isEval ? getVersionEval : getVersion,
fileExists: isEval ? fileExistsEval : fileExists,
ignoreWarnings: arrify(argv.ignoreWarnings)
}))
@@ -168,6 +170,12 @@ const EVAL_PATH = join(cwd, EVAL_FILENAME)
// Store eval contents for in-memory lookups.
const evalFile = { input: '', output: '', version: 0 }

// Require specified modules before start-up.
for (const id of arrify(argv.require)) {
Module._load(id)
}

// Execute the main contents (either eval, script or piped).
if (isEvalScript) {
evalAndExit(code, isPrinted)
} else {
@@ -253,7 +261,7 @@ function _eval (code: string, context: any) {

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

@@ -361,13 +369,6 @@ function getFileEval (fileName: string) {
return fileName === EVAL_PATH ? evalFile.input : getFile(fileName)
}

/**
* Get the file version, checking for eval first.
*/
function getVersionEval (fileName: string) {
return fileName === EVAL_PATH ? String(evalFile.version) : getVersion(fileName)
}

/**
* Get whether the file exists.
*/
9 changes: 9 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -158,6 +158,15 @@ describe('ts-node', function () {
return done()
})
})

it('should support require flags', function (done) {
exec(`${BIN_EXEC} -r ./tests/hello-world -p "console.log('success')"`, function (err, stdout) {
expect(err).to.not.exist
expect(stdout).to.equal('Hello, world!\nsuccess\nundefined\n')

return done()
})
})
})

describe('register', function () {
Loading