fix: hardcoded '/' in normalized options.fs, fixes #412, #408

Changes including:
- will not call fs.resolve when normalizing `fs`
- removed hardcoded `/`
- mandatory `fs.dirname` for relative reference
- mandatory `fs.sep`, defaults to '/'
This commit is contained in:
Harttle
2021-10-16 12:10:55 +08:00
committed by harttle
parent df6d62fd59
commit 9cfa43b8ae
17 changed files with 124 additions and 54 deletions
+14 -2
View File
@@ -1,8 +1,20 @@
import { LoaderOptions } from './loader'
export interface FS {
/** check if a file exists asynchronously */
exists: (filepath: string) => Promise<boolean>;
readFile: (filepath: string) => Promise<string>;
/** check if a file exists synchronously */
existsSync: (filepath: string) => boolean;
/** read a file asynchronously */
readFile: (filepath: string) => Promise<string>;
/** read a file synchronously */
readFileSync: (filepath: string) => string;
resolve: (root: string, file: string, ext: string) => string;
/** resolve a file against directory, for given `ext` option */
resolve: (dir: string, file: string, ext: string, options?: LoaderOptions) => string;
/** defaults to "/", will be used for "within roots" check */
sep?: string;
/** dirname for a filepath, used when resolving relative path */
dirname?: (file: string) => string;
/** fallback file for lookup failure */
fallback?: (file: string) => string | undefined;
}