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

prepare, complete events access to configuration output object #161

Closed
Lordfirespeed opened this issue Jun 3, 2024 · 3 comments · Fixed by #181
Closed

prepare, complete events access to configuration output object #161

Lordfirespeed opened this issue Jun 3, 2024 · 3 comments · Fixed by #181

Comments

@Lordfirespeed
Copy link

Title.

I'd like to add some additional code-generation to my Velite setup, but finding it rather tricky to get the output object without hacky workarounds.

@zce
Copy link
Owner

zce commented Jun 3, 2024

Sorry, I didn't understand your specific intent. Could you provide the code snippets to help me understand your requirements better?

@zce
Copy link
Owner

zce commented Jun 27, 2024

ping @Lordfirespeed

@Lordfirespeed
Copy link
Author

Lordfirespeed commented Jun 27, 2024

Sorry, thankyou for the ping.

My particular use-case was that I wanted to write files to the .velite directory, but I didn't want to hard-code the .velite directory name. I wanted access to this object of the resolved configuration, from the prepare (invoked here) and complete (invoked here) hooks.

Changing the signatures of the prepare and complete hooks to include a config parameter, then passing in the resolved config would suffice:

prepare?: (data: Result<T>, config: Config) => Promisable<void | false>
complete?: (data: Result<T>, config: Config) => Promisable<void>
Here's a TypeScript snippet showing this change would be backwards-compatible.
type Promisable<T> = T | Promise<T>

type Result<T> = {
  foo: T
}

type Config = {
  bar: string
  baz: number
}

type Test<T> = (data: Result<T>, config: Config) => Promisable<void | false>

const testInstance: Test<unknown> = async (data: Result<unknown>) => undefined;

zce added a commit that referenced this issue Jul 8, 2024
@zce zce closed this as completed in #181 Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants