MCPcopy
hub / github.com/vercel/hyper / init

Method init

app/session.ts:109–203  ·  view source on GitHub ↗
({uid, rows, cols: columns, cwd, shell: _shell, shellArgs: _shellArgs}: SessionOptions)

Source from the content-addressed store, hash-verified

107 }
108
109 init({uid, rows, cols: columns, cwd, shell: _shell, shellArgs: _shellArgs}: SessionOptions) {
110 const cleanEnv =
111 process.env['APPIMAGE'] && process.env['APPDIR'] ? shellEnv.sync(_shell || defaultShell) : process.env;
112 const baseEnv = Object.assign(
113 {},
114 cleanEnv,
115 {
116 LANG: `${osLocale.sync().replace(/-/, '_')}.UTF-8`,
117 TERM: 'xterm-256color',
118 COLORTERM: 'truecolor',
119 TERM_PROGRAM: productName,
120 TERM_PROGRAM_VERSION: version
121 },
122 envFromConfig
123 );
124
125 // path to AppImage mount point is added to PATH environment variable automatically
126 // which conflicts with the cli
127 if (baseEnv['APPIMAGE'] && baseEnv['APPDIR']) {
128 baseEnv['PATH'] = [dirname(cliScriptPath)]
129 .concat((baseEnv['PATH'] || '').split(':').filter((val) => !val.startsWith(baseEnv['APPDIR'])))
130 .join(':');
131 }
132
133 // Electron has a default value for process.env.GOOGLE_API_KEY
134 // We don't want to leak this to the shell
135 // See https://github.com/vercel/hyper/issues/696
136 if (baseEnv.GOOGLE_API_KEY && process.env.GOOGLE_API_KEY === baseEnv.GOOGLE_API_KEY) {
137 delete baseEnv.GOOGLE_API_KEY;
138 }
139
140 const defaultShellArgs = ['--login'];
141
142 const options: IWindowsPtyForkOptions = {
143 cols: columns,
144 rows,
145 cwd,
146 env: getDecoratedEnv(baseEnv)
147 };
148
149 // if config do not set the useConpty, it will be judged by the node-pty
150 if (typeof useConpty === 'boolean') {
151 options.useConpty = useConpty;
152 }
153
154 const shell = _shell || defaultShell;
155 const shellArgs = _shellArgs || defaultShellArgs;
156
157 try {
158 this.pty = spawn(shell, shellArgs, options);
159 } catch (_err) {
160 const err = _err as {message: string};
161 if (/is not a function/.test(err.message)) {
162 throw createNodePtyError();
163 } else {
164 throw err;
165 }
166 }

Callers 1

constructorMethod · 0.95

Calls 11

getDecoratedEnvFunction · 0.90
dirnameFunction · 0.85
createNodePtyErrorFunction · 0.85
concatMethod · 0.80
filterMethod · 0.80
testMethod · 0.80
onMethod · 0.80
spawnFunction · 0.50
writeMethod · 0.45
emitMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected