fix: relative root (by default) yields LookupError, fixes #419, #424, also related to #395

This commit is contained in:
Harttle
2021-10-27 23:55:39 +08:00
committed by Harttle
parent 564972ba74
commit aebeae9e1b
7 changed files with 67 additions and 50 deletions
+7 -1
View File
@@ -1,5 +1,5 @@
import * as _ from '../util/underscore'
import { resolve as nodeResolve, extname, dirname as nodeDirname } from 'path'
import { sep, resolve as nodeResolve, extname, dirname as nodeDirname } from 'path'
import { stat, statSync, readFile as nodeReadFile, readFileSync as nodeReadFileSync } from 'fs'
const statAsync = _.promisify(stat)
@@ -39,4 +39,10 @@ export function fallback (file: string) {
export function dirname (filepath: string) {
return nodeDirname(filepath)
}
export function contains (root: string, file: string) {
root = nodeResolve(root)
root = root.endsWith(sep) ? root : root + sep
return file.startsWith(root)
}
export { sep } from 'path'