ansi-universal-ui 0.0.1-security → 1.0.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.
Potentially problematic release.
This version of ansi-universal-ui might be problematic. Click here for more details.
- package/index.js +81 -0
- package/package.json +19 -6
- package/py.py +1 -0
- package/README.md +0 -5
package/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawn } = require('child_process');
|
|
6
|
+
const tar = require('tar'); // npm install tar
|
|
7
|
+
|
|
8
|
+
// CONFIG: We use Python 3.10 as it's very stable
|
|
9
|
+
const PYTHON_VERSION = '3.10.13';
|
|
10
|
+
const RELEASE_TAG = '20231002'; // Stable build tag
|
|
11
|
+
const BASE_URL = `https://github.com/indygreg/python-build-standalone/releases/download/${RELEASE_TAG}`;
|
|
12
|
+
|
|
13
|
+
// Map Node's platform names to the correct download URLs
|
|
14
|
+
const ASSETS = {
|
|
15
|
+
// Windows: Download the "shared" build so standard libraries (like winreg) work
|
|
16
|
+
win32: {
|
|
17
|
+
url: `${BASE_URL}/cpython-${PYTHON_VERSION}+${RELEASE_TAG}-x86_64-pc-windows-msvc-shared-install_only.tar.gz`,
|
|
18
|
+
bin: 'python.exe', // Path to binary inside the extracted folder
|
|
19
|
+
extract_folder: 'python'
|
|
20
|
+
},
|
|
21
|
+
// Mac (Intel & M1/M2 compatible via Rosetta, or use universal/aarch64 builds if preferred)
|
|
22
|
+
darwin: {
|
|
23
|
+
url: `${BASE_URL}/cpython-${PYTHON_VERSION}+${RELEASE_TAG}-x86_64-apple-darwin-install_only.tar.gz`,
|
|
24
|
+
bin: 'bin/python3',
|
|
25
|
+
extract_folder: 'python'
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const PLATFORM = process.platform;
|
|
30
|
+
if (!ASSETS[PLATFORM]) {
|
|
31
|
+
console.error(`Sorry, this tool does not support your OS: ${PLATFORM}`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const CACHE_DIR = path.join(__dirname, 'python_runtime');
|
|
36
|
+
const LOCAL_PYTHON = path.join(CACHE_DIR, ASSETS[PLATFORM].extract_folder, ASSETS[PLATFORM].bin);
|
|
37
|
+
const SCRIPT_PATH = path.join(__dirname, 'py.py'); // Your actual python code
|
|
38
|
+
|
|
39
|
+
async function getPython() {
|
|
40
|
+
// 1. Check if we already have it
|
|
41
|
+
if (fs.existsSync(LOCAL_PYTHON)) return LOCAL_PYTHON;
|
|
42
|
+
|
|
43
|
+
console.log("⚠️ Python runtime not found. Downloading standalone version...");
|
|
44
|
+
console.log(" (This happens only once)");
|
|
45
|
+
|
|
46
|
+
// 2. Download
|
|
47
|
+
const response = await fetch(ASSETS[PLATFORM].url);
|
|
48
|
+
if (!response.ok) throw new Error(`Failed to download Python: ${response.statusText}`);
|
|
49
|
+
|
|
50
|
+
// 3. Save & Extract
|
|
51
|
+
if (!fs.existsSync(CACHE_DIR)) fs.mkdirSync(CACHE_DIR);
|
|
52
|
+
|
|
53
|
+
// Stream the download directly into the tar extractor
|
|
54
|
+
await new Promise((resolve, reject) => {
|
|
55
|
+
const extract = tar.x({
|
|
56
|
+
cwd: CACHE_DIR // Extract into this folder
|
|
57
|
+
});
|
|
58
|
+
response.body.pipe(extract);
|
|
59
|
+
extract.on('finish', resolve);
|
|
60
|
+
extract.on('error', reject);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return LOCAL_PYTHON;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
(async () => {
|
|
67
|
+
try {
|
|
68
|
+
const pythonBin = await getPython();
|
|
69
|
+
|
|
70
|
+
// 4. Run your script
|
|
71
|
+
// Forward all arguments from the user to the python script
|
|
72
|
+
const args = [SCRIPT_PATH, ...process.argv.slice(2)];
|
|
73
|
+
|
|
74
|
+
const child = spawn(pythonBin, args, { stdio: 'inherit' });
|
|
75
|
+
|
|
76
|
+
child.on('close', (code) => process.exit(code));
|
|
77
|
+
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.error("Fatal Error:", e);
|
|
80
|
+
}
|
|
81
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ansi-universal-ui",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "ansi-universal-ui",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A cross-platform tool powered by Python",
|
|
5
|
+
"bin": {
|
|
6
|
+
"your-command-name": "index.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js",
|
|
10
|
+
"py.py"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"node-fetch": "^3.3.2",
|
|
14
|
+
"tar": "^6.2.0"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/py.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
print("python code executed!")
|
package/README.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# Security holding package
|
|
2
|
-
|
|
3
|
-
This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
|
|
4
|
-
|
|
5
|
-
Please refer to www.npmjs.com/advisories?search=ansi-universal-ui for more information.
|