Skip to content
Merged
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
15 changes: 8 additions & 7 deletions packages/void/src/cli/cloudflare-deploy/classify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ export function classifyCloudflareDeployApp(
application: ApplicationAnalysis,
): CloudflareDeployAppClassification {
const framework = application.framework;
const configuredAppType = voidConfig.inference?.appType;

// Frameworks have their own Worker output. Their Vite dependency does not
// imply that the project is a standalone SPA.
const staticPreset = framework
? null
: detectPreset(root, { dir: options.dir, spa: options.spa });
const configuredStatic =
voidConfig.inference?.appType === 'static' || voidConfig.inference?.appType === 'spa';
// Infer a static preset only when neither the config nor a framework determines
// the app type, just as in the static deployment path.
const staticPreset =
framework || configuredAppType
? null
: detectPreset(root, { dir: options.dir, spa: options.spa });
const configuredStatic = configuredAppType === 'static' || configuredAppType === 'spa';
if (staticPreset || configuredStatic || options.dir || options.spa) {
const appType = staticPreset?.appType ?? (options.spa ? 'spa' : 'static');
return unsupported(
Expand Down
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
29 changes: 29 additions & 0 deletions packages/void/test/unit/cloudflare-deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,35 @@ function harness(overrides: Partial<CloudflareDeployDeps> = {}): {
return { deps, trace, wranglerArgs, exitCalls };
}

it('reaches the native Worker build for VitePress with a configured Void backend', async () => {
const root = makeProject({
'package.json': JSON.stringify({ name: 'site', dependencies: { void: '*', vitepress: '*' } }),
'void.config.ts': `export default {
inference: { appType: 'void', build: 'vitepress build && vite build' },
cloudflare: { name: 'site', account_id: 'personal' },
};`,
'vite.config.ts': `import { voidPlugin } from 'void';
export default { plugins: [voidPlugin()], publicDir: '.vitepress/dist' };`,
'routes/api/hello.ts': 'export const GET = () => "hello";',
'.vitepress/config.ts': 'export default {};',
'index.md': '# Site',
});
const runBuild = vi.fn(() => {
throw new Error('Reached the Worker build');
});
const { deps } = harness({ runBuild });
const output = vi.spyOn(log, 'error').mockImplementation(() => {});
try {
await expect(
runCloudflareDeploy(root, { platform: 'cloudflare' }, silentCliLog, deps),
).rejects.toBeInstanceOf(ExitError);
expect(output).toHaveBeenCalledWith('deploy: build failed — Reached the Worker build');
expect(runBuild).toHaveBeenCalledOnce();
} finally {
output.mockRestore();
}
});

describe('existing Cloudflare site handoff', () => {
const existing = {
versionId: 'original',
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