mirror of
https://github.com/nexu-io/open-design.git
synced 2026-06-01 03:14:35 +07:00
fix(web): keep Vercel static builds writing to out (#2946)
* fix(web): keep Vercel static builds writing to out (#1628) Generated-By: looper 0.9.1 (runner=worker, agent=opencode) * fix(web): preserve explicit dist dir overrides Generated-By: looper 0.9.1 (runner=fixer, agent=opencode) * fix(web): preserve explicit dist dir overrides Generated-By: looper 0.9.1 (runner=fixer, agent=opencode)
This commit is contained in:
parent
2bd83b6e23
commit
3d358fc877
3 changed files with 45 additions and 8 deletions
|
|
@ -79,7 +79,9 @@ function resolveDistDir(defaultValue: string) {
|
||||||
return toPosixPath(isAbsolute(configured) ? relative(WEB_ROOT, configured) || '.' : configured);
|
return toPosixPath(isAbsolute(configured) ? relative(WEB_ROOT, configured) || '.' : configured);
|
||||||
}
|
}
|
||||||
|
|
||||||
const DIST_DIR = resolveDistDir(isProd ? (shouldStaticExport ? 'out' : '.next') : '.next');
|
const DIST_DIR = shouldStaticExport && !process.env.OD_WEB_DIST_DIR
|
||||||
|
? null
|
||||||
|
: resolveDistDir('.next');
|
||||||
|
|
||||||
function resolveDevTsconfigPath() {
|
function resolveDevTsconfigPath() {
|
||||||
const configured = process.env.OD_WEB_TSCONFIG_PATH;
|
const configured = process.env.OD_WEB_TSCONFIG_PATH;
|
||||||
|
|
@ -166,9 +168,10 @@ const nextConfig: NextConfig = {
|
||||||
root: WORKSPACE_ROOT,
|
root: WORKSPACE_ROOT,
|
||||||
},
|
},
|
||||||
...(DEV_TSCONFIG_PATH ? { typescript: { tsconfigPath: DEV_TSCONFIG_PATH } } : {}),
|
...(DEV_TSCONFIG_PATH ? { typescript: { tsconfigPath: DEV_TSCONFIG_PATH } } : {}),
|
||||||
// Keep the bundle output predictable so the daemon's STATIC_DIR can point
|
// Static exports keep Next.js's default `out/` output directory so static
|
||||||
// at it without any glob trickery.
|
// hosts like Vercel can publish the generated site directly. Server runtimes
|
||||||
distDir: DIST_DIR,
|
// still keep a predictable traced build directory for sidecar launchers.
|
||||||
|
...(DIST_DIR ? { distDir: DIST_DIR } : {}),
|
||||||
...(shouldStaticExport
|
...(shouldStaticExport
|
||||||
? {
|
? {
|
||||||
output: 'export' as const,
|
output: 'export' as const,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,45 @@
|
||||||
import { describe, expect, it } from 'vitest';
|
import { dirname, resolve } from 'node:path';
|
||||||
import nextConfig from '../../next.config';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||||
import * as spaShellRoute from '../../app/[[...slug]]/page';
|
import * as spaShellRoute from '../../app/[[...slug]]/page';
|
||||||
|
|
||||||
|
const WEB_ROOT = dirname(fileURLToPath(new URL('../../..', import.meta.url)));
|
||||||
|
|
||||||
|
async function loadNextConfig() {
|
||||||
|
vi.resetModules();
|
||||||
|
return (await import('../../next.config')).default;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
delete process.env.OD_WEB_DIST_DIR;
|
||||||
|
vi.resetModules();
|
||||||
|
});
|
||||||
|
|
||||||
describe('SPA shell export route', () => {
|
describe('SPA shell export route', () => {
|
||||||
it('stays compatible with static export builds', () => {
|
it('stays compatible with static export builds', async () => {
|
||||||
|
const nextConfig = await loadNextConfig();
|
||||||
expect(nextConfig.output).toBe('export');
|
expect(nextConfig.output).toBe('export');
|
||||||
|
expect(nextConfig.distDir).toBeUndefined();
|
||||||
expect('dynamicParams' in spaShellRoute).toBe(false);
|
expect('dynamicParams' in spaShellRoute).toBe(false);
|
||||||
expect(spaShellRoute.generateStaticParams()).toEqual([{ slug: [] }]);
|
expect(spaShellRoute.generateStaticParams()).toEqual([{ slug: [] }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keeps an explicit dist dir override even when static export is selected', async () => {
|
||||||
|
const configuredDistDir = resolve(WEB_ROOT, '.tmp', 'vitest-next');
|
||||||
|
process.env.OD_WEB_DIST_DIR = configuredDistDir;
|
||||||
|
|
||||||
|
const nextConfig = await loadNextConfig();
|
||||||
|
|
||||||
|
expect(nextConfig.output).toBe('export');
|
||||||
|
expect(nextConfig.distDir).toContain('vitest-next');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('treats an empty dist dir override as unset for static export builds', async () => {
|
||||||
|
process.env.OD_WEB_DIST_DIR = '';
|
||||||
|
|
||||||
|
const nextConfig = await loadNextConfig();
|
||||||
|
|
||||||
|
expect(nextConfig.output).toBe('export');
|
||||||
|
expect(nextConfig.distDir).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://openapi.vercel.sh/vercel.json",
|
"$schema": "https://openapi.vercel.sh/vercel.json",
|
||||||
"buildCommand": "pnpm install && pnpm --filter @open-design/web build",
|
"buildCommand": "OD_WEB_OUTPUT_MODE= pnpm --filter @open-design/web build",
|
||||||
"installCommand": "pnpm install",
|
"installCommand": "pnpm install",
|
||||||
"outputDirectory": "apps/web/out",
|
"outputDirectory": "apps/web/out",
|
||||||
"framework": null
|
"framework": null
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue