From e888f55424a001df3ba6a93a5dff21984913d259 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Fri, 20 Nov 2015 17:50:28 -0800 Subject: [PATCH] Rename webRoot to cwd --- README.md | 2 +- adapter/pathTransformer.ts | 10 +++++----- package.json | 14 ++++++++++++-- test/adapter/pathTransformer.test.ts | 2 +- test/webkit/utilities.test.ts | 12 ++++++------ test/webkit/webKitDebugAdapter.test.ts | 2 +- webkit/utilities.ts | 8 ++++---- webkit/webKitAdapterInterfaces.d.ts | 8 +++++--- 8 files changed, 35 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4eecb7a..5cdaa05 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Debugger for Chrome -A VS Code extension to debug your JavaScript code in the Chrome browser, or other targets that support the Chrome debug protocol. +A VS Code extension to debug your JavaScript code in the Chrome browser, or other targets that support the Chrome Debugging Protocol. ![Screenshot](images/screenshot.png) diff --git a/adapter/pathTransformer.ts b/adapter/pathTransformer.ts index 62b8915..4e292ec 100644 --- a/adapter/pathTransformer.ts +++ b/adapter/pathTransformer.ts @@ -14,17 +14,17 @@ interface IPendingBreakpoint { * Converts a local path from Code to a path on the target. */ export class PathTransformer implements IDebugTransformer { - private _clientCWD: string; + private _webRoot: string; private _clientPathToWebkitUrl = new Map(); private _webkitUrlToClientPath = new Map(); private _pendingBreakpointsByPath = new Map(); public launch(args: ILaunchRequestArgs): void { - this._clientCWD = args.cwd; + this._webRoot = args.webRoot || args.cwd; } public attach(args: IAttachRequestArgs): void { - this._clientCWD = args.cwd; + this._webRoot = args.webRoot || args.cwd; } public setBreakpoints(args: ISetBreakpointsArgs): Promise { @@ -56,7 +56,7 @@ export class PathTransformer implements IDebugTransformer { public scriptParsed(event: DebugProtocol.Event): void { const webkitUrl: string = event.body.scriptUrl; - const clientPath = utils.webkitUrlToClientPath(this._clientCWD, webkitUrl); + const clientPath = utils.webkitUrlToClientPath(this._webRoot, webkitUrl); this._clientPathToWebkitUrl.set(clientPath, webkitUrl); this._webkitUrlToClientPath.set(webkitUrl, clientPath); event.body.scriptUrl = clientPath; @@ -75,7 +75,7 @@ export class PathTransformer implements IDebugTransformer { if (frame.source.path) { const clientPath = this._webkitUrlToClientPath.has(frame.source.path) ? this._webkitUrlToClientPath.get(frame.source.path) : - utils.webkitUrlToClientPath(this._clientCWD, frame.source.path); + utils.webkitUrlToClientPath(this._webRoot, frame.source.path); if (clientPath) { frame.source.path = clientPath; diff --git a/package.json b/package.json index 575be52..7326ccd 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,12 @@ }, "cwd": { "type": "string", - "description": "Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.", + "description": "DEPRECATED - renamed to webRoot", + "default": "." + }, + "webRoot": { + "type": "string", + "description": "When the 'url' field is specified, this specifies the workspace relative or absolute path to the webserver root.", "default": "." }, "runtimeExecutable": { @@ -153,7 +158,12 @@ }, "cwd": { "type": "string", - "description": "Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.", + "description": "DEPRECATED - renamed to webRoot", + "default": "." + }, + "webRoot": { + "type": "string", + "description": "When the 'url' field is specified, this specifies the workspace relative or absolute path to the webserver root.", "default": "." } } diff --git a/test/adapter/pathTransformer.test.ts b/test/adapter/pathTransformer.test.ts index 1dc7572..a917b8d 100644 --- a/test/adapter/pathTransformer.test.ts +++ b/test/adapter/pathTransformer.test.ts @@ -32,7 +32,7 @@ suite('PathTransformer', () => { utilsMock = testUtils.getSinonMock(mockedObj); utilsMock.expects('webkitUrlToClientPath') .once() - .withExactArgs(/*cwd=*/undefined, TARGET_URL).returns(CLIENT_URL); + .withExactArgs(/*webRoot=*/undefined, TARGET_URL).returns(CLIENT_URL); mockery.registerMock('../webkit/utilities', mockedObj); transformer = createTransformer(); diff --git a/test/webkit/utilities.test.ts b/test/webkit/utilities.test.ts index ecd06f8..f6565e8 100644 --- a/test/webkit/utilities.test.ts +++ b/test/webkit/utilities.test.ts @@ -180,7 +180,7 @@ suite('Utilities', () => { 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'; - const TEST_CWD = 'c:\\site'; + const TEST_WEB_ROOT = 'c:\\site'; function Utilities(): typeof _Utilities { return require(MODULE_UNDER_TEST); @@ -190,12 +190,12 @@ suite('Utilities', () => { assert.equal(Utilities().webkitUrlToClientPath('', ''), ''); }); - test('an empty string is returned when the cwd is missing', () => { + test('an empty string is returned when the webRoot is missing', () => { assert.equal(Utilities().webkitUrlToClientPath(null, TEST_WEBKIT_HTTP_URL), ''); }); test('a url without a path returns an empty string', () => { - assert.equal(Utilities().webkitUrlToClientPath(TEST_CWD, 'http://site.com'), ''); + assert.equal(Utilities().webkitUrlToClientPath(TEST_WEB_ROOT, 'http://site.com'), ''); }); test('it searches the disk for a path that exists, built from the url', () => { @@ -203,7 +203,7 @@ suite('Utilities', () => { if (path !== TEST_CLIENT_PATH) throw new Error('Not found'); }; mockery.registerMock('fs', { statSync }); - assert.equal(Utilities().webkitUrlToClientPath(TEST_CWD, TEST_WEBKIT_HTTP_URL), TEST_CLIENT_PATH); + assert.equal(Utilities().webkitUrlToClientPath(TEST_WEB_ROOT, TEST_WEBKIT_HTTP_URL), TEST_CLIENT_PATH); }); test(`returns an empty string when it can't resolve a url`, () => { @@ -211,7 +211,7 @@ suite('Utilities', () => { throw new Error('Not found'); }; mockery.registerMock('fs', { statSync }); - assert.equal(Utilities().webkitUrlToClientPath(TEST_CWD, TEST_WEBKIT_HTTP_URL), ''); + assert.equal(Utilities().webkitUrlToClientPath(TEST_WEB_ROOT, TEST_WEBKIT_HTTP_URL), ''); }); test('file:/// urls are returned canonicalized', () => { @@ -220,7 +220,7 @@ suite('Utilities', () => { test('uri encodings are fixed', () => { const clientPath = 'c:\\project\\path with spaces\\script.js'; - assert.equal(Utilities().webkitUrlToClientPath(TEST_CWD, 'file:///' + encodeURI(clientPath)), clientPath); + assert.equal(Utilities().webkitUrlToClientPath(TEST_WEB_ROOT, 'file:///' + encodeURI(clientPath)), clientPath); }); }); diff --git a/test/webkit/webKitDebugAdapter.test.ts b/test/webkit/webKitDebugAdapter.test.ts index 8de4252..b2401f0 100644 --- a/test/webkit/webKitDebugAdapter.test.ts +++ b/test/webkit/webKitDebugAdapter.test.ts @@ -240,7 +240,7 @@ suite('WebKitDebugAdapter', () => { platform: () => 'win32' }); const wkda = instantiateWKDA(); - return wkda.launch({ file: 'a.js', runtimeArguments: ['abc', 'def'], cwd: 'c:/' }).then(() => { + return wkda.launch({ file: 'a.js', runtimeArgs: ['abc', 'def'], cwd: 'c:/' }).then(() => { assert(spawnCalled); }); }); diff --git a/webkit/utilities.ts b/webkit/utilities.ts index 7d06804..671071f 100644 --- a/webkit/utilities.ts +++ b/webkit/utilities.ts @@ -216,7 +216,7 @@ function pad0(n: number, numChars: number): string { * http://localhost/scripts/code.js => d:/app/scripts/code.js * file:///d:/scripts/code.js => d:/scripts/code.js */ -export function webkitUrlToClientPath(cwd: string, url: string): string { +export function webkitUrlToClientPath(webRoot: string, url: string): string { if (!url) { return ''; } @@ -230,11 +230,11 @@ export function webkitUrlToClientPath(cwd: string, url: string): string { } // If we don't have the client workingDirectory for some reason, don't try to map the url to a client path - if (!cwd) { + if (!webRoot) { return ''; } - // Search the filesystem under our cwd for the file that best matches the given url + // Search the filesystem under the webRoot for the file that best matches the given url let pathName = nodeUrl.parse(canonicalizeUrl(url)).pathname; if (!pathName || pathName === '/') { return ''; @@ -245,7 +245,7 @@ export function webkitUrlToClientPath(cwd: string, url: string): string { pathName = pathName.replace(/\//g, path.sep); const pathParts = pathName.split(path.sep); while (pathParts.length > 0) { - const clientPath = path.join(cwd, pathParts.join(path.sep)); + const clientPath = path.join(webRoot, pathParts.join(path.sep)); if (existsSync(clientPath)) { return canonicalizeUrl(clientPath); } diff --git a/webkit/webKitAdapterInterfaces.d.ts b/webkit/webKitAdapterInterfaces.d.ts index d0519f2..0a1ed58 100644 --- a/webkit/webKitAdapterInterfaces.d.ts +++ b/webkit/webKitAdapterInterfaces.d.ts @@ -1,6 +1,7 @@ interface ILaunchRequestArgs extends DebugProtocol.LaunchRequestArguments { - cwd: string; - runtimeArguments?: string[]; + cwd: string; /* Automatically set by VS Code to the currently opened folder */ + webRoot?: string; + runtimeArgs?: string[]; runtimeExecutable?: string; file?: string; url?: string; @@ -12,7 +13,8 @@ interface ILaunchRequestArgs extends DebugProtocol.LaunchRequestArguments { } interface IAttachRequestArgs extends DebugProtocol.AttachRequestArguments { - cwd: string; + cwd: string; /* Automatically set by VS Code to the currently opened folder */ + webRoot?: string; port: number; sourceMaps?: boolean; outDir?: string;