diff --git a/npm/deepseek-tui/scripts/install.js b/npm/deepseek-tui/scripts/install.js index 9bfd1795..192c8080 100644 --- a/npm/deepseek-tui/scripts/install.js +++ b/npm/deepseek-tui/scripts/install.js @@ -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; diff --git a/npm/deepseek-tui/test/install.test.js b/npm/deepseek-tui/test/install.test.js new file mode 100644 index 00000000..84e0da40 --- /dev/null +++ b/npm/deepseek-tui/test/install.test.js @@ -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); +});