Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev-server][dev-launcher] inspector network on ios #21265

Merged
merged 10 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/bare-expo/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require File.join(File.dirname(`node --print "require.resolve('expo/package.json

require 'json'
podfile_properties = JSON.parse(File.read('./Podfile.properties.json')) rescue {}
ENV['EX_DEV_CLIENT_NETWORK_INSPECTOR'] = '1' if podfile_properties['EX_DEV_CLIENT_NETWORK_INSPECTOR'] == true

prepare_react_native_project!

Expand Down
4 changes: 2 additions & 2 deletions apps/bare-expo/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ SPEC CHECKSUMS:
EXPermissions: 2291c6736a823b4c680d5bf8e12d3c1c5d11da35
Expo: 79deb55f33fab1b232232868a74713772943238d
expo-dev-client: fb5994b219d6df2a39d73f45b40a4ad2f29d47c2
expo-dev-launcher: 0eaee0ae43104252e3994f6d7a4810c3aad62fc0
expo-dev-launcher: 535eef9421a2cd0529bcc1f9e67ab7cb58fda3e7
expo-dev-menu: b1f53d0ec3d9f330b53a1c701ea3257aad5ce28a
expo-dev-menu-interface: 6c82ae323c4b8724dead4763ce3ff24a2108bdb1
ExpoAppleAuthentication: 7bd5e4150d59e8df37aa80b425850ae88adf9e65
Expand Down Expand Up @@ -1329,6 +1329,6 @@ SPEC CHECKSUMS:
Yoga: 5ed1699acbba8863755998a4245daa200ff3817b
ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb

PODFILE CHECKSUM: c59f327102c50f126198cfae3dbc05c01a4190e9
PODFILE CHECKSUM: 221d96cc63183a5dfbb774316e11def3300ac02d

COCOAPODS: 1.11.2
3 changes: 2 additions & 1 deletion apps/bare-expo/ios/Podfile.properties.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"expo.jsEngine": "hermes"
"expo.jsEngine": "hermes",
"EX_DEV_CLIENT_NETWORK_INSPECTOR": true
}
4 changes: 2 additions & 2 deletions packages/@expo/dev-server/build/JsInspector.js

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

2 changes: 1 addition & 1 deletion packages/@expo/dev-server/build/JsInspector.js.map

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

4 changes: 2 additions & 2 deletions packages/@expo/dev-server/src/JsInspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export async function openJsInspector(app: MetroInspectorProxyApp) {
// 3. The full commit hash is the desired revision
const devtoolsFrontendRev = 'd9568d04d7dd79269c5a655d7ada69650c5a8336'; // Chrome 100.0.4896.75

const urlBase = `https://chrome-devtools-frontend.appspot.com/serve_rev/@${devtoolsFrontendRev}/inspector.html`;
const urlBase = `https://chrome-devtools-frontend.appspot.com/serve_rev/@${devtoolsFrontendRev}/devtools_app.html`;
const ws = app.webSocketDebuggerUrl.replace(/^ws:\/\//, '');
const url = `${urlBase}?panel=sources&v8only=true&ws=${encodeURIComponent(ws)}`;
const url = `${urlBase}?panel=sources&ws=${encodeURIComponent(ws)}`;
await closeJsInspector();
openingBrowserInstance = await launchBrowserAsync(url);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/expo-dev-launcher/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### 🎉 New features

- Added experimental network inspector. ([#21265](https://github.com/expo/expo/pull/21265) by [@kudo](https://github.com/kudo))

### 🐛 Bug fixes

- Fixed dev client crash when server URL has no scheme. ([#21274](https://github.com/expo/expo/pull/21274) by [@gabrieldonadel](https://github.com/gabrieldonadel))
Expand Down
19 changes: 13 additions & 6 deletions packages/expo-dev-launcher/expo-dev-launcher.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,24 @@ Pod::Spec.new do |s|
'GCC_PREPROCESSOR_DEFINITIONS' => "EX_DEV_LAUNCHER_VERSION=#{s.version}"
}

# Swift/Objective-C compatibility
s.pod_target_xcconfig = { "DEFINES_MODULE" => "YES" }
other_c_flags = '$(inherited)'
dev_launcher_url = ENV['EX_DEV_LAUNCHER_URL'] || ""
if dev_launcher_url != ""
escaped_dev_launcher_url = Shellwords.escape(dev_launcher_url).gsub('/','\\/')
s.pod_target_xcconfig = {
'DEFINES_MODULE' => 'YES',
'OTHER_CFLAGS[config=Debug]' => "$(inherited) -DEX_DEV_LAUNCHER_URL=\"\\\"" + escaped_dev_launcher_url + "\\\"\""
}
other_c_flags += " -DEX_DEV_LAUNCHER_URL=\"\\\"" + escaped_dev_launcher_url + "\\\"\""
end
other_swift_flags = "$(inherited)"
if ENV['EX_DEV_CLIENT_NETWORK_INSPECTOR'] == '1'
other_swift_flags += ' -DEX_DEV_CLIENT_NETWORK_INSPECTOR'
end

# Swift/Objective-C compatibility
s.pod_target_xcconfig = {
'DEFINES_MODULE' => 'YES',
'OTHER_CFLAGS[config=Debug]' => other_c_flags,
'OTHER_SWIFT_FLAGS[config=Debug]' => other_swift_flags,
}

s.user_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"${PODS_CONFIGURATION_BUILD_DIR}/expo-dev-launcher/Swift Compatibility Header\"",
}
Expand Down
1 change: 1 addition & 0 deletions packages/expo-dev-launcher/ios/EXDevLauncherController.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ - (instancetype)init {
self.errorManager = [[EXDevLauncherErrorManager alloc] initWithController:self];
self.installationIDHelper = [EXDevLauncherInstallationIDHelper new];
self.shouldPreferUpdatesInterfaceSourceUrl = NO;
[EXDevLauncherNetworkLogger.shared enable];
}
return self;
}
Expand Down
41 changes: 41 additions & 0 deletions packages/expo-dev-launcher/ios/EXDevLauncherUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,47 @@ class EXDevLauncherUtils {
}
}

/**
Swizzles implementations of given class method selectors.
This function will backup original selector implementation for `invokeOriginalClassMethod`.
*/
static func swizzleClassMethod(selector selectorA: Selector, withSelector selectorB: Selector, forClass: AnyClass) {
if let methodA = class_getClassMethod(forClass, selectorA),
let methodB = class_getClassMethod(forClass, selectorB) {
let impA = method_getImplementation(methodA)
let backupSelectorA = NSSelectorFromString("_" + NSStringFromSelector(selectorA))
let metaClass = objc_getMetaClass(String(describing: forClass)) as? AnyClass
class_addMethod(metaClass, backupSelectorA, impA, method_getTypeEncoding(methodA))
method_setImplementation(methodA, method_getImplementation(methodB))
}
}

/**
Invokes the original implementation before swizzling for the given selector
*/
static func invokeOriginalClassMethod(selector: Selector, forClass: AnyClass) throws -> Any? {
typealias ClassMethod = @convention(c) (AnyObject, Selector) -> Any
let imp = try getOriginalClassMethodImp(selector: selector, forClass: forClass)
return unsafeBitCast(imp, to: ClassMethod.self)(self, selector)
}

/**
Invokes the original implementation before swizzling for the given selector
*/
static func invokeOriginalClassMethod(selector: Selector, forClass: AnyClass, A0: Any) throws -> Any? {
typealias ClassMethod = @convention(c) (AnyObject, Selector, Any) -> Any
let imp = try getOriginalClassMethodImp(selector: selector, forClass: forClass)
return unsafeBitCast(imp, to: ClassMethod.self)(self, selector, A0)
}

private static func getOriginalClassMethodImp(selector: Selector, forClass: AnyClass) throws -> IMP {
let backupSelector = NSSelectorFromString("_" + NSStringFromSelector(selector))
guard let method = class_getClassMethod(forClass, backupSelector) else {
fatalError("Backup selector does not exist - forClass[\(forClass)] backupSelector[\(NSStringFromSelector(backupSelector))]")
}
return method_getImplementation(method)
}

static func resourcesBundle() -> Bundle? {
let frameworkBundle = Bundle(for: EXDevLauncherUtils.self)

Expand Down
Loading