Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/void/src/cli/cf-build-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ const moduleTypes: Record<string, ModuleType> = {
'.cjs': 'cjs',
'.wasm': 'wasm',
'.bin': 'data',
'.woff': 'data',
'.woff2': 'data',
'.ttf': 'data',
'.otf': 'data',
'.eot': 'data',
'.txt': 'text',
'.html': 'text',
'.sql': 'text',
Expand Down Expand Up @@ -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()) {
Expand Down
47 changes: 47 additions & 0 deletions packages/void/test/unit/cf-build-output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading