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
2 changes: 2 additions & 0 deletions packages/react/test/integration/react-pages-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import type { IsolatedPlayground } from '../../../../test/integration-helpers.ts';
import { launchPagesBrowser } from '../../../../test/pages-browser.ts';
import {
assertPagesClientBuild,
registerSharedClientTests,
registerSharedDevSsrTest,
} from '../../../../test/pages-client-contract.ts';
Expand Down Expand Up @@ -1350,6 +1351,7 @@ describe('react-pages client (preview)', { retry: 2 }, () => {

beforeAll(async () => {
execFileSync('vp', ['run', 'build'], { cwd: REACT_PAGES_ROOT, stdio: 'pipe' });
assertPagesClientBuild(REACT_PAGES_ROOT);

const server = await startServer(
(port) => (child = spawnFixtureServer(REACT_PAGES_ROOT, 'preview', port)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import type { IsolatedPlayground } from '../../../../test/integration-helpers.ts';
import { launchPagesBrowser } from '../../../../test/pages-browser.ts';
import {
assertPagesClientBuild,
registerSharedClientTests,
registerSharedDevSsrTest,
} from '../../../../test/pages-client-contract.ts';
Expand Down Expand Up @@ -277,6 +278,7 @@ describe('solid-pages client (preview)', { retry: 2 }, () => {

beforeAll(async () => {
execFileSync('vp', ['run', 'build'], { cwd: fixture.root, stdio: 'pipe' });
assertPagesClientBuild(fixture.root);

const server = await startServer(
(port) => (child = spawnFixtureServer(fixture.root, 'preview', port)),
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/test/integration/svelte-pages-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import type { IsolatedPlayground } from '../../../../test/integration-helpers.ts';
import { launchPagesBrowser } from '../../../../test/pages-browser.ts';
import {
assertPagesClientBuild,
registerSharedClientTests,
registerSharedDevSsrTest,
} from '../../../../test/pages-client-contract.ts';
Expand Down Expand Up @@ -164,6 +165,7 @@ describe('svelte-pages client (preview)', { retry: 2 }, () => {

beforeAll(async () => {
execFileSync('vp', ['run', 'build'], { cwd: fixture.root, stdio: 'pipe' });
assertPagesClientBuild(fixture.root);

const server = await startServer(
(port) => (child = spawnFixtureServer(fixture.root, 'preview', port)),
Expand Down
24 changes: 24 additions & 0 deletions packages/void/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,28 @@ export function voidPlugin(options?: {

// Default mode: full Hono routing + generated entry

const pagesClientInput: Plugin = {
name: 'void:pages-client-input',
apply: 'build',
applyToEnvironment: (environment) => environment.name !== 'client',
options: {
order: 'post',
handler(options) {
const { input } = options;
if (
input &&
typeof input === 'object' &&
!Array.isArray(input) &&
input['pages-client'] === 'virtual:void-pages-client'
) {
const entries = { ...input };
delete entries['pages-client'];
return { ...options, input: entries };
}
},
},
};

// Non-CF targets: skip binding inference, D1, migrations, wrangler
if (isNodeTarget(config.target)) {
if (authEnabled) {
Expand Down Expand Up @@ -870,6 +892,7 @@ export function voidPlugin(options?: {
serverRuntimeOptimizerPlugin,
envSchemaPlugin(root),
...pagesDevCssAssetsPlugin(root, devTriggerToken),
pagesClientInput,
routingPlugin(root, {
getApplicationAnalysis,
isAuthEnabled: () => false,
Expand Down Expand Up @@ -1027,6 +1050,7 @@ export function voidPlugin(options?: {
bindingRuntimePlugin(bindingNames),
...(bindings.needsSandbox ? [createSandboxSdkResolvePlugin()] : []),
...pagesDevCssAssetsPlugin(root, devTriggerToken),
pagesClientInput,
routes,
drizzlePlugin(root, true, dialect, {
d1BindingName: bindingNames?.d1,
Expand Down
40 changes: 40 additions & 0 deletions packages/void/test/integration/pages-build-input.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { execFileSync } from 'node:child_process';
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import type { Manifest } from 'vite';
import { expect, it } from 'vite-plus/test';
import { createIsolatedPlayground } from '../../../../test/integration-helpers.ts';

const workspace = join(import.meta.dirname, '../../../..');

it('builds a custom Worker entry named pages-client with shared plugins', () => {
const fixture = createIsolatedPlayground(workspace, 'playground/react-pages');
try {
writeFileSync(join(fixture.root, 'custom-entry.js'), 'console.log("custom Worker entry");');
writeFileSync(
join(fixture.root, 'vite.config.ts'),
`
import { voidReact } from '@void/react/plugin';
import { voidPlugin } from 'void';

export default {
plugins: [voidPlugin(), voidReact()],
builder: { sharedPlugins: true },
environments: {
void_worker: {
build: { rollupOptions: { input: { 'pages-client': './custom-entry.js' } } },
},
},
};
`,
);
execFileSync('vp', ['run', 'build'], { cwd: fixture.root, stdio: 'pipe' });

const worker = JSON.parse(
readFileSync(join(fixture.root, 'dist/ssr/.vite/manifest.json'), 'utf8'),
) as Manifest;
expect(worker['custom-entry.js']).toMatchObject({ file: 'pages-client.js', isEntry: true });
} finally {
fixture.cleanup();
}
});
2 changes: 2 additions & 0 deletions packages/vue/test/integration/vue-pages-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import type { IsolatedPlayground } from '../../../../test/integration-helpers.ts';
import { launchPagesBrowser } from '../../../../test/pages-browser.ts';
import {
assertPagesClientBuild,
registerSharedClientTests,
registerSharedDevSsrTest,
} from '../../../../test/pages-client-contract.ts';
Expand Down Expand Up @@ -348,6 +349,7 @@ describe('vue-pages client (preview)', { retry: 2 }, () => {

beforeAll(async () => {
execFileSync('vp', ['run', 'build'], { cwd: fixture.root, stdio: 'pipe' });
assertPagesClientBuild(fixture.root);

const server = await startServer(
(port) => (child = spawnFixtureServer(fixture.root, 'preview', port)),
Expand Down
14 changes: 14 additions & 0 deletions test/pages-client-contract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import type { Locator, Page, Request } from 'playwright';
import type { Manifest } from 'vite';
import { assert, beforeAll, describe, expect, it } from 'vite-plus/test';
import { PAGES_PROTOCOL_VERSION } from '../packages/edge/src/pages-protocol.ts';
import {
Expand All @@ -7,6 +10,17 @@ import {
serializePageData,
} from '../packages/void/src/pages/serialize.ts';

export function assertPagesClientBuild(root: string): void {
function readManifest(output: string): Manifest {
const path = join(root, 'dist', output, '.vite/manifest.json');
return JSON.parse(readFileSync(path, 'utf8')) as Manifest;
}

const entry = 'virtual:void-pages-client';
expect(readManifest('client')[entry]).toMatchObject({ isEntry: true });
expect(readManifest('ssr')[entry]).toBeUndefined();
}

async function readJsonText(locator: Locator): Promise<unknown> {
const value = await locator.textContent();
assert(value !== null, 'Expected serialized JSON text.');
Expand Down