first-base 1.3.0 → 1.4.0

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/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export type Options = {
8
8
  shell?: boolean | string;
9
9
  windowsVerbatimArguments?: boolean;
10
10
  windowsHide?: boolean;
11
+ pty?: boolean;
11
12
  };
12
13
 
13
14
  export type RunContext = {
package/dist/index.js CHANGED
@@ -1,37 +1,31 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
-
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
4
  var normalSpawn = require("child_process").spawn;
5
+ var ptySpawn = require("node-pty").spawn;
6
+ var stripAnsi = require("strip-ansi");
6
7
 
7
- var stripAnsi = require("strip-ansi"); // Run a child process and return a "run context" object
8
+ // Run a child process and return a "run context" object
8
9
  // to interact with it. Function signature is the same as
9
10
  // child_process spawn, except you can pass `pty: true` in
10
11
  // options to run the process in a psuedo-tty.
11
-
12
-
13
12
  var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
14
13
  var args;
15
14
  var options;
16
-
17
15
  if (Array.isArray(argsOrOptions)) {
18
16
  args = argsOrOptions;
19
17
  } else if (_typeof(argsOrOptions) === "object") {
20
18
  options = argsOrOptions;
21
19
  }
22
-
23
20
  if (passedOptions && !options) {
24
21
  options = passedOptions;
25
22
  }
26
-
27
23
  if (!args) {
28
24
  args = [];
29
25
  }
30
-
31
26
  if (!options) {
32
27
  options = {};
33
28
  }
34
-
35
29
  var child;
36
30
  var stdin;
37
31
  var stdout;
@@ -41,15 +35,12 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
41
35
  var _debug = false;
42
36
  var outputContainsBuffer = "";
43
37
  var pendingOutputContainsRequests = new Set();
44
-
45
38
  var debugLog = function debugLog() {
46
39
  if (_debug) {
47
40
  var _console;
48
-
49
41
  (_console = console).log.apply(_console, arguments);
50
42
  }
51
43
  };
52
-
53
44
  var runContext = {
54
45
  result: {
55
46
  // All of the stdout and stderr the process has written so far.
@@ -75,17 +66,14 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
75
66
  var request = {
76
67
  value: value
77
68
  };
78
-
79
69
  request.resolve = function () {
80
- pendingOutputContainsRequests.delete(request);
70
+ pendingOutputContainsRequests["delete"](request);
81
71
  resolve();
82
72
  };
83
-
84
73
  request.reject = function () {
85
- pendingOutputContainsRequests.delete(request);
74
+ pendingOutputContainsRequests["delete"](request);
86
75
  reject();
87
76
  };
88
-
89
77
  pendingOutputContainsRequests.add(request);
90
78
  });
91
79
  },
@@ -104,19 +92,16 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
104
92
  stdin.end();
105
93
  break;
106
94
  }
107
-
108
95
  case "stdout":
109
96
  {
110
97
  stdout.end();
111
98
  break;
112
99
  }
113
-
114
100
  case "stderr":
115
101
  {
116
102
  stderr.end();
117
103
  break;
118
104
  }
119
-
120
105
  default:
121
106
  {
122
107
  throw new Error("Invalid stream name: '".concat(stream, "'. Valid names are 'stdin', 'stdout', or 'stderr'."));
@@ -127,19 +112,20 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
127
112
  // You can pass "SIGTERM", "SIGKILL", etc. Defaults to "SIGINT".
128
113
  kill: function kill() {
129
114
  var signal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "SIGINT";
130
-
131
115
  if (running) {
132
116
  child.kill(signal);
133
117
  }
134
-
135
118
  if (unreffable) {
136
119
  unreffable.unref();
137
120
  }
138
121
  }
139
122
  };
140
-
141
123
  if (options.pty) {
142
- throw new Error("pty mode is no longer supported due to lack of support for new node.js versions in the node-pty module");
124
+ child = ptySpawn(cmd, args, options);
125
+ stdin = child;
126
+ stdout = child;
127
+ stderr = null; // no way to tell between stdout and stderr with pty
128
+ unreffable = child.socket;
143
129
  } else {
144
130
  child = normalSpawn(cmd, args, options);
145
131
  stdin = child.stdin;
@@ -147,9 +133,7 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
147
133
  stderr = child.stderr;
148
134
  unreffable = child;
149
135
  }
150
-
151
136
  running = true;
152
-
153
137
  var checkForPendingOutputRequestsToResolve = function checkForPendingOutputRequestsToResolve() {
154
138
  pendingOutputContainsRequests.forEach(function (request) {
155
139
  if (typeof request.value === "string") {
@@ -163,16 +147,13 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
163
147
  }
164
148
  });
165
149
  };
166
-
167
150
  stdout.setEncoding("utf-8");
168
-
169
151
  var handleStdoutData = function handleStdoutData(data) {
170
152
  runContext.result.stdout += data;
171
153
  outputContainsBuffer += data;
172
154
  debugLog("STDOUT: ".concat(data.toString()));
173
155
  checkForPendingOutputRequestsToResolve();
174
156
  };
175
-
176
157
  if (stdout.onData) {
177
158
  // the pty instance returned by node-pty
178
159
  // requires attaching handlers differently
@@ -180,11 +161,11 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
180
161
  } else {
181
162
  stdout.on("data", handleStdoutData);
182
163
  }
183
-
184
164
  if (stderr) {
185
- stderr.setEncoding("utf-8"); // this is never a pty instance,
186
- // so we don't need to deal with onData here:
165
+ stderr.setEncoding("utf-8");
187
166
 
167
+ // this is never a pty instance,
168
+ // so we don't need to deal with onData here:
188
169
  stderr.on("data", function (data) {
189
170
  runContext.result.stderr += data;
190
171
  outputContainsBuffer += data;
@@ -192,7 +173,6 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
192
173
  checkForPendingOutputRequestsToResolve();
193
174
  });
194
175
  }
195
-
196
176
  runContext.completion = new Promise(function (resolve) {
197
177
  var finish = function finish(reason) {
198
178
  debugLog("Process ".concat(reason));
@@ -203,7 +183,6 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
203
183
  request.reject(new Error("Child process ".concat(reason, " before its output contained the requested content: ").concat(request.value)));
204
184
  });
205
185
  };
206
-
207
186
  child.once("exit", function (code) {
208
187
  runContext.result.code = code;
209
188
  finish("exited");
@@ -215,7 +194,6 @@ var spawn = function spawn(cmd, argsOrOptions, passedOptions) {
215
194
  });
216
195
  return runContext;
217
196
  };
218
-
219
197
  module.exports = {
220
198
  spawn: spawn
221
199
  };
@@ -9,6 +9,7 @@ export type Options = {
9
9
  shell?: ?boolean | string,
10
10
  windowsVerbatimArguments?: ?boolean,
11
11
  windowsHide?: ?boolean,
12
+ pty?: ?boolean,
12
13
  };
13
14
 
14
15
  export type RunContext = {
package/package.json CHANGED
@@ -1,25 +1,26 @@
1
1
  {
2
2
  "name": "first-base",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Integration testing for CLI applications",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://github.com/suchipi/first-base",
7
7
  "author": "Lily Skye <me@suchipi.com>",
8
8
  "license": "MIT",
9
9
  "dependencies": {
10
+ "node-pty": "^1.0.0",
10
11
  "strip-ansi": "^5.0.0"
11
12
  },
12
13
  "devDependencies": {
13
- "@babel/cli": "^7.2.3",
14
- "@babel/core": "^7.2.2",
15
- "@babel/preset-env": "^7.2.3",
14
+ "@babel/cli": "^7.23.4",
15
+ "@babel/core": "^7.23.7",
16
+ "@babel/preset-env": "^7.23.8",
16
17
  "babel-core": "^7.0.0-bridge.0",
17
- "babel-jest": "^23.6.0",
18
- "eslint": "^5.11.1",
19
- "eslint-config-unobtrusive": "^1.2.2",
20
- "eslint-plugin-import": "^2.14.0",
21
- "jest": "^23.6.0",
22
- "prettier": "^1.15.3"
18
+ "babel-jest": "^29.7.0",
19
+ "eslint": "^8.56.0",
20
+ "eslint-config-unobtrusive": "^1.2.5",
21
+ "eslint-plugin-import": "^2.29.1",
22
+ "jest": "^29.7.0",
23
+ "prettier": "^3.2.4"
23
24
  },
24
25
  "scripts": {
25
26
  "build": "mkdir -p dist; rm -rf dist/*; babel src/index.js --out-dir dist && cp src/index.js.flow dist/ && cp src/index.d.ts dist/",