Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package "recursive-readdir" dependency removal #12805

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-dev-utils/FileSizeReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var fs = require('fs');
var path = require('path');
var chalk = require('chalk');
var filesize = require('filesize');
var recursive = require('recursive-readdir');
var recursive = require('./recursiveReaddir');
var stripAnsi = require('strip-ansi');
var gzipSize = require('gzip-size').sync;

Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"openChrome.applescript",
"printBuildError.js",
"printHostingInstructions.js",
"recursiveReaddir.js",
"redirectServedPathMiddleware.js",
"refreshOverlayInterop.js",
"typescriptFormatter.js",
Expand Down Expand Up @@ -72,7 +73,6 @@
"pkg-up": "^3.1.0",
"prompts": "^2.4.2",
"react-error-overlay": "^6.0.11",
"recursive-readdir": "^2.2.2",
"shell-quote": "^1.7.3",
"strip-ansi": "^6.0.1",
"text-table": "^0.2.0"
Expand Down
71 changes: 71 additions & 0 deletions packages/react-dev-utils/recursiveReaddir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// Roughly based on recursive-readdir which is not maintained
// See: https://github.com/jergason/recursive-readdir/blob/master/index.js

var fs = require('fs');
var p = require('path');

function readdir(path, callback) {
if (!callback) {
return new Promise(function (resolve, reject) {
readdir(path, function (err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

var list = [];

fs.readdir(path, function (err, files) {
if (err) {
return callback(err);
}

var pending = files.length;
if (!pending) {
// we are done, woop woop
return callback(null, list);
}

files.forEach(function (file) {
var filePath = p.join(path, file);
fs.stat(filePath, function (_err, stats) {
if (_err) {
return callback(_err);
}

if (stats.isDirectory()) {
readdir(filePath, function (__err, res) {
if (__err) {
return callback(__err);
}

list = list.concat(res);
pending -= 1;
if (!pending) {
return callback(null, list);
}
});
} else {
list.push(filePath);
pending -= 1;
if (!pending) {
return callback(null, list);
}
}
});
});
});
}

module.exports = readdir;