2015-11-13 13:39:38 +00:00
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
|
2018-09-07 14:05:24 +00:00
|
|
|
//@ts-check
|
|
|
|
'use strict';
|
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
// Simple module style to support node.js and browser environments
|
|
|
|
(function (globalThis, factory) {
|
2018-09-07 10:23:09 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
// Node.js
|
|
|
|
if (typeof exports === 'object') {
|
|
|
|
module.exports = factory();
|
|
|
|
}
|
2020-06-03 08:22:47 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
// Browser
|
|
|
|
else {
|
2023-01-09 23:20:15 +00:00
|
|
|
// @ts-ignore
|
2020-09-22 06:14:45 +00:00
|
|
|
globalThis.MonacoBootstrap = factory();
|
2020-06-24 07:07:14 +00:00
|
|
|
}
|
|
|
|
}(this, function () {
|
2020-09-22 06:14:45 +00:00
|
|
|
const Module = typeof require === 'function' ? require('module') : undefined;
|
|
|
|
const path = typeof require === 'function' ? require('path') : undefined;
|
|
|
|
const fs = typeof require === 'function' ? require('fs') : undefined;
|
2023-07-28 15:17:50 +00:00
|
|
|
const util = typeof require === 'function' ? require('util') : undefined;
|
2018-09-10 05:48:52 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
//#region global bootstrapping
|
2018-09-07 18:30:49 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
// increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
|
|
|
|
Error.stackTraceLimit = 100;
|
2018-01-09 16:04:02 +00:00
|
|
|
|
2022-04-29 21:02:57 +00:00
|
|
|
if (typeof process !== 'undefined' && !process.env['VSCODE_HANDLES_SIGPIPE']) {
|
2022-04-28 15:14:19 +00:00
|
|
|
// Workaround for Electron not installing a handler to ignore SIGPIPE
|
|
|
|
// (https://github.com/electron/electron/issues/13254)
|
2023-01-17 19:25:58 +00:00
|
|
|
let didLogAboutSIGPIPE = false;
|
2022-04-29 21:02:57 +00:00
|
|
|
process.on('SIGPIPE', () => {
|
2023-01-17 19:25:58 +00:00
|
|
|
// See https://github.com/microsoft/vscode-remote-release/issues/6543
|
|
|
|
// We would normally install a SIGPIPE listener in bootstrap.js
|
|
|
|
// But in certain situations, the console itself can be in a broken pipe state
|
|
|
|
// so logging SIGPIPE to the console will cause an infinite async loop
|
|
|
|
if (!didLogAboutSIGPIPE) {
|
|
|
|
didLogAboutSIGPIPE = true;
|
|
|
|
console.error(new Error(`Unexpected SIGPIPE`));
|
|
|
|
}
|
2022-04-29 21:02:57 +00:00
|
|
|
});
|
2020-09-22 06:14:45 +00:00
|
|
|
}
|
2019-09-30 12:55:10 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
//#endregion
|
2018-01-09 16:04:02 +00:00
|
|
|
|
2020-06-03 08:22:47 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
//#region Add support for using node_modules.asar
|
|
|
|
|
2023-05-12 11:36:29 +00:00
|
|
|
function enableASARSupport() {
|
2020-11-24 09:23:00 +00:00
|
|
|
if (!path || !Module || typeof process === 'undefined') {
|
2021-08-04 08:45:11 +00:00
|
|
|
console.warn('enableASARSupport() is only available in node.js environments');
|
2020-09-22 06:14:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-12 11:36:29 +00:00
|
|
|
const NODE_MODULES_PATH = path.join(__dirname, '../node_modules');
|
2020-06-24 07:07:14 +00:00
|
|
|
const NODE_MODULES_ASAR_PATH = `${NODE_MODULES_PATH}.asar`;
|
2020-06-03 08:22:47 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
// @ts-ignore
|
|
|
|
const originalResolveLookupPaths = Module._resolveLookupPaths;
|
2015-11-19 08:11:22 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
// @ts-ignore
|
|
|
|
Module._resolveLookupPaths = function (request, parent) {
|
|
|
|
const paths = originalResolveLookupPaths(request, parent);
|
|
|
|
if (Array.isArray(paths)) {
|
|
|
|
for (let i = 0, len = paths.length; i < len; i++) {
|
|
|
|
if (paths[i] === NODE_MODULES_PATH) {
|
|
|
|
paths.splice(i, 0, NODE_MODULES_ASAR_PATH);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-25 08:29:29 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
return paths;
|
|
|
|
};
|
2019-01-07 11:51:27 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
//#endregion
|
2020-06-03 08:22:47 +00:00
|
|
|
|
2015-11-13 13:39:38 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
//#region URI helpers
|
2020-06-03 08:22:47 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
/**
|
2020-09-22 06:14:45 +00:00
|
|
|
* @param {string} path
|
2020-09-25 12:10:45 +00:00
|
|
|
* @param {{ isWindows?: boolean, scheme?: string, fallbackAuthority?: string }} config
|
2020-06-24 07:07:14 +00:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2020-09-25 12:10:45 +00:00
|
|
|
function fileUriFromPath(path, config) {
|
|
|
|
|
2021-08-12 00:57:48 +00:00
|
|
|
// Since we are building a URI, we normalize any backslash
|
2020-09-25 12:10:45 +00:00
|
|
|
// to slashes and we ensure that the path begins with a '/'.
|
2020-09-22 06:14:45 +00:00
|
|
|
let pathName = path.replace(/\\/g, '/');
|
2020-06-24 07:07:14 +00:00
|
|
|
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
|
|
|
|
pathName = `/${pathName}`;
|
|
|
|
}
|
2015-11-13 13:39:38 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
/** @type {string} */
|
|
|
|
let uri;
|
2020-09-25 12:10:45 +00:00
|
|
|
|
|
|
|
// Windows: in order to support UNC paths (which start with '//')
|
|
|
|
// that have their own authority, we do not use the provided authority
|
|
|
|
// but rather preserve it.
|
|
|
|
if (config.isWindows && pathName.startsWith('//')) {
|
|
|
|
uri = encodeURI(`${config.scheme || 'file'}:${pathName}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise we optionally add the provided authority if specified
|
|
|
|
else {
|
|
|
|
uri = encodeURI(`${config.scheme || 'file'}://${config.fallbackAuthority || ''}${pathName}`);
|
2015-11-26 15:06:08 +00:00
|
|
|
}
|
2020-06-24 07:07:14 +00:00
|
|
|
|
|
|
|
return uri.replace(/#/g, '%23');
|
2015-11-26 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
//#endregion
|
|
|
|
|
2018-08-14 14:31:17 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
//#region NLS helpers
|
2018-09-07 10:23:09 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
/**
|
2020-11-09 08:02:54 +00:00
|
|
|
* @returns {{locale?: string, availableLanguages: {[lang: string]: string;}, pseudo?: boolean } | undefined}
|
2020-06-24 07:07:14 +00:00
|
|
|
*/
|
|
|
|
function setupNLS() {
|
|
|
|
|
2020-11-25 07:16:33 +00:00
|
|
|
// Get the nls configuration as early as possible.
|
|
|
|
const process = safeProcess();
|
2023-01-09 23:20:15 +00:00
|
|
|
/** @type {{ availableLanguages: {}; loadBundle?: (bundle: string, language: string, cb: (err: Error | undefined, result: string | undefined) => void) => void; _resolvedLanguagePackCoreLocation?: string; _corruptedFile?: string }} */
|
2020-06-24 07:07:14 +00:00
|
|
|
let nlsConfig = { availableLanguages: {} };
|
2020-11-25 07:16:33 +00:00
|
|
|
if (process && process.env['VSCODE_NLS_CONFIG']) {
|
2020-06-24 07:07:14 +00:00
|
|
|
try {
|
|
|
|
nlsConfig = JSON.parse(process.env['VSCODE_NLS_CONFIG']);
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore
|
2018-09-07 10:23:09 +00:00
|
|
|
}
|
2020-06-24 07:07:14 +00:00
|
|
|
}
|
2018-09-07 10:23:09 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
if (nlsConfig._resolvedLanguagePackCoreLocation) {
|
|
|
|
const bundles = Object.create(null);
|
2018-09-07 10:23:09 +00:00
|
|
|
|
2023-01-09 23:20:15 +00:00
|
|
|
/**
|
|
|
|
* @param {string} bundle
|
|
|
|
* @param {string} language
|
|
|
|
* @param {(err: Error | undefined, result: string | undefined) => void} cb
|
|
|
|
*/
|
2020-06-24 07:07:14 +00:00
|
|
|
nlsConfig.loadBundle = function (bundle, language, cb) {
|
|
|
|
const result = bundles[bundle];
|
|
|
|
if (result) {
|
|
|
|
cb(undefined, result);
|
|
|
|
|
|
|
|
return;
|
2018-09-07 10:23:09 +00:00
|
|
|
}
|
2015-11-19 08:11:22 +00:00
|
|
|
|
2023-01-09 23:20:15 +00:00
|
|
|
// @ts-ignore
|
2020-11-25 07:16:33 +00:00
|
|
|
safeReadNlsFile(nlsConfig._resolvedLanguagePackCoreLocation, `${bundle.replace(/\//g, '!')}.nls.json`).then(function (content) {
|
2020-06-24 07:07:14 +00:00
|
|
|
const json = JSON.parse(content);
|
|
|
|
bundles[bundle] = json;
|
|
|
|
|
|
|
|
cb(undefined, json);
|
|
|
|
}).catch((error) => {
|
|
|
|
try {
|
|
|
|
if (nlsConfig._corruptedFile) {
|
2020-11-25 07:16:33 +00:00
|
|
|
safeWriteNlsFile(nlsConfig._corruptedFile, 'corrupted').catch(function (error) { console.error(error); });
|
2020-06-24 07:07:14 +00:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
cb(error, undefined);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2020-06-03 08:22:47 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
return nlsConfig;
|
|
|
|
}
|
2020-06-23 12:18:11 +00:00
|
|
|
|
2021-02-01 09:16:35 +00:00
|
|
|
/**
|
|
|
|
* @returns {typeof import('./vs/base/parts/sandbox/electron-sandbox/globals') | undefined}
|
|
|
|
*/
|
2021-04-06 07:51:14 +00:00
|
|
|
function safeSandboxGlobals() {
|
2020-11-24 09:23:00 +00:00
|
|
|
const globals = (typeof self === 'object' ? self : typeof global === 'object' ? global : {});
|
|
|
|
|
2023-01-09 23:20:15 +00:00
|
|
|
// @ts-ignore
|
2020-11-25 07:16:33 +00:00
|
|
|
return globals.vscode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-05 07:54:28 +00:00
|
|
|
* @returns {import('./vs/base/parts/sandbox/electron-sandbox/globals').ISandboxNodeProcess | NodeJS.Process | undefined}
|
2020-11-25 07:16:33 +00:00
|
|
|
*/
|
|
|
|
function safeProcess() {
|
2021-04-06 07:51:14 +00:00
|
|
|
const sandboxGlobals = safeSandboxGlobals();
|
|
|
|
if (sandboxGlobals) {
|
|
|
|
return sandboxGlobals.process; // Native environment (sandboxed)
|
2020-11-24 09:23:00 +00:00
|
|
|
}
|
2020-11-25 07:16:33 +00:00
|
|
|
|
2021-04-06 07:51:14 +00:00
|
|
|
if (typeof process !== 'undefined') {
|
|
|
|
return process; // Native environment (non-sandboxed)
|
2020-11-25 07:16:33 +00:00
|
|
|
}
|
2021-02-01 09:16:35 +00:00
|
|
|
|
|
|
|
return undefined;
|
2020-11-25 07:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-01 09:16:35 +00:00
|
|
|
* @returns {import('./vs/base/parts/sandbox/electron-sandbox/electronTypes').IpcRenderer | undefined}
|
2020-11-25 07:16:33 +00:00
|
|
|
*/
|
|
|
|
function safeIpcRenderer() {
|
2021-04-06 07:51:14 +00:00
|
|
|
const sandboxGlobals = safeSandboxGlobals();
|
|
|
|
if (sandboxGlobals) {
|
|
|
|
return sandboxGlobals.ipcRenderer;
|
2020-11-25 07:16:33 +00:00
|
|
|
}
|
2021-02-01 09:16:35 +00:00
|
|
|
|
|
|
|
return undefined;
|
2020-11-25 07:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string[]} pathSegments
|
|
|
|
* @returns {Promise<string>}
|
|
|
|
*/
|
|
|
|
async function safeReadNlsFile(...pathSegments) {
|
|
|
|
const ipcRenderer = safeIpcRenderer();
|
|
|
|
if (ipcRenderer) {
|
|
|
|
return ipcRenderer.invoke('vscode:readNlsFile', ...pathSegments);
|
|
|
|
}
|
|
|
|
|
2023-07-28 15:17:50 +00:00
|
|
|
if (fs && path && util) {
|
|
|
|
return (await util.promisify(fs.readFile)(path.join(...pathSegments))).toString();
|
2020-11-25 07:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error('Unsupported operation (read NLS files)');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
2023-07-28 15:17:50 +00:00
|
|
|
if (fs && util) {
|
|
|
|
return util.promisify(fs.writeFile)(path, content);
|
2020-11-25 07:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error('Unsupported operation (write NLS files)');
|
2020-11-24 09:23:00 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
//#endregion
|
2021-02-01 09:16:35 +00:00
|
|
|
|
2020-06-24 07:07:14 +00:00
|
|
|
return {
|
|
|
|
enableASARSupport,
|
|
|
|
setupNLS,
|
2020-07-20 08:30:20 +00:00
|
|
|
fileUriFromPath
|
2020-06-24 07:07:14 +00:00
|
|
|
};
|
|
|
|
}));
|