Skip to content
Permalink
Browse files

Migrate SourceCode from Native Module to a Native Extension.

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 47fe52380a232a1c364e21f71e2644a5a3348366
Showing with 10 additions and 5 deletions.
  1. +10 −5 Libraries/Image/resolveAssetSource.js
@@ -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];
@@ -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;
}
@@ -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.
You can’t perform that action at this time.