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

Add types for pino-caller #57

Merged
merged 6 commits into from
Oct 5, 2021
Merged

Add types for pino-caller #57

merged 6 commits into from
Oct 5, 2021

Conversation

halostatue
Copy link
Contributor

No description provided.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a unit test?

@mcollina
Copy link
Member

mcollina commented Oct 3, 2021

We use tsd to test our types.

@coveralls
Copy link

coveralls commented Oct 3, 2021

Coverage Status

Coverage remained the same at 100.0% when pulling 36f3ddd on halostatue:add-types-for-pino-caller into 734abb2 on pinojs:master.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@kibertoad
Copy link
Contributor

CI is failing

@halostatue
Copy link
Contributor Author

It appears that the addition of tsc and tsd have broken some tests for some versions. I ran npm run test on my local (macOS) system and have no issues with either Node 12, 14, or 16, but I don’t know enough about the Pino test setup to figure it out.

@mcollina
Copy link
Member

mcollina commented Oct 3, 2021

feel free to drop node 10.x

@kibertoad
Copy link
Contributor

@halostatue From what I'm seeing, you are missing a bunch of devDependencies with types used in tests

@kibertoad
Copy link
Contributor

yargs parser supports a minimum Node.js version of 10

Yeah, we need to drop old Node versions as well.

index.d.ts Outdated

import Pino = require('pino');

export = Caller;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please avoid using this style of export which relies on interop being enabled, and instead do the infamous triplet?

See https://github.com/pinojs/sonic-boom/blob/master/types/index.d.ts and https://github.com/pinojs/sonic-boom/blob/2150933ffb2108fd9804e99d94035f706fce00db/index.js#L400

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the "infamous triplet"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See examples linked. TS- wise this is a combination of a default and named export, index.js-wise it is a specific way to set both default and named export for single-export project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the linked examples, and I still don’t exactly see what the infamous triplet is, and my searches are failing me on this. Your comment here is the first time that I’ve ever seen that term used anywhere.

Copy link
Contributor

@kibertoad kibertoad Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I ever read about it outside of fastify ecosystem, sorry for the confusion.
You can see https://github.com/fastify/fastify-swagger/pull/282/files for a (hopefully) clear example of what that is.

The idea is to expose library in a way that is compatible with both ESM and CJS, by faking default export for cjs and having named exports for both cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it would be:

export function Caller(logger: Pino.Logger, options?: Options): Pino.Logger;
export { Caller }

?

What should the exported name be, in this case? PinoCaller instead of Caller? I’m looking at https://github.com/pinojs/pino-caller/blob/master/index.js#L27 and seeing that the function is called traceCaller and is only exported as the default.

  1. Should this change the export of the library in index.js so that there’s a pair of exports?
  2. Should I just export the default in the types file until someone wants to do the pair of exports with an “official” name.

I prefer option 2, as this change is turning out to be much larger than I had planned to do.

I’m not trying to be difficult; I based the pino-caller types on https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/pino/index.d.ts in DefinitelyTyped and opened a ticket here a courtesy. The original changes took less than an hour; I’ve already spent three times that on these changes and it would be easier for me to simply remove pino-caller as I shift to typescript than to continue with this PR.

I’m more than happy to leave the branch open, and the PR should be set so that pino-caller contributors can edit this, but I don’t have time to work on this anymore. Sorry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halostatue Thank you so much for all your efforts! They are dearly appreciated. No worries, if you are OK with me taking over the PR, I can add the finishing touches myself.

Copy link
Contributor

@kibertoad kibertoad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infamous triplet is preferable for exports.

@kibertoad kibertoad merged commit 04d5b2e into pinojs:master Oct 5, 2021
@kibertoad
Copy link
Contributor

@halostatue Aaaand done. Thank you so much for your contribution!

@halostatue
Copy link
Contributor Author

Thank you so much. Now I know what the infamous triplet is.

@halostatue halostatue deleted the add-types-for-pino-caller branch October 5, 2021 14:41
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 this pull request may close these issues.

None yet

4 participants