Skip to content

Commit

Permalink
Merge branch '8.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Jan 9, 2020
2 parents 3401f59 + 323c397 commit aa6f36f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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": "8.5.0",
"version": "8.5.4",
"description": "TypeScript execution environment and REPL for node.js, with source map support",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function main (argv: string[]) {
module.paths = (Module as any)._nodeModulePaths(cwd)

// Require specified modules before start-up.
for (const id of requires) module.require(id)
;(Module as any)._preloadModules(requires)

// Prepend `ts-node` arguments to CLI for child processes.
process.execArgv.unshift(__filename, ...process.argv.slice(2, process.argv.length - args._.length))
Expand Down
12 changes: 12 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ describe('ts-node', function () {
})
})

it('should throw error even in transpileOnly mode', function (done) {
exec(`${BIN_EXEC} --transpile-only -pe "console."`, function (err) {
if (err === null) {
return done('Command was expected to fail, but it succeeded.')
}

expect(err.message).to.contain('error TS1003: Identifier expected')

return done()
})
})

it('should pipe into `ts-node` and evaluate', function (done) {
const cp = exec(BIN_EXEC, function (err, stdout) {
expect(err).to.equal(null)
Expand Down
24 changes: 17 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,6 @@ export function create (rawOptions: CreateOptions = {}): Register {

const readFile = options.readFile || ts.sys.readFile
const fileExists = options.fileExists || ts.sys.fileExists
const isScoped = options.scope ? (fileName: string) => relative(cwd, fileName).charAt(0) !== '.' : () => true
const ignore = options.skipIgnore ? [] : (options.ignore || ['/node_modules/']).map(str => new RegExp(str))
const transpileOnly = options.transpileOnly === true
const transformers = options.transformers || undefined
const ignoreDiagnostics = [
Expand All @@ -379,9 +377,15 @@ export function create (rawOptions: CreateOptions = {}): Register {
18003, // "No inputs were found in config file."
...(options.ignoreDiagnostics || [])
].map(Number)

const configDiagnosticList = filterDiagnostics(config.errors, ignoreDiagnostics)
const outputCache = new Map<string, string>()

const isScoped = options.scope ? (relname: string) => relname.charAt(0) !== '.' : () => true
const shouldIgnore = createIgnore(options.skipIgnore ? [] : (
options.ignore || ['(?:^|/)node_modules/']
).map(str => new RegExp(str)))

const diagnosticHost: _ts.FormatDiagnosticsHost = {
getNewLine: () => ts.sys.newLine,
getCurrentDirectory: () => cwd,
Expand Down Expand Up @@ -608,7 +612,7 @@ export function create (rawOptions: CreateOptions = {}): Register {
filterDiagnostics(result.diagnostics, ignoreDiagnostics) :
[]

if (diagnosticList.length) reportTSError(configDiagnosticList)
if (diagnosticList.length) reportTSError(diagnosticList)

return [result.outputText, result.sourceMapText as string]
}
Expand All @@ -628,18 +632,24 @@ export function create (rawOptions: CreateOptions = {}): Register {

let active = true
const enabled = (enabled?: boolean) => enabled === undefined ? active : (active = !!enabled)
const ignored = (fileName: string) => !active || !isScoped(fileName) || shouldIgnore(fileName, ignore)
const ignored = (fileName: string) => {
if (!active) return true
const relname = relative(cwd, fileName)
return !isScoped(relname) || shouldIgnore(relname)
}

return { ts, config, compile, getTypeInfo, ignored, enabled, options }
}

/**
* Check if the filename should be ignored.
*/
function shouldIgnore (filename: string, ignore: RegExp[]) {
const relname = normalizeSlashes(filename)
function createIgnore (ignore: RegExp[]) {
return (relname: string) => {
const path = normalizeSlashes(relname)

return ignore.some(x => x.test(relname))
return ignore.some(x => x.test(path))
}
}

/**
Expand Down

0 comments on commit aa6f36f

Please sign in to comment.