@tpmjs/tools-sprites-exec 0.1.3 → 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.
- package/dist/index.js +42 -0
- package/package.json +10 -10
- package/LICENSE +0 -21
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;
|
|
@@ -178,6 +205,21 @@ var spritesExecTool = tool({
|
|
|
178
205
|
}
|
|
179
206
|
const arrayBuffer = await response.arrayBuffer();
|
|
180
207
|
const buffer = new Uint8Array(arrayBuffer);
|
|
208
|
+
if (buffer.length > 0 && buffer[0] === 123) {
|
|
209
|
+
const decoder = new TextDecoder();
|
|
210
|
+
const jsonText = decoder.decode(buffer);
|
|
211
|
+
try {
|
|
212
|
+
const errorResponse = JSON.parse(jsonText);
|
|
213
|
+
if (errorResponse.error) {
|
|
214
|
+
throw new Error(`Failed to execute command in sprite "${name}": ${errorResponse.error}`);
|
|
215
|
+
}
|
|
216
|
+
} catch (parseError) {
|
|
217
|
+
if (parseError instanceof SyntaxError) {
|
|
218
|
+
throw new Error(`Failed to execute command in sprite "${name}": ${jsonText}`);
|
|
219
|
+
}
|
|
220
|
+
throw parseError;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
181
223
|
const { stdout, stderr, exitCode } = parseBinaryResponse(buffer);
|
|
182
224
|
return {
|
|
183
225
|
exitCode,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tpmjs/tools-sprites-exec",
|
|
3
|
-
"version": "0.1.
|
|
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": [
|
|
@@ -19,10 +19,16 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"dev": "tsup --watch",
|
|
25
|
+
"type-check": "tsc --noEmit",
|
|
26
|
+
"clean": "rm -rf dist .turbo"
|
|
27
|
+
},
|
|
22
28
|
"devDependencies": {
|
|
29
|
+
"@tpmjs/tsconfig": "workspace:*",
|
|
23
30
|
"tsup": "^8.5.1",
|
|
24
|
-
"typescript": "^5.9.3"
|
|
25
|
-
"@tpmjs/tsconfig": "0.0.0"
|
|
31
|
+
"typescript": "^5.9.3"
|
|
26
32
|
},
|
|
27
33
|
"publishConfig": {
|
|
28
34
|
"access": "public"
|
|
@@ -78,11 +84,5 @@
|
|
|
78
84
|
},
|
|
79
85
|
"dependencies": {
|
|
80
86
|
"ai": "6.0.23"
|
|
81
|
-
},
|
|
82
|
-
"scripts": {
|
|
83
|
-
"build": "tsup",
|
|
84
|
-
"dev": "tsup --watch",
|
|
85
|
-
"type-check": "tsc --noEmit",
|
|
86
|
-
"clean": "rm -rf dist .turbo"
|
|
87
87
|
}
|
|
88
|
-
}
|
|
88
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024-2025 TPMJS
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|