Fix #63 - OS X webpack sourcemap issue

This commit is contained in:
Rob Lourens 2015-12-21 13:39:24 -08:00
Родитель dc3e7503a1
Коммит 3b8942a48f
3 изменённых файлов: 24 добавлений и 8 удалений

Просмотреть файл

@ -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
@ -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);

Просмотреть файл

@ -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');
});
});
});

Просмотреть файл

@ -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;
}