Skip to content

Commit 907935c

Browse files
authored
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
1 parent 2397f3a commit 907935c

File tree

3 files changed

+101
-4
lines changed

3 files changed

+101
-4
lines changed

src/index.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ describe('ts-node', function () {
189189
}
190190

191191
expect(err.message).to.contain([
192-
`${join(__dirname, '../tests/throw.ts')}:3`,
192+
`${join(__dirname, '../tests/throw.ts')}:100`,
193193
' bar () { throw new Error(\'this is a demo\') }',
194194
' ^',
195195
'Error: this is a demo'
@@ -206,7 +206,7 @@ describe('ts-node', function () {
206206
}
207207

208208
expect(err.message).to.contain([
209-
`${join(__dirname, '../tests/throw.ts')}:3`,
209+
`${join(__dirname, '../tests/throw.ts')}:100`,
210210
' bar () { throw new Error(\'this is a demo\') }',
211211
' ^'
212212
].join('\n'))
@@ -611,7 +611,7 @@ describe('ts-node', function () {
611611
} catch (error) {
612612
expect(error.stack).to.contain([
613613
'Error: this is a demo',
614-
` at Foo.bar (${join(__dirname, '../tests/throw.ts')}:3:18)`
614+
` at Foo.bar (${join(__dirname, '../tests/throw.ts')}:100:18)`
615615
].join('\n'))
616616

617617
done()

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ export function create (rawOptions: CreateOptions = {}): Register {
420420
sourceMapSupport.install({
421421
environment: 'node',
422422
retrieveFile (path: string) {
423-
return outputCache.get(path)?.content || ''
423+
return outputCache.get(normalizeSlashes(path))?.content || ''
424424
}
425425
})
426426

tests/throw.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,101 @@
1+
// intentional whitespace to prove that sourcemaps are working. Throw should happen on line 100.
2+
// 100 lines is meant to be far more space than the helper functions would take.
13
class Foo {
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
299
constructor () { this.bar() }
3100
bar () { throw new Error('this is a demo') }
4101
}

0 commit comments

Comments
 (0)