-
-
Notifications
You must be signed in to change notification settings - Fork 23
feat(gunshi): add onResolveValue lifecycle hook to CliOptions #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
imjuni
wants to merge
6
commits into
kazupon:main
Choose a base branch
from
imjuni:feat/on-resolve-value-hook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+487
−2
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cc6dbb6
feat(gunshi): add onResolveValue lifecycle hook to CliOptions
imjuni ce8cb72
fix(gunshi): pass frozen snapshot to onResolveValue hook to prevent m…
imjuni 1d4def9
fix(gunshi): recompute validationError after onResolveValue hook
imjuni c12f651
test(gunshi): assert runner is not called when onResolveValue leaves …
imjuni 9166b33
test(gunshi): spy on onResolveValue hook to assert call count and sou…
imjuni 67dd630
test(gunshi): add type tests and nested-mutation case for onResolveVa…
imjuni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,67 @@ | ||
| /** | ||
| * @author kazuya kawaguchi (a.k.a. kazupon) | ||
| * @license MIT | ||
| */ | ||
|
|
||
| import { expectTypeOf, test } from 'vitest' | ||
| import type { Args, ArgExplicitlyProvided, ArgValues } from 'args-tokens' | ||
| import type { Awaitable, ValueResolutionSources } from './types.ts' | ||
|
|
||
| type StringArg = { type: 'string' } | ||
| type NumberArg = { type: 'number' } | ||
| type BooleanArg = { type: 'boolean' } | ||
|
|
||
| type MyArgs = Args & { | ||
| name: StringArg | ||
| port: NumberArg | ||
| debug: BooleanArg | ||
| } | ||
|
|
||
| test('ValueResolutionSources.values is typed as ArgValues<A>', () => { | ||
| type Sources = ValueResolutionSources<MyArgs> | ||
| expectTypeOf<Sources['values']>().toEqualTypeOf<ArgValues<MyArgs>>() | ||
| }) | ||
|
|
||
| test('ValueResolutionSources.explicit is typed as ArgExplicitlyProvided<A>', () => { | ||
| type Sources = ValueResolutionSources<MyArgs> | ||
| expectTypeOf<Sources['explicit']>().toEqualTypeOf<ArgExplicitlyProvided<MyArgs>>() | ||
| }) | ||
|
|
||
| test('sources.values.name resolves to string | undefined', () => { | ||
| type Sources = ValueResolutionSources<MyArgs> | ||
| expectTypeOf<Sources['values']['name']>().toEqualTypeOf<string | undefined>() | ||
| }) | ||
|
|
||
| test('sources.values.port resolves to number | undefined', () => { | ||
| type Sources = ValueResolutionSources<MyArgs> | ||
| expectTypeOf<Sources['values']['port']>().toEqualTypeOf<number | undefined>() | ||
| }) | ||
|
|
||
| test('sources.values.debug resolves to boolean | undefined', () => { | ||
| type Sources = ValueResolutionSources<MyArgs> | ||
| expectTypeOf<Sources['values']['debug']>().toEqualTypeOf<boolean | undefined>() | ||
| }) | ||
|
|
||
| test('sources.explicit flags resolve to boolean', () => { | ||
| type Sources = ValueResolutionSources<MyArgs> | ||
| expectTypeOf<Sources['explicit']['name']>().toEqualTypeOf<boolean>() | ||
| expectTypeOf<Sources['explicit']['port']>().toEqualTypeOf<boolean>() | ||
| expectTypeOf<Sources['explicit']['debug']>().toEqualTypeOf<boolean>() | ||
| }) | ||
|
|
||
| test('onResolveValue hook return type is Awaitable<ArgValues<A> | undefined>', () => { | ||
| type Hook = (sources: ValueResolutionSources<MyArgs>) => Awaitable<ArgValues<MyArgs> | undefined> | ||
| // Sync return: ArgValues<MyArgs> | ||
| expectTypeOf<ReturnType<Hook>>().toEqualTypeOf<Awaitable<ArgValues<MyArgs> | undefined>>() | ||
| }) | ||
|
|
||
| test('onResolveValue hook accepts ValueResolutionSources<A> as parameter', () => { | ||
| type Hook = (sources: ValueResolutionSources<MyArgs>) => Awaitable<ArgValues<MyArgs> | undefined> | ||
| expectTypeOf<Parameters<Hook>[0]>().toEqualTypeOf<ValueResolutionSources<MyArgs>>() | ||
|
imjuni marked this conversation as resolved.
|
||
| }) | ||
|
|
||
| test('ValueResolutionSources defaults A to Args when no type parameter given', () => { | ||
| type DefaultSources = ValueResolutionSources | ||
| expectTypeOf<DefaultSources['values']>().toEqualTypeOf<ArgValues<Args>>() | ||
| expectTypeOf<DefaultSources['explicit']>().toEqualTypeOf<ArgExplicitlyProvided<Args>>() | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.