From 4b9a9df0103014d89148b65e2fd74c03c84c08d3 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Mon, 17 Apr 2023 07:16:45 +0100 Subject: [PATCH 01/18] chore: add and use spec for ScriptManager --- packages/repack/js/NativeScriptManager.ts | 12 ++++++++++++ packages/repack/js/index.ts | 6 ++++++ .../src/modules/ScriptManager/ScriptManager.ts | 4 ++-- packages/repack/tsconfig.json | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 packages/repack/js/NativeScriptManager.ts create mode 100644 packages/repack/js/index.ts diff --git a/packages/repack/js/NativeScriptManager.ts b/packages/repack/js/NativeScriptManager.ts new file mode 100644 index 000000000..9564536e1 --- /dev/null +++ b/packages/repack/js/NativeScriptManager.ts @@ -0,0 +1,12 @@ +import type {TurboModule} from 'react-native'; +import {TurboModuleRegistry} from 'react-native'; + +export interface Spec extends TurboModule { + readonly getConstants: () => {}; + + loadScript(scriptId: string, config: Object): Promise; + prefetchScript(scriptId: string, config: Object): Promise; + invalidateScripts(scripts: Array): Promise; +} + +export default TurboModuleRegistry.get('ScriptManager') as Spec; \ No newline at end of file diff --git a/packages/repack/js/index.ts b/packages/repack/js/index.ts new file mode 100644 index 000000000..edbcadade --- /dev/null +++ b/packages/repack/js/index.ts @@ -0,0 +1,6 @@ +/* + TurboModuleRegistry.get taps into the old Native Modules API under the hood, + we need to re-export our module, to avoid registering it multiple times. +*/ + +export default require('./NativeScriptManager').default; \ No newline at end of file diff --git a/packages/repack/src/modules/ScriptManager/ScriptManager.ts b/packages/repack/src/modules/ScriptManager/ScriptManager.ts index 7945ecf5a..232088ff0 100644 --- a/packages/repack/src/modules/ScriptManager/ScriptManager.ts +++ b/packages/repack/src/modules/ScriptManager/ScriptManager.ts @@ -1,6 +1,6 @@ /* globals __DEV__, __webpack_require__ */ import EventEmitter from 'events'; -import { NativeModules } from 'react-native'; +import NativeScriptManager from '../../../js' import { getWebpackContext } from './getWebpackContext'; import { Script } from './Script'; import type { @@ -101,7 +101,7 @@ export class ScriptManager extends EventEmitter { * @internal */ protected constructor( - private nativeScriptManager = NativeModules.ScriptManager + private nativeScriptManager = NativeScriptManager ) { super(); diff --git a/packages/repack/tsconfig.json b/packages/repack/tsconfig.json index 545004f0b..1fa115a4a 100644 --- a/packages/repack/tsconfig.json +++ b/packages/repack/tsconfig.json @@ -69,6 +69,6 @@ "skipLibCheck": true, /* Skip type checking of declaration files. */ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ }, - "include": ["src/**/*"], + "include": ["src/**/*", "js/NativeScriptManager.ts"], "exclude": ["**/__tests__/**"] } \ No newline at end of file From e68eb4d1938aa6a300905f4f62c6ba1359850e35 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Mon, 17 Apr 2023 07:20:28 +0100 Subject: [PATCH 02/18] chore: setup codegen to generate stubs using NativeScriptManagerSpec --- packages/repack/package.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/repack/package.json b/packages/repack/package.json index 58062bf72..d0f619d1f 100644 --- a/packages/repack/package.json +++ b/packages/repack/package.json @@ -112,5 +112,13 @@ "typescript": "^4.1.5", "webpack": "^5.75.0", "webpack-virtual-modules": "^0.4.4" + }, + "codegenConfig": { + "name": "repack", + "type": "modules", + "jsSrcsDir": "./js", + "android": { + "javaPackageName": "com.callstack.repack" + } } } From 46e4f1cb80e859168b1c5536a3734904906e1cc3 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Mon, 17 Apr 2023 07:28:44 +0100 Subject: [PATCH 03/18] chore: configure podspec to selectively use old and new arch --- packages/repack/callstack-repack.podspec | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/repack/callstack-repack.podspec b/packages/repack/callstack-repack.podspec index db9daa464..5b03a45ee 100644 --- a/packages/repack/callstack-repack.podspec +++ b/packages/repack/callstack-repack.podspec @@ -1,6 +1,7 @@ require "json" package = JSON.parse(File.read(File.join(__dir__, "package.json"))) +folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' Pod::Spec.new do |s| s.name = "callstack-repack" @@ -20,4 +21,20 @@ Pod::Spec.new do |s| s.dependency "React-Core" s.dependency 'JWTDecode', '~> 3.0' s.dependency 'SwiftyRSA' -end + + # Don't install the dependencies when we run `pod install` in the old architecture. + if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then + s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" + s.pod_target_xcconfig = { + "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", + "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1", + "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" + } + s.dependency "React-Codegen" + s.dependency "RCT-Folly" + s.dependency "RCTRequired" + s.dependency "RCTTypeSafety" + s.dependency "ReactCommon/turbomodule/core" + s.dependency "React-RCTFabric" + end +end \ No newline at end of file From 80a85c8649651580901e400c8d4d635b1dbea10b Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Mon, 17 Apr 2023 07:29:14 +0100 Subject: [PATCH 04/18] chore: enable newarch support for iOS and implement stubs --- packages/repack/ios/ScriptManager.h | 14 ++++ packages/repack/ios/ScriptManager.mm | 110 +++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) diff --git a/packages/repack/ios/ScriptManager.h b/packages/repack/ios/ScriptManager.h index 37160c50b..06bb5a4e0 100644 --- a/packages/repack/ios/ScriptManager.h +++ b/packages/repack/ios/ScriptManager.h @@ -1,3 +1,16 @@ +// Use Native Module Spec when we run new architecure +#ifdef RCT_NEW_ARCH_ENABLED +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface ScriptManager : NSObject + +@end + +NS_ASSUME_NONNULL_END + +#else #ifndef ScriptManager_h #define ScriptManager_h @@ -8,3 +21,4 @@ @end #endif /* ScriptManager_h */ +#endif \ No newline at end of file diff --git a/packages/repack/ios/ScriptManager.mm b/packages/repack/ios/ScriptManager.mm index 0dca8e674..ce5e03e16 100644 --- a/packages/repack/ios/ScriptManager.mm +++ b/packages/repack/ios/ScriptManager.mm @@ -262,4 +262,114 @@ - (void)runInBackground:(void(^)())callback dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), callback); } +// We won't compile this code when we build for the old architecture. +#ifdef RCT_NEW_ARCH_ENABLED +- (std::shared_ptr)getTurboModule: + (const facebook::react::ObjCTurboModule::InitParams &)params +{ + return std::make_shared(params); +} +#endif + +- (void)invalidateScripts:(NSArray *)scripts resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { + [self runInBackground:^(){ + NSFileManager* manager = [NSFileManager defaultManager]; + NSString* scriptsDirecotryPath = [self getScriptsDirectoryPath]; + + NSError *error; + if (scripts.count == 0 && [manager fileExistsAtPath:scriptsDirecotryPath]) { + [manager removeItemAtPath:scriptsDirecotryPath error:&error]; + } else { + for (int i = 0; i < scripts.count; i++) { + NSString* scriptFilePath = [self getScriptFilePath:scripts[i]]; + if ([manager fileExistsAtPath:scriptFilePath]) { + [manager removeItemAtPath:[self getScriptFilePath:scripts[i]] error:&error]; + } + if (error != nil) { + break; + } + } + } + + if (error != nil) { + reject(InvalidationFailure, error.localizedDescription, nil); + } else { + resolve(nil); + } + }]; +} + +- (void)loadScript:(NSString *)scriptId config:(NSDictionary *)configDictionary resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { + [self runInBackground:^(){ + // Cast `RCTBridge` to `RCTCxxBridge`. + __weak RCTCxxBridge *bridge = (RCTCxxBridge *)self->_bridge; + + ScriptConfig *config; + @try { + config = [ScriptConfig fromConfigDictionary:configDictionary withScriptId:scriptId]; + } @catch (NSError *error) { + reject(ScriptConfigError, error.localizedDescription, nil); + return; + } + + // Handle http & https + if ([[config.url scheme] hasPrefix:@"http"]) { + if (config.fetch) { + [self downloadAndCache:config completionHandler:^(NSError *error) { + if (error) { + reject(ScriptDownloadFailure, error.localizedFailureReason, nil); + } else { + [self execute:bridge + scriptId:config.scriptId + url:config.url + withResolver:resolve + withRejecter:reject]; + } + }]; + } else { + [self execute:bridge scriptId:scriptId url:config.url withResolver:resolve withRejecter:reject]; + } + + } else if ([[config.url scheme] isEqualToString:@"file"]) { + [self executeFromFilesystem:bridge + config:config + withResolver:resolve + withRejecter:reject]; + } else { + reject(UnsupportedScheme, + [NSString stringWithFormat:@"Scheme in URL '%@' is not supported", config.url.absoluteString], nil); + } + }]; +} + +- (void)prefetchScript:(NSString *)scriptId config:(NSDictionary *)configDictionary resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { + ScriptConfig *config; + @try { + config = [ScriptConfig fromConfigDictionary:configDictionary withScriptId:scriptId]; + } @catch (NSError *error) { + reject(ScriptConfigError, error.localizedDescription, nil); + return; + } + + if (!config.fetch) { + // Do nothing, script is already prefetched + resolve(nil); + } else { + [self runInBackground:^(){ + if ([[config.url scheme] hasPrefix:@"http"]) { + [self downloadAndCache:config completionHandler:^(NSError *error) { + if (error) { + reject(ScriptDownloadFailure, error.localizedFailureReason, nil); + } else { + resolve(nil); + } + }]; + } else { + reject(UnsupportedScheme, + [NSString stringWithFormat:@"Scheme in URL '%@' is not supported", config.url.absoluteString], nil); + } + }]; + } +} + @end From f74ed2a393a279925f6c1d6e66c912a73214c958 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Mon, 17 Apr 2023 07:30:47 +0100 Subject: [PATCH 05/18] chore: configure android build.gradle to support new and old arch --- packages/repack/android/build.gradle | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/repack/android/build.gradle b/packages/repack/android/build.gradle index c84bcf488..90761b7c2 100644 --- a/packages/repack/android/build.gradle +++ b/packages/repack/android/build.gradle @@ -14,9 +14,17 @@ buildscript { } } +def isNewArchitectureEnabled() { + return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" +} + apply plugin: 'com.android.library' apply plugin: 'kotlin-android' +if (isNewArchitectureEnabled()) { + apply plugin: 'com.facebook.react' +} + def getExtOrDefault(name) { return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['RePack_' + name] } @@ -33,7 +41,17 @@ android { targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') versionCode 1 versionName "1.0" + buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()) + } + sourceSets { + main { + if (isNewArchitectureEnabled()) { + java.srcDirs += ['src/newarch'] + } else { + java.srcDirs += ['src/oldarch'] + } + } } buildTypes { From bae8035024f3c2161e0c6a5c54971e621a595bb0 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Mon, 17 Apr 2023 07:31:42 +0100 Subject: [PATCH 06/18] chore: enable newarch support for android and implement module for new and old arch --- .../callstack/repack/ChunkManagerModule.kt | 96 ------------------- .../repack/ChunkManagerModuleImpl.kt | 91 ++++++++++++++++++ .../callstack/repack/ChunkManagerPackage.kt | 37 ++++--- .../callstack/repack/ChunkManagerModule.kt | 25 +++++ .../callstack/repack/ChunkManagerModule.kt | 28 ++++++ 5 files changed, 169 insertions(+), 108 deletions(-) delete mode 100644 packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModule.kt create mode 100644 packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModuleImpl.kt create mode 100644 packages/repack/android/src/newarch/java/com/callstack/repack/ChunkManagerModule.kt create mode 100644 packages/repack/android/src/oldarch/java/com/callstack/repack/ChunkManagerModule.kt diff --git a/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModule.kt b/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModule.kt deleted file mode 100644 index 10a27fb70..000000000 --- a/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModule.kt +++ /dev/null @@ -1,96 +0,0 @@ -package com.callstack.repack - -import android.os.Handler -import com.facebook.react.bridge.* - -class ScriptManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { - private val remoteLoader: RemoteScriptLoader = RemoteScriptLoader(reactApplicationContext) - private val fileSystemLoader: FileSystemScriptLoader = FileSystemScriptLoader(reactApplicationContext) - - override fun getName(): String { - return "ScriptManager" - } - - private fun runInBackground(fn: () -> Unit) { - val handler = Handler() - val runnable = Runnable { - fn() - } - handler.postDelayed(runnable, 0) - - } - - @ReactMethod - fun loadScript(scriptId: String, configMap: ReadableMap, promise: Promise) { - runInBackground { - val config = ScriptConfig.fromReadableMap(scriptId, configMap) - - // Currently, `loadScript` supports either `RemoteScriptLoader` or `FileSystemScriptLoader` - // but not both at the same time - it will likely change in the future. - when { - config.url.protocol.startsWith("http") -> { - if (config.fetch) { - remoteLoader.load(config, promise) - } else { - remoteLoader.execute(config, promise) - } - } - config.url.protocol == "file" -> { - fileSystemLoader.load(config, promise) - } - else -> { - promise.reject( - ScriptLoadingError.UnsupportedScheme.code, - "Scheme in URL: '${config.url}' is not supported" - ) - } - } - } -} - -@ReactMethod -fun prefetchScript(scriptId: String, configMap: ReadableMap, promise: Promise) { - val config = ScriptConfig.fromReadableMap(scriptId, configMap) - if (!config.fetch) { - // Do nothing, script is already prefetched - promise.resolve(null); - } else { - runInBackground { - when { - config.url.protocol.startsWith("http") -> { - remoteLoader.prefetch(config, promise) - } - else -> { - promise.reject( - ScriptLoadingError.UnsupportedScheme.code, - "Scheme in URL: '${config.url}' is not supported" - ) - } - } - } - } -} - -@ReactMethod -fun invalidateScripts(scriptIds: ReadableArray, promise: Promise) { - runInBackground { - if (scriptIds.size() == 0) { - remoteLoader.invalidateAll() - promise.resolve(null) - } else { - try { - for (i in 0 until scriptIds.size()) { - val scriptId = scriptIds.getString(i) - remoteLoader.invalidate(scriptId) - } - promise.resolve(null) - } catch (error: Exception) { - promise.reject( - ScriptLoadingError.ScriptInvalidationFailure.code, - "Cannot invalidate some of the scripts" - ) - } - } - } -} -} diff --git a/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModuleImpl.kt b/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModuleImpl.kt new file mode 100644 index 000000000..1e0b18b25 --- /dev/null +++ b/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModuleImpl.kt @@ -0,0 +1,91 @@ +package com.callstack.repack + +import android.os.Handler +import com.facebook.react.bridge.* + +class ScriptManagerModuleImpl { + companion object { + const val NAME = "ScriptManager" + } + + private fun runInBackground(fn: () -> Unit) { + val handler = Handler() + val runnable = Runnable { + fn() + } + handler.postDelayed(runnable, 0) + + } + + fun loadScript(scriptId: String, configMap: ReadableMap, promise: Promise, remoteLoader: RemoteScriptLoader, fileSystemLoader: FileSystemScriptLoader) { + runInBackground { + val config = ScriptConfig.fromReadableMap(scriptId, configMap) + + // Currently, `loadScript` supports either `RemoteScriptLoader` or `FileSystemScriptLoader` + // but not both at the same time - it will likely change in the future. + when { + config.url.protocol.startsWith("http") -> { + if (config.fetch) { + remoteLoader.load(config, promise) + } else { + remoteLoader.execute(config, promise) + } + } + config.url.protocol == "file" -> { + fileSystemLoader.load(config, promise) + } + else -> { + promise.reject( + ScriptLoadingError.UnsupportedScheme.code, + "Scheme in URL: '${config.url}' is not supported" + ) + } + } + } + } + + + fun prefetchScript(scriptId: String, configMap: ReadableMap, promise: Promise, remoteLoader: RemoteScriptLoader) { + val config = ScriptConfig.fromReadableMap(scriptId, configMap) + if (!config.fetch) { + // Do nothing, script is already prefetched + promise.resolve(null); + } else { + runInBackground { + when { + config.url.protocol.startsWith("http") -> { + remoteLoader.prefetch(config, promise) + } + else -> { + promise.reject( + ScriptLoadingError.UnsupportedScheme.code, + "Scheme in URL: '${config.url}' is not supported" + ) + } + } + } + } + } + + fun invalidateScripts(scriptIds: ReadableArray, promise: Promise, remoteLoader: RemoteScriptLoader) { + runInBackground { + if (scriptIds.size() == 0) { + remoteLoader.invalidateAll() + promise.resolve(null) + } else { + try { + for (i in 0 until scriptIds.size()) { + val scriptId = scriptIds.getString(i) + remoteLoader.invalidate(scriptId) + } + promise.resolve(null) + } catch (error: Exception) { + promise.reject( + ScriptLoadingError.ScriptInvalidationFailure.code, + "Cannot invalidate some of the scripts" + ) + } + } + } + } +} diff --git a/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerPackage.kt b/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerPackage.kt index 529a92695..2c3a6e7e5 100644 --- a/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerPackage.kt +++ b/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerPackage.kt @@ -1,17 +1,30 @@ package com.callstack.repack -import com.facebook.react.ReactPackage -import com.facebook.react.bridge.NativeModule -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.uimanager.ViewManager +import com.facebook.react.bridge.* +import com.facebook.react.TurboReactPackage +import com.facebook.react.module.model.ReactModuleInfo +import com.facebook.react.module.model.ReactModuleInfoProvider +class ScriptManagerPackage : TurboReactPackage() { + override fun getModule(name: String?, reactContext: ReactApplicationContext): NativeModule? = + if (name == ScriptManagerModuleImpl.NAME) { + ScriptManagerModule(reactContext) + } else { + null + } -class ScriptManagerPackage : ReactPackage { - override fun createNativeModules(reactContext: ReactApplicationContext): List { - return listOf(ScriptManagerModule(reactContext)) - } - - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return emptyList() - } + override fun getReactModuleInfoProvider() = ReactModuleInfoProvider { + val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED + mapOf( + ScriptManagerModuleImpl.NAME to ReactModuleInfo( + ScriptManagerModuleImpl.NAME, // name + ScriptManagerModuleImpl.NAME, // className + false, // canOverrideExistingModule + false, // needsEagerInit + true, // hasConstants + false, // isCxxModule + isTurboModule // isTurboModule + ) + ) + } } diff --git a/packages/repack/android/src/newarch/java/com/callstack/repack/ChunkManagerModule.kt b/packages/repack/android/src/newarch/java/com/callstack/repack/ChunkManagerModule.kt new file mode 100644 index 000000000..c9899677b --- /dev/null +++ b/packages/repack/android/src/newarch/java/com/callstack/repack/ChunkManagerModule.kt @@ -0,0 +1,25 @@ +package com.callstack.repack + +import android.os.Handler +import com.facebook.react.bridge.* + +class ScriptManagerModule(reactContext: ReactApplicationContext) : NativeScriptManagerSpec(reactContext) { + private val remoteLoader: RemoteScriptLoader = RemoteScriptLoader(reactApplicationContext) + private val fileSystemLoader: FileSystemScriptLoader = FileSystemScriptLoader(reactApplicationContext) + + private var implementation: ScriptManagerModuleImpl = ScriptManagerModuleImpl() + + override fun getName(): String = ScriptManagerModuleImpl.NAME + + override fun loadScript(scriptId: String, configMap: ReadableMap, promise: Promise) { + implementation.loadScript(scriptId, configMap, promise, remoteLoader, fileSystemLoader) + } + + override fun prefetchScript(scriptId: String, configMap: ReadableMap, promise: Promise) { + implementation.prefetchScript(scriptId, configMap, promise, remoteLoader) + } + + override fun invalidateScripts(scriptIds: ReadableArray, promise: Promise) { + implementation.invalidateScripts(scriptIds, promise, remoteLoader) + } +} diff --git a/packages/repack/android/src/oldarch/java/com/callstack/repack/ChunkManagerModule.kt b/packages/repack/android/src/oldarch/java/com/callstack/repack/ChunkManagerModule.kt new file mode 100644 index 000000000..5baa4da24 --- /dev/null +++ b/packages/repack/android/src/oldarch/java/com/callstack/repack/ChunkManagerModule.kt @@ -0,0 +1,28 @@ +package com.callstack.repack + +import android.os.Handler +import com.facebook.react.bridge.* + +class ScriptManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { + private val remoteLoader: RemoteScriptLoader = RemoteScriptLoader(reactApplicationContext) + private val fileSystemLoader: FileSystemScriptLoader = FileSystemScriptLoader(reactApplicationContext) + + private var implementation: ScriptManagerModuleImpl = ScriptManagerModuleImpl() + + override fun getName(): String = ScriptManagerModuleImpl.NAME + + @ReactMethod + fun loadScript(scriptId: String, configMap: ReadableMap, promise: Promise) { + implementation.loadScript(scriptId, configMap, promise, remoteLoader, fileSystemLoader) + } + + @ReactMethod + fun prefetchScript(scriptId: String, configMap: ReadableMap, promise: Promise) { + implementation.prefetchScript(scriptId, configMap, promise, remoteLoader) + } + + @ReactMethod + fun invalidateScripts(scriptIds: ReadableArray, promise: Promise) { + implementation.invalidateScripts(scriptIds, promise, remoteLoader) + } +} From f27ae60fcee6f2e81ee2f47807c2a9307356ea9b Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Mon, 17 Apr 2023 08:25:54 +0100 Subject: [PATCH 07/18] chore: fix lint --- packages/repack/src/modules/ScriptManager/ScriptManager.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/repack/src/modules/ScriptManager/ScriptManager.ts b/packages/repack/src/modules/ScriptManager/ScriptManager.ts index 232088ff0..773e6912f 100644 --- a/packages/repack/src/modules/ScriptManager/ScriptManager.ts +++ b/packages/repack/src/modules/ScriptManager/ScriptManager.ts @@ -1,6 +1,6 @@ /* globals __DEV__, __webpack_require__ */ import EventEmitter from 'events'; -import NativeScriptManager from '../../../js' +import NativeScriptManager from '../../../js'; import { getWebpackContext } from './getWebpackContext'; import { Script } from './Script'; import type { @@ -100,9 +100,7 @@ export class ScriptManager extends EventEmitter { * * @internal */ - protected constructor( - private nativeScriptManager = NativeScriptManager - ) { + protected constructor( private nativeScriptManager = NativeScriptManager) { super(); if (!nativeScriptManager) { From 742f9fb8ed79bcf8682f4ce796806a321155b1ea Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Mon, 17 Apr 2023 08:31:05 +0100 Subject: [PATCH 08/18] chore: fix lint - delete whitespace --- packages/repack/src/modules/ScriptManager/ScriptManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/repack/src/modules/ScriptManager/ScriptManager.ts b/packages/repack/src/modules/ScriptManager/ScriptManager.ts index 773e6912f..6b360fcec 100644 --- a/packages/repack/src/modules/ScriptManager/ScriptManager.ts +++ b/packages/repack/src/modules/ScriptManager/ScriptManager.ts @@ -100,7 +100,7 @@ export class ScriptManager extends EventEmitter { * * @internal */ - protected constructor( private nativeScriptManager = NativeScriptManager) { + protected constructor(private nativeScriptManager = NativeScriptManager) { super(); if (!nativeScriptManager) { From 1e18f7dd31db0529d1e7f617f99425daea726900 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Thu, 20 Apr 2023 02:03:00 +0100 Subject: [PATCH 09/18] chore: mock test using NativeScriptManagerSpec --- .../ScriptManager/__tests__/ScriptManager.test.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/repack/src/modules/ScriptManager/__tests__/ScriptManager.test.ts b/packages/repack/src/modules/ScriptManager/__tests__/ScriptManager.test.ts index 83a16e6ad..4db79f4dd 100644 --- a/packages/repack/src/modules/ScriptManager/__tests__/ScriptManager.test.ts +++ b/packages/repack/src/modules/ScriptManager/__tests__/ScriptManager.test.ts @@ -1,9 +1,10 @@ /* globals globalThis */ -import * as ReactNative from 'react-native'; import { Script } from '../Script'; import { ScriptManager } from '../ScriptManager'; -jest.mock('react-native', () => ({ NativeModules: { ScriptManager: {} } })); +jest.mock('../../../../js', () => ({ + TurboModuleRegistry: { get: (module: {}) => module }, +})); // @ts-ignore globalThis.__webpack_require__ = { @@ -29,8 +30,6 @@ class FakeCache { } beforeEach(() => { - ReactNative.NativeModules.ScriptManager = {}; - try { ScriptManager.shared.__destroy(); } catch { @@ -39,10 +38,8 @@ beforeEach(() => { }); describe('ScriptManagerAPI', () => { - it('throw error if ScriptManager NativeModule was not found', async () => { - ReactNative.NativeModules.ScriptManager = undefined; - - await expect(() => ScriptManager.shared).toThrow(/module was not found/); + it('should find ScriptManager TurboModules', async () => { + await expect(() => ScriptManager.shared).toBeTruthy(); }); it('throw error if there are no resolvers', async () => { From 391900f1dfb529a532a8e8238014df3e36f15873 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Thu, 20 Apr 2023 03:16:35 +0100 Subject: [PATCH 10/18] chore: new arch guide --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 77439ef23..9c88905d1 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,28 @@ Available at: [Projects](https://github.com/callstack/repack/projects?type=class - [ ] Code signing and verification - [ ] `webpack-init` command +### New Architecture Support (Turbo Module) +---- +This library supports new architecture!. [turbo module](https://reactnative.dev/docs/next/the-new-architecture/pillars-turbomodules) offers a new architecture for initializing native modules. + +If you are using this library in your own project or [running the example](https://github.com/callstack/repack/blob/main/CONTRIBUTING.md#running-the-example), there are some extra steps needed. + +### iOS +Install pods with this flag inside `ios` folder: +```sh +RCT_NEW_ARCH_ENABLED=1 bundle exec pod install +``` +and then run: + +```sh +yarn ios +``` + +### Android +Set `newArchEnabled` to `true` inside `android/gradle.properties` and then run: +```sh +yarn android +``` ### Examples From 5f345dcfb027aad6d1aeeca25f266985743670a2 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Fri, 21 Apr 2023 12:56:03 +0100 Subject: [PATCH 11/18] chore: review fixes --- README.md | 2 +- packages/repack/ios/ScriptManager.mm | 1 - packages/repack/js/NativeScriptManager.ts | 4 +--- packages/repack/tsconfig.json | 2 +- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9c88905d1..2a8cce4fc 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Available at: [Projects](https://github.com/callstack/repack/projects?type=class - [ ] Code signing and verification - [ ] `webpack-init` command -### New Architecture Support (Turbo Module) +### New Architecture Support ---- This library supports new architecture!. [turbo module](https://reactnative.dev/docs/next/the-new-architecture/pillars-turbomodules) offers a new architecture for initializing native modules. diff --git a/packages/repack/ios/ScriptManager.mm b/packages/repack/ios/ScriptManager.mm index ce5e03e16..9dca96ac8 100644 --- a/packages/repack/ios/ScriptManager.mm +++ b/packages/repack/ios/ScriptManager.mm @@ -262,7 +262,6 @@ - (void)runInBackground:(void(^)())callback dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), callback); } -// We won't compile this code when we build for the old architecture. #ifdef RCT_NEW_ARCH_ENABLED - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params diff --git a/packages/repack/js/NativeScriptManager.ts b/packages/repack/js/NativeScriptManager.ts index 9564536e1..bab1e940f 100644 --- a/packages/repack/js/NativeScriptManager.ts +++ b/packages/repack/js/NativeScriptManager.ts @@ -2,11 +2,9 @@ import type {TurboModule} from 'react-native'; import {TurboModuleRegistry} from 'react-native'; export interface Spec extends TurboModule { - readonly getConstants: () => {}; - loadScript(scriptId: string, config: Object): Promise; prefetchScript(scriptId: string, config: Object): Promise; - invalidateScripts(scripts: Array): Promise; + invalidateScripts(scripts: Array): void; } export default TurboModuleRegistry.get('ScriptManager') as Spec; \ No newline at end of file diff --git a/packages/repack/tsconfig.json b/packages/repack/tsconfig.json index 1fa115a4a..75ce89d73 100644 --- a/packages/repack/tsconfig.json +++ b/packages/repack/tsconfig.json @@ -69,6 +69,6 @@ "skipLibCheck": true, /* Skip type checking of declaration files. */ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ }, - "include": ["src/**/*", "js/NativeScriptManager.ts"], + "include": ["src/**/*", "js/*.ts"], "exclude": ["**/__tests__/**"] } \ No newline at end of file From 6c382d42f8bd28a142eedec0644ef619161fa12f Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Mon, 24 Apr 2023 13:10:55 +0100 Subject: [PATCH 12/18] chore: fix code style - update shared implementation to use object --- README.md | 2 +- .../repack/ChunkManagerModuleImpl.kt | 9 ++--- .../callstack/repack/ChunkManagerPackage.kt | 40 +++++++++---------- .../callstack/repack/ChunkManagerModule.kt | 8 ++-- .../callstack/repack/ChunkManagerModule.kt | 8 ++-- packages/repack/js/NativeScriptManager.ts | 2 +- 6 files changed, 32 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 2a8cce4fc..8b344ff56 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Available at: [Projects](https://github.com/callstack/repack/projects?type=class ### New Architecture Support ---- -This library supports new architecture!. [turbo module](https://reactnative.dev/docs/next/the-new-architecture/pillars-turbomodules) offers a new architecture for initializing native modules. +This library supports new architecture! Using [turbo modules](https://reactnative.dev/docs/next/the-new-architecture/pillars-turbomodules) offers a new way of initializing native modules. If you are using this library in your own project or [running the example](https://github.com/callstack/repack/blob/main/CONTRIBUTING.md#running-the-example), there are some extra steps needed. diff --git a/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModuleImpl.kt b/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModuleImpl.kt index 1e0b18b25..1adec0f00 100644 --- a/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModuleImpl.kt +++ b/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerModuleImpl.kt @@ -3,10 +3,9 @@ package com.callstack.repack import android.os.Handler import com.facebook.react.bridge.* -class ScriptManagerModuleImpl { - companion object { - const val NAME = "ScriptManager" - } +object ScriptManagerModuleImpl { + + const val NAME = "ScriptManager" private fun runInBackground(fn: () -> Unit) { val handler = Handler() @@ -49,7 +48,7 @@ class ScriptManagerModuleImpl { val config = ScriptConfig.fromReadableMap(scriptId, configMap) if (!config.fetch) { // Do nothing, script is already prefetched - promise.resolve(null); + promise.resolve(null) } else { runInBackground { when { diff --git a/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerPackage.kt b/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerPackage.kt index 2c3a6e7e5..b8ee61e7d 100644 --- a/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerPackage.kt +++ b/packages/repack/android/src/main/java/com/callstack/repack/ChunkManagerPackage.kt @@ -6,25 +6,25 @@ import com.facebook.react.module.model.ReactModuleInfo import com.facebook.react.module.model.ReactModuleInfoProvider class ScriptManagerPackage : TurboReactPackage() { - override fun getModule(name: String?, reactContext: ReactApplicationContext): NativeModule? = - if (name == ScriptManagerModuleImpl.NAME) { - ScriptManagerModule(reactContext) - } else { - null - } + override fun getModule(name: String?, reactContext: ReactApplicationContext): NativeModule? = + if (name == ScriptManagerModuleImpl.NAME) { + ScriptManagerModule(reactContext) + } else { + null + } - override fun getReactModuleInfoProvider() = ReactModuleInfoProvider { - val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED - mapOf( - ScriptManagerModuleImpl.NAME to ReactModuleInfo( - ScriptManagerModuleImpl.NAME, // name - ScriptManagerModuleImpl.NAME, // className - false, // canOverrideExistingModule - false, // needsEagerInit - true, // hasConstants - false, // isCxxModule - isTurboModule // isTurboModule - ) - ) - } + override fun getReactModuleInfoProvider() = ReactModuleInfoProvider { + val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED + mapOf( + ScriptManagerModuleImpl.NAME to ReactModuleInfo( + ScriptManagerModuleImpl.NAME, // name + ScriptManagerModuleImpl.NAME, // className + false, // canOverrideExistingModule + false, // needsEagerInit + true, // hasConstants + false, // isCxxModule + isTurboModule // isTurboModule + ) + ) + } } diff --git a/packages/repack/android/src/newarch/java/com/callstack/repack/ChunkManagerModule.kt b/packages/repack/android/src/newarch/java/com/callstack/repack/ChunkManagerModule.kt index c9899677b..1505f1fb1 100644 --- a/packages/repack/android/src/newarch/java/com/callstack/repack/ChunkManagerModule.kt +++ b/packages/repack/android/src/newarch/java/com/callstack/repack/ChunkManagerModule.kt @@ -7,19 +7,17 @@ class ScriptManagerModule(reactContext: ReactApplicationContext) : NativeScriptM private val remoteLoader: RemoteScriptLoader = RemoteScriptLoader(reactApplicationContext) private val fileSystemLoader: FileSystemScriptLoader = FileSystemScriptLoader(reactApplicationContext) - private var implementation: ScriptManagerModuleImpl = ScriptManagerModuleImpl() - override fun getName(): String = ScriptManagerModuleImpl.NAME override fun loadScript(scriptId: String, configMap: ReadableMap, promise: Promise) { - implementation.loadScript(scriptId, configMap, promise, remoteLoader, fileSystemLoader) + ScriptManagerModuleImpl.loadScript(scriptId, configMap, promise, remoteLoader, fileSystemLoader) } override fun prefetchScript(scriptId: String, configMap: ReadableMap, promise: Promise) { - implementation.prefetchScript(scriptId, configMap, promise, remoteLoader) + ScriptManagerModuleImpl.prefetchScript(scriptId, configMap, promise, remoteLoader) } override fun invalidateScripts(scriptIds: ReadableArray, promise: Promise) { - implementation.invalidateScripts(scriptIds, promise, remoteLoader) + ScriptManagerModuleImpl.invalidateScripts(scriptIds, promise, remoteLoader) } } diff --git a/packages/repack/android/src/oldarch/java/com/callstack/repack/ChunkManagerModule.kt b/packages/repack/android/src/oldarch/java/com/callstack/repack/ChunkManagerModule.kt index 5baa4da24..59ffdd916 100644 --- a/packages/repack/android/src/oldarch/java/com/callstack/repack/ChunkManagerModule.kt +++ b/packages/repack/android/src/oldarch/java/com/callstack/repack/ChunkManagerModule.kt @@ -7,22 +7,20 @@ class ScriptManagerModule(reactContext: ReactApplicationContext) : ReactContextB private val remoteLoader: RemoteScriptLoader = RemoteScriptLoader(reactApplicationContext) private val fileSystemLoader: FileSystemScriptLoader = FileSystemScriptLoader(reactApplicationContext) - private var implementation: ScriptManagerModuleImpl = ScriptManagerModuleImpl() - override fun getName(): String = ScriptManagerModuleImpl.NAME @ReactMethod fun loadScript(scriptId: String, configMap: ReadableMap, promise: Promise) { - implementation.loadScript(scriptId, configMap, promise, remoteLoader, fileSystemLoader) + ScriptManagerModuleImpl.loadScript(scriptId, configMap, promise, remoteLoader, fileSystemLoader) } @ReactMethod fun prefetchScript(scriptId: String, configMap: ReadableMap, promise: Promise) { - implementation.prefetchScript(scriptId, configMap, promise, remoteLoader) + ScriptManagerModuleImpl.prefetchScript(scriptId, configMap, promise, remoteLoader) } @ReactMethod fun invalidateScripts(scriptIds: ReadableArray, promise: Promise) { - implementation.invalidateScripts(scriptIds, promise, remoteLoader) + ScriptManagerModuleImpl.invalidateScripts(scriptIds, promise, remoteLoader) } } diff --git a/packages/repack/js/NativeScriptManager.ts b/packages/repack/js/NativeScriptManager.ts index bab1e940f..30ca919a4 100644 --- a/packages/repack/js/NativeScriptManager.ts +++ b/packages/repack/js/NativeScriptManager.ts @@ -4,7 +4,7 @@ import {TurboModuleRegistry} from 'react-native'; export interface Spec extends TurboModule { loadScript(scriptId: string, config: Object): Promise; prefetchScript(scriptId: string, config: Object): Promise; - invalidateScripts(scripts: Array): void; + invalidateScripts(scripts: Array): Promise; } export default TurboModuleRegistry.get('ScriptManager') as Spec; \ No newline at end of file From 4d26acc7fdaa7f491406f9d2ed7f3209e1215a9a Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Tue, 25 Apr 2023 10:01:14 +0100 Subject: [PATCH 13/18] chore: remove js included path on repack tsconfig --- packages/repack/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/repack/tsconfig.json b/packages/repack/tsconfig.json index 75ce89d73..545004f0b 100644 --- a/packages/repack/tsconfig.json +++ b/packages/repack/tsconfig.json @@ -69,6 +69,6 @@ "skipLibCheck": true, /* Skip type checking of declaration files. */ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ }, - "include": ["src/**/*", "js/*.ts"], + "include": ["src/**/*"], "exclude": ["**/__tests__/**"] } \ No newline at end of file From 4a09696271656b88b773ed4cd0564dd4beee6d02 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Tue, 25 Apr 2023 11:38:42 +0100 Subject: [PATCH 14/18] chore: add proper types to NativeScriptManager.ts --- packages/repack/js/NativeScriptManager.ts | 41 +++++++++++++++++++++-- packages/repack/package.json | 2 +- yarn.lock | 23 +++++++++---- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/packages/repack/js/NativeScriptManager.ts b/packages/repack/js/NativeScriptManager.ts index 30ca919a4..7cee05bb0 100644 --- a/packages/repack/js/NativeScriptManager.ts +++ b/packages/repack/js/NativeScriptManager.ts @@ -1,9 +1,46 @@ import type {TurboModule} from 'react-native'; import {TurboModuleRegistry} from 'react-native'; +import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes'; + +type WebpackContext = { + p: () => string; + u: (id: string) => string; +} + +type NormalizedScriptLocator = { + method: string; + url: string; + fetch: boolean; + timeout: Int32; + absolute: boolean; + query?: string; + headers?: string; + body?: string; + token?: string; + verifyScriptSignature?: boolean; +} + +type ScriptLocator = { + url: string | ((webpackContext: WebpackContext) => string); + query?: string; + headers?: string; + method?: string; + body?: string | null; + timeout?: Int32; + absolute?: boolean; + cache?: boolean; + token?: string; + verifyScriptSignature?: boolean; + shouldUpdateScript?: ( + scriptId?: string, + caller?:string, + isScriptCacheOutdated?: boolean, + ) => Promise | boolean; +} export interface Spec extends TurboModule { - loadScript(scriptId: string, config: Object): Promise; - prefetchScript(scriptId: string, config: Object): Promise; + loadScript(scriptId: string, config: NormalizedScriptLocator): Promise; + prefetchScript(scriptId: string, config: NormalizedScriptLocator): Promise; invalidateScripts(scripts: Array): Promise; } diff --git a/packages/repack/package.json b/packages/repack/package.json index d0f619d1f..17d7a27a2 100644 --- a/packages/repack/package.json +++ b/packages/repack/package.json @@ -98,7 +98,7 @@ "@types/mime-types": "^2.1.1", "@types/node": "^14.14.28", "@types/react-dom": "^17.0.7", - "@types/react-native": "^0.67.8", + "@types/react-native": "^0.67.20", "@types/shallowequal": "^1.1.1", "babel-jest": "^28.1.1", "babel-loader": "^8.2.2", diff --git a/yarn.lock b/yarn.lock index 6d44f6303..ce31238be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4797,7 +4797,7 @@ __metadata: "@types/mime-types": ^2.1.1 "@types/node": ^14.14.28 "@types/react-dom": ^17.0.7 - "@types/react-native": ^0.67.8 + "@types/react-native": ^0.67.20 "@types/shallowequal": ^1.1.1 babel-jest: ^28.1.1 babel-loader: ^8.2.2 @@ -8909,12 +8909,12 @@ __metadata: languageName: node linkType: hard -"@types/react-native@npm:^0.67.8": - version: 0.67.8 - resolution: "@types/react-native@npm:0.67.8" +"@types/react-native@npm:^0.67.20": + version: 0.67.20 + resolution: "@types/react-native@npm:0.67.20" dependencies: - "@types/react": "*" - checksum: f031ecde8730b06928ebb73e3172de86f53ea7c5f69222bf0985a9a157727302f4df639493bc595dcc0dd74796a53aef394f7b4503879832ea5094aff2033bc3 + "@types/react": ^17 + checksum: cd97888c0a64829db6fc7f5e1a15bd65ffd8ec401d4ed639021a178ca93043dc914d4d6a11242b8bcd7fedd532f59d301bc353f0aa15f7db394d7c3dad272b68 languageName: node linkType: hard @@ -8972,6 +8972,17 @@ __metadata: languageName: node linkType: hard +"@types/react@npm:^17": + version: 17.0.58 + resolution: "@types/react@npm:17.0.58" + dependencies: + "@types/prop-types": "*" + "@types/scheduler": "*" + csstype: ^3.0.2 + checksum: 4eaf32b86c43f388c681e34a00921c508dd88a1d1022aebfadc5fe802b7c5bed863de1a17eed31e43ca2d65222952dfe79a022055a0e6e4e1ad89fc5a42ec05e + languageName: node + linkType: hard + "@types/react@npm:^17.0.24": version: 17.0.24 resolution: "@types/react@npm:17.0.24" From ba282bf0665f5014fd42b266b908cb28342358f1 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Tue, 25 Apr 2023 12:01:43 +0100 Subject: [PATCH 15/18] chore: update yarn.lock --- yarn.lock | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/yarn.lock b/yarn.lock index ce31238be..27629ddd1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8913,7 +8913,7 @@ __metadata: version: 0.67.20 resolution: "@types/react-native@npm:0.67.20" dependencies: - "@types/react": ^17 + "@types/react": "*" checksum: cd97888c0a64829db6fc7f5e1a15bd65ffd8ec401d4ed639021a178ca93043dc914d4d6a11242b8bcd7fedd532f59d301bc353f0aa15f7db394d7c3dad272b68 languageName: node linkType: hard @@ -8972,17 +8972,6 @@ __metadata: languageName: node linkType: hard -"@types/react@npm:^17": - version: 17.0.58 - resolution: "@types/react@npm:17.0.58" - dependencies: - "@types/prop-types": "*" - "@types/scheduler": "*" - csstype: ^3.0.2 - checksum: 4eaf32b86c43f388c681e34a00921c508dd88a1d1022aebfadc5fe802b7c5bed863de1a17eed31e43ca2d65222952dfe79a022055a0e6e4e1ad89fc5a42ec05e - languageName: node - linkType: hard - "@types/react@npm:^17.0.24": version: 17.0.24 resolution: "@types/react@npm:17.0.24" From f36769a5ab5f011df1489536a63e1a9e3bb978c5 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Fri, 19 May 2023 08:47:03 +0100 Subject: [PATCH 16/18] update ScriptLocator types for Spec --- packages/repack/js/NativeScriptManager.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/repack/js/NativeScriptManager.ts b/packages/repack/js/NativeScriptManager.ts index 7cee05bb0..3f9c21260 100644 --- a/packages/repack/js/NativeScriptManager.ts +++ b/packages/repack/js/NativeScriptManager.ts @@ -16,8 +16,7 @@ type NormalizedScriptLocator = { query?: string; headers?: string; body?: string; - token?: string; - verifyScriptSignature?: boolean; + verifyScriptSignature?: string; } type ScriptLocator = { @@ -29,8 +28,7 @@ type ScriptLocator = { timeout?: Int32; absolute?: boolean; cache?: boolean; - token?: string; - verifyScriptSignature?: boolean; + verifyScriptSignature?: string; shouldUpdateScript?: ( scriptId?: string, caller?:string, From ae164e4aea59a7a0b157b10ce1a18f6e4eda8390 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Fri, 19 May 2023 08:48:34 +0100 Subject: [PATCH 17/18] revert to using Object as config types --- packages/repack/js/NativeScriptManager.ts | 39 ++--------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/packages/repack/js/NativeScriptManager.ts b/packages/repack/js/NativeScriptManager.ts index 3f9c21260..30ca919a4 100644 --- a/packages/repack/js/NativeScriptManager.ts +++ b/packages/repack/js/NativeScriptManager.ts @@ -1,44 +1,9 @@ import type {TurboModule} from 'react-native'; import {TurboModuleRegistry} from 'react-native'; -import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes'; - -type WebpackContext = { - p: () => string; - u: (id: string) => string; -} - -type NormalizedScriptLocator = { - method: string; - url: string; - fetch: boolean; - timeout: Int32; - absolute: boolean; - query?: string; - headers?: string; - body?: string; - verifyScriptSignature?: string; -} - -type ScriptLocator = { - url: string | ((webpackContext: WebpackContext) => string); - query?: string; - headers?: string; - method?: string; - body?: string | null; - timeout?: Int32; - absolute?: boolean; - cache?: boolean; - verifyScriptSignature?: string; - shouldUpdateScript?: ( - scriptId?: string, - caller?:string, - isScriptCacheOutdated?: boolean, - ) => Promise | boolean; -} export interface Spec extends TurboModule { - loadScript(scriptId: string, config: NormalizedScriptLocator): Promise; - prefetchScript(scriptId: string, config: NormalizedScriptLocator): Promise; + loadScript(scriptId: string, config: Object): Promise; + prefetchScript(scriptId: string, config: Object): Promise; invalidateScripts(scripts: Array): Promise; } From a58595605ec753f1ec66b4dddf5b7383393ce1d1 Mon Sep 17 00:00:00 2001 From: Eto Olei Date: Wed, 16 Aug 2023 15:04:43 +0100 Subject: [PATCH 18/18] remove irrelevant readme section --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index e96b667cb..b7feebbb8 100644 --- a/README.md +++ b/README.md @@ -56,14 +56,6 @@ Re.Pack uses Webpack 5 and React Native CLI's plugin system to allow you to bund - [x] Code signing and verification - [x] `@callstack/repack-init` - tool that automates the integration of the Re.Pack into React-Native projects -### Planned features - -Available at: [Projects](https://github.com/callstack/repack/projects?type=classic) - -- [ ] `ChunksToHermesBytecodePlugin` plugin to automatically transform async chunks to bytecode format. -- [ ] Code signing and verification -- [ ] `webpack-init` command - ### New Architecture Support (Turbo Module) ---- This library supports new architecture!. [turbo module](https://reactnative.dev/docs/next/the-new-architecture/pillars-turbomodules) offers a new architecture for initializing native modules.