# Code coverage report for lib/config/checkWatchSupport.js

## Statements: 64% (16 / 25) Branches: 50% (6 / 12) Functions: 60% (3 / 5) Lines: 64% (16 / 25)

All files » lib/config/ » checkWatchSupport.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    641
    1

    1

    1
    3
    2

    1
    1

    1
    1

    1

    1
    1
    1
    1

    1

     'use strict';
    var utils = require('../utils'),
        watchable = require('./watchable'),
        fs = require('fs'),
        exec = require('child_process').exec,
        checkComplete = false;

    module.exports = checkWatchSupport;

    /**
     * Runs tests to see if the version of `find` being run supports searching by
     * seconds using `-mtime -1s -print`. Note that this function **modifies** the
     * config being passed in.
     *
     * @param  {Object}   config   reference to config that's *updated* inside
     * @param  {Function} ready once the monitor checks are complete, call ready
     */
    function checkWatchSupport(config, callback) {
      if (checkComplete) {
        return callback(config);
      }

      var ready = function () {
        Iif (checkComplete) {
          //utils.bus.emit('config:update');
        } else {
          checkComplete = true;
          callback(config);
        }
      };

      var alternativeCheck = function () {
        watchable.check(function(success) {
          // whether or not fs.watch actually works on this platform, tested and set
          // later before starting
          config.system.useWatch = success;
          ready(config);
        });
      };

      // Note: we're purposely putting Mac over to the `find` command.
      // this is because it has a default ulimit of 256 - which is WAY LOW,
      // and without asking the user to `unlimit -n <BIG-ASS-NUMBER>` it'll throw
      // up all over your screen like this: http://d.pr/i/R6B8+
      config.system.useFind = utils.isMac || !fs.watch;
      Eif (config.system.useFind) {
        exec('find -L /dev/null -type f -mtime -1s -print', function(error) {
          Iif (error) {
            if (!fs.watch) {
              utils.log.error('The version of node you are using combined with the version of find being used does not support watching files. Upgrade to a newer version of node, or install a version of find that supports search by seconds.');
              process.exit(1);
            } else {
              config.system.useFind = false;
              alternativeCheck();
            }
          } else {
            // Find is compatible with -1s
            ready(config);
          }
        });
      } else {
        alternativeCheck();
      }
    }