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

adjust comments for Pty accepting objects #11

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 15 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,31 @@ export interface Size {
* This is the recommended usage:
*
* ```
* const { Pty } = require('replit-ruspy');
* const fs = require('node:fs');
* const { Pty } = require('@replit/ruspy');
* const fs = require('fs');
*
* const pty = new Pty('sh', [], ENV, CWD, { rows: 24, cols: 80 }, (...result) => {
* pty.close();
* // TODO: Handle process exit.
* const pty = new Pty({
* command: 'sh',
* args: [],
* envs: ENV,
* dir: CWD,
* size: { rows: 24, cols: 80 },
* onExit: (...result) => {
* pty.close();
* // TODO: Handle process exit.
* },
* onData: (err, data) => {
* // NOTE: Optional arguments supported only on linux, workaround for Bun v1.1.7 fd bugs.
* }
* });
*
* const read = new fs.createReadStream('', {
* fd: pty.fd(),
* start: 0,
* highWaterMark: 16 * 1024,
* autoClose: true,
* });
* const write = new fs.createWriteStream('', {
* fd: pty.fd(),
* autoClose: true,
* });
*
* read.on('data', (chunk) => {
Expand All @@ -63,9 +71,6 @@ export interface Size {
* // TODO: Handle the error.
* });
* ```
*
* The last parameter (a callback that gets stdin chunks) is optional and is only there for
* compatibility with bun 1.1.7.
*/
export class Pty {
/** The pid of the forked process. */
Expand Down
6 changes: 3 additions & 3 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ if (os.type() !== 'Darwin') {
}

describe('PTY', () => {
const CWD = process.cwd();

test('spawns and exits', (done) => {
const message = 'hello from a pty';
let buffer = '';
Expand Down Expand Up @@ -201,14 +199,16 @@ describe('PTY', () => {
});

test('respects working directory', (done) => {
const cwd = process.cwd();
let buffer = '';

const pty = new Pty({
command: '/bin/pwd',
dir: cwd,
onExit: (err, exitCode) => {
expect(err).toBeNull();
expect(exitCode).toBe(0);
expect(buffer).toBe(`${CWD}\r\n`);
expect(buffer).toBe(`${cwd}\r\n`);
pty.close();

done();
Expand Down
6 changes: 5 additions & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
"license": "MIT",
"engines": {
"node": ">= 10"
},
"repository": {
"type": "git",
"url": "git+https://github.com/replit/ruspty.git"
}
}
}
8 changes: 6 additions & 2 deletions npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
},
"libc": [
"glibc"
]
}
],
"repository": {
"type": "git",
"url": "git+https://github.com/replit/ruspty.git"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Szymon Kaliski <[email protected]>",
"repository": {
"type": "git",
"url": "https://github.com/replit/ruspty.git"
"url": "git+https://github.com/replit/ruspty.git"
},
"homepage": "https://github.com/replit/ruspty#readme",
"bugs": {
Expand Down
25 changes: 15 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,31 @@ extern crate napi_derive;
/// This is the recommended usage:
///
/// ```
/// const { Pty } = require('replit-ruspy');
/// const fs = require('node:fs');
/// const { Pty } = require('@replit/ruspy');
/// const fs = require('fs');
///
/// const pty = new Pty('sh', [], ENV, CWD, { rows: 24, cols: 80 }, (...result) => {
/// pty.close();
/// // TODO: Handle process exit.
/// const pty = new Pty({
/// command: 'sh',
/// args: [],
/// envs: ENV,
/// dir: CWD,
/// size: { rows: 24, cols: 80 },
/// onExit: (...result) => {
/// pty.close();
/// // TODO: Handle process exit.
/// },
/// onData: (err, data) => {
/// // NOTE: Optional arguments supported only on linux, workaround for Bun v1.1.7 fd bugs.
/// }
/// });
///
/// const read = new fs.createReadStream('', {
/// fd: pty.fd(),
/// start: 0,
/// highWaterMark: 16 * 1024,
/// autoClose: true,
/// });
/// const write = new fs.createWriteStream('', {
/// fd: pty.fd(),
/// autoClose: true,
/// });
///
/// read.on('data', (chunk) => {
Expand All @@ -64,9 +72,6 @@ extern crate napi_derive;
/// // TODO: Handle the error.
/// });
/// ```
///
/// The last parameter (a callback that gets stdin chunks) is optional and is only there for
/// compatibility with bun 1.1.7.
#[napi]
#[allow(dead_code)]
struct Pty {
Expand Down