Skip to content

Conversation

@florian-lefebvre
Copy link
Collaborator

@florian-lefebvre florian-lefebvre commented Nov 17, 2025

unifont was extracted from @nuxt/fonts and inherited some of its APIs. I personally think it is too opinionated, from my experience using it in Astro.

I am aware this a breaking change but unifont is still in v0 so if downstream projects consume this package with ~ range, all should be fine.

This PR suggests a simpler API that still allows downstream consumers to replicate the previous behavior using the new unifont.providers API:

const unifont = await createUnifont([providers.google(), providers.fontsource()])

-const { fonts } = await unifont.resolveFont('Poppins')
+const fonts = []
+for (const provider of unifont.providers) {
+	const result = await unifont.resolveFont({ fontFamily: 'Poppins', provider })
+	if (result.fonts.length >= 0) {
+		fonts.push(...result.fonts)
+		break
+	}
+}

Changes are documented in the README

@florian-lefebvre florian-lefebvre self-assigned this Nov 17, 2025
@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.90%. Comparing base (207a1a2) to head (af01c6f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #287      +/-   ##
==========================================
- Coverage   98.91%   98.90%   -0.01%     
==========================================
  Files          11       11              
  Lines         460      457       -3     
  Branches      113      111       -2     
==========================================
- Hits          455      452       -3     
  Misses          5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@florian-lefebvre florian-lefebvre marked this pull request as ready for review November 17, 2025 16:09
@danielroe
Copy link
Member

could you help me understand what you think is too opinionated here?

are you thinking of a non serial strategy?

@florian-lefebvre
Copy link
Collaborator Author

For me, unifont's purpose is to initialize all providers then be able to retrieve fonts data from them through a unified API. The opinionated bit I'd like to get rid of is the fact that you can a given method for all providers at once, that's something I don't do in Astro.

I think it's simpler and gives more control to users if they can call eg. resolveFont for one provider, and decide themsleves if they want to loop over all providers, or a subset etc.

Happy to discuss the API, maybe it can be updated but really the point of this PR is to remove the loop in each unifont method

@danielroe
Copy link
Member

understood. what about an optional second argument which is a provider name?

without it, it searches all providers?

@florian-lefebvre
Copy link
Collaborator Author

This is the current API with providers as the 3rd argument isn't it? To be clear I know what I'm proposing in this PR is not required per say, it's possible to scope to one provider already. I guess the main argument against it is backward compat but since we're in v0 and with very few dependent packages, I thought that could be fine

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.

3 participants