提交 eb8c718e 编写于 作者: B Benjamin Pasero

debt - fix compile errors in bootstrap files

上级 3154dd4f
......@@ -29,7 +29,7 @@ if (process.env['ELECTRON_RUN_AS_NODE'] || process.versions['electron']) {
}
// Pseudo NLS support
if (nlsConfig.pseudo) {
if (nlsConfig?.pseudo) {
loader(['vs/nls'], function (nlsPlugin) {
nlsPlugin.setPseudoTranslation(nlsConfig.pseudo);
});
......
......@@ -81,7 +81,7 @@ function pipeLoggingToParent() {
// to start the stacktrace where the console message was being written
if (process.env.VSCODE_LOG_STACK === 'true') {
const stack = new Error().stack;
argsArray.push({ __$stack: stack.split('\n').slice(3).join('\n') });
argsArray.push({ __$stack: stack?.split('\n').slice(3).join('\n') });
}
try {
......@@ -114,7 +114,7 @@ function pipeLoggingToParent() {
*/
function safeSend(arg) {
try {
process.send(arg);
process.send?.(arg);
} catch (error) {
// Can happen if the parent channel is closed meanwhile
}
......
......@@ -41,7 +41,7 @@
* extensionDevelopmentPath?: string[],
* extensionTestsPath?: string,
* userEnv?: { [key: string]: string | undefined },
* appRoot?: string,
* appRoot: string,
* nodeCachedDataDir?: string
* }} */
const configuration = JSON.parse(args['config'] || '{}') || {};
......@@ -61,7 +61,7 @@
const enableDeveloperTools = (safeProcess.env['VSCODE_DEV'] || !!configuration.extensionDevelopmentPath) && !configuration.extensionTestsPath;
let developerToolsUnbind;
if (enableDeveloperTools || (options && options.forceEnableDeveloperKeybindings)) {
developerToolsUnbind = registerDeveloperKeybindings(options && options.disallowReloadKeybinding);
developerToolsUnbind = registerDeveloperKeybindings(options?.disallowReloadKeybinding);
}
// Correctly inherit the parent's environment (TODO@sandbox non-sandboxed only)
......@@ -182,7 +182,7 @@
}
/**
* @param {boolean} disallowReloadKeybinding
* @param {boolean | undefined} disallowReloadKeybinding
* @returns {() => void}
*/
function registerDeveloperKeybindings(disallowReloadKeybinding) {
......@@ -203,6 +203,7 @@
const TOGGLE_DEV_TOOLS_KB_ALT = '123'; // F12
const RELOAD_KB = (safeProcess.platform === 'darwin' ? 'meta-82' : 'ctrl-82'); // mac: Cmd-R, rest: Ctrl-R
/** @type {((e: any) => void) | undefined} */
let listener = function (e) {
const key = extractKey(e);
if (key === TOGGLE_DEV_TOOLS_KB || key === TOGGLE_DEV_TOOLS_KB_ALT) {
......
......@@ -42,7 +42,7 @@
//#region Add support for using node_modules.asar
/**
* @param {string} appRoot
* @param {string | undefined} appRoot
*/
function enableASARSupport(appRoot) {
if (!path || !Module) {
......@@ -124,7 +124,7 @@
//#region NLS helpers
/**
* @returns {{locale?: string, availableLanguages: {[lang: string]: string;}, pseudo?: boolean }}
* @returns {{locale?: string, availableLanguages: {[lang: string]: string;}, pseudo?: boolean } | undefined}
*/
function setupNLS() {
if (!path || !fs) {
......@@ -181,7 +181,7 @@
/**
* @param {{ portable: string; applicationName: string; }} product
* @returns {{ portableDataPath: string; isPortable: boolean; }}
* @returns {{ portableDataPath: string; isPortable: boolean; } | undefined}
*/
function configurePortable(product) {
if (!path || !fs) {
......
......@@ -107,7 +107,7 @@ crashReporter.start({
// to ensure that no 'logs' folder is created on disk at a
// location outside of the portable directory
// (https://github.com/microsoft/vscode/issues/56651)
if (portable.isPortable) {
if (portable?.isPortable) {
app.setAppLogsPath(path.join(userDataPath, 'logs'));
}
......@@ -145,7 +145,7 @@ const nodeCachedDataDir = getNodeCachedDir();
* Support user defined locale: load it early before app('ready')
* to have more things running in parallel.
*
* @type {Promise<import('./vs/base/node/languagePacks').NLSConfiguration>} nlsConfig | undefined
* @type {Promise<import('./vs/base/node/languagePacks').NLSConfiguration> | undefined}
*/
let nlsConfigurationPromise = undefined;
......@@ -359,7 +359,7 @@ function getArgvConfigPath() {
/**
* @param {NativeParsedArgs} cliArgs
* @returns {string}
* @returns {string | null}
*/
function getJSFlags(cliArgs) {
const jsFlags = [];
......@@ -387,7 +387,7 @@ function getUserDataPath(cliArgs) {
return path.join(portable.portableDataPath, 'user-data');
}
return path.resolve(cliArgs['user-data-dir'] || paths.getDefaultUserDataPath(process.platform));
return path.resolve(cliArgs['user-data-dir'] || paths.getDefaultUserDataPath());
}
/**
......@@ -468,12 +468,14 @@ function getNodeCachedDir() {
}
async ensureExists() {
try {
await mkdirp(this.value);
if (typeof this.value === 'string') {
try {
await mkdirp(this.value);
return this.value;
} catch (error) {
// ignore
return this.value;
} catch (error) {
// ignore
}
}
}
......
......@@ -11,25 +11,38 @@ const path = require('path');
const os = require('os');
/**
* @param {string} platform
* @returns {string}
*/
function getAppDataPath(platform) {
switch (platform) {
case 'win32': return process.env['VSCODE_APPDATA'] || process.env['APPDATA'] || path.join(process.env['USERPROFILE'], 'AppData', 'Roaming');
case 'darwin': return process.env['VSCODE_APPDATA'] || path.join(os.homedir(), 'Library', 'Application Support');
case 'linux': return process.env['VSCODE_APPDATA'] || process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config');
default: throw new Error('Platform not supported');
function getDefaultUserDataPath() {
// Support global VSCODE_APPDATA environment variable
let appDataPath = process.env['VSCODE_APPDATA'];
// Otherwise check per platform
if (!appDataPath) {
switch (process.platform) {
case 'win32':
appDataPath = process.env['APPDATA'];
if (!appDataPath) {
const userProfile = process.env['USERPROFILE'];
if (typeof userProfile !== 'string') {
throw new Error('Windows: Unexpected undefined %USERPROFILE% environment variable');
}
appDataPath = path.join(userProfile, 'AppData', 'Roaming');
}
break;
case 'darwin':
appDataPath = path.join(os.homedir(), 'Library', 'Application Support');
break;
case 'linux':
appDataPath = process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config');
break;
default:
throw new Error('Platform not supported');
}
}
}
/**
* @param {string} platform
* @returns {string}
*/
function getDefaultUserDataPath(platform) {
return path.join(getAppDataPath(platform), pkg.name);
return path.join(appDataPath, pkg.name);
}
exports.getAppDataPath = getAppDataPath;
exports.getDefaultUserDataPath = getDefaultUserDataPath;
......@@ -5,12 +5,7 @@
import { FileAccess } from 'vs/base/common/network';
interface IPaths {
getAppDataPath(platform: string): string;
getDefaultUserDataPath(platform: string): string;
}
const pathsPath = FileAccess.asFileUri('paths', require).fsPath;
const paths = require.__$__nodeRequire<IPaths>(pathsPath);
export const getAppDataPath = paths.getAppDataPath;
const paths = require.__$__nodeRequire<{ getDefaultUserDataPath(): string }>(pathsPath);
export const getDefaultUserDataPath = paths.getDefaultUserDataPath;
......@@ -223,6 +223,8 @@
* shell specific environment from the OS shell to ensure we are seeing
* all development related environment variables. We do this from the
* main process because it may involve spawning a shell.
*
* @returns {Promise<void>}
*/
function resolveEnv() {
return new Promise(function (resolve) {
......
......@@ -591,12 +591,13 @@ export class CodeApplication extends Disposable {
return undefined;
}
})).filter(pendingUriToHandle => {
// if URI should be blocked, filter it out
// If URI should be blocked, filter it out
if (this.shouldBlockURI(pendingUriToHandle)) {
return false;
}
// filter out any protocol link that wants to open as window so that
// Filter out any protocol link that wants to open as window so that
// we open the right set of windows on startup and not restore the
// previous workspace too.
const windowOpenable = this.getWindowOpenableFromProtocolLink(pendingUriToHandle);
......@@ -614,7 +615,8 @@ export class CodeApplication extends Disposable {
const environmentService = this.environmentService;
urlService.registerHandler({
async handleURL(uri: URI): Promise<boolean> {
// if URI should be blocked, behave as if it's handled
// If URI should be blocked, behave as if it's handled
if (app.shouldBlockURI(uri)) {
return true;
}
......
......@@ -245,5 +245,5 @@ export function parsePathArg(arg: string | undefined, process: NodeJS.Process):
}
export function parseUserDataDir(args: NativeParsedArgs, process: NodeJS.Process): string {
return parsePathArg(args['user-data-dir'], process) || path.resolve(paths.getDefaultUserDataPath(process.platform));
return parsePathArg(args['user-data-dir'], process) || path.resolve(paths.getDefaultUserDataPath());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册