From d26af5811d2690faab1220ef3766faa7bc5bf682 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Fri, 14 Oct 2016 11:11:35 -0700 Subject: [PATCH] Monkey-patch `fs` with graceful-fs before anything else runs Reviewed By: matryoshcow, kentaromiura Differential Revision: D4020645 fbshipit-source-id: a7985109476b78b588c3e2a75ae6f25ea8f09237 --- local-cli/cli.js | 5 ++++- local-cli/cliEntry.js | 23 ++++++++--------------- packager/react-packager/index.js | 7 ------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/local-cli/cli.js b/local-cli/cli.js index c8837ee7c..8369d517f 100644 --- a/local-cli/cli.js +++ b/local-cli/cli.js @@ -8,6 +8,9 @@ */ 'use strict'; +// gracefulify() has to be called before anything else runs +require('graceful-fs').gracefulify(require('fs')); + // This file must be able to run in node 0.12 without babel so we can show that // it is not supported. This is why the rest of the cli code is in `cliEntry.js`. require('./server/checkNodeVersion')(); @@ -15,7 +18,7 @@ require('./server/checkNodeVersion')(); require('../packager/babelRegisterOnly')([ /private-cli\/src/, /local-cli/, - /react-packager\/src/ + /react-packager\/src/, ]); var cliEntry = require('./cliEntry'); diff --git a/local-cli/cliEntry.js b/local-cli/cliEntry.js index 0c12903f9..4acacd3d9 100644 --- a/local-cli/cliEntry.js +++ b/local-cli/cliEntry.js @@ -10,29 +10,22 @@ */ 'use strict'; -const commander = require('commander'); - const Config = require('./util/Config'); -const childProcess = require('child_process'); const Promise = require('promise'); + +const assertRequiredOptions = require('./util/assertRequiredOptions'); const chalk = require('chalk'); +const childProcess = require('child_process'); +const commander = require('commander'); +const commands = require('./commands'); +const defaultConfig = require('./default.config'); +const init = require('./init/init'); const minimist = require('minimist'); const path = require('path'); -const fs = require('fs'); -const gracefulFs = require('graceful-fs'); - -const init = require('./init/init'); -const commands = require('./commands'); -const assertRequiredOptions = require('./util/assertRequiredOptions'); const pkg = require('../package.json'); -const defaultConfig = require('./default.config'); import type { Command } from './commands'; -// graceful-fs helps on getting an error when we run out of file -// descriptors. When that happens it will enqueue the operation and retry it. -gracefulFs.gracefulify(fs); - commander.version(pkg.version); const defaultOptParser = (val) => val; @@ -140,7 +133,7 @@ const addCommand = (command: Command, config: Config) => { function getCliConfig() { // Use a lightweight option parser to look up the CLI configuration file, // which we need to set up the parser for the other args and options - let cliArgs = minimist(process.argv.slice(2)); + const cliArgs = minimist(process.argv.slice(2)); let cwd; let configPath; diff --git a/packager/react-packager/index.js b/packager/react-packager/index.js index 240c5fabd..65892a14d 100644 --- a/packager/react-packager/index.js +++ b/packager/react-packager/index.js @@ -11,7 +11,6 @@ require('../babelRegisterOnly')([/react-packager\/src/]); require('./src/node-haste/fastpath').replace(); -useGracefulFs(); var debug = require('debug'); var Activity = require('./src/Activity'); @@ -73,12 +72,6 @@ exports.getOrderedDependencyPaths = function(options, bundleOptions) { }); }; -function useGracefulFs() { - var fs = require('fs'); - var gracefulFs = require('graceful-fs'); - gracefulFs.gracefulify(fs); -} - function enableDebug() { // react-packager logs debug messages using the 'debug' npm package, and uses // the following prefix throughout.