Skip to content

How to create a custom Plugin #1009

Answered by isaacs
Tarrask asked this question in Q&A
Mar 7, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

In order to preserve the behavior of tap working with both ESM and CommonJS, all plugins have to be able to be loaded with both require and import.

You don't have to publish it to npm, but it does have to be a thing in node_modules with the exports set up properly. tshy is an easy way to do this, plus if you write it in TS then the plugin type signatures will be preserved in the built Test class.

Whatever is the type provided to the TapPlugin<T> parameter has to be what the plugin function returns. It can be void or string or whatever, but has to match. You can also just let TS infer the parameter and not provide it, so this would work:

import { TapPlugin } from '@tapjs/core'
export const p…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Tarrask
Comment options

Answer selected by Tarrask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants