Drop node.js require for bootstrap and bootstrap-window (#100857)

* sandbox - load bootstrap/bootstrap-window via script tags (workbench)

* sandbox - adopt script loading for issue reporter and process explorer
This commit is contained in:
Benjamin Pasero 2020-06-24 09:07:14 +02:00 committed by GitHub
parent 4542519ea7
commit a3f86f0923
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 485 additions and 426 deletions

18
src/bootstrap-fork.js vendored
View file

@ -102,8 +102,6 @@ function pipeLoggingToParent() {
const seen = [];
const argsArray = [];
let res;
// Massage some arguments with special treatment
if (args.length) {
for (let i = 0; i < args.length; i++) {
@ -138,7 +136,7 @@ function pipeLoggingToParent() {
}
try {
res = JSON.stringify(argsArray, function (key, value) {
const res = JSON.stringify(argsArray, function (key, value) {
// Objects get special treatment to prevent circles
if (isObject(value) || Array.isArray(value)) {
@ -151,15 +149,15 @@ function pipeLoggingToParent() {
return value;
});
if (res.length > MAX_LENGTH) {
return 'Output omitted for a large object that exceeds the limits';
}
return res;
} catch (error) {
return 'Output omitted for an object that cannot be inspected (' + error.toString() + ')';
return `Output omitted for an object that cannot be inspected ('${error.toString()}')`;
}
if (res && res.length > MAX_LENGTH) {
return 'Output omitted for a large object that exceeds the limits';
}
return res;
}
/**

View file

@ -6,203 +6,214 @@
//@ts-check
'use strict';
const bootstrap = require('./bootstrap');
// Simple module style to support node.js and browser environments
(function (globalThis, factory) {
/**
* @param {string[]} modulePaths
* @param {(result, configuration: object) => any} resultCallback
* @param {{ forceEnableDeveloperKeybindings?: boolean, disallowReloadKeybinding?: boolean, removeDeveloperKeybindingsAfterLoad?: boolean, canModifyDOM?: (config: object) => void, beforeLoaderConfig?: (config: object, loaderConfig: object) => void, beforeRequire?: () => void }=} options
*/
exports.load = function (modulePaths, resultCallback, options) {
// Node.js
if (typeof exports === 'object') {
module.exports = factory();
}
const webFrame = require('electron').webFrame;
// Browser
else {
globalThis.MonacoBootstrapWindow = factory();
}
}(this, function () {
const path = require('path');
const webFrame = require('electron').webFrame;
const ipc = require('electron').ipcRenderer;
const bootstrap = globalThis.MonacoBootstrap || require('./bootstrap');
const args = parseURLQueryArgs();
/**
* // configuration: INativeWindowConfiguration
* @type {{
* zoomLevel?: number,
* extensionDevelopmentPath?: string[],
* extensionTestsPath?: string,
* userEnv?: { [key: string]: string | undefined },
* appRoot?: string,
* nodeCachedDataDir?: string
* }} */
const configuration = JSON.parse(args['config'] || '{}') || {};
* @param {string[]} modulePaths
* @param {(result, configuration: object) => any} resultCallback
* @param {{ forceEnableDeveloperKeybindings?: boolean, disallowReloadKeybinding?: boolean, removeDeveloperKeybindingsAfterLoad?: boolean, canModifyDOM?: (config: object) => void, beforeLoaderConfig?: (config: object, loaderConfig: object) => void, beforeRequire?: () => void }=} options
*/
function load(modulePaths, resultCallback, options) {
const args = parseURLQueryArgs();
/**
* // configuration: INativeWindowConfiguration
* @type {{
* zoomLevel?: number,
* extensionDevelopmentPath?: string[],
* extensionTestsPath?: string,
* userEnv?: { [key: string]: string | undefined },
* appRoot?: string,
* nodeCachedDataDir?: string
* }} */
const configuration = JSON.parse(args['config'] || '{}') || {};
// Apply zoom level early to avoid glitches
const zoomLevel = configuration.zoomLevel;
if (typeof zoomLevel === 'number' && zoomLevel !== 0) {
webFrame.setZoomLevel(zoomLevel);
// Apply zoom level early to avoid glitches
const zoomLevel = configuration.zoomLevel;
if (typeof zoomLevel === 'number' && zoomLevel !== 0) {
webFrame.setZoomLevel(zoomLevel);
}
// Error handler
process.on('uncaughtException', function (error) {
onUnexpectedError(error, enableDeveloperTools);
});
// Developer tools
const enableDeveloperTools = (process.env['VSCODE_DEV'] || !!configuration.extensionDevelopmentPath) && !configuration.extensionTestsPath;
let developerToolsUnbind;
if (enableDeveloperTools || (options && options.forceEnableDeveloperKeybindings)) {
developerToolsUnbind = registerDeveloperKeybindings(options && options.disallowReloadKeybinding);
}
// Correctly inherit the parent's environment
Object.assign(process.env, configuration.userEnv);
// Enable ASAR support
bootstrap.enableASARSupport(path.join(configuration.appRoot, 'node_modules'));
if (options && typeof options.canModifyDOM === 'function') {
options.canModifyDOM(configuration);
}
// Get the nls configuration into the process.env as early as possible.
const nlsConfig = bootstrap.setupNLS();
let locale = nlsConfig.availableLanguages['*'] || 'en';
if (locale === 'zh-tw') {
locale = 'zh-Hant';
} else if (locale === 'zh-cn') {
locale = 'zh-Hans';
}
window.document.documentElement.setAttribute('lang', locale);
// Load the loader
const amdLoader = require(`${configuration.appRoot}/out/vs/loader.js`);
const amdRequire = amdLoader.require;
const amdDefine = amdLoader.require.define;
const nodeRequire = amdLoader.require.nodeRequire;
window['nodeRequire'] = nodeRequire;
window['require'] = amdRequire;
// replace the patched electron fs with the original node fs for all AMD code
amdDefine('fs', ['original-fs'], function (originalFS) { return originalFS; });
window['MonacoEnvironment'] = {};
const loaderConfig = {
baseUrl: `${bootstrap.uriFromPath(configuration.appRoot)}/out`,
'vs/nls': nlsConfig,
nodeModules: [/*BUILD->INSERT_NODE_MODULES*/]
};
// cached data config
if (configuration.nodeCachedDataDir) {
loaderConfig.nodeCachedData = {
path: configuration.nodeCachedDataDir,
seed: modulePaths.join('')
};
}
if (options && typeof options.beforeLoaderConfig === 'function') {
options.beforeLoaderConfig(configuration, loaderConfig);
}
amdRequire.config(loaderConfig);
if (nlsConfig.pseudo) {
amdRequire(['vs/nls'], function (nlsPlugin) {
nlsPlugin.setPseudoTranslation(nlsConfig.pseudo);
});
}
if (options && typeof options.beforeRequire === 'function') {
options.beforeRequire();
}
amdRequire(modulePaths, result => {
try {
const callbackResult = resultCallback(result, configuration);
if (callbackResult && typeof callbackResult.then === 'function') {
callbackResult.then(() => {
if (developerToolsUnbind && options && options.removeDeveloperKeybindingsAfterLoad) {
developerToolsUnbind();
}
}, error => {
onUnexpectedError(error, enableDeveloperTools);
});
}
} catch (error) {
onUnexpectedError(error, enableDeveloperTools);
}
}, onUnexpectedError);
}
// Error handler
process.on('uncaughtException', function (error) {
onUnexpectedError(error, enableDeveloperTools);
});
/**
* @returns {{[param: string]: string }}
*/
function parseURLQueryArgs() {
const search = window.location.search || '';
// Developer tools
const enableDeveloperTools = (process.env['VSCODE_DEV'] || !!configuration.extensionDevelopmentPath) && !configuration.extensionTestsPath;
let developerToolsUnbind;
if (enableDeveloperTools || (options && options.forceEnableDeveloperKeybindings)) {
developerToolsUnbind = registerDeveloperKeybindings(options && options.disallowReloadKeybinding);
return search.split(/[?&]/)
.filter(function (param) { return !!param; })
.map(function (param) { return param.split('='); })
.filter(function (param) { return param.length === 2; })
.reduce(function (r, param) { r[param[0]] = decodeURIComponent(param[1]); return r; }, {});
}
// Correctly inherit the parent's environment
Object.assign(process.env, configuration.userEnv);
/**
* @param {boolean} disallowReloadKeybinding
* @returns {() => void}
*/
function registerDeveloperKeybindings(disallowReloadKeybinding) {
const extractKey = function (e) {
return [
e.ctrlKey ? 'ctrl-' : '',
e.metaKey ? 'meta-' : '',
e.altKey ? 'alt-' : '',
e.shiftKey ? 'shift-' : '',
e.keyCode
].join('');
};
// Enable ASAR support
bootstrap.enableASARSupport(path.join(configuration.appRoot, 'node_modules'));
// Devtools & reload support
const TOGGLE_DEV_TOOLS_KB = (process.platform === 'darwin' ? 'meta-alt-73' : 'ctrl-shift-73'); // mac: Cmd-Alt-I, rest: Ctrl-Shift-I
const TOGGLE_DEV_TOOLS_KB_ALT = '123'; // F12
const RELOAD_KB = (process.platform === 'darwin' ? 'meta-82' : 'ctrl-82'); // mac: Cmd-R, rest: Ctrl-R
if (options && typeof options.canModifyDOM === 'function') {
options.canModifyDOM(configuration);
}
let listener = function (e) {
const key = extractKey(e);
if (key === TOGGLE_DEV_TOOLS_KB || key === TOGGLE_DEV_TOOLS_KB_ALT) {
ipc.send('vscode:toggleDevTools');
} else if (key === RELOAD_KB && !disallowReloadKeybinding) {
ipc.send('vscode:reloadWindow');
}
};
// Get the nls configuration into the process.env as early as possible.
const nlsConfig = bootstrap.setupNLS();
window.addEventListener('keydown', listener);
let locale = nlsConfig.availableLanguages['*'] || 'en';
if (locale === 'zh-tw') {
locale = 'zh-Hant';
} else if (locale === 'zh-cn') {
locale = 'zh-Hans';
}
window.document.documentElement.setAttribute('lang', locale);
// Load the loader
const amdLoader = require(configuration.appRoot + '/out/vs/loader.js');
const amdRequire = amdLoader.require;
const amdDefine = amdLoader.require.define;
const nodeRequire = amdLoader.require.nodeRequire;
window['nodeRequire'] = nodeRequire;
window['require'] = amdRequire;
// replace the patched electron fs with the original node fs for all AMD code
amdDefine('fs', ['original-fs'], function (originalFS) { return originalFS; });
window['MonacoEnvironment'] = {};
const loaderConfig = {
baseUrl: bootstrap.uriFromPath(configuration.appRoot) + '/out',
'vs/nls': nlsConfig,
nodeModules: [/*BUILD->INSERT_NODE_MODULES*/]
};
// cached data config
if (configuration.nodeCachedDataDir) {
loaderConfig.nodeCachedData = {
path: configuration.nodeCachedDataDir,
seed: modulePaths.join('')
return function () {
if (listener) {
window.removeEventListener('keydown', listener);
listener = undefined;
}
};
}
if (options && typeof options.beforeLoaderConfig === 'function') {
options.beforeLoaderConfig(configuration, loaderConfig);
}
amdRequire.config(loaderConfig);
if (nlsConfig.pseudo) {
amdRequire(['vs/nls'], function (nlsPlugin) {
nlsPlugin.setPseudoTranslation(nlsConfig.pseudo);
});
}
if (options && typeof options.beforeRequire === 'function') {
options.beforeRequire();
}
amdRequire(modulePaths, result => {
try {
const callbackResult = resultCallback(result, configuration);
if (callbackResult && typeof callbackResult.then === 'function') {
callbackResult.then(() => {
if (developerToolsUnbind && options && options.removeDeveloperKeybindingsAfterLoad) {
developerToolsUnbind();
}
}, error => {
onUnexpectedError(error, enableDeveloperTools);
});
}
} catch (error) {
onUnexpectedError(error, enableDeveloperTools);
/**
* @param {string | Error} error
* @param {boolean} enableDeveloperTools
*/
function onUnexpectedError(error, enableDeveloperTools) {
if (enableDeveloperTools) {
ipc.send('vscode:openDevTools');
}
}, onUnexpectedError);
};
/**
* @returns {{[param: string]: string }}
*/
function parseURLQueryArgs() {
const search = window.location.search || '';
console.error(`[uncaught exception]: ${error}`);
return search.split(/[?&]/)
.filter(function (param) { return !!param; })
.map(function (param) { return param.split('='); })
.filter(function (param) { return param.length === 2; })
.reduce(function (r, param) { r[param[0]] = decodeURIComponent(param[1]); return r; }, {});
}
/**
* @param {boolean} disallowReloadKeybinding
* @returns {() => void}
*/
function registerDeveloperKeybindings(disallowReloadKeybinding) {
const ipc = require('electron').ipcRenderer;
const extractKey = function (e) {
return [
e.ctrlKey ? 'ctrl-' : '',
e.metaKey ? 'meta-' : '',
e.altKey ? 'alt-' : '',
e.shiftKey ? 'shift-' : '',
e.keyCode
].join('');
};
// Devtools & reload support
const TOGGLE_DEV_TOOLS_KB = (process.platform === 'darwin' ? 'meta-alt-73' : 'ctrl-shift-73'); // mac: Cmd-Alt-I, rest: Ctrl-Shift-I
const TOGGLE_DEV_TOOLS_KB_ALT = '123'; // F12
const RELOAD_KB = (process.platform === 'darwin' ? 'meta-82' : 'ctrl-82'); // mac: Cmd-R, rest: Ctrl-R
let listener = function (e) {
const key = extractKey(e);
if (key === TOGGLE_DEV_TOOLS_KB || key === TOGGLE_DEV_TOOLS_KB_ALT) {
ipc.send('vscode:toggleDevTools');
} else if (key === RELOAD_KB && !disallowReloadKeybinding) {
ipc.send('vscode:reloadWindow');
if (error && typeof error !== 'string' && error.stack) {
console.error(error.stack);
}
};
window.addEventListener('keydown', listener);
return function () {
if (listener) {
window.removeEventListener('keydown', listener);
listener = undefined;
}
};
}
/**
* @param {string | Error} error
* @param {boolean} enableDeveloperTools
*/
function onUnexpectedError(error, enableDeveloperTools) {
const ipc = require('electron').ipcRenderer;
if (enableDeveloperTools) {
ipc.send('vscode:openDevTools');
}
console.error('[uncaught exception]: ' + error);
if (error && typeof error !== 'string' && error.stack) {
console.error(error.stack);
}
}
return {
load
};
}));

417
src/bootstrap.js vendored
View file

@ -6,230 +6,249 @@
//@ts-check
'use strict';
//#region global bootstrapping
// Simple module style to support node.js and browser environments
(function (globalThis, factory) {
// increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
Error.stackTraceLimit = 100;
// Node.js
if (typeof exports === 'object') {
module.exports = factory();
}
// Workaround for Electron not installing a handler to ignore SIGPIPE
// (https://github.com/electron/electron/issues/13254)
process.on('SIGPIPE', () => {
console.error(new Error('Unexpected SIGPIPE'));
});
//#endregion
//#region Add support for using node_modules.asar
/**
* @param {string=} nodeModulesPath
*/
exports.enableASARSupport = function (nodeModulesPath) {
// Browser
else {
globalThis.MonacoBootstrap = factory();
}
}(this, function () {
const Module = require('module');
const path = require('path');
const fs = require('fs');
let NODE_MODULES_PATH = nodeModulesPath;
if (!NODE_MODULES_PATH) {
NODE_MODULES_PATH = path.join(__dirname, '../node_modules');
}
//#region global bootstrapping
const NODE_MODULES_ASAR_PATH = NODE_MODULES_PATH + '.asar';
// increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
Error.stackTraceLimit = 100;
// @ts-ignore
const originalResolveLookupPaths = Module._resolveLookupPaths;
// Workaround for Electron not installing a handler to ignore SIGPIPE
// (https://github.com/electron/electron/issues/13254)
process.on('SIGPIPE', () => {
console.error(new Error('Unexpected SIGPIPE'));
});
// @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;
}
}
//#endregion
//#region Add support for using node_modules.asar
/**
* @param {string=} nodeModulesPath
*/
function enableASARSupport(nodeModulesPath) {
let NODE_MODULES_PATH = nodeModulesPath;
if (!NODE_MODULES_PATH) {
NODE_MODULES_PATH = path.join(__dirname, '../node_modules');
}
return paths;
};
};
const NODE_MODULES_ASAR_PATH = `${NODE_MODULES_PATH}.asar`;
//#endregion
// @ts-ignore
const originalResolveLookupPaths = Module._resolveLookupPaths;
//#region URI helpers
/**
* @param {string} _path
* @returns {string}
*/
exports.uriFromPath = function (_path) {
const path = require('path');
let pathName = path.resolve(_path).replace(/\\/g, '/');
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
pathName = '/' + pathName;
}
/** @type {string} */
let uri;
if (process.platform === 'win32' && pathName.startsWith('//')) { // specially handle Windows UNC paths
uri = encodeURI('file:' + pathName);
} else {
uri = encodeURI('file://' + pathName);
}
return uri.replace(/#/g, '%23');
};
//#endregion
//#region NLS helpers
/**
* @returns {{locale?: string, availableLanguages: {[lang: string]: string;}, pseudo?: boolean }}
*/
exports.setupNLS = function () {
const path = require('path');
// Get the nls configuration into the process.env as early as possible.
let nlsConfig = { availableLanguages: {} };
if (process.env['VSCODE_NLS_CONFIG']) {
try {
nlsConfig = JSON.parse(process.env['VSCODE_NLS_CONFIG']);
} catch (e) {
// Ignore
}
}
if (nlsConfig._resolvedLanguagePackCoreLocation) {
const bundles = Object.create(null);
nlsConfig.loadBundle = function (bundle, language, cb) {
const result = bundles[bundle];
if (result) {
cb(undefined, result);
return;
}
const bundleFile = path.join(nlsConfig._resolvedLanguagePackCoreLocation, bundle.replace(/\//g, '!') + '.nls.json');
readFile(bundleFile).then(function (content) {
const json = JSON.parse(content);
bundles[bundle] = json;
cb(undefined, json);
}).catch((error) => {
try {
if (nlsConfig._corruptedFile) {
writeFile(nlsConfig._corruptedFile, 'corrupted').catch(function (error) { console.error(error); });
// @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;
}
} finally {
cb(error, undefined);
}
});
}
return paths;
};
}
return nlsConfig;
};
//#endregion
/**
* @param {string} file
* @returns {Promise<string>}
*/
function readFile(file) {
const fs = require('fs');
return fs.promises.readFile(file, 'utf8');
}
//#region URI helpers
/**
* @param {string} file
* @param {string} content
* @returns {Promise<void>}
*/
function writeFile(file, content) {
const fs = require('fs');
return fs.promises.writeFile(file, content, 'utf8');
}
//#endregion
//#region Portable helpers
/**
* @returns {{ portableDataPath: string, isPortable: boolean }}
*/
exports.configurePortable = function () {
const product = require('../product.json');
const path = require('path');
const fs = require('fs');
const appRoot = path.dirname(__dirname);
function getApplicationPath() {
if (process.env['VSCODE_DEV']) {
return appRoot;
/**
* @param {string} _path
* @returns {string}
*/
function uriFromPath(_path) {
let pathName = path.resolve(_path).replace(/\\/g, '/');
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
pathName = `/${pathName}`;
}
if (process.platform === 'darwin') {
return path.dirname(path.dirname(path.dirname(appRoot)));
}
return path.dirname(path.dirname(appRoot));
}
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);
}
const portableDataPath = getPortableDataPath();
const isPortable = !('target' in product) && fs.existsSync(portableDataPath);
const portableTempPath = path.join(portableDataPath, 'tmp');
const isTempPortable = isPortable && fs.existsSync(portableTempPath);
if (isPortable) {
process.env['VSCODE_PORTABLE'] = portableDataPath;
} else {
delete process.env['VSCODE_PORTABLE'];
}
if (isTempPortable) {
if (process.platform === 'win32') {
process.env['TMP'] = portableTempPath;
process.env['TEMP'] = portableTempPath;
/** @type {string} */
let uri;
if (process.platform === 'win32' && pathName.startsWith('//')) { // specially handle Windows UNC paths
uri = encodeURI(`file:${pathName}`);
} else {
process.env['TMPDIR'] = portableTempPath;
uri = encodeURI(`file://${pathName}`);
}
return uri.replace(/#/g, '%23');
}
//#endregion
//#region NLS helpers
/**
* @returns {{locale?: string, availableLanguages: {[lang: string]: string;}, pseudo?: boolean }}
*/
function setupNLS() {
// Get the nls configuration into the process.env as early as possible.
let nlsConfig = { availableLanguages: {} };
if (process.env['VSCODE_NLS_CONFIG']) {
try {
nlsConfig = JSON.parse(process.env['VSCODE_NLS_CONFIG']);
} catch (e) {
// Ignore
}
}
if (nlsConfig._resolvedLanguagePackCoreLocation) {
const bundles = Object.create(null);
nlsConfig.loadBundle = function (bundle, language, cb) {
const result = bundles[bundle];
if (result) {
cb(undefined, result);
return;
}
const bundleFile = path.join(nlsConfig._resolvedLanguagePackCoreLocation, `${bundle.replace(/\//g, '!')}.nls.json`);
readFile(bundleFile).then(function (content) {
const json = JSON.parse(content);
bundles[bundle] = json;
cb(undefined, json);
}).catch((error) => {
try {
if (nlsConfig._corruptedFile) {
writeFile(nlsConfig._corruptedFile, 'corrupted').catch(function (error) { console.error(error); });
}
} finally {
cb(error, undefined);
}
});
};
}
return nlsConfig;
}
/**
* @param {string} file
* @returns {Promise<string>}
*/
function readFile(file) {
return fs.promises.readFile(file, 'utf8');
}
/**
* @param {string} file
* @param {string} content
* @returns {Promise<void>}
*/
function writeFile(file, content) {
return fs.promises.writeFile(file, content, 'utf8');
}
//#endregion
//#region Portable helpers
/**
* @param {{ portable: string; applicationName: string; }} product
* @returns {{portableDataPath: string;isPortable: boolean;}}
*/
function configurePortable(product) {
const appRoot = path.dirname(__dirname);
function getApplicationPath() {
if (process.env['VSCODE_DEV']) {
return appRoot;
}
if (process.platform === 'darwin') {
return path.dirname(path.dirname(path.dirname(appRoot)));
}
return path.dirname(path.dirname(appRoot));
}
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);
}
const portableDataPath = getPortableDataPath();
const isPortable = !('target' in product) && fs.existsSync(portableDataPath);
const portableTempPath = path.join(portableDataPath, 'tmp');
const isTempPortable = isPortable && fs.existsSync(portableTempPath);
if (isPortable) {
process.env['VSCODE_PORTABLE'] = portableDataPath;
} else {
delete process.env['VSCODE_PORTABLE'];
}
if (isTempPortable) {
if (process.platform === 'win32') {
process.env['TMP'] = portableTempPath;
process.env['TEMP'] = portableTempPath;
} else {
process.env['TMPDIR'] = portableTempPath;
}
}
return {
portableDataPath,
isPortable
};
}
//#endregion
//#region ApplicationInsights
// Prevents appinsights from monkey patching modules.
// This should be called before importing the applicationinsights module
function avoidMonkeyPatchFromAppInsights() {
// @ts-ignore
process.env['APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL'] = true; // Skip monkey patching of 3rd party modules by appinsights
global['diagnosticsSource'] = {}; // Prevents diagnostic channel (which patches "require") from initializing entirely
}
//#endregion
return {
portableDataPath,
isPortable
enableASARSupport,
avoidMonkeyPatchFromAppInsights,
configurePortable,
setupNLS,
uriFromPath
};
};
//#endregion
//#region ApplicationInsights
// Prevents appinsights from monkey patching modules.
// This should be called before importing the applicationinsights module
exports.avoidMonkeyPatchFromAppInsights = function () {
// @ts-ignore
process.env['APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL'] = true; // Skip monkey patching of 3rd party modules by appinsights
global['diagnosticsSource'] = {}; // Prevents diagnostic channel (which patches "require") from initializing entirely
};
//#endregion
}));

View file

@ -7,15 +7,16 @@
'use strict';
const bootstrap = require('./bootstrap');
const product = require('../product.json');
// Avoid Monkey Patches from Application Insights
bootstrap.avoidMonkeyPatchFromAppInsights();
// Enable portable support
bootstrap.configurePortable();
bootstrap.configurePortable(product);
// Enable ASAR support
bootstrap.enableASARSupport();
// Load CLI through AMD loader
require('./bootstrap-amd').load('vs/code/node/cli');
require('./bootstrap-amd').load('vs/code/node/cli');

View file

@ -21,7 +21,7 @@ const product = require('../product.json');
const { app, protocol } = require('electron');
// Enable portable support
const portable = bootstrap.configurePortable();
const portable = bootstrap.configurePortable(product);
// Enable ASAR support
bootstrap.enableASARSupport();

View file

@ -1,17 +1,22 @@
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data:; media-src 'none'; child-src 'self'; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https:;">
<style>
body {
display: none
}
</style>
</head>
<body aria-label="">
</body>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data:; media-src 'none'; child-src 'self'; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https:;">
<style>body{display: none}</style>
</head>
<body>
</body>
<!-- Startup via issueReporter.js -->
<script src="issueReporter.js"></script>
<!-- Init Bootstrap Helpers -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<!-- Startup via issueReporter.js -->
<script src="issueReporter.js"></script>
</html>

View file

@ -6,7 +6,13 @@
//@ts-check
'use strict';
const bootstrapWindow = require('../../../../bootstrap-window');
/**
* @type {{ load: (modules: string[], resultCallback: (result, configuration: object) => any, options: object) => unknown }}
*/
const bootstrapWindow = (() => {
// @ts-ignore (defined in bootstrap-window.js)
return window.MonacoBootstrapWindow;
})();
bootstrapWindow.load(['vs/code/electron-browser/issue/issueReporterMain'], function (issueReporter, configuration) {
issueReporter.startup(configuration);

View file

@ -1,17 +1,18 @@
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data:; media-src 'none'; child-src 'self'; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https:;">
</head>
<body aria-label="">
<table id="process-list"></table>
</body>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data:; media-src 'none'; child-src 'self'; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https:;">
</head>
<!-- Init Bootstrap Helpers -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<body aria-label="">
<table id="process-list"></table>
</body>
<!-- Startup via processExplorer.js -->
<script src="processExplorer.js"></script>
</html>
<!-- Startup via processExplorer.js -->
<script src="processExplorer.js"></script>
</html>

View file

@ -6,8 +6,14 @@
//@ts-check
'use strict';
const bootstrapWindow = require('../../../../bootstrap-window');
/**
* @type {{ load: (modules: string[], resultCallback: (result, configuration: object) => any, options: object) => unknown }}
*/
const bootstrapWindow = (() => {
// @ts-ignore (defined in bootstrap-window.js)
return window.MonacoBootstrapWindow;
})();
bootstrapWindow.load(['vs/code/electron-browser/processExplorer/processExplorerMain'], function (processExplorer, configuration) {
processExplorer.startup(configuration.data);
}, { forceEnableDeveloperKeybindings: true });
}, { forceEnableDeveloperKeybindings: true });

View file

@ -8,6 +8,10 @@
<body aria-label="">
</body>
<!-- Init Bootstrap Helpers -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<!-- Startup via workbench.js -->
<script src="workbench.js"></script>
</html>

View file

@ -31,11 +31,17 @@ const perf = (function () {
perf.mark('renderer/started');
const bootstrapWindow = require('../../../../bootstrap-window');
// Setup shell environment
process['lazyEnv'] = getLazyEnv();
/**
* @type {{ load: (modules: string[], resultCallback: (result, configuration: object) => any, options: object) => unknown }}
*/
const bootstrapWindow = (() => {
// @ts-ignore (defined in bootstrap-window.js)
return window.MonacoBootstrapWindow;
})();
// Load workbench main JS, CSS and NLS all in parallel. This is an
// optimization to prevent a waterfall of loading to happen, because
// we know for a fact that workbench.desktop.main will depend on
@ -54,18 +60,20 @@ bootstrapWindow.load([
// @ts-ignore
return require('vs/workbench/electron-browser/desktop.main').main(configuration);
});
}, {
removeDeveloperKeybindingsAfterLoad: true,
canModifyDOM: function (windowConfig) {
showPartsSplash(windowConfig);
},
beforeLoaderConfig: function (windowConfig, loaderConfig) {
loaderConfig.recordStats = true;
},
beforeRequire: function () {
perf.mark('willLoadWorkbenchMain');
{
removeDeveloperKeybindingsAfterLoad: true,
canModifyDOM: function (windowConfig) {
showPartsSplash(windowConfig);
},
beforeLoaderConfig: function (windowConfig, loaderConfig) {
loaderConfig.recordStats = true;
},
beforeRequire: function () {
perf.mark('willLoadWorkbenchMain');
}
}
});
);
/**
* @param {{