react-native-update-cli 2.9.2 → 2.9.3

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.
@@ -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 {
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.3",
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",
@@ -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 = () => {