diff --git a/packager.js b/packager.js index 26917237..ce4dbd25 100644 --- a/packager.js +++ b/packager.js @@ -38,7 +38,12 @@ if (options.projectRoots) { options.projectRoots = options.projectRoots.split(','); } } else { - options.projectRoots = [path.resolve(__dirname, '..')]; + if (__dirname.match(/node_modules\/react-native\/packager$/)) { + // packager is running from node_modules of another project + options.projectRoots = [path.resolve(__dirname, '../../..')]; + } else { + options.projectRoots = [path.resolve(__dirname, '..')]; + } } if (options.root) { diff --git a/react-packager/src/Server/__tests__/Server-test.js b/react-packager/src/Server/__tests__/Server-test.js index 71b7e400..f4905806 100644 --- a/react-packager/src/Server/__tests__/Server-test.js +++ b/react-packager/src/Server/__tests__/Server-test.js @@ -51,7 +51,7 @@ describe('processRequest', function() { Packager = require('../../Packager'); FileWatcher = require('../../FileWatcher'); - Packager.prototype.package = function() { + Packager.prototype.package = jest.genMockFunction().mockImpl(function() { return q({ getSource: function() { return 'this is the source'; @@ -60,7 +60,7 @@ describe('processRequest', function() { return 'this is the source map'; }, }); - }; + }); FileWatcher.prototype.on = function(eventType, callback) { @@ -106,6 +106,21 @@ describe('processRequest', function() { }); }); + pit('works with .ios.js extension', function() { + return makeRequest( + requestHandler, + 'index.ios.includeRequire.bundle' + ).then(function(response) { + expect(response).toEqual('this is the source'); + expect(Packager.prototype.package).toBeCalledWith( + 'index.ios.js', + true, + 'index.ios.includeRequire.map', + true + ); + }); + }); + pit('watches all files in projectRoot', function() { return makeRequest( requestHandler, diff --git a/react-packager/src/Server/index.js b/react-packager/src/Server/index.js index 09a3c640..3043903d 100644 --- a/react-packager/src/Server/index.js +++ b/react-packager/src/Server/index.js @@ -6,7 +6,6 @@ var declareOpts = require('../lib/declareOpts'); var FileWatcher = require('../FileWatcher'); var Packager = require('../Packager'); var Activity = require('../Activity'); -var setImmediate = require('timers').setImmediate; var q = require('q'); var _ = require('underscore'); @@ -236,23 +235,24 @@ Server.prototype.processRequest = function(req, res, next) { function getOptionsFromUrl(reqUrl) { // `true` to parse the query param as an object. var urlObj = url.parse(reqUrl, true); + var pathname = urlObj.pathname; - var match = urlObj.pathname.match(/^\/?([^\.]+)\..*(bundle|map)$/); - if (!(match && match[1])) { - throw new Error('Invalid url format, expected "/path/to/file.bundle"'); - } - var main = match[1] + '.js'; + // Backwards compatibility. Options used to be as added as '.' to the + // entry module name. We can safely remove these options. + var entryFile = pathname.replace(/^\//, '').split('.').filter(function(part) { + if (part === 'includeRequire' || part === 'runModule' || + part === 'bundle' || part === 'map') { + return false; + } + return true; + }).join('.') + '.js'; return { - sourceMapUrl: urlObj.pathname.replace(/\.bundle$/, '.map'), - main: main, + sourceMapUrl: pathname.replace(/\.bundle$/, '.map'), + main: entryFile, dev: getBoolOptionFromQuery(urlObj.query, 'dev', true), minify: getBoolOptionFromQuery(urlObj.query, 'minify'), - runModule: getBoolOptionFromQuery(urlObj.query, 'runModule') || - // Backwards compatibility. - urlObj.pathname.split('.').some(function(part) { - return part === 'runModule'; - }), + runModule: getBoolOptionFromQuery(urlObj.query, 'runModule', true), }; }