Skip to content

Commit

Permalink
feat(hooks): ResolveHookResult
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Mar 4, 2023
1 parent 9e1fbd8 commit 2bde439
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/hooks/__tests__/resolve-result.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @file Type Tests - ResolveHookResult
* @module esm-types/hooks/tests/unit-d/ResolveHookResult
*/

import type { Format } from '#src/enums'
import type { ResolvedModuleUrl } from '#src/types'
import type { Nilable } from '@flex-development/tutils'
import type TestSubject from '../resolve-result'

describe('unit-d:hooks/ResolveHookResult', () => {
it('should match [format?: Nilable<Format>]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('format')
.toEqualTypeOf<Nilable<Format>>()
})

it('should match [shortCircuit?: boolean | undefined]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('shortCircuit')
.toEqualTypeOf<boolean | undefined>()
})

it('should match [url: ResolvedModuleUrl]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('url')
.toEqualTypeOf<ResolvedModuleUrl>()
})
})
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export type { default as GetSourceHookContext } from './get-source-context'
export type { default as GlobalPreloadHook } from './global-preload'
export type { default as GlobalPreloadHookContext } from './global-preload-context'
export type { default as ResolveHookContext } from './resolve-context'
export type { default as ResolveHookResult } from './resolve-result'
export type { default as SourceHookResult } from './source-result'
42 changes: 42 additions & 0 deletions src/hooks/resolve-result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file Hooks - ResolveHookResult
* @module esm-types/hooks/ResolveHookResult
*/

import type { Format } from '#src/enums'
import type { ResolvedModuleUrl } from '#src/types'
import type { Nilable } from '@flex-development/tutils'

/**
* [`resolve`][1] hook result.
*
* [1]: https://nodejs.org/api/esm.html#resolvespecifier-context-nextresolve
*/
interface ResolveHookResult {
/**
* Module format hint for [`load`][1] hook.
*
* **Note**: Hint may be ignored.
*
* [1]: https://nodejs.org/api/esm.html#loadurl-context-nextload
*
* @see {@linkcode Format}
*/
format?: Nilable<Format>

/**
* Signal that the current hook terminates the chain of `resolve` hooks.
*
* @default false
*/
shortCircuit?: boolean | undefined

/**
* Resolved module URL.
*
* @see {@linkcode ResolvedModuleUrl}
*/
url: ResolvedModuleUrl
}

export type { ResolveHookResult as default }

0 comments on commit 2bde439

Please sign in to comment.