Repository navigation
Fix the browser build failing to load without import.meta.url - #1874
ravitejas-tech wants to merge 1 commit into
Conversation
The browser build registered its embedded sRGB ICC profile under the path getIccProfilePath() resolves from import.meta.url, at import time. Bundles for runtimes such as Cloudflare Workers leave import.meta.url undefined, so importing pdfkit threw. The profile is embedded, so register it under a fixed name and point the PDF/A output at that name instead. Fixes foliojs#1873
| // document that never produces PDF/A output has no reason to fail over it. | ||
| export const getIccProfilePath = () => { | ||
| if (iccProfilePath === undefined) { | ||
| if (import.meta.url == null) { |
There was a problem hiding this comment.
This check is still relevant?
In which situation it will be triggered?
There was a problem hiding this comment.
Yes, it is still relevant, but only for the Node build.
The browser build no longer reaches it: it calls setIccProfilePath() at import time, so getIccProfilePath() returns the fixed name before this check.
The Node build still resolves the path on first use. If an application bundles the Node build into a CommonJS output, import.meta.url is undefined there, and a document with a PDF/A subset hits this check. Without it the user would get a bare Invalid URL from new URL(). The existing spec "explains a missing import.meta.url when PDF/A needs the profile" in tests/unit/bundling.spec.js covers that case.
Fixes #1873
What kind of change does this PR introduce?
Bug fix. The browser build registered its embedded sRGB ICC profile at import time, under the path
getIccProfilePath()resolves fromimport.meta.url. Bundles for runtimes such as Cloudflare Workers leaveimport.meta.urlundefined, so importing pdfkit threw.The browser build now registers the profile under a fixed name (
sRGB_IEC61966_2_1.icc) and points the PDF/A output at it, so it never readsimport.meta.url. The Node build is unchanged and still resolves the file on first use.The new test bundles the browser entry the way the release build does, with
import.meta.urlresolved toundefined. It checks that the bundle loads and that PDF/A-1 output still contains the ICC output intent.Checklist: