Fix #63 - OS X webpack sourcemap issue
This commit is contained in:
Родитель
dc3e7503a1
Коммит
3b8942a48f
|
@ -260,13 +260,7 @@ class SourceMap {
|
||||||
|
|
||||||
// Overwrite the sourcemap's sourceRoot with the version that's resolved to an absolute path,
|
// 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
|
// so the work above only has to be done once
|
||||||
if (this._absSourceRoot.startsWith('/')) {
|
sm.sourceRoot = utils.pathToFileURL(this._absSourceRoot);
|
||||||
// OSX paths
|
|
||||||
sm.sourceRoot = 'file://' + this._absSourceRoot;
|
|
||||||
} else {
|
|
||||||
// Windows paths
|
|
||||||
sm.sourceRoot = 'file:///' + this._absSourceRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
sm.sources = sm.sources.map((sourcePath: string) => {
|
sm.sources = sm.sources.map((sourcePath: string) => {
|
||||||
// special-case webpack:/// prefixed sources which is kind of meaningless
|
// 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 {
|
public generatedPositionFor(src: string, line: number, column: number, bias = Bias.GREATEST_LOWER_BOUND): SourceMap.Position {
|
||||||
if (this._sourcesAreURLs) {
|
if (this._sourcesAreURLs) {
|
||||||
src = 'file:///' + src;
|
src = utils.pathToFileURL(src);
|
||||||
} else if (this._absSourceRoot) {
|
} else if (this._absSourceRoot) {
|
||||||
// make input path relative to sourceRoot
|
// make input path relative to sourceRoot
|
||||||
src = Path.relative(this._absSourceRoot, src);
|
src = Path.relative(this._absSourceRoot, src);
|
||||||
|
|
|
@ -439,4 +439,16 @@ suite('Utilities', () => {
|
||||||
assert.equal(Utilities.lstrip('asdf', 'sdf'), 'asdf');
|
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.substr(lStr.length) :
|
||||||
s;
|
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;
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче