-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-parse-config-host.mts
100 lines (93 loc) · 2.7 KB
/
create-parse-config-host.mts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @file createParseConfigHost
* @module tsconfig-utils/lib/createParseConfigHost
*/
import matchFiles from '#internal/match-files'
import createModuleResolutionHost from '#lib/create-module-resolution-host'
import type { ModuleId } from '@flex-development/mlly'
import type {
ModuleResolutionHost,
ParseConfigHost,
ParseConfigHostOptions
} from '@flex-development/tsconfig-utils'
/**
* Create a parse config host.
*
* @see {@linkcode ParseConfigHostOptions}
* @see {@linkcode ParseConfigHost}
*
* @this {void}
*
* @param {ParseConfigHostOptions | null | undefined} [options]
* Host options
* @return {ParseConfigHost}
* Parse config host object
*/
function createParseConfigHost(
this: void,
options?: ParseConfigHostOptions | null | undefined
): ParseConfigHost {
/**
* Module resolution host object.
*
* @const {ModuleResolutionHost} host
*/
const host: ModuleResolutionHost = createModuleResolutionHost(options)
/**
* Treat filenames as case-sensitive?
*
* @var {boolean} useCaseSensitiveFileNames
*/
let useCaseSensitiveFileNames: boolean = !!host.useCaseSensitiveFileNames
if (typeof host.useCaseSensitiveFileNames === 'function') {
useCaseSensitiveFileNames = host.useCaseSensitiveFileNames()
}
return {
directoryExists: host.directoryExists,
fileExists: host.fileExists,
getCurrentDirectory: host.getCurrentDirectory,
getDirectories: host.getDirectories,
readDirectory,
readFile: host.readFile,
realpath: host.realpath,
useCaseSensitiveFileNames
}
/**
* Get a list of files in a directory.
*
* @this {void}
*
* @param {ModuleId} id
* The directory path or URL to read
* @param {Set<string> | ReadonlyArray<string> | undefined} [extensions]
* List of file extensions to filter for
* @param {Set<string> | ReadonlyArray<string> | undefined} [exclude]
* List of glob patterns matching files to exclude
* @param {Set<string> | ReadonlyArray<string> | undefined} [include]
* List of glob patterns matching files to include
* @param {number | null | undefined} [depth]
* Maximum search depth (inclusive)
* @return {ReadonlyArray<string>}
* List of files under directory at `id`
*/
function readDirectory(
this: void,
id: ModuleId,
extensions: Set<string> | readonly string[] | undefined,
exclude: Set<string> | readonly string[] | undefined,
include: Set<string> | readonly string[] | undefined,
depth?: number | null | undefined
): readonly string[] {
return matchFiles(
host,
id,
extensions,
exclude,
include,
useCaseSensitiveFileNames,
depth,
options?.fs
)
}
}
export default createParseConfigHost