From b09fd3ab0cc74748d85ee0545bd81519cc3b2b8a Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Wed, 30 Sep 2026 11:06:23 +0000 Subject: [PATCH] Preserve binary font modules in Cloudflare build output --- packages/void/src/cli/cf-build-output.ts | 10 +++- .../void/test/unit/cf-build-output.test.ts | 47 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/packages/void/src/cli/cf-build-output.ts b/packages/void/src/cli/cf-build-output.ts index 9a88551ca..cfe82ec86 100644 --- a/packages/void/src/cli/cf-build-output.ts +++ b/packages/void/src/cli/cf-build-output.ts @@ -52,6 +52,11 @@ const moduleTypes: Record = { '.cjs': 'cjs', '.wasm': 'wasm', '.bin': 'data', + '.woff': 'data', + '.woff2': 'data', + '.ttf': 'data', + '.otf': 'data', + '.eot': 'data', '.txt': 'text', '.html': 'text', '.sql': 'text', @@ -96,8 +101,11 @@ function copyBundle( } const type = moduleTypes[extname(entry.name).toLowerCase()]; if (!type) { - return null; + throw new Error( + `The built Worker contains an unsupported module ${JSON.stringify(name)}. Emit public assets into the client output or configure the plugin that produced this file to run only in the client environment.`, + ); } + const destinationPath = join(destination, name); mkdirSync(dirname(destinationPath), { recursive: true }); if (entry.isSymbolicLink()) { diff --git a/packages/void/test/unit/cf-build-output.test.ts b/packages/void/test/unit/cf-build-output.test.ts index e63757143..23c59d3f8 100644 --- a/packages/void/test/unit/cf-build-output.test.ts +++ b/packages/void/test/unit/cf-build-output.test.ts @@ -254,6 +254,53 @@ it( CF_BUILD_TIMEOUT_MS, ); +it( + 'preserves binary font modules in a deployable Worker bundle', + async () => { + const output = worker({ + name: 'void-test', + compatibility_date: '2026-09-29', + main: 'index.js', + }); + mkdirSync(join(output, 'assets')); + writeFileSync( + join(output, 'index.js'), + "import font from './assets/font.woff2'; export default { fetch() { return new Response(String(font.byteLength)) } };\n", + ); + writeFileSync(join(output, 'assets/font.woff2'), Buffer.from([1, 2, 3])); + const prepared = await prepareCfBuildOutput(output, 'account-id'); + expect(prepared).not.toBeNull(); + if (!prepared) { + return; + } + try { + const built = await readBuildOutput(prepared.directory); + expect(built.workers.default.config.manifest).toMatchObject({ + mainModule: 'index.js', + modules: { 'assets/font.woff2': { type: 'data' } }, + }); + const cf = join(dirname(fileURLToPath(import.meta.resolve('cf/package.json'))), 'bin', 'cf'); + const dryRun = spawnSync( + process.execPath, + [cf, 'workers', 'versions', 'create', '--prebuilt', '--dry-run'], + { cwd: prepared.directory, encoding: 'utf8' }, + ); + expect(dryRun.status, `${dryRun.stdout}\n${dryRun.stderr}`).toBe(0); + } finally { + prepared.dispose(); + } + }, + CF_BUILD_TIMEOUT_MS, +); + +it('names the file when a plugin emits an unsupported module', async () => { + const output = worker({ name: 'void-test', compatibility_date: '2026-09-29', main: 'index.js' }); + writeFileSync(join(output, 'plugin.unknown'), 'unexpected'); + await expect(prepareCfBuildOutput(output, 'account-id')).rejects.toThrow( + 'unsupported module "plugin.unknown"', + ); +}); + it('preserves worker settings that the previous bridge dropped', async () => { const output = worker({ name: 'void-test',