-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathreader.ts
More file actions
49 lines (36 loc) · 1.32 KB
/
reader.ts
File metadata and controls
49 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import * as path from 'node:path';
import * as fsStat from '@nodelib/fs.stat';
import * as utils from '../utils';
import type Settings from '../settings';
import type { Entry, ErrnoException, FsStats, Pattern, ReaderOptions } from '../types';
export abstract class Reader<T> {
protected readonly _fsStatSettings: fsStat.Settings;
readonly #settings: Settings;
constructor(settings: Settings) {
this.#settings = settings;
this._fsStatSettings = new fsStat.Settings({
followSymbolicLink: settings.followSymbolicLinks,
fs: settings.fs,
throwErrorOnBrokenSymbolicLink: settings.throwErrorOnBrokenSymbolicLink,
});
}
public abstract dynamic(root: string, options: ReaderOptions): T;
public abstract static(patterns: Pattern[], options: ReaderOptions): T;
protected _getFullEntryPath(filepath: string): string {
return path.resolve(this.#settings.cwd, filepath);
}
protected _makeEntry(stats: FsStats, pattern: Pattern): Entry {
const entry: Entry = {
name: pattern,
path: pattern,
dirent: utils.fs.createDirentFromStats(pattern, stats),
};
if (this.#settings.stats) {
entry.stats = stats;
}
return entry;
}
protected _isFatalError(error: ErrnoException): boolean {
return !utils.errno.isEnoentCodeError(error) && !utils.errno.isEnotdirCodeError(error) && !this.#settings.suppressErrors;
}
}