omnish 2.1.2 → 2.1.4

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.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omnish",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "omnish — allowlisted inbox → your real shell (WhatsApp, Telegram, Discord, Slack, and 20+ channels). No AI.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,6 +26,8 @@
26
26
  "files": [
27
27
  "dist",
28
28
  "scripts/check-native-modules.mjs",
29
+ "scripts/check-node-version.mjs",
30
+ "scripts/node-version.mjs",
29
31
  "scripts/fix-node-pty-perms.mjs",
30
32
  "README.md",
31
33
  "CHANGELOG.md",
@@ -38,27 +40,6 @@
38
40
  "bin": {
39
41
  "omnish": "dist/index.js"
40
42
  },
41
- "scripts": {
42
- "reinstall": "rm -rf node_modules && pnpm install",
43
- "postinstall": "node scripts/check-native-modules.mjs && node scripts/fix-node-pty-perms.mjs",
44
- "prepack": "npm run build",
45
- "build": "node scripts/build-bundle.mjs",
46
- "build:doc-index": "node scripts/build-doc-index.mjs",
47
- "typecheck": "tsc --noEmit",
48
- "pretypecheck": "node scripts/build-doc-index.mjs",
49
- "pretest": "node scripts/build-doc-index.mjs",
50
- "format": "prettier --write .",
51
- "format:check": "prettier --check .",
52
- "test": "tsx --test 'src/**/*.test.ts'",
53
- "arch:check": "depcruise src --config .dependency-cruiser.cjs",
54
- "channel:parity": "tsx scripts/channel-parity.mjs",
55
- "omnish": "tsx src/index.ts",
56
- "link": "tsx src/index.ts link",
57
- "run": "tsx src/index.ts run",
58
- "local": "omnish stop || true; node scripts/build-bundle.mjs && npm link && omnish start",
59
- "logout": "tsx src/index.ts logout"
60
- },
61
- "packageManager": "pnpm@11.9.0+sha512.bd682d5d03fe525ef7c9fd6780c6884d1e756ac4c9c9fe00c538782824310dcf90e3ddc4f53835f06dfaebd5085e41855e0bcbb3b60de2ac5bbab89e5036f03b",
62
43
  "engines": {
63
44
  "node": ">=22.13"
64
45
  },
@@ -89,14 +70,6 @@
89
70
  "tsx": "^4.19.2",
90
71
  "typescript": "^5.7.2"
91
72
  },
92
- "pnpm": {
93
- "onlyBuiltDependencies": [
94
- "@parcel/watcher",
95
- "better-sqlite3",
96
- "esbuild",
97
- "node-pty"
98
- ]
99
- },
100
73
  "allowScripts": {
101
74
  "@parcel/watcher": true,
102
75
  "@whiskeysockets/baileys": true,
@@ -104,5 +77,25 @@
104
77
  "node-pty": true,
105
78
  "sharp": true,
106
79
  "protobufjs": true
80
+ },
81
+ "scripts": {
82
+ "reinstall": "rm -rf node_modules && pnpm install",
83
+ "preinstall": "node scripts/check-node-version.mjs",
84
+ "postinstall": "node scripts/check-native-modules.mjs && node scripts/fix-node-pty-perms.mjs",
85
+ "build": "node scripts/build-bundle.mjs",
86
+ "build:doc-index": "node scripts/build-doc-index.mjs",
87
+ "typecheck": "tsc --noEmit",
88
+ "pretypecheck": "node scripts/build-doc-index.mjs",
89
+ "pretest": "node scripts/build-doc-index.mjs",
90
+ "format": "prettier --write .",
91
+ "format:check": "prettier --check .",
92
+ "test": "tsx --test 'src/**/*.test.ts'",
93
+ "arch:check": "depcruise src --config .dependency-cruiser.cjs",
94
+ "channel:parity": "tsx scripts/channel-parity.mjs",
95
+ "omnish": "tsx src/index.ts",
96
+ "link": "tsx src/index.ts link",
97
+ "run": "tsx src/index.ts run",
98
+ "local": "omnish stop || true; node scripts/build-bundle.mjs && npm link && omnish start",
99
+ "logout": "tsx src/index.ts logout"
107
100
  }
108
- }
101
+ }
@@ -2,12 +2,14 @@
2
2
  * Verify native addons load under the current Node ABI (postinstall guard).
3
3
  */
4
4
  import { createRequire } from "node:module";
5
+ import { formatNativeModuleNodeHint } from "./node-version.mjs";
5
6
 
6
7
  const require = createRequire(import.meta.url);
7
8
 
8
9
  const modules = ["better-sqlite3", "node-pty", "@parcel/watcher"];
9
10
 
10
11
  let failed = false;
12
+ let printedNodeHint = false;
11
13
  for (const name of modules) {
12
14
  try {
13
15
  require(name);
@@ -17,9 +19,15 @@ for (const name of modules) {
17
19
  `omnish: native module "${name}" failed to load for Node ${process.version} (ABI ${process.versions.modules}).`,
18
20
  );
19
21
  console.error(` ${err instanceof Error ? err.message : String(err)}`);
20
- console.error(
21
- " Fix: use the Node version in .nvmrc (nvm use) and run: pnpm rebuild better-sqlite3 node-pty @parcel/watcher",
22
- );
22
+ if (!printedNodeHint) {
23
+ printedNodeHint = true;
24
+ console.error(
25
+ " Fix: use Node 22.13+ (see package.json engines), then reinstall or rebuild:",
26
+ );
27
+ console.error(" npm install -g omnish");
28
+ console.error(" npm rebuild -g omnish");
29
+ console.error(formatNativeModuleNodeHint());
30
+ }
23
31
  }
24
32
  }
25
33
 
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * preinstall guard — block unsupported Node with actionable upgrade steps.
4
+ * Skip with OMNISH_SKIP_NODE_CHECK=1 (not recommended).
5
+ */
6
+ import { checkNodeVersion, formatNodeUpgradeHelp } from "./node-version.mjs";
7
+
8
+ if (process.env.OMNISH_SKIP_NODE_CHECK === "1") {
9
+ console.warn("omnish: skipping Node version check (OMNISH_SKIP_NODE_CHECK=1)");
10
+ process.exit(0);
11
+ }
12
+
13
+ const result = checkNodeVersion();
14
+ if (result.ok) {
15
+ process.exit(0);
16
+ }
17
+
18
+ console.error(formatNodeUpgradeHelp(result));
19
+ process.exit(1);
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Node.js version policy for omnish installs and runtime checks.
3
+ * matrix-js-sdk and other deps require Node 22+; package.json engines is the source of truth.
4
+ */
5
+ import fs from "node:fs";
6
+ import os from "node:os";
7
+ import path from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
+ const DEFAULT_ENGINES_NODE = ">=22.13";
12
+ const RECOMMENDED_NODE = "22";
13
+
14
+ function readEnginesNode() {
15
+ try {
16
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
17
+ return typeof pkg.engines?.node === "string" ? pkg.engines.node : DEFAULT_ENGINES_NODE;
18
+ } catch {
19
+ return DEFAULT_ENGINES_NODE;
20
+ }
21
+ }
22
+
23
+ /** @returns {{ major: number, minor: number, patch: number } | null} */
24
+ export function parseSemver(version) {
25
+ const raw = String(version).trim().replace(/^v/, "");
26
+ const m = /^(\d+)\.(\d+)\.(\d+)/.exec(raw);
27
+ if (!m) {
28
+ return null;
29
+ }
30
+ return { major: Number(m[1]), minor: Number(m[2]), patch: Number(m[3]) };
31
+ }
32
+
33
+ /** @returns {{ op: ">=" | ">" | "<=" | "<" | "=", major: number, minor: number, patch: number } | null} */
34
+ export function parseEnginesConstraint(constraint) {
35
+ const m = /^(>=|>|<=|<|=)?\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(String(constraint).trim());
36
+ if (!m) {
37
+ return null;
38
+ }
39
+ return {
40
+ op: /** @type {">=" | ">" | "<=" | "<" | "="} */ (m[1] || ">="),
41
+ major: Number(m[2]),
42
+ minor: m[3] !== undefined ? Number(m[3]) : 0,
43
+ patch: m[4] !== undefined ? Number(m[4]) : 0,
44
+ };
45
+ }
46
+
47
+ /**
48
+ * @param {{ major: number, minor: number, patch: number }} current
49
+ * @param {{ op: string, major: number, minor: number, patch: number }} required
50
+ */
51
+ export function satisfiesEngines(current, required) {
52
+ const cmp = (a, b) => {
53
+ if (a.major !== b.major) {
54
+ return a.major - b.major;
55
+ }
56
+ if (a.minor !== b.minor) {
57
+ return a.minor - b.minor;
58
+ }
59
+ return a.patch - b.patch;
60
+ };
61
+ const delta = cmp(current, required);
62
+ switch (required.op) {
63
+ case ">=":
64
+ return delta >= 0;
65
+ case ">":
66
+ return delta > 0;
67
+ case "<=":
68
+ return delta <= 0;
69
+ case "<":
70
+ return delta < 0;
71
+ case "=":
72
+ return delta === 0;
73
+ default:
74
+ return delta >= 0;
75
+ }
76
+ }
77
+
78
+ /**
79
+ * @param {string} [nodeVersion] process.version
80
+ * @param {string} [enginesNode] package.json engines.node
81
+ */
82
+ export function checkNodeVersion(nodeVersion = process.version, enginesNode = readEnginesNode()) {
83
+ const current = parseSemver(nodeVersion);
84
+ const required = parseEnginesConstraint(enginesNode);
85
+ if (!current || !required) {
86
+ return {
87
+ ok: false,
88
+ current: nodeVersion,
89
+ required: enginesNode,
90
+ recommended: RECOMMENDED_NODE,
91
+ reason: "could not parse Node or engines constraint",
92
+ };
93
+ }
94
+ const ok = satisfiesEngines(current, required);
95
+ return {
96
+ ok,
97
+ current: `v${current.major}.${current.minor}.${current.patch}`,
98
+ required: enginesNode,
99
+ recommended: RECOMMENDED_NODE,
100
+ reason: ok ? null : `need Node ${enginesNode}, found v${current.major}.${current.minor}.${current.patch}`,
101
+ };
102
+ }
103
+
104
+ function shellComment(platform) {
105
+ if (platform === "win32") {
106
+ return "REM";
107
+ }
108
+ return "#";
109
+ }
110
+
111
+ /**
112
+ * @param {string} [platform] os.platform()
113
+ */
114
+ export function formatNodeUpgradeHelp(result, platform = os.platform()) {
115
+ const lines = [];
116
+ const c = shellComment(platform);
117
+ lines.push("");
118
+ lines.push("omnish needs a newer Node.js to install and run.");
119
+ lines.push(` Required : Node ${result.required} (see package.json engines)`);
120
+ lines.push(` You have : ${result.current}`);
121
+ lines.push(` Recommend: Node ${result.recommended} LTS (matches .nvmrc in the repo)`);
122
+ lines.push("");
123
+ lines.push("Why: omnish ships native addons (better-sqlite3, node-pty) and depends on");
124
+ lines.push("packages that require Node 22+. Older Node often fails at install or first run.");
125
+ lines.push("");
126
+ lines.push("Pick one upgrade path, then re-run:");
127
+ lines.push(` npm install -g omnish`);
128
+ lines.push("");
129
+
130
+ if (platform === "win32") {
131
+ lines.push("Windows — nvm-windows (recommended if you use nvm):");
132
+ lines.push(" nvm install 22");
133
+ lines.push(" nvm use 22");
134
+ lines.push(" node -v");
135
+ lines.push(" npm install -g omnish");
136
+ lines.push("");
137
+ lines.push("Windows — official installer / winget:");
138
+ lines.push(" winget install OpenJS.NodeJS.LTS");
139
+ lines.push(" node -v");
140
+ lines.push(" npm install -g omnish");
141
+ lines.push("");
142
+ lines.push("If npm still uses an old Node, open a new terminal after upgrading.");
143
+ return lines.join("\n");
144
+ }
145
+
146
+ if (platform === "darwin") {
147
+ lines.push("macOS — nvm (install + set default + install omnish):");
148
+ lines.push(`${c} install nvm: https://github.com/nvm-sh/nvm#installing-and-updating`);
149
+ lines.push(" curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash");
150
+ lines.push(`${c} restart your shell, then:`);
151
+ lines.push(" nvm install 22");
152
+ lines.push(" nvm alias default 22");
153
+ lines.push(" node -v");
154
+ lines.push(" npm install -g omnish");
155
+ lines.push("");
156
+ lines.push("macOS — Homebrew:");
157
+ lines.push(" brew install node@22");
158
+ lines.push(" brew link --overwrite --force node@22");
159
+ lines.push(" node -v");
160
+ lines.push(" npm install -g omnish");
161
+ lines.push("");
162
+ lines.push("macOS — fnm:");
163
+ lines.push(" fnm install 22");
164
+ lines.push(" fnm default 22");
165
+ lines.push(" npm install -g omnish");
166
+ return lines.join("\n");
167
+ }
168
+
169
+ lines.push("Linux — nvm (install + set default + install omnish):");
170
+ lines.push(`${c} install nvm: https://github.com/nvm-sh/nvm#installing-and-updating`);
171
+ lines.push(" curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash");
172
+ lines.push(`${c} restart your shell, then:`);
173
+ lines.push(" nvm install 22");
174
+ lines.push(" nvm alias default 22");
175
+ lines.push(" node -v");
176
+ lines.push(" npm install -g omnish");
177
+ lines.push("");
178
+ lines.push("Linux — fnm:");
179
+ lines.push(" fnm install 22");
180
+ lines.push(" fnm default 22");
181
+ lines.push(" npm install -g omnish");
182
+ lines.push("");
183
+ lines.push("Linux — NodeSource / distro packages:");
184
+ lines.push(" https://nodejs.org/en/download (pick 22.x Current/LTS)");
185
+ lines.push("");
186
+ lines.push("One-liner bootstrap (tries nvm/fnm, then installs omnish):");
187
+ lines.push(
188
+ " curl -fsSL https://raw.githubusercontent.com/labKnowledge/omnish/main/contrib/install-omnish.sh | bash",
189
+ );
190
+ return lines.join("\n");
191
+ }
192
+
193
+ /**
194
+ * @param {{ current?: string, required?: string, recommended?: string }} [overrides]
195
+ */
196
+ export function formatNativeModuleNodeHint(overrides = {}) {
197
+ const result = checkNodeVersion(overrides.current ?? process.version, overrides.required);
198
+ const lines = [
199
+ "",
200
+ "This often means Node was upgraded/downgraded after omnish was installed, or npm used",
201
+ "a different Node than your shell default.",
202
+ "",
203
+ `Node now: ${result.current} (required: ${result.required})`,
204
+ "",
205
+ "Fix:",
206
+ " 1. Switch to Node 22+ and set it as default (see commands below)",
207
+ " 2. Reinstall: npm install -g omnish",
208
+ " 3. Or rebuild natives: npm rebuild -g omnish",
209
+ formatNodeUpgradeHelp(result),
210
+ ];
211
+ return lines.join("\n");
212
+ }