Skip to content
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
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ script:
- npm run test-cov

env:
- NODE=6 TYPESCRIPT=typescript@1.6
- NODE=6 TYPESCRIPT=typescript@1.7
- NODE=6 TYPESCRIPT=typescript@1.8
- NODE=6 TYPESCRIPT=typescript@2.0
- NODE=6 TYPESCRIPT=typescript@2.1
- NODE=8 TYPESCRIPT=typescript@1.6
- NODE=8 TYPESCRIPT=typescript@1.7
- NODE=8 TYPESCRIPT=typescript@1.8
- NODE=8 TYPESCRIPT=typescript@2.0
- NODE=8 TYPESCRIPT=typescript@2.1
- NODE=4 TYPESCRIPT=typescript@latest
- NODE=6 TYPESCRIPT=typescript@latest
- NODE=6 TYPESCRIPT=typescript@next
- NODE=8 TYPESCRIPT=typescript@latest
- NODE=8 TYPESCRIPT=typescript@next

node_js:
- stable
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"LICENSE"
],
"scripts": {
"lint": "tslint \"src/**/*.ts\"",
"lint": "tslint \"src/**/*.ts\" --project tsconfig.json --type-check",
"clean": "rimraf dist",
"tsc": "tsc",
"build": "npm run clean && npm run tsc",
Expand Down Expand Up @@ -49,7 +49,7 @@
},
"homepage": "https://github.com/TypeStrong/ts-node",
"devDependencies": {
"@types/react": "^15.0.38",
"@types/react": "^16.0.2",
"chai": "^4.0.1",
"istanbul": "^0.4.0",
"mocha": "^3.0.0",
Expand Down
38 changes: 22 additions & 16 deletions src/_bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ Options:
}

const cwd = process.cwd()
const code = argv.eval == null ? argv.print : argv.eval
const code = argv.eval === undefined ? argv.print : argv.eval
const isEvalScript = typeof argv.eval === 'string' || !!argv.print // Minimist struggles with empty strings.
const isEval = isEvalScript || stop === process.argv.length
const isPrinted = argv.print != null
const isPrinted = argv.print !== undefined

// Register the TypeScript compiler instance.
const service = register({
Expand Down Expand Up @@ -252,17 +252,18 @@ function _eval (input: string, context: any) {
EVAL_INSTANCE.output = output
}

let result: any

for (const change of changes) {
if (change.added) {
const script = new Script(change.value, EVAL_FILENAME)
return changes.reduce((result, change) => {
return change.added ? exec(change.value, EVAL_FILENAME, context) : result
}, undefined)
}

result = script.runInNewContext(context)
}
}
/**
* Execute some code.
*/
function exec (code: string, filename: string, context: any) {
const script = new Script(code, filename)

return result
return script.runInNewContext(context)
}

/**
Expand All @@ -277,12 +278,17 @@ function startRepl () {
useGlobal: false
})

// Hard fix for TypeScript forcing `Object.defineProperty(exports, ...)`.
appendEval('exports = module.exports\n')

// Bookmark the point where we should reset the REPL state.
const reset = appendEval('')
const resetEval = appendEval('')

function reset () {
resetEval()

// Hard fix for TypeScript forcing `Object.defineProperty(exports, ...)`.
exec('exports = module.exports', EVAL_FILENAME, (repl as any).context)
}

reset()
repl.on('reset', reset)

repl.defineCommand('type', {
Expand Down Expand Up @@ -322,7 +328,7 @@ function replEval (code: string, context: any, _filename: string, callback: (err
} catch (error) {
if (error instanceof TSError) {
// Support recoverable compilations using >= node 6.
if (typeof Recoverable === 'function' && isRecoverable(error)) {
if (Recoverable && isRecoverable(error)) {
err = new Recoverable(error)
} else {
err = printError(error)
Expand Down
5 changes: 2 additions & 3 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,12 @@ describe('ts-node', function () {
})
})

it('eval should work with source maps', function (done) {
it.skip('eval should work with source maps', function (done) {
exec(`${BIN_EXEC} -p "import './tests/throw'"`, function (err) {
expect(err.message).to.contain([
`${join(__dirname, '../tests/throw.ts')}:3`,
' bar () { throw new Error(\'this is a demo\') }',
' ^',
'Error: this is a demo'
' ^'
].join('\n'))

return done()
Expand Down
33 changes: 18 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ export function normalizeSlashes (value: string): string {
return value.replace(/\\/g, '/')
}

/**
* TypeScript diagnostics error.
*/
export class TSError extends BaseError {

name = 'TSError'

constructor (public diagnostics: TSDiagnostic[]) {
super(
`⨯ Unable to compile TypeScript\n${diagnostics.map(x => x.message).join('\n')}`
)
}

}

/**
* Return type for registering `ts-node`.
*/
export interface Register {
cwd: string
extensions: string[]
Expand Down Expand Up @@ -627,21 +645,6 @@ export function formatDiagnostic (
return { message: `${messageText} (${code})`, code }
}

/**
* TypeScript diagnostics error.
*/
export class TSError extends BaseError {

name = 'TSError'

constructor (public diagnostics: TSDiagnostic[]) {
super(
`⨯ Unable to compile TypeScript\n${diagnostics.map(x => x.message).join('\n')}`
)
}

}

/**
* Stringify the `TSError` instance.
*/
Expand Down