Skip to content

Conversation

@delucis
Copy link
Contributor

@delucis delucis commented Nov 6, 2025

This is a draft PR replacing the fontkit dependency with fontkitten in the unpack package, reducing install size by ~16x (I haven’t measured for unpack specifically yet, but this should also reduce bundle size by ~3x). It would in theory close #236 eventually.

Because fontkitten is ESM-only, this PR also makes unpack ESM-only (it is currently shipped as a dual CJS+ESM package).

@changeset-bot
Copy link

changeset-bot bot commented Nov 6, 2025

🦋 Changeset detected

Latest commit: b72d8d4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@capsizecss/unpack Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@delucis delucis marked this pull request as ready for review November 18, 2025 13:01
@delucis delucis requested a review from a team as a code owner November 18, 2025 13:01
@delucis
Copy link
Contributor Author

delucis commented Nov 18, 2025

Just released the v1 of fontkitten and updated this PR with it, so should be ready for review when someone has time!

@delucis delucis changed the title [WIP] Replace fontkit with fontkitten Replace fontkit with fontkitten Nov 18, 2025
}

if (font !== null && 'fonts' in font && Array.isArray(font.fonts)) {
if (font !== null && font.isCollection) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

isCollection is a new property added in fontkitten to make it easier to quickly distinguish between fonts and font collections.

Comment on lines +136 to 142
export const fromFile = async (
path: string,
options?: Options,
): Promise<Font> => {
const buffer = await readFile(path);
return _fromBuffer(buffer, 'fromFile', 'path', options);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that we’re not using Fontkit’s open() method, I refactored this to just reuse the _fromBuffer function.

import { XMLParser } from 'fast-xml-parser';
import sortKeys from 'sort-keys';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

__dirname is not available in ES modules, so now that this package is marked as ESM with "type": "module" in package.json, this is needed to provide the same value.

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.

Reduce install size of @capsizecss/unpack

2 participants