@tpmjs/tools-sprites-exec 0.1.4 → 0.1.5

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 (2) hide show
  1. package/dist/index.js +28 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15,7 +15,34 @@ function getSpritesToken() {
15
15
  }
16
16
  return token;
17
17
  }
18
+ var SHELL_OPERATORS = ["&&", "||", "|", ";", ">", ">>", "<", "<<", "2>", "2>>", "&>", "$(", "`"];
19
+ function needsShellWrapper(cmdString) {
20
+ let inSingleQuote = false;
21
+ let inDoubleQuote = false;
22
+ for (let i = 0; i < cmdString.length; i++) {
23
+ const char = cmdString[i];
24
+ if (char === "'" && !inDoubleQuote) {
25
+ inSingleQuote = !inSingleQuote;
26
+ continue;
27
+ }
28
+ if (char === '"' && !inSingleQuote) {
29
+ inDoubleQuote = !inDoubleQuote;
30
+ continue;
31
+ }
32
+ if (!inSingleQuote && !inDoubleQuote) {
33
+ for (const op of SHELL_OPERATORS) {
34
+ if (cmdString.slice(i, i + op.length) === op) {
35
+ return true;
36
+ }
37
+ }
38
+ }
39
+ }
40
+ return false;
41
+ }
18
42
  function parseCommand(cmdString) {
43
+ if (needsShellWrapper(cmdString)) {
44
+ return ["sh", "-c", cmdString];
45
+ }
19
46
  const args = [];
20
47
  let current = "";
21
48
  let inSingleQuote = false;
@@ -184,9 +211,7 @@ var spritesExecTool = tool({
184
211
  try {
185
212
  const errorResponse = JSON.parse(jsonText);
186
213
  if (errorResponse.error) {
187
- throw new Error(
188
- `Failed to execute command in sprite "${name}": ${errorResponse.error}`
189
- );
214
+ throw new Error(`Failed to execute command in sprite "${name}": ${errorResponse.error}`);
190
215
  }
191
216
  } catch (parseError) {
192
217
  if (parseError instanceof SyntaxError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpmjs/tools-sprites-exec",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Execute a command inside a sprite and return the output with exit code",
5
5
  "type": "module",
6
6
  "keywords": [