@theia/process 1.30.0-next.7 → 1.30.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.
@@ -1,4 +1,4 @@
1
- import { ShellQuotedString } from '../common/shell-quoting';
1
+ import { ShellQuotedString, ShellQuotingFunctions } from '../common/shell-quoting';
2
2
  export interface ProcessInfo {
3
3
  executable: string;
4
4
  arguments: string[];
@@ -31,5 +31,20 @@ export declare class ShellCommandBuilder {
31
31
  protected buildForPowershell(args: Array<string | ShellQuotedString>, cwd?: string, env?: Array<[string, string | null]>): string;
32
32
  protected buildForCmd(args: Array<string | ShellQuotedString>, cwd?: string, env?: Array<[string, string | null]>): string;
33
33
  protected buildForDefault(args: Array<string | ShellQuotedString>, cwd?: string, env?: Array<[string, string | null]>): string;
34
+ /**
35
+ * This method will try to leave `arg[0]` unescaped if possible. The reason
36
+ * is that shells like `cmd` expect their own commands like `dir` to be
37
+ * unescaped.
38
+ *
39
+ * @returns empty string if `args` is empty, otherwise an escaped command.
40
+ */
41
+ protected createShellCommandLine(args: (string | ShellQuotedString)[], quotingFunctions: ShellQuotingFunctions): string;
42
+ protected quoteExecutableIfNecessary(exec: string | ShellQuotedString, quotingFunctions: ShellQuotingFunctions): string;
43
+ /**
44
+ * If this method returns `false` then we definitely need quoting.
45
+ *
46
+ * May return false positives.
47
+ */
48
+ protected needsQuoting(arg: string): boolean;
34
49
  }
35
50
  //# sourceMappingURL=shell-command-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell-command-builder.d.ts","sourceRoot":"","sources":["../../src/common/shell-command-builder.ts"],"names":[],"mappings":"AAsBA,OAAO,EAA+G,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEzK,MAAM,WAAW,WAAW;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,EAAE,CAAA;CACtB;AAED,MAAM,WAAW,kBAAkB;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,I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AAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,GAAG,MAAM;IAI9H;;;;;;OAMG;IACH,SAAS,CAAC,sBAAsB,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,iBAAiB,CAAC,EAAE,EAAE,gBAAgB,EAAE,qBAAqB,GAAG,MAAM;IAavH,SAAS,CAAC,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,EAAE,gBAAgB,EAAE,qBAAqB,GAAG,MAAM;IAIvH;;;;OAIG;IACH,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAG/C"}
@@ -26,6 +26,7 @@ exports.ShellCommandBuilder = void 0;
26
26
  * Copyright (c) Microsoft Corporation. All rights reserved.
27
27
  * Licensed under the MIT License. See License.txt in the project root for license information.
28
28
  *--------------------------------------------------------------------------------------------*/
29
+ /* eslint-disable no-null/no-null */
29
30
  const inversify_1 = require("@theia/core/shared/inversify");
30
31
  const shell_quoting_1 = require("../common/shell-quoting");
31
32
  /**
@@ -74,10 +75,9 @@ let ShellCommandBuilder = class ShellCommandBuilder {
74
75
  if (cwd) {
75
76
  command += `cd ${shell_quoting_1.BashQuotingFunctions.strong(cwd)} && `;
76
77
  }
77
- if (env) {
78
+ if (env === null || env === void 0 ? void 0 : env.length) {
78
79
  command += 'env';
79
80
  for (const [key, value] of env) {
80
- // eslint-disable-next-line no-null/no-null
81
81
  if (value === null) {
82
82
  command += ` -u ${shell_quoting_1.BashQuotingFunctions.strong(key)}`;
83
83
  }
@@ -87,7 +87,7 @@ let ShellCommandBuilder = class ShellCommandBuilder {
87
87
  }
88
88
  command += ' ';
89
89
  }
90
- command += (0, shell_quoting_1.createShellCommandLine)(args, shell_quoting_1.BashQuotingFunctions);
90
+ command += this.createShellCommandLine(args, shell_quoting_1.BashQuotingFunctions);
91
91
  return command;
92
92
  }
93
93
  buildForPowershell(args, cwd, env) {
@@ -95,14 +95,13 @@ let ShellCommandBuilder = class ShellCommandBuilder {
95
95
  if (cwd) {
96
96
  command += `cd ${shell_quoting_1.PowershellQuotingFunctions.strong(cwd)}; `;
97
97
  }
98
- if (env) {
98
+ if (env === null || env === void 0 ? void 0 : env.length) {
99
99
  for (const [key, value] of env) {
100
100
  // Powershell requires special quoting when dealing with
101
101
  // environment variable names.
102
102
  const quotedKey = key
103
103
  .replace(/`/g, '````')
104
104
  .replace(/\?/g, '``?');
105
- // eslint-disable-next-line no-null/no-null
106
105
  if (value === null) {
107
106
  command += `Remove-Item \${env:${quotedKey}}; `;
108
107
  }
@@ -111,7 +110,7 @@ let ShellCommandBuilder = class ShellCommandBuilder {
111
110
  }
112
111
  }
113
112
  }
114
- command += '& ' + (0, shell_quoting_1.createShellCommandLine)(args, shell_quoting_1.PowershellQuotingFunctions);
113
+ command += '& ' + this.createShellCommandLine(args, shell_quoting_1.PowershellQuotingFunctions);
115
114
  return command;
116
115
  }
117
116
  buildForCmd(args, cwd, env) {
@@ -119,10 +118,10 @@ let ShellCommandBuilder = class ShellCommandBuilder {
119
118
  if (cwd) {
120
119
  command += `cd ${shell_quoting_1.CmdQuotingFunctions.strong(cwd)} && `;
121
120
  }
122
- if (env) {
123
- command += 'cmd /C "';
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
124
  for (const [key, value] of env) {
125
- // eslint-disable-next-line no-null/no-null
126
125
  if (value === null) {
127
126
  command += `set ${shell_quoting_1.CmdQuotingFunctions.strong(key)}="" && `;
128
127
  }
@@ -131,15 +130,43 @@ let ShellCommandBuilder = class ShellCommandBuilder {
131
130
  }
132
131
  }
133
132
  }
134
- command += (0, shell_quoting_1.createShellCommandLine)(args, shell_quoting_1.CmdQuotingFunctions);
135
- if (env) {
136
- command += '"';
137
- }
133
+ command += this.createShellCommandLine(args, shell_quoting_1.CmdQuotingFunctions);
134
+ command += '"';
138
135
  return command;
139
136
  }
140
137
  buildForDefault(args, cwd, env) {
141
138
  return this.buildForBash(args, cwd, env);
142
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
+ }
143
170
  };
144
171
  ShellCommandBuilder = __decorate([
145
172
  (0, inversify_1.injectable)()
@@ -1 +1 @@
1
- {"version":3,"file":"shell-command-builder.js","sourceRoot":"","sources":["../../src/common/shell-command-builder.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,gFAAgF;;;;;;;;;AAEhF;;;gGAGgG;AAEhG,4DAA0D;AAC1D,2DAAyK;AAezK;;GAEG;AAEH,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAE5B;;;;;;;;;;;OAWG;IACH,YAAY,CAAC,e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AAO,OAAO,CAAC;IACnB,CAAC;IAES,eAAe,CAAC,IAAuC,EAAE,GAAY,EAAE,GAAoC;QACjH,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;OAMG;IACO,sBAAsB,CAAC,IAAoC,EAAE,gBAAuC;QAC1G,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACjB,MAAM,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC;YACjC,yEAAyE;YACzE,OAAO,IAAI,IAAI,CAAC,0BAA0B,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;YACnE,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,OAAO,IAAI,GAAG,GAAG,IAAA,sCAAsB,EAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;aACvE;SACJ;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAES,0BAA0B,CAAC,IAAgC,EAAE,gBAAuC;QAC1G,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,8BAAc,EAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAChH,CAAC;IAED;;;;OAIG;IACO,YAAY,CAAC,GAAW;QAC9B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACJ,CAAA;AA7IY,mBAAmB;IAD/B,IAAA,sBAAU,GAAE;GACA,mBAAmB,CA6I/B;AA7IY,kDAAmB"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@theia/process",
3
- "version": "1.30.0-next.7+98a0bf6944d",
3
+ "version": "1.30.0",
4
4
  "description": "Theia process support.",
5
5
  "dependencies": {
6
- "@theia/core": "1.30.0-next.7+98a0bf6944d",
6
+ "@theia/core": "1.30.0",
7
7
  "node-pty": "0.11.0-beta17",
8
8
  "string-argv": "^0.1.1"
9
9
  },
@@ -44,10 +44,10 @@
44
44
  "watch": "theiaext watch"
45
45
  },
46
46
  "devDependencies": {
47
- "@theia/ext-scripts": "1.29.0"
47
+ "@theia/ext-scripts": "1.30.0"
48
48
  },
49
49
  "nyc": {
50
50
  "extends": "../../configs/nyc.json"
51
51
  },
52
- "gitHead": "98a0bf6944d8ef0cfa3cef52b1c1cb35b4eea063"
52
+ "gitHead": "1b32ca5626bb8252143b7a6ad6b513410f49366e"
53
53
  }
@@ -19,8 +19,12 @@
19
19
  * Licensed under the MIT License. See License.txt in the project root for license information.
20
20
  *--------------------------------------------------------------------------------------------*/
21
21
 
22
+ /* eslint-disable no-null/no-null */
23
+
22
24
  import { injectable } from '@theia/core/shared/inversify';
23
- import { createShellCommandLine, BashQuotingFunctions, PowershellQuotingFunctions, CmdQuotingFunctions, ShellQuoting, ShellQuotedString } from '../common/shell-quoting';
25
+ import {
26
+ createShellCommandLine, BashQuotingFunctions, PowershellQuotingFunctions, CmdQuotingFunctions, ShellQuoting, ShellQuotedString, escapeForShell, ShellQuotingFunctions
27
+ } from '../common/shell-quoting';
24
28
 
25
29
  export interface ProcessInfo {
26
30
  executable: string
@@ -85,10 +89,9 @@ export class ShellCommandBuilder {
85
89
  if (cwd) {
86
90
  command += `cd ${BashQuotingFunctions.strong(cwd)} && `;
87
91
  }
88
- if (env) {
92
+ if (env?.length) {
89
93
  command += 'env';
90
94
  for (const [key, value] of env) {
91
- // eslint-disable-next-line no-null/no-null
92
95
  if (value === null) {
93
96
  command += ` -u ${BashQuotingFunctions.strong(key)}`;
94
97
  } else {
@@ -97,7 +100,7 @@ export class ShellCommandBuilder {
97
100
  }
98
101
  command += ' ';
99
102
  }
100
- command += createShellCommandLine(args, BashQuotingFunctions);
103
+ command += this.createShellCommandLine(args, BashQuotingFunctions);
101
104
  return command;
102
105
  }
103
106
 
@@ -106,14 +109,13 @@ export class ShellCommandBuilder {
106
109
  if (cwd) {
107
110
  command += `cd ${PowershellQuotingFunctions.strong(cwd)}; `;
108
111
  }
109
- if (env) {
112
+ if (env?.length) {
110
113
  for (const [key, value] of env) {
111
114
  // Powershell requires special quoting when dealing with
112
115
  // environment variable names.
113
116
  const quotedKey = key
114
117
  .replace(/`/g, '````')
115
118
  .replace(/\?/g, '``?');
116
- // eslint-disable-next-line no-null/no-null
117
119
  if (value === null) {
118
120
  command += `Remove-Item \${env:${quotedKey}}; `;
119
121
  } else {
@@ -121,7 +123,7 @@ export class ShellCommandBuilder {
121
123
  }
122
124
  }
123
125
  }
124
- command += '& ' + createShellCommandLine(args, PowershellQuotingFunctions);
126
+ command += '& ' + this.createShellCommandLine(args, PowershellQuotingFunctions);
125
127
  return command;
126
128
  }
127
129
 
@@ -130,10 +132,10 @@ export class ShellCommandBuilder {
130
132
  if (cwd) {
131
133
  command += `cd ${CmdQuotingFunctions.strong(cwd)} && `;
132
134
  }
133
- if (env) {
134
- command += 'cmd /C "';
135
+ // Current quoting mechanism only works within a nested `cmd` call:
136
+ command += 'cmd /C "';
137
+ if (env?.length) {
135
138
  for (const [key, value] of env) {
136
- // eslint-disable-next-line no-null/no-null
137
139
  if (value === null) {
138
140
  command += `set ${CmdQuotingFunctions.strong(key)}="" && `;
139
141
  } else {
@@ -141,10 +143,8 @@ export class ShellCommandBuilder {
141
143
  }
142
144
  }
143
145
  }
144
- command += createShellCommandLine(args, CmdQuotingFunctions);
145
- if (env) {
146
- command += '"';
147
- }
146
+ command += this.createShellCommandLine(args, CmdQuotingFunctions);
147
+ command += '"';
148
148
  return command;
149
149
  }
150
150
 
@@ -152,4 +152,36 @@ export class ShellCommandBuilder {
152
152
  return this.buildForBash(args, cwd, env);
153
153
  }
154
154
 
155
+ /**
156
+ * This method will try to leave `arg[0]` unescaped if possible. The reason
157
+ * is that shells like `cmd` expect their own commands like `dir` to be
158
+ * unescaped.
159
+ *
160
+ * @returns empty string if `args` is empty, otherwise an escaped command.
161
+ */
162
+ protected createShellCommandLine(args: (string | ShellQuotedString)[], quotingFunctions: ShellQuotingFunctions): string {
163
+ let command = '';
164
+ if (args.length > 0) {
165
+ const [exec, ...execArgs] = args;
166
+ // Some commands like `dir` should not be quoted for `cmd` to understand:
167
+ command += this.quoteExecutableIfNecessary(exec, quotingFunctions);
168
+ if (execArgs.length > 0) {
169
+ command += ' ' + createShellCommandLine(execArgs, quotingFunctions);
170
+ }
171
+ }
172
+ return command;
173
+ }
174
+
175
+ protected quoteExecutableIfNecessary(exec: string | ShellQuotedString, quotingFunctions: ShellQuotingFunctions): string {
176
+ return typeof exec === 'string' && !this.needsQuoting(exec) ? exec : escapeForShell(exec, quotingFunctions);
177
+ }
178
+
179
+ /**
180
+ * If this method returns `false` then we definitely need quoting.
181
+ *
182
+ * May return false positives.
183
+ */
184
+ protected needsQuoting(arg: string): boolean {
185
+ return /\W/.test(arg);
186
+ }
155
187
  }