mirror of
https://github.com/status-im/react-native.git
synced 2025-01-16 04:24:15 +00:00
[react-packager] Allow entry point extensions like .ios.js
This commit is contained in:
parent
81d024924c
commit
ce6354604c
@ -51,7 +51,7 @@ describe('processRequest', function() {
|
|||||||
Packager = require('../../Packager');
|
Packager = require('../../Packager');
|
||||||
FileWatcher = require('../../FileWatcher');
|
FileWatcher = require('../../FileWatcher');
|
||||||
|
|
||||||
Packager.prototype.package = function() {
|
Packager.prototype.package = jest.genMockFunction().mockImpl(function() {
|
||||||
return q({
|
return q({
|
||||||
getSource: function() {
|
getSource: function() {
|
||||||
return 'this is the source';
|
return 'this is the source';
|
||||||
@ -60,7 +60,7 @@ describe('processRequest', function() {
|
|||||||
return 'this is the source map';
|
return 'this is the source map';
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
|
|
||||||
FileWatcher.prototype.on = function(eventType, callback) {
|
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() {
|
pit('watches all files in projectRoot', function() {
|
||||||
return makeRequest(
|
return makeRequest(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
24
packager/react-packager/src/Server/index.js
vendored
24
packager/react-packager/src/Server/index.js
vendored
@ -6,7 +6,6 @@ var declareOpts = require('../lib/declareOpts');
|
|||||||
var FileWatcher = require('../FileWatcher');
|
var FileWatcher = require('../FileWatcher');
|
||||||
var Packager = require('../Packager');
|
var Packager = require('../Packager');
|
||||||
var Activity = require('../Activity');
|
var Activity = require('../Activity');
|
||||||
var setImmediate = require('timers').setImmediate;
|
|
||||||
var q = require('q');
|
var q = require('q');
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
|
|
||||||
@ -236,23 +235,24 @@ Server.prototype.processRequest = function(req, res, next) {
|
|||||||
function getOptionsFromUrl(reqUrl) {
|
function getOptionsFromUrl(reqUrl) {
|
||||||
// `true` to parse the query param as an object.
|
// `true` to parse the query param as an object.
|
||||||
var urlObj = url.parse(reqUrl, true);
|
var urlObj = url.parse(reqUrl, true);
|
||||||
|
var pathname = urlObj.pathname;
|
||||||
|
|
||||||
var match = urlObj.pathname.match(/^\/?([^\.]+)\..*(bundle|map)$/);
|
// Backwards compatibility. Options used to be as added as '.' to the
|
||||||
if (!(match && match[1])) {
|
// entry module name. We can safely remove these options.
|
||||||
throw new Error('Invalid url format, expected "/path/to/file.bundle"');
|
var entryFile = pathname.replace(/^\//, '').split('.').filter(function(part) {
|
||||||
|
if (part === 'includeRequire' || part === 'runModule' ||
|
||||||
|
part === 'bundle' || part === 'map') {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
var main = match[1] + '.js';
|
return true;
|
||||||
|
}).join('.') + '.js';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sourceMapUrl: urlObj.pathname.replace(/\.bundle$/, '.map'),
|
sourceMapUrl: pathname.replace(/\.bundle$/, '.map'),
|
||||||
main: main,
|
main: entryFile,
|
||||||
dev: getBoolOptionFromQuery(urlObj.query, 'dev', true),
|
dev: getBoolOptionFromQuery(urlObj.query, 'dev', true),
|
||||||
minify: getBoolOptionFromQuery(urlObj.query, 'minify'),
|
minify: getBoolOptionFromQuery(urlObj.query, 'minify'),
|
||||||
runModule: getBoolOptionFromQuery(urlObj.query, 'runModule') ||
|
runModule: getBoolOptionFromQuery(urlObj.query, 'runModule', true),
|
||||||
// Backwards compatibility.
|
|
||||||
urlObj.pathname.split('.').some(function(part) {
|
|
||||||
return part === 'runModule';
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user