Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Download file:// sourcemaps correctly. Fix #205, fix Microsoft/vscode…
Browse files Browse the repository at this point in the history
…-chrome-debug#460
  • Loading branch information
roblourens committed Aug 14, 2017
1 parent 9881b3c commit a78782b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/sourceMaps/sourceMapFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ function getSourceMapContent(pathToGenerated: string, mapPath: string): Promise<

function loadSourceMapContents(mapPathOrURL: string): Promise<string> {
let contentsP: Promise<string>;
if (utils.isURL(mapPathOrURL)) {
if (utils.isURL(mapPathOrURL) && !utils.isFileUrl(mapPathOrURL)) {
logger.log(`SourceMaps.loadSourceMapContents: Downloading sourcemap file from ${mapPathOrURL}`);
contentsP = downloadSourceMapContents(mapPathOrURL).catch(e => {
logger.error(`SourceMaps.loadSourceMapContents: Could not download sourcemap from ${mapPathOrURL}`);
return null;
});
} else {
mapPathOrURL = utils.canonicalizeUrl(mapPathOrURL);
contentsP = new Promise((resolve, reject) => {
logger.log(`SourceMaps.loadSourceMapContents: Reading local sourcemap file from ${mapPathOrURL}`);
fs.readFile(mapPathOrURL, (err, data) => {
Expand Down
6 changes: 5 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,15 @@ export function canonicalizeUrl(urlOrPath: string): string {
return urlOrPath;
}

export function isFileUrl(candidate: string): boolean {
return candidate.startsWith('file:///');
}

/**
* If urlOrPath is a file URL, removes the 'file:///', adjusting for platform differences
*/
export function fileUrlToPath(urlOrPath: string): string {
if (urlOrPath.startsWith('file:///')) {
if (isFileUrl(urlOrPath)) {
urlOrPath = urlOrPath.replace('file:///', '');
urlOrPath = decodeURIComponent(urlOrPath);
if (urlOrPath[0] !== '/' && !urlOrPath.match(/^[A-Za-z]:/)) {
Expand Down

0 comments on commit a78782b

Please sign in to comment.