MCPcopy Create free account
hub / github.com/vercel/vercel / readdir

Function readdir

packages/client/src/utils/readdir-recursive.ts:52–112  ·  view source on GitHub ↗
(
  path: string,
  ignores: Ignoreable[]
)

Source from the content-addressed store, hash-verified

50}
51
52export default function readdir(
53 path: string,
54 ignores: Ignoreable[]
55): Promise<string[]> {
56 ignores = ignores.map(toMatcherFunction);
57
58 let list: string[] = [];
59
60 return new Promise(function (resolve, reject) {
61 fs.readdir(path, function (err, files) {
62 if (err) {
63 return reject(err);
64 }
65
66 let pending = files.length;
67 if (!pending) {
68 return resolve(list);
69 }
70
71 files.forEach(function (file) {
72 const filePath = p.join(path, file);
73 fs.lstat(filePath, function (_err, stats) {
74 if (_err) {
75 return reject(_err);
76 }
77
78 const matches = ignores.some(matcher => matcher(filePath, stats));
79 if (matches) {
80 pending -= 1;
81 if (!pending) {
82 return resolve(list);
83 }
84 return null;
85 }
86
87 if (stats.isDirectory()) {
88 readdir(filePath, ignores)
89 .then(function (res) {
90 if (res.length === 0) {
91 // Empty directories get returned
92 list.push(filePath);
93 }
94 list = list.concat(res);
95 pending -= 1;
96 if (!pending) {
97 return resolve(list);
98 }
99 })
100 .catch(reject);
101 } else {
102 list.push(filePath);
103 pending -= 1;
104 if (!pending) {
105 return resolve(list);
106 }
107 }
108 });
109 });

Callers 11

buildFileTreeFunction · 0.70
cleanupFileSystemFunction · 0.50
compileDevTemplatesFunction · 0.50
listDirectoriesFunction · 0.50
walkFunction · 0.50
unit.test.tsFile · 0.50
createFunctionsIteratorFunction · 0.50
scanDistributionsFunction · 0.50
extendDistRecordFunction · 0.50
buildFunction · 0.50

Calls 4

pushMethod · 0.65
resolveFunction · 0.50
joinMethod · 0.45
isDirectoryMethod · 0.45

Tested by

no test coverage detected