react-native-bootsplash 6.1.3 → 6.1.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/src/generate.ts CHANGED
@@ -26,6 +26,11 @@ import { Manifest } from ".";
26
26
  const workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
27
27
  const projectRoot = findProjectRoot(workingPath);
28
28
 
29
+ type PackageJson = {
30
+ version?: string;
31
+ dependencies?: Record<string, string>;
32
+ };
33
+
29
34
  type ProjectType = "detect" | "bare" | "expo";
30
35
  type Platforms = ("android" | "ios" | "web")[];
31
36
 
@@ -186,39 +191,56 @@ export const hfs = {
186
191
  };
187
192
 
188
193
  // Adapted from https://github.com/square/find-yarn-workspace-root
189
- export const getExpoConfig = (from: string): { isExpo: boolean } => {
194
+ const findUp = <T>(from: string, matcher: (dir: string) => T | undefined) => {
190
195
  let previous: string | undefined;
191
196
  let current = path.normalize(from);
192
197
 
193
198
  do {
194
- const pkgPath = path.resolve(
195
- current,
196
- "node_modules",
197
- "expo",
198
- "package.json",
199
- );
200
-
201
- if (fs.existsSync(pkgPath)) {
202
- try {
203
- const pkg = hfs.json(pkgPath) as { version?: string };
204
- const version = pkg.version;
199
+ const found = matcher(current);
205
200
 
206
- if (version == null || semver.lt(version, "51.0.20")) {
207
- log.error("Requires Expo 51.0.20 (or higher)");
208
- process.exit(1);
209
- }
210
-
211
- return { isExpo: true };
212
- } catch {
213
- return { isExpo: false };
214
- }
201
+ if (typeof found !== "undefined") {
202
+ return found;
215
203
  }
216
204
 
217
205
  previous = current;
218
206
  current = path.dirname(current);
219
207
  } while (current !== previous);
208
+ };
209
+
210
+ export const getExpoConfig = (from: string): { isExpo: boolean } => {
211
+ const hasDependency =
212
+ findUp(from, (dir) => {
213
+ const pkgPath = path.resolve(dir, "package.json");
214
+
215
+ if (fs.existsSync(pkgPath)) {
216
+ try {
217
+ const pkg = hfs.json(pkgPath) as PackageJson;
218
+ return pkg.dependencies?.expo != null;
219
+ } catch {} // eslint-disable-line no-empty
220
+ }
221
+ }) ?? false;
222
+
223
+ if (!hasDependency) {
224
+ return { isExpo: false };
225
+ }
226
+
227
+ const version = findUp(from, (dir) => {
228
+ const pkgPath = path.resolve(dir, "node_modules", "expo", "package.json");
229
+
230
+ if (fs.existsSync(pkgPath)) {
231
+ try {
232
+ const pkg = hfs.json(pkgPath) as PackageJson;
233
+ return pkg.version;
234
+ } catch {} // eslint-disable-line no-empty
235
+ }
236
+ });
237
+
238
+ if (version == null || semver.lt(version, "51.0.20")) {
239
+ log.error("Requires Expo 51.0.20 (or higher)");
240
+ process.exit(1);
241
+ }
220
242
 
221
- return { isExpo: false };
243
+ return { isExpo: true };
222
244
  };
223
245
 
224
246
  export const writeJson = (filePath: string, content: object) => {