fix(npm): guard unsupported node during install (#1032)

This commit is contained in:
axobase001
2026-05-07 19:27:38 +08:00
committed by GitHub
parent 2644be9b52
commit b476703a8d
2 changed files with 46 additions and 2 deletions
+23 -2
View File
@@ -1,3 +1,18 @@
function assertSupportedNode() {
const version = process.versions && process.versions.node ? process.versions.node : "unknown";
const major = Number.parseInt(String(version).split(".")[0], 10);
if (Number.isNaN(major) || major < 18) {
process.stderr.write(
"deepseek-tui: Node.js 18 or newer is required for npm installation. " +
`Current Node.js version is ${version}. ` +
"Please upgrade Node.js and rerun `npm install -g deepseek-tui`.\n",
);
process.exit(1);
}
}
assertSupportedNode();
const fs = require("fs");
const https = require("https");
const http = require("http");
@@ -355,8 +370,14 @@ function connectThroughProxy(proxy, targetHost, targetPort, timeoutMs) {
// ────────────────────────────────────────────────────────────────────────────
function httpRequest(rawUrl, opts = {}) {
const totalTimeoutMs = opts.totalTimeoutMs ?? downloadTimeoutMs();
const stallMs = opts.stallMs ?? downloadStallMs();
const totalTimeoutMs =
opts.totalTimeoutMs === undefined || opts.totalTimeoutMs === null
? downloadTimeoutMs()
: opts.totalTimeoutMs;
const stallMs =
opts.stallMs === undefined || opts.stallMs === null
? downloadStallMs()
: opts.stallMs;
return new Promise((resolve, reject) => {
let url;
+23
View File
@@ -0,0 +1,23 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const test = require("node:test");
const installScript = fs.readFileSync(
path.join(__dirname, "..", "scripts", "install.js"),
"utf8",
);
test("install script checks Node support before loading helpers", () => {
const guardIndex = installScript.indexOf("assertSupportedNode();");
const firstRequireIndex = installScript.indexOf("require(");
assert.notEqual(guardIndex, -1);
assert.notEqual(firstRequireIndex, -1);
assert.ok(guardIndex < firstRequireIndex);
});
test("install script remains parseable before the Node support guard runs", () => {
assert.equal(installScript.includes("??"), false);
assert.equal(installScript.includes("?."), false);
});