657d0119cc
* Dont use unreliable inode as unique identifier * Just concat with `\n * Introduce path-overriding code to allow local executables ot be found
23 lines
548 B
TypeScript
23 lines
548 B
TypeScript
// @ts-check
|
|
const { lstatSync, readdirSync } = require("fs");
|
|
const { join } = require("path");
|
|
|
|
/**
|
|
* Find the size of a directory recursively.
|
|
* Symbolic links can cause a loop.
|
|
* @param {string} root
|
|
* @returns {number} bytes
|
|
*/
|
|
function getDirSize(root) {
|
|
const stats = lstatSync(root);
|
|
|
|
if (!stats.isDirectory()) {
|
|
return stats.size;
|
|
}
|
|
|
|
return readdirSync(root)
|
|
.map(file => getDirSize(join(root, file)))
|
|
.reduce((acc, num) => acc + num, 0);
|
|
}
|
|
|
|
module.exports = getDirSize;
|