fix: directory info in lookupError message, #395

This commit is contained in:
Harttle
2021-10-04 12:11:54 +08:00
parent 8348036d45
commit 92bfc65e0b
7 changed files with 15 additions and 9 deletions
+5 -5
View File
@@ -20,16 +20,16 @@ export class Loader {
}
public * lookup (file: string, type: LookupType, sync?: boolean) {
const { fs, root } = this.options
for (const filepath of this.candidates(file, type)) {
const { fs } = this.options
const dirs = this.options[type]
for (const filepath of this.candidates(file, dirs)) {
if (sync ? fs.existsSync(filepath) : yield fs.exists(filepath)) return filepath
}
throw this.lookupError(file, root)
throw this.lookupError(file, dirs)
}
private * candidates (file: string, type: LookupType) {
private * candidates (file: string, dirs: string[]) {
const { fs, extname } = this.options
const dirs = this.options[type]
for (const dir of dirs) {
yield fs.resolve(dir, file, extname)
}