Skip to content

Commit 41291a6

Browse files
committed
chore: Stop using node-pty in Electron renderer process
part of kubernetes-sigs#7456
1 parent 1b19c1e commit 41291a6

File tree

34 files changed

+854
-782
lines changed

34 files changed

+854
-782
lines changed

package-lock.json

+476-586
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
"@types/needle": "2.5.1",
9090
"@types/node": "12.12.31",
9191
"@types/pluralize": "0.0.29",
92-
"@types/react": "17.0.8",
93-
"@types/react-dom": "17.0.5",
92+
"@types/react": "17.0.9",
93+
"@types/react-dom": "17.0.6",
9494
"@types/resize-observer-browser": "0.1.5",
9595
"@types/tmp": "0.2.0",
9696
"@types/turndown": "5.0.0",
@@ -101,7 +101,7 @@
101101
"colors": "1.4.0",
102102
"concurrently": "6.2.0",
103103
"debug": "4.3.1",
104-
"electron": "10.4.7",
104+
"electron": "11.4.7",
105105
"eslint": "6.8.0",
106106
"eslint-plugin-header": "3.1.1",
107107
"eslint-config-prettier": "6.10.1",
@@ -119,7 +119,7 @@
119119
"nyc": "14.1.1",
120120
"prettier": "1.19.1",
121121
"properties-parser": "0.3.1",
122-
"spectron": "12.0.0",
122+
"spectron": "13.0.0",
123123
"tmp": "0.2.1",
124124
"typescript": "4.2.4",
125125
"uuid": "8.3.2"

packages/builder/bin/pty-rebuild.sh

+7-15
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,17 @@ if [ "$1" = "electron" ]; then
3030
ARCH=$(node -e 'console.log(require("os").arch())')
3131
TARGET="${PLATFORM}-${ARCH}"
3232
echo "node-pty PLATFORM=$TARGET"
33-
mkdir -p node_modules/node-pty-prebuilt-multiarch/build/Release
34-
rm -f node_modules/node-pty-prebuilt-multiarch/build/Release/*
35-
cp node_modules/@kui-shell/builder/dist/electron/vendor/node-pty-prebuilt-multiarch/build/$TARGET/electron/* node_modules/node-pty-prebuilt-multiarch/build/Release
36-
gunzip node_modules/node-pty-prebuilt-multiarch/build/Release/*.gz
37-
ls node_modules/node-pty-prebuilt-multiarch/build/Release
33+
mkdir -p node_modules/node-pty/build/Release
34+
rm -f node_modules/node-pty/build/Release/*
35+
cp node_modules/@kui-shell/builder/dist/electron/vendor/node-pty/build/$TARGET/electron/* node_modules/node-pty/build/Release
36+
gunzip node_modules/node-pty/build/Release/*.gz
37+
ls node_modules/node-pty/build/Release
3838
else
3939
if [ -e ./node_modules/.bin/rc ] && [ ! -L ./node_modules/.bin/rc ]; then
4040
echo "rc is not a symlink"
4141
(cd node_modules/.bin && rm -f rc && node -e 'require("fs").symlinkSync("../rc/cli.js", "rc")')
4242
fi
43-
if [ -e ./node_modules/.bin/prebuild-install ] && [ ! -L ./node_modules/.bin/prebuild-install ]; then
44-
echo "prebuild-install is not a symlink"
45-
(cd node_modules/.bin && rm -f prebuild-install && node -e 'require("fs").symlinkSync("../prebuild-install/bin.js", "prebuild-install")')
46-
fi
4743

48-
cd node_modules/node-pty-prebuilt-multiarch
49-
prebuild-install --force --download --runtime $1
44+
cd node_modules/node-pty
45+
npm run install
5046
fi
51-
52-
# Notes: why --force --download? for some reason, when run from `npm
53-
# run ...` prebuild-install insists on the --build-from-source option,
54-
# and nothing we do, short of --force, seems to override this

packages/builder/dist/electron/builders/electron.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const { exec } = require('child_process')
5353
const sign = require('./sign')
5454
const notarize = require('./notarize')
5555

56-
const nodePty = 'node-pty-prebuilt-multiarch'
56+
const nodePty = 'node-pty'
5757

5858
/**
5959
* afterCopy hook to build webpack bundles.

packages/builder/dist/electron/package-lock.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/builder/dist/electron/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "Apache-2.0",
1111
"devDependencies": {
1212
"debug": "4.3.1",
13-
"electron": "10.4.7",
13+
"electron": "11.4.7",
1414
"electron-packager": "15.2.0",
1515
"glob": "7.1.7",
1616
"globby": "11.0.3"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
This directory contains only prebuilt versions of
2-
[node-pty-prebuilt-multiarch](https://github.com/oznu/node-pty-prebuilt-multiarch). The
3-
code has not been modified from this npm release: 0.9.0-beta21.legacy
2+
[node-pty](https://github.com/microsoft/node-pty). The
3+
code has not been modified from this npm release: 0.10.1

packages/builder/npmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
runtime=electron
2-
target=10.0.0
2+
target=11.0.0
33
build_from_source=true
44
disturl=https://atom.io/download/electron

packages/builder/src/kui-dist-init.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ export const main = async (argv: string[]) => {
120120
pjson.scripts.compile = 'kui-compile'
121121
pjson.scripts.watch = 'tsc --build . --watch'
122122
pjson.scripts['watch:webpack'] = 'kui-watch-webpack'
123-
pjson.scripts['pty:rebuild'] = 'cd node_modules/node-pty-prebuilt-multiarch && npm run install'
123+
pjson.scripts['pty:rebuild'] = 'cd node_modules/node-pty && npm run install'
124124
pjson.scripts['pty:electron'] =
125-
'if [ ! -e node_modules/node-pty-prebuilt-multiarch/.npmrc ]; then cp node_modules/@kui-shell/builder/npmrc node_modules/node-pty-prebuilt-multiarch/.npmrc && npm run pty:rebuild; fi'
125+
'if [ ! -e node_modules/node-pty/.npmrc ]; then cp node_modules/@kui-shell/builder/npmrc node_modules/node-pty/.npmrc && npm run pty:rebuild; fi'
126126
pjson.scripts['pty:nodejs'] =
127-
'if [ -e node_modules/node-pty-prebuilt-multiarch/.npmrc ]; then rm -f node_modules/node-pty-prebuilt-multiarch/.npmrc; npm run pty:rebuild; fi'
127+
'if [ -e node_modules/node-pty/.npmrc ]; then rm -f node_modules/node-pty/.npmrc; npm run pty:rebuild; fi'
128128
pjson.scripts.start = 'npm run -s init && npm run -s pty:electron && electron . shell'
129129
await writeFile('package.json', JSON.stringify(pjson, undefined, 2))
130130

packages/core/src/main/spawn-electron.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929

3030
import windowDefaults, { popupWindowDefaults } from '../webapp/defaults'
3131
import ISubwindowPrefs from '../models/SubwindowPrefs'
32+
import { webpackPath } from '../plugins/path'
3233

3334
/**
3435
* Keep a global reference of the window object, if you don't, the window will
@@ -170,6 +171,7 @@ export function createWindow(
170171
webPreferences: {
171172
enableRemoteModule: true,
172173
backgroundThrottling: false,
174+
contextIsolation: false, // prior to electron 12, nodeIntegration: true did not need this
173175
nodeIntegration: true // prior to electron 5, this was the default
174176
}
175177
// titleBarStyle: process.platform === 'darwin' ? 'hiddenInset' : 'default'
@@ -442,10 +444,10 @@ export function createWindow(
442444
debug('invoke', message)
443445

444446
try {
445-
const mod = await import(message.module)
447+
const mod = await import('@kui-shell/plugin-' + webpackPath(message.module) + '/dist/index.js')
446448
debug('invoke got module')
447449

448-
const returnValue = await mod[message.main || 'main'](message.args)
450+
const returnValue = await mod[message.main || 'main'](message.args, event.sender)
449451
debug('invoke got returnValue', returnValue)
450452

451453
event.sender.send(
@@ -600,9 +602,6 @@ export async function initElectron(
600602
debug('loading electron')
601603
const Electron = await import('electron')
602604
app = Electron.app
603-
if (app) {
604-
app.allowRendererProcessReuse = false
605-
}
606605
}
607606

608607
// deal with multiple processes

packages/test/src/api/common.ts

+42-35
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,46 @@ const prepareElectron = (popup: string[]) => {
209209
return new Application(opts)
210210
}
211211

212+
/** Add app.client commands */
213+
function addCommands(ctx: ISuite) {
214+
// add an isActive command; isFocused is not what we want
215+
if (ctx.app && ctx.app.client) {
216+
// ref: https://github.com/webdriverio/webdriverio/issues/1362#issuecomment-224042781
217+
ctx.app.client.addCommand('isActive', selector => {
218+
return ctx.app.client.execute(selector => {
219+
const focused = document.activeElement
220+
221+
if (!focused || focused === document.body) {
222+
return false
223+
} else if (document.querySelector) {
224+
return document.querySelector(selector) === focused
225+
}
226+
227+
return false
228+
}, selector)
229+
})
230+
}
231+
}
232+
233+
/** restart the app */
234+
export const restart = async (ctx: ISuite) => {
235+
try {
236+
await ctx.app.restart()
237+
addCommands(ctx)
238+
} catch (err) {
239+
const errorIsNavigatedError: boolean =
240+
err.message.includes('Inspected target navigated or closed') ||
241+
err.message.includes('cannot determine loading status') ||
242+
err.message.includes('Inspected target navigated or closed')
243+
244+
if (!errorIsNavigatedError) {
245+
throw err
246+
}
247+
}
248+
249+
return CLI.waitForSession(ctx)
250+
}
251+
212252
/** reload the app */
213253
export const refresh = async (ctx: ISuite, wait = true, clean = false) => {
214254
try {
@@ -319,23 +359,8 @@ export const before = (ctx: ISuite, options?: BeforeOptions): HookFunction => {
319359
ctx.timeout(process.env.TIMEOUT || 60000)
320360
await start()
321361

322-
// add an isActive command; isFocused is not what we want
323-
if (ctx.app && ctx.app.client) {
324-
// ref: https://github.com/webdriverio/webdriverio/issues/1362#issuecomment-224042781
325-
ctx.app.client.addCommand('isActive', selector => {
326-
return ctx.app.client.execute(selector => {
327-
const focused = document.activeElement
328-
329-
if (!focused || focused === document.body) {
330-
return false
331-
} else if (document.querySelector) {
332-
return document.querySelector(selector) === focused
333-
}
334-
335-
return false
336-
}, selector)
337-
})
338-
}
362+
// add app.client commands
363+
addCommands(ctx)
339364

340365
// see https://github.com/electron-userland/spectron/issues/763
341366
// and https://github.com/webdriverio/webdriverio/issues/6092
@@ -505,24 +530,6 @@ export const oops = (ctx: ISuite, wait = false) => async (err: Error) => {
505530
// throw err
506531
}
507532

508-
/** restart the app */
509-
export const restart = async (ctx: ISuite) => {
510-
try {
511-
await ctx.app.restart()
512-
} catch (err) {
513-
const errorIsNavigatedError: boolean =
514-
err.message.includes('Inspected target navigated or closed') ||
515-
err.message.includes('cannot determine loading status') ||
516-
err.message.includes('Inspected target navigated or closed')
517-
518-
if (!errorIsNavigatedError) {
519-
throw err
520-
}
521-
}
522-
523-
return CLI.waitForSession(ctx)
524-
}
525-
526533
/** only execute the test in local */
527534
export const localIt = (msg: string, func: Func) => {
528535
if (process.env.MOCHA_RUN_TARGET !== 'webpack') return it(msg, func)

packages/webpack/webpack.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ plugins.push({
305305
console.log('webpack plugins', plugins)
306306

307307
// Notes: when !inBrowser, we want electron to pull
308-
// node-pty-prebuilt-multiarch in as a commonjs external module; this
308+
// node-pty in as a commonjs external module; this
309309
// is because node-pty has binary bits, and we are building one set of
310310
// bundles for all electron platforms. If, in the future, we decide to
311311
// rebuild the bundles for each platform, we can remove this 'commonjs
@@ -319,7 +319,7 @@ console.log('webpack plugins', plugins)
319319
// the 'commonjs node-pty' syntax, see
320320
// https://github.com/webpack/webpack/issues/4238
321321
const externals = !inBrowser
322-
? { 'node-pty-prebuilt-multiarch': 'commonjs node-pty-prebuilt-multiarch' }
322+
? { 'node-pty': 'commonjs node-pty' }
323323
: [
324324
'tape', // modules/composer/node_modules/safer-buffer
325325
'dns', // modules/openwhisk/node_modules/retry/example/dns.js
@@ -328,7 +328,7 @@ const externals = !inBrowser
328328
'request', // needed by some apache-composer samples
329329
'babel-core/register', // wskflow
330330
'aws-sdk', // wskflow
331-
'node-pty-prebuilt-multiarch', // bash-like
331+
'node-pty', // bash-like
332332
'./es6/crc9_1wire', // k8s
333333
'./es6/crc17_xmodem', // k8s, openwhisk
334334
'./es6/crc17_modbus', // k8s, openwhisk

plugins/plugin-bash-like/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"cookie": "0.4.1",
3030
"debug": "4.3.1",
3131
"globby": "11.0.3",
32-
"node-pty-prebuilt-multiarch": "0.9.0",
32+
"node-pty": "0.10.1",
3333
"shelljs": "0.8.4",
3434
"slash": "3.0.0",
3535
"speed-date": "1.0.0",
@@ -46,7 +46,7 @@
4646
"marked",
4747
"xterm",
4848
"ws",
49-
"node-pty-prebuilt-multiarch"
49+
"node-pty"
5050
],
5151
"proxy": [
5252
"asciidoctor.js",
@@ -55,7 +55,7 @@
5555
],
5656
"webpack": [
5757
"ws",
58-
"node-pty-prebuilt-multiarch"
58+
"node-pty"
5959
]
6060
}
6161
},

plugins/plugin-bash-like/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ export { StdioChannelWebsocketSide } from './pty/stdio-channel'
2020
export { getSessionForTab } from './pty/session'
2121
export { dispatchToShell as doExecWithPty, doExecWithStdoutViaPty } from './lib/cmds/catchall'
2222
export { getTabState } from './tab-state'
23+
24+
export { initMainPty } from './pty/electron-main-channel'

0 commit comments

Comments
 (0)