@bash0816/claude-code 2.1.159-3 → 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 -10
- 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 +196 -539
- 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,528 +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
|
-
get(target, key, receiver) {
|
|
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);
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
const moduleLike = { exports: {} };
|
|
533
|
-
const maybePromise = fn(moduleLike.exports, fakeRequire, moduleLike, extractedFile, workdir);
|
|
534
|
-
if (maybePromise && typeof maybePromise.then === 'function') await maybePromise;
|
|
535
|
-
await new Promise(resolve => setTimeout(resolve, 200));
|
|
536
|
-
if (asyncErrors.length > 0) throw asyncErrors[0];
|
|
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 });
|
|
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));
|
|
553
526
|
}
|
|
554
|
-
}
|
|
555
|
-
if (
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
if (error && error.code === 'CLAUDE_TERMUX_OFFICIAL_UPDATE_BLOCKED') {
|
|
562
|
-
console.error(BLOCK_MESSAGE);
|
|
563
|
-
process.exit(error.status || 1);
|
|
564
|
-
}
|
|
565
|
-
console.error(error && error.stack ? error.stack : String(error));
|
|
566
|
-
process.exit(1);
|
|
567
|
-
});
|
|
568
|
-
NODE
|
|
569
|
-
node "$_helper" "$@" </dev/null
|
|
570
|
-
_status=$?
|
|
571
|
-
rm -f "$_helper"
|
|
572
|
-
trap - EXIT HUP INT TERM
|
|
573
|
-
exit "$_status"
|
|
574
|
-
else
|
|
575
|
-
exec node - "$@" <<'NODE'
|
|
576
|
-
const fs = require('fs');
|
|
577
|
-
const path = require('path');
|
|
578
|
-
const {
|
|
579
|
-
BLOCK_MESSAGE,
|
|
580
|
-
createGuardedChildProcess,
|
|
581
|
-
} = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'lib', 'native-update-guard.js'));
|
|
582
|
-
|
|
583
|
-
const sourceBin = process.env.SOURCE_BIN;
|
|
584
|
-
const workdir = process.env.WORKDIR;
|
|
585
|
-
const entryJsOffset = Number(process.env.ENTRY_JS_OFFSET);
|
|
586
|
-
const entryEndOffset = Number(process.env.ENTRY_END_OFFSET);
|
|
587
|
-
const argv = process.argv.slice(2);
|
|
588
|
-
|
|
589
|
-
class RequestedExit extends Error {
|
|
590
|
-
constructor(code) {
|
|
591
|
-
super(`process.exit ${code}`);
|
|
592
|
-
this.name = 'RequestedExit';
|
|
593
|
-
this.code = code;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
function ensureEntryFile() {
|
|
598
|
-
const extractedFile = path.join(workdir, `cli.${entryJsOffset}.${entryEndOffset}.bare-path.js`);
|
|
599
|
-
if (fs.existsSync(extractedFile)) return extractedFile;
|
|
600
|
-
|
|
601
|
-
const len = entryEndOffset - entryJsOffset;
|
|
602
|
-
if (!(len > 0)) throw new Error('invalid replay offsets');
|
|
603
|
-
|
|
604
|
-
const fd = fs.openSync(sourceBin, 'r');
|
|
605
|
-
const buf = Buffer.alloc(len);
|
|
606
|
-
fs.readSync(fd, buf, 0, len, entryJsOffset);
|
|
607
|
-
fs.closeSync(fd);
|
|
608
|
-
|
|
609
|
-
fs.writeFileSync(extractedFile, buf.toString('utf8').replace(/[\0\s]+$/g, ''));
|
|
610
|
-
return extractedFile;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
function createFakeRequire(realRequire) {
|
|
614
|
-
const realChild = realRequire('child_process');
|
|
615
|
-
|
|
616
|
-
function rewriteArgs(args) {
|
|
617
|
-
if (
|
|
618
|
-
Array.isArray(args) &&
|
|
619
|
-
args[0] === 'xdg-open' &&
|
|
620
|
-
Array.isArray(args[1]) &&
|
|
621
|
-
typeof args[1][0] === 'string'
|
|
622
|
-
) {
|
|
623
|
-
return ['termux-open-url', [args[1][0]], ...args.slice(2)];
|
|
624
|
-
}
|
|
625
|
-
return args;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
const guardedChild = createGuardedChildProcess(
|
|
629
|
-
{
|
|
630
|
-
spawn: (...args) => realChild.spawn(...rewriteArgs(args)),
|
|
631
|
-
execFile: (...args) => realChild.execFile(...args),
|
|
632
|
-
exec: (...args) => realChild.exec(...args),
|
|
633
|
-
spawnSync: (...args) => realChild.spawnSync(...rewriteArgs(args)),
|
|
634
|
-
execFileSync: (...args) => realChild.execFileSync(...args),
|
|
635
|
-
execSync: (...args) => realChild.execSync(...args),
|
|
636
|
-
},
|
|
637
|
-
value => process.stderr.write(value),
|
|
638
|
-
);
|
|
639
|
-
|
|
640
|
-
return function fakeRequire(id) {
|
|
641
|
-
if (id === 'ws') {
|
|
642
|
-
class WS {
|
|
643
|
-
on() {}
|
|
644
|
-
once() {}
|
|
645
|
-
addEventListener() {}
|
|
646
|
-
close() {}
|
|
647
|
-
send() {}
|
|
648
|
-
ping() {}
|
|
527
|
+
};
|
|
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));
|
|
649
534
|
}
|
|
650
|
-
return
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
if (id === 'child_process') {
|
|
654
|
-
return guardedChild;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
if (id === 'node:child_process') {
|
|
658
|
-
return guardedChild;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
if (id.startsWith('/$bunfs/root/')) {
|
|
662
|
-
throw new Error('bunfs require blocked: ' + id);
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
return realRequire(id);
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
const ansiPattern =
|
|
670
|
-
/[\u001B\u009B][[\]()#;?]*(?:(?:(?:;[-a-zA-Z\d\/\#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/\#&.:=?%@~_]*)*)?(?:\u0007|\u001B\u005C|\u009C)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))/g;
|
|
671
|
-
const ansiPatternSingle = new RegExp(ansiPattern.source);
|
|
672
|
-
const debugBunShim = process.env.CLAUDE_TERMUX_DEBUG_BUN_SHIM === '1';
|
|
673
|
-
|
|
674
|
-
function stripANSI(text) {
|
|
675
|
-
if (typeof text !== 'string' || text.length === 0) return '';
|
|
676
|
-
return text.replace(ansiPattern, '');
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
function codePointWidth(codePoint) {
|
|
680
|
-
if (
|
|
681
|
-
codePoint <= 0x1f ||
|
|
682
|
-
(codePoint >= 0x7f && codePoint <= 0x9f) ||
|
|
683
|
-
(codePoint >= 0x300 && codePoint <= 0x36f) ||
|
|
684
|
-
(codePoint >= 0x200b && codePoint <= 0x200f) ||
|
|
685
|
-
codePoint === 0xfeff ||
|
|
686
|
-
(codePoint >= 0xfe00 && codePoint <= 0xfe0f)
|
|
687
|
-
) {
|
|
688
|
-
return 0;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
if (
|
|
692
|
-
(codePoint >= 0x1100 && codePoint <= 0x115f) ||
|
|
693
|
-
(codePoint >= 0x2329 && codePoint <= 0x232a) ||
|
|
694
|
-
(codePoint >= 0x2e80 && codePoint <= 0xa4cf && codePoint !== 0x303f) ||
|
|
695
|
-
(codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
|
|
696
|
-
(codePoint >= 0xf900 && codePoint <= 0xfaff) ||
|
|
697
|
-
(codePoint >= 0xfe10 && codePoint <= 0xfe19) ||
|
|
698
|
-
(codePoint >= 0xfe30 && codePoint <= 0xfe6f) ||
|
|
699
|
-
(codePoint >= 0xff00 && codePoint <= 0xff60) ||
|
|
700
|
-
(codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
|
|
701
|
-
(codePoint >= 0x1f300 && codePoint <= 0x1faf8) ||
|
|
702
|
-
(codePoint >= 0x20000 && codePoint <= 0x3fffd)
|
|
703
|
-
) {
|
|
704
|
-
return 2;
|
|
535
|
+
return origWrite(data);
|
|
536
|
+
};
|
|
705
537
|
}
|
|
706
538
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
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
|
+
};
|
|
716
557
|
}
|
|
717
|
-
|
|
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;
|
|
718
561
|
}
|
|
719
562
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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;
|
|
726
570
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
function hashValue(value, seed = 0) {
|
|
731
|
-
const FNV_OFFSET_BASIS_64 = 0xcbf29ce484222325n;
|
|
732
|
-
const FNV_PRIME_64 = 0x100000001b3n;
|
|
733
|
-
const MASK_64 = 0xffffffffffffffffn;
|
|
734
|
-
|
|
735
|
-
const seedNumber = typeof seed === 'bigint' ? Number(seed) : Number(seed);
|
|
736
|
-
const seedValue = Number.isFinite(seedNumber) ? Math.trunc(seedNumber) : 0;
|
|
737
|
-
let result = BigInt.asUintN(64, FNV_OFFSET_BASIS_64 ^ BigInt(seedValue));
|
|
738
|
-
|
|
739
|
-
const bytes = toHashBytes(value);
|
|
740
|
-
for (const byte of bytes) {
|
|
741
|
-
result ^= BigInt(byte);
|
|
742
|
-
result = (result * FNV_PRIME_64) & MASK_64;
|
|
571
|
+
write(data) {
|
|
572
|
+
if (this._closed) return;
|
|
573
|
+
if (this._options.data) this._options.data(this, Buffer.isBuffer(data) ? data : Buffer.from(data));
|
|
743
574
|
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
function which(cmd) {
|
|
749
|
-
const fs = require('fs');
|
|
750
|
-
const path = require('path');
|
|
751
|
-
|
|
752
|
-
if (typeof cmd !== 'string' || cmd.length === 0) return null;
|
|
753
|
-
|
|
754
|
-
const isExecutable = candidate => {
|
|
755
|
-
try {
|
|
756
|
-
fs.accessSync(candidate, fs.constants.X_OK);
|
|
757
|
-
const stat = fs.statSync(candidate);
|
|
758
|
-
return stat.isFile();
|
|
759
|
-
} catch {
|
|
760
|
-
return false;
|
|
761
|
-
}
|
|
762
|
-
};
|
|
763
|
-
|
|
764
|
-
if (cmd.includes(path.sep)) {
|
|
765
|
-
return isExecutable(cmd) ? path.resolve(cmd) : null;
|
|
575
|
+
resize(cols, rows) {
|
|
576
|
+
this._cols = cols;
|
|
577
|
+
this._rows = rows;
|
|
766
578
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
for (const entry of searchPath.split(path.delimiter)) {
|
|
770
|
-
if (!entry) continue;
|
|
771
|
-
const candidate = path.join(entry, cmd);
|
|
772
|
-
if (isExecutable(candidate)) return candidate;
|
|
579
|
+
close() {
|
|
580
|
+
this._closed = true;
|
|
773
581
|
}
|
|
774
|
-
return null;
|
|
775
582
|
}
|
|
776
583
|
|
|
777
|
-
function
|
|
778
|
-
const
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
i += match[0].length;
|
|
797
|
-
continue;
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
if (char === '\n') {
|
|
802
|
-
result.push(char);
|
|
803
|
-
width = 0;
|
|
804
|
-
i += 1;
|
|
805
|
-
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);
|
|
806
603
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
if (width > 0 && width + charWidth > widthLimit) {
|
|
813
|
-
result.push('\n');
|
|
814
|
-
width = 0;
|
|
604
|
+
});
|
|
605
|
+
socket.on('drain', function() {
|
|
606
|
+
if (options.socket && typeof options.socket.drain === 'function') {
|
|
607
|
+
options.socket.drain(connection);
|
|
815
608
|
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
return result.join('');
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
const result = [];
|
|
826
|
-
let line = '';
|
|
827
|
-
let lineWidth = 0;
|
|
828
|
-
let pendingSpaces = '';
|
|
829
|
-
|
|
830
|
-
for (let i = 0; i < input.length; ) {
|
|
831
|
-
const char = input[i];
|
|
832
|
-
|
|
833
|
-
if (char === '\u001b' || char === '\u009b') {
|
|
834
|
-
const match = input.slice(i).match(ansiPatternSingle);
|
|
835
|
-
if (match && match.index === 0) {
|
|
836
|
-
line += match[0];
|
|
837
|
-
i += match[0].length;
|
|
838
|
-
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);
|
|
839
614
|
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
result.push('\n');
|
|
845
|
-
line = '';
|
|
846
|
-
lineWidth = 0;
|
|
847
|
-
pendingSpaces = '';
|
|
848
|
-
i += 1;
|
|
849
|
-
continue;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
const codePoint = input.codePointAt(i);
|
|
853
|
-
const charText = String.fromCodePoint(codePoint);
|
|
854
|
-
if (charText === ' ' || charText === '\t') {
|
|
855
|
-
pendingSpaces += charText;
|
|
856
|
-
i += charText.length;
|
|
857
|
-
continue;
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
let end = i + charText.length;
|
|
861
|
-
while (end < input.length) {
|
|
862
|
-
const nextChar = input[end];
|
|
863
|
-
if (nextChar === '\n' || nextChar === ' ' || nextChar === '\t' || nextChar === '\u001b' || nextChar === '\u009b') {
|
|
864
|
-
break;
|
|
615
|
+
});
|
|
616
|
+
socket.on('error', function(error) {
|
|
617
|
+
if (options.socket && typeof options.socket.error === 'function') {
|
|
618
|
+
options.socket.error(connection, error);
|
|
865
619
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
const text = input.slice(i, end);
|
|
871
|
-
const textWidth = stringWidth(text);
|
|
872
|
-
const pendingWidth = pendingSpaces ? stringWidth(pendingSpaces) : 0;
|
|
873
|
-
|
|
874
|
-
if (lineWidth > 0 && lineWidth + pendingWidth + textWidth > widthLimit) {
|
|
875
|
-
result.push(line);
|
|
876
|
-
result.push('\n');
|
|
877
|
-
line = '';
|
|
878
|
-
lineWidth = 0;
|
|
879
|
-
pendingSpaces = '';
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
if (lineWidth > 0 && pendingSpaces) {
|
|
883
|
-
line += pendingSpaces;
|
|
884
|
-
lineWidth += pendingWidth;
|
|
620
|
+
});
|
|
621
|
+
if (options.socket && typeof options.socket.open === 'function') {
|
|
622
|
+
options.socket.open(connection);
|
|
885
623
|
}
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
line += text;
|
|
889
|
-
lineWidth += textWidth;
|
|
890
|
-
i = end;
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
if (pendingSpaces && lineWidth > 0) {
|
|
894
|
-
line += pendingSpaces;
|
|
895
|
-
}
|
|
896
|
-
if (line.length > 0) result.push(line);
|
|
897
|
-
|
|
898
|
-
return result.join('');
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
const YAML = {
|
|
902
|
-
parse(text) {
|
|
903
|
-
try {
|
|
904
|
-
const lines = String(text).split('\n');
|
|
905
|
-
const result = {};
|
|
906
|
-
for (const line of lines) {
|
|
907
|
-
const m = line.match(/^([^:#]+):\s*(.*)$/);
|
|
908
|
-
if (m) result[m[1].trim()] = m[2].trim().replace(/^['"]|['"]$/g, '');
|
|
909
|
-
}
|
|
910
|
-
return result;
|
|
911
|
-
} catch { return {}; }
|
|
912
|
-
},
|
|
913
|
-
stringify(obj) {
|
|
914
|
-
try {
|
|
915
|
-
return Object.entries(obj || {}).map(([k, v]) => k + ': ' + v).join('\n') + '\n';
|
|
916
|
-
} catch { return ''; }
|
|
917
|
-
},
|
|
918
|
-
};
|
|
919
|
-
|
|
920
|
-
function parseSemverVersion(value) {
|
|
921
|
-
const text = String(value ?? '').trim().replace(/^[v=]/, '');
|
|
922
|
-
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-]+)*)?$/);
|
|
923
|
-
if (!match) return null;
|
|
624
|
+
});
|
|
625
|
+
server.listen(options.port || 0, options.hostname || '127.0.0.1');
|
|
924
626
|
return {
|
|
925
|
-
|
|
926
|
-
|
|
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
|
+
},
|
|
927
637
|
};
|
|
928
638
|
}
|
|
929
639
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
const
|
|
936
|
-
const
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
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;
|
|
942
654
|
}
|
|
943
|
-
return 0;
|
|
944
655
|
}
|
|
945
656
|
|
|
946
|
-
const semver = {
|
|
947
|
-
order(left, right) {
|
|
948
|
-
const a = parseSemverVersion(left), b = parseSemverVersion(right);
|
|
949
|
-
if (!a || !b) return NaN;
|
|
950
|
-
for (let i = 0; i < 3; i++) {
|
|
951
|
-
const d = a.parts[i] - b.parts[i];
|
|
952
|
-
if (d) return d < 0 ? -1 : 1;
|
|
953
|
-
}
|
|
954
|
-
if (a.pre && !b.pre) return -1;
|
|
955
|
-
if (!a.pre && b.pre) return 1;
|
|
956
|
-
if (a.pre && b.pre) return comparePrerelease(a.pre, b.pre);
|
|
957
|
-
return 0;
|
|
958
|
-
},
|
|
959
|
-
satisfies(version, range) {
|
|
960
|
-
if (!version || !range) return false;
|
|
961
|
-
const v = String(version).replace(/^[v=]/, '');
|
|
962
|
-
const clean = String(range).trim();
|
|
963
|
-
if (!clean) return false;
|
|
964
|
-
if (clean.includes('||')) return clean.split('||').some(r => semver.satisfies(v, r.trim()));
|
|
965
|
-
const parts = clean.split(/\s+/).filter(Boolean);
|
|
966
|
-
if (parts.length > 1) return parts.every(p => semver.satisfies(v, p));
|
|
967
|
-
const caret = clean.match(/^\^([0-9].*)$/);
|
|
968
|
-
if (caret) {
|
|
969
|
-
const p = parseSemverVersion(caret[1]);
|
|
970
|
-
if (!p) return false;
|
|
971
|
-
const upper = p.parts[0] > 0 ? (p.parts[0] + 1) + '.0.0'
|
|
972
|
-
: p.parts[1] > 0 ? '0.' + (p.parts[1] + 1) + '.0'
|
|
973
|
-
: '0.0.' + (p.parts[2] + 1);
|
|
974
|
-
return semver.satisfies(v, '>=' + caret[1]) && semver.satisfies(v, '<' + upper);
|
|
975
|
-
}
|
|
976
|
-
const tilde = clean.match(/^~([0-9].*)$/);
|
|
977
|
-
if (tilde) {
|
|
978
|
-
const p = parseSemverVersion(tilde[1]);
|
|
979
|
-
if (!p) return false;
|
|
980
|
-
const original = tilde[1].split('.');
|
|
981
|
-
const upper = original.length >= 2
|
|
982
|
-
? p.parts[0] + '.' + (p.parts[1] + 1) + '.0'
|
|
983
|
-
: (p.parts[0] + 1) + '.0.0';
|
|
984
|
-
return semver.satisfies(v, '>=' + tilde[1]) && semver.satisfies(v, '<' + upper);
|
|
985
|
-
}
|
|
986
|
-
const m = clean.match(/^([><=!]{1,2})\s*([0-9].*)$/);
|
|
987
|
-
if (m) {
|
|
988
|
-
const cmp = semver.order(v, m[2]);
|
|
989
|
-
if (!Number.isFinite(cmp)) return false;
|
|
990
|
-
return m[1] === '>=' ? cmp >= 0 : m[1] === '>' ? cmp > 0 :
|
|
991
|
-
m[1] === '<=' ? cmp <= 0 : m[1] === '<' ? cmp < 0 :
|
|
992
|
-
m[1] === '=' || m[1] === '==' ? cmp === 0 : m[1] === '!=' ? cmp !== 0 : false;
|
|
993
|
-
}
|
|
994
|
-
const exact = parseSemverVersion(clean);
|
|
995
|
-
return exact ? semver.order(v, clean) === 0 : false;
|
|
996
|
-
},
|
|
997
|
-
};
|
|
998
|
-
|
|
999
|
-
|
|
1000
657
|
async function main() {
|
|
1001
658
|
const extractedFile = ensureEntryFile();
|
|
1002
659
|
const code = fs.readFileSync(extractedFile, 'utf8');
|
|
@@ -1023,15 +680,20 @@ async function main() {
|
|
|
1023
680
|
stringWidth,
|
|
1024
681
|
hash: hashValue,
|
|
1025
682
|
which,
|
|
683
|
+
spawn: bunSpawn,
|
|
1026
684
|
wrapAnsi,
|
|
1027
685
|
stripANSI,
|
|
1028
686
|
semver,
|
|
687
|
+
Terminal: TerminalShim,
|
|
688
|
+
listen: bunListen,
|
|
689
|
+
Transpiler: BunTranspiler,
|
|
1029
690
|
YAML,
|
|
1030
691
|
gc: (sync) => {
|
|
1031
692
|
try {
|
|
1032
693
|
if (typeof global.gc === 'function') global.gc(sync === false ? false : true);
|
|
1033
694
|
} catch {}
|
|
1034
695
|
},
|
|
696
|
+
generateHeapSnapshot: () => Buffer.alloc(0),
|
|
1035
697
|
stdin: { stream: null },
|
|
1036
698
|
embeddedFiles: [],
|
|
1037
699
|
};
|
|
@@ -1073,18 +735,13 @@ async function main() {
|
|
|
1073
735
|
Object.defineProperty(process.versions, 'bun', { value: originalBun, configurable: true });
|
|
1074
736
|
}
|
|
1075
737
|
} catch {}
|
|
1076
|
-
if (hadGlobalBun) globalThis.Bun = originalGlobalBun;
|
|
1077
|
-
else delete globalThis.Bun;
|
|
1078
738
|
}
|
|
1079
739
|
}
|
|
1080
740
|
|
|
1081
|
-
main().
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
process.exit(error.status || 1);
|
|
1085
|
-
}
|
|
741
|
+
main().then(() => {
|
|
742
|
+
process.exit(process.exitCode ?? 0);
|
|
743
|
+
}).catch(error => {
|
|
1086
744
|
console.error(error && error.stack ? error.stack : String(error));
|
|
1087
745
|
process.exit(1);
|
|
1088
746
|
});
|
|
1089
747
|
NODE
|
|
1090
|
-
fi
|