@positronic/shell 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { LocalShell } from './local-shell';
2
- import { SSH2Shell } from './ssh2-shell';
1
+ import { LocalShell } from './local-shell.js';
2
+ import { SSH2Shell } from './ssh2-shell.js';
3
3
  export { LocalShell, SSH2Shell };
@@ -94,7 +94,7 @@ function _object_without_properties_loose(source, excluded) {
94
94
  return target;
95
95
  }
96
96
  function _ts_generator(thisArg, body) {
97
- var f, y, t, g, _ = {
97
+ var f, y, t, _ = {
98
98
  label: 0,
99
99
  sent: function() {
100
100
  if (t[0] & 1) throw t[1];
@@ -102,12 +102,8 @@ function _ts_generator(thisArg, body) {
102
102
  },
103
103
  trys: [],
104
104
  ops: []
105
- };
106
- return g = {
107
- next: verb(0),
108
- "throw": verb(1),
109
- "return": verb(2)
110
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
105
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
106
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
111
107
  return this;
112
108
  }), g;
113
109
  function verb(n) {
@@ -120,7 +116,7 @@ function _ts_generator(thisArg, body) {
120
116
  }
121
117
  function step(op) {
122
118
  if (f) throw new TypeError("Generator is already executing.");
123
- while(_)try {
119
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
124
120
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
125
121
  if (y = 0, t) op = [
126
122
  op[0] & 2,
@@ -201,11 +197,13 @@ export var LocalShell = /*#__PURE__*/ function() {
201
197
  _create_class(LocalShell, [
202
198
  {
203
199
  key: "execCommand",
204
- value: function execCommand(givenCommand) {
205
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
206
- var _this = this;
207
- return _async_to_generator(function() {
200
+ value: function execCommand(_0) {
201
+ return _async_to_generator(function(givenCommand) {
202
+ var _this, options;
203
+ var _arguments = arguments;
208
204
  return _ts_generator(this, function(_state) {
205
+ _this = this;
206
+ options = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
209
207
  return [
210
208
  2,
211
209
  new Promise(function(resolve, reject) {
@@ -256,26 +254,26 @@ export var LocalShell = /*#__PURE__*/ function() {
256
254
  })
257
255
  ];
258
256
  });
259
- })();
257
+ }).apply(this, arguments);
260
258
  }
261
259
  },
262
260
  {
263
261
  key: "exec",
264
- value: function exec(command, parameters) {
265
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
266
- var _this = this;
267
- return _async_to_generator(function() {
268
- var _options_stream, stream, execOptions, fullCommand, result;
262
+ value: function exec(_0, _1) {
263
+ return _async_to_generator(function(command, parameters) {
264
+ var options, _options_stream, stream, execOptions, fullCommand, result;
265
+ var _arguments = arguments;
269
266
  return _ts_generator(this, function(_state) {
270
267
  switch(_state.label){
271
268
  case 0:
269
+ options = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
272
270
  _options_stream = options.stream, stream = _options_stream === void 0 ? 'stdout' : _options_stream, execOptions = _object_without_properties(options, [
273
271
  "stream"
274
272
  ]);
275
273
  fullCommand = "".concat(command, " ").concat(parameters.join(' '));
276
274
  return [
277
275
  4,
278
- _this.execCommand(fullCommand, execOptions)
276
+ this.execCommand(fullCommand, execOptions)
279
277
  ];
280
278
  case 1:
281
279
  result = _state.sent();
@@ -291,7 +289,7 @@ export var LocalShell = /*#__PURE__*/ function() {
291
289
  ];
292
290
  }
293
291
  });
294
- })();
292
+ }).apply(this, arguments);
295
293
  }
296
294
  }
297
295
  ]);
@@ -102,7 +102,7 @@ function _object_without_properties_loose(source, excluded) {
102
102
  return target;
103
103
  }
104
104
  function _ts_generator(thisArg, body) {
105
- var f, y, t, g, _ = {
105
+ var f, y, t, _ = {
106
106
  label: 0,
107
107
  sent: function() {
108
108
  if (t[0] & 1) throw t[1];
@@ -110,12 +110,8 @@ function _ts_generator(thisArg, body) {
110
110
  },
111
111
  trys: [],
112
112
  ops: []
113
- };
114
- return g = {
115
- next: verb(0),
116
- "throw": verb(1),
117
- "return": verb(2)
118
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
113
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
114
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
119
115
  return this;
120
116
  }), g;
121
117
  function verb(n) {
@@ -128,7 +124,7 @@ function _ts_generator(thisArg, body) {
128
124
  }
129
125
  function step(op) {
130
126
  if (f) throw new TypeError("Generator is already executing.");
131
- while(_)try {
127
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
132
128
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
133
129
  if (y = 0, t) op = [
134
130
  op[0] & 2,
@@ -212,9 +208,10 @@ export var SSH2Shell = /*#__PURE__*/ function() {
212
208
  {
213
209
  key: "connect",
214
210
  value: function connect() {
215
- var _this = this;
216
211
  return _async_to_generator(function() {
212
+ var _this;
217
213
  return _ts_generator(this, function(_state) {
214
+ _this = this;
218
215
  return [
219
216
  2,
220
217
  new Promise(function(resolve, reject) {
@@ -228,16 +225,18 @@ export var SSH2Shell = /*#__PURE__*/ function() {
228
225
  })
229
226
  ];
230
227
  });
231
- })();
228
+ }).call(this);
232
229
  }
233
230
  },
234
231
  {
235
232
  key: "execCommand",
236
- value: function execCommand(givenCommand) {
237
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
238
- var _this = this;
239
- return _async_to_generator(function() {
233
+ value: function execCommand(_0) {
234
+ return _async_to_generator(function(givenCommand) {
235
+ var _this, options;
236
+ var _arguments = arguments;
240
237
  return _ts_generator(this, function(_state) {
238
+ _this = this;
239
+ options = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
241
240
  return [
242
241
  2,
243
242
  new Promise(function(resolve, reject) {
@@ -311,26 +310,26 @@ export var SSH2Shell = /*#__PURE__*/ function() {
311
310
  })
312
311
  ];
313
312
  });
314
- })();
313
+ }).apply(this, arguments);
315
314
  }
316
315
  },
317
316
  {
318
317
  key: "exec",
319
- value: function exec(command, parameters) {
320
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
321
- var _this = this;
322
- return _async_to_generator(function() {
323
- var _options_stream, stream, execOptions, fullCommand, result;
318
+ value: function exec(_0, _1) {
319
+ return _async_to_generator(function(command, parameters) {
320
+ var options, _options_stream, stream, execOptions, fullCommand, result;
321
+ var _arguments = arguments;
324
322
  return _ts_generator(this, function(_state) {
325
323
  switch(_state.label){
326
324
  case 0:
325
+ options = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
327
326
  _options_stream = options.stream, stream = _options_stream === void 0 ? 'stdout' : _options_stream, execOptions = _object_without_properties(options, [
328
327
  "stream"
329
328
  ]);
330
329
  fullCommand = "".concat(command, " ").concat(parameters.join(' '));
331
330
  return [
332
331
  4,
333
- _this.execCommand(fullCommand, execOptions)
332
+ this.execCommand(fullCommand, execOptions)
334
333
  ];
335
334
  case 1:
336
335
  result = _state.sent();
@@ -346,21 +345,20 @@ export var SSH2Shell = /*#__PURE__*/ function() {
346
345
  ];
347
346
  }
348
347
  });
349
- })();
348
+ }).apply(this, arguments);
350
349
  }
351
350
  },
352
351
  {
353
352
  key: "disconnect",
354
353
  value: function disconnect() {
355
- var _this = this;
356
354
  return _async_to_generator(function() {
357
355
  return _ts_generator(this, function(_state) {
358
- _this.client.end();
356
+ this.client.end();
359
357
  return [
360
358
  2
361
359
  ];
362
360
  });
363
- })();
361
+ }).call(this);
364
362
  }
365
363
  }
366
364
  ]);
@@ -1,4 +1,4 @@
1
- import { LocalShell } from './local-shell';
2
- import { SSH2Shell } from './ssh2-shell';
1
+ import { LocalShell } from './local-shell.js';
2
+ import { SSH2Shell } from './ssh2-shell.js';
3
3
  export { LocalShell, SSH2Shell };
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { Shell, ExecCommandOptions, ExecCommandResponse } from './types';
1
+ import type { Shell, ExecCommandOptions, ExecCommandResponse } from './types.js';
2
2
  interface LocalShellOptions {
3
3
  cwd?: string;
4
4
  shell?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"local-shell.d.ts","sourceRoot":"","sources":["../../src/local-shell.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9E,UAAU,iBAAiB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB;AAED,qBAAa,UAAW,YAAW,KAAK;IAC1B,OAAO,CAAC,MAAM;gBAAN,MAAM,GAAE,iBAAsB;IAE5C,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA+DjG,IAAI,CACR,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAAE,EACpB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,MAAM,GAAG,mBAAmB,CAAC;CAWzC"}
1
+ {"version":3,"file":"local-shell.d.ts","sourceRoot":"","sources":["../../src/local-shell.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,KAAK,EACL,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,UAAU,iBAAiB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB;AAED,qBAAa,UAAW,YAAW,KAAK;IAC1B,OAAO,CAAC,MAAM;gBAAN,MAAM,GAAE,iBAAsB;IAE5C,WAAW,CACf,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,mBAAmB,CAAC;IA+DzB,IAAI,CACR,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAAE,EACpB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,MAAM,GAAG,mBAAmB,CAAC;CAWzC"}
@@ -1,4 +1,4 @@
1
- import type { Shell, ExecCommandOptions, ExecCommandResponse } from './types';
1
+ import type { Shell, ExecCommandOptions, ExecCommandResponse } from './types.js';
2
2
  import type { ConnectConfig } from 'ssh2';
3
3
  interface SSH2ShellOptions extends ConnectConfig {
4
4
  env?: NodeJS.ProcessEnv;
@@ -1 +1 @@
1
- {"version":3,"file":"ssh2-shell.d.ts","sourceRoot":"","sources":["../../src/ssh2-shell.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,KAAK,EAAE,aA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CAAC,MAAM,GAAG,mBAAmB,CAAC,CAAC;CAC1C"}
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@positronic/shell",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
4
7
  "description": "Shell implementations for Positronic",
5
8
  "type": "module",
6
9
  "main": "dist/src/index.js",
7
10
  "types": "dist/types/index.ts",
11
+ "license": "MIT",
8
12
  "scripts": {
9
13
  "tsc": "tsc --project tsconfig.json",
10
14
  "swc": "swc src -d dist",
11
15
  "build": "npm run tsc && npm run swc",
12
- "clean": "rm -rf tsconfig.tsbuildinfo dist"
16
+ "clean": "rm -rf tsconfig.tsbuildinfo dist node_modules"
13
17
  },
14
18
  "dependencies": {
15
19
  "ssh2": "^1.14.0"
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LocalShell } from './local-shell';
2
- import { SSH2Shell } from './ssh2-shell';
1
+ import { LocalShell } from './local-shell.js';
2
+ import { SSH2Shell } from './ssh2-shell.js';
3
3
 
4
- export { LocalShell, SSH2Shell };
4
+ export { LocalShell, SSH2Shell };
@@ -1,7 +1,11 @@
1
1
  import { spawn } from 'child_process';
2
2
  import { Readable } from 'stream';
3
3
 
4
- import type { Shell, ExecCommandOptions, ExecCommandResponse } from './types';
4
+ import type {
5
+ Shell,
6
+ ExecCommandOptions,
7
+ ExecCommandResponse,
8
+ } from './types.js';
5
9
 
6
10
  interface LocalShellOptions {
7
11
  cwd?: string;
@@ -12,7 +16,10 @@ interface LocalShellOptions {
12
16
  export class LocalShell implements Shell {
13
17
  constructor(private config: LocalShellOptions = {}) {}
14
18
 
15
- async execCommand(givenCommand: string, options: ExecCommandOptions = {}): Promise<ExecCommandResponse> {
19
+ async execCommand(
20
+ givenCommand: string,
21
+ options: ExecCommandOptions = {}
22
+ ): Promise<ExecCommandResponse> {
16
23
  return new Promise((resolve, reject) => {
17
24
  const {
18
25
  cwd = this.config.cwd || process.cwd(),
@@ -23,7 +30,7 @@ export class LocalShell implements Shell {
23
30
  onStderr,
24
31
  env = this.config.env,
25
32
  timeout,
26
- shell = this.config.shell || 'bash'
33
+ shell = this.config.shell || 'bash',
27
34
  } = options;
28
35
 
29
36
  const childProcess = spawn(shell, ['-c', givenCommand], {
@@ -90,4 +97,4 @@ export class LocalShell implements Shell {
90
97
 
91
98
  return stream === 'stdout' ? result.stdout : result.stderr;
92
99
  }
93
- }
100
+ }
package/src/ssh2-shell.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import { Client, ClientChannel } from 'ssh2';
2
- import type { Shell, ExecCommandOptions, ExecCommandResponse } from './types';
2
+ import type {
3
+ Shell,
4
+ ExecCommandOptions,
5
+ ExecCommandResponse,
6
+ } from './types.js';
3
7
  import type { ConnectConfig } from 'ssh2';
4
8
 
5
9
  interface SSH2ShellOptions extends ConnectConfig {
@@ -33,95 +37,102 @@ export class SSH2Shell implements Shell {
33
37
  });
34
38
  }
35
39
 
36
- async execCommand(
37
- givenCommand: string,
38
- options: ExecCommandOptions = {}
39
- ) {
40
+ async execCommand(givenCommand: string, options: ExecCommandOptions = {}) {
40
41
  return new Promise<ExecCommandResponse>((resolve, reject) => {
41
42
  const env = { ...this.config.env, ...options.env };
42
43
  const shell = this.config.shell || options.shell || null;
43
- const shellCommand = shell ? `${shell} -c "${givenCommand}"` : givenCommand;
44
+ const shellCommand = shell
45
+ ? `${shell} -c "${givenCommand}"`
46
+ : givenCommand;
44
47
  const cwd = options.cwd || this.defaultCwd;
45
48
 
46
49
  if (cwd) {
47
50
  // Prepend cd command if cwd is specified
48
51
  const fullCommand = `cd ${cwd} && ${shellCommand}`;
49
- this.client.exec(fullCommand, { env }, (err: Error | undefined, stream: ClientChannel) => {
50
- if (err) {
51
- reject(err);
52
- return;
52
+ this.client.exec(
53
+ fullCommand,
54
+ { env },
55
+ (err: Error | undefined, stream: ClientChannel) => {
56
+ if (err) {
57
+ reject(err);
58
+ return;
59
+ }
60
+
61
+ const { noTrim = false } = options;
62
+
63
+ let stdout: string[] = [];
64
+ let stderr: string[] = [];
65
+
66
+ stream.on('data', (data: Buffer) => {
67
+ stdout.push(data.toString());
68
+ });
69
+
70
+ stream.stderr.on('data', (data: Buffer) => {
71
+ stderr.push(data.toString());
72
+ });
73
+
74
+ stream.on('close', (code: number, signal: string | null) => {
75
+ const response: ExecCommandResponse = {
76
+ stdout: noTrim ? stdout.join('') : stdout.join('').trim(),
77
+ stderr: noTrim ? stderr.join('') : stderr.join('').trim(),
78
+ code,
79
+ signal,
80
+ };
81
+ resolve(response);
82
+ });
83
+
84
+ stream.on('error', (err: Error) => {
85
+ reject(err);
86
+ });
53
87
  }
54
-
55
- const {
56
- noTrim = false
57
- } = options;
58
-
59
- let stdout: string[] = [];
60
- let stderr: string[] = [];
61
-
62
- stream.on('data', (data: Buffer) => {
63
- stdout.push(data.toString());
64
- });
65
-
66
- stream.stderr.on('data', (data: Buffer) => {
67
- stderr.push(data.toString());
68
- });
69
-
70
- stream.on('close', (code: number, signal: string | null) => {
71
- const response: ExecCommandResponse = {
72
- stdout: noTrim ? stdout.join('') : stdout.join('').trim(),
73
- stderr: noTrim ? stderr.join('') : stderr.join('').trim(),
74
- code,
75
- signal
76
- };
77
- resolve(response);
78
- });
79
-
80
- stream.on('error', (err: Error) => {
81
- reject(err);
82
- });
83
- });
88
+ );
84
89
  } else {
85
- this.client.exec(shellCommand, { env }, (err: Error | undefined, stream: ClientChannel) => {
86
- if (err) {
87
- reject(err);
88
- return;
90
+ this.client.exec(
91
+ shellCommand,
92
+ { env },
93
+ (err: Error | undefined, stream: ClientChannel) => {
94
+ if (err) {
95
+ reject(err);
96
+ return;
97
+ }
98
+
99
+ const { noTrim = false } = options;
100
+
101
+ let stdout: string[] = [];
102
+ let stderr: string[] = [];
103
+
104
+ stream.on('data', (data: Buffer) => {
105
+ stdout.push(data.toString());
106
+ });
107
+
108
+ stream.stderr.on('data', (data: Buffer) => {
109
+ stderr.push(data.toString());
110
+ });
111
+
112
+ stream.on('close', (code: number, signal: string | null) => {
113
+ const response: ExecCommandResponse = {
114
+ stdout: noTrim ? stdout.join('') : stdout.join('').trim(),
115
+ stderr: noTrim ? stderr.join('') : stderr.join('').trim(),
116
+ code,
117
+ signal,
118
+ };
119
+ resolve(response);
120
+ });
121
+
122
+ stream.on('error', (err: Error) => {
123
+ reject(err);
124
+ });
89
125
  }
90
-
91
- const {
92
- noTrim = false
93
- } = options;
94
-
95
- let stdout: string[] = [];
96
- let stderr: string[] = [];
97
-
98
- stream.on('data', (data: Buffer) => {
99
- stdout.push(data.toString());
100
- });
101
-
102
- stream.stderr.on('data', (data: Buffer) => {
103
- stderr.push(data.toString());
104
- });
105
-
106
- stream.on('close', (code: number, signal: string | null) => {
107
- const response: ExecCommandResponse = {
108
- stdout: noTrim ? stdout.join('') : stdout.join('').trim(),
109
- stderr: noTrim ? stderr.join('') : stderr.join('').trim(),
110
- code,
111
- signal
112
- };
113
- resolve(response);
114
- });
115
-
116
- stream.on('error', (err: Error) => {
117
- reject(err);
118
- });
119
- });
126
+ );
120
127
  }
121
128
  });
122
129
  }
123
130
 
124
- async exec(command: string, parameters: string[], options: ExecCommandOptions = {}) {
131
+ async exec(
132
+ command: string,
133
+ parameters: string[],
134
+ options: ExecCommandOptions = {}
135
+ ) {
125
136
  const { stream = 'stdout', ...execOptions } = options;
126
137
  const fullCommand = `${command} ${parameters.join(' ')}`;
127
138
  const result = await this.execCommand(fullCommand, execOptions);
@@ -136,4 +147,4 @@ export class SSH2Shell implements Shell {
136
147
  async disconnect() {
137
148
  this.client.end();
138
149
  }
139
- }
150
+ }
package/src/types.ts CHANGED
@@ -21,6 +21,13 @@ export interface ExecCommandResponse {
21
21
  }
22
22
 
23
23
  export interface Shell {
24
- execCommand(givenCommand: string, options?: ExecCommandOptions): Promise<ExecCommandResponse>;
25
- exec(command: string, parameters: string[], options?: ExecCommandOptions): Promise<string | ExecCommandResponse>;
26
- }
24
+ execCommand(
25
+ givenCommand: string,
26
+ options?: ExecCommandOptions
27
+ ): Promise<ExecCommandResponse>;
28
+ exec(
29
+ command: string,
30
+ parameters: string[],
31
+ options?: ExecCommandOptions
32
+ ): Promise<string | ExecCommandResponse>;
33
+ }
package/tsconfig.json CHANGED
@@ -7,4 +7,4 @@
7
7
  },
8
8
  "include": ["**/*"],
9
9
  "exclude": ["dist", "node_modules", "**/*.test.ts"]
10
- }
10
+ }