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