-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
fix(types): correct CommonJS export in @fastify/otel typings #30
base: main
Are you sure you want to change the base?
Conversation
The typescript typings were exporting using the ESM style exports, but this is a CJS module, so the exports were not resolving correctly. This switches the type export to use `export = ` syntax instead which works for ESM consumers as well as CJS consumers. Fixes fastify#24 Signed-off-by: Bret Comnes <[email protected]>
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.
can you add some tests for it? Check test/index.test-d.ts
@@ -16,5 +16,4 @@ declare class FastifyOtelInstrumentation<Config extends FastifyOtelInstrumentati | |||
plugin (): (instance: FastifyInstance, opts: FastifyOtelOptions, done: (err?: Error) => void) => void | |||
} | |||
|
|||
export default FastifyOtelInstrumentation | |||
export { FastifyOtelInstrumentation } | |||
export = FastifyOtelInstrumentation |
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.
Good spot!
Is this enough? Should we export the default as other plugins do?
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 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add some tests using eg tsd?
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.
Yes
Yes, I will add some when I find time on an evening. Anyone feel free to beat me to it. |
@@ -16,5 +16,4 @@ declare class FastifyOtelInstrumentation<Config extends FastifyOtelInstrumentati | |||
plugin (): (instance: FastifyInstance, opts: FastifyOtelOptions, done: (err?: Error) => void) => void | |||
} | |||
|
|||
export default FastifyOtelInstrumentation | |||
export { FastifyOtelInstrumentation } |
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:
Line 410 in 1f850f6
module.exports = FastifyOtelInstrumentation |
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?
The typescript typings were exporting using the ESM style exports, but this is a CJS module, so the exports were not resolving correctly. This switches the type export to use
export =
syntax instead which works for ESM consumers as well as CJS consumers.Fixes #24
Checklist
npm run test
andnpm run benchmark
documentation is changed or addedand the Code of conduct