Skip to content

Commit

Permalink
[go] Update @react-native-async-storage/async-storage to 1.23.1 (#…
Browse files Browse the repository at this point in the history
…28154)

# Why

Updates `react-native-async-storage` to `1.23.1`

For now it keeps it as a vendored module, because there are some patch
files that should be applied only to ExpoGo version.

# How

Updated the patch files, then run:

```
et uvm -m @react-native-async-storage/async-storage -c v1.23.1
```

# Test Plan

Tesed in Expo Go in NCL on iOS 17 and Android 14
  • Loading branch information
behenate committed Apr 18, 2024
1 parent 46c9644 commit 4e6c0a8
Show file tree
Hide file tree
Showing 23 changed files with 508 additions and 218 deletions.
4 changes: 4 additions & 0 deletions apps/bare-expo/ios/BareExpo.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apps/bare-expo/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ PODS:
- React-logger (= 0.74.0-rc.9)
- React-perflogger (= 0.74.0-rc.9)
- React-utils (= 0.74.0-rc.9)
- RNCAsyncStorage (1.18.2):
- RNCAsyncStorage (1.23.1):
- React-Core
- RNCMaskedView (0.3.1):
- React-Core
Expand Down Expand Up @@ -2631,7 +2631,7 @@ SPEC CHECKSUMS:
React-runtimescheduler: a7eace44357207a91a32d4ad497c3d1ff1306eb0
React-utils: ab1d0edc4d9725b9979c192ffd6062365c898d7b
ReactCommon: 5448e997e7732e230daebf51eb9996727b4a66b9
RNCAsyncStorage: ddc4ee162bfd41b0d2c68bf2d95acd81dd7f1f93
RNCAsyncStorage: 826b603ae9c0f88b5ac4e956801f755109fa4d5c
RNCMaskedView: 090213d32d8b3bb83a4dcb7d12c18f0152591906
RNCPicker: 3e2c37a8328f368ce14da050cdc8231deb5fc9f9
RNDateTimePicker: 08f00a2c341bf96e4b30da15799fbdd4c5fa48a3
Expand Down
2 changes: 1 addition & 1 deletion apps/bare-expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@babel/runtime": "^7.20.0",
"@react-native-async-storage/async-storage": "1.18.2",
"@react-native-async-storage/async-storage": "1.23.1",
"@react-native-community/datetimepicker": "7.6.4",
"@react-native-community/netinfo": "11.3.1",
"@react-native-community/slider": "4.5.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,86 +1,68 @@
import java.nio.file.Paths

def resolveModulePath(packageName) {
def basePath = rootDir.toPath().normalize()

// Node's module resolution algorithm searches up to the root directory,
// after which the base path will be null
while (basePath) {
def candidatePath = Paths.get(basePath.toString(), 'node_modules', packageName)
if (candidatePath.toFile().exists()) {
return candidatePath.toString()
}

basePath = basePath.getParent()
}

return null
}

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def getFlagOrDefault(flagName, defaultValue) {
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] == "true" : defaultValue
}

def getVersionOrDefault(String flagName, String defaultVersion) {
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] : defaultVersion
}

configurations {
compileClasspath
}

buildscript {
// kotlin version is dictated by rootProject extension or property in gradle.properties
ext.asyncStorageKtVersion = rootProject.ext.has('kotlinVersion')
? rootProject.ext['kotlinVersion']
: rootProject.hasProperty('AsyncStorage_kotlinVersion')
? rootProject.properties['AsyncStorage_kotlinVersion']
: '1.8.10'
apply from: "config.gradle"
def kotlinVersion = ext.AsyncStorageConfig.kotlinVersion
def kspVersion = ext.AsyncStorageConfig.kspVersion

repositories {
mavenCentral()
google()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$asyncStorageKtVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "com.google.devtools.ksp:symbol-processing-gradle-plugin:$kspVersion"
}
}

// AsyncStorage has default size of 6MB.
// This is a sane limit to protect the user from the app storing too much data in the database.
// This also protects the database from filling up the disk cache and becoming malformed.
// If you really need bigger size, please keep in mind the potential consequences.
long dbSizeInMB = 6L
def newDbSize = rootProject.properties['AsyncStorage_db_size_in_MB']
if (newDbSize != null && newDbSize.isLong()) {
dbSizeInMB = newDbSize.toLong()
}

// Instead of reusing AsyncTask thread pool, AsyncStorage can use its own executor
def useDedicatedExecutor = getFlagOrDefault('AsyncStorage_dedicatedExecutor', false)
apply plugin: 'com.android.library'
apply from: 'config.gradle'

// Use next storage implementation
def useNextStorage = getFlagOrDefault("AsyncStorage_useNextStorage", false)
boolean isNewArchitectureEnabled = ext.AsyncStorageConfig.isNewArchitectureEnabled
boolean useNextStorage = ext.AsyncStorageConfig.useNextStorage

logger.info("[AsyncStorage] Config used: {}", ext.AsyncStorageConfig)

apply plugin: 'com.android.library'
if (useNextStorage) {
apply plugin: 'com.google.devtools.ksp'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply from: './testresults.gradle'
}

if (isNewArchitectureEnabled) {
apply plugin: "com.facebook.react"
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', 32)
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
namespace "com.reactnativecommunity.asyncstorage"
buildFeatures {
buildConfig true
}
}

compileSdkVersion project.ext.AsyncStorageConfig.compileSdkVersion
// Used to override the NDK path/version by allowing users to customize
// the NDK path/version from their root project (e.g. for M1 support)
if (rootProject.hasProperty("ndkPath")) {
ndkPath rootProject.ext.ndkPath
}
if (rootProject.hasProperty("ndkVersion")) {
ndkVersion rootProject.ext.ndkVersion
}


defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 23)
targetSdkVersion safeExtGet('targetSdkVersion', 32)
buildConfigField "Long", "AsyncStorage_db_size", "${dbSizeInMB}L"
buildConfigField "boolean", "AsyncStorage_useDedicatedExecutor", "${useDedicatedExecutor}"
minSdkVersion project.ext.AsyncStorageConfig.minSdkVersion
targetSdkVersion project.ext.AsyncStorageConfig.targetSdkVersion
buildConfigField "Long", "AsyncStorage_db_size", "${project.ext.AsyncStorageConfig.databaseSizeMB}L"
buildConfigField "boolean", "AsyncStorage_useDedicatedExecutor", "${project.ext.AsyncStorageConfig.useDedicatedExecutor}"
buildConfigField "boolean", "AsyncStorage_useNextStorage", "${useNextStorage}"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "${isNewArchitectureEnabled}"
}
lintOptions {
abortOnError false
Expand All @@ -94,49 +76,49 @@ android {
}
}
}

sourceSets.main {
java {
if (useNextStorage) {
srcDirs += 'src/kotlinPackage/java'
} else {
srcDirs += 'src/javaPackage/java'
}

if (!isNewArchitectureEnabled) {
srcDirs += 'src/oldarch/java'
}
}
}
}

repositories {
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "${resolveModulePath("react-native")}/android"
url "${project.ext.resolveModulePath("react-native")}/android"
}
google()
mavenCentral()
}

dependencies {

if (useNextStorage) {
def room_version = getVersionOrDefault('AsyncStorage_next_roomVersion', '2.4.3')
def coroutines_version = "1.6.4"
def coroutinesTest_version = "1.6.4"
// if we don't provide explicit dependency on reflection, kotlin plugin
// would add one automatically, probably a version that is not compatible with
// used kotlin
def kotlinReflect_version = project.ext.asyncStorageKtVersion
def junit_version = "4.13.2"
def robolectric_version = "4.7.3"
def truth_version = "1.1.3"
def androidxtest_version = "1.4.0"
def androidtest_junit_version = "1.1.3"
def room_version = project.ext.AsyncStorageConfig.roomVersion

implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinReflect_version"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
kapt "androidx.room:room-compiler:$room_version"

testImplementation "junit:junit:$junit_version"
testImplementation "androidx.test:runner:$androidxtest_version"
testImplementation "androidx.test:rules:$androidxtest_version"
testImplementation "androidx.test.ext:junit:$androidtest_junit_version"
testImplementation "org.robolectric:robolectric:$robolectric_version"
testImplementation "com.google.truth:truth:$truth_version"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesTest_version"
ksp "androidx.room:room-compiler:$room_version"

implementation project.ext.AsyncStorageLibs.coroutines

testImplementation project.ext.AsyncStorageLibs.testCoroutines
testImplementation project.ext.AsyncStorageLibs.testJunit
testImplementation project.ext.AsyncStorageLibs.testExtJunit
testImplementation project.ext.AsyncStorageLibs.testRunner
testImplementation project.ext.AsyncStorageLibs.testRules
testImplementation project.ext.AsyncStorageLibs.testRobolectric
testImplementation project.ext.AsyncStorageLibs.testTruth
}

//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}
implementation 'com.facebook.react:react-native:+' // from node_modules
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import java.nio.file.Paths

def DEFAULT_KOTLIN_VERSION = "1.9.20"
def DEFAULT_ROOM_VERSION = "2.4.3"

def kotlinVersion = getKotlinVersion(DEFAULT_KOTLIN_VERSION)

project.ext.AsyncStorageConfig = [
kotlinVersion : kotlinVersion,
kspVersion : getKspVersion(kotlinVersion),
roomVersion : getPropertyOfDefault('AsyncStorage_next_roomVersion', DEFAULT_ROOM_VERSION),
minSdkVersion : safeExtGet('minSdkVersion', 23),
targetSdkVersion : safeExtGet('targetSdkVersion', 32),
compileSdkVersion : safeExtGet('compileSdkVersion', 32),
useNextStorage : getFlagOrDefault("AsyncStorage_useNextStorage", false),
databaseSizeMB : getDatabaseSize(),
isNewArchitectureEnabled: isNewArchitectureEnabled(),
useDedicatedExecutor : getFlagOrDefault('AsyncStorage_dedicatedExecutor', false),
]

project.ext.AsyncStorageLibs = [
coroutines : "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3",
testCoroutines : "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3",
testJunit : "junit:junit:4.13.2",
testRunner : "androidx.test:runner:1.4.0",
testRules : "androidx.test:rules:1.4.0",
testExtJunit : "androidx.test.ext:junit:1.1.3",
testRobolectric: "org.robolectric:robolectric:4.11.1",
testTruth : "com.google.truth:truth:1.1.3",
]


def getKotlinVersion(String defaultVersion) {
return rootProject.ext.has('kotlinVersion')
? rootProject.ext['kotlinVersion']
: rootProject.hasProperty('AsyncStorage_kotlinVersion')
? rootProject.properties['AsyncStorage_kotlinVersion']
: defaultVersion
}

def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
// - Invoke gradle with `-newArchEnabled=true`
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

String getKspVersion(String kotlinVersion) {

String overriddenKspVersion = getPropertyOfDefault("AsyncStorage_next_kspVersion", null)
if (overriddenKspVersion != null) {
return overriddenKspVersion
}
// https://github.com/google/ksp/releases
def kspVersions = [
"1.9.20-1.0.14",
"1.9.10-1.0.13",
"1.9.0-1.0.13",
"1.8.22-1.0.11",
"1.8.21-1.0.11",
"1.8.20-1.0.11",
"1.8.10-1.0.9",
"1.8.0-1.0.9",
"1.7.22-1.0.8",
"1.7.21-1.0.8",
"1.7.20-1.0.8",
"1.7.10-1.0.6",
"1.7.0-1.0.6",
"1.6.21-1.0.6",
"1.6.20-1.0.5",
"1.6.10-1.0.4",
"1.6.0-1.0.2",
"1.5.31-1.0.1",
"1.5.30-1.0.0",
]

return kspVersions.find { it.startsWith(kotlinVersion) } ?: kspVersions.first()
}

// AsyncStorage has default size of 6MB.
// This is a sane limit to protect the user from the app storing too much data in the database.
// This also protects the database from filling up the disk cache and becoming malformed.
// If you really need bigger size, please keep in mind the potential consequences.
long getDatabaseSize() {
long dbSizeInMB = 6L
def newDbSize = getPropertyOfDefault('AsyncStorage_db_size_in_MB', null)
if (newDbSize != null && newDbSize.isLong()) {
dbSizeInMB = newDbSize.toLong()
}
return dbSizeInMB
}

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def getFlagOrDefault(flagName, defaultValue) {
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] == "true" : defaultValue
}

def getPropertyOfDefault(String flagName, String defaultVersion) {
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] : defaultVersion
}

ext.resolveModulePath = { packageName ->
def basePath = rootDir.toPath().normalize()

// Node's module resolution algorithm searches up to the root directory,
// after which the base path will be null
while (basePath) {
def candidatePath = Paths.get(basePath.toString(), 'node_modules', packageName)
if (candidatePath.toFile().exists()) {
return candidatePath.toString()
}

basePath = basePath.getParent()
}

return null
}

0 comments on commit 4e6c0a8

Please sign in to comment.