expo-manifests 0.5.2 → 0.7.0

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 (36) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/android/build.gradle +14 -20
  3. package/android/src/main/AndroidManifest.xml +1 -2
  4. package/android/src/main/java/expo/modules/manifests/core/BaseLegacyManifest.kt +1 -1
  5. package/android/src/main/java/expo/modules/manifests/core/JSONObjectExtension.kt +17 -0
  6. package/android/src/main/java/expo/modules/manifests/core/Manifest.kt +56 -2
  7. package/android/src/main/java/expo/modules/manifests/core/NewManifest.kt +6 -1
  8. package/android/src/test/java/expo/modules/manifests/core/ManifestTest.kt +59 -0
  9. package/android/src/{androidTest → test}/java/expo/modules/manifests/core/NewManifestTest.kt +3 -6
  10. package/ios/EXManifests/BareManifest.swift +19 -0
  11. package/ios/EXManifests/BaseLegacyManifest.swift +39 -0
  12. package/ios/EXManifests/LegacyManifest.swift +30 -0
  13. package/ios/EXManifests/Manifest.swift +413 -0
  14. package/ios/EXManifests/ManifestFactory.swift +17 -0
  15. package/ios/EXManifests/NewManifest.swift +83 -0
  16. package/ios/EXManifests.podspec +14 -5
  17. package/ios/Tests/BareManifestSpec.swift +69 -0
  18. package/ios/Tests/LegacyManifestSpec.swift +69 -0
  19. package/ios/Tests/ManifestSpec.swift +38 -0
  20. package/ios/Tests/NewManifestSpec.swift +97 -0
  21. package/package.json +3 -3
  22. package/ios/EXManifests/EXManifestsBareManifest.h +0 -20
  23. package/ios/EXManifests/EXManifestsBareManifest.m +0 -23
  24. package/ios/EXManifests/EXManifestsBaseLegacyManifest.h +0 -22
  25. package/ios/EXManifests/EXManifestsBaseLegacyManifest.m +0 -50
  26. package/ios/EXManifests/EXManifestsBaseManifest.h +0 -51
  27. package/ios/EXManifests/EXManifestsBaseManifest.m +0 -323
  28. package/ios/EXManifests/EXManifestsLegacyManifest.h +0 -19
  29. package/ios/EXManifests/EXManifestsLegacyManifest.m +0 -33
  30. package/ios/EXManifests/EXManifestsManifest.h +0 -86
  31. package/ios/EXManifests/EXManifestsManifestFactory.h +0 -14
  32. package/ios/EXManifests/EXManifestsManifestFactory.m +0 -22
  33. package/ios/EXManifests/EXManifestsNewManifest.h +0 -33
  34. package/ios/EXManifests/EXManifestsNewManifest.m +0 -89
  35. package/ios/Tests/EXManifestsNewManifestTests.m +0 -50
  36. package/ios/Tests/dummy.swift +0 -4
package/CHANGELOG.md CHANGED
@@ -10,7 +10,31 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 0.5.2 — 2023-02-21
13
+ ## 0.7.0 — 2023-06-21
14
+
15
+ ### 📚 3rd party library updates
16
+
17
+ - Updated `junit` to `4.13.2`. ([#22395](https://github.com/expo/expo/pull/22395) by [@josephyanks](https://github.com/josephyanks))
18
+
19
+ ### 🎉 New features
20
+
21
+ - Added `Manifests.getPluginProperties()` helper to query dedicated package's properties inside the `plugins` config. ([#22701](https://github.com/expo/expo/pull/22701) by [@kudo](https://github.com/kudo))
22
+
23
+ ### 🐛 Bug fixes
24
+
25
+ - Fixed Android build warnings for Gradle version 8. ([#22537](https://github.com/expo/expo/pull/22537), [#22609](https://github.com/expo/expo/pull/22609) by [@kudo](https://github.com/kudo))
26
+
27
+ ## 0.6.0 — 2023-05-08
28
+
29
+ ### 🎉 New features
30
+
31
+ - Support new SDK version field in new manifests. ([#22356](https://github.com/expo/expo/pull/22356) by [@wschurman](https://github.com/wschurman))
32
+
33
+ ### 💡 Others
34
+
35
+ - Convert iOS implementation to Swift. ([#21298](https://github.com/expo/expo/pull/21298), [#21648](https://github.com/expo/expo/pull/21648) by [@wschurman](https://github.com/wschurman))
36
+
37
+ ## 0.5.2 - 2023-02-21
14
38
 
15
39
  ### 🐛 Bug fixes
16
40
 
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '0.5.2'
6
+ version = '0.7.0'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -35,19 +35,11 @@ buildscript {
35
35
  }
36
36
  }
37
37
 
38
- // Creating sources with comments
39
- task androidSourcesJar(type: Jar) {
40
- classifier = 'sources'
41
- from android.sourceSets.main.java.srcDirs
42
- }
43
-
44
38
  afterEvaluate {
45
39
  publishing {
46
40
  publications {
47
41
  release(MavenPublication) {
48
42
  from components.release
49
- // Add additional sourcesJar to artifacts
50
- artifact(androidSourcesJar)
51
43
  }
52
44
  }
53
45
  repositories {
@@ -70,11 +62,12 @@ android {
70
62
  jvmTarget = JavaVersion.VERSION_11.majorVersion
71
63
  }
72
64
 
65
+ namespace "expo.modules.manifests"
73
66
  defaultConfig {
74
67
  minSdkVersion safeExtGet("minSdkVersion", 21)
75
68
  targetSdkVersion safeExtGet("targetSdkVersion", 33)
76
69
  versionCode 31
77
- versionName '0.5.2'
70
+ versionName '0.7.0'
78
71
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
79
72
  }
80
73
  lintOptions {
@@ -86,21 +79,22 @@ android {
86
79
  sourceSets {
87
80
  androidTest.assets.srcDirs += files("$projectDir/src/androidTest/schemas".toString())
88
81
  }
82
+ publishing {
83
+ singleVariant("release") {
84
+ withSourcesJar()
85
+ }
86
+ }
89
87
  }
90
88
 
91
89
  dependencies {
92
90
  implementation project(':expo-json-utils')
93
91
 
94
- testImplementation 'junit:junit:4.12'
95
- testImplementation 'androidx.test:core:1.4.0'
96
- testImplementation 'org.mockito:mockito-core:1.10.19'
97
- testImplementation 'io.mockk:mockk:1.12.3'
98
-
99
- androidTestImplementation 'androidx.test:runner:1.4.0'
100
- androidTestImplementation 'androidx.test:core:1.4.0'
101
- androidTestImplementation 'androidx.test:rules:1.4.0'
102
- androidTestImplementation 'org.mockito:mockito-android:3.7.7'
103
- androidTestImplementation 'io.mockk:mockk-android:1.12.3'
92
+ testImplementation 'junit:junit:4.13.2'
93
+ testImplementation 'androidx.test:core:1.5.0'
94
+ testImplementation 'org.mockito:mockito-core:4.0.0'
95
+ testImplementation 'io.mockk:mockk:1.13.5'
96
+ testImplementation 'org.json:json:20230227'
97
+ testImplementation "com.google.truth:truth:1.1.2"
104
98
 
105
99
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
106
100
  }
@@ -1,3 +1,2 @@
1
- <manifest package="expo.modules.manifests"
2
- xmlns:android="http://schemas.android.com/apk/res/android">
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
3
2
  </manifest>
@@ -18,7 +18,7 @@ abstract class BaseLegacyManifest(json: JSONObject) : Manifest(json) {
18
18
  @Throws(JSONException::class)
19
19
  override fun getBundleURL(): String = json.require("bundleUrl")
20
20
 
21
- override fun getSDKVersion(): String? = json.getNullable("sdkVersion")
21
+ override fun getExpoGoSDKVersion(): String? = json.getNullable("sdkVersion")
22
22
 
23
23
  override fun getExpoGoConfigRootObject(): JSONObject? {
24
24
  return json
@@ -0,0 +1,17 @@
1
+ // Copyright 2015-present 650 Industries. All rights reserved.
2
+
3
+ package expo.modules.manifests.core
4
+
5
+ import org.json.JSONObject
6
+
7
+ /**
8
+ * Convert a [JSONObject] to Map<String, Any> recursively
9
+ */
10
+ fun JSONObject.toMap(): Map<String, Any> {
11
+ return keys().asSequence().associateWith {
12
+ when (val value = this@toMap[it]) {
13
+ is JSONObject -> value.toMap()
14
+ else -> value
15
+ }
16
+ }
17
+ }
@@ -70,7 +70,11 @@ abstract class Manifest(protected val json: JSONObject) {
70
70
 
71
71
  fun getMetadata(): JSONObject? = json.getNullable("metadata")
72
72
 
73
- abstract fun getSDKVersion(): String?
73
+ /**
74
+ * Get the SDK version that should be attempted to be used in Expo Go. If no SDK version can be
75
+ * determined, returns null
76
+ */
77
+ abstract fun getExpoGoSDKVersion(): String?
74
78
 
75
79
  abstract fun getAssets(): JSONArray?
76
80
 
@@ -172,7 +176,7 @@ abstract class Manifest(protected val json: JSONObject) {
172
176
  var result = expoClientConfig
173
177
  ?.getNullable<JSONObject>("android")?.getNullable<String>("jsEngine") ?: expoClientConfig?.getNullable<String>("jsEngine")
174
178
  if (result == null) {
175
- val sdkVersionComponents = getSDKVersion()?.split(".")
179
+ val sdkVersionComponents = getExpoGoSDKVersion()?.split(".")
176
180
  val sdkMajorVersion = if (sdkVersionComponents?.size == 3) sdkVersionComponents[0].toIntOrNull() else 0
177
181
  result = if (sdkMajorVersion in 1..47) "jsc" else "hermes"
178
182
  }
@@ -226,6 +230,18 @@ abstract class Manifest(protected val json: JSONObject) {
226
230
  @Throws(JSONException::class)
227
231
  fun getFacebookAutoInitEnabled(): Boolean = getExpoClientConfigRootObject()!!.require("facebookAutoInitEnabled")
228
232
 
233
+ /**
234
+ * Queries the dedicated package properties in `plugins`
235
+ */
236
+ @Throws(JSONException::class, IllegalArgumentException::class)
237
+ fun getPluginProperties(packageName: String): Map<String, Any>? {
238
+ val pluginsRawValue = getExpoClientConfigRootObject()?.getNullable<JSONArray>("plugins") ?: return null
239
+ val plugins = PluginType.fromRawArrayValue(pluginsRawValue) ?: return null
240
+ return plugins.filterIsInstance<PluginType.WithProps>()
241
+ .firstOrNull { it.plugin.first == packageName }
242
+ ?.plugin?.second
243
+ }
244
+
229
245
  companion object {
230
246
  @JvmStatic fun fromManifestJson(manifestJson: JSONObject): Manifest {
231
247
  return when {
@@ -242,3 +258,41 @@ abstract class Manifest(protected val json: JSONObject) {
242
258
  }
243
259
  }
244
260
  }
261
+
262
+ internal typealias PluginWithProps = Pair<String, Map<String, Any>>
263
+ internal typealias PluginWithoutProps = String
264
+ internal sealed class PluginType {
265
+ data class WithProps(val plugin: PluginWithProps) : PluginType()
266
+ data class WithoutProps(val plugin: PluginWithoutProps) : PluginType()
267
+
268
+ companion object {
269
+ @Throws(IllegalArgumentException::class)
270
+ private fun fromRawValue(value: Any): PluginType? {
271
+ return when (value) {
272
+ is JSONArray -> {
273
+ if (value.length() != 2) {
274
+ throw IllegalArgumentException("Value for (key = plugins) has incorrect type")
275
+ }
276
+ val name = value.get(0) as? String ?: return null
277
+ val props = value.get(1) as? JSONObject ?: return null
278
+ WithProps(name to props.toMap())
279
+ }
280
+ is String -> {
281
+ WithoutProps(value)
282
+ }
283
+ else -> throw IllegalArgumentException("Value for (key = plugins) has incorrect type")
284
+ }
285
+ }
286
+
287
+ @Throws(IllegalArgumentException::class)
288
+ fun fromRawArrayValue(value: JSONArray): List<PluginType> {
289
+ return mutableListOf<PluginType>().apply {
290
+ for (i in 0 until value.length()) {
291
+ fromRawValue(value.get(i))?.let {
292
+ add(it)
293
+ }
294
+ }
295
+ }
296
+ }
297
+ }
298
+ }
@@ -33,7 +33,8 @@ class NewManifest(json: JSONObject) : Manifest(json) {
33
33
  @Throws(JSONException::class)
34
34
  override fun getBundleURL(): String = getLaunchAsset().require("url")
35
35
 
36
- override fun getSDKVersion(): String? {
36
+ @Deprecated(message = "exposdk:... runtime version is deprecated")
37
+ private fun getSDKVersionFromRuntimeVersion(): String? {
37
38
  val runtimeVersion = getRuntimeVersion()
38
39
  if (runtimeVersion == "exposdk:UNVERSIONED") {
39
40
  return "UNVERSIONED"
@@ -47,6 +48,10 @@ class NewManifest(json: JSONObject) : Manifest(json) {
47
48
  return null
48
49
  }
49
50
 
51
+ override fun getExpoGoSDKVersion(): String? {
52
+ return getExpoClientConfigRootObject()?.getString("sdkVersion") ?: getSDKVersionFromRuntimeVersion()
53
+ }
54
+
50
55
  @Throws(JSONException::class)
51
56
  fun getLaunchAsset(): JSONObject = json.require("launchAsset")
52
57
 
@@ -0,0 +1,59 @@
1
+ // Copyright 2015-present 650 Industries. All rights reserved.
2
+
3
+ package expo.modules.manifests.core
4
+
5
+ import com.google.common.truth.Truth
6
+ import org.json.JSONObject
7
+ import org.junit.Test
8
+
9
+ class ManifestTest {
10
+ @Test
11
+ fun getPluginProperties_emptyManifest_returnsNull() {
12
+ val manifestJson = JSONObject(emptyMap<String, Any>())
13
+ val manifest = Manifest.fromManifestJson(manifestJson)
14
+ Truth.assertThat(manifest.getPluginProperties("test")).isNull()
15
+ }
16
+
17
+ @Test
18
+ fun getPluginProperties_emptyPlugins_returnsNull() {
19
+ val manifestJson = JSONObject(mapOf<String, Any>("plugins" to emptyArray<Any>()))
20
+ val manifest = Manifest.fromManifestJson(manifestJson)
21
+ Truth.assertThat(manifest.getPluginProperties("test")).isNull()
22
+ }
23
+
24
+ @Test
25
+ fun getPluginProperties_nonMatchedPlugins_returnsNull() {
26
+ val manifestJson = JSONObject(mapOf<String, Any>("plugins" to arrayOf("hello")))
27
+ val manifest = Manifest.fromManifestJson(manifestJson)
28
+ Truth.assertThat(manifest.getPluginProperties("test")).isNull()
29
+ }
30
+
31
+ @Test
32
+ fun getPluginProperties_matchedPluginWithoutProps_returnsNull() {
33
+ val manifestJson = JSONObject(mapOf<String, Any>("plugins" to arrayOf("test")))
34
+ val manifest = Manifest.fromManifestJson(manifestJson)
35
+ Truth.assertThat(manifest.getPluginProperties("test")).isNull()
36
+ }
37
+
38
+ @Test
39
+ fun getPluginProperties_matchedPluginWithProps_returnsProps() {
40
+ val props = mapOf<String, Any>("foo" to "bar")
41
+ val pluginWithProp = arrayOf("test", props)
42
+ val manifestJson = JSONObject(mapOf<String, Any>("plugins" to arrayOf(pluginWithProp)))
43
+ val manifest = Manifest.fromManifestJson(manifestJson)
44
+ val result = manifest.getPluginProperties("test")
45
+ Truth.assertThat(result).isNotNull()
46
+ Truth.assertThat(result).containsExactlyEntriesIn(props)
47
+ }
48
+
49
+ @Test
50
+ fun getPluginProperties_matchedPluginWithNestedProps_returnsNestedProps() {
51
+ val props = mapOf<String, Any>("nested" to mapOf<String, Any>("insideNested" to true))
52
+ val pluginWithProp = arrayOf("test", props)
53
+ val manifestJson = JSONObject(mapOf<String, Any>("plugins" to arrayOf(pluginWithProp)))
54
+ val manifest = Manifest.fromManifestJson(manifestJson)
55
+ val result = manifest.getPluginProperties("test")
56
+ Truth.assertThat(result).isNotNull()
57
+ Truth.assertThat(result).containsExactlyEntriesIn(props)
58
+ }
59
+ }
@@ -1,12 +1,9 @@
1
1
  package expo.modules.manifests.core
2
2
 
3
- import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
4
3
  import org.json.JSONObject
5
4
  import org.junit.Assert
6
5
  import org.junit.Test
7
- import org.junit.runner.RunWith
8
6
 
9
- @RunWith(AndroidJUnit4ClassRunner::class)
10
7
  class NewManifestTest {
11
8
  @Test
12
9
  @Throws(Exception::class)
@@ -15,7 +12,7 @@ class NewManifestTest {
15
12
  val manifestJson =
16
13
  "{\"runtimeVersion\":\"$runtimeVersion\"}"
17
14
  val manifest = NewManifest(JSONObject(manifestJson))
18
- Assert.assertEquals(manifest.getSDKVersion(), "39.0.0")
15
+ Assert.assertEquals(manifest.getExpoGoSDKVersion(), "39.0.0")
19
16
  }
20
17
 
21
18
  @Test
@@ -25,7 +22,7 @@ class NewManifestTest {
25
22
  val manifestJson =
26
23
  "{\"runtimeVersion\":\"$runtimeVersion\"}"
27
24
  val manifest = NewManifest(JSONObject(manifestJson))
28
- Assert.assertEquals(manifest.getSDKVersion(), "UNVERSIONED")
25
+ Assert.assertEquals(manifest.getExpoGoSDKVersion(), "UNVERSIONED")
29
26
  }
30
27
 
31
28
  @Test
@@ -43,7 +40,7 @@ class NewManifestTest {
43
40
  val manifestJson =
44
41
  "{\"runtimeVersion\":\"$runtimeVersion\"}"
45
42
  val manifest = NewManifest(JSONObject(manifestJson))
46
- Assert.assertNull(manifest.getSDKVersion())
43
+ Assert.assertNull(manifest.getExpoGoSDKVersion())
47
44
  }
48
45
  }
49
46
  }
@@ -0,0 +1,19 @@
1
+ // Copyright © 2021 650 Industries. All rights reserved.
2
+
3
+ import Foundation
4
+
5
+ @objc(EXManifestsBareManifest)
6
+ @objcMembers
7
+ public class BareManifest: BaseLegacyManifest {
8
+ public func rawId() -> String {
9
+ return rawManifestJSON().requiredValue(forKey: "id")
10
+ }
11
+
12
+ public func commitTimeNumber() -> Int {
13
+ return rawManifestJSON().requiredValue(forKey: "commitTime")
14
+ }
15
+
16
+ public func metadata() -> [String: Any]? {
17
+ return rawManifestJSON().optionalValue(forKey: "metadata")
18
+ }
19
+ }
@@ -0,0 +1,39 @@
1
+ // Copyright © 2021 650 Industries. All rights reserved.
2
+
3
+ import Foundation
4
+
5
+ @objc(EXManifestBaseLegacyManifest)
6
+ @objcMembers
7
+ public class BaseLegacyManifest: Manifest {
8
+ override func expoClientConfigRootObject() -> [String: Any]? {
9
+ return rawManifestJSON()
10
+ }
11
+
12
+ override func expoGoConfigRootObject() -> [String: Any]? {
13
+ return rawManifestJSON()
14
+ }
15
+
16
+ public override func stableLegacyId() -> String {
17
+ return rawManifestJSON().optionalValue(forKey: "originalFullName") ?? legacyId()
18
+ }
19
+
20
+ public override func scopeKey() -> String {
21
+ return rawManifestJSON().optionalValue(forKey: "scopeKey") ?? stableLegacyId()
22
+ }
23
+
24
+ public override func easProjectId() -> String? {
25
+ return rawManifestJSON().optionalValue(forKey: "projectId")
26
+ }
27
+
28
+ public override func bundleUrl() -> String {
29
+ return rawManifestJSON().requiredValue(forKey: "bundleUrl")
30
+ }
31
+
32
+ public override func expoGoSDKVersion() -> String? {
33
+ return rawManifestJSON().optionalValue(forKey: "sdkVersion")
34
+ }
35
+
36
+ public func assets() -> [[String: Any]]? {
37
+ return self.rawManifestJSON().optionalValue(forKey: "assets")
38
+ }
39
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright © 2021 650 Industries. All rights reserved.
2
+ import Foundation
3
+
4
+ @objc(EXManifestsLegacyManifest)
5
+ @objcMembers
6
+ public class LegacyManifest: BaseLegacyManifest {
7
+ public func releaseID() -> String {
8
+ return rawManifestJSON().requiredValue(forKey: "releaseId")
9
+ }
10
+
11
+ public func commitTime() -> String {
12
+ return rawManifestJSON().requiredValue(forKey: "commitTime")
13
+ }
14
+
15
+ public func bundledAssets() -> [Any]? {
16
+ return rawManifestJSON().optionalValue(forKey: "bundledAssets")
17
+ }
18
+
19
+ public func runtimeVersion() -> Any? {
20
+ return rawManifestJSON().optionalValue(forKey: "runtimeVersion")
21
+ }
22
+
23
+ public func bundleKey() -> String? {
24
+ return rawManifestJSON().optionalValue(forKey: "bundleKey")
25
+ }
26
+
27
+ public func assetUrlOverride() -> String? {
28
+ return rawManifestJSON().optionalValue(forKey: "assetUrlOverride")
29
+ }
30
+ }