89 lines
2.7 KiB
TypeScript
89 lines
2.7 KiB
TypeScript
import { execFileSync } from 'node:child_process';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { sites } from '@openai/sites-vite-plugin';
|
|
import tailwindcss from '@tailwindcss/postcss';
|
|
import vinext from 'vinext';
|
|
import { defineConfig } from 'vite';
|
|
import hostingConfig from './.openai/hosting.json';
|
|
|
|
const fullGitSha = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;
|
|
const configuredRevision = process.env.BUILD_REVISION?.trim();
|
|
let buildRevision = 'unavailable';
|
|
if (configuredRevision && fullGitSha.test(configuredRevision)) {
|
|
buildRevision = configuredRevision;
|
|
} else {
|
|
try {
|
|
const checkoutRevision = execFileSync('git', ['rev-parse', 'HEAD'], {
|
|
cwd: fileURLToPath(new URL('.', import.meta.url)),
|
|
encoding: 'utf8',
|
|
stdio: ['ignore', 'pipe', 'ignore'],
|
|
}).trim();
|
|
if (fullGitSha.test(checkoutRevision)) buildRevision = checkoutRevision;
|
|
} catch {
|
|
// Container contexts exclude .git; only an explicit workflow SHA can identify them.
|
|
}
|
|
}
|
|
|
|
const SITE_CREATOR_PLACEHOLDER_DATABASE_ID =
|
|
'00000000-0000-4000-8000-000000000000';
|
|
|
|
const { d1, r2 } = hostingConfig;
|
|
|
|
// macOS Seatbelt blocks FSEvents, so Codex previews need polling for HMR.
|
|
const isCodexSeatbeltSandbox = process.env.CODEX_SANDBOX === 'seatbelt';
|
|
|
|
const localBindingConfig = {
|
|
main: 'vinext/server/fetch-handler',
|
|
compatibility_flags: ['nodejs_compat'],
|
|
d1_databases: d1
|
|
? [
|
|
{
|
|
binding: d1,
|
|
database_name: 'site-creator-d1',
|
|
database_id: SITE_CREATOR_PLACEHOLDER_DATABASE_ID,
|
|
},
|
|
]
|
|
: [],
|
|
r2_buckets: r2
|
|
? [
|
|
{
|
|
binding: r2,
|
|
bucket_name: 'site-creator-r2',
|
|
},
|
|
]
|
|
: [],
|
|
};
|
|
|
|
export default defineConfig(async () => {
|
|
// Keep Wrangler and Miniflare state project-local. These are non-secret tool
|
|
// settings; application environment belongs in ignored `.env*` files.
|
|
process.env.WRANGLER_WRITE_LOGS ??= 'false';
|
|
process.env.WRANGLER_LOG_PATH ??= '.wrangler/logs';
|
|
process.env.MINIFLARE_REGISTRY_PATH ??= '.wrangler/registry';
|
|
|
|
// Wrangler snapshots its log path while the Cloudflare plugin is imported.
|
|
const { cloudflare } = await import('@cloudflare/vite-plugin');
|
|
|
|
return {
|
|
define: { __BUILD_REVISION__: JSON.stringify(buildRevision) },
|
|
css: { postcss: { plugins: [tailwindcss()] } },
|
|
server: {
|
|
watch: {
|
|
// Worker registry heartbeats must not reload an active game.
|
|
ignored: ['**/.wrangler/**'],
|
|
...(isCodexSeatbeltSandbox
|
|
? { useFsEvents: false, usePolling: true }
|
|
: {}),
|
|
},
|
|
},
|
|
plugins: [
|
|
vinext(),
|
|
sites(),
|
|
cloudflare({
|
|
viteEnvironment: { name: 'rsc', childEnvironments: ['ssr'] },
|
|
config: localBindingConfig,
|
|
}),
|
|
],
|
|
};
|
|
});
|