Skip to content

Commit

Permalink
Migrate SourceCode from Native Module to a Native Extension.
Browse files Browse the repository at this point in the history
Reviewed By: danzimm

Differential Revision: D6848275

fbshipit-source-id: c50305018aa2bdf014f5f665f370f65866197c3b
  • Loading branch information
Dmitry Zakharov authored and facebook-github-bot committed Feb 8, 2018
1 parent 528bbac commit 47fe523
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Libraries/Image/resolveAssetSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@

const AssetRegistry = require('AssetRegistry');
const AssetSourceResolver = require('AssetSourceResolver');
const NativeModules = require('NativeModules');

import type { ResolvedAssetSource } from 'AssetSourceResolver';

let _customSourceTransformer, _serverURL, _scriptURL;
let _sourceCodeScriptURL: ?string;

function getDevServerURL(): ?string {
if (_serverURL === undefined) {
var scriptURL = NativeModules.SourceCode.scriptURL;
var match = scriptURL && scriptURL.match(/^https?:\/\/.*?\//);
const match = _sourceCodeScriptURL && _sourceCodeScriptURL.match(/^https?:\/\/.*?\//);
if (match) {
// jsBundle was loaded from network
_serverURL = match[0];
Expand Down Expand Up @@ -54,8 +53,7 @@ function _coerceLocalScriptURL(scriptURL: ?string): ?string {

function getScriptURL(): ?string {
if (_scriptURL === undefined) {
const scriptURL = NativeModules.SourceCode.scriptURL;
_scriptURL = _coerceLocalScriptURL(scriptURL);
_scriptURL = _coerceLocalScriptURL(_sourceCodeScriptURL);
}
return _scriptURL;
}
Expand Down Expand Up @@ -91,6 +89,13 @@ function resolveAssetSource(source: any): ?ResolvedAssetSource {
return resolver.defaultAsset();
}

let sourceCodeScriptURL: ?string = global.nativeExtensions && global.nativeExtensions.SourceCode && global.nativeExtensions.SourceCode.scriptURL;
if (!sourceCodeScriptURL) {
const NativeModules = require('NativeModules');
sourceCodeScriptURL = NativeModules && NativeModules.SourceCode && NativeModules.SourceCode.scriptURL;
}
_sourceCodeScriptURL = sourceCodeScriptURL;

module.exports = resolveAssetSource;
module.exports.pickScale = AssetSourceResolver.pickScale;
module.exports.setCustomSourceTransformer = setCustomSourceTransformer;

0 comments on commit 47fe523

Please sign in to comment.