Skip to content

Commit 75aa3a8

Browse files
ornarieceornariece
and
ornariece
authored
fix(typescript): Original source absolute path resolution updates (#129)
If I'm getting this correctly, the absolute path to the original source file should be solved relatively not from the source map root directory, but rather from the source map file's parent directory. A slight nuance that breaks the mapping when using a nested directory structure for the generated source files. The change required allowing a recursive check of the source map root directory when checking for `.map` files. Co-authored-by: ornariece <[email protected]>
1 parent cc31889 commit 75aa3a8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ export class Session extends DebugSession {
745745
return false;
746746
}
747747
try {
748-
let fileNames = fs.readdirSync(filePath);
748+
let fileNames = fs.readdirSync(filePath, { encoding: null, recursive: true });
749749
for (let fn of fileNames) {
750750
if (extensions.some(ext => fn.endsWith(ext))) {
751751
return true;

src/SourceMaps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ class SourceMapCache {
132132
if (path.isAbsolute(originalSource)) {
133133
// we have an absolute path already, so generate a relative path to the current dir
134134
originalSourceAbsolutePath = originalSource;
135-
originalSourceRelative = path.relative(this._sourceMapRoot, originalSourceAbsolutePath);
135+
originalSourceRelative = path.relative(path.dirname(mapFullPath), originalSourceAbsolutePath);
136136
preferAbsolute = true;
137137
} else {
138138
// generate relative path from map to ts file
139139
originalSourceRelative = normalizePathForRemote(originalSource);
140140
// map has relative path back to original source, resolve for absolute path
141-
originalSourceAbsolutePath = path.resolve(this._sourceMapRoot, originalSourceRelative);
141+
originalSourceAbsolutePath = path.resolve(path.dirname(mapFullPath), originalSourceRelative);
142142
}
143143

144144
// collect all relevant path info, used for resolving original->generated and generated->original

0 commit comments

Comments
 (0)