Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/claude-code/lib/termux-run-claude-native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ function rewriteNativeChunkSource(source) {
const _bunPropertyAccessExpected = (() => {
const _ver = String(process.env.CURRENT_CLAUDE_VERSION || '');
const _m = _ver.match(/^(\d+)\.(\d+)\.(\d+)/);
if (_m && (Number(_m[1]) > 2 || Number(_m[2]) > 1 || Number(_m[3]) >= 219)) return 42;
if (_m && (Number(_m[1]) > 2 || Number(_m[2]) > 1 || Number(_m[3]) >= 216)) return 40;
if (_m && (Number(_m[1]) > 2 || Number(_m[2]) > 1 || Number(_m[3]) >= 214)) return 39;
if (_m && (Number(_m[1]) > 2 || Number(_m[2]) > 1 || Number(_m[3]) >= 205)) return 38;
Expand Down Expand Up @@ -1275,6 +1276,7 @@ function rewriteNativeChunkSource(source) {
const _bunPropertyAccessExpected = (() => {
const _ver = String(process.env.CURRENT_CLAUDE_VERSION || '');
const _m = _ver.match(/^(\d+)\.(\d+)\.(\d+)/);
if (_m && (Number(_m[1]) > 2 || Number(_m[2]) > 1 || Number(_m[3]) >= 219)) return 42;
if (_m && (Number(_m[1]) > 2 || Number(_m[2]) > 1 || Number(_m[3]) >= 216)) return 40;
if (_m && (Number(_m[1]) > 2 || Number(_m[2]) > 1 || Number(_m[3]) >= 214)) return 39;
if (_m && (Number(_m[1]) > 2 || Number(_m[2]) > 1 || Number(_m[3]) >= 205)) return 38;
Expand Down
37 changes: 37 additions & 0 deletions packages/claude-code/lib/termux-run-claude-native.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,43 @@ test('rewriteNativeChunkSource rejects stale Bun property access count for versi
}
});

test('rewriteNativeChunkSource rewrites the synthetic bundle slice (version 2.1.219)', () => {
process.env.CURRENT_CLAUDE_VERSION = '2.1.219';
try {
const { rewriteNativeChunkSource } = loadHelperApi();
const typeofBun = Array.from({ length: 7 }, () => 'typeof Bun').join('; ');
const bunProps = Array.from({ length: 42 }, (_, index) => `Bun.p${index}`).join('; ');
const source = `function(exports, require, module, __filename, __dirname) { ${typeofBun}; typeof globalThis.Bun; globalThis.Bun; ${bunProps}; npmInstallDeprecated:!0; npmInstallDeprecated:!0 }`;
const patched = rewriteNativeChunkSource(source);

assert.match(patched, /var __claudeBun = globalThis\.__claudeBunShim;/);
assert.match(patched, /typeof __claudeBun/);
assert.match(patched, /typeof globalThis\.__claudeBun/);
assert.match(patched, /globalThis\.__claudeBun/);
assert.match(patched, /__claudeBun\./);
assert.equal((patched.match(/__claudeBun\./g) || []).length, 42);
} finally {
delete process.env.CURRENT_CLAUDE_VERSION;
}
});

test('rewriteNativeChunkSource rejects stale Bun property access count for version 2.1.219', () => {
process.env.CURRENT_CLAUDE_VERSION = '2.1.219';
try {
const { rewriteNativeChunkSource } = loadHelperApi();
const typeofBun = Array.from({ length: 7 }, () => 'typeof Bun').join('; ');
const bunProps = Array.from({ length: 41 }, (_, index) => `Bun.p${index}`).join('; ');
const source = `function(exports, require, module, __filename, __dirname) { ${typeofBun}; typeof globalThis.Bun; globalThis.Bun; ${bunProps}; npmInstallDeprecated:!0; npmInstallDeprecated:!0 }`;

assert.throws(
() => rewriteNativeChunkSource(source),
/unexpected Bun property access count 41/,
);
} finally {
delete process.env.CURRENT_CLAUDE_VERSION;
}
});

test('rewriteNativeChunkSource rejects unexpected replacement counts', () => {
const { rewriteNativeChunkSource } = loadHelperApi();
const source = buildSyntheticBundleSource().replace('Bun.p30;', '');
Expand Down