feat(turbopack): hash the font file name if it exceeds our max file size (#69144)
### What?
When using google fonts, we import files and write them with their hash
to the filesystem. Some of these fonts get very close to the file size
limit which, after appending a hash onto them, causes turbo to fail with
a write error.
### Why?
Different operating systems have different path length requirements. In
short:
- macOS: limit per segment, longer limit for entire path length
- unix: limit per segment, longer limit for entire path length
- windows: hard limit of 260 chars unless using UNC
We need to respect these.
### How?
A small change in the font code that rewrites filesystem paths if they
approach this limit, with some buffer room. ~Rather than truncating I
opted for a 64 bit hash because many fonts have long common prefixes. We
could bump this up to 128 or higher but in practice there will be very
very few files that need this code path.~ _(bgw):_ This now uses a
combination of truncation (for legibility/debuggability) and a 128 bit
hash (for collision avoidance).
Another option is a general handler for this where reads and writes are
intercepted in turbo tasks fs but I wanted to achieve a few things:
- explicitly handle sources of problematic file names at the source,
rather than having a blanket impl
- avoid obscure hashed names appearing in our outputs generally since it
makes debugging harder
- avoid lots of hashing on reads and writes
To me it is safer to have the source ensure they are meeting the needs
of the system since we can control source specific implementations.
Closes PACK-3012
---------
Co-authored-by:
Benjamin Woodruff <benjamin.woodruff@vercel.com>
Showing
Please
register
or
sign in
to comment