Skip to content

Commit 1c47205

Browse files
ovflowdclaude
andcommitted
refactor(platform): flatten platform packages and route via #platform
Collapse platforms/{vercel,cloudflare}/src/ into the package roots so analytics, instrumentation, image-loader, and the worker entrypoint sit at the package root. Both packages now expose a single flat exports map (`./*: ./*`); platform-cloudflare no longer needs an explicit `./image-loader` entry because the consumer (next.platform.config.mjs) calls `require.resolve(...image-loader.ts)` with the extension. Move apps/site/{next,playwright}.platform.config.mjs into apps/site/platform/ and update the apps/site `#platform/*` imports default branch to a single literal path (`./platform/*`). Import sites carry explicit extensions so Node resolves them without extension fallback: `#platform/next.platform.config.mjs`, `#platform/playwright.platform.config.mjs`. Update platforms/cloudflare/wrangler.jsonc `main` to the flattened worker path, and align both platform tsconfigs on `include: ["**/*.ts","**/*.tsx","**/*.mjs"]` now that there is no `src/` to scope to. Also: factor DEPLOY_TARGET out of next.constants.mjs into a small next.platform.constants.mjs (avoids dragging client-side env into build-time config), simplify transpilePackages derivation, drop the playwright.config.d.ts `Pick<Config, ...>` (resolves `use` to `{}`) in favor of `PlaywrightTestConfig`, and refresh docs/technologies.md. Verified: standalone build, Vercel build (`NEXT_PUBLIC_DEPLOY_TARGET= vercel --conditions=vercel`), Cloudflare worker build, and `playwright --list` (18 tests) all green. Co-Authored-By: Claude Opus 4.7 <[email protected]>
1 parent 53b1ce5 commit 1c47205

28 files changed

Lines changed: 99 additions & 132 deletions

apps/site/mdx/plugins.mjs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import rehypeSlug from 'rehype-slug';
77
import remarkGfm from 'remark-gfm';
88
import readingTime from 'remark-reading-time';
99

10-
// MDX overrides contributed by the active deployment target. Resolved via
11-
// the `#platform/next.platform.config` import map in `package.json`; each
12-
// platform owns its own `{ wasm, twoslash }` defaults and the in-repo
13-
// default file acts as the standalone fallback.
14-
import platform from '#platform/next.platform.config';
10+
import platform from '#platform/next.platform.config.mjs';
1511

1612
import remarkTableTitles from '../util/table';
1713

apps/site/next.config.mjs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
import createNextIntlPlugin from 'next-intl/plugin';
44

5-
import platform from '#platform/next.platform.config';
5+
import platform from '#platform/next.platform.config.mjs';
66

7-
import {
8-
BASE_PATH,
9-
ENABLE_STATIC_EXPORT,
10-
DEPLOY_TARGET,
11-
} from './next.constants.mjs';
7+
import { BASE_PATH, ENABLE_STATIC_EXPORT } from './next.constants.mjs';
128
import { getImagesConfig } from './next.image.config.mjs';
9+
import { DEPLOY_TARGET } from './next.platform.constants.mjs';
1310
import { redirects, rewrites } from './next.rewrites.mjs';
1411

12+
const platformImages = await platform.images?.();
13+
const platformNextConfig = await platform.nextConfig?.();
14+
15+
const transpilePackages = DEPLOY_TARGET
16+
? [`@node-core/platform-${DEPLOY_TARGET}`]
17+
: [];
18+
1519
/** @type {import('next').NextConfig} */
1620
const nextConfig = {
1721
// Full Support of React 18 SSR and Streaming
@@ -21,14 +25,9 @@ const nextConfig = {
2125
// We allow the BASE_PATH to be overridden in case that the Website
2226
// is being built on a subdirectory (e.g. /nodejs-website)
2327
basePath: BASE_PATH,
24-
images: getImagesConfig(await platform.images?.()),
28+
images: getImagesConfig(platformImages),
2529
serverExternalPackages: ['twoslash'],
26-
// Transpile platform packages' TSX/TS sources when they're pulled in via
27-
// the `@platform/*` aliases from the active `next.platform.config.mjs`.
28-
transpilePackages: [
29-
'@node-core/platform-vercel',
30-
'@node-core/platform-cloudflare',
31-
],
30+
transpilePackages,
3231
outputFileTracingIncludes: {
3332
// Twoslash needs TypeScript declarations to function, and, by default, Next.js
3433
// strips them for brevity. Therefore, they must be explicitly included.
@@ -96,7 +95,7 @@ const nextConfig = {
9695
.filter(Boolean),
9796
},
9897
}),
99-
...(await platform.nextConfig?.()),
98+
...platformNextConfig,
10099
};
101100

102101
const withNextIntl = createNextIntlPlugin('./i18n.tsx');

apps/site/next.constants.mjs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@
55
*/
66
export const IS_DEV_ENV = process.env.NODE_ENV === 'development';
77

8-
/**
9-
* Identifies the deployment platform the site is being built for.
10-
*
11-
* Set by the deployment wrapper at build time: `vercel.json`'s `buildCommand`
12-
* sets `vercel`, `open-next.config.ts`'s `buildCommand` sets `cloudflare`.
13-
* Unset for standalone builds (local dev, static export).
14-
*
15-
* The `NEXT_PUBLIC_` prefix makes Next.js inline the value at build time,
16-
* enabling dead-code elimination of platform-specific branches.
17-
*
18-
* @type {'vercel' | 'cloudflare' | undefined}
19-
*/
20-
export const DEPLOY_TARGET = process.env.NEXT_PUBLIC_DEPLOY_TARGET;
21-
228
/**
239
* This is used for telling Next.js to do a Static Export Build of the Website
2410
*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
/**
4+
* Identifies the deployment platform the site is being built for.
5+
*
6+
* Set by the deployment wrapper at build time: `vercel.json`'s `build.env`
7+
* sets `vercel`, `open-next.config.ts`'s `buildCommand` sets `cloudflare`.
8+
* Unset for standalone builds (local dev, static export).
9+
*
10+
* The `NEXT_PUBLIC_` prefix makes Next.js inline the value at build time,
11+
* enabling dead-code elimination of platform-specific branches.
12+
*
13+
* @type {'vercel' | 'cloudflare' | undefined}
14+
*/
15+
export const DEPLOY_TARGET = process.env.NEXT_PUBLIC_DEPLOY_TARGET;

apps/site/package.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,10 @@
118118
"./*.mjs",
119119
"./*/index.mjs"
120120
],
121-
"#platform/next.platform.config": {
122-
"cloudflare": "@node-core/platform-cloudflare/next.platform.config",
123-
"vercel": "@node-core/platform-vercel/next.platform.config",
124-
"default": "./next.platform.config.mjs"
125-
},
126-
"#platform/playwright.platform.config": {
127-
"cloudflare": "@node-core/platform-cloudflare/playwright.platform.config",
128-
"vercel": "@node-core/platform-vercel/playwright.platform.config",
129-
"default": "./playwright.platform.config.mjs"
121+
"#platform/*": {
122+
"cloudflare": "@node-core/platform-cloudflare/*",
123+
"vercel": "@node-core/platform-vercel/*",
124+
"default": "./platform/*"
130125
}
131126
},
132127
"engines": {
File renamed without changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Default Playwright platform config used when no `DEPLOY_TARGET` is set —
3+
* local dev against `next dev`, static export, generic hosting. Each
4+
* platform contributes its own `baseURL` (with optional
5+
* `PLAYWRIGHT_BASE_URL` override for CI), so consumers just spread
6+
* `platform.use` into their `defineConfig` call.
7+
*
8+
* @type {import('../playwright.platform.config').PlatformPlaywrightConfig}
9+
*/
10+
export default {
11+
use: { baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000' },
12+
};

apps/site/playwright.config.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig, devices } from '@playwright/test';
22

3-
import platform from '#platform/playwright.platform.config';
3+
import platform from '#platform/playwright.platform.config.mjs';
44

55
const isCI = !!process.env.CI;
66

@@ -12,12 +12,9 @@ export default defineConfig({
1212
retries: isCI ? 2 : 0,
1313
workers: isCI ? 1 : undefined,
1414
reporter: isCI ? [['html'], ['github']] : [['html']],
15-
...(platform.webServer ? { webServer: platform.webServer } : {}),
15+
...platform,
1616
use: {
17-
baseURL:
18-
process.env.PLAYWRIGHT_BASE_URL ||
19-
platform.baseURL ||
20-
'http://127.0.0.1:3000',
17+
...platform.use,
2118
trace: 'on-first-retry',
2219
},
2320
projects: [

apps/site/playwright.platform.config.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import type { Config } from '@playwright/test';
1+
import type { PlaywrightTestConfig } from '@playwright/test';
22

33
/**
44
* Shared Playwright platform-config contract consumed by
55
* `apps/site/playwright.config.ts` and implemented by each
66
* `@node-core/platform-<target>` package.
77
*/
8-
export type PlatformPlaywrightConfig = {
9-
baseURL?: string;
10-
webServer?: Config['webServer'];
11-
};
8+
export type PlatformPlaywrightConfig = Pick<
9+
PlaywrightTestConfig,
10+
'webServer' | 'use'
11+
>;
1212

1313
declare const config: PlatformPlaywrightConfig;
1414

apps/site/playwright.platform.config.mjs

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)