From 907935c382f4a35c5a186eb2a49162b1e1ea5b12 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Wed, 13 May 2020 01:13:23 -0400 Subject: [PATCH] Normalize paths when looking up items on outputCache (#1038) * Normalize paths when looking up items on outputCache * Tweak tests to be absolutely sure sourcemaps are working --- src/index.spec.ts | 6 +-- src/index.ts | 2 +- tests/throw.ts | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 4 deletions(-) diff --git a/src/index.spec.ts b/src/index.spec.ts index 0d41f65d2..064f42ee0 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -189,7 +189,7 @@ describe('ts-node', function () { } expect(err.message).to.contain([ - `${join(__dirname, '../tests/throw.ts')}:3`, + `${join(__dirname, '../tests/throw.ts')}:100`, ' bar () { throw new Error(\'this is a demo\') }', ' ^', 'Error: this is a demo' @@ -206,7 +206,7 @@ describe('ts-node', function () { } expect(err.message).to.contain([ - `${join(__dirname, '../tests/throw.ts')}:3`, + `${join(__dirname, '../tests/throw.ts')}:100`, ' bar () { throw new Error(\'this is a demo\') }', ' ^' ].join('\n')) @@ -611,7 +611,7 @@ describe('ts-node', function () { } catch (error) { expect(error.stack).to.contain([ 'Error: this is a demo', - ` at Foo.bar (${join(__dirname, '../tests/throw.ts')}:3:18)` + ` at Foo.bar (${join(__dirname, '../tests/throw.ts')}:100:18)` ].join('\n')) done() diff --git a/src/index.ts b/src/index.ts index e37442a90..9ee508ad4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -420,7 +420,7 @@ export function create (rawOptions: CreateOptions = {}): Register { sourceMapSupport.install({ environment: 'node', retrieveFile (path: string) { - return outputCache.get(path)?.content || '' + return outputCache.get(normalizeSlashes(path))?.content || '' } }) diff --git a/tests/throw.ts b/tests/throw.ts index 1183d9ff5..dbd4cbc2e 100644 --- a/tests/throw.ts +++ b/tests/throw.ts @@ -1,4 +1,101 @@ +// intentional whitespace to prove that sourcemaps are working. Throw should happen on line 100. +// 100 lines is meant to be far more space than the helper functions would take. class Foo { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + constructor () { this.bar() } bar () { throw new Error('this is a demo') } }