| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.readdir = exports.readdirWithFileTypes = exports.read = void 0; |
| 4 |
const fsStat = require("@nodelib/fs.stat"); |
| 5 |
const constants_1 = require("../constants"); |
| 6 |
const utils = require("../utils"); |
| 7 |
const common = require("./common"); |
| 8 |
function read(directory, settings) { |
| 9 |
if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) { |
| 10 |
return readdirWithFileTypes(directory, settings); |
| 11 |
} |
| 12 |
return readdir(directory, settings); |
| 13 |
} |
| 14 |
exports.read = read; |
| 15 |
function readdirWithFileTypes(directory, settings) { |
| 16 |
const dirents = settings.fs.readdirSync(directory, { withFileTypes: true }); |
| 17 |
return dirents.map((dirent) => { |
| 18 |
const entry = { |
| 19 |
dirent, |
| 20 |
name: dirent.name, |
| 21 |
path: common.joinPathSegments(directory, dirent.name, settings.pathSegmentSeparator) |
| 22 |
}; |
| 23 |
if (entry.dirent.isSymbolicLink() && settings.followSymbolicLinks) { |
| 24 |
try { |
| 25 |
const stats = settings.fs.statSync(entry.path); |
| 26 |
entry.dirent = utils.fs.createDirentFromStats(entry.name, stats); |
| 27 |
} |
| 28 |
catch (error) { |
| 29 |
if (settings.throwErrorOnBrokenSymbolicLink) { |
| 30 |
throw error; |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
return entry; |
| 35 |
}); |
| 36 |
} |
| 37 |
exports.readdirWithFileTypes = readdirWithFileTypes; |
| 38 |
function readdir(directory, settings) { |
| 39 |
const names = settings.fs.readdirSync(directory); |
| 40 |
return names.map((name) => { |
| 41 |
const entryPath = common.joinPathSegments(directory, name, settings.pathSegmentSeparator); |
| 42 |
const stats = fsStat.statSync(entryPath, settings.fsStatSettings); |
| 43 |
const entry = { |
| 44 |
name, |
| 45 |
path: entryPath, |
| 46 |
dirent: utils.fs.createDirentFromStats(name, stats) |
| 47 |
}; |
| 48 |
if (settings.stats) { |
| 49 |
entry.stats = stats; |
| 50 |
} |
| 51 |
return entry; |
| 52 |
}); |
| 53 |
} |
| 54 |
exports.readdir = readdir; |