react-native-update-cli 2.22.8 → 2.23.0

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.
@@ -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,5 +1,6 @@
1
1
  import chalk from 'chalk';
2
2
  import { compare, satisfies } from 'compare-versions';
3
+ import fs from 'fs';
3
4
  import { doDelete, get, getAllPackages, post, put, uploadFile } from './api';
4
5
  import { getPlatform, getSelectedApp } from './app';
5
6
  import { choosePackage } from './package';
@@ -533,15 +534,55 @@ export const versionCommands = {
533
534
  const nonInteractive =
534
535
  getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
535
536
 
537
+ // The source map is archived with the version so `pushy symbolicate` can
538
+ // map crashes back to source. An explicit path that does not exist is a
539
+ // publish error; no path at all is a loud warning (custom pipelines that
540
+ // never produced a map keep working).
541
+ const sourcemapPath =
542
+ typeof options.sourcemap === 'string' && options.sourcemap
543
+ ? options.sourcemap
544
+ : undefined;
545
+ if (sourcemapPath && !fs.existsSync(sourcemapPath)) {
546
+ throw new Error(t('sourceMapNotFound', { path: sourcemapPath }));
547
+ }
548
+ if (!sourcemapPath) {
549
+ console.log(chalk.yellow(t('sourceMapMissingWarning')));
550
+ }
551
+
536
552
  // Hashing/caching the bundle and asking git for the commit are independent
537
553
  // of the upload, so they overlap with it instead of running afterwards.
538
554
  // describePpkBundle never rejects (best effort); a failed upload still
539
555
  // fails the publish exactly as before.
540
- const [{ hash }, bundleMeta, commit] = await Promise.all([
556
+ // A server that predates source-map archiving (self-hosted, or a SaaS
557
+ // region not yet rolled) rejects the .map upload with 400; that must not
558
+ // fail the publish, only lose the archive.
559
+ let sourceMapUploadError: unknown;
560
+ const [{ hash }, bundleMeta, commit, sourceMapUpload] = await Promise.all([
541
561
  uploadFile(fn, undefined, appId),
542
562
  describePpkBundle(fn, options.hermesBase),
543
563
  getCommitInfo(),
564
+ sourcemapPath
565
+ ? uploadFile(sourcemapPath, undefined, appId).catch(
566
+ (error: unknown) => {
567
+ sourceMapUploadError = error;
568
+ return undefined;
569
+ },
570
+ )
571
+ : Promise.resolve(undefined),
544
572
  ]);
573
+ const sourceMapKey = sourceMapUpload?.hash;
574
+ if (sourcemapPath && !sourceMapKey) {
575
+ console.log(
576
+ chalk.yellow(
577
+ t('sourceMapUploadFailedWarning', {
578
+ error:
579
+ sourceMapUploadError instanceof Error
580
+ ? sourceMapUploadError.message
581
+ : String(sourceMapUploadError),
582
+ }),
583
+ ),
584
+ );
585
+ }
545
586
  const depVersions = getDepVersions();
546
587
 
547
588
  const versionName =
@@ -561,8 +602,13 @@ export const versionCommands = {
561
602
  commit,
562
603
  // Hermes delta-mode chain metadata (old servers drop unknown fields)
563
604
  ...bundleMeta,
605
+ // archived source map (old servers drop unknown fields)
606
+ ...(sourceMapKey ? { sourceMapKey } : {}),
564
607
  });
565
608
  console.log(t('packageUploadSuccess', { id }));
609
+ if (sourceMapKey) {
610
+ console.log(t('sourceMapArchived', { id }));
611
+ }
566
612
 
567
613
  const {
568
614
  packageId,