-
-
Notifications
You must be signed in to change notification settings - Fork 19
fix(types): correct CommonJS export in @fastify/otel typings #30
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,19 +24,19 @@ type FastifyError = any | |
|
|
||
| type HookHandlerDoneFunction = <TError extends Error = FastifyError>(err?: TError) => void | ||
|
|
||
| export type FastifyPlugin = ( | ||
| type FastifyPlugin = ( | ||
| instance: FastifyInstance, | ||
| opts: any, | ||
| done: HookHandlerDoneFunction, | ||
| ) => unknown | Promise<unknown> | ||
|
|
||
| export interface FastifyOtelOptions {} | ||
| export interface FastifyOtelInstrumentationOpts extends InstrumentationConfig { | ||
| interface FastifyOtelOptions {} | ||
| interface FastifyOtelInstrumentationOpts extends InstrumentationConfig { | ||
| servername?: string | ||
| registerOnInitialization?: boolean | ||
| } | ||
|
|
||
| export interface FastifyInstance { | ||
| interface FastifyInstance { | ||
| version: string; | ||
| register: (plugin: any) => FastifyInstance; | ||
| after: (listener?: (err: Error) => void) => FastifyInstance; | ||
|
|
@@ -49,11 +49,21 @@ export interface FastifyInstance { | |
| } | ||
|
|
||
| declare class FastifyOtelInstrumentation<Config extends FastifyOtelInstrumentationOpts = FastifyOtelInstrumentationOpts> extends InstrumentationBase<Config> { | ||
| static FastifyInstrumentation: FastifyOtelInstrumentation | ||
| static FastifyInstrumentation: typeof FastifyOtelInstrumentation | ||
| constructor (config?: FastifyOtelInstrumentationOpts) | ||
| init (): InstrumentationNodeModuleDefinition[] | ||
| plugin (): FastifyPlugin | ||
| } | ||
|
|
||
| export default FastifyOtelInstrumentation | ||
| export { FastifyOtelInstrumentation } | ||
| // Declare the CommonJS export object | ||
| declare namespace FastifyOtelInstrumentation { | ||
| export { | ||
| FastifyOtelInstrumentation, | ||
| FastifyOtelInstrumentationOpts, | ||
| FastifyOtelOptions, | ||
| FastifyPlugin, | ||
| FastifyInstance | ||
| } | ||
| } | ||
|
|
||
| export = FastifyOtelInstrumentation | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good spot! Is this enough? Should we export the default as other plugins do?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't recall spotting other issues on other plugins, but also I import them into register in an fp so maybe I missed the issues. If it's an issue here, then it's also presumably an issue elsewhere. There might be other places where this is addressed, would need to investigate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add some tests using eg tsd?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mucked around with the tests, and I simply am not familiar enough with TSD or CJS/ESM nuance tests to know how to actually test for this. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no attempt at named exports afaict:
otel/index.js
Line 410 in 1f850f6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bcomnes can you add the named export support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added named exports and a default export.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible to support named mjs exports correctly when assigning module.exports like this. MJS resolves this as { default, and 'module.exports' }.