react-native-update-cli 2.22.7 → 2.22.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.
Files changed (65) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/cli.json +5 -0
  4. package/lib/api.d.ts +7 -0
  5. package/lib/api.js +106 -38
  6. package/lib/app.js +3 -2
  7. package/lib/bin.js +16 -2
  8. package/lib/bundle-runner.d.ts +11 -4
  9. package/lib/bundle-runner.js +176 -90
  10. package/lib/bundle.d.ts +1 -0
  11. package/lib/bundle.js +2 -0
  12. package/lib/diff.d.ts +9 -0
  13. package/lib/diff.js +162 -120
  14. package/lib/locales/en.d.ts +1 -0
  15. package/lib/locales/en.js +1 -0
  16. package/lib/locales/zh.d.ts +1 -0
  17. package/lib/locales/zh.js +1 -0
  18. package/lib/native-package.d.ts +5 -1
  19. package/lib/native-package.js +145 -84
  20. package/lib/package.d.ts +7 -3
  21. package/lib/package.js +22 -12
  22. package/lib/types.d.ts +2 -0
  23. package/lib/utils/dep-versions.d.ts +7 -0
  24. package/lib/utils/dep-versions.js +66 -31
  25. package/lib/utils/hbcTransform.d.ts +21 -0
  26. package/lib/utils/hbcTransform.js +146 -5
  27. package/lib/utils/hermes-base.d.ts +21 -4
  28. package/lib/utils/hermes-base.js +146 -37
  29. package/lib/utils/http-helper.d.ts +6 -1
  30. package/lib/utils/http-helper.js +23 -11
  31. package/lib/utils/index.d.ts +30 -1
  32. package/lib/utils/index.js +98 -24
  33. package/lib/utils/latest-version/index.d.ts +11 -8
  34. package/lib/utils/latest-version/index.js +91 -25
  35. package/lib/utils/zip-entries.js +20 -15
  36. package/lib/utils/zip-options.d.ts +2 -0
  37. package/lib/utils/zip-options.js +9 -4
  38. package/lib/utils/zip-range.d.ts +47 -15
  39. package/lib/utils/zip-range.js +192 -83
  40. package/lib/utils/zip-raw-writer.d.ts +47 -0
  41. package/lib/utils/zip-raw-writer.js +204 -0
  42. package/lib/versions.js +19 -9
  43. package/package.json +10 -12
  44. package/src/api.ts +126 -46
  45. package/src/app.ts +3 -2
  46. package/src/bin.ts +17 -2
  47. package/src/bundle-runner.ts +225 -113
  48. package/src/bundle.ts +3 -0
  49. package/src/diff.ts +210 -153
  50. package/src/locales/en.ts +2 -0
  51. package/src/locales/zh.ts +2 -0
  52. package/src/native-package.ts +186 -96
  53. package/src/package.ts +26 -13
  54. package/src/types.ts +2 -0
  55. package/src/utils/dep-versions.ts +76 -33
  56. package/src/utils/hbcTransform.ts +194 -5
  57. package/src/utils/hermes-base.ts +156 -45
  58. package/src/utils/http-helper.ts +24 -13
  59. package/src/utils/index.ts +136 -26
  60. package/src/utils/latest-version/index.ts +109 -33
  61. package/src/utils/zip-entries.ts +18 -16
  62. package/src/utils/zip-options.ts +8 -3
  63. package/src/utils/zip-range.ts +244 -88
  64. package/src/utils/zip-raw-writer.ts +247 -0
  65. package/src/versions.ts +17 -7
@@ -0,0 +1,247 @@
1
+ // A minimal zip writer that copies entries *as stored* — their compressed
2
+ // bytes, CRC, sizes and timestamps straight from the source archive's central
3
+ // directory — so repacking a subset of an apk / ipa / hap costs disk I/O, not
4
+ // a second deflate of every asset (yazl can only add uncompressed data and
5
+ // re-deflates it). Plain zip only: no zip64, no data descriptors, no extra
6
+ // fields; callers must check `fitsRawZip` before choosing this writer.
7
+ import fs from 'fs-extra';
8
+ import type { Readable } from 'stream';
9
+ import type { Entry } from 'yauzl';
10
+
11
+ const LOCAL_HEADER_SIGNATURE = 0x04034b50;
12
+ const CENTRAL_HEADER_SIGNATURE = 0x02014b50;
13
+ const EOCD_SIGNATURE = 0x06054b50;
14
+ const VERSION_NEEDED_DEFAULT = 20;
15
+ /** "made by" for entries this writer creates itself: unix, spec 2.0 */
16
+ const VERSION_MADE_BY_UNIX = (3 << 8) | 20;
17
+ const FLAG_UTF8_NAMES = 0x800;
18
+ const FLAG_DATA_DESCRIPTOR = 0x8;
19
+ /** general-purpose bits carried over from a copied entry: encryption, deflate strength */
20
+ const FLAG_KEEP_MASK = 0x0007;
21
+ const MAX_UINT32 = 0xffffffff;
22
+ const MAX_UINT16 = 0xffff;
23
+ /** external attributes of a plain `-rw-r--r--` file */
24
+ const UNIX_REGULAR_FILE_ATTRIBUTES = 0o100644 << 16;
25
+
26
+ export interface RawZipEntry {
27
+ fileName: string;
28
+ compressionMethod: number;
29
+ crc32: number;
30
+ compressedSize: number;
31
+ uncompressedSize: number;
32
+ lastModFileTime: number;
33
+ lastModFileDate: number;
34
+ generalPurposeBitFlag?: number;
35
+ versionMadeBy?: number;
36
+ versionNeededToExtract?: number;
37
+ internalFileAttributes?: number;
38
+ externalFileAttributes?: number;
39
+ }
40
+
41
+ /**
42
+ * Whether an archive of `sourceSize` bytes with `entryCount` entries can be
43
+ * (partially) copied without zip64 structures: an output that only keeps a
44
+ * subset of the entries is never larger than its source.
45
+ */
46
+ export function fitsRawZip(sourceSize: number, entryCount: number): boolean {
47
+ return sourceSize < MAX_UINT32 && entryCount < MAX_UINT16;
48
+ }
49
+
50
+ let crcTable: Int32Array | undefined;
51
+ function getCrcTable(): Int32Array {
52
+ if (!crcTable) {
53
+ crcTable = new Int32Array(256);
54
+ for (let n = 0; n < 256; n++) {
55
+ let c = n;
56
+ for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
57
+ crcTable[n] = c;
58
+ }
59
+ }
60
+ return crcTable;
61
+ }
62
+
63
+ /** CRC-32 (IEEE) continued from `seed` (the running value, not inverted) */
64
+ export function crc32Update(seed: number, chunk: Buffer): number {
65
+ const table = getCrcTable();
66
+ let crc = ~seed;
67
+ for (let i = 0; i < chunk.length; i++) {
68
+ crc = table[(crc ^ chunk[i]) & 0xff] ^ (crc >>> 8);
69
+ }
70
+ return ~crc >>> 0;
71
+ }
72
+
73
+ export class RawZipWriter {
74
+ private readonly out: fs.WriteStream;
75
+ private readonly central: Buffer[] = [];
76
+ private offset = 0;
77
+ private count = 0;
78
+ private failure: Error | null = null;
79
+ private readonly closed: Promise<void>;
80
+
81
+ constructor(readonly output: string) {
82
+ this.out = fs.createWriteStream(output);
83
+ this.closed = new Promise<void>((resolve, reject) => {
84
+ this.out.once('close', resolve);
85
+ this.out.once('error', (error) => {
86
+ this.failure = error;
87
+ reject(error);
88
+ });
89
+ });
90
+ // surfaced by the next write / end(), never as an unhandled rejection
91
+ this.closed.catch(() => {});
92
+ }
93
+
94
+ /** Copy one entry with its file data exactly as stored in the source. */
95
+ async addRawEntry(meta: RawZipEntry, data: Readable): Promise<void> {
96
+ if (
97
+ meta.compressedSize > MAX_UINT32 ||
98
+ meta.uncompressedSize > MAX_UINT32 ||
99
+ this.offset > MAX_UINT32 ||
100
+ this.count >= MAX_UINT16
101
+ ) {
102
+ throw new Error(`zip64 required for ${meta.fileName}`);
103
+ }
104
+ const name = Buffer.from(meta.fileName, 'utf8');
105
+ if (name.length > MAX_UINT16) {
106
+ throw new Error(`file name too long: ${meta.fileName}`);
107
+ }
108
+ const flags =
109
+ ((meta.generalPurposeBitFlag ?? 0) &
110
+ FLAG_KEEP_MASK &
111
+ ~FLAG_DATA_DESCRIPTOR) |
112
+ FLAG_UTF8_NAMES;
113
+ const versionNeeded = Math.max(
114
+ VERSION_NEEDED_DEFAULT,
115
+ meta.versionNeededToExtract ?? 0,
116
+ );
117
+ const localOffset = this.offset;
118
+
119
+ const local = Buffer.alloc(30 + name.length);
120
+ local.writeUInt32LE(LOCAL_HEADER_SIGNATURE, 0);
121
+ local.writeUInt16LE(versionNeeded, 4);
122
+ local.writeUInt16LE(flags, 6);
123
+ local.writeUInt16LE(meta.compressionMethod, 8);
124
+ local.writeUInt16LE(meta.lastModFileTime, 10);
125
+ local.writeUInt16LE(meta.lastModFileDate, 12);
126
+ local.writeUInt32LE(meta.crc32 >>> 0, 14);
127
+ local.writeUInt32LE(meta.compressedSize, 18);
128
+ local.writeUInt32LE(meta.uncompressedSize, 22);
129
+ local.writeUInt16LE(name.length, 26);
130
+ local.writeUInt16LE(0, 28);
131
+ name.copy(local, 30);
132
+ await this.write(local);
133
+
134
+ let copied = 0;
135
+ for await (const chunk of data as AsyncIterable<Buffer>) {
136
+ copied += chunk.length;
137
+ await this.write(chunk);
138
+ }
139
+ if (copied !== meta.compressedSize) {
140
+ throw new Error(
141
+ `${meta.fileName}: read ${copied} bytes, expected ${meta.compressedSize}`,
142
+ );
143
+ }
144
+
145
+ const header = Buffer.alloc(46 + name.length);
146
+ header.writeUInt32LE(CENTRAL_HEADER_SIGNATURE, 0);
147
+ header.writeUInt16LE(meta.versionMadeBy ?? VERSION_MADE_BY_UNIX, 4);
148
+ header.writeUInt16LE(versionNeeded, 6);
149
+ header.writeUInt16LE(flags, 8);
150
+ header.writeUInt16LE(meta.compressionMethod, 10);
151
+ header.writeUInt16LE(meta.lastModFileTime, 12);
152
+ header.writeUInt16LE(meta.lastModFileDate, 14);
153
+ header.writeUInt32LE(meta.crc32 >>> 0, 16);
154
+ header.writeUInt32LE(meta.compressedSize, 20);
155
+ header.writeUInt32LE(meta.uncompressedSize, 24);
156
+ header.writeUInt16LE(name.length, 28);
157
+ header.writeUInt16LE(0, 30); // extra
158
+ header.writeUInt16LE(0, 32); // comment
159
+ header.writeUInt16LE(0, 34); // disk number start
160
+ header.writeUInt16LE(meta.internalFileAttributes ?? 0, 36);
161
+ header.writeUInt32LE(
162
+ (meta.externalFileAttributes ?? UNIX_REGULAR_FILE_ATTRIBUTES) >>> 0,
163
+ 38,
164
+ );
165
+ header.writeUInt32LE(localOffset, 42);
166
+ name.copy(header, 46);
167
+ this.central.push(header);
168
+ this.count += 1;
169
+ }
170
+
171
+ /**
172
+ * Add a local file uncompressed (its CRC is computed in a first pass).
173
+ * `like` lends its timestamp and attributes, e.g. the archive entry this
174
+ * file replaces.
175
+ */
176
+ async addStoredFile(
177
+ filePath: string,
178
+ fileName: string,
179
+ like?: Pick<
180
+ Entry,
181
+ | 'lastModFileTime'
182
+ | 'lastModFileDate'
183
+ | 'externalFileAttributes'
184
+ | 'versionMadeBy'
185
+ >,
186
+ ): Promise<void> {
187
+ let crc = 0;
188
+ let size = 0;
189
+ for await (const chunk of fs.createReadStream(
190
+ filePath,
191
+ ) as AsyncIterable<Buffer>) {
192
+ crc = crc32Update(crc, chunk);
193
+ size += chunk.length;
194
+ }
195
+ await this.addRawEntry(
196
+ {
197
+ fileName,
198
+ compressionMethod: 0,
199
+ crc32: crc,
200
+ compressedSize: size,
201
+ uncompressedSize: size,
202
+ lastModFileTime: like?.lastModFileTime ?? 0,
203
+ lastModFileDate: like?.lastModFileDate ?? 0x21, // 1980-01-01
204
+ externalFileAttributes: like?.externalFileAttributes,
205
+ versionMadeBy: like?.versionMadeBy,
206
+ },
207
+ fs.createReadStream(filePath),
208
+ );
209
+ }
210
+
211
+ /** Write the central directory and close the file. */
212
+ async end(): Promise<void> {
213
+ const cdOffset = this.offset;
214
+ for (const header of this.central) await this.write(header);
215
+ const cdSize = this.offset - cdOffset;
216
+ if (cdOffset > MAX_UINT32 || cdSize > MAX_UINT32) {
217
+ throw new Error('zip64 required for the central directory');
218
+ }
219
+ const eocd = Buffer.alloc(22);
220
+ eocd.writeUInt32LE(EOCD_SIGNATURE, 0);
221
+ eocd.writeUInt16LE(0, 4);
222
+ eocd.writeUInt16LE(0, 6);
223
+ eocd.writeUInt16LE(this.count, 8);
224
+ eocd.writeUInt16LE(this.count, 10);
225
+ eocd.writeUInt32LE(cdSize, 12);
226
+ eocd.writeUInt32LE(cdOffset, 16);
227
+ eocd.writeUInt16LE(0, 20);
228
+ await this.write(eocd);
229
+ this.out.end();
230
+ await this.closed;
231
+ }
232
+
233
+ /** Stop writing and remove the partial output. */
234
+ async abort(): Promise<void> {
235
+ this.out.destroy();
236
+ await this.closed.catch(() => {});
237
+ await fs.remove(this.output).catch(() => {});
238
+ }
239
+
240
+ private write(chunk: Buffer): Promise<void> {
241
+ if (this.failure) return Promise.reject(this.failure);
242
+ this.offset += chunk.length;
243
+ return new Promise((resolve, reject) => {
244
+ this.out.write(chunk, (error) => (error ? reject(error) : resolve()));
245
+ });
246
+ }
247
+ }
package/src/versions.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import chalk from 'chalk';
2
2
  import { compare, satisfies } from 'compare-versions';
3
- import Table from 'tty-table';
4
3
  import { doDelete, get, getAllPackages, post, put, uploadFile } from './api';
5
4
  import { getPlatform, getSelectedApp } from './app';
6
5
  import { choosePackage } from './package';
7
6
  import type { Package, Platform, Version } from './types';
8
- import { isNonInteractive, question } from './utils';
9
- import { depVersions } from './utils/dep-versions';
7
+ import { isNonInteractive, loadTtyTable, question } from './utils';
8
+ import { getDepVersions } from './utils/dep-versions';
10
9
  import { getCommitInfo } from './utils/git';
11
10
  import { getHbcVersion } from './utils/hbcTransform';
12
11
  import {
@@ -234,6 +233,8 @@ function printDepsChangesForPackage({
234
233
  ),
235
234
  );
236
235
  console.log(summaryText);
236
+ // tty-table is ~25 ms to load; only pay for it when a table is rendered
237
+ const Table = loadTtyTable();
237
238
  console.log(Table(header, rows).render());
238
239
  console.log(chalk.yellow(t('depsChangeRiskWarning')));
239
240
  return true;
@@ -532,8 +533,16 @@ export const versionCommands = {
532
533
  const nonInteractive =
533
534
  getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
534
535
 
535
- const { hash } = await uploadFile(fn, undefined, appId);
536
- const bundleMeta = await describePpkBundle(fn, options.hermesBase);
536
+ // Hashing/caching the bundle and asking git for the commit are independent
537
+ // of the upload, so they overlap with it instead of running afterwards.
538
+ // describePpkBundle never rejects (best effort); a failed upload still
539
+ // fails the publish exactly as before.
540
+ const [{ hash }, bundleMeta, commit] = await Promise.all([
541
+ uploadFile(fn, undefined, appId),
542
+ describePpkBundle(fn, options.hermesBase),
543
+ getCommitInfo(),
544
+ ]);
545
+ const depVersions = getDepVersions();
537
546
 
538
547
  const versionName =
539
548
  name ||
@@ -549,7 +558,7 @@ export const versionCommands = {
549
558
  metaInfo ??
550
559
  (nonInteractive ? '' : await question(t('versionMetaInfoQuestion'))),
551
560
  deps: depVersions,
552
- commit: await getCommitInfo(),
561
+ commit,
553
562
  // Hermes delta-mode chain metadata (old servers drop unknown fields)
554
563
  ...bundleMeta,
555
564
  });
@@ -729,7 +738,8 @@ export const versionCommands = {
729
738
  if (nonInteractive) {
730
739
  throw new Error(t('packageIdRequired'));
731
740
  }
732
- pkgId = String((await choosePackage(String(appId))).id);
741
+ // the package list was already fetched above: no second round trip
742
+ pkgId = String((await choosePackage(String(appId), allPkgs)).id);
733
743
  }
734
744
 
735
745
  if (!pkgId) {