提交 36883965 编写于 作者: J Johannes Rieken

debt - use getPathFromAmdModule instead of 'URI.parse(require.toUrl(xxx)).fsPath'

上级 e9ed5e19
......@@ -3,14 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import uri from 'vs/base/common/uri';
import { getPathFromAmdModule } from 'vs/base/common/amd';
interface IPaths {
getAppDataPath(platform: string): string;
getDefaultUserDataPath(platform: string): string;
}
const pathsPath = uri.parse(require.toUrl('paths')).fsPath;
const pathsPath = getPathFromAmdModule(require, 'paths');
const paths = require.__$__nodeRequire<IPaths>(pathsPath);
export const getAppDataPath = paths.getAppDataPath;
export const getDefaultUserDataPath = paths.getDefaultUserDataPath;
\ No newline at end of file
export const getDefaultUserDataPath = paths.getDefaultUserDataPath;
......@@ -11,12 +11,12 @@ import * as nls from 'vs/nls';
import { TPromise, TValueCallback, ErrorCallback } from 'vs/base/common/winjs.base';
import * as Types from 'vs/base/common/types';
import { IStringDictionary } from 'vs/base/common/collections';
import URI from 'vs/base/common/uri';
import * as Objects from 'vs/base/common/objects';
import * as TPath from 'vs/base/common/paths';
import * as Platform from 'vs/base/common/platform';
import { LineDecoder } from 'vs/base/node/decoder';
import { CommandOptions, ForkOptions, SuccessData, Source, TerminateResponse, TerminateResponseCode, Executable } from 'vs/base/common/processes';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export { CommandOptions, ForkOptions, SuccessData, Source, TerminateResponse, TerminateResponseCode };
export type TProgressCallback<T> = (progress: T) => void;
......@@ -54,7 +54,7 @@ export function terminateProcess(process: cp.ChildProcess, cwd?: string): Termin
}
} else if (Platform.isLinux || Platform.isMacintosh) {
try {
let cmd = URI.parse(require.toUrl('vs/base/node/terminateProcess.sh')).fsPath;
let cmd = getPathFromAmdModule(require, 'vs/base/node/terminateProcess.sh');
let result = cp.spawnSync(cmd, [process.pid.toString()]);
if (result.error) {
return { success: false, error: result.error };
......
......@@ -6,7 +6,8 @@
'use strict';
import { exec } from 'child_process';
import URI from 'vs/base/common/uri';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export interface ProcessItem {
name: string;
......@@ -207,7 +208,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
// The cpu usage value reported on Linux is the average over the process lifetime,
// recalculate the usage over a one second interval
// JSON.stringify is needed to escape spaces, https://github.com/nodejs/node/issues/6803
let cmd = JSON.stringify(URI.parse(require.toUrl('vs/base/node/cpuUsage.sh')).fsPath);
let cmd = JSON.stringify(getPathFromAmdModule(require, 'vs/base/node/cpuUsage.sh'));
cmd += ' ' + pids.join(' ');
exec(cmd, {}, (err, stdout, stderr) => {
......
......@@ -9,7 +9,7 @@ import * as path from 'path';
import * as os from 'os';
import * as net from 'net';
import * as cp from 'child_process';
import uri from 'vs/base/common/uri';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export interface IForkOpts {
cwd?: string;
......@@ -117,7 +117,7 @@ export function fork(modulePath: string, args: string[], options: IForkOpts, cal
};
// Create the process
let bootstrapperPath = (uri.parse(require.toUrl('./stdForkStart.js')).fsPath);
let bootstrapperPath = (getPathFromAmdModule(require, './stdForkStart.js'));
childProcess = cp.fork(bootstrapperPath, [modulePath].concat(args), {
silent: true,
cwd: options.cwd,
......
......@@ -7,12 +7,12 @@
import * as assert from 'assert';
import { Client } from 'vs/base/parts/ipc/node/ipc.cp';
import uri from 'vs/base/common/uri';
import { always } from 'vs/base/common/async';
import { ITestChannel, TestServiceClient, ITestService } from './testService';
import { getPathFromAmdModule } from 'vs/base/common/amd';
function createClient(): Client {
return new Client(uri.parse(require.toUrl('bootstrap')).fsPath, {
return new Client(getPathFromAmdModule(require, 'bootstrap'), {
serverName: 'TestServer',
env: { AMD_ENTRYPOINT: 'vs/base/parts/ipc/test/node/testApp', verbose: true }
});
......@@ -111,4 +111,4 @@ suite('IPC performance', () => {
count += batch.length;
});
}
});
\ No newline at end of file
});
......@@ -9,8 +9,8 @@ import * as assert from 'assert';
import * as cp from 'child_process';
import * as objects from 'vs/base/common/objects';
import * as platform from 'vs/base/common/platform';
import URI from 'vs/base/common/uri';
import * as processes from 'vs/base/node/processes';
import { getPathFromAmdModule } from 'vs/base/common/amd';
function fork(id: string): cp.ChildProcess {
const opts: any = {
......@@ -21,7 +21,7 @@ function fork(id: string): cp.ChildProcess {
})
};
return cp.fork(URI.parse(require.toUrl('bootstrap')).fsPath, ['--type=processTests'], opts);
return cp.fork(getPathFromAmdModule(require, 'bootstrap'), ['--type=processTests'], opts);
}
suite('Processes', () => {
......
......@@ -7,13 +7,14 @@
import * as assert from 'assert';
import URI from 'vs/base/common/uri';
import { readFileSync } from 'fs';
import { getPathFromAmdModule } from 'vs/base/common/amd';
suite('URI - perf', function () {
let manyFileUris: URI[];
setup(function () {
manyFileUris = [];
let data = readFileSync(URI.parse(require.toUrl('./uri.test.data.txt')).fsPath).toString();
let data = readFileSync(getPathFromAmdModule(require, './uri.test.data.txt')).toString();
let lines = data.split('\n');
for (let line of lines) {
manyFileUris.push(URI.file(line));
......
......@@ -8,13 +8,13 @@
import * as assert from 'assert';
import * as path from 'path';
import * as os from 'os';
import URI from 'vs/base/common/uri';
import { extract } from 'vs/base/node/zip';
import { generateUuid } from 'vs/base/common/uuid';
import { rimraf, exists } from 'vs/base/node/pfs';
import { NullLogService } from 'vs/platform/log/common/log';
import { getPathFromAmdModule } from 'vs/base/common/amd';
const fixtures = URI.parse(require.toUrl('./fixtures')).fsPath;
const fixtures = getPathFromAmdModule(require, './fixtures');
suite('Zip', () => {
......
......@@ -8,12 +8,12 @@ import * as crypto from 'crypto';
import * as paths from 'vs/base/node/paths';
import * as os from 'os';
import * as path from 'path';
import URI from 'vs/base/common/uri';
import { memoize } from 'vs/base/common/decorators';
import pkg from 'vs/platform/node/package';
import product from 'vs/platform/node/product';
import { toLocalISOString } from 'vs/base/common/date';
import { isWindows, isLinux } from 'vs/base/common/platform';
import { getPathFromAmdModule } from 'vs/base/common/amd';
// Read this before there's any chance it is overwritten
// Related to https://github.com/Microsoft/vscode/issues/30624
......@@ -77,7 +77,7 @@ export class EnvironmentService implements IEnvironmentService {
get args(): ParsedArgs { return this._args; }
@memoize
get appRoot(): string { return path.dirname(URI.parse(require.toUrl('')).fsPath); }
get appRoot(): string { return path.dirname(getPathFromAmdModule(require, '')); }
get execPath(): string { return this._execPath; }
......
......@@ -40,8 +40,9 @@ import { ExtensionsLifecycle } from 'vs/platform/extensionManagement/node/extens
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { isEngineValid } from 'vs/platform/extensions/node/extensionValidator';
import { getPathFromAmdModule } from 'vs/base/common/amd';
const SystemExtensionsRoot = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', 'extensions'));
const SystemExtensionsRoot = path.normalize(path.join(getPathFromAmdModule(require, ''), '..', 'extensions'));
const ERROR_SCANNING_SYS_EXTENSIONS = 'scanningSystem';
const ERROR_SCANNING_USER_EXTENSIONS = 'scanningUser';
const INSTALL_ERROR_UNSET_UNINSTALLED = 'unsetUninstalled';
......
......@@ -4,13 +4,13 @@
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import uri from 'vs/base/common/uri';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export interface IPackageConfiguration {
name: string;
version: string;
}
const rootPath = path.dirname(uri.parse(require.toUrl('')).fsPath);
const rootPath = path.dirname(getPathFromAmdModule(require, ''));
const packageJsonPath = path.join(rootPath, 'package.json');
export default require.__$__nodeRequire(packageJsonPath) as IPackageConfiguration;
\ No newline at end of file
export default require.__$__nodeRequire(packageJsonPath) as IPackageConfiguration;
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import uri from 'vs/base/common/uri';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export interface IProductConfiguration {
nameShort: string;
......@@ -86,7 +86,7 @@ export interface ISurveyData {
userProbability: number;
}
const rootPath = path.dirname(uri.parse(require.toUrl('')).fsPath);
const rootPath = path.dirname(getPathFromAmdModule(require, ''));
const productJsonPath = path.join(rootPath, 'product.json');
const product = require.__$__nodeRequire(productJsonPath) as IProductConfiguration;
......
......@@ -10,7 +10,6 @@ import * as pfs from 'vs/base/node/pfs';
import * as platform from 'vs/base/common/platform';
import { nfcall } from 'vs/base/common/async';
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import { Action } from 'vs/base/common/actions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { Registry } from 'vs/platform/registry/common/platform';
......@@ -20,6 +19,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import Severity from 'vs/base/common/severity';
import { ILogService } from 'vs/platform/log/common/log';
import { getPathFromAmdModule } from 'vs/base/common/amd';
function ignore<T>(code: string, value: T = null): (err: any) => TPromise<T> {
return err => err.code === code ? TPromise.as<T>(value) : TPromise.wrapError<T>(err);
......@@ -28,7 +28,7 @@ function ignore<T>(code: string, value: T = null): (err: any) => TPromise<T> {
let _source: string = null;
function getSource(): string {
if (!_source) {
const root = URI.parse(require.toUrl('')).fsPath;
const root = getPathFromAmdModule(require, '');
_source = path.resolve(root, '..', 'bin', 'code');
}
return _source;
......
......@@ -19,10 +19,10 @@ import { IOutputService } from 'vs/workbench/parts/output/common/output';
import { DebugAdapter, SocketDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
import uri from 'vs/base/common/uri';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { memoize } from 'vs/base/common/decorators';
import { TaskDefinitionRegistry } from 'vs/workbench/parts/tasks/common/taskDefinitionRegistry';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export class Debugger {
......@@ -173,7 +173,7 @@ export class Debugger {
return telemetryInfo;
}).then(data => {
const client = new TelemetryClient(
uri.parse(require.toUrl('bootstrap')).fsPath,
getPathFromAmdModule(require, 'bootstrap'),
{
serverName: 'Debug Telemetry',
timeout: 1000 * 60 * 5,
......
......@@ -11,8 +11,8 @@ import * as env from 'vs/base/common/platform';
import * as pfs from 'vs/base/node/pfs';
import { assign } from 'vs/base/common/objects';
import { TPromise } from 'vs/base/common/winjs.base';
import uri from 'vs/base/common/uri';
import { ITerminalLauncher, ITerminalSettings } from 'vs/workbench/parts/debug/common/debug';
import { getPathFromAmdModule } from 'vs/base/common/amd';
const TERMINAL_TITLE = nls.localize('console.title', "VS Code Console");
......@@ -132,7 +132,7 @@ class MacTerminalService extends TerminalLauncher {
// and then launches the program inside that window.
const script = terminalApp === MacTerminalService.DEFAULT_TERMINAL_OSX ? 'TerminalHelper' : 'iTermHelper';
const scriptpath = uri.parse(require.toUrl(`vs/workbench/parts/execution/electron-browser/${script}.scpt`)).fsPath;
const scriptpath = getPathFromAmdModule(require, `vs/workbench/parts/execution/electron-browser/${script}.scpt`);
const osaArgs = [
scriptpath,
......@@ -415,4 +415,4 @@ export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments
}
return command;
}
\ No newline at end of file
}
......@@ -15,8 +15,8 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { ITerminalService } from 'vs/workbench/parts/execution/common/execution';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ITerminalConfiguration, getDefaultTerminalWindows, getDefaultTerminalLinuxReady, DEFAULT_TERMINAL_OSX } from 'vs/workbench/parts/execution/electron-browser/terminal';
import uri from 'vs/base/common/uri';
import { IProcessEnvironment } from 'vs/base/common/platform';
import { getPathFromAmdModule } from 'vs/base/common/amd';
const TERMINAL_TITLE = nls.localize('console.title', "VS Code Console");
......@@ -143,7 +143,7 @@ export class MacTerminalService implements ITerminalService {
// and then launches the program inside that window.
const script = terminalApp === DEFAULT_TERMINAL_OSX ? 'TerminalHelper' : 'iTermHelper';
const scriptpath = uri.parse(require.toUrl(`vs/workbench/parts/execution/electron-browser/${script}.scpt`)).fsPath;
const scriptpath = getPathFromAmdModule(require, `vs/workbench/parts/execution/electron-browser/${script}.scpt`);
const osaArgs = [
scriptpath,
......
......@@ -8,7 +8,6 @@
import * as nls from 'vs/nls';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import * as objects from 'vs/base/common/objects';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { isWindows, isLinux } from 'vs/base/common/platform';
import { findFreePort } from 'vs/base/node/ports';
......@@ -36,6 +35,7 @@ import { IRemoteConsoleLog, log, parse } from 'vs/base/node/console';
import { getScopes } from 'vs/platform/configuration/common/configurationRegistry';
import { ILogService } from 'vs/platform/log/common/log';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export class ExtensionHostProcessWorker {
......@@ -171,7 +171,7 @@ export class ExtensionHostProcessWorker {
}
// Run Extension Host as fork of current process
this._extensionHostProcess = fork(URI.parse(require.toUrl('bootstrap')).fsPath, ['--type=extensionHost'], opts);
this._extensionHostProcess = fork(getPathFromAmdModule(require, 'bootstrap'), ['--type=extensionHost'], opts);
// Catch all output coming from the extension host process
type Output = { data: string, format: string[] };
......
......@@ -43,18 +43,19 @@ import { RPCProtocol } from 'vs/workbench/services/extensions/node/rpcProtocol';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { Schemas } from 'vs/base/common/network';
import { getPathFromAmdModule } from 'vs/base/common/amd';
let _SystemExtensionsRoot: string = null;
function getSystemExtensionsRoot(): string {
if (!_SystemExtensionsRoot) {
_SystemExtensionsRoot = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', 'extensions'));
_SystemExtensionsRoot = path.normalize(path.join(getPathFromAmdModule(require, ''), '..', 'extensions'));
}
return _SystemExtensionsRoot;
}
let _ExtraDevSystemExtensionsRoot: string = null;
function getExtraDevSystemExtensionsRoot(): string {
if (!_ExtraDevSystemExtensionsRoot) {
_ExtraDevSystemExtensionsRoot = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', '.build', 'builtInExtensions'));
_ExtraDevSystemExtensionsRoot = path.normalize(path.join(getPathFromAmdModule(require, ''), '..', '.build', 'builtInExtensions'));
}
return _ExtraDevSystemExtensionsRoot;
}
......@@ -796,7 +797,7 @@ export class ExtensionService extends Disposable implements IExtensionService {
let finalBuiltinExtensions: TPromise<IExtensionDescription[]> = TPromise.wrap(builtinExtensions);
if (devMode) {
const builtInExtensionsFilePath = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', 'build', 'builtInExtensions.json'));
const builtInExtensionsFilePath = path.normalize(path.join(getPathFromAmdModule(require, ''), '..', 'build', 'builtInExtensions.json'));
const builtInExtensions = pfs.readFile(builtInExtensionsFilePath, 'utf8')
.then<IBuiltInExtension[]>(raw => JSON.parse(raw));
......
......@@ -7,7 +7,6 @@
import { getNextTickChannel } from 'vs/base/parts/ipc/common/ipc';
import { Client } from 'vs/base/parts/ipc/node/ipc.cp';
import uri from 'vs/base/common/uri';
import { toFileChangesEvent, IRawFileChange } from 'vs/workbench/services/files/node/watcher/common';
import { IWatcherChannel, WatcherChannelClient } from 'vs/workbench/services/files/node/watcher/nsfw/watcherIpc';
import { FileChangesEvent, IFilesConfiguration } from 'vs/platform/files/common/files';
......@@ -17,6 +16,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { filterEvent } from 'vs/base/common/event';
import { IWatchError } from 'vs/workbench/services/files/node/watcher/nsfw/watcher';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export class FileWatcher {
private static readonly MAX_RESTARTS = 5;
......@@ -39,7 +39,7 @@ export class FileWatcher {
public startWatching(): () => void {
const client = new Client(
uri.parse(require.toUrl('bootstrap')).fsPath,
getPathFromAmdModule(require, 'bootstrap'),
{
serverName: 'Watcher',
args: ['--type=watcherService'],
......
......@@ -7,7 +7,6 @@
import { getNextTickChannel } from 'vs/base/parts/ipc/common/ipc';
import { Client } from 'vs/base/parts/ipc/node/ipc.cp';
import uri from 'vs/base/common/uri';
import { toFileChangesEvent, IRawFileChange } from 'vs/workbench/services/files/node/watcher/common';
import { IWatcherChannel, WatcherChannelClient } from 'vs/workbench/services/files/node/watcher/unix/watcherIpc';
import { FileChangesEvent, IFilesConfiguration } from 'vs/platform/files/common/files';
......@@ -17,6 +16,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { Schemas } from 'vs/base/common/network';
import { filterEvent } from 'vs/base/common/event';
import { IWatchError } from 'vs/workbench/services/files/node/watcher/unix/watcher';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export class FileWatcher {
private static readonly MAX_RESTARTS = 5;
......@@ -42,7 +42,7 @@ export class FileWatcher {
const args = ['--type=watcherService'];
const client = new Client(
uri.parse(require.toUrl('bootstrap')).fsPath,
getPathFromAmdModule(require, 'bootstrap'),
{
serverName: 'Watcher',
args,
......@@ -122,4 +122,4 @@ export class FileWatcher {
this.isDisposed = true;
this.toDispose = dispose(this.toDispose);
}
}
\ No newline at end of file
}
......@@ -10,9 +10,9 @@ import * as cp from 'child_process';
import { FileChangeType } from 'vs/platform/files/common/files';
import * as decoder from 'vs/base/node/decoder';
import * as glob from 'vs/base/common/glob';
import uri from 'vs/base/common/uri';
import { IRawFileChange } from 'vs/workbench/services/files/node/watcher/common';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export class OutOfProcessWin32FolderWatcher {
......@@ -41,7 +41,7 @@ export class OutOfProcessWin32FolderWatcher {
args.push('-verbose');
}
this.handle = cp.spawn(uri.parse(require.toUrl('vs/workbench/services/files/node/watcher/win32/CodeHelper.exe')).fsPath, args);
this.handle = cp.spawn(getPathFromAmdModule(require, 'vs/workbench/services/files/node/watcher/win32/CodeHelper.exe'), args);
const stdoutLineDecoder = new decoder.LineDecoder();
......@@ -116,4 +116,4 @@ export class OutOfProcessWin32FolderWatcher {
this.handle = null;
}
}
}
\ No newline at end of file
}
......@@ -26,6 +26,7 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IRawSearch, IRawSearchService, ISerializedFileMatch, ISerializedSearchComplete, ISerializedSearchProgressItem, isSerializedSearchComplete, isSerializedSearchSuccess, ITelemetryEvent } from './search';
import { ISearchChannel, SearchChannelClient } from './searchIpc';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export class SearchService extends Disposable implements ISearchService {
public _serviceBrand: any;
......@@ -331,7 +332,7 @@ export class DiskSearch implements ISearchResultProvider {
}
const client = new Client(
uri.parse(require.toUrl('bootstrap')).fsPath,
getPathFromAmdModule(require, 'bootstrap'),
opts);
const channel = getNextTickChannel(client.getChannel<ISearchChannel>('search'));
......
......@@ -7,11 +7,11 @@
import * as os from 'os';
import uri from 'vs/base/common/uri';
import * as ipc from 'vs/base/parts/ipc/common/ipc';
import { Client } from 'vs/base/parts/ipc/node/ipc.cp';
import { ISearchWorker, ISearchWorkerChannel, SearchWorkerChannelClient } from './worker/searchWorkerIpc';
import { getPathFromAmdModule } from 'vs/base/common/amd';
export interface ITextSearchWorkerProvider {
getWorkers(): ISearchWorker[];
......@@ -31,7 +31,7 @@ export class TextSearchWorkerProvider implements ITextSearchWorkerProvider {
private createWorker(): void {
let client = new Client(
uri.parse(require.toUrl('bootstrap')).fsPath,
getPathFromAmdModule(require, 'bootstrap'),
{
serverName: 'Search Worker ' + this.workers.length,
args: ['--type=searchWorker'],
......@@ -49,4 +49,4 @@ export class TextSearchWorkerProvider implements ITextSearchWorkerProvider {
this.workers.push(channelClient);
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册