From 2f4dcae50579b37d4ea3c15014cf7be241f2871b Mon Sep 17 00:00:00 2001 From: Alex Kotliarskyi Date: Thu, 7 May 2015 17:30:41 -0700 Subject: [PATCH] [ReactNative] Register assets with AssetRegistry --- react-packager/src/Packager/__tests__/Packager-test.js | 8 ++++---- react-packager/src/Packager/index.js | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/react-packager/src/Packager/__tests__/Packager-test.js b/react-packager/src/Packager/__tests__/Packager-test.js index 3f093446..d4a1c0f3 100644 --- a/react-packager/src/Packager/__tests__/Packager-test.js +++ b/react-packager/src/Packager/__tests__/Packager-test.js @@ -166,12 +166,12 @@ describe('Packager', function() { }; expect(p.addModule.mock.calls[3][0]).toEqual({ - code: 'lol module.exports = ' + + code: 'lol module.exports = require("AssetRegistry").registerAsset(' + JSON.stringify(imgModule) + - '; lol', - sourceCode: 'module.exports = ' + + '); lol', + sourceCode: 'module.exports = require("AssetRegistry").registerAsset(' + JSON.stringify(imgModule) + - ';', + ');', sourcePath: '/root/img/new_image.png' }); diff --git a/react-packager/src/Packager/index.js b/react-packager/src/Packager/index.js index c03a0432..e647f764 100644 --- a/react-packager/src/Packager/index.js +++ b/react-packager/src/Packager/index.js @@ -219,7 +219,8 @@ Packager.prototype.generateAssetModule = function(ppackage, module) { ppackage.addAsset(img); - var code = 'module.exports = ' + JSON.stringify(img) + ';'; + var ASSET_TEMPLATE = 'module.exports = require("AssetRegistry").registerAsset(%json);'; + var code = ASSET_TEMPLATE.replace('%json', JSON.stringify(img)); return new ModuleTransport({ code: code,