Skip to content

Commit 704cfd4

Browse files
committed
fix(node): set --localstorage-file for tsx via run-tsx launcher
Node 22+ exposes localStorage; teleproto's store2 probes it at load time. tsx spawns child processes that inherit NODE_OPTIONS, not only parent argv. - Add scripts/run-tsx.cjs (default cache path, TB_LOCALSTORAGE_FILE override) - Wire start/dev/tpm npm scripts through the launcher Made-with: Cursor
1 parent ce7b225 commit 704cfd4

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "0.2.7",
44
"description": "",
55
"scripts": {
6-
"start": "tsx -r tsconfig-paths/register ./src/index.ts",
7-
"tpm": "tsx -r tsconfig-paths/register ./src/plugin/tpm.ts",
8-
"dev": "NODE_ENV=development tsx -r tsconfig-paths/register ./src/index.ts"
6+
"start": "node scripts/run-tsx.cjs ./src/index.ts",
7+
"tpm": "node scripts/run-tsx.cjs ./src/plugin/tpm.ts",
8+
"dev": "NODE_ENV=development node scripts/run-tsx.cjs ./src/index.ts"
99
},
1010
"repository": {
1111
"type": "git",

scripts/run-tsx.cjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
/**
3+
* Node 22+ exposes global localStorage backed by --localstorage-file.
4+
* teleproto → store2 touches localStorage at load time; without a valid path,
5+
* Node warns. tsx may spawn child Node processes that only inherit env, not
6+
* the parent argv flag — so this sets NODE_OPTIONS (merged with any existing).
7+
*
8+
* Override file path with TB_LOCALSTORAGE_FILE.
9+
*/
10+
const { spawnSync } = require('node:child_process');
11+
const fs = require('node:fs');
12+
const path = require('node:path');
13+
const os = require('node:os');
14+
15+
const root = path.join(__dirname, '..');
16+
const cacheBase = process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache');
17+
const defaultFile = path.join(cacheBase, 'telebox', 'node-localstorage');
18+
const lsFile = process.env.TB_LOCALSTORAGE_FILE || defaultFile;
19+
20+
fs.mkdirSync(path.dirname(lsFile), { recursive: true });
21+
22+
const tsxCli = path.join(root, 'node_modules', 'tsx', 'dist', 'cli.mjs');
23+
const entryArgs = process.argv.slice(2);
24+
if (entryArgs.length === 0) {
25+
console.error('usage: node scripts/run-tsx.cjs <script.ts> [args...]');
26+
process.exit(1);
27+
}
28+
29+
const env = { ...process.env };
30+
const flag = `--localstorage-file=${lsFile}`;
31+
const existing = (env.NODE_OPTIONS || '').trim();
32+
env.NODE_OPTIONS = existing ? `${existing} ${flag}` : flag;
33+
34+
const r = spawnSync(
35+
process.execPath,
36+
[tsxCli, '-r', 'tsconfig-paths/register', ...entryArgs],
37+
{ cwd: root, env, stdio: 'inherit' }
38+
);
39+
process.exit(r.status === null ? 1 : r.status);

0 commit comments

Comments
 (0)