clientUrl -> clientPath
This commit is contained in:
Родитель
13142273d3
Коммит
fa14fe559b
|
@ -14,7 +14,8 @@ interface IPendingBreakpoint {
|
|||
*/
|
||||
export class PathTransformer implements IDebugTransformer {
|
||||
private _clientCWD: string;
|
||||
private _clientUrlToWebkitUrl = new Map<string, string>();
|
||||
private _clientPathToWebkitUrl = new Map<string, string>();
|
||||
private _webkitUrlToClientPath = new Map<string, string>();
|
||||
private _pendingBreakpointsByUrl = new Map<string, IPendingBreakpoint>();
|
||||
|
||||
public launch(args: ILaunchRequestArgs): void {
|
||||
|
@ -29,8 +30,8 @@ export class PathTransformer implements IDebugTransformer {
|
|||
return new Promise<void>(resolve => {
|
||||
if (args.source.path) {
|
||||
const url = utils.canonicalizeUrl(args.source.path);
|
||||
if (this._clientUrlToWebkitUrl.has(url)) {
|
||||
args.source.path = this._clientUrlToWebkitUrl.get(url);
|
||||
if (this._clientPathToWebkitUrl.has(url)) {
|
||||
args.source.path = this._clientPathToWebkitUrl.get(url);
|
||||
resolve();
|
||||
} else {
|
||||
utils.Logger.log(`No target url cached for client url: ${url}, waiting for target script to be loaded.`);
|
||||
|
@ -46,18 +47,18 @@ export class PathTransformer implements IDebugTransformer {
|
|||
}
|
||||
|
||||
public clearTargetContext(): void {
|
||||
this._clientUrlToWebkitUrl = new Map<string, string>();
|
||||
this._clientPathToWebkitUrl = new Map<string, string>();
|
||||
}
|
||||
|
||||
public scriptParsed(event: DebugProtocol.Event): void {
|
||||
const webkitUrl: string = event.body.scriptUrl;
|
||||
const clientUrl = utils.webkitUrlToClientUrl(this._clientCWD, webkitUrl);
|
||||
this._clientUrlToWebkitUrl.set(clientUrl, webkitUrl);
|
||||
event.body.scriptUrl = clientUrl;
|
||||
const clientPath = utils.webkitUrlToClientPath(this._clientCWD, webkitUrl);
|
||||
this._clientPathToWebkitUrl.set(clientPath, webkitUrl);
|
||||
event.body.scriptUrl = clientPath;
|
||||
|
||||
if (this._pendingBreakpointsByUrl.has(clientUrl)) {
|
||||
const pendingBreakpoint = this._pendingBreakpointsByUrl.get(clientUrl);
|
||||
this._pendingBreakpointsByUrl.delete(clientUrl);
|
||||
if (this._pendingBreakpointsByUrl.has(clientPath)) {
|
||||
const pendingBreakpoint = this._pendingBreakpointsByUrl.get(clientPath);
|
||||
this._pendingBreakpointsByUrl.delete(clientPath);
|
||||
this.setBreakpoints(pendingBreakpoint.args).then(pendingBreakpoint.resolve);
|
||||
}
|
||||
}
|
||||
|
@ -67,9 +68,9 @@ export class PathTransformer implements IDebugTransformer {
|
|||
// Try to resolve the url to a path in the workspace. If it's not in the workspace,
|
||||
// just use the script.url as-is.
|
||||
if (frame.source.path) {
|
||||
const clientUrl = utils.webkitUrlToClientUrl(this._clientCWD, frame.source.path);
|
||||
if (clientUrl) {
|
||||
frame.source.path = clientUrl;
|
||||
const clientPath = utils.webkitUrlToClientPath(this._clientCWD, frame.source.path);
|
||||
if (clientPath) {
|
||||
frame.source.path = clientPath;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -30,7 +30,7 @@ suite('PathTransformer', () => {
|
|||
// Mock the utils functions
|
||||
const mockedObj = testUtils.getDefaultUtilitiesMock();
|
||||
utilsMock = testUtils.getSinonMock(mockedObj);
|
||||
utilsMock.expects('webkitUrlToClientUrl')
|
||||
utilsMock.expects('webkitUrlToClientPath')
|
||||
.once()
|
||||
.withExactArgs(/*cwd=*/undefined, TARGET_URL).returns(CLIENT_URL);
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ suite('Utilities', () => {
|
|||
});
|
||||
});
|
||||
|
||||
suite('webkitUrlToClientUrl()', () => {
|
||||
suite('webkitUrlToClientPath()', () => {
|
||||
const TEST_CLIENT_PATH = 'c:/site/scripts/a.js';
|
||||
const TEST_WEBKIT_LOCAL_URL = 'file:///' + TEST_CLIENT_PATH;
|
||||
const TEST_WEBKIT_HTTP_URL = 'http://site.com/page/scripts/a.js';
|
||||
|
@ -176,15 +176,15 @@ suite('Utilities', () => {
|
|||
}
|
||||
|
||||
test('an empty string is returned for a missing url', () => {
|
||||
assert.equal(Utilities().webkitUrlToClientUrl('', ''), '');
|
||||
assert.equal(Utilities().webkitUrlToClientPath('', ''), '');
|
||||
});
|
||||
|
||||
test('an empty string is returned when the cwd is missing', () => {
|
||||
assert.equal(Utilities().webkitUrlToClientUrl(null, TEST_WEBKIT_HTTP_URL), '');
|
||||
assert.equal(Utilities().webkitUrlToClientPath(null, TEST_WEBKIT_HTTP_URL), '');
|
||||
});
|
||||
|
||||
test('a url without a path returns an empty string', () => {
|
||||
assert.equal(Utilities().webkitUrlToClientUrl(TEST_CWD, 'http://site.com'), '');
|
||||
assert.equal(Utilities().webkitUrlToClientPath(TEST_CWD, 'http://site.com'), '');
|
||||
});
|
||||
|
||||
test('it searches the disk for a path that exists, built from the url', () => {
|
||||
|
@ -192,7 +192,7 @@ suite('Utilities', () => {
|
|||
if (path !== TEST_CLIENT_PATH) throw new Error('Not found');
|
||||
};
|
||||
mockery.registerMock('fs', { statSync });
|
||||
assert.equal(Utilities().webkitUrlToClientUrl(TEST_CWD, TEST_WEBKIT_HTTP_URL), TEST_CLIENT_PATH);
|
||||
assert.equal(Utilities().webkitUrlToClientPath(TEST_CWD, TEST_WEBKIT_HTTP_URL), TEST_CLIENT_PATH);
|
||||
});
|
||||
|
||||
test(`returns an empty string when it can't resolve a url`, () => {
|
||||
|
@ -200,16 +200,16 @@ suite('Utilities', () => {
|
|||
throw new Error('Not found');
|
||||
};
|
||||
mockery.registerMock('fs', { statSync });
|
||||
assert.equal(Utilities().webkitUrlToClientUrl(TEST_CWD, TEST_WEBKIT_HTTP_URL), '');
|
||||
assert.equal(Utilities().webkitUrlToClientPath(TEST_CWD, TEST_WEBKIT_HTTP_URL), '');
|
||||
});
|
||||
|
||||
test('file:/// urls are returned canonicalized', () => {
|
||||
assert.equal(Utilities().webkitUrlToClientUrl('', TEST_WEBKIT_LOCAL_URL), TEST_CLIENT_PATH);
|
||||
assert.equal(Utilities().webkitUrlToClientPath('', TEST_WEBKIT_LOCAL_URL), TEST_CLIENT_PATH);
|
||||
});
|
||||
|
||||
test('uri encodings are fixed', () => {
|
||||
const clientPath = 'c:/project/path with spaces/script.js';
|
||||
assert.equal(Utilities().webkitUrlToClientUrl(TEST_CWD, 'file:///' + encodeURI(clientPath)), clientPath);
|
||||
assert.equal(Utilities().webkitUrlToClientPath(TEST_CWD, 'file:///' + encodeURI(clientPath)), clientPath);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ export class Logger {
|
|||
* http://localhost/scripts/code.js => d:/app/scripts/code.js
|
||||
* file:///d:/scripts/code.js => d:/scripts/code.js
|
||||
*/
|
||||
export function webkitUrlToClientUrl(cwd: string, url: string): string {
|
||||
export function webkitUrlToClientPath(cwd: string, url: string): string {
|
||||
if (!url) {
|
||||
return '';
|
||||
}
|
||||
|
@ -222,10 +222,10 @@ export function webkitUrlToClientUrl(cwd: string, url: string): string {
|
|||
|
||||
const pathParts = pathName.split('/');
|
||||
while (pathParts.length > 0) {
|
||||
const clientUrl = path.join(cwd, pathParts.join('/'));
|
||||
const canClientUrl = canonicalizeUrl(clientUrl); // path.join will change / to \
|
||||
if (existsSync(canClientUrl)) {
|
||||
return canonicalizeUrl(canClientUrl);
|
||||
const clientPath = path.join(cwd, pathParts.join('/'));
|
||||
const canClientPath = canonicalizeUrl(clientPath); // path.join will change / to \
|
||||
if (existsSync(canClientPath)) {
|
||||
return canonicalizeUrl(canClientPath);
|
||||
}
|
||||
|
||||
pathParts.shift();
|
||||
|
|
Загрузка…
Ссылка в новой задаче