/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/configCases/clean/enabled/readdir.js
50 строк
1 KB
Alexander Akait
test: run webpack test suite under Deno and Bun in CI (#21216)
20 июн 2026, 22:25
Не верифицирован
20 июн 2026, 22:25
40b972f
Код
Авторство
О чём код?
const fs = require('fs'); const path = require('path'); /** * @param {string} path path * @returns {string} path */ function handlePath(path) { return path.replace(/\\/g, "/"); } /** * @param {string} from from * @returns {{ files: string[], directories: string[] }} */ module.exports = function readDir(from) { /** @type {string[]} */ const collectedFiles = []; /** @type {string[]} */ const collectedDirectories = []; const stack = [from]; let cursor; while ((cursor = stack.pop())) { const stat = fs.statSync(cursor); if (stat.isDirectory()) { const items = fs.readdirSync(cursor); if (from !== cursor) { const relative = path.relative(from, cursor); collectedDirectories.push(handlePath(relative)); } for (let i = 0; i < items.length; i++) { stack.push(path.join(cursor, items[i])); } } else { const relative = path.relative(from, cursor); collectedFiles.push(handlePath(relative)); } } // Sort so the snapshot is stable across runtimes (Deno's `fs.readdirSync` // returns entries in a different order than Node). return { files: collectedFiles.sort(), directories: collectedDirectories.sort() }; }