Skip to content
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

refactor(libui)!: require renderForm streams to be specified #4589

Merged
merged 2 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .yarn/versions/27f02004.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
releases:
"@yarnpkg/libui": major

declined:
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-version"
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The following changes only affect people writing Yarn plugins:

- The `getCustomDataKey` function in `Installer` from `@yarnpkg/core` has been moved to `Linker`.

- `renderForm`'s `options` argument is now required to enforce that custom streams are always specified.

### Compatibility

- The patched filesystem now supports `ftruncate`.
Expand Down
9 changes: 4 additions & 5 deletions packages/yarnpkg-libui/sources/misc/renderForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ type InferProps<T extends React.ComponentType> = T extends React.ComponentType<i

export type SubmitInjectedComponent<T, C extends React.ComponentType = React.ComponentType> = React.ComponentType<InferProps<C> & { useSubmit: (value: T) => void }>;

// TODO: make the streams required in the next major so that people don't forget to pass them
export type RenderFormOptions = {
stdin?: Readable;
stdout?: Writable;
stderr?: Writable;
stdin: Readable;
stdout: Writable;
stderr: Writable;
};

export async function renderForm<T, C extends React.ComponentType = React.ComponentType>(UserComponent: SubmitInjectedComponent<T, C>, props: InferProps<C>, {stdin, stdout, stderr}: RenderFormOptions = {}) {
export async function renderForm<T, C extends React.ComponentType = React.ComponentType>(UserComponent: SubmitInjectedComponent<T, C>, props: InferProps<C>, {stdin, stdout, stderr}: RenderFormOptions) {
let returnedValue: T | undefined;

const useSubmit = (value: T) => {
Expand Down