MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / findFileSync

Function findFileSync

framework/utils/lib/utils.ts:236–258  ·  view source on GitHub ↗
(pathname: string, doThrow: boolean | Error = true)

Source from the content-addressed store, hash-verified

234}
235
236export function findFileSync(pathname: string, doThrow: boolean | Error = true) {
237 if (fs.pathExistsSync(path.resolve(pathname))) return path.resolve(pathname);
238 if (fs.pathExistsSync(path.resolve(process.cwd(), pathname))) return path.resolve(process.cwd(), pathname);
239 if (fs.pathExistsSync(path.resolve(__dirname, pathname))) return path.resolve(__dirname, pathname);
240 try {
241 return require.resolve(pathname);
242 } catch (e) { }
243 if (pathname.includes('/')) {
244 const eles = pathname.split('/');
245 let pkg = eles.shift();
246 if (pkg.startsWith('@')) pkg = `${pkg}/${eles.shift()}`;
247 const rest = eles.join('/');
248 try {
249 const p = path.dirname(require.resolve(path.join(pkg, 'package.json')));
250 if (fs.statSync(path.resolve(p, rest))) return path.resolve(p, rest);
251 } catch (e) { }
252 }
253 if (fs.pathExistsSync(path.resolve(os.homedir(), pathname))) return path.resolve(os.homedir(), pathname);
254 if (fs.pathExistsSync(path.resolve(os.homedir(), '.hydro', pathname))) return path.resolve(os.homedir(), '.hydro', pathname);
255 if (fs.pathExistsSync(path.resolve(os.homedir(), '.config', 'hydro', pathname))) return path.resolve(os.homedir(), '.config', 'hydro', pathname);
256 if (doThrow) throw (typeof doThrow !== 'boolean' ? doThrow : new Error(`File ${pathname} not found`));
257 return null;
258}
259
260export const htmlEncode = (str: string) => str.replace(/[&<>'"]/g,
261 (tag: string) => ({

Callers 9

template.tsFile · 0.90
loadFunction · 0.90
locateFileFunction · 0.90
setting.tsFile · 0.90
task.tsFile · 0.90
vj4.tsFile · 0.90
readYamlCasesFunction · 0.90
generateCdpZipFunction · 0.85
index.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected