Skip to content

Commit e3fb803

Browse files
morinokamiclaude
andauthored
fix(config): stop pointing users at the legacy void.json (#716)
Projects configure Void through `void.config.ts`, but several messages still name `void.json`, a file those projects don't have. For example, with `sourceDir: 'src'` and `routes/` in both the project root and `src/`, `vp dev` stops with: ``` Error: sourceDir: void.json sets "sourceDir": "src", but convention path(s) also exist at the project root: routes. Move them under "src" or remove the root copy. ``` The same file name appears in: - `sourceDir` errors from `readProjectPaths()`, which framework adapters and many CLI commands use. `readConfig()` already named the right file. - The `[cause]` line printed under every `void.config.ts` validation error, because `validateConfig()` kept the error from before it replaced the file name: ``` Error: config: "routing.isr" in void.config.ts must be a boolean. [cause]: Error: config: "routing.isr" in void.json must be a boolean. ``` - `VoidAssetRewriteError`. - `origin` labels in the dev `X-Void-Routing` header and routing lint warnings. `docs/guide/edge/rewrites.md` already documents them as `void.config.ts#routing.rewrites`. - The file tree on the App Types docs page. `VoidAssetRewriteError` also links to `void.dev`, which answers any path with a page that redirects to `/lander`. The docs are on `void.cloud`. ## Fix - The `sourceDir` and conflict errors name the project's actual config file, so projects that still use `void.json` keep seeing `void.json`. - `validateConfig()` no longer attaches the original error as `cause`. Its message only differs by the placeholder file name. - `VoidAssetRewriteError` names `void.config.ts` and links to `void.cloud`. - `origin` labels read `void.config.ts#routing.*`. - The App Types file tree lists `void.config.ts`. The other docs already use it, so they do not change. ## Not changed here - `VoidAssetRewriteError` and the `origin` labels aren't given the file name, so projects that still use `void.json` see `void.config.ts` there. `void init` and `void deploy` migrate those projects. - `playground/kitchen-sink/pages/auth.vue` still says `void.json`. ## Tests - `packages/void/test/unit/project-paths.test.ts`: the `sourceDir` and conflict errors with `void.config.ts`, with `void.json` and with no config file. - `packages/void/test/unit/config.test.ts`: what an invalid `void.config.ts` prints, through `util.inspect`, which is what adds the `[cause]` line. - `packages/void/test/unit/compile.test.ts`: the file name and link in `VoidAssetRewriteError`. - `origin` expectations in five unit test files move to the new label. These cases fail without this fix, except the `void.json` ones, which already passed. ## Verification - `vp test run`: 774 files pass, 1 skipped (15,966 tests pass, 29 skipped). - `vp run check`: 33/33 pass. - By hand with `vp dev` on a copy of `playground/ssr`: - `/docs/x` through a `routing.rewrites` rule answers `X-Void-Routing: rewrite[/docs/*] -> /api/hello (void.config.ts#routing.rewrites)`. - `/old` through a `routing.redirects` rule answers `X-Void-Routing: redirect[/old] -> /api/hello 302 (void.config.ts#routing.redirects)`. - `c.rewrite('/hero.png')` in middleware answers 500 and logs `VoidAssetRewriteError`, which names `void.config.ts` and links to `void.cloud`. - A bad `sourceDir`, a bad `routing.isr` and a root conflict stop the server. With `void.config.ts`, the output has no `void.json` and no `[cause]` line. With `void.json`, the errors name `void.json`. - By hand with `void prepare` and a bad `routing.isr` in `void.config.ts`: the error names `void.config.ts`, and the output has no `void.json`. - `vp run --filter ./docs build`: the App Types page lists `void.config.ts`, and `void.json` is gone from it. - Not run by hand: a `routing.fallbacks` rule. The app's SSR entry answered first, and the unit tests check that label. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent be9b568 commit e3fb803

11 files changed

Lines changed: 122 additions & 48 deletions

File tree

‎docs/.vitepress/theme/VoidAppFileTree.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function buildItems(ext: string): Array<FileTreeItem> {
4040
{ name: 'crons/', collapsed: true, children: [{ name: 'daily-cleanup.ts' }] },
4141
{ name: 'queues/', collapsed: true, children: [{ name: 'email-sender.ts' }] },
4242
{ name: 'vite.config.ts' },
43-
{ name: 'void.json' },
43+
{ name: 'void.config.ts' },
4444
];
4545
}
4646
</script>

‎packages/void/src/config-loader.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export const TYPED_CONFIG_FILE = 'void.config.ts';
88

99
export type LoadedVoidConfig = { source: string; value: unknown };
1010

11+
/** The file to name in messages about a project's settings. Only legacy projects use JSON. */
12+
export function getConfigFileName(root: string): string {
13+
return existsSync(join(root, LEGACY_CONFIG_FILE)) ? LEGACY_CONFIG_FILE : TYPED_CONFIG_FILE;
14+
}
15+
1116
/** Evaluate a TypeScript config without requiring Void to be installed in the target project. */
1217
export function loadTypedVoidConfigFile(path: string): unknown {
1318
const sourceEntry = fileURLToPath(new URL('./config-entry.ts', import.meta.url));

‎packages/void/src/config.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ export function validateConfig(config: unknown, source: string = CONFIG_FILE): V
427427
return validateConfigObject(config);
428428
} catch (error) {
429429
if (source !== CONFIG_FILE && error instanceof Error) {
430-
throw new Error(error.message.replaceAll(CONFIG_FILE, source), { cause: error });
430+
// No `cause`: Node would print its message too, which names the placeholder.
431+
throw new Error(error.message.replaceAll(CONFIG_FILE, source));
431432
}
432433
throw error;
433434
}
@@ -450,7 +451,7 @@ function validateConfigObject(obj: unknown): VoidConfig {
450451
if (typeof obj.sourceDir !== 'string') {
451452
throw new Error(`config: "sourceDir" in ${CONFIG_FILE} must be a string.`);
452453
}
453-
validateSourceDir(obj.sourceDir);
454+
validateSourceDir(obj.sourceDir, CONFIG_FILE);
454455
}
455456

456457
// Validate target
@@ -1172,7 +1173,7 @@ export function convertRedirectsConfig(
11721173
return undefined;
11731174
}
11741175

1175-
const origin = 'void.json#routing.redirects';
1176+
const origin = 'void.config.ts#routing.redirects';
11761177
const rules: Array<DevRedirectRule> = [];
11771178
for (const [rawSource, dest] of Object.entries(redirects)) {
11781179
const parsed = parseHostPrefixedSource(rawSource);
@@ -1231,7 +1232,7 @@ function convertRewriteRules(
12311232
return undefined;
12321233
}
12331234

1234-
const origin = `void.json#routing.${field}`;
1235+
const origin = `void.config.ts#routing.${field}`;
12351236
const rules: Array<DevRedirectRule> = [];
12361237
for (const [rawSource, destination] of Object.entries(entries)) {
12371238
const parsed = parseHostPrefixedSource(rawSource);

‎packages/void/src/project-paths.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync } from 'node:fs';
22
import { isAbsolute, join, normalize } from 'pathslash';
3-
import { loadVoidConfig } from './config-loader.ts';
3+
import { getConfigFileName, loadVoidConfig, TYPED_CONFIG_FILE } from './config-loader.ts';
44
import type { VoidConfig } from './config.ts';
55

66
const SOURCE_CONVENTION_DIRECTORIES = [
@@ -50,9 +50,9 @@ export type ProjectPaths = {
5050
envFileCandidates: ReadonlyArray<string>;
5151
};
5252

53-
export function validateSourceDir(value: string): string {
53+
export function validateSourceDir(value: string, configFile: string = TYPED_CONFIG_FILE): string {
5454
if (value.trim() !== value || value.length === 0) {
55-
throw new Error('config: "sourceDir" in void.json must be a non-empty relative directory.');
55+
throw new Error(`config: "sourceDir" in ${configFile} must be a non-empty relative directory.`);
5656
}
5757
if (
5858
value === '.' ||
@@ -63,24 +63,24 @@ export function validateSourceDir(value: string): string {
6363
isAbsolute(value)
6464
) {
6565
throw new Error(
66-
`config: "sourceDir" path '${value}' in void.json must be a relative directory.`,
66+
`config: "sourceDir" path '${value}' in ${configFile} must be a relative directory.`,
6767
);
6868
}
6969
const normalized = normalize(value).replace(/\/+$/, '');
7070
if (normalized === '' || normalized === '.') {
7171
throw new Error(
72-
`config: "sourceDir" path '${value}' in void.json must be a relative directory.`,
72+
`config: "sourceDir" path '${value}' in ${configFile} must be a relative directory.`,
7373
);
7474
}
7575
return normalized;
7676
}
7777

78-
function getSourceDir(config?: VoidConfig): string {
79-
return config?.sourceDir ? validateSourceDir(config.sourceDir) : '';
78+
function getSourceDir(root: string, config?: VoidConfig): string {
79+
return config?.sourceDir ? validateSourceDir(config.sourceDir, getConfigFileName(root)) : '';
8080
}
8181

8282
export function resolveProjectPaths(root: string, config?: VoidConfig): ProjectPaths {
83-
const sourceDir = getSourceDir(config);
83+
const sourceDir = getSourceDir(root, config);
8484
const sourceRoot = sourceDir ? join(root, sourceDir) : root;
8585
const sourceRelative = (path: string) => (sourceDir ? `${sourceDir}/${path}` : path);
8686

@@ -142,6 +142,6 @@ export function assertNoRootSourceConventionConflicts(paths: ProjectPaths): void
142142
return;
143143
}
144144
throw new Error(
145-
`sourceDir: void.json sets "sourceDir": "${paths.sourceDir}", but convention path(s) also exist at the project root: ${conflicts.join(', ')}. Move them under "${paths.sourceDir}" or remove the root copy.`,
145+
`sourceDir: ${getConfigFileName(paths.root)} sets "sourceDir": "${paths.sourceDir}", but convention path(s) also exist at the project root: ${conflicts.join(', ')}. Move them under "${paths.sourceDir}" or remove the root copy.`,
146146
);
147147
}

‎packages/void/src/runtime/handler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class VoidAssetRewriteError extends Error {
2222
override name = 'VoidAssetRewriteError';
2323
constructor(destination: string) {
2424
super(
25-
`c.rewrite() cannot re-dispatch to a static asset path (${JSON.stringify(destination)}). Runtime rewrites only reach routes and SSR entries inside the worker — static asset handlers run in front of the worker. To rewrite into an asset, use a static \`routing.rewrites\` rule in void.json or a \`200!\` entry in _redirects. See https://void.dev/guide/edge/rewrites#runtime-rewrites-cannot-reach-static-assets`,
25+
`c.rewrite() cannot re-dispatch to a static asset path (${JSON.stringify(destination)}). Runtime rewrites only reach routes and SSR entries inside the worker — static asset handlers run in front of the worker. To rewrite into an asset, use a static \`routing.rewrites\` rule in void.config.ts or a \`200!\` entry in _redirects. See https://void.cloud/guide/edge/rewrites#runtime-rewrites-cannot-reach-static-assets`,
2626
);
2727
}
2828
}

‎packages/void/test/unit/compile.test.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,14 @@ describe('c.rewrite runtime wrapper', () => {
422422
destination: '/fallback.html',
423423
status: 200,
424424
force: false,
425-
origin: 'void.json#routing.fallbacks',
425+
origin: 'void.config.ts#routing.fallbacks',
426426
},
427427
{
428428
source: '/docs/*',
429429
destination: '/rewrite-target',
430430
status: 200,
431431
force: true,
432-
origin: 'void.json#routing.rewrites',
432+
origin: 'void.config.ts#routing.rewrites',
433433
},
434434
];
435435
const { always: preAsset, fallbacks: postAsset } = splitRedirectRulesByForce(allRules);
@@ -588,9 +588,9 @@ describe('c.rewrite runtime wrapper', () => {
588588
expect(caught).toBeInstanceOf(VoidAssetRewriteError);
589589
expect((caught as Error).name).toBe('VoidAssetRewriteError');
590590
expect((caught as Error).message).toContain(destination);
591-
expect((caught as Error).message).toContain('routing.rewrites');
591+
expect((caught as Error).message).toContain('`routing.rewrites` rule in void.config.ts');
592592
expect((caught as Error).message).toContain(
593-
'https://void.dev/guide/edge/rewrites#runtime-rewrites-cannot-reach-static-assets',
593+
'https://void.cloud/guide/edge/rewrites#runtime-rewrites-cannot-reach-static-assets',
594594
);
595595
},
596596
);
@@ -617,14 +617,14 @@ describe('default-target dev parity', () => {
617617
source: '/old',
618618
destination: '/new',
619619
status: 301,
620-
origin: 'void.json#routing.redirects',
620+
origin: 'void.config.ts#routing.redirects',
621621
},
622622
{
623623
source: '/rewrite',
624624
destination: '/new',
625625
status: 200,
626626
force: true,
627-
origin: 'void.json#routing.rewrites',
627+
origin: 'void.config.ts#routing.rewrites',
628628
},
629629
];
630630
const headerRules = [{ pattern: '/*', headers: [['x-test', '1']] as Array<[string, string]> }];
@@ -634,7 +634,7 @@ describe('default-target dev parity', () => {
634634
destination: '/docs.html',
635635
status: 200,
636636
force: false,
637-
origin: 'void.json#routing.fallbacks',
637+
origin: 'void.config.ts#routing.fallbacks',
638638
},
639639
];
640640

‎packages/void/test/unit/config.test.ts‎

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mkdirSync, writeFileSync, rmSync, readFileSync } from 'node:fs';
22
import { join } from 'node:path';
3+
import { inspect } from 'node:util';
34
import { describe, it, expect, vi, beforeEach } from 'vite-plus/test';
45

56
vi.mock('../../src/log', () => ({
@@ -130,6 +131,21 @@ describe('readConfig', () => {
130131
cleanup();
131132
});
132133

134+
it('prints only void.config.ts when a typed config is invalid', () => {
135+
setup();
136+
writeFileSync(join(tmpDir, 'void.config.ts'), 'export default { routing: { isr: 1 } };\n');
137+
let error: unknown;
138+
try {
139+
readConfig(tmpDir);
140+
} catch (caught) {
141+
error = caught;
142+
}
143+
// inspect() is what prints the `[cause]` line under an uncaught error.
144+
expect(inspect(error)).toContain('"routing.isr" in void.config.ts must be a boolean');
145+
expect(inspect(error)).not.toContain('void.json');
146+
cleanup();
147+
});
148+
133149
it('accepts an explicit Cloudflare deploy mode', () => {
134150
setup(JSON.stringify({ deploy: { cloudflare: { mode: 'atomic' } } }));
135151
expect(readConfig(tmpDir).deploy?.cloudflare?.mode).toBe('atomic');
@@ -971,7 +987,7 @@ describe('routing rules: host-prefixed sources', () => {
971987
destination: 'https://foo.com/:splat',
972988
status: 302,
973989
host: 'www.foo.com',
974-
origin: 'void.json#routing.redirects',
990+
origin: 'void.config.ts#routing.redirects',
975991
},
976992
]);
977993
cleanup();
@@ -1294,14 +1310,24 @@ describe('convertRedirectsConfig', () => {
12941310
it('converts string destinations with default 302', () => {
12951311
const result = convertRedirectsConfig({ '/old': '/new' });
12961312
expect(result).toEqual([
1297-
{ source: '/old', destination: '/new', status: 302, origin: 'void.json#routing.redirects' },
1313+
{
1314+
source: '/old',
1315+
destination: '/new',
1316+
status: 302,
1317+
origin: 'void.config.ts#routing.redirects',
1318+
},
12981319
]);
12991320
});
13001321

13011322
it('converts object destinations with explicit status', () => {
13021323
const result = convertRedirectsConfig({ '/old': { to: '/new', status: 301 } });
13031324
expect(result).toEqual([
1304-
{ source: '/old', destination: '/new', status: 301, origin: 'void.json#routing.redirects' },
1325+
{
1326+
source: '/old',
1327+
destination: '/new',
1328+
status: 301,
1329+
origin: 'void.config.ts#routing.redirects',
1330+
},
13051331
]);
13061332
});
13071333

@@ -1311,12 +1337,12 @@ describe('convertRedirectsConfig', () => {
13111337
'/c/*': { to: '/d/:splat', status: 308 },
13121338
});
13131339
expect(result).toEqual([
1314-
{ source: '/a', destination: '/b', status: 302, origin: 'void.json#routing.redirects' },
1340+
{ source: '/a', destination: '/b', status: 302, origin: 'void.config.ts#routing.redirects' },
13151341
{
13161342
source: '/c/*',
13171343
destination: '/d/:splat',
13181344
status: 308,
1319-
origin: 'void.json#routing.redirects',
1345+
origin: 'void.config.ts#routing.redirects',
13201346
},
13211347
]);
13221348
});
@@ -1339,7 +1365,7 @@ describe('convertRewritesConfig', () => {
13391365
destination: '/en/docs',
13401366
status: 200,
13411367
force: true,
1342-
origin: 'void.json#routing.rewrites',
1368+
origin: 'void.config.ts#routing.rewrites',
13431369
},
13441370
]);
13451371
});
@@ -1355,14 +1381,14 @@ describe('convertRewritesConfig', () => {
13551381
destination: '/en',
13561382
status: 200,
13571383
force: true,
1358-
origin: 'void.json#routing.rewrites',
1384+
origin: 'void.config.ts#routing.rewrites',
13591385
},
13601386
{
13611387
source: '/docs/*',
13621388
destination: '/en/docs/:splat',
13631389
status: 200,
13641390
force: true,
1365-
origin: 'void.json#routing.rewrites',
1391+
origin: 'void.config.ts#routing.rewrites',
13661392
},
13671393
]);
13681394
});
@@ -1385,7 +1411,7 @@ describe('convertFallbacksConfig', () => {
13851411
destination: '/index.html',
13861412
status: 200,
13871413
force: false,
1388-
origin: 'void.json#routing.fallbacks',
1414+
origin: 'void.config.ts#routing.fallbacks',
13891415
},
13901416
]);
13911417
});
@@ -1401,14 +1427,14 @@ describe('convertFallbacksConfig', () => {
14011427
destination: '/api/fallback',
14021428
status: 200,
14031429
force: false,
1404-
origin: 'void.json#routing.fallbacks',
1430+
origin: 'void.config.ts#routing.fallbacks',
14051431
},
14061432
{
14071433
source: '/*',
14081434
destination: '/index.html',
14091435
status: 200,
14101436
force: false,
1411-
origin: 'void.json#routing.fallbacks',
1437+
origin: 'void.config.ts#routing.fallbacks',
14121438
},
14131439
]);
14141440
});
@@ -1441,7 +1467,7 @@ describe('lintDestinationSplats', () => {
14411467
const msg = warnMock.mock.calls[0][0];
14421468
expect(msg).toContain('/old/*');
14431469
expect(msg).toContain('/new/*');
1444-
expect(msg).toContain('void.json#routing.redirects');
1470+
expect(msg).toContain('void.config.ts#routing.redirects');
14451471
});
14461472

14471473
it('emits a single aggregated warning covering all affected rules', async () => {
@@ -1467,7 +1493,7 @@ describe('lintDestinationSplats', () => {
14671493
const rules = convertFallbacksConfig({ '/docs/*': '/docs/*' });
14681494
lintDestinationSplats(rules, 'fallbacks (post-asset)');
14691495
expect(warnMock).toHaveBeenCalledOnce();
1470-
expect(warnMock.mock.calls[0][0]).toContain('void.json#routing.fallbacks');
1496+
expect(warnMock.mock.calls[0][0]).toContain('void.config.ts#routing.fallbacks');
14711497
});
14721498
});
14731499

‎packages/void/test/unit/lint-duplicate-sources.test.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ describe('lintDuplicateSources', () => {
3434
it('emits no warning when all sources are unique', () => {
3535
const rules: Array<DevRedirectRule> = [
3636
rule('/docs/*', '_redirects:1'),
37-
rule('/api/*', 'void.json#routing.rewrites'),
38-
rule('/blog/*', 'void.json#routing.redirects', { status: 302 }),
37+
rule('/api/*', 'void.config.ts#routing.rewrites'),
38+
rule('/blog/*', 'void.config.ts#routing.redirects', { status: 302 }),
3939
];
4040

4141
lintDuplicateSources(rules, 'redirects');
@@ -52,8 +52,8 @@ describe('lintDuplicateSources', () => {
5252
it('emits a single aggregated warning naming the duplicate source and every origin', () => {
5353
const rules: Array<DevRedirectRule> = [
5454
rule('/docs/*', '_redirects:12'),
55-
rule('/api/*', 'void.json#routing.redirects', { status: 302 }),
56-
rule('/docs/*', 'void.json#routing.rewrites'),
55+
rule('/api/*', 'void.config.ts#routing.redirects', { status: 302 }),
56+
rule('/docs/*', 'void.config.ts#routing.rewrites'),
5757
];
5858

5959
lintDuplicateSources(rules, 'redirects/rewrites (pre-asset)');
@@ -63,17 +63,17 @@ describe('lintDuplicateSources', () => {
6363
expect(msg).toContain('redirects/rewrites (pre-asset)');
6464
expect(msg).toContain('/docs/*');
6565
expect(msg).toContain('_redirects:12');
66-
expect(msg).toContain('void.json#routing.rewrites');
66+
expect(msg).toContain('void.config.ts#routing.rewrites');
6767
// The non-duplicated /api/* source must not appear
6868
expect(msg).not.toContain('/api/*');
6969
});
7070

7171
it('aggregates multiple duplicate sources into one message', () => {
7272
const rules: Array<DevRedirectRule> = [
7373
rule('/docs/*', '_redirects:12'),
74-
rule('/docs/*', 'void.json#routing.rewrites'),
75-
rule('/api/*', 'void.json#routing.rewrites'),
76-
rule('/api/*', 'void.json#routing.rewrites'),
74+
rule('/docs/*', 'void.config.ts#routing.rewrites'),
75+
rule('/api/*', 'void.config.ts#routing.rewrites'),
76+
rule('/api/*', 'void.config.ts#routing.rewrites'),
7777
rule('/blog/*', '_redirects:20'),
7878
];
7979

‎packages/void/test/unit/merge-routing-rules.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('mergeRoutingRules', () => {
9595
});
9696

9797
expect(result.redirectRules).toHaveLength(2);
98-
expect(result.redirectRules[0].origin).toBe('void.json#routing.rewrites');
98+
expect(result.redirectRules[0].origin).toBe('void.config.ts#routing.rewrites');
9999
expect(result.redirectRules[0].destination).toBe('/handbook/:splat');
100100
expect(result.redirectRules[1].origin).toMatch(/^_redirects:/);
101101
expect(result.redirectRules[1].destination).toBe('/en/docs/:splat');
@@ -160,12 +160,12 @@ describe('mergeRoutingRules', () => {
160160
expect(result.redirectRules[0]).toMatchObject({
161161
source: '/x',
162162
destination: '/from-redirect',
163-
origin: 'void.json#routing.redirects',
163+
origin: 'void.config.ts#routing.redirects',
164164
});
165165
expect(result.redirectRules[1]).toMatchObject({
166166
source: '/x',
167167
destination: '/from-rewrite',
168-
origin: 'void.json#routing.rewrites',
168+
origin: 'void.config.ts#routing.rewrites',
169169
});
170170
});
171171

0 commit comments

Comments
 (0)