react-native-update-cli 2.9.2 → 2.9.4

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.js CHANGED
@@ -114,21 +114,30 @@ const closeSession = ()=>{
114
114
  }
115
115
  session = undefined;
116
116
  };
117
+ function createRequestError(error, requestUrl) {
118
+ const message = typeof error === 'string' ? error : error instanceof Error ? error.message : String(error);
119
+ return new Error(`${message}\nURL: ${requestUrl}`);
120
+ }
117
121
  async function query(url, options) {
118
122
  const baseUrl = await _httphelper.getBaseUrl;
119
123
  const fullUrl = `${baseUrl}${url}`;
120
- const resp = await (0, _nodefetch.default)(fullUrl, options);
124
+ let resp;
125
+ try {
126
+ resp = await (0, _nodefetch.default)(fullUrl, options);
127
+ } catch (error) {
128
+ throw createRequestError(error, fullUrl);
129
+ }
121
130
  const text = await resp.text();
122
131
  let json;
123
132
  try {
124
133
  json = JSON.parse(text);
125
134
  } catch (e) {}
126
135
  if (resp.status !== 200) {
127
- const message = (json == null ? void 0 : json.message) || resp.statusText;
136
+ const message = (json == null ? void 0 : json.message) || resp.statusText || `HTTP ${resp.status}`;
128
137
  if (resp.status === 401) {
129
- throw new Error((0, _i18n.t)('loginExpired'));
138
+ throw createRequestError((0, _i18n.t)('loginExpired'), fullUrl);
130
139
  }
131
- throw new Error(message);
140
+ throw createRequestError(message, fullUrl);
132
141
  }
133
142
  return json;
134
143
  }
@@ -221,12 +230,17 @@ async function uploadFile(fn, key) {
221
230
  // form.append('file', fileStream, {
222
231
  // contentType: 'application/octet-stream',
223
232
  // });
224
- const res = await (0, _nodefetch.default)(realUrl, {
225
- method: 'POST',
226
- body: form
227
- });
233
+ let res;
234
+ try {
235
+ res = await (0, _nodefetch.default)(realUrl, {
236
+ method: 'POST',
237
+ body: form
238
+ });
239
+ } catch (error) {
240
+ throw createRequestError(error, realUrl);
241
+ }
228
242
  if (res.status > 299) {
229
- throw new Error(`${res.status}: ${res.statusText}`);
243
+ throw createRequestError(`${res.status}: ${res.statusText || 'Upload failed'}`, realUrl);
230
244
  }
231
245
  // const body = await response.json();
232
246
  return {
@@ -15,6 +15,13 @@ export interface RunBundleCommandOptions {
15
15
  cli: BundleCliOptions;
16
16
  isSentry: boolean;
17
17
  }
18
+ type ResolvedExpoCli = {
19
+ cliPath: string;
20
+ usingExpo: boolean;
21
+ };
22
+ export declare function hasProjectDependency(dependencyName: string, projectRoot?: string): boolean;
23
+ export declare function resolveExpoCli(projectRoot?: string): ResolvedExpoCli;
18
24
  export declare function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, forceHermes, cli, isSentry, }: RunBundleCommandOptions): Promise<void>;
19
25
  export declare function copyDebugidForSentry(bundleName: string, outputFolder: string, sourcemapOutput: string): Promise<void>;
20
26
  export declare function uploadSourcemapForSentry(bundleName: string, outputFolder: string, sourcemapOutput: string, version: string): Promise<void>;
27
+ export {};
@@ -12,6 +12,12 @@ _export(exports, {
12
12
  copyDebugidForSentry: function() {
13
13
  return copyDebugidForSentry;
14
14
  },
15
+ hasProjectDependency: function() {
16
+ return hasProjectDependency;
17
+ },
18
+ resolveExpoCli: function() {
19
+ return resolveExpoCli;
20
+ },
15
21
  runReactNativeBundleCommand: function() {
16
22
  return runReactNativeBundleCommand;
17
23
  },
@@ -73,6 +79,70 @@ function _interop_require_wildcard(obj, nodeInterop) {
73
79
  }
74
80
  const g2js = require('gradle-to-js/lib/parser');
75
81
  const properties = require('properties');
82
+ const dependencyFields = [
83
+ 'dependencies',
84
+ 'devDependencies',
85
+ 'peerDependencies',
86
+ 'optionalDependencies'
87
+ ];
88
+ function hasProjectDependency(dependencyName, projectRoot = process.cwd()) {
89
+ try {
90
+ const packageJson = JSON.parse(_fsextra.readFileSync(_path.default.join(projectRoot, 'package.json'), 'utf8'));
91
+ return dependencyFields.some((field)=>{
92
+ const dependencies = packageJson[field];
93
+ if (typeof dependencies !== 'object' || dependencies === null) {
94
+ return false;
95
+ }
96
+ return dependencyName in dependencies;
97
+ });
98
+ } catch (e) {
99
+ return false;
100
+ }
101
+ }
102
+ function resolveExpoCli(projectRoot = process.cwd()) {
103
+ if (!hasProjectDependency('expo', projectRoot)) {
104
+ return {
105
+ cliPath: '',
106
+ usingExpo: false
107
+ };
108
+ }
109
+ try {
110
+ const searchPaths = [
111
+ projectRoot
112
+ ];
113
+ try {
114
+ const expoPackageJsonPath = require.resolve('expo/package.json', {
115
+ paths: [
116
+ projectRoot
117
+ ]
118
+ });
119
+ searchPaths.push(_path.default.dirname(expoPackageJsonPath));
120
+ } catch (e) {
121
+ // expo 包不存在,忽略
122
+ }
123
+ const cliPath = require.resolve('@expo/cli', {
124
+ paths: searchPaths
125
+ });
126
+ const expoCliVersion = JSON.parse(_fsextra.readFileSync(require.resolve('@expo/cli/package.json', {
127
+ paths: searchPaths
128
+ }), 'utf8')).version;
129
+ if (!(0, _compareversions.satisfies)(expoCliVersion, '>= 0.10.17')) {
130
+ return {
131
+ cliPath: '',
132
+ usingExpo: false
133
+ };
134
+ }
135
+ return {
136
+ cliPath,
137
+ usingExpo: true
138
+ };
139
+ } catch (e) {
140
+ return {
141
+ cliPath: '',
142
+ usingExpo: false
143
+ };
144
+ }
145
+ }
76
146
  async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, forceHermes, cli, isSentry }) {
77
147
  let gradleConfig = {};
78
148
  if (platform === 'android') {
@@ -90,35 +160,9 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
90
160
  let cliPath = '';
91
161
  let usingExpo = false;
92
162
  const getExpoCli = ()=>{
93
- try {
94
- const searchPaths = [
95
- process.cwd()
96
- ];
97
- try {
98
- const expoPath = require.resolve('expo/package.json', {
99
- paths: [
100
- process.cwd()
101
- ]
102
- });
103
- const expoDir = expoPath.replace(/\/package\.json$/, '');
104
- searchPaths.push(expoDir);
105
- } catch (e) {
106
- // expo 包不存在,忽略
107
- }
108
- cliPath = require.resolve('@expo/cli', {
109
- paths: searchPaths
110
- });
111
- const expoCliVersion = JSON.parse(_fsextra.readFileSync(require.resolve('@expo/cli/package.json', {
112
- paths: searchPaths
113
- })).toString()).version;
114
- if ((0, _compareversions.satisfies)(expoCliVersion, '>= 0.10.17')) {
115
- usingExpo = true;
116
- } else {
117
- cliPath = '';
118
- }
119
- } catch (e) {
120
- // fallback 到 RN CLI
121
- }
163
+ const resolvedExpoCli = resolveExpoCli();
164
+ cliPath = resolvedExpoCli.cliPath;
165
+ usingExpo = resolvedExpoCli.usingExpo;
122
166
  };
123
167
  const getRnCli = ()=>{
124
168
  try {
@@ -65,7 +65,7 @@ const ping = async (url)=>{
65
65
  if (!pingFinished) {
66
66
  // console.log('ping timeout', url);
67
67
  }
68
- }, 2000))
68
+ }, 5000))
69
69
  ]);
70
70
  };
71
71
  const testUrls = async (urls)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.9.2",
3
+ "version": "2.9.4",
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",
package/src/api.ts CHANGED
@@ -75,10 +75,25 @@ export const closeSession = () => {
75
75
  session = undefined;
76
76
  };
77
77
 
78
+ function createRequestError(error: unknown, requestUrl: string) {
79
+ const message =
80
+ typeof error === 'string'
81
+ ? error
82
+ : error instanceof Error
83
+ ? error.message
84
+ : String(error);
85
+ return new Error(`${message}\nURL: ${requestUrl}`);
86
+ }
87
+
78
88
  async function query(url: string, options: fetch.RequestInit) {
79
89
  const baseUrl = await getBaseUrl;
80
90
  const fullUrl = `${baseUrl}${url}`;
81
- const resp = await fetch(fullUrl, options);
91
+ let resp: fetch.Response;
92
+ try {
93
+ resp = await fetch(fullUrl, options);
94
+ } catch (error) {
95
+ throw createRequestError(error, fullUrl);
96
+ }
82
97
  const text = await resp.text();
83
98
  let json: any;
84
99
  try {
@@ -86,11 +101,11 @@ async function query(url: string, options: fetch.RequestInit) {
86
101
  } catch (e) {}
87
102
 
88
103
  if (resp.status !== 200) {
89
- const message = json?.message || resp.statusText;
104
+ const message = json?.message || resp.statusText || `HTTP ${resp.status}`;
90
105
  if (resp.status === 401) {
91
- throw new Error(t('loginExpired'));
106
+ throw createRequestError(t('loginExpired'), fullUrl);
92
107
  }
93
- throw new Error(message);
108
+ throw createRequestError(message, fullUrl);
94
109
  }
95
110
  return json;
96
111
  }
@@ -195,13 +210,21 @@ export async function uploadFile(fn: string, key?: string) {
195
210
  // contentType: 'application/octet-stream',
196
211
  // });
197
212
 
198
- const res = await fetch(realUrl, {
199
- method: 'POST',
200
- body: form,
201
- });
213
+ let res: fetch.Response;
214
+ try {
215
+ res = await fetch(realUrl, {
216
+ method: 'POST',
217
+ body: form,
218
+ });
219
+ } catch (error) {
220
+ throw createRequestError(error, realUrl);
221
+ }
202
222
 
203
223
  if (res.status > 299) {
204
- throw new Error(`${res.status}: ${res.statusText}`);
224
+ throw createRequestError(
225
+ `${res.status}: ${res.statusText || 'Upload failed'}`,
226
+ realUrl,
227
+ );
205
228
  }
206
229
 
207
230
  // const body = await response.json();
@@ -32,6 +32,90 @@ interface GradleConfig {
32
32
  enableHermes?: boolean;
33
33
  }
34
34
 
35
+ const dependencyFields = [
36
+ 'dependencies',
37
+ 'devDependencies',
38
+ 'peerDependencies',
39
+ 'optionalDependencies',
40
+ ] as const;
41
+
42
+ type ResolvedExpoCli = {
43
+ cliPath: string;
44
+ usingExpo: boolean;
45
+ };
46
+
47
+ export function hasProjectDependency(
48
+ dependencyName: string,
49
+ projectRoot = process.cwd(),
50
+ ): boolean {
51
+ try {
52
+ const packageJson = JSON.parse(
53
+ fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'),
54
+ ) as Record<string, unknown>;
55
+
56
+ return dependencyFields.some((field) => {
57
+ const dependencies = packageJson[field];
58
+ if (typeof dependencies !== 'object' || dependencies === null) {
59
+ return false;
60
+ }
61
+ return dependencyName in dependencies;
62
+ });
63
+ } catch {
64
+ return false;
65
+ }
66
+ }
67
+
68
+ export function resolveExpoCli(projectRoot = process.cwd()): ResolvedExpoCli {
69
+ if (!hasProjectDependency('expo', projectRoot)) {
70
+ return {
71
+ cliPath: '',
72
+ usingExpo: false,
73
+ };
74
+ }
75
+
76
+ try {
77
+ const searchPaths = [projectRoot];
78
+
79
+ try {
80
+ const expoPackageJsonPath = require.resolve('expo/package.json', {
81
+ paths: [projectRoot],
82
+ });
83
+ searchPaths.push(path.dirname(expoPackageJsonPath));
84
+ } catch {
85
+ // expo 包不存在,忽略
86
+ }
87
+
88
+ const cliPath = require.resolve('@expo/cli', {
89
+ paths: searchPaths,
90
+ });
91
+ const expoCliVersion = JSON.parse(
92
+ fs.readFileSync(
93
+ require.resolve('@expo/cli/package.json', {
94
+ paths: searchPaths,
95
+ }),
96
+ 'utf8',
97
+ ),
98
+ ).version;
99
+
100
+ if (!satisfies(expoCliVersion, '>= 0.10.17')) {
101
+ return {
102
+ cliPath: '',
103
+ usingExpo: false,
104
+ };
105
+ }
106
+
107
+ return {
108
+ cliPath,
109
+ usingExpo: true,
110
+ };
111
+ } catch {
112
+ return {
113
+ cliPath: '',
114
+ usingExpo: false,
115
+ };
116
+ }
117
+ }
118
+
35
119
  export async function runReactNativeBundleCommand({
36
120
  bundleName,
37
121
  dev,
@@ -65,40 +149,9 @@ export async function runReactNativeBundleCommand({
65
149
  let usingExpo = false;
66
150
 
67
151
  const getExpoCli = () => {
68
- try {
69
- const searchPaths = [process.cwd()];
70
-
71
- try {
72
- const expoPath = require.resolve('expo/package.json', {
73
- paths: [process.cwd()],
74
- });
75
- const expoDir = expoPath.replace(/\/package\.json$/, '');
76
- searchPaths.push(expoDir);
77
- } catch {
78
- // expo 包不存在,忽略
79
- }
80
-
81
- cliPath = require.resolve('@expo/cli', {
82
- paths: searchPaths,
83
- });
84
-
85
- const expoCliVersion = JSON.parse(
86
- fs
87
- .readFileSync(
88
- require.resolve('@expo/cli/package.json', {
89
- paths: searchPaths,
90
- }),
91
- )
92
- .toString(),
93
- ).version;
94
- if (satisfies(expoCliVersion, '>= 0.10.17')) {
95
- usingExpo = true;
96
- } else {
97
- cliPath = '';
98
- }
99
- } catch {
100
- // fallback 到 RN CLI
101
- }
152
+ const resolvedExpoCli = resolveExpoCli();
153
+ cliPath = resolvedExpoCli.cliPath;
154
+ usingExpo = resolvedExpoCli.usingExpo;
102
155
  };
103
156
 
104
157
  const getRnCli = () => {
@@ -48,7 +48,7 @@ export const ping = async (url: string) => {
48
48
  if (!pingFinished) {
49
49
  // console.log('ping timeout', url);
50
50
  }
51
- }, 2000),
51
+ }, 5000),
52
52
  ),
53
53
  ]) as Promise<string | null>;
54
54
  };