[PR #656] [MERGED] feat(font): replace generated google font catalog with virtual import rewrites #748

Closed
opened 2026-05-06 13:09:55 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/656
Author: @southpolesteve
Created: 3/22/2026
Status: Merged
Merged: 3/22/2026
Merged by: @southpolesteve

Base: mainHead: codex/font-google-transform-pr


📝 Commits (1)

  • 7fa91cb feat(font): rewrite next/font/google imports via virtual modules

📊 Changes

8 files changed (+473 additions, -2375 deletions)

View changed files

📝 packages/vinext/src/index.ts (+338 -42)
📝 packages/vinext/src/shims/font-google-base.ts (+4 -3)
packages/vinext/src/shims/font-google.generated.ts (+0 -2251)
📝 packages/vinext/src/shims/font-google.ts (+1 -1)
📝 packages/vinext/src/shims/next-shims-font-google.generated.d.ts (+1 -0)
📝 scripts/generate-google-fonts.js (+1 -17)
📝 tests/font-google.test.ts (+116 -56)
📝 tests/shims.test.ts (+12 -5)

📄 Description

Summary

Closes #200.

This reworks the core idea from #262 by @yunus25jmi1, but switches the implementation to per-import virtual modules instead of local const rewrites.

That keeps the maintenance win of deleting the generated font-google.generated.ts catalog, while preserving normal ESM semantics for named imports and broadening compatibility for real-world call sites.

What Changed

  • delete packages/vinext/src/shims/font-google.generated.ts
  • rewrite named next/font/google imports and re-exports to virtual modules that export only the requested fonts
  • keep createFontLoader as a public shim export for direct runtime use and tests
  • continue self-hosting in build mode, now with support for aliased lowercase locals and proxy member calls like fonts.Roboto_Mono(...)
  • transform dependency files that import next/font/google, not just app source files
  • keep the generated .d.ts for IDE autocomplete and types

Why This Shape

The earlier approach in #262 had a good goal, but converting imports into local const declarations changed module evaluation semantics and dropped compatibility for some import patterns.

Using virtual modules avoids the TDZ/hoisting regression for named imports while still removing the giant generated runtime catalog.

Testing

  • vp test run tests/font-google.test.ts
  • vp test run tests/shims.test.ts -t "next/font/google shim"
  • vp check packages/vinext/src/index.ts packages/vinext/src/shims/font-google.ts packages/vinext/src/shims/font-google-base.ts packages/vinext/src/shims/next-shims-font-google.generated.d.ts scripts/generate-google-fonts.js tests/font-google.test.ts tests/shims.test.ts

Credit

Credit to @yunus25jmi1 for the original PR and direction in #262: https://github.com/cloudflare/vinext/pull/262


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/656 **Author:** [@southpolesteve](https://github.com/southpolesteve) **Created:** 3/22/2026 **Status:** ✅ Merged **Merged:** 3/22/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `codex/font-google-transform-pr` --- ### 📝 Commits (1) - [`7fa91cb`](https://github.com/cloudflare/vinext/commit/7fa91cb10092e00b1b365ed71a520c0bc1c8ab42) feat(font): rewrite next/font/google imports via virtual modules ### 📊 Changes **8 files changed** (+473 additions, -2375 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+338 -42) 📝 `packages/vinext/src/shims/font-google-base.ts` (+4 -3) ➖ `packages/vinext/src/shims/font-google.generated.ts` (+0 -2251) 📝 `packages/vinext/src/shims/font-google.ts` (+1 -1) 📝 `packages/vinext/src/shims/next-shims-font-google.generated.d.ts` (+1 -0) 📝 `scripts/generate-google-fonts.js` (+1 -17) 📝 `tests/font-google.test.ts` (+116 -56) 📝 `tests/shims.test.ts` (+12 -5) </details> ### 📄 Description ## Summary Closes #200. This reworks the core idea from #262 by @yunus25jmi1, but switches the implementation to per-import virtual modules instead of local `const` rewrites. That keeps the maintenance win of deleting the generated `font-google.generated.ts` catalog, while preserving normal ESM semantics for named imports and broadening compatibility for real-world call sites. ## What Changed - delete `packages/vinext/src/shims/font-google.generated.ts` - rewrite named `next/font/google` imports and re-exports to virtual modules that export only the requested fonts - keep `createFontLoader` as a public shim export for direct runtime use and tests - continue self-hosting in build mode, now with support for aliased lowercase locals and proxy member calls like `fonts.Roboto_Mono(...)` - transform dependency files that import `next/font/google`, not just app source files - keep the generated `.d.ts` for IDE autocomplete and types ## Why This Shape The earlier approach in #262 had a good goal, but converting imports into local `const` declarations changed module evaluation semantics and dropped compatibility for some import patterns. Using virtual modules avoids the TDZ/hoisting regression for named imports while still removing the giant generated runtime catalog. ## Testing - `vp test run tests/font-google.test.ts` - `vp test run tests/shims.test.ts -t "next/font/google shim"` - `vp check packages/vinext/src/index.ts packages/vinext/src/shims/font-google.ts packages/vinext/src/shims/font-google-base.ts packages/vinext/src/shims/next-shims-font-google.generated.d.ts scripts/generate-google-fonts.js tests/font-google.test.ts tests/shims.test.ts` ## Credit Credit to @yunus25jmi1 for the original PR and direction in #262: https://github.com/cloudflare/vinext/pull/262 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:55 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#748
No description provided.