react-native-update-cli 2.29.3 → 2.29.5

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/lib/api.d.ts CHANGED
@@ -11,6 +11,13 @@ export declare const saveSession: () => void;
11
11
  export declare const closeSession: () => void;
12
12
  /** Remove credentials, query signatures and fragments before logging a URL. */
13
13
  export declare function redactRequestUrl(requestUrl: string): string;
14
+ /**
15
+ * The underlying reason of a network failure, e.g.
16
+ * `ENOTFOUND: getaddrinfo ENOTFOUND 1.rnupdate.online`. Node's fetch only says
17
+ * "fetch failed" and keeps the reason in `cause`, which is otherwise printed
18
+ * only under RNU_DEBUG=1.
19
+ */
20
+ export declare function describeNetworkCause(error: unknown): string | undefined;
14
21
  export declare const get: (api: string) => Promise<any>;
15
22
  export declare const post: (api: string, body?: Record<string, any>) => Promise<any>;
16
23
  export declare const put: (api: string, body?: Record<string, any>) => Promise<any>;
package/lib/api.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getAllPackages = exports.doDelete = exports.put = exports.post = exports.get = exports.closeSession = exports.saveSession = exports.loadSession = exports.replaceSession = exports.setApiToken = exports.getApiToken = exports.getSession = void 0;
7
7
  exports.redactRequestUrl = redactRequestUrl;
8
+ exports.describeNetworkCause = describeNetworkCause;
8
9
  exports.uploadTimeoutMs = uploadTimeoutMs;
9
10
  exports.isTransientUploadError = isTransientUploadError;
10
11
  exports.uploadFile = uploadFile;
@@ -95,12 +96,13 @@ function redactRequestUrl(requestUrl) {
95
96
  : `${requestUrl.slice(0, secretStart)}?<redacted>`;
96
97
  }
97
98
  }
98
- function createRequestError(error, requestUrl, status) {
99
- const message = typeof error === 'string'
99
+ function createRequestError(error, requestUrl, status, detail) {
100
+ const baseMessage = typeof error === 'string'
100
101
  ? error
101
102
  : error instanceof Error
102
103
  ? error.message
103
104
  : String(error);
105
+ const message = detail ? `${baseMessage} (${detail})` : baseMessage;
104
106
  const cause = error instanceof Error || (typeof error === 'object' && error !== null)
105
107
  ? error
106
108
  : undefined;
@@ -120,35 +122,103 @@ const PROXY_ERROR_PATTERNS = [
120
122
  'ETIMEDOUT',
121
123
  'EHOSTUNREACH',
122
124
  'ENETUNREACH',
125
+ // DNS: offline, or a proxy/VPN that hijacks name resolution
126
+ 'ENOTFOUND',
127
+ 'EAI_AGAIN',
128
+ // undici's own connect/socket failures (Node's fetch)
129
+ 'UND_ERR_CONNECT_TIMEOUT',
130
+ 'UND_ERR_SOCKET',
131
+ // a TLS-inspecting corporate proxy re-signing with an untrusted root
132
+ 'UNABLE_TO_GET_ISSUER_CERT',
133
+ 'SELF_SIGNED_CERT_IN_CHAIN',
123
134
  ];
135
+ /** The error chain from `error` down through its causes, without cycles. */
136
+ function errorChain(error) {
137
+ const chain = [];
138
+ let current = error;
139
+ while (current !== undefined &&
140
+ current !== null &&
141
+ !chain.includes(current)) {
142
+ chain.push(current);
143
+ current =
144
+ typeof current === 'object'
145
+ ? current.cause
146
+ : undefined;
147
+ }
148
+ return chain;
149
+ }
150
+ /**
151
+ * The underlying reason of a network failure, e.g.
152
+ * `ENOTFOUND: getaddrinfo ENOTFOUND 1.rnupdate.online`. Node's fetch only says
153
+ * "fetch failed" and keeps the reason in `cause`, which is otherwise printed
154
+ * only under RNU_DEBUG=1.
155
+ */
156
+ function describeNetworkCause(error) {
157
+ const top = error instanceof Error ? error.message : String(error);
158
+ for (const item of errorChain(error).slice(1).reverse()) {
159
+ if (!(item instanceof Error)) {
160
+ continue;
161
+ }
162
+ // happy-eyeballs connects fail with an AggregateError of per-address errors
163
+ const inner = !item.code &&
164
+ item instanceof AggregateError &&
165
+ item.errors[0] instanceof Error
166
+ ? item.errors[0]
167
+ : item;
168
+ const code = inner.code;
169
+ const message = inner.message || item.message;
170
+ if (!code && (!message || message === top)) {
171
+ continue;
172
+ }
173
+ if (!code) {
174
+ return message;
175
+ }
176
+ return message && !message.includes(code)
177
+ ? `${code}: ${message}`
178
+ : message || code;
179
+ }
180
+ return undefined;
181
+ }
124
182
  function isProxyRelatedError(error) {
125
- const seen = new Set();
126
183
  const parts = [];
127
- let current = error;
128
- while (current !== undefined && current !== null && !seen.has(current)) {
129
- seen.add(current);
184
+ for (const current of errorChain(error)) {
130
185
  if (current instanceof Error) {
131
186
  const code = current.code;
132
187
  parts.push(`${current.name} ${code ?? ''} ${current.message}`);
188
+ if (current instanceof AggregateError) {
189
+ for (const inner of current.errors) {
190
+ if (inner instanceof Error) {
191
+ const innerCode = inner.code;
192
+ parts.push(`${inner.name} ${innerCode ?? ''} ${inner.message}`);
193
+ }
194
+ }
195
+ }
133
196
  }
134
197
  else {
135
198
  parts.push(String(current));
136
199
  }
137
- current =
138
- typeof current === 'object'
139
- ? current.cause
140
- : undefined;
141
200
  }
142
201
  const lower = parts.join('\n').toLowerCase();
143
202
  return PROXY_ERROR_PATTERNS.some((p) => lower.includes(p.toLowerCase()));
144
203
  }
145
204
  /** A request error for `url`, with the proxy hints when a proxy is the likely cause. */
146
- function networkError(error, url) {
147
- const baseError = createRequestError(error, url);
205
+ function networkError(error, url, { apiRequest = false } = {}) {
206
+ const baseError = createRequestError(error, url, undefined, describeNetworkCause(error));
207
+ const hints = [];
208
+ if (apiRequest && (0, http_helper_1.isBaseUrlUnreachableFallback)()) {
209
+ hints.push((0, i18n_1.t)('allEndpointsUnreachable', {
210
+ example: constants_1.defaultEndpoints[constants_1.defaultEndpoints.length - 1],
211
+ }));
212
+ }
148
213
  if (isProxyRelatedError(error)) {
149
- return new Error(`${baseError.message}\n\n${(0, i18n_1.t)('proxyNetworkError')}\n${(0, i18n_1.t)('proxyNetworkErrorTips')}`, { cause: baseError });
214
+ hints.push(`${(0, i18n_1.t)('proxyNetworkError')}\n${(0, i18n_1.t)('proxyNetworkErrorTips')}`);
215
+ }
216
+ if (!hints.length) {
217
+ return baseError;
150
218
  }
151
- return baseError;
219
+ return new Error(`${baseError.message}\n\n${hints.join('\n\n')}`, {
220
+ cause: baseError,
221
+ });
152
222
  }
153
223
  async function query(url, options) {
154
224
  const baseUrl = await (0, http_helper_1.getBaseUrl)();
@@ -158,7 +228,7 @@ async function query(url, options) {
158
228
  resp = await (0, runtime_1.runtimeFetch)(fullUrl, options);
159
229
  }
160
230
  catch (error) {
161
- throw networkError(error, fullUrl);
231
+ throw networkError(error, fullUrl, { apiRequest: true });
162
232
  }
163
233
  const text = await resp.text();
164
234
  let json;
@@ -138,6 +138,7 @@ declare const _default: {
138
138
  composeSourceMapsNotFound: string;
139
139
  installPackageRequired: string;
140
140
  installFailed: string;
141
+ allEndpointsUnreachable: string;
141
142
  proxyNetworkError: string;
142
143
  proxyNetworkErrorTips: string;
143
144
  invalidId: string;
package/lib/locales/en.js CHANGED
@@ -146,8 +146,9 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
146
146
  composeSourceMapsNotFound: 'Cannot find react-native/scripts/compose-source-maps.js, skipping hermes sourcemap composing. The uploaded sourcemap may not match the compiled bundle.',
147
147
  installPackageRequired: 'Please specify the package to install, e.g. "{{scriptName}} install node-hdiffpatch"',
148
148
  installFailed: 'Failed to install {{packages}}: {{error}}',
149
- proxyNetworkError: 'Network error — likely caused by a proxy/VPN. Please try disabling your proxy and retry.',
150
- proxyNetworkErrorTips: 'Common fixes:\n1. Disable system proxy or VPN\n2. Check HTTP_PROXY / HTTPS_PROXY environment variables\n3. Check proxy settings in .npmrc',
149
+ allEndpointsUnreachable: 'None of the API endpoints is reachable from this machine (each was probed), so the problem is in the local network rather than the server. If only one endpoint works for you, pin it with the RNU_API environment variable, e.g. RNU_API={{example}}',
150
+ proxyNetworkError: 'Network error — likely caused by DNS, a proxy/VPN or a certificate problem. Please try disabling your proxy and retry.',
151
+ proxyNetworkErrorTips: "Common fixes:\n1. Disable system proxy or VPN (or let this service's domains bypass it)\n2. Check HTTP_PROXY / HTTPS_PROXY environment variables\n3. Check proxy settings in .npmrc\n4. If your network re-signs HTTPS certificates, point NODE_EXTRA_CA_CERTS at its root certificate",
151
152
  invalidId: 'Invalid id: {{id}}',
152
153
  outputPathRequired: 'Output path is required.',
153
154
  unsupportedFileType: 'Unsupported file type: {{fileType}}',
@@ -138,6 +138,7 @@ declare const _default: {
138
138
  composeSourceMapsNotFound: string;
139
139
  installPackageRequired: string;
140
140
  installFailed: string;
141
+ allEndpointsUnreachable: string;
141
142
  proxyNetworkError: string;
142
143
  proxyNetworkErrorTips: string;
143
144
  invalidId: string;
package/lib/locales/zh.js CHANGED
@@ -146,8 +146,9 @@ exports.default = {
146
146
  composeSourceMapsNotFound: '找不到 react-native/scripts/compose-source-maps.js,跳过 hermes sourcemap 合成。上传的 sourcemap 可能与编译后的 bundle 不匹配。',
147
147
  installPackageRequired: '请指定要安装的包,例如 "{{scriptName}} install node-hdiffpatch"',
148
148
  installFailed: '安装 {{packages}} 失败: {{error}}',
149
- proxyNetworkError: '网络连接异常,可能是代理/VPN 导致。请尝试关闭代理后重试。',
150
- proxyNetworkErrorTips: '常见解决方法:\n1. 关闭系统代理或 VPN\n2. 检查 HTTP_PROXY / HTTPS_PROXY 环境变量\n3. 检查 .npmrc 中的 proxy 配置',
149
+ allEndpointsUnreachable: '本机无法连接任何一条 API 线路(已逐一探测),问题出在本机网络而非服务端。如果只有某条线路可用,可以用 RNU_API 环境变量指定,例如 RNU_API={{example}}',
150
+ proxyNetworkError: '网络连接异常,可能是 DNS、代理/VPN 或证书问题导致。请尝试关闭代理后重试。',
151
+ proxyNetworkErrorTips: '常见解决方法:\n1. 关闭系统代理或 VPN(或将本服务的域名设为直连)\n2. 检查 HTTP_PROXY / HTTPS_PROXY 环境变量\n3. 检查 .npmrc 中的 proxy 配置\n4. 公司网络会替换 HTTPS 证书时,用 NODE_EXTRA_CA_CERTS 指定公司根证书',
151
152
  invalidId: '无效的 id:{{id}}',
152
153
  outputPathRequired: '必须指定输出路径。',
153
154
  unsupportedFileType: '不支持的文件类型:{{fileType}}',
@@ -16,6 +16,6 @@ export interface SlimPackageOptions {
16
16
  }
17
17
  /**
18
18
  * Repack a native package with only the bundle and resources required by
19
- * package-origin diffs. Entry names and nested Harmony HAP structure are kept.
19
+ * package-origin diffs, plus the server-only entries. Entry names and nested Harmony HAP structure are kept.
20
20
  */
21
21
  export declare function createSlimNativePackage(source: string, output: string, platform: Platform, options?: SlimPackageOptions): Promise<void>;
@@ -8,7 +8,10 @@ exports.createSlimNativePackage = createSlimNativePackage;
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const os_1 = __importDefault(require("os"));
10
10
  const path_1 = __importDefault(require("path"));
11
+ const stream_1 = require("stream");
12
+ const util_1 = require("util");
11
13
  const yauzl_1 = require("yauzl");
14
+ const zlib_1 = __importDefault(require("zlib"));
12
15
  const fs_helpers_1 = require("./utils/fs-helpers");
13
16
  const zip_entries_1 = require("./utils/zip-entries");
14
17
  const zip_raw_writer_1 = require("./utils/zip-raw-writer");
@@ -55,6 +58,15 @@ const nativePackageRules = {
55
58
  function resolveNativePackageEntry(platform, entryName) {
56
59
  return nativePackageRules[platform].resolveEntry(entryName);
57
60
  }
61
+ /**
62
+ * Entries kept for the server only: it maps resource names to their (shortened)
63
+ * paths through resources.arsc when building a package diff. They are never a
64
+ * diff origin, so they stay out of resolveNativePackageEntry.
65
+ */
66
+ const serverOnlyEntries = {
67
+ android: 'resources.arsc',
68
+ };
69
+ const deflateRaw = (0, util_1.promisify)(zlib_1.default.deflateRaw);
58
70
  /**
59
71
  * Copies each entry's stored bytes, CRC and sizes verbatim (yauzl hands out
60
72
  * the raw file data with `decodeFileData: false`), so slimming a package is
@@ -71,6 +83,21 @@ class RawCopySink {
71
83
  });
72
84
  await this.writer.addRawEntry(entry, readStream);
73
85
  }
86
+ async copyEntryDeflated(sourceZip, entry) {
87
+ if (entry.compressionMethod !== 0) {
88
+ return this.copyEntry(sourceZip, entry);
89
+ }
90
+ const deflated = await deflateRaw(await (0, zip_entries_1.readEntry)(entry, sourceZip), {
91
+ level: zlib_1.default.constants.Z_BEST_COMPRESSION,
92
+ });
93
+ await this.writer.addRawEntry({
94
+ ...entry,
95
+ compressionMethod: 8,
96
+ compressedSize: deflated.length,
97
+ // deflate strength bits of a stored entry mean nothing
98
+ generalPurposeBitFlag: 0,
99
+ }, stream_1.Readable.from([deflated]));
100
+ }
74
101
  addFile(filePath, fileName, like) {
75
102
  // a nested slim archive is a zip of deflated entries: storing it as-is
76
103
  // loses nothing and skips another pass over its bytes
@@ -89,13 +116,19 @@ class RepackSink {
89
116
  constructor(output) {
90
117
  this.output = (0, zip_entries_1.createOutputZip)(output);
91
118
  }
92
- async copyEntry(sourceZip, entry) {
119
+ copyEntry(sourceZip, entry) {
120
+ return this.add(sourceZip, entry, entry.compressionMethod !== 0);
121
+ }
122
+ copyEntryDeflated(sourceZip, entry) {
123
+ return this.add(sourceZip, entry, true);
124
+ }
125
+ async add(sourceZip, entry, compress) {
93
126
  const readStream = await (0, zip_entries_1.openEntryStream)(entry, sourceZip);
94
127
  await new Promise((resolve, reject) => {
95
128
  readStream.once('error', reject);
96
129
  readStream.once('end', () => resolve());
97
130
  this.output.zipfile.addReadStream(readStream, entry.fileName, {
98
- compress: entry.compressionMethod !== 0,
131
+ compress,
99
132
  mtime: entry.getLastModDate(),
100
133
  });
101
134
  });
@@ -189,6 +222,10 @@ async function filterNativePackageArchive(source, output, platform, options) {
189
222
  includedBundles += 1;
190
223
  }
191
224
  }
225
+ else if (entry.fileName === serverOnlyEntries[platform]) {
226
+ await sink.copyEntryDeflated(sourceZip, entry);
227
+ includedEntries += 1;
228
+ }
192
229
  sourceZip.readEntry();
193
230
  }
194
231
  catch (error) {
@@ -210,7 +247,7 @@ async function filterNativePackageArchive(source, output, platform, options) {
210
247
  }
211
248
  /**
212
249
  * Repack a native package with only the bundle and resources required by
213
- * package-origin diffs. Entry names and nested Harmony HAP structure are kept.
250
+ * package-origin diffs, plus the server-only entries. Entry names and nested Harmony HAP structure are kept.
214
251
  */
215
252
  async function createSlimNativePackage(source, output, platform, options = {}) {
216
253
  const result = await filterNativePackageArchive(source, output, platform, options);
@@ -1,5 +1,13 @@
1
1
  export declare const ping: (url: string, signal?: AbortSignal) => Promise<string | null>;
2
+ export declare const pickReachableUrl: (urls: string[], hedgeDelayMs?: number) => Promise<string | null>;
3
+ /** Like pickReachableUrl, but falls back to urls[0] when all fail. */
2
4
  export declare const testUrls: (urls?: string[], hedgeDelayMs?: number) => Promise<string | null>;
5
+ /**
6
+ * True when no default endpoint answered the ping and the API base url is the
7
+ * unverified fallback (defaultEndpoints[0]): a request failing there means the
8
+ * machine reaches none of the endpoints, not that this one host is down.
9
+ */
10
+ export declare const isBaseUrlUnreachableFallback: () => boolean;
3
11
  /**
4
12
  * The API base url: the env override, or the first default endpoint that
5
13
  * answers a HEAD ping. Resolved lazily on the first API call (offline commands
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBaseUrl = exports.testUrls = exports.ping = void 0;
3
+ exports.getBaseUrl = exports.isBaseUrlUnreachableFallback = exports.testUrls = exports.pickReachableUrl = exports.ping = void 0;
4
4
  const constants_1 = require("./constants");
5
5
  const runtime_1 = require("./runtime");
6
6
  const ping = async (url, signal) => {
@@ -33,10 +33,10 @@ const HEDGE_DELAY_MS = 250;
33
33
  // Hedged race instead of pinging every endpoint at once: the preferred (first)
34
34
  // url is tried immediately, each following one only after HEDGE_DELAY_MS of
35
35
  // silence (or immediately when a previous ping failed). The first success wins
36
- // and the losing pings are aborted. Falls back to urls[0] when all fail.
37
- const testUrls = async (urls, hedgeDelayMs = HEDGE_DELAY_MS) => {
38
- if (!urls?.length) {
39
- return null;
36
+ // and the losing pings are aborted. Resolves null when every ping fails.
37
+ const pickReachableUrl = (urls, hedgeDelayMs = HEDGE_DELAY_MS) => {
38
+ if (!urls.length) {
39
+ return Promise.resolve(null);
40
40
  }
41
41
  return new Promise((resolve) => {
42
42
  const controllers = [];
@@ -57,7 +57,7 @@ const testUrls = async (urls, hedgeDelayMs = HEDGE_DELAY_MS) => {
57
57
  controller.abort();
58
58
  }
59
59
  }
60
- resolve(winner ?? urls[0]);
60
+ resolve(winner);
61
61
  };
62
62
  const launchNext = () => {
63
63
  if (hedgeTimer) {
@@ -91,20 +91,36 @@ const testUrls = async (urls, hedgeDelayMs = HEDGE_DELAY_MS) => {
91
91
  launchNext();
92
92
  });
93
93
  };
94
+ exports.pickReachableUrl = pickReachableUrl;
95
+ /** Like pickReachableUrl, but falls back to urls[0] when all fail. */
96
+ const testUrls = async (urls, hedgeDelayMs = HEDGE_DELAY_MS) => {
97
+ if (!urls?.length) {
98
+ return null;
99
+ }
100
+ return (await (0, exports.pickReachableUrl)(urls, hedgeDelayMs)) ?? urls[0];
101
+ };
94
102
  exports.testUrls = testUrls;
95
103
  let baseUrlPromise;
104
+ let noEndpointReachable = false;
105
+ /**
106
+ * True when no default endpoint answered the ping and the API base url is the
107
+ * unverified fallback (defaultEndpoints[0]): a request failing there means the
108
+ * machine reaches none of the endpoints, not that this one host is down.
109
+ */
110
+ const isBaseUrlUnreachableFallback = () => noEndpointReachable;
111
+ exports.isBaseUrlUnreachableFallback = isBaseUrlUnreachableFallback;
96
112
  async function resolveBaseUrl() {
97
113
  const testEndpoint = process.env.PUSHY_REGISTRY || process.env.RNU_API;
98
114
  if (testEndpoint) {
99
115
  return testEndpoint;
100
116
  }
101
- const ret = await (0, exports.testUrls)(constants_1.defaultEndpoints.map((url) => `${url}/status`));
102
- let baseUrl = constants_1.defaultEndpoints[0];
103
- if (ret) {
104
- // remove /status
105
- baseUrl = ret.replace('/status', '');
117
+ const ret = await (0, exports.pickReachableUrl)(constants_1.defaultEndpoints.map((url) => `${url}/status`));
118
+ if (!ret) {
119
+ noEndpointReachable = true;
120
+ return constants_1.defaultEndpoints[0];
106
121
  }
107
- return baseUrl;
122
+ // remove /status
123
+ return ret.replace('/status', '');
108
124
  }
109
125
  /**
110
126
  * The API base url: the env override, or the first default endpoint that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.29.3",
3
+ "version": "2.29.5",
4
4
  "description": "command line tool for react-native-update (remote updates for react native)",
5
5
  "main": "lib/exports.js",
6
6
  "types": "lib/exports.d.ts",
@@ -59,7 +59,7 @@
59
59
  "bugs": {
60
60
  "url": "https://github.com/reactnativecn/react-native-update-cli/issues"
61
61
  },
62
- "homepage": "https://github.com/reactnativecn/react-native-update-cli",
62
+ "homepage": "https://cresc.dev/docs/cli",
63
63
  "dependencies": {
64
64
  "bplist-parser": "^0.3.2",
65
65
  "chalk": "4",