@bash0816/claude-code 2.1.159-9 → 2.1.161-1

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.
@@ -2,6 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  const cp = require('child_process');
5
+ const crypto = require('crypto');
5
6
  const fs = require('fs');
6
7
  const os = require('os');
7
8
  const path = require('path');
@@ -9,9 +10,11 @@ const path = require('path');
9
10
  const packageDir = path.resolve(__dirname, '..');
10
11
  const config = require(path.join(packageDir, 'config', 'claude-native-audited-versions.json'));
11
12
  const pkg = require(path.join(packageDir, 'package.json'));
12
- const manifest = require(path.join(packageDir, 'config', 'claude-termux-release-manifest.json'));
13
- const version = process.argv[2] || manifest.default_native_version || manifest.latest_audited_version || pkg.version;
13
+ const version = process.argv[2] || pkg.version;
14
14
  const item = config.versions[version];
15
+ const curlRetries = process.env.CLAUDE_TERMUX_FETCH_RETRIES || '4';
16
+ const curlConnectTimeout = process.env.CLAUDE_TERMUX_FETCH_CONNECT_TIMEOUT || '20';
17
+ const curlMaxTime = process.env.CLAUDE_TERMUX_FETCH_MAX_TIME || '300';
15
18
 
16
19
  if (!item) {
17
20
  console.error(`Unsupported audited Claude Code version: ${version}`);
@@ -29,18 +32,15 @@ if (fs.existsSync(sourceBin)) {
29
32
  }
30
33
 
31
34
  fs.mkdirSync(versionDir, { recursive: true });
32
- const packDir = fs.mkdtempSync(path.join(os.tmpdir(), `cluade-code-${version}-`));
35
+ const packDir = fs.mkdtempSync(path.join(os.tmpdir(), `claude-code-${version}-`));
33
36
 
34
37
  try {
35
- run('npm', ['pack', item.native_spec, '--pack-destination', packDir]);
36
- const tgz = fs.readdirSync(packDir).find(name => name.endsWith('.tgz'));
37
- if (!tgz) {
38
- throw new Error('npm pack did not produce a tgz');
39
- }
38
+ const tgzPath = fetchNativeTarball(item.native_spec, packDir);
39
+ verifyTarball(tgzPath, item);
40
40
 
41
41
  const extractDir = path.join(packDir, 'native');
42
42
  fs.mkdirSync(extractDir, { recursive: true });
43
- run('tar', ['-xzf', path.join(packDir, tgz), '-C', extractDir]);
43
+ run('tar', ['-xzf', tgzPath, '-C', extractDir]);
44
44
 
45
45
  fs.rmSync(nativeDest, { recursive: true, force: true });
46
46
  fs.mkdirSync(path.dirname(nativeDest), { recursive: true });
@@ -57,6 +57,76 @@ function run(command, args) {
57
57
  }
58
58
  }
59
59
 
60
+ function runCapture(command, args) {
61
+ const result = cp.spawnSync(command, args, {
62
+ stdio: ['ignore', 'pipe', 'inherit'],
63
+ encoding: 'utf8',
64
+ });
65
+ if (result.status !== 0) {
66
+ throw new Error(`${command} ${args.join(' ')} failed`);
67
+ }
68
+ return result.stdout.trim();
69
+ }
70
+
71
+ function fetchNativeTarball(spec, packDir) {
72
+ const directTarball = path.join(packDir, 'native-package.tgz');
73
+
74
+ try {
75
+ const tarballUrl = runCapture('npm', ['view', spec, 'dist.tarball', '--json']).replace(/^"|"$/g, '');
76
+ if (!tarballUrl) {
77
+ throw new Error(`npm view did not return dist.tarball for ${spec}`);
78
+ }
79
+ run('curl', [
80
+ '--fail',
81
+ '--location',
82
+ '--retry', String(curlRetries),
83
+ '--connect-timeout', String(curlConnectTimeout),
84
+ '--max-time', String(curlMaxTime),
85
+ '--output', directTarball,
86
+ tarballUrl,
87
+ ]);
88
+ if (fs.existsSync(directTarball)) {
89
+ return directTarball;
90
+ }
91
+ } catch (error) {
92
+ console.error(`Direct tarball fetch failed for ${spec}; falling back to npm pack.`);
93
+ console.error(error && error.message ? error.message : String(error));
94
+ fs.rmSync(directTarball, { force: true });
95
+ }
96
+
97
+ const packJson = runCapture('npm', ['pack', spec, '--pack-destination', packDir, '--json']);
98
+ let packEntries;
99
+ try {
100
+ packEntries = JSON.parse(packJson);
101
+ } catch (error) {
102
+ throw new Error(`npm pack did not return valid JSON for ${spec}`);
103
+ }
104
+ const packEntry = Array.isArray(packEntries) ? packEntries.find(entry => entry && entry.filename) : null;
105
+ if (!packEntry || !packEntry.filename) {
106
+ throw new Error('npm pack did not produce a tgz');
107
+ }
108
+ return path.join(packDir, packEntry.filename);
109
+ }
110
+
111
+ function verifyTarball(file, audited) {
112
+ const buf = fs.readFileSync(file);
113
+ if (audited.tarball_sha256) {
114
+ const sha256 = crypto.createHash('sha256').update(buf).digest('hex');
115
+ if (sha256 !== audited.tarball_sha256) {
116
+ throw new Error(`tarball sha256 mismatch for ${version}`);
117
+ }
118
+ }
119
+ if (audited.tarball_integrity) {
120
+ const sha512 = `sha512-${crypto.createHash('sha512').update(buf).digest('base64')}`;
121
+ if (sha512 !== audited.tarball_integrity) {
122
+ throw new Error(`tarball integrity mismatch for ${version}`);
123
+ }
124
+ }
125
+ if (audited.tarball_size !== undefined && Number(audited.tarball_size) !== buf.length) {
126
+ throw new Error(`tarball size mismatch for ${version}`);
127
+ }
128
+ }
129
+
60
130
  function validateOffsets(file, audited) {
61
131
  const buf = fs.readFileSync(file);
62
132
  const start = Number(audited.entry_js_offset);