function _rmdirRecursiveSync(root) {
  const dirs = [root];

  do {
    var
      dir = dirs.pop(),
      deferred = false,
      files = fs.readdirSync(dir);

    for (var i = 0, length = files.length; i < length; i++) {
      var
        file = path.join(dir, files[i]),
        stat = fs.lstatSync(file); // lstat so we don't recurse into symlinked directories

      if (stat.isDirectory()) {
        if (!deferred) {
          deferred = true;
          dirs.push(dir);
        }
        dirs.push(file);
      } else {
        fs.unlinkSync(file);
      }
    }

    if (!deferred) {
      fs.rmdirSync(dir);
    }
  } while (dirs.length !== 0);
}
/**
 * Removes files and folders in a directory recursively.
 *
 * @param {string} root
 * @private
 */
Removes files and folders in a directory recursively.
@param {string} root
@private
Removes files and folders in a directory recursively . @param { string } root @private
function _rmdirRecursiveSync(root) {
  const dirs = [root];
  do {
    var
      dir = dirs.pop(),
      deferred = false,
      files = fs.readdirSync(dir);
    for (var i = 0, length = files.length; i < length; i++) {
      var
        file = path.join(dir, files[i]),
        stat = fs.lstatSync(file); 
      if (stat.isDirectory()) {
        if (!deferred) {
          deferred = true;
          dirs.push(dir);
        }
        dirs.push(file);
      } else {
        fs.unlinkSync(file);
      }
    }
    if (!deferred) {
      fs.rmdirSync(dir);
    }
  } while (dirs.length !== 0);
}
function _rmdirRecursiveSync ( root ) { const dirs = [ root ] ; do { var dir = dirs . pop ( ) , deferred = false , files = fs . readdirSync ( dir ) ; for ( var i = 0 , length = files . length ; i < length ; i ++ ) { var file = path . join ( dir , files [ i ] ) , stat = fs . lstatSync ( file ) ; if ( stat . isDirectory ( ) ) { if ( ! deferred ) { deferred = true ; dirs . push ( dir ) ; } dirs . push ( file ) ; } else { fs . unlinkSync ( file ) ; } } if ( ! deferred ) { fs . rmdirSync ( dir ) ; } } while ( dirs . length !== 0 ) ; }
Removes files and folders in a directory recursively.
Removes files and folders in a directory recursively .
// lstat so we don't recurse into symlinked directories