@theia/process 1.17.0-next.ff9e0507 → 1.18.0-next.04e2816d

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.
Files changed (39) hide show
  1. package/lib/common/process-common-module.js +3 -3
  2. package/lib/common/process-common-module.js.map +1 -1
  3. package/lib/common/shell-command-builder.js +54 -129
  4. package/lib/common/shell-command-builder.js.map +1 -1
  5. package/lib/common/shell-command-builder.slow-spec.js +162 -291
  6. package/lib/common/shell-command-builder.slow-spec.js.map +1 -1
  7. package/lib/common/shell-quoting.js +22 -22
  8. package/lib/common/shell-quoting.js.map +1 -1
  9. package/lib/common/shell-quoting.spec.js +34 -84
  10. package/lib/common/shell-quoting.spec.js.map +1 -1
  11. package/lib/node/dev-null-stream.js +10 -27
  12. package/lib/node/dev-null-stream.js.map +1 -1
  13. package/lib/node/multi-ring-buffer.js +104 -195
  14. package/lib/node/multi-ring-buffer.js.map +1 -1
  15. package/lib/node/multi-ring-buffer.spec.js +220 -468
  16. package/lib/node/multi-ring-buffer.spec.js.map +1 -1
  17. package/lib/node/process-backend-module.js +25 -31
  18. package/lib/node/process-backend-module.js.map +1 -1
  19. package/lib/node/process-manager.js +37 -65
  20. package/lib/node/process-manager.js.map +1 -1
  21. package/lib/node/process.js +68 -131
  22. package/lib/node/process.js.map +1 -1
  23. package/lib/node/pseudo-pty.js +8 -9
  24. package/lib/node/pseudo-pty.js.map +1 -1
  25. package/lib/node/raw-process.js +60 -92
  26. package/lib/node/raw-process.js.map +1 -1
  27. package/lib/node/raw-process.spec.js +114 -238
  28. package/lib/node/raw-process.spec.js.map +1 -1
  29. package/lib/node/task-terminal-process.js +13 -29
  30. package/lib/node/task-terminal-process.js.map +1 -1
  31. package/lib/node/terminal-process.js +75 -103
  32. package/lib/node/terminal-process.js.map +1 -1
  33. package/lib/node/terminal-process.spec.js +55 -132
  34. package/lib/node/terminal-process.spec.js.map +1 -1
  35. package/lib/node/test/process-test-container.js +4 -4
  36. package/lib/node/test/process-test-container.js.map +1 -1
  37. package/lib/node/utils.js +12 -45
  38. package/lib/node/utils.js.map +1 -1
  39. package/package.json +3 -3
@@ -15,9 +15,9 @@
15
15
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
16
  ********************************************************************************/
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- var inversify_1 = require("@theia/core/shared/inversify");
19
- var shell_command_builder_1 = require("./shell-command-builder");
20
- exports.default = new inversify_1.ContainerModule(function (bind, unbind, isBound, rebind) {
18
+ const inversify_1 = require("@theia/core/shared/inversify");
19
+ const shell_command_builder_1 = require("./shell-command-builder");
20
+ exports.default = new inversify_1.ContainerModule((bind, unbind, isBound, rebind) => {
21
21
  bind(shell_command_builder_1.ShellCommandBuilder).toSelf().inSingletonScope();
22
22
  });
23
23
  //# sourceMappingURL=process-common-module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"process-common-module.js","sourceRoot":"","sources":["../../src/common/process-common-module.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;AAElF,0DAA+D;AAC/D,iEAA8D;AAE9D,kBAAe,IAAI,2BAAe,CAAC,UAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAC7D,IAAI,CAAC,2CAAmB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;AAC1D,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"process-common-module.js","sourceRoot":"","sources":["../../src/common/process-common-module.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;AAElF,4DAA+D;AAC/D,mEAA8D;AAE9D,kBAAe,IAAI,2BAAe,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;IACjE,IAAI,CAAC,2CAAmB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;AAC1D,CAAC,CAAC,CAAC"}
@@ -20,47 +20,18 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
20
20
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
21
  return c > 3 && r && Object.defineProperty(target, key, r), r;
22
22
  };
23
- var __values = (this && this.__values) || function(o) {
24
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
25
- if (m) return m.call(o);
26
- if (o && typeof o.length === "number") return {
27
- next: function () {
28
- if (o && i >= o.length) o = void 0;
29
- return { value: o && o[i++], done: !o };
30
- }
31
- };
32
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
33
- };
34
- var __read = (this && this.__read) || function (o, n) {
35
- var m = typeof Symbol === "function" && o[Symbol.iterator];
36
- if (!m) return o;
37
- var i = m.call(o), r, ar = [], e;
38
- try {
39
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
40
- }
41
- catch (error) { e = { error: error }; }
42
- finally {
43
- try {
44
- if (r && !r.done && (m = i["return"])) m.call(i);
45
- }
46
- finally { if (e) throw e.error; }
47
- }
48
- return ar;
49
- };
50
23
  Object.defineProperty(exports, "__esModule", { value: true });
51
24
  exports.ShellCommandBuilder = void 0;
52
25
  /*---------------------------------------------------------------------------------------------
53
26
  * Copyright (c) Microsoft Corporation. All rights reserved.
54
27
  * Licensed under the MIT License. See License.txt in the project root for license information.
55
28
  *--------------------------------------------------------------------------------------------*/
56
- var inversify_1 = require("@theia/core/shared/inversify");
57
- var shell_quoting_1 = require("../common/shell-quoting");
29
+ const inversify_1 = require("@theia/core/shared/inversify");
30
+ const shell_quoting_1 = require("../common/shell-quoting");
58
31
  /**
59
32
  * Create command lines ready to be sent to a shell's stdin for evaluation.
60
33
  */
61
- var ShellCommandBuilder = /** @class */ (function () {
62
- function ShellCommandBuilder() {
63
- }
34
+ let ShellCommandBuilder = class ShellCommandBuilder {
64
35
  /**
65
36
  * Constructs a command line to run in a shell. The shell could be
66
37
  * re-used/long-lived, this means we cannot spawn a new process with a nice
@@ -73,28 +44,16 @@ var ShellCommandBuilder = /** @class */ (function () {
73
44
  * @param hostProcessInfo the host terminal process infos
74
45
  * @param commandOptions program to execute in the host terminal
75
46
  */
76
- ShellCommandBuilder.prototype.buildCommand = function (hostProcessInfo, commandOptions) {
77
- var e_1, _a;
78
- var host = hostProcessInfo && hostProcessInfo.executable;
79
- var cwd = commandOptions.cwd;
80
- var args = commandOptions.args.map(function (value) { return ({
81
- value: value,
82
- quoting: "strong" /* Strong */,
83
- }); });
84
- var env = [];
47
+ buildCommand(hostProcessInfo, commandOptions) {
48
+ const host = hostProcessInfo && hostProcessInfo.executable;
49
+ const cwd = commandOptions.cwd;
50
+ const args = commandOptions.args.map(value => ({
51
+ value, quoting: "strong" /* Strong */,
52
+ }));
53
+ const env = [];
85
54
  if (commandOptions.env) {
86
- try {
87
- for (var _b = __values(Object.keys(commandOptions.env)), _c = _b.next(); !_c.done; _c = _b.next()) {
88
- var key = _c.value;
89
- env.push([key, commandOptions.env[key]]);
90
- }
91
- }
92
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
93
- finally {
94
- try {
95
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
96
- }
97
- finally { if (e_1) throw e_1.error; }
55
+ for (const key of Object.keys(commandOptions.env)) {
56
+ env.push([key, commandOptions.env[key]]);
98
57
  }
99
58
  }
100
59
  if (host) {
@@ -109,100 +68,67 @@ var ShellCommandBuilder = /** @class */ (function () {
109
68
  }
110
69
  }
111
70
  return this.buildForDefault(args, cwd, env);
112
- };
113
- ShellCommandBuilder.prototype.buildForBash = function (args, cwd, env) {
114
- var e_2, _a;
115
- var command = '';
71
+ }
72
+ buildForBash(args, cwd, env) {
73
+ let command = '';
116
74
  if (cwd) {
117
- command += "cd " + shell_quoting_1.BashQuotingFunctions.strong(cwd) + " && ";
75
+ command += `cd ${shell_quoting_1.BashQuotingFunctions.strong(cwd)} && `;
118
76
  }
119
77
  if (env) {
120
78
  command += 'env';
121
- try {
122
- for (var env_1 = __values(env), env_1_1 = env_1.next(); !env_1_1.done; env_1_1 = env_1.next()) {
123
- var _b = __read(env_1_1.value, 2), key = _b[0], value = _b[1];
124
- // eslint-disable-next-line no-null/no-null
125
- if (value === null) {
126
- command += " -u " + shell_quoting_1.BashQuotingFunctions.strong(key);
127
- }
128
- else {
129
- command += " " + shell_quoting_1.BashQuotingFunctions.strong(key + "=" + value);
130
- }
79
+ for (const [key, value] of env) {
80
+ // eslint-disable-next-line no-null/no-null
81
+ if (value === null) {
82
+ command += ` -u ${shell_quoting_1.BashQuotingFunctions.strong(key)}`;
131
83
  }
132
- }
133
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
134
- finally {
135
- try {
136
- if (env_1_1 && !env_1_1.done && (_a = env_1.return)) _a.call(env_1);
84
+ else {
85
+ command += ` ${shell_quoting_1.BashQuotingFunctions.strong(`${key}=${value}`)}`;
137
86
  }
138
- finally { if (e_2) throw e_2.error; }
139
87
  }
140
88
  command += ' ';
141
89
  }
142
90
  command += shell_quoting_1.createShellCommandLine(args, shell_quoting_1.BashQuotingFunctions);
143
91
  return command;
144
- };
145
- ShellCommandBuilder.prototype.buildForPowershell = function (args, cwd, env) {
146
- var e_3, _a;
147
- var command = '';
92
+ }
93
+ buildForPowershell(args, cwd, env) {
94
+ let command = '';
148
95
  if (cwd) {
149
- command += "cd " + shell_quoting_1.PowershellQuotingFunctions.strong(cwd) + "; ";
96
+ command += `cd ${shell_quoting_1.PowershellQuotingFunctions.strong(cwd)}; `;
150
97
  }
151
98
  if (env) {
152
- try {
153
- for (var env_2 = __values(env), env_2_1 = env_2.next(); !env_2_1.done; env_2_1 = env_2.next()) {
154
- var _b = __read(env_2_1.value, 2), key = _b[0], value = _b[1];
155
- // Powershell requires special quoting when dealing with
156
- // environment variable names.
157
- var quotedKey = key
158
- .replace(/`/g, '````')
159
- .replace(/\?/g, '``?');
160
- // eslint-disable-next-line no-null/no-null
161
- if (value === null) {
162
- command += "Remove-Item ${env:" + quotedKey + "}; ";
163
- }
164
- else {
165
- command += "${env:" + quotedKey + "}=" + shell_quoting_1.PowershellQuotingFunctions.strong(value) + "; ";
166
- }
99
+ for (const [key, value] of env) {
100
+ // Powershell requires special quoting when dealing with
101
+ // environment variable names.
102
+ const quotedKey = key
103
+ .replace(/`/g, '````')
104
+ .replace(/\?/g, '``?');
105
+ // eslint-disable-next-line no-null/no-null
106
+ if (value === null) {
107
+ command += `Remove-Item \${env:${quotedKey}}; `;
167
108
  }
168
- }
169
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
170
- finally {
171
- try {
172
- if (env_2_1 && !env_2_1.done && (_a = env_2.return)) _a.call(env_2);
109
+ else {
110
+ command += `\${env:${quotedKey}}=${shell_quoting_1.PowershellQuotingFunctions.strong(value)}; `;
173
111
  }
174
- finally { if (e_3) throw e_3.error; }
175
112
  }
176
113
  }
177
114
  command += '& ' + shell_quoting_1.createShellCommandLine(args, shell_quoting_1.PowershellQuotingFunctions);
178
115
  return command;
179
- };
180
- ShellCommandBuilder.prototype.buildForCmd = function (args, cwd, env) {
181
- var e_4, _a;
182
- var command = '';
116
+ }
117
+ buildForCmd(args, cwd, env) {
118
+ let command = '';
183
119
  if (cwd) {
184
- command += "cd " + shell_quoting_1.CmdQuotingFunctions.strong(cwd) + " && ";
120
+ command += `cd ${shell_quoting_1.CmdQuotingFunctions.strong(cwd)} && `;
185
121
  }
186
122
  if (env) {
187
123
  command += 'cmd /C "';
188
- try {
189
- for (var env_3 = __values(env), env_3_1 = env_3.next(); !env_3_1.done; env_3_1 = env_3.next()) {
190
- var _b = __read(env_3_1.value, 2), key = _b[0], value = _b[1];
191
- // eslint-disable-next-line no-null/no-null
192
- if (value === null) {
193
- command += "set " + shell_quoting_1.CmdQuotingFunctions.strong(key) + "=\"\" && ";
194
- }
195
- else {
196
- command += "set " + shell_quoting_1.CmdQuotingFunctions.strong(key + "=" + value) + " && ";
197
- }
124
+ for (const [key, value] of env) {
125
+ // eslint-disable-next-line no-null/no-null
126
+ if (value === null) {
127
+ command += `set ${shell_quoting_1.CmdQuotingFunctions.strong(key)}="" && `;
198
128
  }
199
- }
200
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
201
- finally {
202
- try {
203
- if (env_3_1 && !env_3_1.done && (_a = env_3.return)) _a.call(env_3);
129
+ else {
130
+ command += `set ${shell_quoting_1.CmdQuotingFunctions.strong(`${key}=${value}`)} && `;
204
131
  }
205
- finally { if (e_4) throw e_4.error; }
206
132
  }
207
133
  }
208
134
  command += shell_quoting_1.createShellCommandLine(args, shell_quoting_1.CmdQuotingFunctions);
@@ -210,14 +136,13 @@ var ShellCommandBuilder = /** @class */ (function () {
210
136
  command += '"';
211
137
  }
212
138
  return command;
213
- };
214
- ShellCommandBuilder.prototype.buildForDefault = function (args, cwd, env) {
139
+ }
140
+ buildForDefault(args, cwd, env) {
215
141
  return this.buildForBash(args, cwd, env);
216
- };
217
- ShellCommandBuilder = __decorate([
218
- inversify_1.injectable()
219
- ], ShellCommandBuilder);
220
- return ShellCommandBuilder;
221
- }());
142
+ }
143
+ };
144
+ ShellCommandBuilder = __decorate([
145
+ inversify_1.injectable()
146
+ ], ShellCommandBuilder);
222
147
  exports.ShellCommandBuilder = ShellCommandBuilder;
223
148
  //# sourceMappingURL=shell-command-builder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell-command-builder.js","sourceRoot":"","sources":["../../src/common/shell-command-builder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElF;;;gGAGgG;AAEhG,0DAA0D;AAC1D,yDAAyK;AAezK;;GAEG;AAEH;IAAA;IAiHA,CAAC;IA/GG;;;;;;;;;;;OAWG;IACH,0CAAY,GAAZ,UAAa,eAAwC,EAAE,cAAkC;;QAErF,IAAM,IAAI,GAAG,eAAe,IAAI,eAAe,CAAC,UAAU,CAAC;QAC3D,IAAM,GAAG,G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,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;CAEJ,CAAA;AAjHY,mBAAmB;IAD/B,sBAAU,EAAE;GACA,mBAAmB,CAiH/B;AAjHY,kDAAmB"}
@@ -14,124 +14,48 @@
14
14
  *
15
15
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
16
  ********************************************************************************/
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- 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;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- var __read = (this && this.__read) || function (o, n) {
54
- var m = typeof Symbol === "function" && o[Symbol.iterator];
55
- if (!m) return o;
56
- var i = m.call(o), r, ar = [], e;
57
- try {
58
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
- }
60
- catch (error) { e = { error: error }; }
61
- finally {
62
- try {
63
- if (r && !r.done && (m = i["return"])) m.call(i);
64
- }
65
- finally { if (e) throw e.error; }
66
- }
67
- return ar;
68
- };
69
- var __spread = (this && this.__spread) || function () {
70
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
71
- return ar;
72
- };
73
- var __values = (this && this.__values) || function(o) {
74
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
75
- if (m) return m.call(o);
76
- if (o && typeof o.length === "number") return {
77
- next: function () {
78
- if (o && i >= o.length) o = void 0;
79
- return { value: o && o[i++], done: !o };
80
- }
81
- };
82
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
83
- };
84
- var e_1, _a;
85
17
  Object.defineProperty(exports, "__esModule", { value: true });
86
18
  /**
87
19
  * This test suite assumes that we run in a NodeJS environment!
88
20
  */
89
- var child_process_1 = require("child_process");
90
- var path_1 = require("path");
91
- var shell_command_builder_1 = require("./shell-command-builder");
92
- var safe_1 = require("colors/safe"); // tslint:disable-line:no-implicit-dependencies
93
- var isWindows = process.platform === 'win32';
21
+ const child_process_1 = require("child_process");
22
+ const path_1 = require("path");
23
+ const shell_command_builder_1 = require("./shell-command-builder");
24
+ const safe_1 = require("colors/safe"); // tslint:disable-line:no-implicit-dependencies
25
+ const isWindows = process.platform === 'win32';
94
26
  /**
95
27
  * Extra debugging info (very verbose).
96
28
  */
97
- var _debug = Boolean(process.env['THEIA_PROCESS_TEST_DEBUG']);
29
+ const _debug = Boolean(process.env['THEIA_PROCESS_TEST_DEBUG']);
98
30
  /**
99
31
  * On Windows, some shells simply mess up the terminal's output.
100
32
  * Enable if you still want to test those.
101
33
  */
102
- var _runWeirdShell = Boolean(process.env['THEIA_PROCESS_TEST_WEIRD_SHELL']) || undefined;
34
+ const _runWeirdShell = Boolean(process.env['THEIA_PROCESS_TEST_WEIRD_SHELL']) || undefined;
103
35
  /**
104
36
  * You might only have issues with a specific shell (`cmd.exe` I am looking at you).
105
37
  */
106
- var _onlyTestShell = process.env['THEIA_PROCESS_TEST_ONLY'] || undefined;
38
+ const _onlyTestShell = process.env['THEIA_PROCESS_TEST_ONLY'] || undefined;
107
39
  /**
108
40
  * Only log if environment variable is set.
109
41
  */
110
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
- function debug() {
112
- var parts = [];
113
- for (var _i = 0; _i < arguments.length; _i++) {
114
- parts[_i] = arguments[_i];
115
- }
43
+ function debug(...parts) {
116
44
  if (_debug) {
117
- console.debug.apply(console, __spread(parts));
45
+ console.debug(...parts);
118
46
  }
119
47
  }
120
- var testResources = path_1.join(__dirname, '../../src/common/tests');
121
- var spawnOptions = {
48
+ const testResources = path_1.join(__dirname, '../../src/common/tests');
49
+ const spawnOptions = {
122
50
  // We do our own quoting, don't rely on the one done by NodeJS:
123
51
  windowsVerbatimArguments: true,
124
52
  stdio: ['pipe', 'pipe', 'pipe'],
125
53
  };
126
54
  // Formatting options, used with `scanLines` for debugging.
127
- var stdoutFormat = function (prefix) { return function (data) {
128
- return safe_1.bold(safe_1.yellow(prefix + " STDOUT:")) + " " + safe_1.bgYellow(safe_1.black(data));
129
- }; };
130
- var stderrFormat = function (prefix) { return function (data) {
131
- return safe_1.bold(safe_1.red(prefix + " STDERR:")) + " " + safe_1.bgRed(safe_1.white(data));
132
- }; };
55
+ const stdoutFormat = (prefix) => (data) => `${safe_1.bold(safe_1.yellow(`${prefix} STDOUT:`))} ${safe_1.bgYellow(safe_1.black(data))}`;
56
+ const stderrFormat = (prefix) => (data) => `${safe_1.bold(safe_1.red(`${prefix} STDERR:`))} ${safe_1.bgRed(safe_1.white(data))}`;
133
57
  // Default error scanner
134
- var errorScanner = function (handle) {
58
+ const errorScanner = (handle) => {
135
59
  if (/^\s*\w+Error:/.test(handle.line) ||
136
60
  /^\s*Cannot find /.test(handle.line)) {
137
61
  throw new Error(handle.text);
@@ -139,13 +63,13 @@ var errorScanner = function (handle) {
139
63
  };
140
64
  // Yarn mangles the PATH and creates some proxy script around node(.exe),
141
65
  // which messes up our environment, failing the tests.
142
- var hostNodePath = process.env['npm_node_execpath'] ||
66
+ const hostNodePath = process.env['npm_node_execpath'] ||
143
67
  process.env['NODE'];
144
68
  if (!hostNodePath) {
145
69
  throw new Error('Could not determine the real node path.');
146
70
  }
147
- var shellCommandBuilder = new shell_command_builder_1.ShellCommandBuilder();
148
- var shellConfigs = [{
71
+ const shellCommandBuilder = new shell_command_builder_1.ShellCommandBuilder();
72
+ const shellConfigs = [{
149
73
  name: 'bash',
150
74
  path: isWindows
151
75
  ? _runWeirdShell && execShellCommand('where bash.exe')
@@ -198,11 +122,11 @@ var shellConfigs = [{
198
122
  // at Microsoft.PowerShell.ConsoleShell.Start(String bannerText, String helpText, String[] args)
199
123
  // at Microsoft.PowerShell.UnmanagedPSEntry.Start(String consoleFilePath, String[] args, Int32 argc)
200
124
  /* eslint-enable max-len */
201
- var id = 0;
202
- var _loop_1 = function (shellConfig) {
203
- var skipMessage;
125
+ let id = 0;
126
+ for (const shellConfig of shellConfigs) {
127
+ let skipMessage;
204
128
  if (typeof _onlyTestShell === 'string' && shellConfig.name !== _onlyTestShell) {
205
- skipMessage = "only testing " + _onlyTestShell;
129
+ skipMessage = `only testing ${_onlyTestShell}`;
206
130
  }
207
131
  else if (!shellConfig.path) {
208
132
  // For each shell, skip if we could not find the executable path.
@@ -212,8 +136,8 @@ var _loop_1 = function (shellConfig) {
212
136
  // Run a test in the shell to catch runtime issues.
213
137
  // CI seems to have issues with some shells depending on the environment...
214
138
  try {
215
- var debugName = shellConfig.name + "/test";
216
- var shellTest = child_process_1.spawnSync(shellConfig.path, {
139
+ const debugName = `${shellConfig.name}/test`;
140
+ const shellTest = child_process_1.spawnSync(shellConfig.path, {
217
141
  input: 'echo abcdefghijkl\n\n',
218
142
  timeout: 5000,
219
143
  });
@@ -231,24 +155,23 @@ var _loop_1 = function (shellConfig) {
231
155
  /**
232
156
  * If skipMessage is set, we should skip the test and explain why.
233
157
  */
234
- var describeOrSkip = function (callback) {
235
- var describeMessage = "test " + shellConfig.name + " commands";
158
+ const describeOrSkip = (callback) => {
159
+ const describeMessage = `test ${shellConfig.name} commands`;
236
160
  if (typeof skipMessage === 'undefined') {
237
161
  describe(describeMessage, callback);
238
162
  }
239
163
  else {
240
- describe.skip(describeMessage + " - skip: " + skipMessage, callback);
164
+ describe.skip(`${describeMessage} - skip: ${skipMessage}`, callback);
241
165
  }
242
166
  };
243
167
  describeOrSkip(function () {
244
- var _this = this;
245
168
  this.timeout(10000);
246
- var nodePath;
247
- var cwd;
248
- var submit;
249
- var processInfo;
250
- var context;
251
- beforeEach(function () {
169
+ let nodePath;
170
+ let cwd;
171
+ let submit;
172
+ let processInfo;
173
+ let context;
174
+ beforeEach(() => {
252
175
  // In WSL, the node path is different than the host one (Windows vs Linux).
253
176
  nodePath = shellConfig.nodePath || hostNodePath;
254
177
  // On windows, when running bash we need to convert paths from Windows
@@ -264,117 +187,79 @@ var _loop_1 = function (shellConfig) {
264
187
  submit = '\n\n';
265
188
  }
266
189
  // TestContext holds all state for a given test.
267
- var testContextName = shellConfig.name + "/" + ++id;
190
+ const testContextName = `${shellConfig.name}/${++id}`;
268
191
  context = new TestCaseContext(testContextName, submit);
269
192
  processInfo = createShell(context, shellConfig.path);
270
193
  });
271
- afterEach(function () {
194
+ afterEach(() => {
272
195
  processInfo.shell.kill();
273
196
  context.finalize();
274
197
  });
275
- it('use simple environment variables', function () { return __awaiter(_this, void 0, void 0, function () {
276
- var envName, envValue;
277
- var _a;
278
- return __generator(this, function (_b) {
279
- switch (_b.label) {
280
- case 0:
281
- envName = 'SIMPLE_NAME';
282
- envValue = 'SIMPLE_VALUE';
283
- return [4 /*yield*/, testCommandLine(context, processInfo, {
284
- cwd: cwd, args: [nodePath, '-p', "`[${process.env['" + envName + "']}]`"],
285
- env: (_a = {},
286
- _a[envName] = envValue,
287
- _a)
288
- }, [
289
- // stderr
290
- scanLines(context, processInfo.shell.stderr, errorScanner, stderrFormat(context.name)),
291
- // stdout
292
- scanLines(context, processInfo.shell.stdout, function (handle) {
293
- errorScanner(handle);
294
- if (handle.line.includes("[" + envValue + "]")) {
295
- handle.resolve();
296
- }
297
- }, stdoutFormat(context.name)),
298
- ])];
299
- case 1:
300
- _b.sent();
301
- return [2 /*return*/];
198
+ it('use simple environment variables', async () => {
199
+ const envName = 'SIMPLE_NAME';
200
+ const envValue = 'SIMPLE_VALUE';
201
+ await testCommandLine(context, processInfo, {
202
+ cwd, args: [nodePath, '-p', `\`[\${process.env['${envName}']}]\``],
203
+ env: {
204
+ [envName]: envValue,
302
205
  }
303
- });
304
- }); });
305
- it('use problematic environment variables', function () { return __awaiter(_this, void 0, void 0, function () {
306
- var envName, envValue;
307
- var _a;
308
- return __generator(this, function (_b) {
309
- switch (_b.label) {
310
- case 0:
311
- envName = 'A?B_C | D $PATH';
312
- envValue = 'SUCCESS';
313
- return [4 /*yield*/, testCommandLine(context, processInfo, {
314
- cwd: cwd, args: [nodePath, '-p', "`[${process.env['" + envName + "']}]`"],
315
- env: (_a = {},
316
- _a[envName] = envValue,
317
- _a)
318
- }, [
319
- // stderr
320
- scanLines(context, processInfo.shell.stderr, errorScanner, stderrFormat(context.name)),
321
- // stdout
322
- scanLines(context, processInfo.shell.stdout, function (handle) {
323
- errorScanner(handle);
324
- if (handle.line.includes("[" + envValue + "]")) {
325
- handle.resolve();
326
- }
327
- if (handle.line.includes('[undefined]')) {
328
- handle.reject(new Error(handle.text));
329
- }
330
- }, stdoutFormat(context.name)),
331
- ])];
332
- case 1:
333
- _b.sent();
334
- return [2 /*return*/];
335
- }
336
- });
337
- }); });
338
- it('command with complex arguments', function () { return __awaiter(_this, void 0, void 0, function () {
339
- var left, right;
340
- return __generator(this, function (_a) {
341
- switch (_a.label) {
342
- case 0:
343
- left = 'ABC';
344
- right = 'DEF';
345
- return [4 /*yield*/, testCommandLine(context, processInfo, {
346
- cwd: cwd, args: [nodePath, '-e', "{\n const left = '" + left + "';\n const right = '" + right + "';\n console.log(`[${left}|${right}]`);\n }"],
347
- }, [
348
- // stderr
349
- scanLines(context, processInfo.shell.stderr, errorScanner, stderrFormat(context.name)),
350
- // stdout
351
- scanLines(context, processInfo.shell.stdout, function (handle) {
352
- errorScanner(handle);
353
- if (handle.line.includes("[" + left + "|" + right + "]")) {
354
- handle.resolve();
355
- }
356
- }, stdoutFormat(context.name)),
357
- ])];
358
- case 1:
359
- _a.sent();
360
- return [2 /*return*/];
206
+ }, [
207
+ // stderr
208
+ scanLines(context, processInfo.shell.stderr, errorScanner, stderrFormat(context.name)),
209
+ // stdout
210
+ scanLines(context, processInfo.shell.stdout, handle => {
211
+ errorScanner(handle);
212
+ if (handle.line.includes(`[${envValue}]`)) {
213
+ handle.resolve();
214
+ }
215
+ }, stdoutFormat(context.name)),
216
+ ]);
217
+ });
218
+ it('use problematic environment variables', async () => {
219
+ const envName = 'A?B_C | D $PATH';
220
+ const envValue = 'SUCCESS';
221
+ await testCommandLine(context, processInfo, {
222
+ cwd, args: [nodePath, '-p', `\`[\${process.env['${envName}']}]\``],
223
+ env: {
224
+ [envName]: envValue,
361
225
  }
362
- });
363
- }); });
226
+ }, [
227
+ // stderr
228
+ scanLines(context, processInfo.shell.stderr, errorScanner, stderrFormat(context.name)),
229
+ // stdout
230
+ scanLines(context, processInfo.shell.stdout, handle => {
231
+ errorScanner(handle);
232
+ if (handle.line.includes(`[${envValue}]`)) {
233
+ handle.resolve();
234
+ }
235
+ if (handle.line.includes('[undefined]')) {
236
+ handle.reject(new Error(handle.text));
237
+ }
238
+ }, stdoutFormat(context.name)),
239
+ ]);
240
+ });
241
+ it('command with complex arguments', async () => {
242
+ const left = 'ABC';
243
+ const right = 'DEF';
244
+ await testCommandLine(context, processInfo, {
245
+ cwd, args: [nodePath, '-e', `{
246
+ const left = '${left}';
247
+ const right = '${right}';
248
+ console.log(\`[\${left}|\${right}]\`);
249
+ }`],
250
+ }, [
251
+ // stderr
252
+ scanLines(context, processInfo.shell.stderr, errorScanner, stderrFormat(context.name)),
253
+ // stdout
254
+ scanLines(context, processInfo.shell.stdout, handle => {
255
+ errorScanner(handle);
256
+ if (handle.line.includes(`[${left}|${right}]`)) {
257
+ handle.resolve();
258
+ }
259
+ }, stdoutFormat(context.name)),
260
+ ]);
261
+ });
364
262
  });
365
- };
366
- try {
367
- for (var shellConfigs_1 = __values(shellConfigs), shellConfigs_1_1 = shellConfigs_1.next(); !shellConfigs_1_1.done; shellConfigs_1_1 = shellConfigs_1.next()) {
368
- var shellConfig = shellConfigs_1_1.value;
369
- _loop_1(shellConfig);
370
- }
371
- }
372
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
373
- finally {
374
- try {
375
- if (shellConfigs_1_1 && !shellConfigs_1_1.done && (_a = shellConfigs_1.return)) _a.call(shellConfigs_1);
376
- }
377
- finally { if (e_1) throw e_1.error; }
378
263
  }
379
264
  /**
380
265
  * Allow `command` to fail and return undefined instead.
@@ -397,100 +282,89 @@ function convertWindowsPath(windowsPath) {
397
282
  // Convert back-slashes to forward-slashes
398
283
  .replace(/\\/g, '/')
399
284
  // Convert drive-letter to usual mounting point in WSL
400
- .replace(/^[A-Za-z]:\//, function (s) { return "/mnt/" + s[0].toLowerCase() + "/"; });
285
+ .replace(/^[A-Za-z]:\//, s => `/mnt/${s[0].toLowerCase()}/`);
401
286
  }
402
287
  /**
403
288
  * Display trailing whitespace in a string, such as \r and \n.
404
289
  */
405
290
  function displayWhitespaces(line) {
406
291
  return line
407
- .replace(/\r?\n/, function (s) { return s.length === 2 ? '<\\r\\n>\r\n' : '<\\n>\n'; });
292
+ .replace(/\r?\n/, s => s.length === 2 ? '<\\r\\n>\r\n' : '<\\n>\n');
408
293
  }
409
294
  /**
410
295
  * Actually run `prepareCommandLine`.
411
296
  */
412
- function testCommandLine(context, processInfo, options,
297
+ async function testCommandLine(context, processInfo, options,
413
298
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
414
299
  firstOf) {
415
- return __awaiter(this, void 0, void 0, function () {
416
- var commandLine;
417
- return __generator(this, function (_a) {
418
- commandLine = shellCommandBuilder.buildCommand(processInfo, options);
419
- debug(safe_1.bold(safe_1.white(context.name + " STDIN:")) + " " + safe_1.bgWhite(safe_1.black(displayWhitespaces(commandLine))));
420
- processInfo.shell.stdin.write(commandLine + context.submit);
421
- return [2 /*return*/, Promise.race(firstOf)];
422
- });
423
- });
300
+ const commandLine = shellCommandBuilder.buildCommand(processInfo, options);
301
+ debug(`${safe_1.bold(safe_1.white(`${context.name} STDIN:`))} ${safe_1.bgWhite(safe_1.black(displayWhitespaces(commandLine)))}`);
302
+ processInfo.shell.stdin.write(commandLine + context.submit);
303
+ return Promise.race(firstOf);
424
304
  }
425
305
  /**
426
306
  * Creates a `(Test)ProcessInfo` object by spawning the specified shell.
427
307
  */
428
- function createShell(context, shellExecutable, shellArguments) {
429
- if (shellArguments === void 0) { shellArguments = []; }
430
- var shell = child_process_1.spawn(shellExecutable, shellArguments, spawnOptions);
431
- debug(safe_1.magenta(safe_1.bold(context.name + " SPAWN:") + " " + shellExecutable + " " + shellArguments.join(' ')));
432
- shell.on('close', function (code, signal) { return debug(safe_1.magenta(safe_1.bold(context.name + " CLOSE:") + " " + shellExecutable + " code(" + code + ") signal(" + signal + ")")); });
308
+ function createShell(context, shellExecutable, shellArguments = []) {
309
+ const shell = child_process_1.spawn(shellExecutable, shellArguments, spawnOptions);
310
+ debug(safe_1.magenta(`${safe_1.bold(`${context.name} SPAWN:`)} ${shellExecutable} ${shellArguments.join(' ')}`));
311
+ shell.on('close', (code, signal) => debug(safe_1.magenta(`${safe_1.bold(`${context.name} CLOSE:`)} ${shellExecutable} code(${code}) signal(${signal})`)));
433
312
  return {
434
313
  executable: shellExecutable,
435
314
  arguments: [],
436
- shell: shell,
315
+ shell,
437
316
  };
438
317
  }
439
318
  /**
440
319
  * Fire `callback` once per new detected line.
441
320
  */
442
- function scanLines(context, stream, callback, debugFormat) {
443
- if (debugFormat === void 0) { debugFormat = function (s) { return s; }; }
444
- return __awaiter(this, void 0, void 0, function () {
445
- return __generator(this, function (_a) {
446
- return [2 /*return*/, new Promise(function (resolve, reject) {
447
- var line = '';
448
- var text = '';
449
- stream.on('close', function () {
450
- debug(debugFormat('<CLOSED>'));
451
- });
452
- // The `data` listener will be collected on 'close', which will happen
453
- // once we kill the process.
454
- stream.on('data', function (data) {
455
- if (context.resolved) {
456
- return;
457
- }
458
- var split = data.toString().split('\n');
459
- while (!context.resolved && split.length > 1) {
460
- line += split.shift() + '\n';
461
- text += line;
462
- debug(debugFormat(displayWhitespaces(line)));
463
- try {
464
- callback({
465
- resolve: function (value) {
466
- if (!context.resolved) {
467
- context.resolve();
468
- resolve(value);
469
- debug(safe_1.bold(safe_1.green(context.name + " SCANLINES RESOLVED")));
470
- }
471
- },
472
- reject: function (reason) {
473
- if (!context.resolved) {
474
- context.resolve();
475
- reject(reason);
476
- debug(safe_1.bold(safe_1.red(context.name + " SCANLINES REJECTED")));
477
- }
478
- },
479
- line: line,
480
- text: text,
481
- });
321
+ async function scanLines(context, stream, callback, debugFormat = (s) => s) {
322
+ return new Promise((resolve, reject) => {
323
+ let line = '';
324
+ let text = '';
325
+ stream.on('close', () => {
326
+ debug(debugFormat('<CLOSED>'));
327
+ });
328
+ // The `data` listener will be collected on 'close', which will happen
329
+ // once we kill the process.
330
+ stream.on('data', data => {
331
+ if (context.resolved) {
332
+ return;
333
+ }
334
+ const split = data.toString().split('\n');
335
+ while (!context.resolved && split.length > 1) {
336
+ line += split.shift() + '\n';
337
+ text += line;
338
+ debug(debugFormat(displayWhitespaces(line)));
339
+ try {
340
+ callback({
341
+ resolve: (value) => {
342
+ if (!context.resolved) {
343
+ context.resolve();
344
+ resolve(value);
345
+ debug(safe_1.bold(safe_1.green(`${context.name} SCANLINES RESOLVED`)));
482
346
  }
483
- catch (error) {
484
- debug(safe_1.bold(safe_1.red(context.name + " SCANLINES THROWED")));
347
+ },
348
+ reject: (reason) => {
349
+ if (!context.resolved) {
485
350
  context.resolve();
486
- reject(error);
487
- break;
351
+ reject(reason);
352
+ debug(safe_1.bold(safe_1.red(`${context.name} SCANLINES REJECTED`)));
488
353
  }
489
- line = '';
490
- }
491
- line += split[0];
354
+ },
355
+ line,
356
+ text,
492
357
  });
493
- })];
358
+ }
359
+ catch (error) {
360
+ debug(safe_1.bold(safe_1.red(`${context.name} SCANLINES THROWED`)));
361
+ context.resolve();
362
+ reject(error);
363
+ break;
364
+ }
365
+ line = '';
366
+ }
367
+ line += split[0];
494
368
  });
495
369
  });
496
370
  }
@@ -499,8 +373,8 @@ function scanLines(context, stream, callback, debugFormat) {
499
373
  * and synchronize multiple listeners so that when one resolves the test case,
500
374
  * the others can be put in "sleep mode" until destruction.
501
375
  */
502
- var TestCaseContext = /** @class */ (function () {
503
- function TestCaseContext(
376
+ class TestCaseContext {
377
+ constructor(
504
378
  /**
505
379
  * A name associated with this context, to help with debugging.
506
380
  */
@@ -509,26 +383,23 @@ var TestCaseContext = /** @class */ (function () {
509
383
  * The characters to send in order to submit a command (mostly
510
384
  * powershell is causing issues).
511
385
  */
512
- submit,
386
+ submit = '\n',
513
387
  /**
514
388
  * @internal Current state of the test case, if it is finished or not.
515
389
  */
516
- resolved) {
517
- if (submit === void 0) { submit = '\n'; }
518
- if (resolved === void 0) { resolved = false; }
390
+ resolved = false) {
519
391
  this.name = name;
520
392
  this.submit = submit;
521
393
  this.resolved = resolved;
522
394
  }
523
- TestCaseContext.prototype.resolve = function () {
395
+ resolve() {
524
396
  this.resolved = true;
525
- };
526
- TestCaseContext.prototype.finalize = function () {
397
+ }
398
+ finalize() {
527
399
  if (!this.resolved) {
528
400
  this.resolve();
529
- debug(safe_1.red(safe_1.bold(this.name + " CONTEXT:") + " context wasn't resolved when finalizing, resolving!"));
401
+ debug(safe_1.red(`${safe_1.bold(`${this.name} CONTEXT:`)} context wasn't resolved when finalizing, resolving!`));
530
402
  }
531
- };
532
- return TestCaseContext;
533
- }());
403
+ }
404
+ }
534
405
  //# sourceMappingURL=shell-command-builder.slow-spec.js.map