@@ -2,6 +2,7 @@ import {EventEmitter} from 'events';
22import { ChildProcess , spawn , SpawnOptions } from 'child_process' ;
33import { EOL as newline } from 'os' ;
44import { join } from 'path'
5+ import { Readable , Writable } from 'stream'
56
67function toArray < T > ( source ?:T | T [ ] ) :T [ ] {
78 if ( typeof source === 'undefined' || source === null ) {
@@ -26,15 +27,15 @@ function extend(obj:{}, ...args) {
2627 return obj ;
2728}
2829
29- interface Options extends SpawnOptions {
30- mode : 'text' | 'json' | 'binary'
31- formatter : ( param :string ) => any
32- parser : ( param :string ) => any
33- encoding : string
34- pythonPath : string
35- pythonOptions : string [ ]
36- scriptPath : string
37- args : string [ ]
30+ export interface Options extends SpawnOptions {
31+ mode ? : 'text' | 'json' | 'binary'
32+ formatter ? : ( param :string ) => any
33+ parser ? : ( param :string ) => any
34+ encoding ? : string
35+ pythonPath ? : string
36+ pythonOptions ? : string [ ]
37+ scriptPath ? : string
38+ args ? : string [ ]
3839}
3940
4041class PythonShellError extends Error {
@@ -47,17 +48,17 @@ class PythonShellError extends Error{
4748 * @param {object } [options] The launch options (also passed to child_process.spawn)
4849 * @constructor
4950 */
50- class PythonShell extends EventEmitter {
51+ export class PythonShell extends EventEmitter {
5152 script :string
5253 command :string [ ]
5354 mode :string
5455 formatter :( param :string | Object ) => any
5556 parser :( param :string ) => any
5657 terminated :boolean
5758 childProcess :ChildProcess
58- stdin : NodeJS . WriteStream ; //or writeable stream? Whats difference?
59- stdout : NodeJS . ReadStream ;
60- stderr : NodeJS . ReadStream ;
59+ stdin : Writable ;
60+ stdout : Readable ;
61+ stderr : Readable ;
6162 private stderrHasEnded :boolean ;
6263 private stdoutHasEnded :boolean ;
6364 private exitCode :number ;
@@ -68,7 +69,7 @@ class PythonShell extends EventEmitter{
6869 //@ts -ignore keeping it initialized to {} for backwards API compatability
6970 static defaultOptions :Options = { } ; //allow global overrides for options
7071
71- constructor ( script :string , options :Options ) {
72+ constructor ( script :string , options ? :Options ) {
7273 super ( ) ;
7374
7475 /**
@@ -195,7 +196,7 @@ class PythonShell extends EventEmitter{
195196 * @param {Function } callback The callback function to invoke with the script results
196197 * @return {PythonShell } The PythonShell instance
197198 */
198- static run ( script :string , options :Options , callback :( err :PythonShellError , output ?:any [ ] ) => any ) {
199+ static run ( script :string , options ? :Options , callback ? :( err :PythonShellError , output ?:any [ ] ) => any ) {
199200 if ( typeof options === 'function' ) {
200201 callback = options ;
201202 options = null ;
@@ -300,6 +301,3 @@ class PythonShell extends EventEmitter{
300301 return this ;
301302 } ;
302303} ;
303-
304-
305- module . exports = PythonShell ;
0 commit comments