Skip to content

Commit

Permalink
Rename bundleUrl to jsbundleURL
Browse files Browse the repository at this point in the history
Reviewed By: fkgozali

Differential Revision: D6236921

fbshipit-source-id: f1018836465ba6cf21679fe9d21c18eec762199d
  • Loading branch information
Yujie Liu authored and facebook-github-bot committed Nov 8, 2017
1 parent b983de9 commit b0193b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions Libraries/Image/AssetSourceResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -66,7 +66,7 @@ class AssetSourceResolver {
}

isLoadedFromFileSystem(): boolean {
return !!this.bundleUrl;
return !!this.jsbundleUrl;
}

defaultAsset(): ResolvedAssetSource {
Expand All @@ -79,7 +79,7 @@ class AssetSourceResolver {
this.drawableFolderInBundle() :
this.resourceIdentifierWithoutScale();
} else {
return this.scaledAssetURLInBundle();
return this.scaledAssetURLInScript();
}
}

Expand All @@ -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/[email protected]'
*/
scaledAssetURLInBundle(): ResolvedAssetSource {
const path = this.bundleUrl || 'file://';
scaledAssetURLInScript(): ResolvedAssetSource {
const path = this.jsbundleUrl || 'file://';
return this.fromSource(path + getScaledAssetPath(this.asset));
}

Expand All @@ -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)
);
Expand Down
26 changes: 13 additions & 13 deletions Libraries/Image/resolveAssetSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
Expand Down

0 comments on commit b0193b0

Please sign in to comment.