Skip to content

Commit 3688396

Browse files
committed
debt - use getPathFromAmdModule instead of 'URI.parse(require.toUrl(xxx)).fsPath'
1 parent e9ed5e1 commit 3688396

23 files changed

Lines changed: 56 additions & 51 deletions

File tree

src/vs/base/node/paths.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import uri from 'vs/base/common/uri';
6+
import { getPathFromAmdModule } from 'vs/base/common/amd';
77

88
interface IPaths {
99
getAppDataPath(platform: string): string;
1010
getDefaultUserDataPath(platform: string): string;
1111
}
1212

13-
const pathsPath = uri.parse(require.toUrl('paths')).fsPath;
13+
const pathsPath = getPathFromAmdModule(require, 'paths');
1414
const paths = require.__$__nodeRequire<IPaths>(pathsPath);
1515
export const getAppDataPath = paths.getAppDataPath;
16-
export const getDefaultUserDataPath = paths.getDefaultUserDataPath;
16+
export const getDefaultUserDataPath = paths.getDefaultUserDataPath;

src/vs/base/node/processes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import * as nls from 'vs/nls';
1111
import { TPromise, TValueCallback, ErrorCallback } from 'vs/base/common/winjs.base';
1212
import * as Types from 'vs/base/common/types';
1313
import { IStringDictionary } from 'vs/base/common/collections';
14-
import URI from 'vs/base/common/uri';
1514
import * as Objects from 'vs/base/common/objects';
1615
import * as TPath from 'vs/base/common/paths';
1716
import * as Platform from 'vs/base/common/platform';
1817
import { LineDecoder } from 'vs/base/node/decoder';
1918
import { CommandOptions, ForkOptions, SuccessData, Source, TerminateResponse, TerminateResponseCode, Executable } from 'vs/base/common/processes';
19+
import { getPathFromAmdModule } from 'vs/base/common/amd';
2020
export { CommandOptions, ForkOptions, SuccessData, Source, TerminateResponse, TerminateResponseCode };
2121

2222
export type TProgressCallback<T> = (progress: T) => void;
@@ -54,7 +54,7 @@ export function terminateProcess(process: cp.ChildProcess, cwd?: string): Termin
5454
}
5555
} else if (Platform.isLinux || Platform.isMacintosh) {
5656
try {
57-
let cmd = URI.parse(require.toUrl('vs/base/node/terminateProcess.sh')).fsPath;
57+
let cmd = getPathFromAmdModule(require, 'vs/base/node/terminateProcess.sh');
5858
let result = cp.spawnSync(cmd, [process.pid.toString()]);
5959
if (result.error) {
6060
return { success: false, error: result.error };

src/vs/base/node/ps.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
'use strict';
77

88
import { exec } from 'child_process';
9-
import URI from 'vs/base/common/uri';
9+
10+
import { getPathFromAmdModule } from 'vs/base/common/amd';
1011

1112
export interface ProcessItem {
1213
name: string;
@@ -207,7 +208,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
207208
// The cpu usage value reported on Linux is the average over the process lifetime,
208209
// recalculate the usage over a one second interval
209210
// JSON.stringify is needed to escape spaces, https://github.com/nodejs/node/issues/6803
210-
let cmd = JSON.stringify(URI.parse(require.toUrl('vs/base/node/cpuUsage.sh')).fsPath);
211+
let cmd = JSON.stringify(getPathFromAmdModule(require, 'vs/base/node/cpuUsage.sh'));
211212
cmd += ' ' + pids.join(' ');
212213

213214
exec(cmd, {}, (err, stdout, stderr) => {

src/vs/base/node/stdFork.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as path from 'path';
99
import * as os from 'os';
1010
import * as net from 'net';
1111
import * as cp from 'child_process';
12-
import uri from 'vs/base/common/uri';
12+
import { getPathFromAmdModule } from 'vs/base/common/amd';
1313

1414
export interface IForkOpts {
1515
cwd?: string;
@@ -117,7 +117,7 @@ export function fork(modulePath: string, args: string[], options: IForkOpts, cal
117117
};
118118

119119
// Create the process
120-
let bootstrapperPath = (uri.parse(require.toUrl('./stdForkStart.js')).fsPath);
120+
let bootstrapperPath = (getPathFromAmdModule(require, './stdForkStart.js'));
121121
childProcess = cp.fork(bootstrapperPath, [modulePath].concat(args), {
122122
silent: true,
123123
cwd: options.cwd,

src/vs/base/parts/ipc/test/node/ipc.perf.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
import * as assert from 'assert';
99
import { Client } from 'vs/base/parts/ipc/node/ipc.cp';
10-
import uri from 'vs/base/common/uri';
1110
import { always } from 'vs/base/common/async';
1211
import { ITestChannel, TestServiceClient, ITestService } from './testService';
12+
import { getPathFromAmdModule } from 'vs/base/common/amd';
1313

1414
function createClient(): Client {
15-
return new Client(uri.parse(require.toUrl('bootstrap')).fsPath, {
15+
return new Client(getPathFromAmdModule(require, 'bootstrap'), {
1616
serverName: 'TestServer',
1717
env: { AMD_ENTRYPOINT: 'vs/base/parts/ipc/test/node/testApp', verbose: true }
1818
});
@@ -111,4 +111,4 @@ suite('IPC performance', () => {
111111
count += batch.length;
112112
});
113113
}
114-
});
114+
});

src/vs/base/test/node/processes/processes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import * as assert from 'assert';
99
import * as cp from 'child_process';
1010
import * as objects from 'vs/base/common/objects';
1111
import * as platform from 'vs/base/common/platform';
12-
import URI from 'vs/base/common/uri';
1312
import * as processes from 'vs/base/node/processes';
13+
import { getPathFromAmdModule } from 'vs/base/common/amd';
1414

1515
function fork(id: string): cp.ChildProcess {
1616
const opts: any = {
@@ -21,7 +21,7 @@ function fork(id: string): cp.ChildProcess {
2121
})
2222
};
2323

24-
return cp.fork(URI.parse(require.toUrl('bootstrap')).fsPath, ['--type=processTests'], opts);
24+
return cp.fork(getPathFromAmdModule(require, 'bootstrap'), ['--type=processTests'], opts);
2525
}
2626

2727
suite('Processes', () => {

src/vs/base/test/node/uri.test.perf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import * as assert from 'assert';
88
import URI from 'vs/base/common/uri';
99
import { readFileSync } from 'fs';
10+
import { getPathFromAmdModule } from 'vs/base/common/amd';
1011

1112
suite('URI - perf', function () {
1213

1314
let manyFileUris: URI[];
1415
setup(function () {
1516
manyFileUris = [];
16-
let data = readFileSync(URI.parse(require.toUrl('./uri.test.data.txt')).fsPath).toString();
17+
let data = readFileSync(getPathFromAmdModule(require, './uri.test.data.txt')).toString();
1718
let lines = data.split('\n');
1819
for (let line of lines) {
1920
manyFileUris.push(URI.file(line));

src/vs/base/test/node/zip/zip.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import * as assert from 'assert';
99
import * as path from 'path';
1010
import * as os from 'os';
11-
import URI from 'vs/base/common/uri';
1211
import { extract } from 'vs/base/node/zip';
1312
import { generateUuid } from 'vs/base/common/uuid';
1413
import { rimraf, exists } from 'vs/base/node/pfs';
1514
import { NullLogService } from 'vs/platform/log/common/log';
15+
import { getPathFromAmdModule } from 'vs/base/common/amd';
1616

17-
const fixtures = URI.parse(require.toUrl('./fixtures')).fsPath;
17+
const fixtures = getPathFromAmdModule(require, './fixtures');
1818

1919
suite('Zip', () => {
2020

src/vs/platform/environment/node/environmentService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import * as crypto from 'crypto';
88
import * as paths from 'vs/base/node/paths';
99
import * as os from 'os';
1010
import * as path from 'path';
11-
import URI from 'vs/base/common/uri';
1211
import { memoize } from 'vs/base/common/decorators';
1312
import pkg from 'vs/platform/node/package';
1413
import product from 'vs/platform/node/product';
1514
import { toLocalISOString } from 'vs/base/common/date';
1615
import { isWindows, isLinux } from 'vs/base/common/platform';
16+
import { getPathFromAmdModule } from 'vs/base/common/amd';
1717

1818
// Read this before there's any chance it is overwritten
1919
// Related to https://github.com/Microsoft/vscode/issues/30624
@@ -77,7 +77,7 @@ export class EnvironmentService implements IEnvironmentService {
7777
get args(): ParsedArgs { return this._args; }
7878

7979
@memoize
80-
get appRoot(): string { return path.dirname(URI.parse(require.toUrl('')).fsPath); }
80+
get appRoot(): string { return path.dirname(getPathFromAmdModule(require, '')); }
8181

8282
get execPath(): string { return this._execPath; }
8383

src/vs/platform/extensionManagement/node/extensionManagementService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ import { ExtensionsLifecycle } from 'vs/platform/extensionManagement/node/extens
4040
import { toErrorMessage } from 'vs/base/common/errorMessage';
4141
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
4242
import { isEngineValid } from 'vs/platform/extensions/node/extensionValidator';
43+
import { getPathFromAmdModule } from 'vs/base/common/amd';
4344

44-
const SystemExtensionsRoot = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', 'extensions'));
45+
const SystemExtensionsRoot = path.normalize(path.join(getPathFromAmdModule(require, ''), '..', 'extensions'));
4546
const ERROR_SCANNING_SYS_EXTENSIONS = 'scanningSystem';
4647
const ERROR_SCANNING_USER_EXTENSIONS = 'scanningUser';
4748
const INSTALL_ERROR_UNSET_UNINSTALLED = 'unsetUninstalled';

0 commit comments

Comments
 (0)