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: v2.1.1
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: v2.1.2
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Mar 21, 2017

  1. Copy the full SHA
    b251147 View commit details
  2. Copy the full SHA
    ec00796 View commit details
  3. v2.1.2

    blakeembrey committed Mar 21, 2017
    Copy the full SHA
    4a17778 View commit details
Showing with 36 additions and 40 deletions.
  1. +1 −1 package.json
  2. +9 −3 src/index.spec.ts
  3. +26 −36 src/index.ts
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": "2.1.1",
"version": "2.1.2",
"preferGlobal": true,
"description": "TypeScript execution environment and REPL for node",
"main": "dist/index.js",
12 changes: 9 additions & 3 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -135,30 +135,36 @@ describe('ts-node', function () {
})

it('should pipe into `ts-node` and evaluate', function (done) {
exec(`echo "console.log('hello')" | ${BIN_EXEC}`, function (err, stdout) {
const cp = exec(BIN_EXEC, function (err, stdout) {
expect(err).to.not.exist
expect(stdout).to.equal('hello\n')

return done()
})

cp.stdin.end("console.log('hello')")
})

it('should pipe into `ts-node`', function (done) {
exec(`echo "true" | ${BIN_EXEC} -p`, function (err, stdout) {
const cp = exec(`${BIN_EXEC} -p`, function (err, stdout) {
expect(err).to.not.exist
expect(stdout).to.equal('true\n')

return done()
})

cp.stdin.end('true')
})

it('should pipe into an eval script', function (done) {
exec(`echo "true" | ${BIN_EXEC} -p '(process.stdin as any).isTTY'`, function (err, stdout) {
const cp = exec(`${BIN_EXEC} -p '(process.stdin as any).isTTY'`, function (err, stdout) {
expect(err).to.not.exist
expect(stdout).to.equal('undefined\n')

return done()
})

cp.stdin.end('true')
})

it('should support require flags', function (done) {
62 changes: 26 additions & 36 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -26,26 +26,13 @@ export interface TSCommon {
getPreEmitDiagnostics: typeof TS.getPreEmitDiagnostics
flattenDiagnosticMessageText: typeof TS.flattenDiagnosticMessageText
transpileModule: typeof TS.transpileModule
ModuleKind: typeof TS.ModuleKind
ScriptTarget: typeof TS.ScriptTarget
findConfigFile: typeof TS.findConfigFile
readConfigFile: typeof TS.readConfigFile
parseJsonConfigFileContent: typeof TS.parseJsonConfigFileContent

// TypeScript 1.5+, 1.7+ added `fileExists` parameter.
findConfigFile (path: string, fileExists?: (path: string) => boolean): string

// TypeScript 1.5+, 1.7+ added `readFile` parameter.
readConfigFile (path: string, readFile?: (path: string) => string): {
config?: any
error?: TS.Diagnostic
}

// TypeScript 1.7+.
parseJsonConfigFileContent? (
json: any,
host: any,
basePath: string,
existingOptions: any,
configFileName: string
): any

// TypeScript 1.5+.
// TypeScript 1.5 and 1.6.
parseConfigFile? (json: any, host: any, basePath: string): any
}

@@ -206,6 +193,16 @@ export function register (options: Options = {}): () => Register {
throw new TSError(formatDiagnostics(configDiagnostics, cwd, ts, 0))
}

// Target ES5 output by default (instead of ES3).
if (config.options.target === undefined) {
config.options.target = ts.ScriptTarget.ES5
}

// Target CommonJS modules by default (instead of magically switching to ES6 when the target is ES6).
if (config.options.module === undefined) {
config.options.module = ts.ModuleKind.CommonJS
}

// Enable `allowJs` when flag is set.
if (config.options.allowJs) {
extensions.push('.js')
@@ -423,22 +420,15 @@ function registerExtension (
function readConfig (compilerOptions: any, project: string | boolean | undefined, cwd: string, ts: TSCommon) {
const result = loadSync(cwd, typeof project === 'string' ? project : undefined)

result.config.compilerOptions = extend(
{
target: 'es5',
module: 'commonjs'
},
result.config.compilerOptions,
compilerOptions,
{
sourceMap: true,
inlineSourceMap: false,
inlineSources: true,
declaration: false,
noEmit: false,
outDir: '$$ts-node$$'
}
)
// Override default configuration options.
result.config.compilerOptions = extend(result.config.compilerOptions, compilerOptions, {
sourceMap: true,
inlineSourceMap: false,
inlineSources: true,
declaration: false,
noEmit: false,
outDir: '$$ts-node$$'
})

// Delete options that *should not* be passed through.
delete result.config.compilerOptions.out
@@ -453,7 +443,7 @@ function readConfig (compilerOptions: any, project: string | boolean | undefined
}

if (typeof ts.parseJsonConfigFileContent === 'function') {
return ts.parseJsonConfigFileContent(result.config, ts.sys, basePath, null, configPath as string)
return ts.parseJsonConfigFileContent(result.config, ts.sys, basePath, undefined, configPath as string)
}

throw new TypeError('Could not find a compatible `parseConfigFile` function')