Skip to content

Add baseURL support for fontface assets#1275

Merged
obiot merged 2 commits intomasterfrom
fix/fontface-baseurl
Mar 19, 2026
Merged

Add baseURL support for fontface assets#1275
obiot merged 2 commits intomasterfrom
fix/fontface-baseurl

Conversation

@obiot
Copy link
Member

@obiot obiot commented Mar 19, 2026

Summary

  • Fontface assets now support baseURL, resolving font paths consistently with all other asset types (image, audio, json, etc.)
  • The loader strips any url() wrapper before prepending baseURL, so both font/foo.woff2 and url(font/foo.woff2) work correctly
  • Updated example and jsdoc to use plain paths instead of url() wrappers

Test plan

  • Existing loader tests pass
  • New test verifies fontface is included in wildcard setBaseURL("*")
  • New test verifies url() stripping before baseURL is applied
  • Verify UI example loads font correctly in browser

🤖 Generated with Claude Code

Fontface assets were the only asset type not benefiting from baseURL,
making font path resolution inconsistent with images, audio, etc.
The loader now strips any url() wrapper before prepending baseURL,
so both plain paths and url()-wrapped paths work correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 19, 2026 02:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds baseURL support for fontface assets so font paths resolve consistently with other loader asset types, and updates examples/docs accordingly.

Changes:

  • Include fontface in wildcard setBaseURL("*", ...) configuration.
  • Strip a url(...) wrapper from fontface src before applying baseURL.
  • Update JSDoc/examples/changelog and add tests for the new behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/melonjs/src/loader/loader.js Adds fontface to wildcard baseURL and strips url(...) before baseURL concatenation in load()
packages/melonjs/src/loader/parsers/fontface.js Adjusts fontface parser example and wraps non-url( sources into url(...)
packages/melonjs/tests/loader.spec.js Adds assertions for wildcard baseURL including fontface and a new url() stripping test
packages/melonjs/CHANGELOG.md Documents fontface baseURL support
packages/examples/src/examples/ui/ExampleUI.tsx Updates example fontface asset to use a plain path instead of url(...)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 140 to 144
baseURL["js"] = url;
baseURL["tmx"] = url;
baseURL["tsx"] = url;
// XXX ?
//baseURL["fontface"] = url;
baseURL["fontface"] = url;
}
Comment on lines +517 to +522
if (
asset.type === "fontface" &&
typeof asset.src === "string" &&
asset.src.startsWith("url(")
) {
asset.src = asset.src.slice(4, -1);
Comment on lines +21 to +23
// FontFace constructor expects src in `url(...)` format
if (!data.src.startsWith("url(")) {
data.src = "url(" + data.src + ")";
Comment on lines +273 to +299
it("should strip url() wrapper from fontface src before applying baseURL", () => {
loader.setBaseURL("fontface", "assets/");

// simulate what load() does: strip url() then prepend baseURL
const asset1 = {
name: "font1",
type: "fontface",
src: "url(font/test.woff2)",
};
const asset2 = { name: "font2", type: "fontface", src: "font/test.woff2" };

// strip url() wrapper for fontface assets
if (asset1.src.startsWith("url(")) {
asset1.src = asset1.src.slice(4, -1);
}
if (asset2.src.startsWith("url(")) {
asset2.src = asset2.src.slice(4, -1);
}

// apply baseURL
asset1.src = loader.baseURL[asset1.type] + asset1.src;
asset2.src = loader.baseURL[asset2.type] + asset2.src;

// both should resolve to the same path
expect(asset1.src).toBe("assets/font/test.woff2");
expect(asset2.src).toBe("assets/font/test.woff2");

- Fix url() stripping to handle quotes and whitespace via regex
- Preserve local() font source descriptors (don't wrap in url())
- Skip baseURL prepend for local() and data: sources
- Update JSDoc to list fontface as a supported type for setBaseURL
- Rewrite test to use stubbed parser instead of duplicating logic
- Add test for local() passthrough

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@obiot obiot merged commit b57ddaf into master Mar 19, 2026
8 checks passed
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.

2 participants