@theia/process 1.34.3 → 1.34.4

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 (70) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +30 -30
  3. package/lib/common/process-common-module.d.ts +3 -3
  4. package/lib/common/process-common-module.js +22 -22
  5. package/lib/common/process-manager-types.d.ts +35 -35
  6. package/lib/common/process-manager-types.js +23 -23
  7. package/lib/common/shell-command-builder.d.ts +49 -49
  8. package/lib/common/shell-command-builder.js +174 -174
  9. package/lib/common/shell-command-builder.slow-spec.d.ts +9 -9
  10. package/lib/common/shell-command-builder.slow-spec.js +404 -404
  11. package/lib/common/shell-quoting.d.ts +91 -91
  12. package/lib/common/shell-quoting.js +145 -145
  13. package/lib/common/shell-quoting.spec.d.ts +1 -1
  14. package/lib/common/shell-quoting.spec.js +170 -170
  15. package/lib/node/dev-null-stream.d.ts +17 -17
  16. package/lib/node/dev-null-stream.js +41 -41
  17. package/lib/node/index.d.ts +6 -6
  18. package/lib/node/index.js +33 -33
  19. package/lib/node/multi-ring-buffer.d.ts +68 -68
  20. package/lib/node/multi-ring-buffer.js +310 -310
  21. package/lib/node/multi-ring-buffer.spec.d.ts +1 -1
  22. package/lib/node/multi-ring-buffer.spec.js +422 -422
  23. package/lib/node/process-backend-module.d.ts +3 -3
  24. package/lib/node/process-backend-module.js +56 -56
  25. package/lib/node/process-manager.d.ts +33 -33
  26. package/lib/node/process-manager.js +113 -113
  27. package/lib/node/process.d.ts +95 -95
  28. package/lib/node/process.js +153 -153
  29. package/lib/node/pseudo-pty.d.ts +22 -22
  30. package/lib/node/pseudo-pty.js +38 -38
  31. package/lib/node/raw-process.d.ts +45 -45
  32. package/lib/node/raw-process.js +115 -115
  33. package/lib/node/raw-process.spec.d.ts +1 -1
  34. package/lib/node/raw-process.spec.js +164 -164
  35. package/lib/node/task-terminal-process.d.ts +10 -10
  36. package/lib/node/task-terminal-process.js +47 -47
  37. package/lib/node/terminal-process.d.ts +49 -49
  38. package/lib/node/terminal-process.js +180 -180
  39. package/lib/node/terminal-process.spec.d.ts +1 -1
  40. package/lib/node/terminal-process.spec.js +89 -89
  41. package/lib/node/test/process-test-container.d.ts +2 -2
  42. package/lib/node/test/process-test-container.js +28 -28
  43. package/lib/node/utils.d.ts +16 -16
  44. package/lib/node/utils.js +77 -77
  45. package/package.json +4 -4
  46. package/src/common/process-common-module.ts +22 -22
  47. package/src/common/process-manager-types.ts +58 -58
  48. package/src/common/shell-command-builder.slow-spec.ts +486 -486
  49. package/src/common/shell-command-builder.ts +187 -187
  50. package/src/common/shell-quoting.spec.ts +176 -176
  51. package/src/common/shell-quoting.ts +236 -236
  52. package/src/common/tests/$weird(),file=name.js +1 -1
  53. package/src/common/tests/white space.js +1 -1
  54. package/src/node/dev-null-stream.ts +47 -47
  55. package/src/node/index.ts +22 -22
  56. package/src/node/multi-ring-buffer.spec.ts +486 -486
  57. package/src/node/multi-ring-buffer.ts +348 -348
  58. package/src/node/process-backend-module.ts +67 -67
  59. package/src/node/process-manager.ts +107 -107
  60. package/src/node/process.ts +207 -207
  61. package/src/node/pseudo-pty.ts +54 -54
  62. package/src/node/raw-process.spec.ts +199 -199
  63. package/src/node/raw-process.ts +156 -156
  64. package/src/node/string-argv.d.ts +21 -21
  65. package/src/node/task-terminal-process.ts +41 -41
  66. package/src/node/terminal-process.spec.ts +104 -104
  67. package/src/node/terminal-process.ts +198 -198
  68. package/src/node/test/process-fork-test.js +22 -22
  69. package/src/node/test/process-test-container.ts +27 -27
  70. package/src/node/utils.ts +79 -79
@@ -1,175 +1,175 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2020 Ericsson and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.ShellCommandBuilder = void 0;
25
- /*---------------------------------------------------------------------------------------------
26
- * Copyright (c) Microsoft Corporation. All rights reserved.
27
- * Licensed under the MIT License. See License.txt in the project root for license information.
28
- *--------------------------------------------------------------------------------------------*/
29
- /* eslint-disable no-null/no-null */
30
- const inversify_1 = require("@theia/core/shared/inversify");
31
- const shell_quoting_1 = require("../common/shell-quoting");
32
- /**
33
- * Create command lines ready to be sent to a shell's stdin for evaluation.
34
- */
35
- let ShellCommandBuilder = class ShellCommandBuilder {
36
- /**
37
- * Constructs a command line to run in a shell. The shell could be
38
- * re-used/long-lived, this means we cannot spawn a new process with a nice
39
- * and fresh environment, we need to encode environment modifications into
40
- * the returned command.
41
- *
42
- * Inspired by VS Code implementation, see:
43
- * https://github.com/microsoft/vscode/blob/f395cac4fff0721a8099126172c01411812bcb4a/src/vs/workbench/contrib/debug/node/terminals.ts#L79
44
- *
45
- * @param hostProcessInfo the host terminal process infos
46
- * @param commandOptions program to execute in the host terminal
47
- */
48
- buildCommand(hostProcessInfo, commandOptions) {
49
- const host = hostProcessInfo && hostProcessInfo.executable;
50
- const cwd = commandOptions.cwd;
51
- const args = commandOptions.args.map(value => ({
52
- value, quoting: "strong" /* Strong */,
53
- }));
54
- const env = [];
55
- if (commandOptions.env) {
56
- for (const key of Object.keys(commandOptions.env)) {
57
- env.push([key, commandOptions.env[key]]);
58
- }
59
- }
60
- if (host) {
61
- if (/(bash|wsl)(.exe)?$/.test(host)) {
62
- return this.buildForBash(args, cwd, env);
63
- }
64
- else if (/(ps|pwsh|powershell)(.exe)?$/i.test(host)) {
65
- return this.buildForPowershell(args, cwd, env);
66
- }
67
- else if (/cmd(.exe)?$/i.test(host)) {
68
- return this.buildForCmd(args, cwd, env);
69
- }
70
- }
71
- return this.buildForDefault(args, cwd, env);
72
- }
73
- buildForBash(args, cwd, env) {
74
- let command = '';
75
- if (cwd) {
76
- command += `cd ${shell_quoting_1.BashQuotingFunctions.strong(cwd)} && `;
77
- }
78
- if (env === null || env === void 0 ? void 0 : env.length) {
79
- command += 'env';
80
- for (const [key, value] of env) {
81
- if (value === null) {
82
- command += ` -u ${shell_quoting_1.BashQuotingFunctions.strong(key)}`;
83
- }
84
- else {
85
- command += ` ${shell_quoting_1.BashQuotingFunctions.strong(`${key}=${value}`)}`;
86
- }
87
- }
88
- command += ' ';
89
- }
90
- command += this.createShellCommandLine(args, shell_quoting_1.BashQuotingFunctions);
91
- return command;
92
- }
93
- buildForPowershell(args, cwd, env) {
94
- let command = '';
95
- if (cwd) {
96
- command += `cd ${shell_quoting_1.PowershellQuotingFunctions.strong(cwd)}; `;
97
- }
98
- if (env === null || env === void 0 ? void 0 : env.length) {
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
- if (value === null) {
106
- command += `Remove-Item \${env:${quotedKey}}; `;
107
- }
108
- else {
109
- command += `\${env:${quotedKey}}=${shell_quoting_1.PowershellQuotingFunctions.strong(value)}; `;
110
- }
111
- }
112
- }
113
- command += '& ' + this.createShellCommandLine(args, shell_quoting_1.PowershellQuotingFunctions);
114
- return command;
115
- }
116
- buildForCmd(args, cwd, env) {
117
- let command = '';
118
- if (cwd) {
119
- command += `cd ${shell_quoting_1.CmdQuotingFunctions.strong(cwd)} && `;
120
- }
121
- // Current quoting mechanism only works within a nested `cmd` call:
122
- command += 'cmd /C "';
123
- if (env === null || env === void 0 ? void 0 : env.length) {
124
- for (const [key, value] of env) {
125
- if (value === null) {
126
- command += `set ${shell_quoting_1.CmdQuotingFunctions.strong(key)}="" && `;
127
- }
128
- else {
129
- command += `set ${shell_quoting_1.CmdQuotingFunctions.strong(`${key}=${value}`)} && `;
130
- }
131
- }
132
- }
133
- command += this.createShellCommandLine(args, shell_quoting_1.CmdQuotingFunctions);
134
- command += '"';
135
- return command;
136
- }
137
- buildForDefault(args, cwd, env) {
138
- return this.buildForBash(args, cwd, env);
139
- }
140
- /**
141
- * This method will try to leave `arg[0]` unescaped if possible. The reason
142
- * is that shells like `cmd` expect their own commands like `dir` to be
143
- * unescaped.
144
- *
145
- * @returns empty string if `args` is empty, otherwise an escaped command.
146
- */
147
- createShellCommandLine(args, quotingFunctions) {
148
- let command = '';
149
- if (args.length > 0) {
150
- const [exec, ...execArgs] = args;
151
- // Some commands like `dir` should not be quoted for `cmd` to understand:
152
- command += this.quoteExecutableIfNecessary(exec, quotingFunctions);
153
- if (execArgs.length > 0) {
154
- command += ' ' + (0, shell_quoting_1.createShellCommandLine)(execArgs, quotingFunctions);
155
- }
156
- }
157
- return command;
158
- }
159
- quoteExecutableIfNecessary(exec, quotingFunctions) {
160
- return typeof exec === 'string' && !this.needsQuoting(exec) ? exec : (0, shell_quoting_1.escapeForShell)(exec, quotingFunctions);
161
- }
162
- /**
163
- * If this method returns `false` then we definitely need quoting.
164
- *
165
- * May return false positives.
166
- */
167
- needsQuoting(arg) {
168
- return /\W/.test(arg);
169
- }
170
- };
171
- ShellCommandBuilder = __decorate([
172
- (0, inversify_1.injectable)()
173
- ], ShellCommandBuilder);
174
- exports.ShellCommandBuilder = ShellCommandBuilder;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2020 Ericsson and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ShellCommandBuilder = void 0;
25
+ /*---------------------------------------------------------------------------------------------
26
+ * Copyright (c) Microsoft Corporation. All rights reserved.
27
+ * Licensed under the MIT License. See License.txt in the project root for license information.
28
+ *--------------------------------------------------------------------------------------------*/
29
+ /* eslint-disable no-null/no-null */
30
+ const inversify_1 = require("@theia/core/shared/inversify");
31
+ const shell_quoting_1 = require("../common/shell-quoting");
32
+ /**
33
+ * Create command lines ready to be sent to a shell's stdin for evaluation.
34
+ */
35
+ let ShellCommandBuilder = class ShellCommandBuilder {
36
+ /**
37
+ * Constructs a command line to run in a shell. The shell could be
38
+ * re-used/long-lived, this means we cannot spawn a new process with a nice
39
+ * and fresh environment, we need to encode environment modifications into
40
+ * the returned command.
41
+ *
42
+ * Inspired by VS Code implementation, see:
43
+ * https://github.com/microsoft/vscode/blob/f395cac4fff0721a8099126172c01411812bcb4a/src/vs/workbench/contrib/debug/node/terminals.ts#L79
44
+ *
45
+ * @param hostProcessInfo the host terminal process infos
46
+ * @param commandOptions program to execute in the host terminal
47
+ */
48
+ buildCommand(hostProcessInfo, commandOptions) {
49
+ const host = hostProcessInfo && hostProcessInfo.executable;
50
+ const cwd = commandOptions.cwd;
51
+ const args = commandOptions.args.map(value => ({
52
+ value, quoting: "strong" /* Strong */,
53
+ }));
54
+ const env = [];
55
+ if (commandOptions.env) {
56
+ for (const key of Object.keys(commandOptions.env)) {
57
+ env.push([key, commandOptions.env[key]]);
58
+ }
59
+ }
60
+ if (host) {
61
+ if (/(bash|wsl)(.exe)?$/.test(host)) {
62
+ return this.buildForBash(args, cwd, env);
63
+ }
64
+ else if (/(ps|pwsh|powershell)(.exe)?$/i.test(host)) {
65
+ return this.buildForPowershell(args, cwd, env);
66
+ }
67
+ else if (/cmd(.exe)?$/i.test(host)) {
68
+ return this.buildForCmd(args, cwd, env);
69
+ }
70
+ }
71
+ return this.buildForDefault(args, cwd, env);
72
+ }
73
+ buildForBash(args, cwd, env) {
74
+ let command = '';
75
+ if (cwd) {
76
+ command += `cd ${shell_quoting_1.BashQuotingFunctions.strong(cwd)} && `;
77
+ }
78
+ if (env === null || env === void 0 ? void 0 : env.length) {
79
+ command += 'env';
80
+ for (const [key, value] of env) {
81
+ if (value === null) {
82
+ command += ` -u ${shell_quoting_1.BashQuotingFunctions.strong(key)}`;
83
+ }
84
+ else {
85
+ command += ` ${shell_quoting_1.BashQuotingFunctions.strong(`${key}=${value}`)}`;
86
+ }
87
+ }
88
+ command += ' ';
89
+ }
90
+ command += this.createShellCommandLine(args, shell_quoting_1.BashQuotingFunctions);
91
+ return command;
92
+ }
93
+ buildForPowershell(args, cwd, env) {
94
+ let command = '';
95
+ if (cwd) {
96
+ command += `cd ${shell_quoting_1.PowershellQuotingFunctions.strong(cwd)}; `;
97
+ }
98
+ if (env === null || env === void 0 ? void 0 : env.length) {
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
+ if (value === null) {
106
+ command += `Remove-Item \${env:${quotedKey}}; `;
107
+ }
108
+ else {
109
+ command += `\${env:${quotedKey}}=${shell_quoting_1.PowershellQuotingFunctions.strong(value)}; `;
110
+ }
111
+ }
112
+ }
113
+ command += '& ' + this.createShellCommandLine(args, shell_quoting_1.PowershellQuotingFunctions);
114
+ return command;
115
+ }
116
+ buildForCmd(args, cwd, env) {
117
+ let command = '';
118
+ if (cwd) {
119
+ command += `cd ${shell_quoting_1.CmdQuotingFunctions.strong(cwd)} && `;
120
+ }
121
+ // Current quoting mechanism only works within a nested `cmd` call:
122
+ command += 'cmd /C "';
123
+ if (env === null || env === void 0 ? void 0 : env.length) {
124
+ for (const [key, value] of env) {
125
+ if (value === null) {
126
+ command += `set ${shell_quoting_1.CmdQuotingFunctions.strong(key)}="" && `;
127
+ }
128
+ else {
129
+ command += `set ${shell_quoting_1.CmdQuotingFunctions.strong(`${key}=${value}`)} && `;
130
+ }
131
+ }
132
+ }
133
+ command += this.createShellCommandLine(args, shell_quoting_1.CmdQuotingFunctions);
134
+ command += '"';
135
+ return command;
136
+ }
137
+ buildForDefault(args, cwd, env) {
138
+ return this.buildForBash(args, cwd, env);
139
+ }
140
+ /**
141
+ * This method will try to leave `arg[0]` unescaped if possible. The reason
142
+ * is that shells like `cmd` expect their own commands like `dir` to be
143
+ * unescaped.
144
+ *
145
+ * @returns empty string if `args` is empty, otherwise an escaped command.
146
+ */
147
+ createShellCommandLine(args, quotingFunctions) {
148
+ let command = '';
149
+ if (args.length > 0) {
150
+ const [exec, ...execArgs] = args;
151
+ // Some commands like `dir` should not be quoted for `cmd` to understand:
152
+ command += this.quoteExecutableIfNecessary(exec, quotingFunctions);
153
+ if (execArgs.length > 0) {
154
+ command += ' ' + (0, shell_quoting_1.createShellCommandLine)(execArgs, quotingFunctions);
155
+ }
156
+ }
157
+ return command;
158
+ }
159
+ quoteExecutableIfNecessary(exec, quotingFunctions) {
160
+ return typeof exec === 'string' && !this.needsQuoting(exec) ? exec : (0, shell_quoting_1.escapeForShell)(exec, quotingFunctions);
161
+ }
162
+ /**
163
+ * If this method returns `false` then we definitely need quoting.
164
+ *
165
+ * May return false positives.
166
+ */
167
+ needsQuoting(arg) {
168
+ return /\W/.test(arg);
169
+ }
170
+ };
171
+ ShellCommandBuilder = __decorate([
172
+ (0, inversify_1.injectable)()
173
+ ], ShellCommandBuilder);
174
+ exports.ShellCommandBuilder = ShellCommandBuilder;
175
175
  //# sourceMappingURL=shell-command-builder.js.map
@@ -1,10 +1,10 @@
1
- /// <reference types="node" />
2
- /**
3
- * This test suite assumes that we run in a NodeJS environment!
4
- */
5
- import { ChildProcess } from 'child_process';
6
- import { ProcessInfo } from './shell-command-builder';
7
- export interface TestProcessInfo extends ProcessInfo {
8
- shell: ChildProcess;
9
- }
1
+ /// <reference types="node" />
2
+ /**
3
+ * This test suite assumes that we run in a NodeJS environment!
4
+ */
5
+ import { ChildProcess } from 'child_process';
6
+ import { ProcessInfo } from './shell-command-builder';
7
+ export interface TestProcessInfo extends ProcessInfo {
8
+ shell: ChildProcess;
9
+ }
10
10
  //# sourceMappingURL=shell-command-builder.slow-spec.d.ts.map