Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Partial fix for (handling webRoot): Issue #226 #543

Merged
merged 6 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,24 +277,30 @@ function getSourceMapPathOverrides(webRoot: string, sourceMapPathOverrides?: ISo
export function resolveWebRootPattern(webRoot: string, sourceMapPathOverrides: ISourceMapPathOverrides, warnOnMissing: boolean): ISourceMapPathOverrides {
const resolvedOverrides: ISourceMapPathOverrides = {};
for (let pattern in sourceMapPathOverrides) {
const replacePattern = sourceMapPathOverrides[pattern];
resolvedOverrides[pattern] = replacePattern;

const webRootIndex = replacePattern.indexOf('${webRoot}');
if (webRootIndex === 0) {
if (webRoot) {
resolvedOverrides[pattern] = replacePattern.replace('${webRoot}', webRoot);
} else if (warnOnMissing) {
logger.log('Warning: sourceMapPathOverrides entry contains ${webRoot}, but webRoot is not set');
}
} else if (webRootIndex > 0) {
logger.log('Warning: in a sourceMapPathOverrides entry, ${webRoot} is only valid at the beginning of the path');
}
const replacePattern = replaceWebRootInSourceMapPathOverridesEntry(webRoot, pattern, warnOnMissing);
const replacePatternValue = replaceWebRootInSourceMapPathOverridesEntry(webRoot, sourceMapPathOverrides[pattern], warnOnMissing);

resolvedOverrides[replacePattern] = replacePatternValue;
}

return resolvedOverrides;
}

function replaceWebRootInSourceMapPathOverridesEntry(webRoot: string, entry: string, warnOnMissing: boolean): string {
const webRootIndex = entry.indexOf('${webRoot}');
if (webRootIndex === 0) {
if (webRoot) {
return entry.replace('${webRoot}', webRoot);
} else if (warnOnMissing) {
logger.log('Warning: sourceMapPathOverrides entry contains ${webRoot}, but webRoot is not set');
}
} else if (webRootIndex > 0) {
logger.log('Warning: in a sourceMapPathOverrides entry, ${webRoot} is only valid at the beginning of the path');
}

return entry;
}

function getChromeSpawnHelperPath(): string {
if (path.basename(__dirname) === 'src') {
// For tests
Expand Down
13 changes: 9 additions & 4 deletions test/chromeDebugAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,13 @@ suite('ChromeDebugAdapter', () => {
assert.deepEqual(
resolveWebRootPattern(WEBROOT, <ISourceMapPathOverrides>{ '/src': '${webRoot}/app/src'}),
{ '/src': WEBROOT + '/app/src' });
assert.deepEqual(
resolveWebRootPattern(WEBROOT, <ISourceMapPathOverrides>{ '${webRoot}/src': '${webRoot}/app/src'}),
{ [WEBROOT + '/src']: WEBROOT + '/app/src'});
});

test(`ignores the webRoot pattern when it's not at the beginning of the string`, () => {
const overrides: ISourceMapPathOverrides = { '/src': '/app/${webRoot}/src'};
const overrides: ISourceMapPathOverrides = { '/another/${webRoot}/src': '/app/${webRoot}/src'};
assert.deepEqual(
resolveWebRootPattern(WEBROOT, overrides),
overrides);
Expand All @@ -150,19 +153,21 @@ suite('ChromeDebugAdapter', () => {
'/src*': '${webRoot}/app',
'*/app.js': '*/app.js',
'/src/app.js': '/src/${webRoot}',
'/app.js': '${webRoot}/app.js'
'/app.js': '${webRoot}/app.js',
'${webRoot}/app1.js': '${webRoot}/app.js'
};

const expOverrides: ISourceMapPathOverrides = {
'/src*': WEBROOT + '/app',
'*/app.js': '*/app.js',
'/src/app.js': '/src/${webRoot}',
'/app.js': WEBROOT + '/app.js'
'/app.js': WEBROOT + '/app.js',
[WEBROOT + '/app1.js']: WEBROOT + '/app.js'
};

assert.deepEqual(
resolveWebRootPattern(WEBROOT, overrides),
expOverrides);
});
})
});
});