Skip to content

Commit

Permalink
0.9.0-beta2
Browse files Browse the repository at this point in the history
  • Loading branch information
oznu committed May 14, 2019
2 parents a608744 + 4637d85 commit 6e9acd6
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 106 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ package-lock.json
fixtures/space folder/
.vscode/settings.json

prebuilds
prebuilds
.vscode/ipch/
22 changes: 22 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- script: |
npm run lint
displayName: 'Lint'
- job: macOS
pool:
vmImage: 'xcode9-macos10.13'
Expand All @@ -38,6 +39,7 @@ jobs:
- script: |
npm run lint
displayName: 'Lint'
- job: Windows
pool:
vmImage: 'vs2017-win2016'
Expand All @@ -55,3 +57,23 @@ jobs:
- script: |
npm run lint
displayName: 'Lint'
- job: Release
dependsOn:
- Linux
- macOS
- Windows
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
pool:
vmImage: 'ubuntu-16.04'
steps:
- task: NodeTool@0
inputs:
versionSpec: '8.x'
displayName: 'Install Node.js'
- script: |
npm i
displayName: 'Install dependencies and build'
- script: |
NPM_AUTH_TOKEN="$(NPM_AUTH_TOKEN)" node ./scripts/publish.js
displayName: 'Publish to npm'
2 changes: 1 addition & 1 deletion examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"dependencies": {
"electron": "^4.0.1",
"node-pty": "^0.8.0",
"xterm": "^3.12.1"
"xterm": "^3.13.0"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": {
"name": "Microsoft Corporation"
},
"version": "0.8.2-unofficial.1",
"version": "0.9.0-beta2",
"license": "MIT",
"main": "./lib/index.js",
"types": "./typings/node-pty.d.ts",
Expand Down Expand Up @@ -42,7 +42,7 @@
"prepublish": "npm run tsc"
},
"dependencies": {
"nan": "2.12.1",
"nan": "^2.13.2",
"prebuild-install": "^5.2.5"
},
"devDependencies": {
Expand Down
62 changes: 62 additions & 0 deletions scripts/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright (c) 2019, Microsoft Corporation (MIT License).
*/

const cp = require('child_process');
const fs = require('fs');
const path = require('path');
const packageJson = require('../package.json');

// Setup auth
fs.writeFileSync(`${process.env['HOME']}/.npmrc`, `//registry.npmjs.org/:_authToken=${process.env['NPM_AUTH_TOKEN']}`);

// Determine if this is a stable or beta release
const publishedVersions = getPublishedVersions();
const isStableRelease = publishedVersions.indexOf(packageJson.version) === -1;

// Get the next version
let nextVersion = isStableRelease ? packageJson.version : getNextBetaVersion();
console.log(`Publishing version: ${nextVersion}`);

// Set the version in package.json
const packageJsonFile = path.resolve(__dirname, '..', 'package.json');
packageJson.version = nextVersion;
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson, null, 2));

// Publish
const args = ['publish'];
if (!isStableRelease) {
args.push('--tag', 'beta');
}
const result = cp.spawn('npm', args, { stdio: 'inherit' });
result.on('exit', code => process.exit(code));

function getNextBetaVersion() {
if (!/^[0-9]+\.[0-9]+\.[0-9]+$/.exec(packageJson.version)) {
console.error('The package.json version must be of the form x.y.z');
process.exit(1);
}
const tag = 'beta';
const stableVersion = packageJson.version.split('.');
const nextStableVersion = `${stableVersion[0]}.${parseInt(stableVersion[1]) + 1}.0`;
const publishedVersions = getPublishedVersions(nextStableVersion, tag);
if (publishedVersions.length === 0) {
return `${nextStableVersion}-${tag}1`;
}
const latestPublishedVersion = publishedVersions.sort((a, b) => {
const aVersion = parseInt(a.substr(a.search(/[0-9]+$/)));
const bVersion = parseInt(b.substr(b.search(/[0-9]+$/)));
return aVersion > bVersion ? -1 : 1;
})[0];
const latestTagVersion = parseInt(latestPublishedVersion.substr(latestPublishedVersion.search(/[0-9]+$/)), 10);
return `${nextStableVersion}-${tag}${latestTagVersion + 1}`;
}

function getPublishedVersions(version, tag) {
const versionsProcess = cp.spawnSync('npm', ['view', packageJson.name, 'versions', '--json']);
const versionsJson = JSON.parse(versionsProcess.stdout);
if (tag) {
return versionsJson.filter(v => !v.search(new RegExp(`${version}-${tag}[0-9]+`)));
}
return versionsJson;
}
2 changes: 2 additions & 0 deletions src/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export abstract class Terminal implements ITerminal {
public get onExit(): IEvent<IExitEvent> { return this._onExit.event; }

public get pid(): number { return this._pid; }
public get cols(): number { return this._cols; }
public get rows(): number { return this._rows; }

constructor(opt?: IPtyForkOptions) {
// for 'close'
Expand Down
48 changes: 20 additions & 28 deletions src/unix/pty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ NAN_METHOD(PtyFork) {
signal(SIGINT, SIG_DFL);

// file
v8::String::Utf8Value file(info[0]->ToString());
Nan::Utf8String file(info[0]);

// args
int i = 0;
Expand All @@ -162,7 +162,7 @@ NAN_METHOD(PtyFork) {
argv[0] = strdup(*file);
argv[argl-1] = NULL;
for (; i < argc; i++) {
v8::String::Utf8Value arg(argv_->Get(Nan::New<v8::Integer>(i))->ToString());
Nan::Utf8String arg(Nan::Get(argv_, i).ToLocalChecked());
argv[i+1] = strdup(*arg);
}

Expand All @@ -173,26 +173,26 @@ NAN_METHOD(PtyFork) {
char **env = new char*[envc+1];
env[envc] = NULL;
for (; i < envc; i++) {
v8::String::Utf8Value pair(env_->Get(Nan::New<v8::Integer>(i))->ToString());
Nan::Utf8String pair(Nan::Get(env_, i).ToLocalChecked());
env[i] = strdup(*pair);
}

// cwd
v8::String::Utf8Value cwd_(info[3]->ToString());
Nan::Utf8String cwd_(info[3]);
char *cwd = strdup(*cwd_);

// size
struct winsize winp;
winp.ws_col = info[4]->IntegerValue();
winp.ws_row = info[5]->IntegerValue();
winp.ws_col = info[4]->IntegerValue(Nan::GetCurrentContext()).FromJust();
winp.ws_row = info[5]->IntegerValue(Nan::GetCurrentContext()).FromJust();
winp.ws_xpixel = 0;
winp.ws_ypixel = 0;

// termios
struct termios t = termios();
struct termios *term = &t;
term->c_iflag = ICRNL | IXON | IXANY | IMAXBEL | BRKINT;
if (info[8]->ToBoolean()->Value()) {
if (info[8]->BooleanValue(Nan::GetCurrentContext()).FromJust()) {
#if defined(IUTF8)
term->c_iflag |= IUTF8;
#endif
Expand Down Expand Up @@ -227,8 +227,8 @@ NAN_METHOD(PtyFork) {
cfsetospeed(term, B38400);

// uid / gid
int uid = info[6]->IntegerValue();
int gid = info[7]->IntegerValue();
int uid = info[6]->IntegerValue(Nan::GetCurrentContext()).FromJust();
int gid = info[7]->IntegerValue(Nan::GetCurrentContext()).FromJust();

// fork the pty
int master = -1;
Expand Down Expand Up @@ -312,8 +312,8 @@ NAN_METHOD(PtyOpen) {

// size
struct winsize winp;
winp.ws_col = info[0]->IntegerValue();
winp.ws_row = info[1]->IntegerValue();
winp.ws_col = info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust();
winp.ws_row = info[1]->IntegerValue(Nan::GetCurrentContext()).FromJust();
winp.ws_xpixel = 0;
winp.ws_ypixel = 0;

Expand Down Expand Up @@ -357,11 +357,11 @@ NAN_METHOD(PtyResize) {
return Nan::ThrowError("Usage: pty.resize(fd, cols, rows)");
}

int fd = info[0]->IntegerValue();
int fd = info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust();

struct winsize winp;
winp.ws_col = info[1]->IntegerValue();
winp.ws_row = info[2]->IntegerValue();
winp.ws_col = info[1]->IntegerValue(Nan::GetCurrentContext()).FromJust();
winp.ws_row = info[2]->IntegerValue(Nan::GetCurrentContext()).FromJust();
winp.ws_xpixel = 0;
winp.ws_ypixel = 0;

Expand Down Expand Up @@ -390,9 +390,9 @@ NAN_METHOD(PtyGetProc) {
return Nan::ThrowError("Usage: pty.process(fd, tty)");
}

int fd = info[0]->IntegerValue();
int fd = info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust();

v8::String::Utf8Value tty_(info[1]->ToString());
Nan::Utf8String tty_(info[1]);
char *tty = strdup(*tty_);
char *name = pty_getproc(fd, tty);
free(tty);
Expand Down Expand Up @@ -706,18 +706,10 @@ pty_forkpty(int *amaster,

NAN_MODULE_INIT(init) {
Nan::HandleScope scope;
Nan::Set(target,
Nan::New<v8::String>("fork").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(PtyFork)->GetFunction());
Nan::Set(target,
Nan::New<v8::String>("open").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(PtyOpen)->GetFunction());
Nan::Set(target,
Nan::New<v8::String>("resize").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(PtyResize)->GetFunction());
Nan::Set(target,
Nan::New<v8::String>("process").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(PtyGetProc)->GetFunction());
Nan::Export(target, "fork", PtyFork);
Nan::Export(target, "open", PtyOpen);
Nan::Export(target, "resize", PtyResize);
Nan::Export(target, "process", PtyGetProc);
}

NODE_MODULE(pty, init)
28 changes: 16 additions & 12 deletions src/unixTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

import * as net from 'net';
import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from './terminal';
import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from './interfaces';
Expand Down Expand Up @@ -52,8 +51,8 @@ export class UnixTerminal extends Terminal {
opt = opt || {};
opt.env = opt.env || process.env;

const cols = opt.cols || DEFAULT_COLS;
const rows = opt.rows || DEFAULT_ROWS;
this._cols = opt.cols || DEFAULT_COLS;
this._rows = opt.rows || DEFAULT_ROWS;
const uid = opt.uid || -1;
const gid = opt.gid || -1;
const env = assign({}, opt.env);
Expand Down Expand Up @@ -97,7 +96,7 @@ export class UnixTerminal extends Terminal {
};

// fork
const term = pty.fork(file, args, parsedEnv, cwd, cols, rows, uid, gid, (encoding === 'utf8'), onexit);
const term = pty.fork(file, args, parsedEnv, cwd, this._cols, this._rows, uid, gid, (encoding === 'utf8'), onexit);

this._socket = new PipeSocket(term.fd);
if (encoding !== null) {
Expand Down Expand Up @@ -176,17 +175,21 @@ export class UnixTerminal extends Terminal {

const cols = opt.cols || DEFAULT_COLS;
const rows = opt.rows || DEFAULT_ROWS;
const encoding = opt.encoding ? 'utf8' : opt.encoding;
const encoding = (opt.encoding === undefined ? 'utf8' : opt.encoding);

// open
const term: IUnixOpenProcess = pty.open(cols, rows);

self._master = new PipeSocket(<number>term.master);
self._master.setEncoding(encoding);
if (encoding !== null) {
self._master.setEncoding(encoding);
}
self._master.resume();

self._slave = new PipeSocket(term.slave);
self._slave.setEncoding(encoding);
if (encoding !== null) {
self._slave.setEncoding(encoding);
}
self._slave.resume();

self._socket = self._master;
Expand Down Expand Up @@ -249,6 +252,8 @@ export class UnixTerminal extends Terminal {

public resize(cols: number, rows: number): void {
pty.resize(this._fd, cols, rows);
this._cols = cols;
this._rows = rows;
}

private _sanitizeEnv(env: IProcessEnv): void {
Expand Down Expand Up @@ -276,11 +281,10 @@ export class UnixTerminal extends Terminal {
*/
class PipeSocket extends net.Socket {
constructor(fd: number) {
const tty = (<any>process).binding('tty_wrap');
const guessHandleType = tty.guessHandleType;
tty.guessHandleType = () => 'PIPE';
const { Pipe, constants } = (<any>process).binding('pipe_wrap'); // tslint:disable-line
// @types/node has fd as string? https://github.com/DefinitelyTyped/DefinitelyTyped/pull/18275
super({ fd: <any>fd });
tty.guessHandleType = guessHandleType;
const handle = new Pipe(constants.SOCKET);
handle.open(fd);
super(<any>{ handle });
}
}
Loading

0 comments on commit 6e9acd6

Please sign in to comment.