Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dll path #731

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2f0934b
预构建
xiaobaidadada Nov 20, 2024
aa3c85e
预构建版本
xiaobaidadada Nov 20, 2024
c7b100b
构建环境
xiaobaidadada Nov 20, 2024
9eb94d1
构建环境
xiaobaidadada Nov 20, 2024
e940f7d
lock版本
xiaobaidadada Nov 20, 2024
1b786f1
prebuild
xiaobaidadada Nov 20, 2024
1cf3c48
prebuild
xiaobaidadada Nov 20, 2024
a733355
prebuild
xiaobaidadada Nov 20, 2024
75f8bc6
prebuild
xiaobaidadada Nov 20, 2024
a5e0be4
prebuild
xiaobaidadada Nov 20, 2024
8df4a7f
powershell的问题
xiaobaidadada Nov 20, 2024
803a4eb
分别用不同的参数
xiaobaidadada Nov 20, 2024
13631eb
区分环境编译
xiaobaidadada Nov 20, 2024
0c6c36c
build
xiaobaidadada Nov 20, 2024
22464aa
push
xiaobaidadada Nov 20, 2024
9a184e3
--access public
xiaobaidadada Nov 20, 2024
4e259f7
Update build.yml
xiaobaidadada Nov 21, 2024
2dab267
Update post-install.js
xiaobaidadada Nov 21, 2024
9ddd6c1
Update package.json
xiaobaidadada Nov 21, 2024
29713fc
Update build.yml
xiaobaidadada Nov 21, 2024
0565109
Update build.yml
xiaobaidadada Nov 21, 2024
994a540
Update build.yml
xiaobaidadada Nov 21, 2024
aa8ccbb
Update build.yml
xiaobaidadada Nov 21, 2024
728bbb5
1.0.3
xiaobaidadada Nov 21, 2024
e2db91a
预构建
xiaobaidadada Nov 21, 2024
d478ec8
预构建
xiaobaidadada Nov 21, 2024
2ee9c07
预构建
xiaobaidadada Nov 21, 2024
8e15ebd
NODE_BUILD_CMD
xiaobaidadada Nov 21, 2024
e945bbd
x64
xiaobaidadada Nov 21, 2024
9373f68
conpty(resize也需要dll)也支持动态dll路径
xiaobaidadada Nov 21, 2024
2c9e900
webpack打包适应,线程处理
xiaobaidadada Nov 21, 2024
c4fb1b2
require
xiaobaidadada Nov 21, 2024
62a5f94
查找全部子进程todo
xiaobaidadada Nov 21, 2024
91ebf9a
1.0.3打包测试
xiaobaidadada Nov 21, 2024
1ba971b
Debug路径下require
xiaobaidadada Nov 22, 2024
0f9be4f
1.0.4
xiaobaidadada Nov 22, 2024
817e125
build.yml
xiaobaidadada Nov 22, 2024
171ed44
workflow修改
xiaobaidadada Mar 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 192 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
name: "构建与发布"
run-name: 任务参数:${{ inputs.job }} ;分支:${{ github.ref_name }} # 每次运行的时候显示的名字

on:
workflow_dispatch: # 手动触发
inputs: # 定义触发的时候可以输入的参数
job: # 参数名称 通过 ${{ github.event.inputs.job }} 访问值 下面是参数的要求描述
description: "任务类型 all,push-npm,预构建:prebuild(linux和win,mac x64),alpine,alpine-arm,linux-arm"
required: true
default: prebuild
type: string
ubuntu_version:
description: 'ubuntu版本'
required: false
default: 'ubuntu-latest' # ${{ inputs.ubuntu_version || 'ubuntu-20.04' }} 也可以
win_version:
description: 'windows版本'
required: false
default: 'windows-latest'

env: # 用来定义环境变量 可用于工作流中所有作业的步骤的变量的 map
# See https://github.com/nodejs/release#release-schedule
# Node.js v16 EOL = 2023-09-11. v21 EOL = 2024-06-01.
# NODE_OLD_BUILD_CMD: npx --no-install prebuild -r node -t 14.0.0 -t 16.0.0 --include-regex
NODE_BUILD_CMD: npx --no-install prebuild -r node -t 16.0.0 -t 18.0.0 -t 20.0.0 -t 22.0.0 --include-regex
# Merge with NODE_BUILD_CMD when Node.js v18 is EOL
# NO_V18_NODE_BUILD_CMD: npx --no-install prebuild -r node -t 20.0.0 -t 22.0.0 --include-regex
# See https://www.electronjs.org/docs/latest/tutorial/electron-timelines#version-support-policy
# Electron v25 EOL = 2023-12-05. v26 EOL = 2024-02-20. v27 EOL = 2024-04-16. v28 EOL = 2024-06-11. v29 EOL = 2024-08-20.
ELECTRON_BUILD_CMD: npx --no-install prebuild -r electron -t 26.0.0 -t 27.0.0 -t 28.0.0 -t 29.0.0 -t 30.0.0 -t 31.0.0 -t 32.0.0 --include-regex

# 所有的jobs下的任务都会被执行
jobs:
test:
strategy:
matrix: # 定义在多个维度版本进行构建的 虚拟环境 矩阵(就是os * node的组合)
os:
- ubuntu-20.04
- macos-13
- macos-14
- windows-2019
node:
- 18
- 20
- 22
name: Testing Node ${{ matrix.node }} on ${{ matrix.os }}
if: ${{ github.event_name == 'test' }} # 让某个job执行
runs-on: ${{ matrix.os }} # 使用matrix.os中的 运行环境
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- if: ${{ startsWith(matrix.os, 'windows') }}
run: pip.exe install setuptools
- if: ${{ startsWith(matrix.os, 'macos') }}
run: brew install python-setuptools
- if: ${{ !startsWith(matrix.os, 'windows') && !startsWith(matrix.os, 'macos') }}
run: python3 -m pip install setuptools
- if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: |
sudo apt update
sudo apt install gcc-10 g++-10 -y
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10
- run: npm install --ignore-scripts
- run: npm run build-debug
- run: npm test
- name: Test SpatiaLite extension
if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: |
sudo apt update
sudo apt install libsqlite3-mod-spatialite -y
node -e "require('./lib/index.js')(':memory:').loadExtension('mod_spatialite').exec('SELECT InitSpatialMetaData();')"

publish-npm:
if: ${{ github.event.inputs.job == 'push-npm' || github.event.inputs.job == 'all'}}
name: Publishing to NPM
runs-on: ${{inputs.ubuntu_version}}
#needs: # 等待别的 job 任务完成
#- prebuild
#- prebuild-alpine
#- prebuild-alpine-arm
#- prebuild-linux-arm
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org
- run: |
npm install --ignore-scripts
npm run build
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

prebuild: # 执行node的 预构建
if: ${{ github.event.inputs.job == 'prebuild' || github.event.inputs.job == 'all' }}
strategy:
fail-fast: false
matrix:
os:
- ${{inputs.ubuntu_version}}
#- macos-13
#- macos-14
- ${{inputs.win_version}}
name: Prebuild on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
# needs: test
steps:
- uses: actions/checkout@v4 # 使用社区的指令
- uses: actions/setup-node@v4
with:
node-version: 18
- run: npm install --ignore-scripts
- if: ${{ startsWith(matrix.os, 'windows') }}
run: pip.exe install setuptools
- if: ${{ startsWith(matrix.os, 'macos') }}
run: brew install python-setuptools
- if: ${{ !startsWith(matrix.os, 'windows') && !startsWith(matrix.os, 'macos') }}
run: python3 -m pip install setuptools
- if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: |
sudo apt update
sudo apt install gcc-10 g++-10 -y
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10
${{ env.NODE_BUILD_CMD }} "\.(node|exe|dll|pdb)" -u ${{ secrets.GITHUB_TOKEN }}
${{ env.ELECTRON_BUILD_CMD }} "\.(node|exe|dll|pdb)" -u ${{ secrets.GITHUB_TOKEN }}
- if: matrix.os == 'windows-2019'
run: |
${{ env.NODE_BUILD_CMD }} ('\.' -join ('node', 'exe', 'dll', 'pdb')) -u ${{ secrets.GITHUB_TOKEN }}
${{ env.NODE_BUILD_CMD }} ('\.' -join ('node', 'exe', 'dll', 'pdb')) --arch arm64 -u ${{ secrets.GITHUB_TOKEN }}
${{ env.NODE_BUILD_CMD }} ('\.' -join ('node', 'exe', 'dll', 'pdb')) --arch ia32 -u ${{ secrets.GITHUB_TOKEN }}
${{ env.ELECTRON_BUILD_CMD }} ('\.' -join ('node', 'exe', 'dll', 'pdb')) -u ${{ secrets.GITHUB_TOKEN }}
${{ env.ELECTRON_BUILD_CMD }} ('\.' -join ('node', 'exe', 'dll', 'pdb')) --arch arm64 -u ${{ secrets.GITHUB_TOKEN }}
${{ env.ELECTRON_BUILD_CMD }} ('\.' -join ('node', 'exe', 'dll', 'pdb')) --arch ia32 -u ${{ secrets.GITHUB_TOKEN }}

prebuild-alpine:
if: ${{ github.event.inputs.job == 'alpine' || github.event.inputs.job == 'all' }}
strategy:
fail-fast: false
name: Prebuild on alpine
runs-on: ${{inputs.ubuntu_version}}
container: node:18-alpine
#needs: test
steps:
- uses: actions/checkout@v4
- run: apk add build-base git python3 py3-setuptools --update-cache
- run: npm install --ignore-scripts
- run: |
${{ env.NODE_BUILD_CMD }} '\.(node|exe|dll|pdb)' -u ${{ secrets.GITHUB_TOKEN }}

prebuild-alpine-arm:
if: ${{ github.event.inputs.job == 'alpine-arm' || github.event.inputs.job == 'all' }}
strategy:
fail-fast: false
matrix:
arch:
- arm/v7
- arm64
name: Prebuild on alpine (${{ matrix.arch }})
runs-on: ${{inputs.ubuntu_version}}
#needs: test
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- run: |
docker run --rm -v $(pwd):/tmp/project --entrypoint /bin/sh --platform linux/${{ matrix.arch }} node:18-alpine -c "\
apk add build-base git python3 py3-setuptools --update-cache && \
cd /tmp/project && \
npm install --ignore-scripts && \
${{ env.NODE_BUILD_CMD }} '\.(node|exe|dll|pdb)' -u ${{ secrets.GITHUB_TOKEN }}"

prebuild-linux-arm:
if: ${{ github.event.inputs.job == 'linux-arm' || github.event.inputs.job == 'all' }}
strategy:
fail-fast: false
matrix:
arch:
- arm/v7
- arm64
name: Prebuild on Linux (${{ matrix.arch }})
runs-on: ${{inputs.ubuntu_version}}
#needs: test
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- run: |
docker run --rm -v $(pwd):/tmp/project --entrypoint /bin/sh --platform linux/${{ matrix.arch }} node:18-bullseye -c "\
cd /tmp/project && \
npm install --ignore-scripts && \
${{ env.NODE_BUILD_CMD }} '\.(node|exe|dll|pdb)' -u ${{ secrets.GITHUB_TOKEN }}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -12,3 +12,5 @@ fixtures/space folder/
.vscode/settings.json
.vscode/ipch/
yarn.lock
.idea
test.js
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

167 changes: 6 additions & 161 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,164 +1,9 @@
# node-pty
# node-pty-prebuilt
在windwos下spawn函数的opt选项添加了exePath,可以指定 exePath的位置.

[![Build Status](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty?branchName=main)](https://dev.azure.com/vscode/node-pty/_build/latest?definitionId=11&branchName=main)
The spawn function's opt option has been added with agentExePath, which allows specifying the location of the agent executable.

`forkpty(3)` bindings for node.js. This allows you to fork processes with pseudoterminal file descriptors. It returns a terminal object which allows reads and writes.
https://github.com/microsoft/node-pty

This is useful for:

- Writing a terminal emulator (eg. via [xterm.js](https://github.com/sourcelair/xterm.js)).
- Getting certain programs to *think* you're a terminal, such as when you need a program to send you control sequences.

`node-pty` supports Linux, macOS and Windows. Windows support is possible by utilizing the [Windows conpty API](https://blogs.msdn.microsoft.com/commandline/2018/08/02/windows-command-line-introducing-the-windows-pseudo-console-conpty/) on Windows 1809+ and the [winpty](https://github.com/rprichard/winpty) library in older version.

## API

The full API for node-pty is contained within the [TypeScript declaration file](https://github.com/microsoft/node-pty/blob/main/typings/node-pty.d.ts), use the branch/tag picker in GitHub (`w`) to navigate to the correct version of the API.

## Example Usage

```js
import * as os from 'node:os';
import * as pty from 'node-pty';

const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';

const ptyProcess = pty.spawn(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.env.HOME,
env: process.env
});

ptyProcess.onData((data) => {
process.stdout.write(data);
});

ptyProcess.write('ls\r');
ptyProcess.resize(100, 40);
ptyProcess.write('ls\r');
```

## Real-world Uses

`node-pty` powers many different terminal emulators, including:

- [Microsoft Visual Studio Code](https://code.visualstudio.com)
- [Hyper](https://hyper.is/)
- [Upterm](https://github.com/railsware/upterm)
- [Script Runner](https://github.com/ioquatix/script-runner) for Atom.
- [Theia](https://github.com/theia-ide/theia)
- [FreeMAN](https://github.com/matthew-matvei/freeman) file manager
- [terminus](https://atom.io/packages/terminus) - An Atom plugin for providing terminals inside your Atom workspace.
- [x-terminal](https://atom.io/packages/x-terminal) - Also an Atom plugin that provides terminals inside your Atom workspace.
- [Termination](https://atom.io/packages/termination) - Also an Atom plugin that provides terminals inside your Atom workspace.
- [atom-xterm](https://atom.io/packages/atom-xterm) - Also an Atom plugin that provides terminals inside your Atom workspace.
- [electerm](https://github.com/electerm/electerm) Terminal/SSH/SFTP client(Linux, macOS, Windows).
- [Extraterm](http://extraterm.org/)
- [Wetty](https://github.com/krishnasrinivas/wetty) Browser based Terminal over HTTP and HTTPS
- [nomad](https://github.com/lukebarnard1/nomad-term)
- [DockerStacks](https://github.com/sfx101/docker-stacks) Local LAMP/LEMP stack using Docker
- [TeleType](https://github.com/akshaykmr/TeleType): cli tool that allows you to share your terminal online conveniently. Show off mad cli-fu, help a colleague, teach, or troubleshoot.
- [mesos-term](https://github.com/criteo/mesos-term): A web terminal for Apache Mesos. It allows to execute commands within containers.
- [Commas](https://github.com/CyanSalt/commas): A hackable terminal and command runner.
- [ENiGMA½ BBS Software](https://github.com/NuSkooler/enigma-bbs): A modern BBS software with a nostalgic flair!
- [Tinkerun](https://github.com/tinkerun/tinkerun): A new way of running Tinker.
- [Tess](https://tessapp.dev): Hackable, simple and rapid terminal for the new era of technology 👍
- [NxShell](https://nxshell.github.io/): An easy to use new terminal for Windows/Linux/MacOS platform.
- [OpenSumi](https://github.com/opensumi/core): A framework helps you quickly build Cloud or Desktop IDE products.

Do you use node-pty in your application as well? Please open a [Pull Request](https://github.com/Tyriar/node-pty/pulls) to include it here. We would love to have it in our list.

## Building

```bash
# Install dependencies and build C++
npm install
# Compile TypeScript -> JavaScript
npm run build
```

## Dependencies

Node.JS 16 or Electron 19 is required to use `node-pty`. What version of node is supported is currently mostly bound to [whatever version Visual Studio Code is using](https://github.com/microsoft/node-pty/issues/557#issuecomment-1332193541).

### Linux (apt)

```sh
sudo apt install -y make python build-essential
```

### macOS

Xcode is needed to compile the sources, this can be installed from the App Store.

### Windows

`npm install` requires some tools to be present in the system like Python and C++ compiler. Windows users can easily install them by running the following command in PowerShell as administrator. For more information see https://github.com/felixrieseberg/windows-build-tools:

```sh
npm install --global --production windows-build-tools
```

The following are also needed:

- [Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk) - only the "Desktop C++ Apps" components are needed to be installed
- Spectre-mitigated libraries - In order to avoid the build error "MSB8040: Spectre-mitigated libraries are required for this project", open the Visual Studio Installer, press the Modify button, navigate to the "Individual components" tab, search "Spectre", and install an option like "MSVC v143 - VS 2022 C++ x64/x86 Spectre-mitigated libs (Latest)" (the exact option to install will depend on your version of Visual Studio as well as your operating system architecture)

## Debugging

[The wiki](https://github.com/Microsoft/node-pty/wiki/Debugging) contains instructions for debugging node-pty.

## Security

All processes launched from node-pty will launch at the same permission level of the parent process. Take care particularly when using node-pty inside a server that's accessible on the internet. We recommend launching the pty inside a container to protect your host machine.

## Thread Safety

Note that node-pty is not thread safe so running it across multiple worker threads in node.js could cause issues.

## Flow Control

Automatic flow control can be enabled by either providing `handleFlowControl = true` in the constructor options or setting it later on:

```js
const PAUSE = '\x13'; // XOFF
const RESUME = '\x11'; // XON

const ptyProcess = pty.spawn(shell, [], {handleFlowControl: true});

// flow control in action
ptyProcess.write(PAUSE); // pty will block and pause the child program
...
ptyProcess.write(RESUME); // pty will enter flow mode and resume the child program

// temporarily disable/re-enable flow control
ptyProcess.handleFlowControl = false;
...
ptyProcess.handleFlowControl = true;
```

By default `PAUSE` and `RESUME` are XON/XOFF control codes (as shown above). To avoid conflicts in environments that use these control codes for different purposes the messages can be customized as `flowControlPause: string` and `flowControlResume: string` in the constructor options. `PAUSE` and `RESUME` are not passed to the underlying pseudoterminal if flow control is enabled.

## Troubleshooting

### Powershell gives error 8009001d

> Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d.

This happens when PowerShell is launched with no `SystemRoot` environment variable present.

### ConnectNamedPipe failed: Windows error 232

This error can occur due to anti-virus software intercepting winpty from creating a pty. To workaround this you can exclude this file from your anti-virus scanning `node-pty\build\Release\winpty-agent.exe`

## pty.js

This project is forked from [chjj/pty.js](https://github.com/chjj/pty.js) with the primary goals being to provide better support for later Node.js versions and Windows.

## License

Copyright (c) 2012-2015, Christopher Jeffrey (MIT License).<br>
Copyright (c) 2016, Daniel Imms (MIT License).<br>
Copyright (c) 2018, Microsoft Corporation (MIT License).
1. 在windows下useConpty如果开启,不能在debug模式下运行,useConptyDll如果开启了,你依然可以用exePath参数来指定它所需要的dll位置,不提供会使用项目默认的。
2. 已经适配webpack打包
Loading