-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Give the NPM package some love #2200
Conversation
we need this for publishing because npm will run the postinstall script after we install
Generated by 🚫 dangerJS |
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.
Looks good to me. I agree that we should hide PDFKitTextMeasurer
and QuickTextMeasurer
from the public interface. 👍
OK - cheers. Given this is the only outstanding thing and will change the public interface and docs, lets tack that on to this PR. Do you have a feel for whether it is sensible for the default (or possibly only) measurer to be Any thoughts? |
After looking into this some more, as far as I can tell, these are both custom classes that we've written in text-measurer.js. The CLI targets one-off generations, therefore it doesn't make sense to add the caching capabilities, it would only slow things down. If users use this as part of a Node module, they may or may not benefit from having caching depending on their use-case. However I think that they are most likely to write something that will call |
Aah yes I see you've used the classic "work out what's going on by actually reading the code" technique - cunning :) My initial thought on this was that we should probably decouple the LRU cache from the badge generation (which would imply just using
Where possible I prefer the boolean condition to be positive. i.e: I'll update this tomorrow. Cheers. |
How does this feel as a new public surface for the package? |
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.
The public interface is clean and simple, I like it. 👍
badge(format, (svg, err) => { | ||
// svg is a string containing your badge | ||
})}) | ||
const svg = bf.create(format) |
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.
So this is sync now?
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.
Yep. As noted in #1388 (comment) its now synchronous
Using |
lib/gh-badges.js
Outdated
const { PDFKitTextMeasurer, QuickTextMeasurer } = require('./text-measurer') | ||
|
||
class BadgeFactory { | ||
constructor({ fontPath, fallbackFontPath, cache = true }) { |
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.
QuickTextMeasurer
doesn't cache as much as it memoizes the most common inputs. Something like precomputeWidths
would be more accurate.
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.
Changed. Do you think this should default to true
or false
?
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.
false
, since I’d wager the most common use will be generating a single badge.
* @param {string} format.colorB | ||
* @param {string} format.format | ||
* @param {string} format.template | ||
* @return {string} Badge in SVG or JSON format |
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'd love to switch this over to the schema we're using for new-style services, though that could definitely happen another day.
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.
The DocBlock is helpful, because it allows editors/IDEs to show inline help, but we could definitely improve the validation. Lets save that for a minor release though
Following on from the discussion in #1388 I've done a bit of work to whip the NPM package into shape so we can do a
2.0.0-beta1
release. There is one additional issue I think we should consider before publishing a 2.0.0 release:Is it useful to force the user to make a choice of text measurer in order to generate a badge? Would it be better to be opinionated on this and provide a simpler public interface using either
PDFKitTextMeasurer
orQuickTextMeasurer
(at least as a default)? As a point of reference, the CLI usesPDFKitTextMeasurer
only.