-
Notifications
You must be signed in to change notification settings - Fork 484
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
Feat: loadFromUrl supports Node.js environment #503
Feat: loadFromUrl supports Node.js environment #503
Conversation
I just made a PR on the fork to add a test for this. Edit: at some point we might want to switch over to fetch completely, but I'm fine with fixing it like that for now, as Node 16 (LTS) has just reached EOL about 3 months ago. Browser-wise, all evergreen browsers support fetch now, and I'm not 100% sure, but I guess this should be polyfilled for older browsers during build anyway. @ILOVEPIE maybe we need some kind of roadmap to keep track of things like this? |
@Connum we should get this reviewed and merged, once the tests are in. |
Alternatively, instead of waiting for @antoineol, we could merge this PR and add the test with a separate PR. |
@Connum I think it's bests to keep tests in the same PR. I'm not too fond of the idea of committing something to master without testing it. |
Pinging @antoineol If we don't hear back, we should make a new PR from this PR merged with the test I added |
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 finally managed to merge the test myself with the help of gh CLI.
Just adapted the test because it didn't pass anymore due to the changes in the names object |
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.
We should avoid redundant checks in the code.
# Conflicts: # dist/opentype.js # dist/opentype.js.map # dist/opentype.module.js # dist/opentype.module.js.map
added |
Description
This solution provides a node implementation to fetch the font file from the URL, using standard http/https modules (to avoid adding a dependency like axios).
Btw the typing of
load()
does not include the third parameter that allows to useloadFromUrl
. I don't know who is maintaining it.Motivation and Context
loadFromUrl assumes it is run in the browser environment only, but I needed it in Node.js environment. I tried to polyfill XHR2, but the polyfill seems to have a bug: something hangs for 120 seconds. So I provide a nodejs implementation here.
How Has This Been Tested?
The function loadFromUrl was tested with code like:
And I tested a larger workflow with something like
load(url, undefined, { isUrl: true })
, ensuring it returns the font with the data I expected.Environment: node. No impact noticed on the rest of the library. All unit tests are still passing (with just 2 warnings that were already there).
Screenshots (if appropriate):
N/A
Types of changes
Counted as new feature, but I'm tempted to say it's a bug, since it uses the existing API in node, which is supposed to be a supported environment. :)
Checklist:
npm run test
and all tests passed green (including code styling checks). => 2 warnings for code styling that were already there when I forked the master.