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

Commit

Permalink
Merge pull request #147 from llgcode/source-url-mapping
Browse files Browse the repository at this point in the history
add path mapping
  • Loading branch information
roblourens authored Jan 17, 2017
2 parents d7d8433 + cfe89fc commit 9503839
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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

0 comments on commit 9503839

Please sign in to comment.