mirror of
https://github.com/status-im/metro.git
synced 2025-01-09 18:45:41 +00:00
b05ca45244
Summary: @public Currently, every time we call into the packager we have to change the ulimit to make sure we don't hit the EMFILE error (the packager uses as much concurrency as possible). Using graceful-fs, the fs module -- with monkey patching -- becomes intelligent enough to recover from EMFILE errors. Test Plan: * set `ulimit -n 256* * start server * request from your browser: http://localhost:8081/RKJSModules/MainBundle/CatalystBundle.includeRequire.bundle * it works
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
'use strict';
|
|
|
|
useGracefulFs();
|
|
|
|
var Activity = require('./src/Activity');
|
|
var Server = require('./src/Server');
|
|
|
|
exports.middleware = function(options) {
|
|
var server = new Server(options);
|
|
return server.processRequest.bind(server);
|
|
};
|
|
|
|
exports.buildPackageFromUrl = function(options, reqUrl) {
|
|
Activity.disable();
|
|
// Don't start the filewatcher or the cache.
|
|
if (options.nonPersistent == null) {
|
|
options.nonPersistent = true;
|
|
}
|
|
|
|
var server = new Server(options);
|
|
return server.buildPackageFromUrl(reqUrl)
|
|
.then(function(p) {
|
|
server.end();
|
|
return p;
|
|
});
|
|
};
|
|
|
|
exports.getDependencies = function(options, main) {
|
|
Activity.disable();
|
|
// Don't start the filewatcher or the cache.
|
|
if (options.nonPersistent == null) {
|
|
options.nonPersistent = true;
|
|
}
|
|
|
|
var server = new Server(options);
|
|
return server.getDependencies(main)
|
|
.then(function(r) {
|
|
server.end();
|
|
return r.dependencies;
|
|
});
|
|
};
|
|
|
|
function useGracefulFs() {
|
|
var fs = require('fs');
|
|
var gracefulFs = require('graceful-fs');
|
|
|
|
// A bit sneaky but it's not straightforward to update all the
|
|
// modules we depend on.
|
|
Object.keys(fs).forEach(function(method) {
|
|
if (typeof fs[method] === 'function' && gracefulFs[method]) {
|
|
fs[method] = gracefulFs[method];
|
|
}
|
|
});
|
|
}
|