Skip to content

Commit f7052e6

Browse files
committed
refactor(lib): [createModuleResolutionHost] implement host options
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 7704399 commit f7052e6

13 files changed

+252
-34
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ This package is fully typed with [TypeScript][].
100100

101101
- [`FileSystem`](./src/interfaces/file-system.mts)
102102
- [`LoadTsconfigOptions`](./src/interfaces/options-load-tsconfig.mts)
103+
- [`ModuleResolutionHostOptions`](./src/interfaces/options-module-resolution-host.mts)
103104
- [`ModuleResolutionHost`](./src/interfaces/host-module-resolution.mts)
105+
- [`ParseConfigHostOptions`](./src/interfaces/options-parse-config-host.mts)
104106
- [`ParseConfigHost`](./src/interfaces/host-parse-config.mts)
105107
- [`ReadTsconfigOptions`](./src/interfaces/options-read-tsconfig.mts)
106108
- [`ResolvePathOptions`](./src/interfaces/options-resolve-path.mts)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @file Type Tests - ModuleResolutionHostOptions
3+
* @module tsconfig-utils/interfaces/tests/unit-d/ModuleResolutionHostOptions
4+
*/
5+
6+
import type TestSubject from '#interfaces/options-module-resolution-host'
7+
import type { ModuleId } from '@flex-development/mlly'
8+
import type { FileSystem } from '@flex-development/tsconfig-utils'
9+
import type { Nilable } from '@flex-development/tutils'
10+
11+
describe('unit-d:interfaces/ModuleResolutionHostOptions', () => {
12+
it('should allow empty object', () => {
13+
assertType<TestSubject>({})
14+
})
15+
16+
it('should match [fs?: FileSystem | null | undefined]', () => {
17+
expectTypeOf<TestSubject>()
18+
.toHaveProperty('fs')
19+
.toEqualTypeOf<Nilable<FileSystem>>()
20+
})
21+
22+
it('should match [root?: ModuleId | null | undefined]', () => {
23+
expectTypeOf<TestSubject>()
24+
.toHaveProperty('root')
25+
.toEqualTypeOf<Nilable<ModuleId>>()
26+
})
27+
28+
it('should match [useCaseSensitiveFileNames?: ((this: void) => boolean) | boolean | null | undefined]', () => {
29+
expectTypeOf<TestSubject>()
30+
.toHaveProperty('root')
31+
.toEqualTypeOf<Nilable<ModuleId>>()
32+
})
33+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @file Type Tests - ParseConfigHostOptions
3+
* @module tsconfig-utils/interfaces/tests/unit-d/ParseConfigHostOptions
4+
*/
5+
6+
import type TestSubject from '#interfaces/options-parse-config-host'
7+
import type {
8+
ModuleResolutionHostOptions
9+
} from '@flex-development/tsconfig-utils'
10+
11+
describe('unit-d:interfaces/ParseConfigHostOptions', () => {
12+
it('should allow empty object', () => {
13+
assertType<TestSubject>({})
14+
})
15+
16+
it('should extend ModuleResolutionHostOptions', () => {
17+
expectTypeOf<TestSubject>().toMatchTypeOf<ModuleResolutionHostOptions>()
18+
})
19+
})

src/interfaces/file-system.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ interface FileSystem extends mlly.FileSystem {
4545
readdir(this: void, id: mlly.ModuleId): string[]
4646

4747
/**
48-
* Get the canonical pathname of `id`.
48+
* Get the resolved pathname of `id`.
4949
*
5050
* @see {@linkcode mlly.ModuleId}
5151
*

src/interfaces/host-module-resolution.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ interface ModuleResolutionHost {
7979
readFile(this: void, id: ModuleId): string | undefined
8080

8181
/**
82-
* Get the canonical pathname of `id`.
82+
* Get the resolved pathname of `id`.
8383
*
8484
* @see {@linkcode ModuleId}
8585
*

src/interfaces/index.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export type { default as ParseConfigHost } from '#interfaces/host-parse-config'
1111
export type {
1212
default as LoadTsconfigOptions
1313
} from '#interfaces/options-load-tsconfig'
14+
export type {
15+
default as ModuleResolutionHostOptions
16+
} from '#interfaces/options-module-resolution-host'
17+
export type {
18+
default as ParseConfigHostOptions
19+
} from '#interfaces/options-parse-config-host'
1420
export type {
1521
default as ReadTsconfigOptions
1622
} from '#interfaces/options-read-tsconfig'
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @file Interfaces - ModuleResolutionHostOptions
3+
* @module tsconfig-utils/interfaces/ModuleResolutionHostOptions
4+
*/
5+
6+
import type { ModuleId } from '@flex-development/mlly'
7+
import type { FileSystem } from '@flex-development/tsconfig-utils'
8+
9+
/**
10+
* Options for creating module resolution hosts.
11+
*/
12+
interface ModuleResolutionHostOptions {
13+
/**
14+
* File system API.
15+
*
16+
* @see {@linkcode FileSystem}
17+
*/
18+
fs?: FileSystem | null | undefined
19+
20+
/**
21+
* Module id of root directory.
22+
*
23+
* @see {@linkcode ModuleId}
24+
*
25+
* @default pathe.cwd()
26+
*/
27+
root?: ModuleId | null | undefined
28+
29+
/**
30+
* Boolean indicating filenames should be treated as case-sensitive, or a
31+
* function that returns such a value.
32+
*/
33+
useCaseSensitiveFileNames?:
34+
| ((this: void) => boolean)
35+
| boolean
36+
| null
37+
| undefined
38+
}
39+
40+
export type { ModuleResolutionHostOptions as default }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @file Interfaces - ParseConfigHostOptions
3+
* @module tsconfig-utils/interfaces/ParseConfigHostOptions
4+
*/
5+
6+
import type {
7+
ModuleResolutionHostOptions
8+
} from '@flex-development/tsconfig-utils'
9+
10+
/**
11+
* Options for creating parse config hosts.
12+
*
13+
* @see {@linkcode ModuleResolutionHostOptions}
14+
*
15+
* @extends {ModuleResolutionHostOptions}
16+
*/
17+
interface ParseConfigHostOptions extends ModuleResolutionHostOptions {}
18+
19+
export type { ParseConfigHostOptions as default }

src/internal/fs.browser.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const fs: FileSystem = {
3434
},
3535

3636
/**
37-
* Get the canonical pathname of a directory or file.
37+
* Get the resolved pathname of a directory or file.
3838
*
3939
* @return {never}
4040
* Never; not implemented

src/lib/__tests__/create-module-resolution-host.spec.mts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @module tsconfig-utils/lib/tests/unit/createModuleResolutionHost
44
*/
55

6+
import fs from '#internal/fs'
67
import testSubject from '#lib/create-module-resolution-host'
78
import * as mlly from '@flex-development/mlly'
89
import pathe from '@flex-development/pathe'
@@ -13,7 +14,11 @@ describe('unit:lib/createModuleResolutionHost', () => {
1314
let subject: ModuleResolutionHost
1415

1516
beforeAll(() => {
16-
subject = testSubject()
17+
subject = testSubject({
18+
fs,
19+
root: mlly.cwd(),
20+
useCaseSensitiveFileNames: true
21+
})
1722
})
1823

1924
describe('host', () => {

0 commit comments

Comments
 (0)