MCPcopy Create free account
hub / github.com/webpack/webpack-cli / extractFolder

Function extractFolder

scripts/utils.js:12–39  ·  view source on GitHub ↗

* @param {string} folderToRead folder to read * @param {string[]} folders folders * @param {((stats: import("node:fs").Stats, file: string) => boolean)=} folderStrategy filter function * @returns {string[]} folders

(folderToRead, folders = [], folderStrategy = undefined)

Source from the content-addressed store, hash-verified

10 * @returns {string[]} folders
11 */
12function extractFolder(folderToRead, folders = [], folderStrategy = undefined) {
13 let files;
14
15 try {
16 files = fs.readdirSync(folderToRead);
17 } catch {
18 return [];
19 }
20
21 if (!files) {
22 return [];
23 }
24
25 for (const file of files) {
26 const filePath = path.resolve(path.join(folderToRead, file));
27 const stats = fs.statSync(filePath);
28
29 if (folderStrategy && folderStrategy(stats, file)) {
30 folders.push(folderToRead);
31 }
32
33 if (stats.isDirectory() && file !== "node_modules") {
34 extractFolder(filePath, folders, folderStrategy);
35 }
36 }
37
38 return folders;
39}
40
41/**
42 * @param {string} strategy strategy

Callers 1

collectTestFoldersFunction · 0.85

Calls 1

folderStrategyFunction · 0.85

Tested by

no test coverage detected