@bash0816/claude-code 2.1.159-4 → 2.1.159-9
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/README.md +14 -61
- package/bin/claude +2 -2
- package/config/claude-native-audited-versions.json +22 -19
- package/config/claude-termux-release-manifest.json +7 -2
- package/lib/check-updates.js +123 -13
- package/lib/postinstall.js +2 -1
- package/lib/preinstall.js +6 -0
- package/lib/prepare-native.js +9 -51
- package/lib/termux-run-claude-native.sh +193 -540
- package/package.json +5 -15
- package/lib/native-update-guard.js +0 -257
- package/lib/native-update-guard.test.js +0 -310
- package/lib/version-utils.js +0 -24
- package/lib/version-utils.test.js +0 -25
|
@@ -6,7 +6,6 @@ WORKDIR="${WORKDIR:-${HOME}/.claude-termux-native-package/launcher-workdir}"
|
|
|
6
6
|
ENTRY_JS_OFFSET="${ENTRY_JS_OFFSET:?ENTRY_JS_OFFSET is required}"
|
|
7
7
|
ENTRY_END_OFFSET="${ENTRY_END_OFFSET:?ENTRY_END_OFFSET is required}"
|
|
8
8
|
CURRENT_CLAUDE_VERSION="${CURRENT_CLAUDE_VERSION:?CURRENT_CLAUDE_VERSION is required}"
|
|
9
|
-
CLAUDE_TERMUX_PACKAGE_DIR="${CLAUDE_TERMUX_PACKAGE_DIR:?CLAUDE_TERMUX_PACKAGE_DIR is required}"
|
|
10
9
|
TERMUX_TMPDIR="${TMPDIR:-/data/data/com.termux/files/usr/tmp}"
|
|
11
10
|
SSL_CERT_DIR="${SSL_CERT_DIR:-/data/data/com.termux/files/usr/etc/tls}"
|
|
12
11
|
SSL_CERT_FILE="${SSL_CERT_FILE:-/data/data/com.termux/files/usr/etc/tls/cert.pem}"
|
|
@@ -40,24 +39,9 @@ export ENTRY_JS_OFFSET
|
|
|
40
39
|
export ENTRY_END_OFFSET
|
|
41
40
|
export CURRENT_CLAUDE_VERSION
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
for _a in "$@"; do
|
|
45
|
-
case "$_a" in
|
|
46
|
-
-p|--print) _pf=1; break ;;
|
|
47
|
-
--) break ;;
|
|
48
|
-
esac
|
|
49
|
-
done
|
|
50
|
-
|
|
51
|
-
if [ "$_pf" = "1" ] && [ "${CLAUDE_TERMUX_STDIN:-}" != "inherit" ]; then
|
|
52
|
-
_helper=$(mktemp "${TMPDIR:-/tmp}/claude-helper.XXXXXX.js")
|
|
53
|
-
trap 'rm -f "$_helper"' EXIT HUP INT TERM
|
|
54
|
-
cat <<'NODE' > "$_helper"
|
|
42
|
+
node - "$@" <<'NODE'
|
|
55
43
|
const fs = require('fs');
|
|
56
44
|
const path = require('path');
|
|
57
|
-
const {
|
|
58
|
-
BLOCK_MESSAGE,
|
|
59
|
-
createGuardedChildProcess,
|
|
60
|
-
} = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'lib', 'native-update-guard.js'));
|
|
61
45
|
|
|
62
46
|
const sourceBin = process.env.SOURCE_BIN;
|
|
63
47
|
const workdir = process.env.WORKDIR;
|
|
@@ -90,8 +74,39 @@ function ensureEntryFile() {
|
|
|
90
74
|
}
|
|
91
75
|
|
|
92
76
|
function createFakeRequire(realRequire) {
|
|
93
|
-
const
|
|
77
|
+
const realVm = realRequire('vm');
|
|
78
|
+
|
|
79
|
+
function injectBunIntoContext(context) {
|
|
80
|
+
if (!context || typeof context !== 'object') return context;
|
|
81
|
+
try {
|
|
82
|
+
if (!Object.prototype.hasOwnProperty.call(context, 'Bun')) {
|
|
83
|
+
Object.defineProperty(context, 'Bun', {
|
|
84
|
+
value: globalThis.Bun,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
} catch {}
|
|
90
|
+
return context;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!realVm.__bunShimPatched) {
|
|
94
|
+
const origCreateContext = realVm.createContext.bind(realVm);
|
|
95
|
+
const origRunInNewContext = realVm.runInNewContext.bind(realVm);
|
|
96
|
+
realVm.createContext = (ctx, ...rest) => origCreateContext(injectBunIntoContext(ctx), ...rest);
|
|
97
|
+
realVm.runInNewContext = (code, ctx, ...rest) => origRunInNewContext(code, injectBunIntoContext(ctx), ...rest);
|
|
98
|
+
const ScriptProto = realVm.Script && realVm.Script.prototype;
|
|
99
|
+
if (ScriptProto && !ScriptProto.__bunShimPatched) {
|
|
100
|
+
const origRunInContext = ScriptProto.runInContext;
|
|
101
|
+
const origRunInNewCtx = ScriptProto.runInNewContext;
|
|
102
|
+
ScriptProto.runInContext = function(ctx, ...rest) { return origRunInContext.call(this, injectBunIntoContext(ctx), ...rest); };
|
|
103
|
+
ScriptProto.runInNewContext = function(ctx, ...rest) { return origRunInNewCtx.call(this, injectBunIntoContext(ctx), ...rest); };
|
|
104
|
+
Object.defineProperty(ScriptProto, '__bunShimPatched', { value: true });
|
|
105
|
+
}
|
|
106
|
+
Object.defineProperty(realVm, '__bunShimPatched', { value: true });
|
|
107
|
+
}
|
|
94
108
|
|
|
109
|
+
const realChild = realRequire('child_process');
|
|
95
110
|
function rewriteArgs(args) {
|
|
96
111
|
if (
|
|
97
112
|
Array.isArray(args) &&
|
|
@@ -104,18 +119,6 @@ function createFakeRequire(realRequire) {
|
|
|
104
119
|
return args;
|
|
105
120
|
}
|
|
106
121
|
|
|
107
|
-
const guardedChild = createGuardedChildProcess(
|
|
108
|
-
{
|
|
109
|
-
spawn: (...args) => realChild.spawn(...rewriteArgs(args)),
|
|
110
|
-
execFile: (...args) => realChild.execFile(...args),
|
|
111
|
-
exec: (...args) => realChild.exec(...args),
|
|
112
|
-
spawnSync: (...args) => realChild.spawnSync(...rewriteArgs(args)),
|
|
113
|
-
execFileSync: (...args) => realChild.execFileSync(...args),
|
|
114
|
-
execSync: (...args) => realChild.execSync(...args),
|
|
115
|
-
},
|
|
116
|
-
value => process.stderr.write(value),
|
|
117
|
-
);
|
|
118
|
-
|
|
119
122
|
return function fakeRequire(id) {
|
|
120
123
|
if (id === 'ws') {
|
|
121
124
|
class WS {
|
|
@@ -130,12 +133,17 @@ function createFakeRequire(realRequire) {
|
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
if (id === 'child_process') {
|
|
133
|
-
return
|
|
136
|
+
return {
|
|
137
|
+
spawn: (...args) => realChild.spawn(...rewriteArgs(args)),
|
|
138
|
+
execFile: (...args) => realChild.execFile(...args),
|
|
139
|
+
exec: (...args) => realChild.exec(...args),
|
|
140
|
+
spawnSync: (...args) => realChild.spawnSync(...rewriteArgs(args)),
|
|
141
|
+
execFileSync: (...args) => realChild.execFileSync(...args),
|
|
142
|
+
execSync: (...args) => realChild.execSync(...args),
|
|
143
|
+
};
|
|
134
144
|
}
|
|
135
145
|
|
|
136
|
-
if (id === '
|
|
137
|
-
return guardedChild;
|
|
138
|
-
}
|
|
146
|
+
if (id === 'vm') return realVm;
|
|
139
147
|
|
|
140
148
|
if (id.startsWith('/$bunfs/root/')) {
|
|
141
149
|
throw new Error('bunfs require blocked: ' + id);
|
|
@@ -475,530 +483,177 @@ const semver = {
|
|
|
475
483
|
},
|
|
476
484
|
};
|
|
477
485
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const
|
|
485
|
-
const
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if (!(key in target) && typeof key !== 'symbol' && debugBunShim) {
|
|
520
|
-
console.error('[BunShim missing]', key);
|
|
521
|
-
}
|
|
522
|
-
return Reflect.get(target, key, receiver);
|
|
523
|
-
},
|
|
524
|
-
});
|
|
525
|
-
globalThis.Bun = BunProxy;
|
|
526
|
-
|
|
527
|
-
process.argv = ['node', extractedFile, ...argv];
|
|
528
|
-
process.exit = code => {
|
|
529
|
-
throw new RequestedExit(code);
|
|
486
|
+
function bunSpawn(argv, options) {
|
|
487
|
+
const childProcess = require('child_process');
|
|
488
|
+
options = options || {};
|
|
489
|
+
if (!Array.isArray(argv) || argv.length === 0) {
|
|
490
|
+
throw new TypeError('Bun.spawn expects a non-empty argv array');
|
|
491
|
+
}
|
|
492
|
+
const command = argv[0];
|
|
493
|
+
const args = argv.slice(1);
|
|
494
|
+
const terminal = options.terminal || null;
|
|
495
|
+
|
|
496
|
+
function resolveStdio(val, fallback) {
|
|
497
|
+
if (val === 'ignore' || val === 'inherit' || val === 'pipe') return val;
|
|
498
|
+
return fallback;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
let stdioSpec;
|
|
502
|
+
if (terminal) {
|
|
503
|
+
stdioSpec = ['pipe', 'pipe', 'pipe'];
|
|
504
|
+
} else if (Array.isArray(options.stdio)) {
|
|
505
|
+
stdioSpec = options.stdio.map(function(s) { return resolveStdio(s, 'pipe'); });
|
|
506
|
+
} else {
|
|
507
|
+
stdioSpec = [
|
|
508
|
+
resolveStdio(options.stdin, 'pipe'),
|
|
509
|
+
resolveStdio(options.stdout, 'pipe'),
|
|
510
|
+
resolveStdio(options.stderr, 'pipe'),
|
|
511
|
+
];
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const nodeChild = childProcess.spawn(command, args, {
|
|
515
|
+
cwd: options.cwd,
|
|
516
|
+
env: options.env || process.env,
|
|
517
|
+
detached: options.detached,
|
|
518
|
+
windowsHide: options.windowsHide,
|
|
519
|
+
stdio: stdioSpec,
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
if (terminal) {
|
|
523
|
+
const fireData = function(chunk) {
|
|
524
|
+
if (!terminal._closed && terminal._options && typeof terminal._options.data === 'function') {
|
|
525
|
+
terminal._options.data(terminal, Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
526
|
+
}
|
|
530
527
|
};
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
} catch (error) {
|
|
538
|
-
if (error instanceof RequestedExit) {
|
|
539
|
-
process.exitCode = error.code;
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
throw error;
|
|
543
|
-
} finally {
|
|
544
|
-
process.removeListener('uncaughtException', onAsyncError);
|
|
545
|
-
process.removeListener('unhandledRejection', onAsyncError);
|
|
546
|
-
process.argv = originalArgv;
|
|
547
|
-
process.exit = originalExit;
|
|
548
|
-
try {
|
|
549
|
-
if (originalBun === undefined) {
|
|
550
|
-
delete process.versions.bun;
|
|
551
|
-
} else {
|
|
552
|
-
Object.defineProperty(process.versions, 'bun', { value: originalBun, configurable: true });
|
|
528
|
+
if (nodeChild.stdout) nodeChild.stdout.on('data', fireData);
|
|
529
|
+
if (nodeChild.stderr) nodeChild.stderr.on('data', fireData);
|
|
530
|
+
const origWrite = terminal.write.bind(terminal);
|
|
531
|
+
terminal.write = function(data) {
|
|
532
|
+
if (nodeChild.stdin && !nodeChild.stdin.destroyed) {
|
|
533
|
+
nodeChild.stdin.write(Buffer.isBuffer(data) ? data : Buffer.from(data));
|
|
553
534
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
else delete globalThis.Bun;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
main().then(() => {
|
|
561
|
-
process.exit(process.exitCode ?? 0);
|
|
562
|
-
}).catch(error => {
|
|
563
|
-
if (error && error.code === 'CLAUDE_TERMUX_OFFICIAL_UPDATE_BLOCKED') {
|
|
564
|
-
console.error(BLOCK_MESSAGE);
|
|
565
|
-
process.exit(error.status || 1);
|
|
566
|
-
}
|
|
567
|
-
console.error(error && error.stack ? error.stack : String(error));
|
|
568
|
-
process.exit(1);
|
|
569
|
-
});
|
|
570
|
-
NODE
|
|
571
|
-
node "$_helper" "$@" </dev/null
|
|
572
|
-
_status=$?
|
|
573
|
-
rm -f "$_helper"
|
|
574
|
-
trap - EXIT HUP INT TERM
|
|
575
|
-
exit "$_status"
|
|
576
|
-
else
|
|
577
|
-
exec node - "$@" <<'NODE'
|
|
578
|
-
const fs = require('fs');
|
|
579
|
-
const path = require('path');
|
|
580
|
-
const {
|
|
581
|
-
BLOCK_MESSAGE,
|
|
582
|
-
createGuardedChildProcess,
|
|
583
|
-
} = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'lib', 'native-update-guard.js'));
|
|
584
|
-
|
|
585
|
-
const sourceBin = process.env.SOURCE_BIN;
|
|
586
|
-
const workdir = process.env.WORKDIR;
|
|
587
|
-
const entryJsOffset = Number(process.env.ENTRY_JS_OFFSET);
|
|
588
|
-
const entryEndOffset = Number(process.env.ENTRY_END_OFFSET);
|
|
589
|
-
const argv = process.argv.slice(2);
|
|
590
|
-
|
|
591
|
-
class RequestedExit extends Error {
|
|
592
|
-
constructor(code) {
|
|
593
|
-
super(`process.exit ${code}`);
|
|
594
|
-
this.name = 'RequestedExit';
|
|
595
|
-
this.code = code;
|
|
535
|
+
return origWrite(data);
|
|
536
|
+
};
|
|
596
537
|
}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
function ensureEntryFile() {
|
|
600
|
-
const extractedFile = path.join(workdir, `cli.${entryJsOffset}.${entryEndOffset}.bare-path.js`);
|
|
601
|
-
if (fs.existsSync(extractedFile)) return extractedFile;
|
|
602
|
-
|
|
603
|
-
const len = entryEndOffset - entryJsOffset;
|
|
604
|
-
if (!(len > 0)) throw new Error('invalid replay offsets');
|
|
605
|
-
|
|
606
|
-
const fd = fs.openSync(sourceBin, 'r');
|
|
607
|
-
const buf = Buffer.alloc(len);
|
|
608
|
-
fs.readSync(fd, buf, 0, len, entryJsOffset);
|
|
609
|
-
fs.closeSync(fd);
|
|
610
|
-
|
|
611
|
-
fs.writeFileSync(extractedFile, buf.toString('utf8').replace(/[\0\s]+$/g, ''));
|
|
612
|
-
return extractedFile;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
function createFakeRequire(realRequire) {
|
|
616
|
-
const realChild = realRequire('child_process');
|
|
617
538
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
539
|
+
nodeChild.exited = new Promise(function(resolve) {
|
|
540
|
+
nodeChild.once('exit', function(code, signal) {
|
|
541
|
+
resolve(code != null ? code : (signal ? 1 : 0));
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
function makeTextReader(stream) {
|
|
546
|
+
return {
|
|
547
|
+
text: function() {
|
|
548
|
+
return new Promise(function(resolve, reject) {
|
|
549
|
+
if (!stream) return resolve('');
|
|
550
|
+
const chunks = [];
|
|
551
|
+
stream.on('data', function(chunk) { chunks.push(chunk); });
|
|
552
|
+
stream.on('end', function() { resolve(Buffer.concat(chunks).toString('utf8')); });
|
|
553
|
+
stream.on('error', reject);
|
|
554
|
+
});
|
|
555
|
+
},
|
|
556
|
+
};
|
|
628
557
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
spawn: (...args) => realChild.spawn(...rewriteArgs(args)),
|
|
633
|
-
execFile: (...args) => realChild.execFile(...args),
|
|
634
|
-
exec: (...args) => realChild.exec(...args),
|
|
635
|
-
spawnSync: (...args) => realChild.spawnSync(...rewriteArgs(args)),
|
|
636
|
-
execFileSync: (...args) => realChild.execFileSync(...args),
|
|
637
|
-
execSync: (...args) => realChild.execSync(...args),
|
|
638
|
-
},
|
|
639
|
-
value => process.stderr.write(value),
|
|
640
|
-
);
|
|
641
|
-
|
|
642
|
-
return function fakeRequire(id) {
|
|
643
|
-
if (id === 'ws') {
|
|
644
|
-
class WS {
|
|
645
|
-
on() {}
|
|
646
|
-
once() {}
|
|
647
|
-
addEventListener() {}
|
|
648
|
-
close() {}
|
|
649
|
-
send() {}
|
|
650
|
-
ping() {}
|
|
651
|
-
}
|
|
652
|
-
return { default: WS, WebSocket: WS };
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
if (id === 'child_process') {
|
|
656
|
-
return guardedChild;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
if (id === 'node:child_process') {
|
|
660
|
-
return guardedChild;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
if (id.startsWith('/$bunfs/root/')) {
|
|
664
|
-
throw new Error('bunfs require blocked: ' + id);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
return realRequire(id);
|
|
668
|
-
};
|
|
558
|
+
if (nodeChild.stdout) Object.assign(nodeChild.stdout, makeTextReader(nodeChild.stdout));
|
|
559
|
+
if (nodeChild.stderr) Object.assign(nodeChild.stderr, makeTextReader(nodeChild.stderr));
|
|
560
|
+
return nodeChild;
|
|
669
561
|
}
|
|
670
562
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
return text.replace(ansiPattern, '');
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
function codePointWidth(codePoint) {
|
|
682
|
-
if (
|
|
683
|
-
codePoint <= 0x1f ||
|
|
684
|
-
(codePoint >= 0x7f && codePoint <= 0x9f) ||
|
|
685
|
-
(codePoint >= 0x300 && codePoint <= 0x36f) ||
|
|
686
|
-
(codePoint >= 0x200b && codePoint <= 0x200f) ||
|
|
687
|
-
codePoint === 0xfeff ||
|
|
688
|
-
(codePoint >= 0xfe00 && codePoint <= 0xfe0f)
|
|
689
|
-
) {
|
|
690
|
-
return 0;
|
|
563
|
+
class TerminalShim {
|
|
564
|
+
constructor(options) {
|
|
565
|
+
options = options || {};
|
|
566
|
+
this._options = options;
|
|
567
|
+
this._cols = options.cols || 80;
|
|
568
|
+
this._rows = options.rows || 24;
|
|
569
|
+
this._closed = false;
|
|
691
570
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
(
|
|
695
|
-
(codePoint >= 0x2329 && codePoint <= 0x232a) ||
|
|
696
|
-
(codePoint >= 0x2e80 && codePoint <= 0xa4cf && codePoint !== 0x303f) ||
|
|
697
|
-
(codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
|
|
698
|
-
(codePoint >= 0xf900 && codePoint <= 0xfaff) ||
|
|
699
|
-
(codePoint >= 0xfe10 && codePoint <= 0xfe19) ||
|
|
700
|
-
(codePoint >= 0xfe30 && codePoint <= 0xfe6f) ||
|
|
701
|
-
(codePoint >= 0xff00 && codePoint <= 0xff60) ||
|
|
702
|
-
(codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
|
|
703
|
-
(codePoint >= 0x1f300 && codePoint <= 0x1faf8) ||
|
|
704
|
-
(codePoint >= 0x20000 && codePoint <= 0x3fffd)
|
|
705
|
-
) {
|
|
706
|
-
return 2;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
return 1;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
function stringWidth(value) {
|
|
713
|
-
const text = stripANSI(typeof value === 'string' ? value : String(value ?? ''));
|
|
714
|
-
let width = 0;
|
|
715
|
-
for (const char of text) {
|
|
716
|
-
const codePoint = char.codePointAt(0);
|
|
717
|
-
width += codePointWidth(codePoint);
|
|
571
|
+
write(data) {
|
|
572
|
+
if (this._closed) return;
|
|
573
|
+
if (this._options.data) this._options.data(this, Buffer.isBuffer(data) ? data : Buffer.from(data));
|
|
718
574
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
function toHashBytes(value) {
|
|
723
|
-
if (Buffer.isBuffer(value)) return Buffer.from(value);
|
|
724
|
-
if (value instanceof Uint8Array) return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
|
|
725
|
-
if (value instanceof ArrayBuffer) return Buffer.from(value);
|
|
726
|
-
if (ArrayBuffer.isView(value)) {
|
|
727
|
-
return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
|
|
575
|
+
resize(cols, rows) {
|
|
576
|
+
this._cols = cols;
|
|
577
|
+
this._rows = rows;
|
|
728
578
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
function hashValue(value, seed = 0) {
|
|
733
|
-
const FNV_OFFSET_BASIS_64 = 0xcbf29ce484222325n;
|
|
734
|
-
const FNV_PRIME_64 = 0x100000001b3n;
|
|
735
|
-
const MASK_64 = 0xffffffffffffffffn;
|
|
736
|
-
|
|
737
|
-
const seedNumber = typeof seed === 'bigint' ? Number(seed) : Number(seed);
|
|
738
|
-
const seedValue = Number.isFinite(seedNumber) ? Math.trunc(seedNumber) : 0;
|
|
739
|
-
let result = BigInt.asUintN(64, FNV_OFFSET_BASIS_64 ^ BigInt(seedValue));
|
|
740
|
-
|
|
741
|
-
const bytes = toHashBytes(value);
|
|
742
|
-
for (const byte of bytes) {
|
|
743
|
-
result ^= BigInt(byte);
|
|
744
|
-
result = (result * FNV_PRIME_64) & MASK_64;
|
|
579
|
+
close() {
|
|
580
|
+
this._closed = true;
|
|
745
581
|
}
|
|
746
|
-
|
|
747
|
-
return BigInt(result);
|
|
748
582
|
}
|
|
749
583
|
|
|
750
|
-
function
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
const searchPath = process.env.PATH || '';
|
|
771
|
-
for (const entry of searchPath.split(path.delimiter)) {
|
|
772
|
-
if (!entry) continue;
|
|
773
|
-
const candidate = path.join(entry, cmd);
|
|
774
|
-
if (isExecutable(candidate)) return candidate;
|
|
775
|
-
}
|
|
776
|
-
return null;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
function wrapAnsi(str, columns, options) {
|
|
780
|
-
const input = typeof str === 'string' ? str : String(str ?? '');
|
|
781
|
-
const widthLimit = Number(columns);
|
|
782
|
-
if (!Number.isFinite(widthLimit) || widthLimit <= 0) return input;
|
|
783
|
-
|
|
784
|
-
const wordWrap = !options || options.wordWrap !== false;
|
|
785
|
-
const hard = !!(options && options.hard);
|
|
786
|
-
|
|
787
|
-
if (!wordWrap || hard) {
|
|
788
|
-
const result = [];
|
|
789
|
-
let width = 0;
|
|
790
|
-
|
|
791
|
-
for (let i = 0; i < input.length; ) {
|
|
792
|
-
const char = input[i];
|
|
793
|
-
|
|
794
|
-
if (char === '\u001b' || char === '\u009b') {
|
|
795
|
-
const match = input.slice(i).match(ansiPatternSingle);
|
|
796
|
-
if (match && match.index === 0) {
|
|
797
|
-
result.push(match[0]);
|
|
798
|
-
i += match[0].length;
|
|
799
|
-
continue;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
if (char === '\n') {
|
|
804
|
-
result.push(char);
|
|
805
|
-
width = 0;
|
|
806
|
-
i += 1;
|
|
807
|
-
continue;
|
|
584
|
+
function bunListen(options) {
|
|
585
|
+
const net = require('net');
|
|
586
|
+
options = options || {};
|
|
587
|
+
const sockets = new Set();
|
|
588
|
+
const server = net.createServer(function(socket) {
|
|
589
|
+
sockets.add(socket);
|
|
590
|
+
const connection = {
|
|
591
|
+
data: undefined,
|
|
592
|
+
write: function(chunk) {
|
|
593
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
594
|
+
const ok = socket.write(buffer);
|
|
595
|
+
return ok ? buffer.length : 0;
|
|
596
|
+
},
|
|
597
|
+
end: function(chunk) { socket.end(chunk); },
|
|
598
|
+
destroy: function(error) { socket.destroy(error); },
|
|
599
|
+
};
|
|
600
|
+
socket.on('data', function(chunk) {
|
|
601
|
+
if (options.socket && typeof options.socket.data === 'function') {
|
|
602
|
+
options.socket.data(connection, chunk);
|
|
808
603
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
if (width > 0 && width + charWidth > widthLimit) {
|
|
815
|
-
result.push('\n');
|
|
816
|
-
width = 0;
|
|
604
|
+
});
|
|
605
|
+
socket.on('drain', function() {
|
|
606
|
+
if (options.socket && typeof options.socket.drain === 'function') {
|
|
607
|
+
options.socket.drain(connection);
|
|
817
608
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
return result.join('');
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
const result = [];
|
|
828
|
-
let line = '';
|
|
829
|
-
let lineWidth = 0;
|
|
830
|
-
let pendingSpaces = '';
|
|
831
|
-
|
|
832
|
-
for (let i = 0; i < input.length; ) {
|
|
833
|
-
const char = input[i];
|
|
834
|
-
|
|
835
|
-
if (char === '\u001b' || char === '\u009b') {
|
|
836
|
-
const match = input.slice(i).match(ansiPatternSingle);
|
|
837
|
-
if (match && match.index === 0) {
|
|
838
|
-
line += match[0];
|
|
839
|
-
i += match[0].length;
|
|
840
|
-
continue;
|
|
609
|
+
});
|
|
610
|
+
socket.on('close', function() {
|
|
611
|
+
sockets.delete(socket);
|
|
612
|
+
if (options.socket && typeof options.socket.close === 'function') {
|
|
613
|
+
options.socket.close(connection);
|
|
841
614
|
}
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
result.push('\n');
|
|
847
|
-
line = '';
|
|
848
|
-
lineWidth = 0;
|
|
849
|
-
pendingSpaces = '';
|
|
850
|
-
i += 1;
|
|
851
|
-
continue;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
const codePoint = input.codePointAt(i);
|
|
855
|
-
const charText = String.fromCodePoint(codePoint);
|
|
856
|
-
if (charText === ' ' || charText === '\t') {
|
|
857
|
-
pendingSpaces += charText;
|
|
858
|
-
i += charText.length;
|
|
859
|
-
continue;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
let end = i + charText.length;
|
|
863
|
-
while (end < input.length) {
|
|
864
|
-
const nextChar = input[end];
|
|
865
|
-
if (nextChar === '\n' || nextChar === ' ' || nextChar === '\t' || nextChar === '\u001b' || nextChar === '\u009b') {
|
|
866
|
-
break;
|
|
615
|
+
});
|
|
616
|
+
socket.on('error', function(error) {
|
|
617
|
+
if (options.socket && typeof options.socket.error === 'function') {
|
|
618
|
+
options.socket.error(connection, error);
|
|
867
619
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
const text = input.slice(i, end);
|
|
873
|
-
const textWidth = stringWidth(text);
|
|
874
|
-
const pendingWidth = pendingSpaces ? stringWidth(pendingSpaces) : 0;
|
|
875
|
-
|
|
876
|
-
if (lineWidth > 0 && lineWidth + pendingWidth + textWidth > widthLimit) {
|
|
877
|
-
result.push(line);
|
|
878
|
-
result.push('\n');
|
|
879
|
-
line = '';
|
|
880
|
-
lineWidth = 0;
|
|
881
|
-
pendingSpaces = '';
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
if (lineWidth > 0 && pendingSpaces) {
|
|
885
|
-
line += pendingSpaces;
|
|
886
|
-
lineWidth += pendingWidth;
|
|
620
|
+
});
|
|
621
|
+
if (options.socket && typeof options.socket.open === 'function') {
|
|
622
|
+
options.socket.open(connection);
|
|
887
623
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
line += text;
|
|
891
|
-
lineWidth += textWidth;
|
|
892
|
-
i = end;
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
if (pendingSpaces && lineWidth > 0) {
|
|
896
|
-
line += pendingSpaces;
|
|
897
|
-
}
|
|
898
|
-
if (line.length > 0) result.push(line);
|
|
899
|
-
|
|
900
|
-
return result.join('');
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
const YAML = {
|
|
904
|
-
parse(text) {
|
|
905
|
-
try {
|
|
906
|
-
const lines = String(text).split('\n');
|
|
907
|
-
const result = {};
|
|
908
|
-
for (const line of lines) {
|
|
909
|
-
const m = line.match(/^([^:#]+):\s*(.*)$/);
|
|
910
|
-
if (m) result[m[1].trim()] = m[2].trim().replace(/^['"]|['"]$/g, '');
|
|
911
|
-
}
|
|
912
|
-
return result;
|
|
913
|
-
} catch { return {}; }
|
|
914
|
-
},
|
|
915
|
-
stringify(obj) {
|
|
916
|
-
try {
|
|
917
|
-
return Object.entries(obj || {}).map(([k, v]) => k + ': ' + v).join('\n') + '\n';
|
|
918
|
-
} catch { return ''; }
|
|
919
|
-
},
|
|
920
|
-
};
|
|
921
|
-
|
|
922
|
-
function parseSemverVersion(value) {
|
|
923
|
-
const text = String(value ?? '').trim().replace(/^[v=]/, '');
|
|
924
|
-
const match = text.match(/^(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/);
|
|
925
|
-
if (!match) return null;
|
|
624
|
+
});
|
|
625
|
+
server.listen(options.port || 0, options.hostname || '127.0.0.1');
|
|
926
626
|
return {
|
|
927
|
-
|
|
928
|
-
|
|
627
|
+
get port() {
|
|
628
|
+
const address = server.address();
|
|
629
|
+
return address && typeof address === 'object' ? address.port : 0;
|
|
630
|
+
},
|
|
631
|
+
stop: function(closeConnections) {
|
|
632
|
+
server.close();
|
|
633
|
+
if (closeConnections) {
|
|
634
|
+
for (const socket of sockets) socket.destroy();
|
|
635
|
+
}
|
|
636
|
+
},
|
|
929
637
|
};
|
|
930
638
|
}
|
|
931
639
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
const
|
|
938
|
-
const
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
640
|
+
class BunTranspiler {
|
|
641
|
+
constructor(_options) {}
|
|
642
|
+
transformSync(code) { return typeof code === 'string' ? code : ''; }
|
|
643
|
+
scanImports(code) {
|
|
644
|
+
const imports = [];
|
|
645
|
+
const str = String(code);
|
|
646
|
+
const reStatic = /(?:^|[^.])import\s+(?:[^'"]+\s+from\s+)?['"]([^'"]+)['"]/gm;
|
|
647
|
+
const reDynamic = /import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
648
|
+
const reRequire = /require\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
649
|
+
let m;
|
|
650
|
+
while ((m = reStatic.exec(str)) !== null) imports.push({ path: m[1], kind: 'import-statement' });
|
|
651
|
+
while ((m = reDynamic.exec(str)) !== null) imports.push({ path: m[1], kind: 'dynamic-import' });
|
|
652
|
+
while ((m = reRequire.exec(str)) !== null) imports.push({ path: m[1], kind: 'require-call' });
|
|
653
|
+
return imports;
|
|
944
654
|
}
|
|
945
|
-
return 0;
|
|
946
655
|
}
|
|
947
656
|
|
|
948
|
-
const semver = {
|
|
949
|
-
order(left, right) {
|
|
950
|
-
const a = parseSemverVersion(left), b = parseSemverVersion(right);
|
|
951
|
-
if (!a || !b) return NaN;
|
|
952
|
-
for (let i = 0; i < 3; i++) {
|
|
953
|
-
const d = a.parts[i] - b.parts[i];
|
|
954
|
-
if (d) return d < 0 ? -1 : 1;
|
|
955
|
-
}
|
|
956
|
-
if (a.pre && !b.pre) return -1;
|
|
957
|
-
if (!a.pre && b.pre) return 1;
|
|
958
|
-
if (a.pre && b.pre) return comparePrerelease(a.pre, b.pre);
|
|
959
|
-
return 0;
|
|
960
|
-
},
|
|
961
|
-
satisfies(version, range) {
|
|
962
|
-
if (!version || !range) return false;
|
|
963
|
-
const v = String(version).replace(/^[v=]/, '');
|
|
964
|
-
const clean = String(range).trim();
|
|
965
|
-
if (!clean) return false;
|
|
966
|
-
if (clean.includes('||')) return clean.split('||').some(r => semver.satisfies(v, r.trim()));
|
|
967
|
-
const parts = clean.split(/\s+/).filter(Boolean);
|
|
968
|
-
if (parts.length > 1) return parts.every(p => semver.satisfies(v, p));
|
|
969
|
-
const caret = clean.match(/^\^([0-9].*)$/);
|
|
970
|
-
if (caret) {
|
|
971
|
-
const p = parseSemverVersion(caret[1]);
|
|
972
|
-
if (!p) return false;
|
|
973
|
-
const upper = p.parts[0] > 0 ? (p.parts[0] + 1) + '.0.0'
|
|
974
|
-
: p.parts[1] > 0 ? '0.' + (p.parts[1] + 1) + '.0'
|
|
975
|
-
: '0.0.' + (p.parts[2] + 1);
|
|
976
|
-
return semver.satisfies(v, '>=' + caret[1]) && semver.satisfies(v, '<' + upper);
|
|
977
|
-
}
|
|
978
|
-
const tilde = clean.match(/^~([0-9].*)$/);
|
|
979
|
-
if (tilde) {
|
|
980
|
-
const p = parseSemverVersion(tilde[1]);
|
|
981
|
-
if (!p) return false;
|
|
982
|
-
const original = tilde[1].split('.');
|
|
983
|
-
const upper = original.length >= 2
|
|
984
|
-
? p.parts[0] + '.' + (p.parts[1] + 1) + '.0'
|
|
985
|
-
: (p.parts[0] + 1) + '.0.0';
|
|
986
|
-
return semver.satisfies(v, '>=' + tilde[1]) && semver.satisfies(v, '<' + upper);
|
|
987
|
-
}
|
|
988
|
-
const m = clean.match(/^([><=!]{1,2})\s*([0-9].*)$/);
|
|
989
|
-
if (m) {
|
|
990
|
-
const cmp = semver.order(v, m[2]);
|
|
991
|
-
if (!Number.isFinite(cmp)) return false;
|
|
992
|
-
return m[1] === '>=' ? cmp >= 0 : m[1] === '>' ? cmp > 0 :
|
|
993
|
-
m[1] === '<=' ? cmp <= 0 : m[1] === '<' ? cmp < 0 :
|
|
994
|
-
m[1] === '=' || m[1] === '==' ? cmp === 0 : m[1] === '!=' ? cmp !== 0 : false;
|
|
995
|
-
}
|
|
996
|
-
const exact = parseSemverVersion(clean);
|
|
997
|
-
return exact ? semver.order(v, clean) === 0 : false;
|
|
998
|
-
},
|
|
999
|
-
};
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
657
|
async function main() {
|
|
1003
658
|
const extractedFile = ensureEntryFile();
|
|
1004
659
|
const code = fs.readFileSync(extractedFile, 'utf8');
|
|
@@ -1025,15 +680,20 @@ async function main() {
|
|
|
1025
680
|
stringWidth,
|
|
1026
681
|
hash: hashValue,
|
|
1027
682
|
which,
|
|
683
|
+
spawn: bunSpawn,
|
|
1028
684
|
wrapAnsi,
|
|
1029
685
|
stripANSI,
|
|
1030
686
|
semver,
|
|
687
|
+
Terminal: TerminalShim,
|
|
688
|
+
listen: bunListen,
|
|
689
|
+
Transpiler: BunTranspiler,
|
|
1031
690
|
YAML,
|
|
1032
691
|
gc: (sync) => {
|
|
1033
692
|
try {
|
|
1034
693
|
if (typeof global.gc === 'function') global.gc(sync === false ? false : true);
|
|
1035
694
|
} catch {}
|
|
1036
695
|
},
|
|
696
|
+
generateHeapSnapshot: () => Buffer.alloc(0),
|
|
1037
697
|
stdin: { stream: null },
|
|
1038
698
|
embeddedFiles: [],
|
|
1039
699
|
};
|
|
@@ -1075,20 +735,13 @@ async function main() {
|
|
|
1075
735
|
Object.defineProperty(process.versions, 'bun', { value: originalBun, configurable: true });
|
|
1076
736
|
}
|
|
1077
737
|
} catch {}
|
|
1078
|
-
if (hadGlobalBun) globalThis.Bun = originalGlobalBun;
|
|
1079
|
-
else delete globalThis.Bun;
|
|
1080
738
|
}
|
|
1081
739
|
}
|
|
1082
740
|
|
|
1083
741
|
main().then(() => {
|
|
1084
742
|
process.exit(process.exitCode ?? 0);
|
|
1085
743
|
}).catch(error => {
|
|
1086
|
-
if (error && error.code === 'CLAUDE_TERMUX_OFFICIAL_UPDATE_BLOCKED') {
|
|
1087
|
-
console.error(BLOCK_MESSAGE);
|
|
1088
|
-
process.exit(error.status || 1);
|
|
1089
|
-
}
|
|
1090
744
|
console.error(error && error.stack ? error.stack : String(error));
|
|
1091
745
|
process.exit(1);
|
|
1092
746
|
});
|
|
1093
747
|
NODE
|
|
1094
|
-
fi
|