|
21 | 21 | globalThis.MonacoBootstrapWindow = factory(); |
22 | 22 | } |
23 | 23 | }(this, function () { |
24 | | - const path = require.__$__nodeRequire('path'); |
25 | | - const bootstrap = globalThis.MonacoBootstrap; |
| 24 | + const preloadGlobals = globals(); |
| 25 | + const sandbox = preloadGlobals.context.sandbox; |
| 26 | + const safeProcess = sandbox ? preloadGlobals.process : process; |
26 | 27 |
|
27 | 28 | /** |
28 | 29 | * @param {string[]} modulePaths |
|
43 | 44 | const configuration = JSON.parse(args['config'] || '{}') || {}; |
44 | 45 |
|
45 | 46 | // Error handler |
46 | | - process.on('uncaughtException', function (error) { |
| 47 | + safeProcess.on('uncaughtException', function (error) { |
47 | 48 | onUnexpectedError(error, enableDeveloperTools); |
48 | 49 | }); |
49 | 50 |
|
50 | 51 | // Developer tools |
51 | | - const enableDeveloperTools = (process.env['VSCODE_DEV'] || !!configuration.extensionDevelopmentPath) && !configuration.extensionTestsPath; |
| 52 | + const enableDeveloperTools = (safeProcess.env['VSCODE_DEV'] || !!configuration.extensionDevelopmentPath) && !configuration.extensionTestsPath; |
52 | 53 | let developerToolsUnbind; |
53 | 54 | if (enableDeveloperTools || (options && options.forceEnableDeveloperKeybindings)) { |
54 | 55 | developerToolsUnbind = registerDeveloperKeybindings(options && options.disallowReloadKeybinding); |
55 | 56 | } |
56 | 57 |
|
57 | | - // Correctly inherit the parent's environment |
58 | | - Object.assign(process.env, configuration.userEnv); |
| 58 | + // Correctly inherit the parent's environment (TODO@sandbox non-sandboxed only) |
| 59 | + if (!sandbox) { |
| 60 | + Object.assign(safeProcess.env, configuration.userEnv); |
| 61 | + } |
59 | 62 |
|
60 | | - // Enable ASAR support |
61 | | - bootstrap.enableASARSupport(path.join(configuration.appRoot, 'node_modules')); |
| 63 | + // Enable ASAR support (TODO@sandbox non-sandboxed only) |
| 64 | + if (!sandbox) { |
| 65 | + globalThis.MonacoBootstrap.enableASARSupport(configuration.appRoot); |
| 66 | + } |
62 | 67 |
|
63 | 68 | if (options && typeof options.canModifyDOM === 'function') { |
64 | 69 | options.canModifyDOM(configuration); |
65 | 70 | } |
66 | 71 |
|
67 | | - // Get the nls configuration into the process.env as early as possible. |
68 | | - const nlsConfig = bootstrap.setupNLS(); |
| 72 | + // Get the nls configuration into the process.env as early as possible (TODO@sandbox non-sandboxed only) |
| 73 | + const nlsConfig = sandbox ? { availableLanguages: {} } : globalThis.MonacoBootstrap.setupNLS(); |
69 | 74 |
|
70 | 75 | let locale = nlsConfig.availableLanguages['*'] || 'en'; |
71 | 76 | if (locale === 'zh-tw') { |
|
76 | 81 |
|
77 | 82 | window.document.documentElement.setAttribute('lang', locale); |
78 | 83 |
|
79 | | - // do not advertise AMD to avoid confusing UMD modules loaded with nodejs |
80 | | - window['define'] = undefined; |
| 84 | + // do not advertise AMD to avoid confusing UMD modules loaded with nodejs (TODO@sandbox non-sandboxed only) |
| 85 | + if (!sandbox) { |
| 86 | + window['define'] = undefined; |
| 87 | + } |
81 | 88 |
|
82 | | - // replace the patched electron fs with the original node fs for all AMD code |
83 | | - require.define('fs', ['original-fs'], function (originalFS) { return originalFS; }); |
| 89 | + // replace the patched electron fs with the original node fs for all AMD code (TODO@sandbox non-sandboxed only) |
| 90 | + if (!sandbox) { |
| 91 | + require.define('fs', ['original-fs'], function (originalFS) { return originalFS; }); |
| 92 | + } |
84 | 93 |
|
85 | 94 | window['MonacoEnvironment'] = {}; |
86 | 95 |
|
87 | 96 | const loaderConfig = { |
88 | | - baseUrl: `${bootstrap.uriFromPath(configuration.appRoot)}/out`, |
| 97 | + baseUrl: `${uriFromPath(configuration.appRoot)}/out`, |
89 | 98 | 'vs/nls': nlsConfig, |
90 | 99 | amdModulesPattern: /^vs\//, |
91 | 100 | }; |
|
150 | 159 | * @returns {() => void} |
151 | 160 | */ |
152 | 161 | function registerDeveloperKeybindings(disallowReloadKeybinding) { |
153 | | - const ipcRenderer = globals().ipcRenderer; |
| 162 | + const ipcRenderer = preloadGlobals.ipcRenderer; |
154 | 163 |
|
155 | 164 | const extractKey = function (e) { |
156 | 165 | return [ |
|
163 | 172 | }; |
164 | 173 |
|
165 | 174 | // Devtools & reload support |
166 | | - const TOGGLE_DEV_TOOLS_KB = (process.platform === 'darwin' ? 'meta-alt-73' : 'ctrl-shift-73'); // mac: Cmd-Alt-I, rest: Ctrl-Shift-I |
| 175 | + const TOGGLE_DEV_TOOLS_KB = (safeProcess.platform === 'darwin' ? 'meta-alt-73' : 'ctrl-shift-73'); // mac: Cmd-Alt-I, rest: Ctrl-Shift-I |
167 | 176 | const TOGGLE_DEV_TOOLS_KB_ALT = '123'; // F12 |
168 | | - const RELOAD_KB = (process.platform === 'darwin' ? 'meta-82' : 'ctrl-82'); // mac: Cmd-R, rest: Ctrl-R |
| 177 | + const RELOAD_KB = (safeProcess.platform === 'darwin' ? 'meta-82' : 'ctrl-82'); // mac: Cmd-R, rest: Ctrl-R |
169 | 178 |
|
170 | 179 | let listener = function (e) { |
171 | 180 | const key = extractKey(e); |
|
192 | 201 | */ |
193 | 202 | function onUnexpectedError(error, enableDeveloperTools) { |
194 | 203 | if (enableDeveloperTools) { |
195 | | - const ipcRenderer = globals().ipcRenderer; |
| 204 | + const ipcRenderer = preloadGlobals.ipcRenderer; |
196 | 205 | ipcRenderer.send('vscode:openDevTools'); |
197 | 206 | } |
198 | 207 |
|
|
211 | 220 | return window.vscode; |
212 | 221 | } |
213 | 222 |
|
| 223 | + /** |
| 224 | + * TODO@sandbox this should not use the file:// protocol at all |
| 225 | + * and be consolidated with the fileUriFromPath() method in |
| 226 | + * bootstrap.js. |
| 227 | + * |
| 228 | + * @param {string} path |
| 229 | + * @returns {string} |
| 230 | + */ |
| 231 | + function uriFromPath(path) { |
| 232 | + let pathName = path.replace(/\\/g, '/'); |
| 233 | + if (pathName.length > 0 && pathName.charAt(0) !== '/') { |
| 234 | + pathName = `/${pathName}`; |
| 235 | + } |
| 236 | + |
| 237 | + /** @type {string} */ |
| 238 | + let uri; |
| 239 | + if (safeProcess.platform === 'win32' && pathName.startsWith('//')) { // specially handle Windows UNC paths |
| 240 | + uri = encodeURI(`file:${pathName}`); |
| 241 | + } else { |
| 242 | + uri = encodeURI(`file://${pathName}`); |
| 243 | + } |
| 244 | + |
| 245 | + return uri.replace(/#/g, '%23'); |
| 246 | + } |
| 247 | + |
214 | 248 | return { |
215 | 249 | load, |
216 | 250 | globals |
|
0 commit comments