Skip to content

Commit

Permalink
fix: platform detection after Node.js 21 (#3956)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain authored Aug 20, 2024
1 parent 1e0967c commit 10c5d83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
5 changes: 1 addition & 4 deletions packages/terminal-next/src/common/preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ export const terminalPreferenceSchema: PreferenceSchema = {
},
[CodeTerminalSettingId.ShellArgsMacOs]: {
type: 'array',
// Unlike on Linux, ~/.profile is not sourced when logging into a macOS session. This
// is the reason terminals on macOS typically run login shells by default which set up
// the environment. See http://unix.stackexchange.com/a/119675/115410
default: ['-l'],
default: [],
markdownDeprecationMessage: shellDeprecationMessageOsx,
},
[CodeTerminalSettingId.ShellArgsWindows]: {
Expand Down
41 changes: 22 additions & 19 deletions packages/utils/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,36 @@ interface INodeProcess {
nextTick: any;
versions?: {
electron?: string;
node?: string;
chrome?: string;
};
type?: string;
}
declare const process: INodeProcess;
declare const global: any;

let nodeProcess: INodeProcess | undefined;
if (typeof process !== 'undefined' && typeof process?.versions?.node === 'string') {

This comment has been minimized.

Copy link
@erha19

erha19 Sep 13, 2024

Member

遇到一个问题,这里的修改可能会导致纯前端构建出错,最终导致快捷键绑定异常

This comment has been minimized.

Copy link
@erha19

erha19 Sep 13, 2024

Member

解决方案:
Webpack.DeginePlugin 中:

{
      'process.versions': JSON.stringify(false),
}

This comment has been minimized.

Copy link
@bytemain

bytemain Sep 13, 2024

Author Member

webpack 注入的 process.versions.node 值是什么?

This comment has been minimized.

Copy link
@erha19

erha19 Sep 13, 2024

Member

就是正常的字符串值 v5.0

nodeProcess = process;
}

interface INavigator {
userAgent: string;
language: string;
}
declare const navigator: INavigator;
declare const self: any;

const isElectronRenderer =
typeof process !== 'undefined' &&
typeof process.versions !== 'undefined' &&
typeof process.versions.electron !== 'undefined' &&
process.type === 'renderer';
const isElectronRenderer = typeof nodeProcess?.versions?.electron === 'string' && nodeProcess.type === 'renderer';

// OS detection
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;
_isWebKit = userAgent.indexOf('AppleWebKit') >= 0;
} else if (typeof process === 'object') {
_isWindows = process.platform === 'win32';
_isMacintosh = process.platform === 'darwin';
_isLinux = process.platform === 'linux';
if (typeof nodeProcess === 'object') {
_isWindows = nodeProcess.platform === 'win32';
_isMacintosh = nodeProcess.platform === 'darwin';
_isLinux = nodeProcess.platform === 'linux';
_locale = LANGUAGE_DEFAULT;
_language = LANGUAGE_DEFAULT;
const rawNlsConfig = process.env['VSCODE_NLS_CONFIG'];
const rawNlsConfig = nodeProcess.env['VSCODE_NLS_CONFIG'];
if (rawNlsConfig) {
try {
const nlsConfig: NLSConfig = JSON.parse(rawNlsConfig);
Expand All @@ -80,6 +74,15 @@ if (typeof navigator === 'object' && !isElectronRenderer) {
} catch (e) {}
}
_isNative = true;
} else 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;
_isWebKit = userAgent.indexOf('AppleWebKit') >= 0;
}

export const enum Platform {
Expand Down

0 comments on commit 10c5d83

Please sign in to comment.