Rename bundleUrl to jsbundleURL

Reviewed By: fkgozali

Differential Revision: D6236921

fbshipit-source-id: f1018836465ba6cf21679fe9d21c18eec762199d
This commit is contained in:
Yujie Liu 2017-11-07 17:43:35 -08:00 committed by Facebook Github Bot
parent b983de9c54
commit b0193b098c
2 changed files with 23 additions and 23 deletions

View File

@ -50,14 +50,14 @@ function getAssetPathInDrawableFolder(asset): string {
class AssetSourceResolver {
serverUrl: ?string;
// where the bundle is being run from
bundleUrl: ?string;
// where the jsbundle is being run from
jsbundleUrl: ?string;
// the asset to resolve
asset: PackagerAsset;
constructor(serverUrl: ?string, bundleUrl: ?string, asset: PackagerAsset) {
constructor(serverUrl: ?string, jsbundleUrl: ?string, asset: PackagerAsset) {
this.serverUrl = serverUrl;
this.bundleUrl = bundleUrl;
this.jsbundleUrl = jsbundleUrl;
this.asset = asset;
}
@ -66,7 +66,7 @@ class AssetSourceResolver {
}
isLoadedFromFileSystem(): boolean {
return !!this.bundleUrl;
return !!this.jsbundleUrl;
}
defaultAsset(): ResolvedAssetSource {
@ -79,7 +79,7 @@ class AssetSourceResolver {
this.drawableFolderInBundle() :
this.resourceIdentifierWithoutScale();
} else {
return this.scaledAssetURLInBundle();
return this.scaledAssetURLInScript();
}
}
@ -104,11 +104,11 @@ class AssetSourceResolver {
}
/**
* Resolves to where the bundle is running from, with a scaled asset filename
* Resolves to where the script is running from, with a scaled asset filename
* E.g. 'file:///sdcard/bundle/assets/AwesomeModule/icon@2x.png'
*/
scaledAssetURLInBundle(): ResolvedAssetSource {
const path = this.bundleUrl || 'file://';
scaledAssetURLInScript(): ResolvedAssetSource {
const path = this.jsbundleUrl || 'file://';
return this.fromSource(path + getScaledAssetPath(this.asset));
}
@ -129,7 +129,7 @@ class AssetSourceResolver {
* E.g. 'file:///sdcard/AwesomeModule/drawable-mdpi/icon.png'
*/
drawableFolderInBundle(): ResolvedAssetSource {
const path = this.bundleUrl || 'file://';
const path = this.jsbundleUrl || 'file://';
return this.fromSource(
path + getAssetPathInDrawableFolder(this.asset)
);

View File

@ -19,45 +19,45 @@ const NativeModules = require('NativeModules');
import type { ResolvedAssetSource } from 'AssetSourceResolver';
let _customSourceTransformer, _serverURL, _bundleSourceURL;
let _customSourceTransformer, _serverURL, _scriptURL;
function getDevServerURL(): ?string {
if (_serverURL === undefined) {
var scriptURL = NativeModules.SourceCode.scriptURL;
var match = scriptURL && scriptURL.match(/^https?:\/\/.*?\//);
if (match) {
// Bundle was loaded from network
// jsBundle was loaded from network
_serverURL = match[0];
} else {
// Bundle was loaded from file
// jsBundle was loaded from file
_serverURL = null;
}
}
return _serverURL;
}
function getBundleSourceURL(): ?string {
if (_bundleSourceURL === undefined) {
function getScriptURL(): ?string {
if (_scriptURL === undefined) {
const scriptURL = NativeModules.SourceCode.scriptURL;
if (!scriptURL) {
// scriptURL is falsy, we have nothing to go on here
_bundleSourceURL = null;
return _bundleSourceURL;
_scriptURL = null;
return _scriptURL;
}
if (scriptURL.startsWith('assets://')) {
// android: running from within assets, no offline path to use
_bundleSourceURL = null;
return _bundleSourceURL;
_scriptURL = null;
return _scriptURL;
}
_bundleSourceURL = scriptURL.substring(0, scriptURL.lastIndexOf('/') + 1);
_scriptURL = scriptURL.substring(0, scriptURL.lastIndexOf('/') + 1);
if (!scriptURL.startsWith('file://')) {
// Add file protocol in case we have an absolute file path and not a URL.
// This shouldn't really be necessary. scriptURL should be a URL.
_bundleSourceURL = 'file://' + _bundleSourceURL;
_scriptURL = 'file://' + _scriptURL;
}
}
return _bundleSourceURL;
return _scriptURL;
}
function setCustomSourceTransformer(
@ -80,7 +80,7 @@ function resolveAssetSource(source: any): ?ResolvedAssetSource {
return null;
}
const resolver = new AssetSourceResolver(getDevServerURL(), getBundleSourceURL(), asset);
const resolver = new AssetSourceResolver(getDevServerURL(), getScriptURL(), asset);
if (_customSourceTransformer) {
return _customSourceTransformer(resolver);
}