UNPKG

zephyr-agent

Version:
192 lines (191 loc) • 6.72 kB
"use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.d = (exports1, getters, values)=>{ var define = (defs, kind)=>{ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, [kind]: defs[key] }); }; define(getters, "get"); define(values, "value"); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { readDirRecursive: ()=>readDirRecursive, readDirRecursiveWithContents: ()=>readDirRecursiveWithContents }); const promises_namespaceObject = require("node:fs/promises"); const external_node_path_namespaceObject = require("node:path"); const SKIP_PATH_PATTERNS = [ /(^|\/)node_modules($|\/)/i, /(^|\/)\.git($|\/)/i, /(^|\/)\.DS_Store$/i, /(^|\/)thumbs\.db$/i ]; async function readDirRecursive(dirPath, options = {}) { const files = []; for await (const file of resolveDir({ currentDir: (0, external_node_path_namespaceObject.resolve)(dirPath), relativePrefix: '', readContents: false, activeRealDirs: new Set(), includeIgnoredPaths: options.includeIgnoredPaths ?? false, failOnError: options.failOnError ?? false }))files.push({ fullPath: file.fullPath, relativePath: file.relativePath }); return files; } async function readDirRecursiveWithContents(dirPath, options = {}) { const files = []; for await (const file of resolveDir({ currentDir: (0, external_node_path_namespaceObject.resolve)(dirPath), relativePrefix: '', readContents: true, activeRealDirs: new Set(), includeIgnoredPaths: options.includeIgnoredPaths ?? false, failOnError: options.failOnError ?? false }))if (file.content) files.push(file); return files; } async function* resolveDir({ currentDir, relativePrefix, readContents, activeRealDirs, includeIgnoredPaths, failOnError }) { let entries; try { entries = await (0, promises_namespaceObject.readdir)(currentDir, { withFileTypes: true }); } catch (error) { if (failOnError) throw error; return; } const currentRealDir = await safeRealpath(currentDir, failOnError); if (activeRealDirs.has(currentRealDir)) return; activeRealDirs.add(currentRealDir); try { for (const entry of entries){ const fullPath = (0, external_node_path_namespaceObject.resolve)(currentDir, entry.name); const relativePath = relativePrefix ? (0, external_node_path_namespaceObject.join)(relativePrefix, entry.name) : entry.name; const normalizedRelativePath = normalizePath(relativePath); if (!(!includeIgnoredPaths && shouldSkipRelativePath(normalizedRelativePath, entry))) yield* resolveFile({ fullPath, relativePath, entry, readContents, activeRealDirs, includeIgnoredPaths, failOnError }); } } finally{ activeRealDirs.delete(currentRealDir); } } async function* resolveFile({ fullPath, relativePath, entry, readContents, activeRealDirs, includeIgnoredPaths, failOnError }) { if (entry.isSymbolicLink()) return void (yield* resolveSymbolicLink({ fullPath, relativePath, readContents, activeRealDirs, includeIgnoredPaths, failOnError })); if (entry.isDirectory()) return void (yield* resolveDir({ currentDir: fullPath, relativePrefix: relativePath, readContents, activeRealDirs, includeIgnoredPaths, failOnError })); if (entry.isFile()) { const content = readContents ? await safeReadFile(fullPath, failOnError) : void 0; if (readContents && !content) return; yield { fullPath, relativePath, content }; } } async function* resolveSymbolicLink({ fullPath, relativePath, readContents, activeRealDirs, includeIgnoredPaths, failOnError }) { const realPath = await safeRealpath(fullPath, failOnError); let realStat; try { realStat = await (0, promises_namespaceObject.stat)(realPath); } catch (error) { if (failOnError) throw error; return; } if (realStat.isDirectory()) { if (activeRealDirs.has(realPath)) return; yield* resolveDir({ currentDir: realPath, relativePrefix: relativePath, readContents, activeRealDirs, includeIgnoredPaths, failOnError }); return; } if (realStat.isFile()) { const content = readContents ? await safeReadFile(realPath, failOnError) : void 0; if (readContents && !content) return; yield { fullPath: realPath, relativePath, content }; } } async function safeReadFile(path, failOnError) { try { return await (0, promises_namespaceObject.readFile)(path); } catch (error) { if (failOnError) throw error; return; } } async function safeRealpath(path, failOnError) { try { return await (0, promises_namespaceObject.realpath)(path); } catch (error) { if (failOnError) throw error; return path; } } function normalizePath(filePath) { return filePath.replace(/\\/g, '/'); } function shouldSkipRelativePath(relativePath, entry) { if (entry.isDirectory()) return SKIP_PATH_PATTERNS.some((pattern)=>pattern.test(`${relativePath}/`)); return SKIP_PATH_PATTERNS.some((pattern)=>pattern.test(relativePath)); } exports.readDirRecursive = __webpack_exports__.readDirRecursive; exports.readDirRecursiveWithContents = __webpack_exports__.readDirRecursiveWithContents; for(var __rspack_i in __webpack_exports__)if (-1 === [ "readDirRecursive", "readDirRecursiveWithContents" ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i]; Object.defineProperty(exports, '__esModule', { value: true }); //# sourceMappingURL=read-dir-recursive.js.map