@yeaft/webchat-agent 0.1.621 → 0.1.623
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/check-node-version.js +74 -0
- package/cli.js +3 -0
- package/index.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* check-node-version.js — Runtime guard for Node.js minimum version.
|
|
3
|
+
*
|
|
4
|
+
* The agent and server use `node:sqlite` (DatabaseSync) which is built-in
|
|
5
|
+
* to Node ≥ 22.5.0. On older Node the import fails with the cryptic
|
|
6
|
+
* `No such built-in module: node:sqlite`. We replace that with a clear
|
|
7
|
+
* actionable message and exit early.
|
|
8
|
+
*
|
|
9
|
+
* Why this exists even though `package.json` has `"engines": { "node": ">=22.5.0" }`:
|
|
10
|
+
* - npm only WARNS on engines mismatch by default (not strict).
|
|
11
|
+
* - `nvm use 22` selects whichever 22.x is already installed; if the
|
|
12
|
+
* user has 22.0–22.4, they pass the major check but fail node:sqlite.
|
|
13
|
+
* - Globally-installed CLIs (`@yeaft/webchat-agent`) bypass package.json
|
|
14
|
+
* engines entirely on the user's system.
|
|
15
|
+
*
|
|
16
|
+
* Call `assertNodeVersion()` at the very top of every entry point (before
|
|
17
|
+
* any import that transitively touches `node:sqlite`).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const MIN_MAJOR = 22;
|
|
21
|
+
const MIN_MINOR = 5;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Parse `process.version` ("v22.5.1") into [major, minor, patch].
|
|
25
|
+
* Returns null on unrecognized input rather than throwing — we never
|
|
26
|
+
* want this guard to break startup itself.
|
|
27
|
+
*/
|
|
28
|
+
function parseNodeVersion(v) {
|
|
29
|
+
if (typeof v !== 'string') return null;
|
|
30
|
+
const m = /^v?(\d+)\.(\d+)\.(\d+)/.exec(v);
|
|
31
|
+
if (!m) return null;
|
|
32
|
+
return [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @returns {boolean} true if current Node satisfies the minimum.
|
|
37
|
+
*/
|
|
38
|
+
export function isSupportedNodeVersion(versionString = process.version) {
|
|
39
|
+
const parsed = parseNodeVersion(versionString);
|
|
40
|
+
if (!parsed) return true; // unknown — don't block
|
|
41
|
+
const [major, minor] = parsed;
|
|
42
|
+
if (major > MIN_MAJOR) return true;
|
|
43
|
+
if (major < MIN_MAJOR) return false;
|
|
44
|
+
return minor >= MIN_MINOR;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Print a clear error and exit(1) if Node is too old.
|
|
49
|
+
*
|
|
50
|
+
* @param {{ component?: string }} [opts]
|
|
51
|
+
*/
|
|
52
|
+
export function assertNodeVersion(opts = {}) {
|
|
53
|
+
if (isSupportedNodeVersion()) return;
|
|
54
|
+
const component = opts.component || 'yeaft';
|
|
55
|
+
const required = `${MIN_MAJOR}.${MIN_MINOR}.0`;
|
|
56
|
+
const lines = [
|
|
57
|
+
'',
|
|
58
|
+
`✖ ${component} requires Node.js ≥ ${required}`,
|
|
59
|
+
` Current: ${process.version}`,
|
|
60
|
+
'',
|
|
61
|
+
' This project uses the built-in `node:sqlite` module which was',
|
|
62
|
+
` added in Node ${required}.`,
|
|
63
|
+
'',
|
|
64
|
+
' Fix:',
|
|
65
|
+
' # if you use nvm:',
|
|
66
|
+
' nvm install 22 # installs the latest 22.x (currently > 22.5)',
|
|
67
|
+
' nvm use 22',
|
|
68
|
+
'',
|
|
69
|
+
' # or upgrade Node from https://nodejs.org/',
|
|
70
|
+
'',
|
|
71
|
+
];
|
|
72
|
+
process.stderr.write(lines.join('\n'));
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
package/cli.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* CLI entry point for @yeaft/webchat-agent
|
|
4
4
|
* Parses command-line arguments and starts the agent or runs subcommands
|
|
5
5
|
*/
|
|
6
|
+
import { assertNodeVersion } from './check-node-version.js';
|
|
7
|
+
assertNodeVersion({ component: '@yeaft/webchat-agent' });
|
|
8
|
+
|
|
6
9
|
import { execSync, spawn } from 'child_process';
|
|
7
10
|
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
8
11
|
import { dirname, join } from 'path';
|
package/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { assertNodeVersion } from './check-node-version.js';
|
|
2
|
+
assertNodeVersion({ component: '@yeaft/webchat-agent' });
|
|
3
|
+
|
|
1
4
|
import 'dotenv/config';
|
|
2
5
|
import { platform, homedir } from 'os';
|
|
3
6
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, cpSync, chmodSync, readdirSync } from 'fs';
|