-
-
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
Move JSON rendering from badge-maker to server [*****] #4980
Conversation
|
Failures seem unrelated, except that one triggered an error in an untested code path in the request handler, which I fixed in 0a68459. |
I'll have a look at this one over the weekend |
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's some sensible stuff going on here e.g: moving some of the normalize/default logic out of make-badge.makeBadge()
into _clean
and using more consistent terminology in the input params for make-badge.makeBadge()
.
Having seen the implementation: If you consider that the near-future goal is that we generate our own (SVG) badges via index.makeBadge()
(and hence everything will go through _validate()
and _clean()
implicitly), do you reckon exporting an undocumented function is worse than exposing an undocumented format="json"
param or depending on a relative import for the purpose of json output?
They all represent a sort of "backdoor", or a way in which we're not going to eat our own dogfood, so if we're going to do one of those things we might as well pick the one that requires us to do the least acrobatics elsewhere in the codebase achieve it, if you see what I mean.
delete cleaned.style | ||
} | ||
// Whitespace removal. | ||
cleaned.label = `${cleaned.label}`.trim() |
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.
For a message only badge, running
cleaned.label = `${cleaned.label}`.trim()
would result in the label property being the string literal "undefined"
. This is not what we want.
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.
Indeed. I'll fix this up tomorrow.
The server needs to access the normalization capability, though not the validation code, of the badge maker, separately from invoking I suspect we should export a public Maybe this function should assume the data is valid, or maybe it should validate it, not sure. I haven't thought carefully about what is validation vs. what is normalization. We could tackle that now, or defer it to a follow-on. Deferring might be the thing to do since we want to release 3.0.0… if it's private and undocumented, then we can make it public in 3.1.0. Thoughts? |
If the objective is to move Once we do #4947 #4949 and #4950 the code in const { makeBadge } = require('badge-maker')
//...
makeBadge(badgeData) ..at which point everything for the SVG request is getting processed by In principle, I agree that not exposing makeBadge({...badgeData, format='json'}) instead of doing the whole |
Having thought about this a while, I feel like it's pretty fine for the package to have non-secret |
I've picked a couple bits of this out. I'm thinking I'll close it for now, and wait to address the rest when we're ready to dogfood our own package. |
makeBadge()
into a_clean()
function which is privately exported by badge-maker. It's necessary that the server can access this functionality to do the JSON rendering. (Alternatively we could remove the underscore to make this part of the public API. However this may not be necessary, as I think it will only be needed for Shields.)coalesceBadge()
more in line with the badge-maker public schema.Closes #4948