MCPcopy Index your code
hub / github.com/dmno-dev/varlock / resolveTargetPaths

Function resolveTargetPaths

packages/varlock/src/cli/commands/scan.command.ts:208–249  ·  view source on GitHub ↗
(targets: Array<string>, cwd: string)

Source from the content-addressed store, hash-verified

206 * - Explicit files are included directly (if not a binary extension).
207 */
208export async function resolveTargetPaths(targets: Array<string>, cwd: string): Promise<Array<string>> {
209 const seen = new Set<string>();
210 const files: Array<string> = [];
211
212 async function addFile(absPath: string) {
213 if (seen.has(absPath)) return;
214 seen.add(absPath);
215 files.push(absPath);
216 }
217
218 async function addPath(absPath: string) {
219 let stat;
220 try {
221 stat = await fs.stat(absPath);
222 } catch {
223 return; // path doesn't exist — silently skip
224 }
225 if (stat.isDirectory()) {
226 for (const f of await walkDirectoryAll(absPath)) {
227 await addFile(f);
228 }
229 } else if (stat.isFile()) {
230 const ext = path.extname(absPath).toLowerCase();
231 if (!BINARY_EXTENSIONS.has(ext)) {
232 await addFile(absPath);
233 }
234 }
235 }
236
237 for (const target of targets) {
238 if (GLOB_CHARS.test(target)) {
239 // Expand glob pattern; paths returned by fsGlob are relative to cwd
240 for await (const match of fs.glob(target, { cwd })) {
241 await addPath(path.resolve(cwd, match));
242 }
243 } else {
244 await addPath(path.resolve(cwd, target));
245 }
246 }
247
248 return files;
249}
250
251/**
252 * Scans a single file for occurrences of any of the provided sensitive values.

Callers 2

commandFnFunction · 0.85

Calls 2

addPathFunction · 0.85
resolveMethod · 0.65

Tested by

no test coverage detected