Skip to content

Commit

Permalink
Fix microsoft#63 - OS X webpack sourcemap issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Lourens committed Dec 21, 2015
1 parent dc3e750 commit 3b8942a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
10 changes: 2 additions & 8 deletions adapter/sourceMaps/sourceMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,7 @@ class SourceMap {

// Overwrite the sourcemap's sourceRoot with the version that's resolved to an absolute path,
// so the work above only has to be done once
if (this._absSourceRoot.startsWith('/')) {
// OSX paths
sm.sourceRoot = 'file://' + this._absSourceRoot;
} else {
// Windows paths
sm.sourceRoot = 'file:///' + this._absSourceRoot;
}
sm.sourceRoot = utils.pathToFileURL(this._absSourceRoot);

sm.sources = sm.sources.map((sourcePath: string) => {
// special-case webpack:/// prefixed sources which is kind of meaningless
Expand Down Expand Up @@ -339,7 +333,7 @@ class SourceMap {
*/
public generatedPositionFor(src: string, line: number, column: number, bias = Bias.GREATEST_LOWER_BOUND): SourceMap.Position {
if (this._sourcesAreURLs) {
src = 'file:///' + src;
src = utils.pathToFileURL(src);
} else if (this._absSourceRoot) {
// make input path relative to sourceRoot
src = Path.relative(this._absSourceRoot, src);
Expand Down
12 changes: 12 additions & 0 deletions test/webkit/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,16 @@ suite('Utilities', () => {
assert.equal(Utilities.lstrip('asdf', 'sdf'), 'asdf');
});
});

suite('pathToFileURL', () => {
const Utilities = getUtilities();

test('converts windows-style paths', () => {
assert.equal(Utilities.pathToFileURL('c:/code/app.js'), 'file:///c:/code/app.js');
});

test('converts unix-style paths', () => {
assert.equal(Utilities.pathToFileURL('/code/app.js'), 'file:///code/app.js');
});
});
});
10 changes: 10 additions & 0 deletions webkit/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,13 @@ export function lstrip(s: string, lStr: string): string {
s.substr(lStr.length) :
s;
}

/**
* Convert a local path to a file URL, like
* C:/code/app.js => file:///C:/code/app.js
* /code/app.js => file:///code/app.js
*/
export function pathToFileURL(path: string): string {
return (path.startsWith('/') ? 'file://' : 'file:///') +
path;
}

0 comments on commit 3b8942a

Please sign in to comment.