Skip to content
Open
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
3 changes: 2 additions & 1 deletion packages/void/src/cli/deploy-cloudflare-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export function resolveCloudflareStaticPreset(
),
};
}
if (detectFramework(root)) {
// `static` and `spa` returned above, so a configured app type here means a Worker deploy.
if (detectFramework(root) || voidConfig.inference?.appType) {
return null;
}
const detected = detectPreset(root, { spa: options.spa, strictBackend: true });
Expand Down
28 changes: 28 additions & 0 deletions packages/void/test/unit/preset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { join, resolve } from 'node:path';
import { toSlash } from 'pathslash';
import { describe, expect, it, beforeEach, afterEach } from 'vite-plus/test';
import { packageFixturePath } from '../../../../test/fixture-dir.ts';
import { resolveCloudflareStaticPreset } from '../../src/cli/deploy-cloudflare-static.ts';
import {
detectPreset,
findBackendSources,
formatProjectCommand,
hasBackendFiles,
resolveProjectCommand,
} from '../../src/cli/preset.ts';
import type { VoidConfig } from '../../src/config.ts';

const TMP = packageFixturePath(import.meta.dirname, '.tmp-preset');

Expand Down Expand Up @@ -266,6 +268,32 @@ describe('detectPreset — strictBackend', () => {
});
});

describe('resolveCloudflareStaticPreset — configured app type', () => {
const vitepressPkg = { devDependencies: { vitepress: '^1.0.0' } };

// The guide sends a VitePress site with `routes/` to `appType: "void"`, which this branch ignored.
it('returns null for a configured appType "void" with an SSG plus backend', () => {
const root = setupProject({ pkg: vitepressPkg, dirs: ['.vitepress', 'routes'] });
const voidConfig = { inference: { appType: 'void' } } as VoidConfig;
expect(resolveCloudflareStaticPreset(root, voidConfig, {})).toBeNull();
});

it('still refuses the unconfigured SSG plus backend case', () => {
const root = setupProject({ pkg: vitepressPkg, dirs: ['.vitepress', 'routes'] });
expect(() => resolveCloudflareStaticPreset(root, {} as VoidConfig, {})).toThrow('vitepress');
});

it('keeps resolving a configured static app that also has backend sources', () => {
const root = setupProject({ pkg: vitepressPkg, dirs: ['.vitepress', 'routes'] });
const voidConfig = { inference: { appType: 'static' } } as VoidConfig;
expect(resolveCloudflareStaticPreset(root, voidConfig, {})).toEqual({
buildCommand: 'vitepress build',
outputDir: toSlash(resolve(root, '.vitepress/dist')),
appType: 'static',
});
});
});

describe('findBackendSources', () => {
it('lists every backend source relative to the root', () => {
const root = setupProject({
Expand Down