@bash0816/claude-code 2.1.159 → 2.1.161-2

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/LICENSE ADDED
@@ -0,0 +1,198 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable by
79
+ such Contributor that are necessarily infringed by their Contribution(s)
80
+ alone or by combination of their Contribution(s) with the Work to
81
+ which such Contribution(s) was submitted. If You institute patent
82
+ litigation against any entity (including a cross-claim or counterclaim
83
+ in a lawsuit) alleging that the Work or a Contribution incorporated
84
+ within the Work constitutes direct or contributory patent infringement,
85
+ then any patent licenses granted to You under this License for that
86
+ Work shall terminate as of the date such litigation is filed.
87
+
88
+ 4. Redistribution. You may reproduce and distribute copies of the Work
89
+ or Derivative Works thereof in any medium, with or without
90
+ modifications, and in Source or Object form, provided that You meet
91
+ the following conditions:
92
+
93
+ (a) You must give any other recipients of the Work or Derivative Works
94
+ a copy of this License; and
95
+
96
+ (b) You must cause any modified files to carry prominent notices stating
97
+ that You changed the files; and
98
+
99
+ (c) You must retain, in the Source form of any Derivative Works that
100
+ You distribute, all copyright, patent, trademark, and attribution
101
+ notices from the Source form of the Work, excluding those notices
102
+ that do not pertain to any part of the Derivative Works; and
103
+
104
+ (d) If the Work includes a "NOTICE" text file as part of its
105
+ distribution, then any Derivative Works that You distribute must
106
+ include a readable copy of the attribution notices contained
107
+ within such NOTICE file, excluding those notices that do not
108
+ pertain to any part of the Derivative Works, in at least one of
109
+ the following places: within a NOTICE text file distributed as part
110
+ of the Derivative Works; within the Source form or documentation,
111
+ if provided along with the Derivative Works; or, within a display
112
+ generated by the Derivative Works, if and wherever such third-party
113
+ notices normally appear. The contents of the NOTICE file are for
114
+ informational purposes only and do not modify the License. You may
115
+ add Your own attribution notices within Derivative Works that You
116
+ distribute, alongside or as an addendum to the NOTICE text from the
117
+ Work, provided that such additional attribution notices cannot be
118
+ construed as modifying the License.
119
+
120
+ You may add Your own copyright statement to Your modifications and may
121
+ provide additional or different license terms and conditions for use,
122
+ reproduction, or distribution of your modifications, or for any such
123
+ Derivative Works as a whole, provided Your use, reproduction, and
124
+ distribution of the Work otherwise complies with the conditions stated
125
+ in this License.
126
+
127
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
128
+ any Contribution intentionally submitted for inclusion in the Work by
129
+ You to the Licensor shall be under the terms and conditions of this
130
+ License, without any additional terms or conditions. Notwithstanding
131
+ the above, nothing herein shall supersede or modify the terms of any
132
+ separate license agreement you may have executed with Licensor
133
+ regarding such Contributions.
134
+
135
+ 6. Trademarks. This License does not grant permission to use the trade
136
+ names, trademarks, service marks, or product names of the Licensor,
137
+ except as required for reasonable and customary use in describing the
138
+ origin of the Work and reproducing the content of the NOTICE file.
139
+
140
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to
141
+ in writing, Licensor provides the Work (and each Contributor provides
142
+ its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR
143
+ CONDITIONS OF ANY KIND, either express or implied, including, without
144
+ limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
145
+ MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
146
+ responsible for determining the appropriateness of using or
147
+ redistributing the Work and assume any risks associated with Your
148
+ exercise of permissions under this License.
149
+
150
+ 8. Limitation of Liability. In no event and under no legal theory,
151
+ whether in tort (including negligence), contract, or otherwise,
152
+ unless required by applicable law (such as deliberate and grossly
153
+ negligent acts) or agreed to in writing, shall any Contributor be
154
+ liable to You for damages, including any direct, indirect, special,
155
+ incidental, or consequential damages of any character arising as a
156
+ result of this License or out of the use or inability to use the
157
+ Work (including but not limited to damages for loss of goodwill,
158
+ work stoppage, computer failure or malfunction, or any and all
159
+ other commercial damages or losses), even if such Contributor
160
+ has been advised of the possibility of such damages.
161
+
162
+ 9. Accepting Warranty or Additional Liability. While redistributing
163
+ the Work or Derivative Works thereof, You may choose to offer,
164
+ and charge a fee for, acceptance of support, warranty, indemnity,
165
+ or other liability obligations and/or rights consistent with this
166
+ License. However, in accepting such obligations, You may act only
167
+ on Your own behalf and on Your sole responsibility, not on behalf
168
+ of any other Contributor, and only if You agree to indemnify,
169
+ defend, and hold each Contributor harmless for any liability
170
+ incurred by, or claims asserted against, such Contributor by reason
171
+ of your accepting any such warranty or additional liability.
172
+
173
+ END OF TERMS AND CONDITIONS
174
+
175
+ APPENDIX: How to apply the Apache License to your work.
176
+
177
+ To apply the Apache License to your work, attach the following
178
+ boilerplate notice, with the fields enclosed by brackets "{}"
179
+ replaced with your own identifying information. (Don't include
180
+ the brackets!) The text should be enclosed in the appropriate
181
+ comment syntax for the file format. We also recommend that a
182
+ file or class name and description of purpose be included on the
183
+ same "printed page" as the copyright notice for easier
184
+ identification within third-party archives.
185
+
186
+ Copyright {yyyy} {name of copyright owner}
187
+
188
+ Licensed under the Apache License, Version 2.0 (the "License");
189
+ you may not use this file except in compliance with the License.
190
+ You may obtain a copy of the License at
191
+
192
+ http://www.apache.org/licenses/LICENSE-2.0
193
+
194
+ Unless required by applicable law or agreed to in writing, software
195
+ distributed under the License is distributed on an "AS IS" BASIS,
196
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
197
+ See the License for the specific language governing permissions and
198
+ limitations under the License.
package/README.md CHANGED
@@ -34,16 +34,10 @@ After npm owns the `claude` bin link, normal `npm install -g` updates work.
34
34
 
35
35
  npm が `claude` bin link を管理する状態になれば、通常の `npm install -g` 更新が使えます。
36
36
 
37
- Specific audited versions:
38
-
39
- 監査済みの固定 version:
40
-
41
- Current quick examples:
42
-
43
- 現在の quick example:
37
+ Latest audited version / 最新監査済み版:
44
38
 
45
39
  ```sh
46
- npm install -g @bash0816/claude-code@2.1.157
40
+ npm install -g @bash0816/claude-code@2.1.159-13
47
41
  ```
48
42
 
49
43
  ## Update / 更新
@@ -60,6 +54,14 @@ claude update
60
54
  npm install -g @bash0816/claude-code@<latest_audited_version>
61
55
  ```
62
56
 
57
+ If you already have the repo's `2.1.161` release or the official upstream
58
+ `2.1.165` installed, install `2.1.159-13` explicitly. `claude update` will not
59
+ roll a newer installed terminal back to this repo's current audited release.
60
+
61
+ この repo の `2.1.161` release または official upstream の `2.1.165` を
62
+ すでに入れている端末では、`2.1.159-13` を明示 install してください。
63
+ `claude update` だけでは、より新しい端末をこの repo の現在の audited release に戻しません。
64
+
63
65
  Normal launch also checks the same manifest with a short timeout and prints a notice when a newer audited version is available.
64
66
 
65
67
  通常起動時も、同じ manifest を短い timeout で確認し、新しい監査済み version があれば通知します。
@@ -68,8 +70,8 @@ Normal launch also checks the same manifest with a short timeout and prints a no
68
70
 
69
71
  - Only audited versions in `config/claude-native-audited-versions.json` can run.
70
72
  - `config/claude-native-audited-versions.json` にある監査済み version だけを実行できます。
71
- - `2.1.150-1`, `2.1.150-2`, `2.1.150-3`, `2.1.153-1`, `2.1.153-2`, `2.1.153-3`, `2.1.153-4`, `2.1.118`, `2.1.119`, `2.1.121`, `2.1.122`, `2.1.123`, `2.1.126`, `2.1.128`, `2.1.136`, `2.1.137`, `2.1.138`, `2.1.139`, `2.1.140`, `2.1.141`, `2.1.142`, `2.1.143`, `2.1.144`, `2.1.150`, `2.1.153`, `2.1.157` are included in the package metadata.
72
- - `2.1.150-1`、`2.1.150-2`、`2.1.150-3`、`2.1.153-1`、`2.1.153-2`、`2.1.153-3`、`2.1.153-4`、`2.1.118`、`2.1.119`、`2.1.121`、`2.1.122`、`2.1.123`、`2.1.126`、`2.1.128`、`2.1.136`、`2.1.137`、`2.1.138`、`2.1.139`、`2.1.140`、`2.1.141`、`2.1.142`、`2.1.143`、`2.1.144`、`2.1.150`、`2.1.153`、`2.1.157` を package metadata に含めています。
73
+ - See `config/claude-native-audited-versions.json` for the full list of included versions.
74
+ - 含まれるバージョンの全リストは `config/claude-native-audited-versions.json` を参照してください。
73
75
  - The metadata file is the source of truth for the currently audited set.
74
76
  - 現在の監査済み version 集合の source of truth は metadata file です。
75
77
  - Native artifacts are cached under `${HOME}/.claude-termux-native-package`.
@@ -182,23 +182,90 @@
182
182
  "entry_end_offset": 238725072,
183
183
  "status": "termux_verified"
184
184
  },
185
- "2.1.158": {
186
- "wrapper_spec": "@anthropic-ai/claude-code@2.1.158",
187
- "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.158",
188
- "entry_js_offset": 223216532,
189
- "entry_end_offset": 238731386,
190
- "tarball_sha256": "681c094f346b3299ea624a7e4624605a061373669d7b95bd67ba4f132a6b9e5e",
191
- "tarball_integrity": "sha512-HdQpQv69huzIogSFi2OlIj9Pc2g0+WgZcoLwKIpKyWasxV8IagqSx/sNNFYFWv/q1kv4Cf2F84P2ZbNUaOvHDA==",
185
+ "2.1.159-2": {
186
+ "wrapper_spec": "@anthropic-ai/claude-code@2.1.159",
187
+ "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.159",
188
+ "entry_js_offset": 223232708,
189
+ "entry_end_offset": 238749397,
190
+ "tarball_integrity": "sha512-c8dXbuQdrotGWll46GlnXm5IPpORK2VrBSosCmI6f8t7Snc/3F58fX0MbIjJ/ycXpY0aaKuOnufCuxf7wi1Xqw==",
191
+ "tarball_sha256": "0b551634f11742310ba3b6344fb7912ba1ed8ee0ef4702eab0099d31b4eeb070",
192
192
  "status": "offset_discovered"
193
193
  },
194
- "2.1.159": {
194
+ "2.1.159-4": {
195
195
  "wrapper_spec": "@anthropic-ai/claude-code@2.1.159",
196
196
  "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.159",
197
197
  "entry_js_offset": 223232708,
198
198
  "entry_end_offset": 238749397,
199
+ "tarball_integrity": "sha512-c8dXbuQdrotGWll46GlnXm5IPpORK2VrBSosCmI6f8t7Snc/3F58fX0MbIjJ/ycXpY0aaKuOnufCuxf7wi1Xqw==",
199
200
  "tarball_sha256": "0b551634f11742310ba3b6344fb7912ba1ed8ee0ef4702eab0099d31b4eeb070",
201
+ "status": "termux_verified"
202
+ },
203
+ "2.1.159-5": {
204
+ "wrapper_spec": "@anthropic-ai/claude-code@2.1.159",
205
+ "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.159",
206
+ "entry_js_offset": 223232708,
207
+ "entry_end_offset": 238749397,
208
+ "tarball_integrity": "sha512-c8dXbuQdrotGWll46GlnXm5IPpORK2VrBSosCmI6f8t7Snc/3F58fX0MbIjJ/ycXpY0aaKuOnufCuxf7wi1Xqw==",
209
+ "tarball_sha256": "0b551634f11742310ba3b6344fb7912ba1ed8ee0ef4702eab0099d31b4eeb070",
210
+ "status": "offset_discovered"
211
+ },
212
+ "2.1.159-8": {
213
+ "wrapper_spec": "@anthropic-ai/claude-code@2.1.159",
214
+ "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.159",
215
+ "entry_js_offset": 223232708,
216
+ "entry_end_offset": 238749397,
200
217
  "tarball_integrity": "sha512-c8dXbuQdrotGWll46GlnXm5IPpORK2VrBSosCmI6f8t7Snc/3F58fX0MbIjJ/ycXpY0aaKuOnufCuxf7wi1Xqw==",
218
+ "tarball_sha256": "0b551634f11742310ba3b6344fb7912ba1ed8ee0ef4702eab0099d31b4eeb070",
219
+ "status": "termux_verified"
220
+ },
221
+ "2.1.159-13": {
222
+ "wrapper_spec": "@anthropic-ai/claude-code@2.1.159",
223
+ "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.159",
224
+ "entry_js_offset": 223232708,
225
+ "entry_end_offset": 238749397,
226
+ "tarball_integrity": "sha512-P6fld9U2MQWZfdEskwjWar4r/wXPQRiYXnwn/TVN2rURHiII0xJuWS/PeTICXMiOZYTbjEGXvPWj/N/FK9YnHA==",
227
+ "tarball_sha256": "634d412b07f04cd43ceefacd8f13166d30d8b47adb8dc2e25a7786eebc598d70",
228
+ "tarball_size": 14768,
229
+ "status": "termux_verified"
230
+ },
231
+ "2.1.161": {
232
+ "wrapper_spec": "@anthropic-ai/claude-code@2.1.161",
233
+ "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.161",
234
+ "entry_js_offset": 225551924,
235
+ "entry_end_offset": 241503454,
236
+ "tarball_integrity": "sha512-rLEzd8/q4UnTLDSAd3eYgog+G0iZ8y6K8yh0gSxf82d7uOkypYaBUkbmFENuHuzIzCIf9Yy/utCJfp6kQFjUow==",
237
+ "tarball_sha256": "e87d973bbe58593e06c101196f6417f7d950bf777cb9f1a8ff002ebf987ea066",
238
+ "tarball_size": 74314760,
201
239
  "status": "offset_discovered"
240
+ },
241
+ "2.1.161-1": {
242
+ "wrapper_spec": "@anthropic-ai/claude-code@2.1.161",
243
+ "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.161",
244
+ "entry_js_offset": 225551924,
245
+ "entry_end_offset": 241503454,
246
+ "tarball_integrity": "sha512-rLEzd8/q4UnTLDSAd3eYgog+G0iZ8y6K8yh0gSxf82d7uOkypYaBUkbmFENuHuzIzCIf9Yy/utCJfp6kQFjUow==",
247
+ "tarball_sha256": "e87d973bbe58593e06c101196f6417f7d950bf777cb9f1a8ff002ebf987ea066",
248
+ "tarball_size": 74314760,
249
+ "status": "reverted"
250
+ },
251
+ "2.1.161-2": {
252
+ "wrapper_spec": "@anthropic-ai/claude-code@2.1.161",
253
+ "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.161",
254
+ "entry_js_offset": 225551924,
255
+ "entry_end_offset": 241503454,
256
+ "tarball_integrity": "sha512-rLEzd8/q4UnTLDSAd3eYgog+G0iZ8y6K8yh0gSxf82d7uOkypYaBUkbmFENuHuzIzCIf9Yy/utCJfp6kQFjUow==",
257
+ "tarball_sha256": "e87d973bbe58593e06c101196f6417f7d950bf777cb9f1a8ff002ebf987ea066",
258
+ "tarball_size": 74314760,
259
+ "status": "offset_discovered"
260
+ },
261
+ "2.1.165": {
262
+ "wrapper_spec": "@anthropic-ai/claude-code@2.1.165",
263
+ "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.165",
264
+ "entry_js_offset": 226798932,
265
+ "entry_end_offset": 242980856,
266
+ "tarball_integrity": "sha512-uGwKxRQGTxh3BZGnX096CLf/2us5lUFnk4KerWhG4WCpRiEUSu4TUDojp/S3SUzA//FpM57fViUW07XL3T19lw==",
267
+ "tarball_sha256": "6dc6d84624bedaf5ff0948b178fdfc9c2724d8051cb00e70559e292055f7155e",
268
+ "status": "reverted"
202
269
  }
203
270
  }
204
271
  }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "manifest_version": 1,
3
3
  "package_name": "@bash0816/claude-code",
4
- "latest_audited_version": "2.1.157",
5
- "latest_candidate_version": "2.1.159",
6
- "previous_stable_version": "2.1.153",
4
+ "latest_audited_version": "2.1.159-13",
5
+ "latest_candidate_version": "2.1.161-2",
6
+ "previous_stable_version": "2.1.159-8",
7
7
  "manifest_url": "https://raw.githubusercontent.com/bash0816/ClaudeCode-Termux/main/config/claude-termux-release-manifest.json"
8
8
  }
@@ -10,6 +10,7 @@ const path = require('path');
10
10
  const packageDir = path.resolve(__dirname, '..');
11
11
  const pkg = require(path.join(packageDir, 'package.json'));
12
12
  const localManifest = require(path.join(packageDir, 'config', 'claude-termux-release-manifest.json'));
13
+ const { compareVersions } = require('./version-utils');
13
14
  const mode = process.argv[2] || 'notify';
14
15
  const currentVersion = process.argv[3] || pkg.version;
15
16
  const dryRun = process.argv.includes('--dry-run');
@@ -20,17 +21,6 @@ const ttlMs = Number(process.env.CLAUDE_TERMUX_UPDATE_CACHE_TTL_MS || String(24
20
21
  const skipCheck = process.env.CLAUDE_TERMUX_SKIP_UPDATE_CHECK === '1';
21
22
  const manifestUrl = process.env.CLAUDE_TERMUX_MANIFEST_URL || localManifest.manifest_url;
22
23
 
23
- function compareVersions(a, b) {
24
- const aParts = String(a).split('.').map(Number);
25
- const bParts = String(b).split('.').map(Number);
26
- const len = Math.max(aParts.length, bParts.length);
27
- for (let index = 0; index < len; index += 1) {
28
- const diff = (aParts[index] || 0) - (bParts[index] || 0);
29
- if (diff !== 0) return diff;
30
- }
31
- return 0;
32
- }
33
-
34
24
  function readCache() {
35
25
  try {
36
26
  return JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
@@ -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');
@@ -35,6 +36,7 @@ const packDir = fs.mkdtempSync(path.join(os.tmpdir(), `claude-code-${version}-`)
35
36
 
36
37
  try {
37
38
  const tgzPath = fetchNativeTarball(item.native_spec, packDir);
39
+ verifyTarball(tgzPath, item);
38
40
 
39
41
  const extractDir = path.join(packDir, 'native');
40
42
  fs.mkdirSync(extractDir, { recursive: true });
@@ -89,14 +91,40 @@ function fetchNativeTarball(spec, packDir) {
89
91
  } catch (error) {
90
92
  console.error(`Direct tarball fetch failed for ${spec}; falling back to npm pack.`);
91
93
  console.error(error && error.message ? error.message : String(error));
94
+ fs.rmSync(directTarball, { force: true });
92
95
  }
93
96
 
94
- run('npm', ['pack', spec, '--pack-destination', packDir]);
95
- const tgz = fs.readdirSync(packDir).find(name => name.endsWith('.tgz'));
96
- if (!tgz) {
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) {
97
106
  throw new Error('npm pack did not produce a tgz');
98
107
  }
99
- return path.join(packDir, tgz);
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
+ }
100
128
  }
101
129
 
102
130
  function validateOffsets(file, audited) {