Support using webpack's process: 'mock' (Microsoft/monaco-editor-webpack-plugin#17)

This commit is contained in:
Alex Dima 2018-10-17 12:01:34 +02:00
parent f853267a5b
commit eef12f8734

View file

@ -27,6 +27,10 @@ interface INodeProcess {
env: IProcessEnvironment;
getuid(): number;
nextTick: Function;
versions?: {
electron?: string;
};
type?: string;
}
declare let process: INodeProcess;
declare let global: any;
@ -40,8 +44,18 @@ declare let self: any;
export const LANGUAGE_DEFAULT = 'en';
const isElectronRenderer = (typeof process !== 'undefined' && typeof process.versions !== 'undefined' && typeof process.versions.electron !== 'undefined' && process.type === 'renderer');
// OS detection
if (typeof process === 'object' && typeof process.nextTick === 'function' && typeof process.platform === 'string') {
if (typeof navigator === 'object' && !isElectronRenderer) {
const userAgent = navigator.userAgent;
_isWindows = userAgent.indexOf('Windows') >= 0;
_isMacintosh = userAgent.indexOf('Macintosh') >= 0;
_isLinux = userAgent.indexOf('Linux') >= 0;
_isWeb = true;
_locale = navigator.language;
_language = _locale;
} else if (typeof process === 'object') {
_isWindows = (process.platform === 'win32');
_isMacintosh = (process.platform === 'darwin');
_isLinux = (process.platform === 'linux');
@ -60,14 +74,6 @@ if (typeof process === 'object' && typeof process.nextTick === 'function' && typ
}
}
_isNative = true;
} else if (typeof navigator === 'object') {
const userAgent = navigator.userAgent;
_isWindows = userAgent.indexOf('Windows') >= 0;
_isMacintosh = userAgent.indexOf('Macintosh') >= 0;
_isLinux = userAgent.indexOf('Linux') >= 0;
_isWeb = true;
_locale = navigator.language;
_language = _locale;
}
export const enum Platform {