expo-network-addons 0.1.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.
- package/.eslintrc.js +2 -0
- package/README.md +24 -0
- package/android/build.gradle +93 -0
- package/android/proguard-rules.pro +11 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/networkaddons/ExpoOkHttpInterceptor.kt +13 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +2 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +12 -0
- package/expo-network-addons-gradle-plugin/build.gradle.kts +38 -0
- package/expo-network-addons-gradle-plugin/src/main/kotlin/expo/modules/networkaddons/NetworkAddonsPlugin.kt +135 -0
- package/package.json +43 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +9 -0
package/.eslintrc.js
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# expo-network-addons
|
|
2
|
+
|
|
3
|
+
**`expo-network-addons`** is a set of networking addons
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Brotli Compression on Android
|
|
8
|
+
|
|
9
|
+
`expo-network-addons` provides automatic Brotli compression for all OkHttp requests made by your app. This can significantly reduce the size of network responses, resulting in faster load times and reduced data usage. The Brotli support is backed by [okhttp-brotli](https://github.com/square/okhttp/blob/master/okhttp-brotli/).
|
|
10
|
+
|
|
11
|
+
## API documentation
|
|
12
|
+
|
|
13
|
+
- [Documentation for the main branch][docs-main]
|
|
14
|
+
- [Documentation for the latest stable release][docs-stable]
|
|
15
|
+
|
|
16
|
+
### Installation
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
npx expo install expo-network-addons
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Contributing
|
|
23
|
+
|
|
24
|
+
Contributions are very welcome! Please refer to guidelines described in the [contributing guide](https://github.com/expo/expo#contributing).
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
apply plugin: 'kotlin-android'
|
|
3
|
+
apply plugin: 'maven-publish'
|
|
4
|
+
|
|
5
|
+
group = 'expo.modules.networkaddons'
|
|
6
|
+
version = '0.1.0'
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
10
|
+
if (expoModulesCorePlugin.exists()) {
|
|
11
|
+
apply from: expoModulesCorePlugin
|
|
12
|
+
applyKotlinExpoModulesCorePlugin()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Simple helper that allows the root project to override versions declared by this library.
|
|
16
|
+
ext.safeExtGet = { prop, fallback ->
|
|
17
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Ensures backward compatibility
|
|
21
|
+
ext.getKotlinVersion = {
|
|
22
|
+
if (ext.has("kotlinVersion")) {
|
|
23
|
+
ext.kotlinVersion()
|
|
24
|
+
} else {
|
|
25
|
+
ext.safeExtGet("kotlinVersion", "1.8.10")
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
repositories {
|
|
30
|
+
mavenCentral()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dependencies {
|
|
34
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
afterEvaluate {
|
|
39
|
+
publishing {
|
|
40
|
+
publications {
|
|
41
|
+
release(MavenPublication) {
|
|
42
|
+
from components.release
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
repositories {
|
|
46
|
+
maven {
|
|
47
|
+
url = mavenLocal().url
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
android {
|
|
54
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 31)
|
|
55
|
+
|
|
56
|
+
compileOptions {
|
|
57
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
58
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
kotlinOptions {
|
|
62
|
+
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
namespace "expo.modules.networkaddons"
|
|
66
|
+
defaultConfig {
|
|
67
|
+
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
68
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 31)
|
|
69
|
+
versionCode 1
|
|
70
|
+
versionName "0.1.0"
|
|
71
|
+
consumerProguardFiles("proguard-rules.pro")
|
|
72
|
+
}
|
|
73
|
+
lintOptions {
|
|
74
|
+
abortOnError false
|
|
75
|
+
}
|
|
76
|
+
publishing {
|
|
77
|
+
singleVariant("release") {
|
|
78
|
+
withSourcesJar()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
repositories {
|
|
84
|
+
mavenCentral()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
dependencies {
|
|
88
|
+
implementation project(':expo-modules-core')
|
|
89
|
+
implementation("com.squareup.okhttp3:okhttp:4.9.2")
|
|
90
|
+
implementation("com.squareup.okhttp3:okhttp-brotli:4.9.2")
|
|
91
|
+
|
|
92
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
93
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2015-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
package expo.modules.networkaddons
|
|
4
|
+
|
|
5
|
+
import okhttp3.Interceptor
|
|
6
|
+
import okhttp3.Response
|
|
7
|
+
import okhttp3.brotli.BrotliInterceptor
|
|
8
|
+
|
|
9
|
+
@Suppress("unused")
|
|
10
|
+
class ExpoOkHttpInterceptor : Interceptor {
|
|
11
|
+
override fun intercept(chain: Interceptor.Chain): Response =
|
|
12
|
+
BrotliInterceptor.intercept(chain)
|
|
13
|
+
}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,wBAAkB"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAe,EAAE,CAAC","sourcesContent":["export default {};\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
2
|
+
|
|
3
|
+
plugins {
|
|
4
|
+
kotlin("jvm") version "1.8.10"
|
|
5
|
+
id("java-gradle-plugin")
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
repositories {
|
|
9
|
+
google()
|
|
10
|
+
mavenCentral()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
dependencies {
|
|
14
|
+
implementation(gradleApi())
|
|
15
|
+
implementation("com.android.tools.build:gradle:7.4.2")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
java {
|
|
19
|
+
sourceCompatibility = JavaVersion.VERSION_11
|
|
20
|
+
targetCompatibility = JavaVersion.VERSION_11
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
tasks.withType<KotlinCompile> {
|
|
24
|
+
kotlinOptions {
|
|
25
|
+
jvmTarget = JavaVersion.VERSION_11.toString()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
group = "expo.modules"
|
|
30
|
+
|
|
31
|
+
gradlePlugin {
|
|
32
|
+
plugins {
|
|
33
|
+
register("expoNetworkAddonsPlugin") {
|
|
34
|
+
id = "expo-network-addons-gradle-plugin"
|
|
35
|
+
implementationClass = "expo.modules.networkaddons.NetworkAddonsPlugin"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Copyright 2015-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
package expo.modules.networkaddons
|
|
4
|
+
|
|
5
|
+
import com.android.build.api.instrumentation.AsmClassVisitorFactory
|
|
6
|
+
import com.android.build.api.instrumentation.ClassContext
|
|
7
|
+
import com.android.build.api.instrumentation.ClassData
|
|
8
|
+
import com.android.build.api.instrumentation.FramesComputationMode
|
|
9
|
+
import com.android.build.api.instrumentation.InstrumentationParameters
|
|
10
|
+
import com.android.build.api.instrumentation.InstrumentationScope
|
|
11
|
+
import com.android.build.api.variant.AndroidComponentsExtension
|
|
12
|
+
import org.gradle.api.Plugin
|
|
13
|
+
import org.gradle.api.Project
|
|
14
|
+
import org.gradle.api.provider.Property
|
|
15
|
+
import org.gradle.api.tasks.Input
|
|
16
|
+
import org.gradle.api.tasks.Optional
|
|
17
|
+
import org.objectweb.asm.ClassVisitor
|
|
18
|
+
import org.objectweb.asm.MethodVisitor
|
|
19
|
+
import org.objectweb.asm.Opcodes
|
|
20
|
+
import org.slf4j.LoggerFactory
|
|
21
|
+
|
|
22
|
+
abstract class NetworkAddonsPlugin : Plugin<Project> {
|
|
23
|
+
|
|
24
|
+
override fun apply(project: Project) {
|
|
25
|
+
val androidComponents = project.extensions.getByType(AndroidComponentsExtension::class.java)
|
|
26
|
+
val devLauncherInstalled = project.findProject(":expo-dev-launcher") != null
|
|
27
|
+
|
|
28
|
+
androidComponents.onVariants(androidComponents.selector().all()) { variant ->
|
|
29
|
+
variant.instrumentation.transformClassesWith(NetworkAddonsClassVisitorFactory::class.java, InstrumentationScope.ALL) {
|
|
30
|
+
it.enabled.set(true)
|
|
31
|
+
it.debugVariant.set(variant.buildType == "debug")
|
|
32
|
+
it.devLauncherInstalled.set(devLauncherInstalled)
|
|
33
|
+
}
|
|
34
|
+
variant.instrumentation.setAsmFramesComputationMode(FramesComputationMode.COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface NetworkAddonsPluginParameters : InstrumentationParameters {
|
|
39
|
+
@get:Input
|
|
40
|
+
@get:Optional
|
|
41
|
+
val enabled: Property<Boolean>
|
|
42
|
+
|
|
43
|
+
@get:Input
|
|
44
|
+
@get:Optional
|
|
45
|
+
val debugVariant: Property<Boolean>
|
|
46
|
+
|
|
47
|
+
@get:Input
|
|
48
|
+
@get:Optional
|
|
49
|
+
val devLauncherInstalled: Property<Boolean>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
abstract class NetworkAddonsClassVisitorFactory : AsmClassVisitorFactory<NetworkAddonsPluginParameters> {
|
|
53
|
+
override fun createClassVisitor(
|
|
54
|
+
classContext: ClassContext,
|
|
55
|
+
nextClassVisitor: ClassVisitor
|
|
56
|
+
): ClassVisitor {
|
|
57
|
+
if (parameters.get().enabled.getOrElse(false)) {
|
|
58
|
+
logger.debug("[NetworkAddonsPlugin] parameters: debugVariant[${parameters.get().debugVariant}] devLauncherInstalled[${parameters.get().devLauncherInstalled}]")
|
|
59
|
+
return OkHttpClassVisitor(classContext, instrumentationContext.apiVersion.get(), nextClassVisitor, parameters.get())
|
|
60
|
+
}
|
|
61
|
+
return nextClassVisitor
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
override fun isInstrumentable(classData: ClassData): Boolean {
|
|
65
|
+
if (parameters.get().enabled.getOrElse(false)) {
|
|
66
|
+
return classData.className in listOf("okhttp3.OkHttpClient\$Builder")
|
|
67
|
+
}
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class OkHttpClassVisitor(
|
|
73
|
+
private val classContext: ClassContext,
|
|
74
|
+
api: Int, classVisitor: ClassVisitor,
|
|
75
|
+
private val parameters: NetworkAddonsPluginParameters
|
|
76
|
+
) : ClassVisitor(api, classVisitor) {
|
|
77
|
+
override fun visitMethod(access: Int, name: String?, descriptor: String?, signature: String?, exceptions: Array<out String>?): MethodVisitor {
|
|
78
|
+
val originalVisitor = super.visitMethod(access, name, descriptor, signature, exceptions)
|
|
79
|
+
if (name == "build") {
|
|
80
|
+
return OkHttpClientCustomBuildMethod(api, originalVisitor, parameters)
|
|
81
|
+
}
|
|
82
|
+
return originalVisitor
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
class OkHttpClientCustomBuildMethod(
|
|
87
|
+
api: Int, methodVisitor: MethodVisitor,
|
|
88
|
+
private val parameters: NetworkAddonsPluginParameters
|
|
89
|
+
) : MethodVisitor(api, methodVisitor) {
|
|
90
|
+
override fun visitCode() {
|
|
91
|
+
// opcodes for `this.addInterceptor(expo.modules.kotlin.devtools.ExpoNetworkInspectOkHttpAppInterceptor())`
|
|
92
|
+
visitVarInsn(Opcodes.ALOAD, 0)
|
|
93
|
+
visitTypeInsn(Opcodes.NEW, "expo/modules/networkaddons/ExpoOkHttpInterceptor")
|
|
94
|
+
visitInsn(Opcodes.DUP)
|
|
95
|
+
visitMethodInsn(Opcodes.INVOKESPECIAL, "expo/modules/networkaddons/ExpoOkHttpInterceptor", "<init>", "()V", false)
|
|
96
|
+
visitTypeInsn(Opcodes.CHECKCAST, "okhttp3/Interceptor")
|
|
97
|
+
visitMethodInsn(Opcodes.INVOKEVIRTUAL, "okhttp3/OkHttpClient\$Builder", "addInterceptor", "(Lokhttp3/Interceptor;)Lokhttp3/OkHttpClient\$Builder;", false)
|
|
98
|
+
|
|
99
|
+
if (parameters.debugVariant.getOrElse(false) && parameters.devLauncherInstalled.getOrElse(false)) {
|
|
100
|
+
//
|
|
101
|
+
// NOTE: The following code should be kept in sync with **packages/expo-dev-launcher/expo-dev-launcher-gradle-plugin/src/main/kotlin/expo/modules/devlauncher/DevLauncherPlugin.kt**
|
|
102
|
+
//
|
|
103
|
+
|
|
104
|
+
// opcodes for `this.addInterceptor(expo.modules.kotlin.devtools.ExpoNetworkInspectOkHttpAppInterceptor())`
|
|
105
|
+
visitVarInsn(Opcodes.ALOAD, 0)
|
|
106
|
+
visitTypeInsn(Opcodes.NEW, "expo/modules/kotlin/devtools/ExpoNetworkInspectOkHttpAppInterceptor")
|
|
107
|
+
visitInsn(Opcodes.DUP)
|
|
108
|
+
visitMethodInsn(Opcodes.INVOKESPECIAL, "expo/modules/kotlin/devtools/ExpoNetworkInspectOkHttpAppInterceptor", "<init>", "()V", false)
|
|
109
|
+
visitTypeInsn(Opcodes.CHECKCAST, "okhttp3/Interceptor")
|
|
110
|
+
visitMethodInsn(Opcodes.INVOKEVIRTUAL, "okhttp3/OkHttpClient\$Builder", "addInterceptor", "(Lokhttp3/Interceptor;)Lokhttp3/OkHttpClient\$Builder;", false)
|
|
111
|
+
|
|
112
|
+
// opcodes for `this.addNetworkInterceptor(expo.modules.kotlin.devtools.ExpoNetworkInspectOkHttpNetworkInterceptor())`
|
|
113
|
+
visitVarInsn(Opcodes.ALOAD, 0)
|
|
114
|
+
visitTypeInsn(Opcodes.NEW, "expo/modules/kotlin/devtools/ExpoNetworkInspectOkHttpNetworkInterceptor")
|
|
115
|
+
visitInsn(Opcodes.DUP)
|
|
116
|
+
visitMethodInsn(Opcodes.INVOKESPECIAL, "expo/modules/kotlin/devtools/ExpoNetworkInspectOkHttpNetworkInterceptor", "<init>", "()V", false)
|
|
117
|
+
visitTypeInsn(Opcodes.CHECKCAST, "okhttp3/Interceptor")
|
|
118
|
+
visitMethodInsn(Opcodes.INVOKEVIRTUAL, "okhttp3/OkHttpClient\$Builder", "addNetworkInterceptor", "(Lokhttp3/Interceptor;)Lokhttp3/OkHttpClient\$Builder;", false)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// opcodes for `return OkHttpClient(this)`
|
|
122
|
+
visitTypeInsn(Opcodes.NEW, "okhttp3/OkHttpClient")
|
|
123
|
+
visitInsn(Opcodes.DUP)
|
|
124
|
+
visitVarInsn(Opcodes.ALOAD, 0)
|
|
125
|
+
visitMethodInsn(Opcodes.INVOKESPECIAL, "okhttp3/OkHttpClient", "<init>", "(Lokhttp3/OkHttpClient\$Builder;)V", false)
|
|
126
|
+
visitInsn(Opcodes.ARETURN)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
companion object {
|
|
131
|
+
internal val logger by lazy {
|
|
132
|
+
LoggerFactory.getLogger(NetworkAddonsPlugin::class.java)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "expo-network-addons",
|
|
3
|
+
"title": "Expo Networking Addons",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Expo module that provides extra functionalities for networking",
|
|
6
|
+
"main": "build/index.js",
|
|
7
|
+
"types": "build/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "expo-module build",
|
|
11
|
+
"clean": "expo-module clean",
|
|
12
|
+
"lint": "expo-module lint",
|
|
13
|
+
"test": "expo-module test",
|
|
14
|
+
"prepare": "expo-module prepare",
|
|
15
|
+
"prepublishOnly": "expo-module prepublishOnly",
|
|
16
|
+
"expo-module": "expo-module"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://docs.expo.dev/",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/expo/expo.git",
|
|
22
|
+
"directory": "packages/expo-network-addons"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"react-native",
|
|
26
|
+
"expo",
|
|
27
|
+
"expo-network-addons",
|
|
28
|
+
"ExpoNetworkAddons",
|
|
29
|
+
"network",
|
|
30
|
+
"addons",
|
|
31
|
+
"EAS"
|
|
32
|
+
],
|
|
33
|
+
"author": "650 Industries, Inc.",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"dependencies": {},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"expo-module-scripts": "^3.0.4"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"expo": "*"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "73a47bb80ef6baac585af29383a92f312813f638"
|
|
43
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|
package/tsconfig.json
ADDED