|
16 | 16 |
|
17 | 17 | // Browser |
18 | 18 | else { |
19 | | - try { |
20 | | - globalThis.MonacoBootstrap = factory(); |
21 | | - } catch (error) { |
22 | | - console.warn(error); // expected when e.g. running with sandbox: true (TODO@sandbox eventually consolidate this) |
23 | | - } |
| 19 | + globalThis.MonacoBootstrap = factory(); |
24 | 20 | } |
25 | 21 | }(this, function () { |
26 | | - const Module = require('module'); |
27 | | - const path = require('path'); |
28 | | - const fs = require('fs'); |
| 22 | + const Module = typeof require === 'function' ? require('module') : undefined; |
| 23 | + const path = typeof require === 'function' ? require('path') : undefined; |
| 24 | + const fs = typeof require === 'function' ? require('fs') : undefined; |
29 | 25 |
|
30 | 26 | //#region global bootstrapping |
31 | 27 |
|
|
34 | 30 |
|
35 | 31 | // Workaround for Electron not installing a handler to ignore SIGPIPE |
36 | 32 | // (https://github.com/electron/electron/issues/13254) |
37 | | - process.on('SIGPIPE', () => { |
38 | | - console.error(new Error('Unexpected SIGPIPE')); |
39 | | - }); |
| 33 | + if (typeof process !== 'undefined') { |
| 34 | + process.on('SIGPIPE', () => { |
| 35 | + console.error(new Error('Unexpected SIGPIPE')); |
| 36 | + }); |
| 37 | + } |
40 | 38 |
|
41 | 39 | //#endregion |
42 | 40 |
|
|
47 | 45 | * @param {string} appRoot |
48 | 46 | */ |
49 | 47 | function enableASARSupport(appRoot) { |
| 48 | + if (!path || !Module) { |
| 49 | + console.warn('enableASARSupport() is only available in node.js environments'); |
| 50 | + return; |
| 51 | + } |
| 52 | + |
50 | 53 | let NODE_MODULES_PATH = appRoot ? path.join(appRoot, 'node_modules') : undefined; |
51 | 54 | if (!NODE_MODULES_PATH) { |
52 | 55 | NODE_MODULES_PATH = path.join(__dirname, '../node_modules'); |
|
84 | 87 | //#region URI helpers |
85 | 88 |
|
86 | 89 | /** |
87 | | - * @param {string} _path |
| 90 | + * @param {string} path |
| 91 | + * @param {boolean} isWindows |
88 | 92 | * @returns {string} |
89 | 93 | */ |
90 | | - function fileUriFromPath(_path) { |
91 | | - let pathName = path.resolve(_path).replace(/\\/g, '/'); |
| 94 | + function fileUriFromPath(path, isWindows) { |
| 95 | + let pathName = path.replace(/\\/g, '/'); |
92 | 96 | if (pathName.length > 0 && pathName.charAt(0) !== '/') { |
93 | 97 | pathName = `/${pathName}`; |
94 | 98 | } |
95 | 99 |
|
96 | 100 | /** @type {string} */ |
97 | 101 | let uri; |
98 | | - if (process.platform === 'win32' && pathName.startsWith('//')) { // specially handle Windows UNC paths |
| 102 | + if (isWindows && pathName.startsWith('//')) { // specially handle Windows UNC paths |
99 | 103 | uri = encodeURI(`file:${pathName}`); |
100 | 104 | } else { |
101 | 105 | uri = encodeURI(`file://${pathName}`); |
|
113 | 117 | * @returns {{locale?: string, availableLanguages: {[lang: string]: string;}, pseudo?: boolean }} |
114 | 118 | */ |
115 | 119 | function setupNLS() { |
| 120 | + if (!path || !fs) { |
| 121 | + console.warn('setupNLS() is only available in node.js environments'); |
| 122 | + return; |
| 123 | + } |
116 | 124 |
|
117 | 125 | // Get the nls configuration into the process.env as early as possible. |
118 | 126 | let nlsConfig = { availableLanguages: {} }; |
|
163 | 171 |
|
164 | 172 | /** |
165 | 173 | * @param {{ portable: string; applicationName: string; }} product |
166 | | - * @returns {{portableDataPath: string;isPortable: boolean;}} |
| 174 | + * @returns {{ portableDataPath: string; isPortable: boolean; }} |
167 | 175 | */ |
168 | 176 | function configurePortable(product) { |
| 177 | + if (!path || !fs) { |
| 178 | + console.warn('configurePortable() is only available in node.js environments'); |
| 179 | + return; |
| 180 | + } |
| 181 | + |
169 | 182 | const appRoot = path.dirname(__dirname); |
170 | 183 |
|
171 | 184 | function getApplicationPath() { |
|
228 | 241 | // Prevents appinsights from monkey patching modules. |
229 | 242 | // This should be called before importing the applicationinsights module |
230 | 243 | function avoidMonkeyPatchFromAppInsights() { |
| 244 | + if (typeof process === 'undefined') { |
| 245 | + console.warn('avoidMonkeyPatchFromAppInsights() is only available in node.js environments'); |
| 246 | + return; |
| 247 | + } |
| 248 | + |
231 | 249 | // @ts-ignore |
232 | 250 | process.env['APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL'] = true; // Skip monkey patching of 3rd party modules by appinsights |
233 | 251 | global['diagnosticsSource'] = {}; // Prevents diagnostic channel (which patches "require") from initializing entirely |
|
0 commit comments