react-native-update-cli 2.29.0 → 2.29.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.
Files changed (85) hide show
  1. package/lib/account.js +2 -4
  2. package/lib/api.d.ts +1 -1
  3. package/lib/api.js +35 -73
  4. package/lib/app.js +13 -27
  5. package/lib/auto-update.d.ts +1 -1
  6. package/lib/auto-update.js +6 -16
  7. package/lib/bin.js +4 -6
  8. package/lib/bundle-pack.js +26 -60
  9. package/lib/bundle-runner.js +89 -119
  10. package/lib/bundle.js +18 -26
  11. package/lib/diff.js +43 -133
  12. package/lib/locales/en.d.ts +0 -10
  13. package/lib/locales/en.js +0 -10
  14. package/lib/locales/zh.d.ts +0 -10
  15. package/lib/locales/zh.js +0 -10
  16. package/lib/native-package.js +27 -99
  17. package/lib/package.d.ts +6 -1
  18. package/lib/package.js +56 -108
  19. package/lib/provider.js +3 -5
  20. package/lib/symbolicate.js +1 -16
  21. package/lib/utils/add-gitignore.js +0 -1
  22. package/lib/utils/app-info-parser/aab.d.ts +5 -22
  23. package/lib/utils/app-info-parser/aab.js +89 -226
  24. package/lib/utils/app-info-parser/apk.d.ts +12 -13
  25. package/lib/utils/app-info-parser/apk.js +28 -78
  26. package/lib/utils/app-info-parser/ipa.d.ts +2 -14
  27. package/lib/utils/app-info-parser/ipa.js +9 -70
  28. package/lib/utils/app-info-parser/resource-finder.d.ts +1 -34
  29. package/lib/utils/app-info-parser/resource-finder.js +95 -234
  30. package/lib/utils/app-info-parser/xml-parser/binary.d.ts +6 -55
  31. package/lib/utils/app-info-parser/xml-parser/binary.js +152 -556
  32. package/lib/utils/app-info-parser/zip.d.ts +6 -24
  33. package/lib/utils/app-info-parser/zip.js +19 -86
  34. package/lib/utils/check-plugin.d.ts +7 -5
  35. package/lib/utils/check-plugin.js +15 -25
  36. package/lib/utils/dep-versions.d.ts +0 -6
  37. package/lib/utils/dep-versions.js +2 -27
  38. package/lib/utils/failure-fingerprint.js +3 -4
  39. package/lib/utils/fs-helpers.d.ts +18 -0
  40. package/lib/utils/fs-helpers.js +84 -0
  41. package/lib/utils/git.d.ts +0 -1
  42. package/lib/utils/git.js +0 -8
  43. package/lib/utils/hash.d.ts +3 -0
  44. package/lib/utils/hash.js +19 -0
  45. package/lib/utils/hbcTransform.d.ts +9 -2
  46. package/lib/utils/hbcTransform.js +41 -70
  47. package/lib/utils/hermes-base.d.ts +1 -5
  48. package/lib/utils/hermes-base.js +136 -196
  49. package/lib/utils/hermes-literals.d.ts +5 -3
  50. package/lib/utils/hermes-literals.js +30 -53
  51. package/lib/utils/hermes-raw.d.ts +7 -0
  52. package/lib/utils/hermes-raw.js +26 -9
  53. package/lib/utils/http-helper.d.ts +0 -1
  54. package/lib/utils/http-helper.js +0 -20
  55. package/lib/utils/i18n.js +0 -2
  56. package/lib/utils/index.d.ts +5 -19
  57. package/lib/utils/index.js +95 -189
  58. package/lib/utils/latest-version.d.ts +19 -0
  59. package/lib/utils/latest-version.js +137 -0
  60. package/lib/utils/options.d.ts +2 -1
  61. package/lib/utils/options.js +5 -7
  62. package/lib/utils/runtime.d.ts +1 -1
  63. package/lib/utils/runtime.js +2 -10
  64. package/lib/utils/upload-request.d.ts +33 -0
  65. package/lib/utils/upload-request.js +120 -0
  66. package/lib/utils/zip-entries.d.ts +23 -0
  67. package/lib/utils/zip-entries.js +130 -139
  68. package/lib/utils/zip-options.js +29 -56
  69. package/lib/utils/zip-range.js +29 -69
  70. package/lib/utils/zip-raw-writer.js +6 -5
  71. package/lib/versions.d.ts +5 -0
  72. package/lib/versions.js +86 -153
  73. package/package.json +1 -9
  74. package/lib/utils/app-info-parser/app.d.ts +0 -4
  75. package/lib/utils/app-info-parser/app.js +0 -10
  76. package/lib/utils/app-info-parser/index.d.ts +0 -16
  77. package/lib/utils/app-info-parser/index.js +0 -46
  78. package/lib/utils/app-info-parser/utils.d.ts +0 -31
  79. package/lib/utils/app-info-parser/utils.js +0 -135
  80. package/lib/utils/app-info-parser/xml-parser/manifest.d.ts +0 -10
  81. package/lib/utils/app-info-parser/xml-parser/manifest.js +0 -202
  82. package/lib/utils/latest-version/index.d.ts +0 -149
  83. package/lib/utils/latest-version/index.js +0 -326
  84. package/lib/utils/plugin-config.d.ts +0 -9
  85. package/lib/utils/plugin-config.js +0 -61
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ // Streaming uploads on node:http(s): a multipart form or a raw PUT whose body
3
+ // is read from disk as it is sent, with an exact Content-Length.
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.fileContentType = fileContentType;
9
+ exports.multipartRequest = multipartRequest;
10
+ exports.sendUploadRequest = sendUploadRequest;
11
+ const crypto_1 = require("crypto");
12
+ const path_1 = __importDefault(require("path"));
13
+ const stream_1 = require("stream");
14
+ /**
15
+ * The file part's Content-Type for the extensions the CLI uploads, as the
16
+ * form-data package used to pick them (mime-types): object stores keep it as
17
+ * the stored object's type.
18
+ */
19
+ const FILE_CONTENT_TYPES = {
20
+ '.aab': 'application/x-authorware-bin',
21
+ '.apk': 'application/vnd.android.package-archive',
22
+ '.json': 'application/json',
23
+ '.map': 'application/json',
24
+ '.zip': 'application/zip',
25
+ };
26
+ function fileContentType(fileName) {
27
+ return (FILE_CONTENT_TYPES[path_1.default.extname(fileName).toLowerCase()] ??
28
+ 'application/octet-stream');
29
+ }
30
+ /**
31
+ * multipart/form-data with `fields` first and the file last. The file's size
32
+ * is known up front, so the request carries Content-Length instead of a
33
+ * chunked body: what object stores expect, and the only framing that survives
34
+ * a proxy agent's rewrite of the buffered request head.
35
+ */
36
+ function multipartRequest(fields, file) {
37
+ // A 'data' listener (the progress bar) may have set the stream flowing:
38
+ // hold its chunks until the body below reads them.
39
+ file.stream.pause();
40
+ const boundary = `--------------------------${(0, crypto_1.randomBytes)(12).toString('hex')}`;
41
+ let head = '';
42
+ for (const [name, value] of Object.entries(fields)) {
43
+ head += `--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`;
44
+ }
45
+ head +=
46
+ `--${boundary}\r\n` +
47
+ `Content-Disposition: form-data; name="file"; filename="${path_1.default.basename(file.name)}"\r\n` +
48
+ `Content-Type: ${fileContentType(file.name)}\r\n\r\n`;
49
+ const headBytes = Buffer.from(head);
50
+ const tailBytes = Buffer.from(`\r\n--${boundary}--\r\n`);
51
+ async function* parts() {
52
+ yield headBytes;
53
+ let sent = 0;
54
+ for await (const chunk of file.stream) {
55
+ sent += chunk.length;
56
+ yield chunk;
57
+ }
58
+ // a file that shrank since its size was taken would leave the request
59
+ // short of its Content-Length, waiting out the whole upload deadline
60
+ if (sent !== file.size) {
61
+ throw new Error(`${file.name} changed during the upload: sent ${sent} of ${file.size} bytes`);
62
+ }
63
+ yield tailBytes;
64
+ }
65
+ return {
66
+ method: 'POST',
67
+ headers: {
68
+ 'content-type': `multipart/form-data;boundary=${boundary}`,
69
+ 'content-length': String(headBytes.length + file.size + tailBytes.length),
70
+ },
71
+ body: stream_1.Readable.from(parts(), { objectMode: false }),
72
+ };
73
+ }
74
+ /**
75
+ * Send `request` and resolve with the response status once its head arrives
76
+ * (the body is drained and dropped). Network errors reject as they are, with
77
+ * their `code` (ECONNRESET, ...); aborting `signal` rejects with an AbortError.
78
+ */
79
+ function sendUploadRequest(url, request, options) {
80
+ const { request: send } = url.startsWith('https:')
81
+ ? require('https')
82
+ : require('http');
83
+ return new Promise((resolve, reject) => {
84
+ const req = send(url, {
85
+ method: request.method,
86
+ headers: {
87
+ accept: '*/*',
88
+ ...(options.userAgent ? { 'user-agent': options.userAgent } : {}),
89
+ ...request.headers,
90
+ },
91
+ agent: options.agent,
92
+ });
93
+ const fail = (error) => {
94
+ request.body.destroy();
95
+ req.destroy(error);
96
+ reject(error);
97
+ };
98
+ const { signal } = options;
99
+ const onAbort = () => {
100
+ fail(Object.assign(new Error('The upload was aborted'), {
101
+ name: 'AbortError',
102
+ code: 'ABORT_ERR',
103
+ }));
104
+ };
105
+ if (signal?.aborted)
106
+ return onAbort();
107
+ signal?.addEventListener('abort', onAbort, { once: true });
108
+ req.on('error', fail);
109
+ request.body.on('error', fail);
110
+ req.on('response', (res) => {
111
+ signal?.removeEventListener('abort', onAbort);
112
+ res.resume();
113
+ resolve({
114
+ status: res.statusCode ?? 0,
115
+ statusText: res.statusMessage ?? '',
116
+ });
117
+ });
118
+ request.body.pipe(req);
119
+ });
120
+ }
@@ -1,5 +1,28 @@
1
+ import type { Readable } from 'stream';
1
2
  import { type Entry, type ZipFile as YauzlZipFile } from 'yauzl';
3
+ import { ZipFile as YazlZipFile } from 'yazl';
4
+ export declare function openEntryStream(entry: Entry, zipFile: YauzlZipFile, options?: {
5
+ decodeFileData?: boolean;
6
+ }): Promise<Readable>;
2
7
  export declare function readEntry(entry: Entry, zipFile: YauzlZipFile): Promise<Buffer>;
3
8
  export declare function writeEntry(entry: Entry, zipFile: YauzlZipFile, outputPath: string): Promise<void>;
4
9
  export declare function readEntryPrefix(entry: Entry, zipFile: YauzlZipFile, maxBytes: number): Promise<Buffer>;
10
+ /** Open a local zip and stop at the first matching entry (caller closes). */
11
+ export declare function openFirstEntry(zipPath: string, matches: (name: string) => boolean): Promise<{
12
+ zipFile: YauzlZipFile;
13
+ entry: Entry;
14
+ } | null>;
15
+ /** Content of the first matching entry of a local zip, or null. */
16
+ export declare function readFirstEntry(zipPath: string, matches: (name: string) => boolean): Promise<Buffer | null>;
17
+ /** Extract the first matching entry of a local zip to `outputPath`. */
18
+ export declare function extractFirstEntry(zipPath: string, matches: (name: string) => boolean, outputPath: string): Promise<boolean>;
19
+ /**
20
+ * A yazl archive piped into `output`. `writePromise` settles once the file is
21
+ * closed; `abort` releases the fd and deletes the partial file.
22
+ */
23
+ export declare function createOutputZip(output: string): {
24
+ zipfile: YazlZipFile;
25
+ writePromise: Promise<void>;
26
+ abort: () => Promise<void>;
27
+ };
5
28
  export declare function enumZipEntries(zipFn: string, callback: (entry: Entry, zipFile: YauzlZipFile, nestedPath?: string) => Promise<any> | undefined, nestedPath?: string): Promise<unknown>;
@@ -1,161 +1,165 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.openEntryStream = openEntryStream;
39
7
  exports.readEntry = readEntry;
40
8
  exports.writeEntry = writeEntry;
41
9
  exports.readEntryPrefix = readEntryPrefix;
10
+ exports.openFirstEntry = openFirstEntry;
11
+ exports.readFirstEntry = readFirstEntry;
12
+ exports.extractFirstEntry = extractFirstEntry;
13
+ exports.createOutputZip = createOutputZip;
42
14
  exports.enumZipEntries = enumZipEntries;
43
- const fs = __importStar(require("fs-extra"));
15
+ const fs_1 = __importDefault(require("fs"));
44
16
  const os_1 = __importDefault(require("os"));
45
17
  const path_1 = __importDefault(require("path"));
46
18
  const promises_1 = require("stream/promises");
47
19
  const yauzl_1 = require("yauzl");
48
- function readEntry(entry, zipFile) {
49
- const buffers = [];
20
+ const yazl_1 = require("yazl");
21
+ const fs_helpers_1 = require("./fs-helpers");
22
+ function openEntryStream(entry, zipFile, options = {}) {
50
23
  return new Promise((resolve, reject) => {
51
- zipFile.openReadStream(entry, (err, stream) => {
52
- if (err) {
53
- return reject(err);
54
- }
55
- if (!stream) {
56
- return reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
57
- }
58
- stream.on('data', (chunk) => {
59
- buffers.push(chunk);
60
- });
61
- stream.on('end', () => {
62
- // a single chunk (a cached Range read) is handed back as-is, not copied
63
- resolve(buffers.length === 1 ? buffers[0] : Buffer.concat(buffers));
64
- });
65
- stream.on('error', (err) => {
66
- reject(err);
67
- });
68
- });
69
- });
70
- }
71
- function writeEntry(entry, zipFile, outputPath) {
72
- fs.ensureDirSync(path_1.default.dirname(outputPath));
73
- return new Promise((resolve, reject) => {
74
- zipFile.openReadStream(entry, (err, stream) => {
75
- if (err) {
76
- reject(err);
24
+ zipFile.openReadStream(entry, options, (err, stream) => {
25
+ if (err || !stream) {
26
+ reject(err ?? new Error(`Unable to read zip entry: ${entry.fileName}`));
77
27
  return;
78
28
  }
79
- if (!stream) {
80
- reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
81
- return;
82
- }
83
- (0, promises_1.pipeline)(stream, fs.createWriteStream(outputPath)).then(resolve, reject);
29
+ resolve(stream);
84
30
  });
85
31
  });
86
32
  }
87
- function readEntryPrefix(entry, zipFile, maxBytes) {
33
+ async function readEntry(entry, zipFile) {
34
+ const buffers = [];
35
+ for await (const chunk of await openEntryStream(entry, zipFile)) {
36
+ buffers.push(chunk);
37
+ }
38
+ // a single chunk (a cached Range read) is handed back as-is, not copied
39
+ return buffers.length === 1 ? buffers[0] : Buffer.concat(buffers);
40
+ }
41
+ async function writeEntry(entry, zipFile, outputPath) {
42
+ (0, fs_helpers_1.ensureDirSync)(path_1.default.dirname(outputPath));
43
+ await (0, promises_1.pipeline)(await openEntryStream(entry, zipFile), fs_1.default.createWriteStream(outputPath));
44
+ }
45
+ async function readEntryPrefix(entry, zipFile, maxBytes) {
88
46
  if (maxBytes <= 0) {
89
- return Promise.resolve(Buffer.alloc(0));
47
+ return Buffer.alloc(0);
90
48
  }
91
49
  const buffers = [];
92
50
  let length = 0;
51
+ // leaving the loop early destroys the stream without an error
52
+ for await (const chunk of await openEntryStream(entry, zipFile)) {
53
+ const slice = chunk.subarray(0, maxBytes - length);
54
+ buffers.push(slice);
55
+ length += slice.length;
56
+ if (length >= maxBytes) {
57
+ break;
58
+ }
59
+ }
60
+ return Buffer.concat(buffers, length);
61
+ }
62
+ /** Open a local zip and stop at the first matching entry (caller closes). */
63
+ function openFirstEntry(zipPath, matches) {
93
64
  return new Promise((resolve, reject) => {
94
- zipFile.openReadStream(entry, (err, stream) => {
95
- if (err) {
65
+ (0, yauzl_1.open)(zipPath, { lazyEntries: true, autoClose: false }, (err, zipFile) => {
66
+ if (err)
96
67
  return reject(err);
97
- }
98
- if (!stream) {
99
- return reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
100
- }
101
68
  let settled = false;
102
- let expectedDestroyError;
103
- const cleanup = () => {
104
- stream.off('data', onData);
105
- stream.off('end', onEnd);
106
- stream.off('error', onError);
107
- };
108
- const finish = (destroyStream = false) => {
109
- if (settled) {
110
- return;
111
- }
112
- settled = true;
113
- stream.off('data', onData);
114
- stream.off('end', onEnd);
115
- if (!destroyStream) {
116
- stream.off('error', onError);
117
- }
118
- resolve(Buffer.concat(buffers, length));
119
- if (destroyStream) {
120
- expectedDestroyError = new Error('zip entry prefix read complete');
121
- stream.destroy(expectedDestroyError);
122
- }
123
- };
124
- const onData = (chunk) => {
125
- const remaining = maxBytes - length;
126
- if (remaining <= 0) {
127
- finish(true);
128
- return;
69
+ zipFile.on('error', (error) => {
70
+ if (!settled) {
71
+ settled = true;
72
+ reject(error);
129
73
  }
130
- const slice = chunk.length > remaining ? chunk.subarray(0, remaining) : chunk;
131
- buffers.push(slice);
132
- length += slice.length;
133
- if (length >= maxBytes) {
134
- finish(true);
74
+ });
75
+ zipFile.on('end', () => {
76
+ if (!settled) {
77
+ settled = true;
78
+ zipFile.close();
79
+ resolve(null);
135
80
  }
136
- };
137
- const onEnd = () => finish();
138
- const onError = (error) => {
139
- if (settled && error === expectedDestroyError) {
140
- cleanup();
81
+ });
82
+ zipFile.on('entry', (entry) => {
83
+ if (settled)
141
84
  return;
142
- }
143
- if (settled) {
85
+ if (matches(entry.fileName)) {
86
+ settled = true;
87
+ resolve({ zipFile, entry });
144
88
  return;
145
89
  }
146
- settled = true;
147
- cleanup();
148
- reject(error);
149
- };
150
- stream.on('data', onData);
151
- stream.once('end', onEnd);
152
- stream.once('error', onError);
90
+ zipFile.readEntry();
91
+ });
92
+ zipFile.readEntry();
153
93
  });
154
94
  });
155
95
  }
96
+ /** Content of the first matching entry of a local zip, or null. */
97
+ async function readFirstEntry(zipPath, matches) {
98
+ const found = await openFirstEntry(zipPath, matches);
99
+ if (!found)
100
+ return null;
101
+ try {
102
+ return await readEntry(found.entry, found.zipFile);
103
+ }
104
+ finally {
105
+ found.zipFile.close();
106
+ }
107
+ }
108
+ /** Extract the first matching entry of a local zip to `outputPath`. */
109
+ async function extractFirstEntry(zipPath, matches, outputPath) {
110
+ const found = await openFirstEntry(zipPath, matches);
111
+ if (!found)
112
+ return false;
113
+ try {
114
+ await writeEntry(found.entry, found.zipFile, outputPath);
115
+ }
116
+ finally {
117
+ found.zipFile.close();
118
+ }
119
+ return true;
120
+ }
121
+ /**
122
+ * A yazl archive piped into `output`. `writePromise` settles once the file is
123
+ * closed; `abort` releases the fd and deletes the partial file.
124
+ */
125
+ function createOutputZip(output) {
126
+ (0, fs_helpers_1.ensureDirSync)(path_1.default.dirname(output));
127
+ const zipfile = new yazl_1.ZipFile();
128
+ const writeStream = fs_1.default.createWriteStream(output);
129
+ const writePromise = new Promise((resolve, reject) => {
130
+ zipfile.outputStream.on('error', reject);
131
+ // without this, a full disk / read-only target left the promise pending
132
+ writeStream.on('error', reject);
133
+ zipfile.outputStream.pipe(writeStream).on('close', () => {
134
+ resolve(void 0);
135
+ });
136
+ });
137
+ // a write error can come while the caller is still building entries, long
138
+ // before it awaits writePromise: mark it handled now (awaiting the original
139
+ // promise still rejects) so it never surfaces as an unhandled rejection
140
+ writePromise.catch(() => { });
141
+ // 失败时释放输出 fd 并删掉半成品,避免残留一个截断的包
142
+ const abort = async () => {
143
+ zipfile.outputStream.unpipe(writeStream);
144
+ // yazl 的 outputStream 类型声明缺 destroy,运行时是 PassThrough
145
+ zipfile.outputStream.destroy();
146
+ if (!writeStream.closed) {
147
+ // 等 fd 真正关闭再删文件,避免 Windows 上删除被占用文件失败
148
+ await new Promise((resolve) => {
149
+ writeStream.once('close', () => resolve());
150
+ if (!writeStream.destroyed) {
151
+ writeStream.destroy();
152
+ }
153
+ });
154
+ }
155
+ // best effort: a failed cleanup must not mask the original error
156
+ await fs_1.default.promises.rm(output, { force: true }).catch(() => { });
157
+ };
158
+ return { zipfile, writePromise, abort };
159
+ }
156
160
  async function enumZipEntries(zipFn, callback, nestedPath = '') {
157
161
  return new Promise((resolve, reject) => {
158
- (0, yauzl_1.open)(zipFn, { lazyEntries: true }, async (err, zipfile) => {
162
+ (0, yauzl_1.open)(zipFn, { lazyEntries: true }, (err, zipfile) => {
159
163
  if (err) {
160
164
  return reject(err);
161
165
  }
@@ -166,30 +170,17 @@ async function enumZipEntries(zipFn, callback, nestedPath = '') {
166
170
  try {
167
171
  if (!entry.fileName.endsWith('/') &&
168
172
  entry.fileName.toLowerCase().endsWith('.hap')) {
169
- const tempDir = await fs.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'nested_zip_'));
173
+ const tempDir = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'nested_zip_'));
170
174
  const tempZipPath = path_1.default.join(tempDir, 'temp.zip');
171
175
  try {
172
- await new Promise((res, rej) => {
173
- zipfile.openReadStream(entry, async (err, readStream) => {
174
- if (err)
175
- return rej(err);
176
- const writeStream = fs.createWriteStream(tempZipPath);
177
- readStream.on('error', rej);
178
- readStream.pipe(writeStream);
179
- writeStream.on('finish', () => res(void 0));
180
- writeStream.on('error', rej);
181
- });
182
- });
176
+ await writeEntry(entry, zipfile, tempZipPath);
183
177
  await enumZipEntries(tempZipPath, callback, `${fullPath}/`);
184
178
  }
185
179
  finally {
186
- await fs.remove(tempDir);
180
+ await (0, fs_helpers_1.remove)(tempDir);
187
181
  }
188
182
  }
189
- const result = callback(entry, zipfile, fullPath);
190
- if (result && typeof result.then === 'function') {
191
- await result;
192
- }
183
+ await callback(entry, zipfile, fullPath);
193
184
  }
194
185
  catch (error) {
195
186
  // the rejection carries the error; logging it here too would make
@@ -43,6 +43,7 @@ exports.zipOptionsForPayloadEntry = zipOptionsForPayloadEntry;
43
43
  exports.zipOptionsForPayloadFile = zipOptionsForPayloadFile;
44
44
  const fs = __importStar(require("fs"));
45
45
  const path_1 = __importDefault(require("path"));
46
+ const hbcTransform_1 = require("./hbcTransform");
46
47
  exports.ZIP_ENTRY_SNIFF_BYTES = 64;
47
48
  exports.MANIFEST_COMPRESSION_THRESHOLD_BYTES = 256;
48
49
  // Deflate level for the bundle/asset payload. Level 9 measured ~4x the CPU
@@ -74,9 +75,6 @@ const alreadyCompressedExtensions = new Set([
74
75
  '.zip',
75
76
  '.zst',
76
77
  ]);
77
- const HERMES_MAGIC = Buffer.from([
78
- 0xc6, 0x1f, 0xbc, 0x03, 0xc1, 0x03, 0x19, 0x1f,
79
- ]);
80
78
  const HERMES_DELTA_MAGIC = Buffer.from([
81
79
  0x39, 0xe0, 0x43, 0xfc, 0x3e, 0xfc, 0xe6, 0xe0,
82
80
  ]);
@@ -85,64 +83,39 @@ function startsWith(bytes, signature) {
85
83
  bytes.subarray(0, signature.length).equals(signature));
86
84
  }
87
85
  function hasHermesBytecodeMagic(bytes) {
88
- return (startsWith(bytes, HERMES_MAGIC) || startsWith(bytes, HERMES_DELTA_MAGIC));
86
+ return startsWith(bytes, hbcTransform_1.HBC_MAGIC) || startsWith(bytes, HERMES_DELTA_MAGIC);
89
87
  }
88
+ /** leading bytes of formats that are already compressed */
89
+ const COMPRESSED_MAGIC = [
90
+ [0x89, 0x50, 0x4e, 0x47], // PNG
91
+ [0xff, 0xd8, 0xff], // JPEG
92
+ 'GIF87a',
93
+ 'GIF89a',
94
+ [0x50, 0x4b, 0x03, 0x04], // zip
95
+ [0x50, 0x4b, 0x05, 0x06], // empty zip
96
+ [0x50, 0x4b, 0x07, 0x08], // spanned zip
97
+ [0x1f, 0x8b], // gzip
98
+ 'BZh',
99
+ [0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00], // xz
100
+ [0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c], // 7z
101
+ [0x28, 0xb5, 0x2f, 0xfd], // zstd
102
+ 'OggS',
103
+ 'ID3', // mp3 with tags
104
+ 'wOFF',
105
+ 'wOF2',
106
+ ].map((magic) => Buffer.from(magic));
90
107
  function hasAlreadyCompressedMagic(bytes) {
91
108
  if (bytes.length < 2) {
92
109
  return false;
93
110
  }
94
- if (startsWith(bytes, Buffer.from([0x89, 0x50, 0x4e, 0x47]))) {
95
- return true;
96
- }
97
- if (startsWith(bytes, Buffer.from([0xff, 0xd8, 0xff]))) {
98
- return true;
99
- }
100
- if (startsWith(bytes, Buffer.from('GIF87a', 'ascii')) ||
101
- startsWith(bytes, Buffer.from('GIF89a', 'ascii'))) {
102
- return true;
103
- }
104
- if (bytes.length >= 12 &&
105
- bytes.subarray(0, 4).equals(Buffer.from('RIFF', 'ascii')) &&
106
- bytes.subarray(8, 12).equals(Buffer.from('WEBP', 'ascii'))) {
107
- return true;
108
- }
109
- if (startsWith(bytes, Buffer.from([0x50, 0x4b, 0x03, 0x04])) ||
110
- startsWith(bytes, Buffer.from([0x50, 0x4b, 0x05, 0x06])) ||
111
- startsWith(bytes, Buffer.from([0x50, 0x4b, 0x07, 0x08]))) {
112
- return true;
113
- }
114
- if (startsWith(bytes, Buffer.from([0x1f, 0x8b]))) {
115
- return true;
116
- }
117
- if (startsWith(bytes, Buffer.from('BZh', 'ascii'))) {
118
- return true;
119
- }
120
- if (startsWith(bytes, Buffer.from([0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00]))) {
121
- return true;
122
- }
123
- if (startsWith(bytes, Buffer.from([0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c]))) {
124
- return true;
125
- }
126
- if (startsWith(bytes, Buffer.from([0x28, 0xb5, 0x2f, 0xfd]))) {
127
- return true;
128
- }
129
- if (bytes.length >= 12 && bytes.subarray(4, 8).equals(Buffer.from('ftyp'))) {
130
- return true;
131
- }
132
- if (startsWith(bytes, Buffer.from('OggS', 'ascii'))) {
133
- return true;
134
- }
135
- if (startsWith(bytes, Buffer.from('ID3', 'ascii'))) {
136
- return true;
137
- }
138
- if (bytes[0] === 0xff && bytes.length >= 2 && (bytes[1] & 0xe0) === 0xe0) {
139
- return true;
140
- }
141
- if (startsWith(bytes, Buffer.from('wOFF', 'ascii')) ||
142
- startsWith(bytes, Buffer.from('wOF2', 'ascii'))) {
143
- return true;
144
- }
145
- return false;
111
+ const at = (offset, ascii) => bytes.subarray(offset, offset + ascii.length).equals(Buffer.from(ascii));
112
+ return (COMPRESSED_MAGIC.some((magic) => startsWith(bytes, magic)) ||
113
+ // WebP: RIFF container with a WEBP form type
114
+ (bytes.length >= 12 && at(0, 'RIFF') && at(8, 'WEBP')) ||
115
+ // ISO base media (mp4, m4a, heic, avif...)
116
+ (bytes.length >= 12 && at(4, 'ftyp')) ||
117
+ // MPEG audio frame sync
118
+ (bytes[0] === 0xff && (bytes[1] & 0xe0) === 0xe0));
146
119
  }
147
120
  function readFilePrefix(filePath) {
148
121
  const buffer = Buffer.alloc(exports.ZIP_ENTRY_SNIFF_BYTES);