MCPcopy Create free account
hub / github.com/Snapchat/Valdi / findFile

Function findFile

npm_modules/cli/test/helpers/ProjectHelpers.ts:28–63  ·  view source on GitHub ↗
(fileName, withinModule)

Source from the content-addressed store, hash-verified

26
27export function createProject(name: string, rootPath: string): ProjectConfig {
28 const findFile: ProjectConfig['findFile'] = (fileName, withinModule) => {
29 return new Promise((resolve, reject) => {
30 const buffers: Buffer[] = [];
31
32 const errorBuffers: Buffer[] = [];
33 const directory = path.join(...['.', 'modules'].concat(withinModule ?? []));
34
35 const child = spawn('find', [directory]);
36 child.stdout.on('data', (chunk: Buffer) => {
37 buffers.push(chunk);
38 });
39
40 child.stderr.on('data', (chunk: Buffer) => {
41 errorBuffers.push(chunk);
42 });
43
44 child.on('close', code => {
45 if (!!code && code > 0) {
46 reject(new Error('exited with error code: ' + code.toString()));
47 }
48
49 const output = Buffer.concat(buffers).toString('utf8');
50
51 const files = output.trim().split('\n');
52
53 const found = files.find(file => file.endsWith(`/${fileName}`));
54
55 if (!found) {
56 reject(new Error('File not found: ' + fileName));
57 return;
58 }
59
60 resolve(path.join(rootPath, found));
61 });
62 });
63 };
64 return {
65 name,
66 rootPath,

Callers 1

createProjectFunction · 0.85

Calls 10

rejectFunction · 0.85
splitMethod · 0.80
onMethod · 0.65
toStringMethod · 0.65
resolveFunction · 0.50
joinMethod · 0.45
concatMethod · 0.45
pushMethod · 0.45
trimMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected