Added timeouts to fs operations in packager

Reviewed By: davidaurelio

Differential Revision: D3316555

fbshipit-source-id: edf6e08569b6cb434219f4460367eec0827530fd
This commit is contained in:
Konstantin Raev 2016-05-18 08:30:51 -07:00 committed by Facebook Github Bot 2
parent 5fbd3751a0
commit bd7114d00f
1 changed files with 15 additions and 3 deletions

View File

@ -16,9 +16,21 @@ const fs = require('fs');
const getAssetDataFromName = require('node-haste').getAssetDataFromName;
const path = require('path');
const stat = Promise.denodeify(fs.stat);
const readDir = Promise.denodeify(fs.readdir);
const readFile = Promise.denodeify(fs.readFile);
const createTimeoutPromise = (timeout) => new Promise((resolve, reject) => {
setTimeout(reject, timeout, 'fs operation timeout');
});
function timeoutableDenodeify(fsFunc, timeout) {
return function raceWrapper(...args) {
return new Promise.race([
createTimeoutPromise(timeout),
Promise.denodeify(fsFunc).apply(this, args)
]);
};
}
const stat = timeoutableDenodeify(fs.stat, 5000);
const readDir = timeoutableDenodeify(fs.readdir, 5000);
const readFile = timeoutableDenodeify(fs.readFile, 5000);
const validateOpts = declareOpts({
projectRoots: {