Replace deprecated fs API
This commit is contained in:
Родитель
3493452dae
Коммит
0248563c4d
|
@ -12,7 +12,7 @@ const MODULE_UNDER_TEST = '../../webkit/utilities';
|
|||
suite('Utilities', () => {
|
||||
setup(() => {
|
||||
mockery.enable({ useCleanCache: true });
|
||||
mockery.registerMock('fs', { statSync: () => { }});
|
||||
mockery.registerMock('fs', { statSync: () => { } });
|
||||
mockery.registerMock('os', { platform: () => 'win32' });
|
||||
mockery.registerAllowable(MODULE_UNDER_TEST);
|
||||
});
|
||||
|
@ -96,4 +96,17 @@ suite('Utilities', () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
suite('existsSync()', () => {
|
||||
test('it returns false when statSync throws', () => {
|
||||
const statSync = (path: string) => {
|
||||
if (path.indexOf('notfound') >= 0) throw new Error('Not found');
|
||||
};
|
||||
mockery.registerMock('fs', { statSync });
|
||||
|
||||
const Utilities: typeof _Utilities = require(MODULE_UNDER_TEST);
|
||||
assert.equal(Utilities.existsSync('exists'), true);
|
||||
assert.equal(Utilities.existsSync('thisfilenotfound'), false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,16 +13,6 @@ const DEFAULT_CHROME_PATH = {
|
|||
};
|
||||
|
||||
export function getBrowserPath(): string {
|
||||
function existsSync(path: string): boolean {
|
||||
try {
|
||||
fs.statSync(path);
|
||||
return true;
|
||||
} catch (e) {
|
||||
// doesn't exist
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const platform = getPlatform();
|
||||
if (platform === Platform.OSX) {
|
||||
return existsSync(DEFAULT_CHROME_PATH.OSX) ? DEFAULT_CHROME_PATH.OSX : null;
|
||||
|
@ -50,6 +40,19 @@ export function getPlatform(): Platform {
|
|||
Platform.Linux;
|
||||
}
|
||||
|
||||
/**
|
||||
* Node's fs.existsSync is deprecated, implement it in terms of statSync
|
||||
*/
|
||||
export function existsSync(path: string): boolean {
|
||||
try {
|
||||
fs.statSync(path);
|
||||
return true;
|
||||
} catch (e) {
|
||||
// doesn't exist
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export class DebounceHelper {
|
||||
private waitToken: NodeJS.Timer;
|
||||
|
||||
|
|
|
@ -8,9 +8,8 @@ import {WebKitConnection} from './webKitConnection';
|
|||
import * as Utilities from './utilities';
|
||||
|
||||
import {spawn, ChildProcess} from 'child_process';
|
||||
import * as nodeUrl from 'url';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as NodeUrl from 'url';
|
||||
import * as Path from 'path';
|
||||
|
||||
interface IPendingBreakpoint {
|
||||
resolve: (response: SetBreakpointsResponseBody) => void;
|
||||
|
@ -480,15 +479,15 @@ export class WebKitDebugAdapter implements IDebugAdapter {
|
|||
}
|
||||
|
||||
// Search the filesystem under our cwd for the file that best matches the given url
|
||||
const pathName = nodeUrl.parse(canonicalizeUrl(url)).pathname;
|
||||
const pathName = NodeUrl.parse(canonicalizeUrl(url)).pathname;
|
||||
if (!pathName) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const pathParts = pathName.split('/');
|
||||
while (pathParts.length > 0) {
|
||||
const clientUrl = path.join(this._clientCWD, pathParts.join('/'));
|
||||
if (fs.existsSync(clientUrl)) {
|
||||
const clientUrl = Path.join(this._clientCWD, pathParts.join('/'));
|
||||
if (Utilities.existsSync(clientUrl)) {
|
||||
return canonicalizeUrl(clientUrl); // path.join will change / to \
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче