Rename webRoot to cwd
This commit is contained in:
Родитель
1aa9c0d69b
Коммит
e888f55424
|
@ -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)
|
||||
|
||||
|
|
|
@ -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<string, string>();
|
||||
private _webkitUrlToClientPath = new Map<string, string>();
|
||||
private _pendingBreakpointsByPath = new Map<string, IPendingBreakpoint>();
|
||||
|
||||
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<void> {
|
||||
|
@ -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;
|
||||
|
|
14
package.json
14
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": "."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче