fix: 修复终端可用

This commit is contained in:
msojocs 2022-01-30 16:59:31 +08:00
parent 08971b899a
commit 4b427c2855
19 changed files with 1850 additions and 19 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ mew/
node_modules
test/mini-ci
crash-server
build

View File

@ -21,7 +21,7 @@ fail() {
echo "start"
python --version
node --version
echo "docker node version: $( node --version )"
# export http_proxy="http://192.168.249.236:7890"
ACTION_MODE=$( export ACTION_MODE )
@ -54,8 +54,8 @@ apt-get clean; # 清空缓存
apt-get update; # 更新
apt-get install -y libx11-dev libxkbfile-dev p7zip-full
npm install -g npm
npm install -g node-gyp
echo "=====安装node-gyp nw-gyp===="
npm install -g npm node-gyp nw-gyp
node-gyp install
node-gyp list
@ -70,4 +70,7 @@ node-gyp list
# end test
cd /workspace
# rm -rf package.nw node nwjs
#
# exec ./tools/rebuild-node-modules 0.53.1
exec ./tools/setup-wechat-devtools-bash

View File

@ -24,3 +24,7 @@ devtools_app.html并没有被加载
|-------------|-------|------|
|1.03.2006090 |0.39.3 |12.6.0|
|1.05.2201210 |0.49.3 |13.14.0|
# 终端测试
return r.handleEvent ? r.handleEvent.apply(this, o) : r.apply(this, o)

19
docs/Terminal.MD Normal file
View File

@ -0,0 +1,19 @@
文件`package.nw/js/libs/vseditor/bundled/editor.bundled.js`
使用`console.warn`进行调试输出
`this._processManager.createProcess(this._shellLaunchConfig,this._cols,this._rows,this._accessibilityService.isScreenReaderOptimized())`
在`const s=await this._process.start();`处崩溃
`setupPtyProcess`崩溃
const test = (await Promise.resolve().then(()=>i(1645)))
i ---- Array
[
"spawn"
"fork"
"createTerminal"
"open"
"native"
]

16
test/node-pty/code/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "nwjs",
"request": "launch",
"name": "Launch NWjs",
"nwjsVersion": "0.60.0",
"webRoot": "${workspaceFolder}",
"reloadAfterAttached": true
}
]
}

View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
We are using node.js 9999
<script>
document.write(process.version)
console.log(123)
var os = require('os');
var pty = require('node-pty');
var shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
console.log(456)
var ptyProcess = pty.spawn(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.env.HOME,
env: process.env
});
ptyProcess.onData(function(data) {
process.stdout.write(data);
});
ptyProcess.write('ls\r');
ptyProcess.resize(100, 40);
ptyProcess.write('ls\r');
</script>.
<script scr=index.js></script>
</body>
</html>

View File

@ -0,0 +1,22 @@
console.log("index.js")
var os = require('os');
var pty = require('node-pty');
console.info(process.versions)
var shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
var ptyProcess = pty.spawn(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.env.HOME,
env: process.env
});
ptyProcess.onData(function(data) {
process.stdout.write(data);
});
ptyProcess.write('ls\r');
ptyProcess.resize(100, 40);
ptyProcess.write('ls\r');

1628
test/node-pty/code/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
{
"name": "node_pty_test",
"main": "index.html",
"dependencies": {
"native-watchdog": "^1.3.0",
"node-gyp": "^8.4.1",
"node-pty": "^0.10.1"
}
}

6
test/node-pty/code/test Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash
root_dir=$(cd `dirname $0`/../../.. && pwd -P)
echo $root_dir
export PATH="$root_dir/node/bin:$PATH"
$(dirname $0)/test2

22
test/node-pty/code/test2 Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env node
var os = require('os');
var pty = require('node-pty');
console.info(process.versions)
var shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
var ptyProcess = pty.spawn(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.env.HOME,
env: process.env
});
ptyProcess.onData(function(data) {
process.stdout.write(data);
});
ptyProcess.write('ls\r');
ptyProcess.resize(100, 40);
ptyProcess.write('ls\r');

26
test/node-pty/test Normal file
View File

@ -0,0 +1,26 @@
#!/bin/bash
# update
root_dir=$(cd `dirname $0`/../.. && pwd -P)
current_dir=$(dirname $0)
echo "项目目录: $root_dir"
echo "脚本目录: $current_dir"
nwjs_version=0.53.1
$root_dir/tools/update-node-node 16.1.0
$root_dir/tools/update-nwjs-node $nwjs_version
export PATH="$root_dir/node/bin:$PATH"
# install
echo "安装node-pty"
npm install -g nw-gyp node-gyp
rm -rf "$current_dir/code/package-lock.json" "$current_dir/code/node_modules"
npm install --prefix="$current_dir/code" node-pty
npm config set python "/usr/bin/python2"
ln -s "/usr/bin/python2" "$root_dir/node/bin/python"
python --version
cd "$current_dir/code/node_modules/node-pty" && nw-gyp rebuild "--target=$nwjs_version" --arch=x64 --python=/usr/bin/python2
# run
rm -rf "$root_dir/tmp/node-pty"
"$root_dir/nwjs/nw" "$current_dir/code" --nwapp="$current_dir/code" --user-data-dir="$root_dir/tmp/node-pty"

7
test/test-bash Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
PY_VERSION=`python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'`
echo $PY_VERSION
if [ "$PY_VERSION" == "Python 3.10.1" ]; then
echo ok
fi

View File

@ -15,7 +15,7 @@ const parseFile = function (path) {
content.name = "wechat_devtools";
// 开启调试,更新参数
content['chromium-args'] = content['chromium-args'].replace('--disable-devtools', '').replace('--ignore-gpu-blacklist', '--ignore-gpu-blocklist') + ' --mixed-context'
content.window.height = content.window.width = 500
console.log("arite")
fs.writeFileSync(path, JSON.stringify(content, null, 4));

View File

@ -1,5 +1,7 @@
#!/bin/bash
# 参数:
# 1 ---- NW版本
#
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
@ -7,12 +9,27 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
NW_VERSION=$1
package_dir="$DIR/../package.nw"
export PATH=$DIR/../node/bin:$PATH
if [ -z $NW_VERSION ]; then
echo "NW 版本未指定!"
exit 1
fi
echo "目录: $DIR"
echo "NW VERSION: $NW_VERSION"
node --version
export PATH="$DIR/../node/bin:$PATH"
PY_VERSION=`python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'`
if [ $PY_VERSION != 2 ]; then
hash python2 2>/dev/null || { echo >&2 "I require python2 but it's not installed. Aborting."; exit 1; }
ln -s "$( which python2 )" "$DIR/../node/bin/python"
fi
hash nw-gyp 2>/dev/null || {
echo "=======请安装nw-gyp======="
exit 1
}
rm -fr "${package_dir}/node_modules/vscode-windows-ca-certs" # the module is only available in windows
rm -fr "${package_dir}/node_modules/vscode-windows-registry" # the module is only available in windows
@ -21,8 +38,7 @@ rm -fr "${package_dir}/node_modules/windows-process-tree" # the module is only a
rm -fr "${package_dir}/node_modules/vscode-ripgrep/bin" # redownload bin on linux
rm -fr "${package_dir}/node_modules/node-pty/build/Release/conpty.node" # the native module is not available in windows
rm -fr "${package_dir}/node_modules/node-pty/build/Release/conpty_console_list.node" # the native module is not available in windows
rm -fr "${package_dir}/node_modules/node-pty" "${package_dir}/node_modules/node-pty-node" # the native module is not available in windows
(cd "${package_dir}/node_modules" && find -name *.pdb | xargs -I{} rm -r {}) # remove pdb debugging file
@ -30,14 +46,14 @@ rm -fr "${package_dir}/node_modules_tmp" # remove previous hacking tmp
mkdir -p "${package_dir}/node_modules_tmp"
cp -fr "${package_dir}/node_modules" "${package_dir}/node_modules_tmp/node_modules"
rm -fr "${package_dir}/node_modules_tmp/node_modules/node-pty"
rm -fr "${package_dir}/node_modules_tmp/node_modules/node-pty-node"
rm -fr "${package_dir}/node_modules_tmp/node_modules/native-watchdog"
rm -fr "${package_dir}/node_modules_tmp/node_modules/oniguruma-node"
rm -fr "${package_dir}/node_modules_tmp/node_modules/spdlog"
rm -fr "${package_dir}/node_modules_tmp/node_modules/spdlog-node"
# npm install @vscode/ripgrep --registry=https://registry.npm.taobao.org
# npm install nodegit --registry=https://registry.npm.taobao.org --nodegit_binary_host_mirror=https://npm.taobao.org/mirrors/nodegit/v0.27.0/
(cd "${package_dir}/node_modules_tmp" && npm install \
(npm install \
extract-file-icon \
native-keymap \
node-pty \
@ -48,19 +64,29 @@ rm -fr "${package_dir}/node_modules_tmp/node_modules/spdlog-node"
vscode-oniguruma \
vscode-ripgrep \
nodegit \
--prefix="${package_dir}/node_modules_tmp" \
--registry=https://registry.npm.taobao.org \
--nodegit_binary_host_mirror=https://npm.taobao.org/mirrors/nodegit/v0.27.0/) # reinstall modules
# rebuild
echo "nw-gyp version: $( nw-gyp --version )"
cd "$package_dir/node_modules_tmp/node_modules/node-pty" && nw-gyp rebuild --arch=x64 "--target=$NW_VERSION"
(cp -fr "${package_dir}/node_modules_tmp/node_modules/node-pty" "${package_dir}/node_modules_tmp/node_modules/node-pty-node")
rm -rf "${package_dir}/node_modules/node-pty" "${package_dir}/node_modules/node-pty-node"
cp -fr "${package_dir}/node_modules_tmp/node_modules/node-pty" "${package_dir}/node_modules"
(cp -fr "${package_dir}/node_modules/node-pty" "${package_dir}/node_modules/node-pty-node")
cd "$package_dir/node_modules_tmp/node_modules/native-watchdog" && nw-gyp rebuild --arch=x64 "--target=$NW_VERSION"
rm -rf "${package_dir}/node_modules/native-watchdog" && cp -fr "${package_dir}/node_modules_tmp/node_modules/native-watchdog" "${package_dir}/node_modules"
(cp -fr "${package_dir}/node_modules_tmp/node_modules/oniguruma" "${package_dir}/node_modules_tmp/node_modules/oniguruma-node")
(cp -fr "${package_dir}/node_modules_tmp/node_modules/spdlog" "${package_dir}/node_modules_tmp/node_modules/spdlog-node")
(cd "${package_dir}/node_modules_tmp/node_modules" && find -name "*.node" | xargs -I{} cp -r {} ${package_dir}/node_modules/{})
(cd "${package_dir}/node_modules_tmp/node_modules" && find -name "*.node" | xargs -I{} /bin/cp -rf {} ${package_dir}/node_modules/{})
mkdir -p "${package_dir}/node_modules/vscode-ripgrep/bin"
cp -fr "${package_dir}/node_modules_tmp/node_modules/vscode-ripgrep/bin/rg" "${package_dir}/node_modules/vscode-ripgrep/bin/rg"
rm -rf "${package_dir}/node_modules/native-watchdog" && cp -fr "${package_dir}/node_modules_tmp/node_modules/native-watchdog" "${package_dir}/node_modules"
rm -rf "${package_dir}/node_modules_tmp"
# 移除旧配置

View File

@ -97,6 +97,8 @@ const upgrade = function (extractPath) {
const start = async () => {
try {
const args = process.argv.slice(2);
if(args[0])nodeConfig.version=args[0]
const nodePath = path.resolve(__dirname, "../node/bin/node")
if(fs.existsSync(nodePath)){
const version = execSync(`${path.resolve(__dirname, "../node/bin/node")} --version`).toString().replace('\n', '')

View File

@ -103,7 +103,10 @@ const upgrade = function (extractPath) {
}
const init = async () => {
try {
const args = process.argv.slice(2);
const nwjs = require("../conf/nwjs.json");
if(args[0])nwjs.version = args[0]
const localPath = await download(nwjs)
const extractPath = await extract(localPath)
const result = await upgrade(extractPath)

View File

@ -235,7 +235,8 @@ const rebuild_wechat_devtools_node_modules = function () {
info("Rebuilding wechat-devtools node modules");
return new Promise((resolve, reject) => {
const e = spawn(path.resolve(__dirname, "rebuild-node-modules"), [], {
const nwConfig = require(path.resolve(__dirname, "../conf/nwjs.json"))
const e = spawn(path.resolve(__dirname, "rebuild-node-modules"), [nwConfig.version], {
stdio: "inherit",
})
e.on("error", code=>{