-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(interfaces):
ModuleResolutionHost
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
3bd4124
commit 776f17d
Showing
4 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/interfaces/__tests__/host-module-resolution.spec-d.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* @file Type Tests - ModuleResolutionHost | ||
* @module tsconfig-utils/interfaces/tests/unit-d/ModuleResolutionHost | ||
*/ | ||
|
||
import type TestSubject from '#interfaces/host-module-resolution' | ||
import type { ModuleId } from '@flex-development/mlly' | ||
import type ts from 'typescript' | ||
|
||
describe('unit-d:interfaces/ModuleResolutionHost', () => { | ||
it('should match ts.ModuleResolutionHost', () => { | ||
expectTypeOf<TestSubject>().toMatchTypeOf<ts.ModuleResolutionHost>() | ||
}) | ||
|
||
describe('directoryExists', () => { | ||
type Subject = TestSubject['directoryExists'] | ||
|
||
it('should match [this: void]', () => { | ||
expectTypeOf<Subject>().thisParameter.toEqualTypeOf<void>() | ||
}) | ||
|
||
describe('parameters', () => { | ||
it('should be callable with [ModuleId]', () => { | ||
expectTypeOf<Subject>().parameters.toEqualTypeOf<[ModuleId]>() | ||
}) | ||
}) | ||
|
||
describe('returns', () => { | ||
it('should return boolean', () => { | ||
expectTypeOf<Subject>().returns.toEqualTypeOf<boolean>() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('fileExists', () => { | ||
type Subject = TestSubject['fileExists'] | ||
|
||
it('should match [this: void]', () => { | ||
expectTypeOf<Subject>().thisParameter.toEqualTypeOf<void>() | ||
}) | ||
|
||
describe('parameters', () => { | ||
it('should be callable with [ModuleId]', () => { | ||
expectTypeOf<Subject>().parameters.toEqualTypeOf<[ModuleId]>() | ||
}) | ||
}) | ||
|
||
describe('returns', () => { | ||
it('should return boolean', () => { | ||
expectTypeOf<Subject>().returns.toEqualTypeOf<boolean>() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('getDirectories', () => { | ||
type Subject = TestSubject['getDirectories'] | ||
|
||
it('should match [this: void]', () => { | ||
expectTypeOf<Subject>().thisParameter.toEqualTypeOf<void>() | ||
}) | ||
|
||
describe('parameters', () => { | ||
it('should be callable with [ModuleId]', () => { | ||
expectTypeOf<Subject>().parameters.toEqualTypeOf<[ModuleId]>() | ||
}) | ||
}) | ||
|
||
describe('returns', () => { | ||
it('should return string[]', () => { | ||
expectTypeOf<Subject>().returns.toEqualTypeOf<string[]>() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('readFile', () => { | ||
type Subject = TestSubject['readFile'] | ||
|
||
it('should match [this: void]', () => { | ||
expectTypeOf<Subject>().thisParameter.toEqualTypeOf<void>() | ||
}) | ||
|
||
describe('parameters', () => { | ||
it('should be callable with [ModuleId]', () => { | ||
expectTypeOf<Subject>().parameters.toEqualTypeOf<[ModuleId]>() | ||
}) | ||
}) | ||
|
||
describe('returns', () => { | ||
it('should return string | undefined', () => { | ||
expectTypeOf<Subject>().returns.toEqualTypeOf<string | undefined>() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('realpath', () => { | ||
type Subject = TestSubject['realpath'] | ||
|
||
it('should match [this: void]', () => { | ||
expectTypeOf<Subject>().thisParameter.toEqualTypeOf<void>() | ||
}) | ||
|
||
describe('parameters', () => { | ||
it('should be callable with [ModuleId]', () => { | ||
expectTypeOf<Subject>().parameters.toEqualTypeOf<[ModuleId]>() | ||
}) | ||
}) | ||
|
||
describe('returns', () => { | ||
it('should return string', () => { | ||
expectTypeOf<Subject>().returns.toEqualTypeOf<string>() | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* @file Interfaces - ModuleResolutionHost | ||
* @module tsconfig-utils/interfaces/ModuleResolutionHost | ||
*/ | ||
|
||
import type { ModuleId } from '@flex-development/mlly' | ||
|
||
/** | ||
* Module resolution host API. | ||
* | ||
* The module resolution host acts a bridge between the TypeScript compiler and | ||
* the file system. | ||
*/ | ||
interface ModuleResolutionHost { | ||
/** | ||
* Check if a directory exists at `id`. | ||
* | ||
* @see {@linkcode ModuleId} | ||
* | ||
* @this {void} | ||
* | ||
* @param {ModuleId} id | ||
* The module id to check | ||
* @return {boolean} | ||
* `true` if directory exists at `id`, `false` otherwise | ||
*/ | ||
directoryExists(this: void, id: ModuleId): boolean | ||
|
||
/** | ||
* Check if a file exists at `id`. | ||
* | ||
* @see {@linkcode ModuleId} | ||
* | ||
* @this {void} | ||
* | ||
* @param {ModuleId} id | ||
* The module id to check | ||
* @return {boolean} | ||
* `true` if file exists at `id`, `false` otherwise | ||
*/ | ||
fileExists(this: void, id: ModuleId): boolean | ||
|
||
/** | ||
* Get the path to current working directory. | ||
* | ||
* @this {void} | ||
* | ||
* @return {string} | ||
* Path to current working directory | ||
*/ | ||
getCurrentDirectory(this: void): string | ||
|
||
/** | ||
* Get a list of subdirectories. | ||
* | ||
* @see {@linkcode ModuleId} | ||
* | ||
* @this {void} | ||
* | ||
* @param {ModuleId} id | ||
* The directory path or URL to read | ||
* @return {string[]} | ||
* List of subdirectory names | ||
*/ | ||
getDirectories(this: void, id: ModuleId): string[] | ||
|
||
/** | ||
* Get the contents of a file. | ||
* | ||
* @see {@linkcode ModuleId} | ||
* | ||
* @this {void} | ||
* | ||
* @param {ModuleId} id | ||
* Module id of file | ||
* @return {Buffer | string} | ||
* File contents or `undefined` if file does not exist at `id` | ||
*/ | ||
readFile(this: void, id: ModuleId): string | undefined | ||
|
||
/** | ||
* Get the resolved pathname for `id`. | ||
* | ||
* @see {@linkcode ModuleId} | ||
* | ||
* @this {void} | ||
* | ||
* @param {ModuleId} id | ||
* The path or `file:` URL to handle | ||
* @return {string} | ||
* Resolved pathname | ||
*/ | ||
realpath(this: void, id: ModuleId): string | ||
|
||
/** | ||
* Treat filenames as case-sensitive? | ||
*/ | ||
useCaseSensitiveFileNames?: ((this: void) => boolean) | boolean | undefined | ||
} | ||
|
||
export type { ModuleResolutionHost as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters