mirror of https://github.com/status-im/metro.git
Updates from Fri 20 Mar
- declare timeoutID | Basil Hosmer - [react-packager] Allow entry point extensions like .ios.js | Amjad Masad - [react-native] Use SpreadProperty to make react-docgen happy | Felix Kling - clean Examples/2048 | Basil Hosmer - [ReactNative] Adjust packager default root when running from within node_modules | Alex Kotliarskyi - [ReactNative] Add missing websocket dependency | Alex Kotliarskyi - [react-packager] change all but one `ix` to `require` | Amjad Masad
This commit is contained in:
parent
d11511f5dd
commit
f0aeb066c8
|
@ -37,9 +37,14 @@ if (options.projectRoots) {
|
|||
if (!Array.isArray(options.projectRoots)) {
|
||||
options.projectRoots = options.projectRoots.split(',');
|
||||
}
|
||||
} else {
|
||||
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) {
|
||||
if (typeof options.root === 'string') {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"');
|
||||
// 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;
|
||||
}
|
||||
var main = match[1] + '.js';
|
||||
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),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue