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

add path mapping #147

Merged
merged 1 commit into from
Jan 17, 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
1 change: 1 addition & 0 deletions src/debugAdapterInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type ISourceMapPathOverrides = { [pattern: string]: string };
*/
export interface ICommonRequestArgs {
webRoot?: string;
pathMapping?: {[url: string]: string};
outDir?: string;
outFiles?: string[];
sourceMaps?: boolean;
Expand Down
33 changes: 32 additions & 1 deletion src/transformers/urlPathTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ import * as ChromeUtils from '../chrome/chromeUtils';
import {ChromeDebugAdapter} from '../chrome/chromeDebugAdapter';

import * as path from 'path';
import * as url from 'url';

/**
* Converts a local path from Code to a path on the target.
*/
export class UrlPathTransformer extends BasePathTransformer {
private _webRoot: string;
private _pathMapping: {[url: string]: string};
private _clientPathToTargetUrl = new Map<string, string>();
private _targetUrlToClientPath = new Map<string, string>();

public launch(args: ILaunchRequestArgs): Promise<void> {
this._webRoot = args.webRoot;
this._pathMapping = args.pathMapping;
return super.launch(args);
}

Expand Down Expand Up @@ -61,8 +64,36 @@ export class UrlPathTransformer extends BasePathTransformer {
}

public scriptParsed(scriptUrl: string): string {
const clientPath = ChromeUtils.targetUrlToClientPath(this._webRoot, scriptUrl);
let clientPath: string;
const parsedUrl = url.parse(scriptUrl);
const origin = `${parsedUrl.protocol}//${parsedUrl.host}`;

let p = parsedUrl.pathname;
while (p) {
let localPath = this._pathMapping[origin + p];
if (localPath) {
clientPath = path.join(localPath, parsedUrl.pathname.substring(p.length));
break;
}
localPath = this._pathMapping[p];
if (localPath) {
clientPath = path.join(localPath, parsedUrl.pathname.substring(p.length));
break;
}
if (p === "/") {
break;
}
p = path.dirname(p);
if (p !== "/") {
// We need to differianciate folder and files by having a leading '/' except for root.
p = p + "/";
}
}

if (!clientPath) {
// Deprecated webRoot
clientPath = ChromeUtils.targetUrlToClientPath(this._webRoot, scriptUrl);
}
if (!clientPath) {
// It's expected that eval scripts (eval://) won't be resolved
if (!scriptUrl.startsWith(ChromeDebugAdapter.PLACEHOLDER_URL_PROTOCOL)) {
Expand Down