Skip to content

Commit

Permalink
Consolidate bundle URL creation
Browse files Browse the repository at this point in the history
Summary:
`DevServerHelper` had multiple places that created bundle URLs.
This consolidates that logic into a single place, and uses an enum for different "bundle types" (bundle, bundle deltas, source maps).

Reviewed By: pakoito

Differential Revision: D6900906

fbshipit-source-id: 64ed9360ea85dc5755308d822d5fc55fe8cb5a55
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Feb 6, 2018
1 parent 1ea3065 commit 644123a
Showing 1 changed file with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ public interface SymbolicationListener {
void onSymbolicationComplete(@Nullable Iterable<StackFrame> stackFrames);
}

private enum BundleType {
BUNDLE("bundle"),
DELTA("delta"),
MAP("map");

private final String mTypeID;

BundleType(String typeID) {
mTypeID = typeID;
}

public String typeID() {
return mTypeID;
}
}

private final DevInternalSettings mSettings;
private final OkHttpClient mClient;
private final Handler mRestartOnChangePollingHandler;
Expand Down Expand Up @@ -427,16 +443,20 @@ private boolean getJSMinifyMode() {
return mSettings.isJSMinifyEnabled();
}

private static String createBundleURL(
String host, String jsModulePath, boolean devMode, boolean jsMinify, boolean useDeltas) {
private String createBundleURL(String mainModuleID, BundleType type, String host) {
return String.format(
Locale.US,
BUNDLE_URL_FORMAT,
host,
jsModulePath,
useDeltas ? "delta" : "bundle",
devMode,
jsMinify);
mainModuleID,
type.typeID(),
getDevMode(),
getJSMinifyMode());
}

private String createBundleURL(String mainModuleID, BundleType type) {
return createBundleURL(
mainModuleID, type, mSettings.getPackagerConnectionSettings().getDebugServerHost());
}

private static String createResourceURL(String host, String resourcePath) {
Expand All @@ -453,11 +473,10 @@ private static String createOpenStackFrameURL(String host) {

public String getDevServerBundleURL(final String jsModulePath) {
return createBundleURL(
mSettings.getPackagerConnectionSettings().getDebugServerHost(),
jsModulePath,
getDevMode(),
getJSMinifyMode(),
mSettings.isBundleDeltasEnabled());
jsModulePath,
mSettings.isBundleDeltasEnabled() ? BundleType.DELTA : BundleType.BUNDLE,
mSettings.getPackagerConnectionSettings().getDebugServerHost()
);
}

public void isPackagerRunning(final PackagerStatusCallback callback) {
Expand Down Expand Up @@ -614,33 +633,20 @@ public void onResponse(Call call, Response response) throws IOException {
}

public String getSourceMapUrl(String mainModuleName) {
return String.format(
Locale.US,
BUNDLE_URL_FORMAT,
mSettings.getPackagerConnectionSettings().getDebugServerHost(),
mainModuleName,
"map",
getDevMode(),
getJSMinifyMode());
return createBundleURL(mainModuleName, BundleType.MAP);
}

public String getSourceUrl(String mainModuleName) {
return String.format(
Locale.US,
BUNDLE_URL_FORMAT,
mSettings.getPackagerConnectionSettings().getDebugServerHost(),
mainModuleName,
mSettings.isBundleDeltasEnabled() ? "delta" : "bundle",
getDevMode(),
getJSMinifyMode());
return createBundleURL(
mainModuleName, mSettings.isBundleDeltasEnabled() ? BundleType.DELTA : BundleType.BUNDLE);
}

public String getJSBundleURLForRemoteDebugging(String mainModuleName) {
// The host we use when connecting to the JS bundle server from the emulator is not the
// same as the one needed to connect to the same server from the JavaScript proxy running on the
// host itself.
return createBundleURL(
getHostForJSProxy(), mainModuleName, getDevMode(), getJSMinifyMode(), false);
mainModuleName, BundleType.BUNDLE, getHostForJSProxy());
}

/**
Expand Down

0 comments on commit 644123a

Please sign in to comment.