(pathname: string, doThrow: boolean | Error = true)
| 234 | } |
| 235 | |
| 236 | export 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 | |
| 260 | export const htmlEncode = (str: string) => str.replace(/[&<>'"]/g, |
| 261 | (tag: string) => ({ |
no outgoing calls
no test coverage detected