Skip to content

Commit

Permalink
Use a fake outDir option for --allowJs support
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Jun 13, 2016
1 parent b3a9264 commit dd61b78
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"mocha": "^2.1.0",
"ntypescript": "^1.201507091536.1",
"proxyquire": "^1.7.2",
"semver": "^5.1.0",
"tslint": "^3.10.2",
"tslint-config-standard": "^1.0.0",
"typescript": "1.8.7",
Expand Down
20 changes: 20 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { expect } from 'chai'
import { exec } from 'child_process'
import { join, normalize } from 'path'
import semver = require('semver')
import ts = require('typescript')
import proxyquire = require('proxyquire')
import { register, VERSION } from './index'

Expand Down Expand Up @@ -43,6 +45,24 @@ describe('ts-node', function () {
})
})

if (semver.gte(ts.version, '1.8.0')) {
it('should allow js', function (done) {
exec(
[
BIN_EXEC,
'-o "{\\\"allowJs\\\":true}"',
'-p "import { main } from \'./tests/allow-js/run\';main()"'
].join(' '),
function (err, stdout) {
expect(err).to.not.exist
expect(stdout).to.equal('hello world\n')

return done()
}
)
})
}

it('should eval code', function (done) {
exec(
`${BIN_EXEC} -e "import * as m from './tests/module';console.log(m.example('test'))"`,
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,15 @@ function readConfig (options: Options, cwd: string, ts: TSCommon) {
inlineSourceMap: true,
inlineSources: true,
declaration: false,
noEmit: false
noEmit: false,
outDir: `tmp${Math.random().toString(36).substr(2)}`
}
)

// Delete options that *should not* be passed through.
delete result.config.compilerOptions.out
delete result.config.compilerOptions.outFile

// Resolve before getting `dirname` to work around Microsoft/TypeScript#2965
const basePath = fileName ? dirname(resolve(fileName)) : cwd

Expand Down
3 changes: 3 additions & 0 deletions tests/allow-js/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function main () {
return 'hello world'
}
3 changes: 3 additions & 0 deletions typings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
"globalDevDependencies": {
"chai": "registry:dt/chai#3.4.0+20160216071402",
"mocha": "registry:dt/mocha#2.2.5+20151023103246"
},
"devDependencies": {
"semver": "registry:npm/semver#5.0.0+20160211003958"
}
}

0 comments on commit dd61b78

Please sign in to comment.