mirror of
https://github.com/coder/code-server.git
synced 2025-08-01 19:30:05 +08:00
Update to VS Code 1.52.1
This commit is contained in:
121
lib/vscode/src/bootstrap.js
vendored
121
lib/vscode/src/bootstrap.js
vendored
@ -42,11 +42,11 @@
|
||||
//#region Add support for using node_modules.asar
|
||||
|
||||
/**
|
||||
* @param {string} appRoot
|
||||
* @param {string | undefined} appRoot
|
||||
*/
|
||||
function enableASARSupport(appRoot) {
|
||||
if (!path || !Module) {
|
||||
console.warn('enableASARSupport() is only available in node.js environments');
|
||||
if (!path || !Module || typeof process === 'undefined') {
|
||||
console.warn('enableASARSupport() is only available in node.js environments'); // TODO@sandbox ASAR is currently non-sandboxed only
|
||||
return;
|
||||
}
|
||||
|
||||
@ -124,17 +124,14 @@
|
||||
//#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) {
|
||||
console.warn('setupNLS() is only available in node.js environments');
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the nls configuration into the process.env as early as possible.
|
||||
// Get the nls configuration as early as possible.
|
||||
const process = safeProcess();
|
||||
let nlsConfig = { availableLanguages: {} };
|
||||
if (process.env['VSCODE_NLS_CONFIG']) {
|
||||
if (process && process.env['VSCODE_NLS_CONFIG']) {
|
||||
try {
|
||||
nlsConfig = JSON.parse(process.env['VSCODE_NLS_CONFIG']);
|
||||
} catch (e) {
|
||||
@ -153,8 +150,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const bundleFile = path.join(nlsConfig._resolvedLanguagePackCoreLocation, `${bundle.replace(/\//g, '!')}.nls.json`);
|
||||
fs.promises.readFile(bundleFile, 'utf8').then(function (content) {
|
||||
safeReadNlsFile(nlsConfig._resolvedLanguagePackCoreLocation, `${bundle.replace(/\//g, '!')}.nls.json`).then(function (content) {
|
||||
const json = JSON.parse(content);
|
||||
bundles[bundle] = json;
|
||||
|
||||
@ -162,7 +158,7 @@
|
||||
}).catch((error) => {
|
||||
try {
|
||||
if (nlsConfig._corruptedFile) {
|
||||
fs.promises.writeFile(nlsConfig._corruptedFile, 'corrupted', 'utf8').catch(function (error) { console.error(error); });
|
||||
safeWriteNlsFile(nlsConfig._corruptedFile, 'corrupted').catch(function (error) { console.error(error); });
|
||||
}
|
||||
} finally {
|
||||
cb(error, undefined);
|
||||
@ -174,77 +170,73 @@
|
||||
return nlsConfig;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
function safeGlobals() {
|
||||
const globals = (typeof self === 'object' ? self : typeof global === 'object' ? global : {});
|
||||
|
||||
|
||||
//#region Portable helpers
|
||||
return globals.vscode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ portable: string; applicationName: string; }} product
|
||||
* @returns {{ portableDataPath: string; isPortable: boolean; }}
|
||||
* @returns {NodeJS.Process | undefined}
|
||||
*/
|
||||
function configurePortable(product) {
|
||||
if (!path || !fs) {
|
||||
console.warn('configurePortable() is only available in node.js environments');
|
||||
return;
|
||||
function safeProcess() {
|
||||
if (typeof process !== 'undefined') {
|
||||
return process; // Native environment (non-sandboxed)
|
||||
}
|
||||
|
||||
const appRoot = path.dirname(__dirname);
|
||||
const globals = safeGlobals();
|
||||
if (globals) {
|
||||
return globals.process; // Native environment (sandboxed)
|
||||
}
|
||||
}
|
||||
|
||||
function getApplicationPath() {
|
||||
if (process.env['VSCODE_DEV']) {
|
||||
return appRoot;
|
||||
}
|
||||
/**
|
||||
* @returns {Electron.IpcRenderer | undefined}
|
||||
*/
|
||||
function safeIpcRenderer() {
|
||||
const globals = safeGlobals();
|
||||
if (globals) {
|
||||
return globals.ipcRenderer;
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
return path.dirname(path.dirname(path.dirname(appRoot)));
|
||||
}
|
||||
|
||||
return path.dirname(path.dirname(appRoot));
|
||||
/**
|
||||
* @param {string[]} pathSegments
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async function safeReadNlsFile(...pathSegments) {
|
||||
const ipcRenderer = safeIpcRenderer();
|
||||
if (ipcRenderer) {
|
||||
return ipcRenderer.invoke('vscode:readNlsFile', ...pathSegments);
|
||||
}
|
||||
|
||||
function getPortableDataPath() {
|
||||
if (process.env['VSCODE_PORTABLE']) {
|
||||
return process.env['VSCODE_PORTABLE'];
|
||||
}
|
||||
|
||||
if (process.platform === 'win32' || process.platform === 'linux') {
|
||||
return path.join(getApplicationPath(), 'data');
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const portableDataName = product.portable || `${product.applicationName}-portable-data`;
|
||||
return path.join(path.dirname(getApplicationPath()), portableDataName);
|
||||
if (fs && path) {
|
||||
return (await fs.promises.readFile(path.join(...pathSegments))).toString();
|
||||
}
|
||||
|
||||
const portableDataPath = getPortableDataPath();
|
||||
const isPortable = !('target' in product) && fs.existsSync(portableDataPath);
|
||||
const portableTempPath = path.join(portableDataPath, 'tmp');
|
||||
const isTempPortable = isPortable && fs.existsSync(portableTempPath);
|
||||
throw new Error('Unsupported operation (read NLS files)');
|
||||
}
|
||||
|
||||
if (isPortable) {
|
||||
process.env['VSCODE_PORTABLE'] = portableDataPath;
|
||||
} else {
|
||||
delete process.env['VSCODE_PORTABLE'];
|
||||
/**
|
||||
* @param {string} path
|
||||
* @param {string} content
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
function safeWriteNlsFile(path, content) {
|
||||
const ipcRenderer = safeIpcRenderer();
|
||||
if (ipcRenderer) {
|
||||
return ipcRenderer.invoke('vscode:writeNlsFile', path, content);
|
||||
}
|
||||
|
||||
if (isTempPortable) {
|
||||
if (process.platform === 'win32') {
|
||||
process.env['TMP'] = portableTempPath;
|
||||
process.env['TEMP'] = portableTempPath;
|
||||
} else {
|
||||
process.env['TMPDIR'] = portableTempPath;
|
||||
}
|
||||
if (fs) {
|
||||
return fs.promises.writeFile(path, content);
|
||||
}
|
||||
|
||||
return {
|
||||
portableDataPath,
|
||||
isPortable
|
||||
};
|
||||
throw new Error('Unsupported operation (write NLS files)');
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
|
||||
//#region ApplicationInsights
|
||||
|
||||
@ -267,7 +259,6 @@
|
||||
return {
|
||||
enableASARSupport,
|
||||
avoidMonkeyPatchFromAppInsights,
|
||||
configurePortable,
|
||||
setupNLS,
|
||||
fileUriFromPath
|
||||
};
|
||||
|
Reference in New Issue
Block a user