Skip to content

Commit 3e24abf

Browse files
ovflowdclaude
andcommitted
refactor(platform): collapse @platform aliases into a single wildcard
Replace the per-file `@platform/analytics`, `@platform/instrumentation`, and `@platform/next.config.mjs` aliases (duplicated across each platform package) with a single `'@platform' -> PLATFORM_ALIAS` mapping wired in the root `apps/site/next.config.mjs` for both Turbopack and webpack. Drop the `aliases` field from `PlatformConfig` and from each platform's `next.config.mjs`. Add `playwright` scripts to the cloudflare and vercel platform packages (env baked in via cross-env), simplify the cloudflare playwright workflow to invoke them, rename `playwright.config.ts` -> `playwright.config.mjs`, and move `cross-env` into `dependencies` on `@node-core/platform-vercel` so Vercel's `pnpm install --prod` keeps it. Co-Authored-By: Claude Opus 4.7 <[email protected]>
1 parent 130867d commit 3e24abf

12 files changed

Lines changed: 46 additions & 52 deletions

.github/workflows/playwright-cloudflare-open-next.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ jobs:
5555
run: node --run build:cloudflare
5656

5757
- name: Run Playwright tests
58-
working-directory: apps/site
58+
working-directory: platforms/cloudflare
5959
run: node --run playwright
60-
env:
61-
NEXT_PUBLIC_DEPLOY_TARGET: cloudflare
6260

6361
- name: Upload Playwright test results
6462
if: always()

apps/site/next.config.mjs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@ import createNextIntlPlugin from 'next-intl/plugin';
44

55
import { BASE_PATH, ENABLE_STATIC_EXPORT } from './next.constants.mjs';
66
import { getImagesConfig } from './next.image.config.mjs';
7-
import { DEPLOY_TARGET } from './next.platform.constants.mjs';
7+
import { DEPLOY_TARGET, PLATFORM_ALIAS } from './next.platform.constants.mjs';
88
import { redirects, rewrites } from './next.rewrites.mjs';
99

10-
// Loaded by Node directly (Next.js doesn't bundle `next.config.mjs`), so
11-
// we resolve the active platform via a dynamic import keyed on
12-
// `DEPLOY_TARGET` rather than a `@platform/*` alias (those only resolve
13-
// inside Turbopack/webpack).
14-
const { default: platform } = await import(
15-
`@node-core/platform-${DEPLOY_TARGET}/next.config.mjs`
16-
);
10+
/**
11+
* Loaded by Node directly (Next.js doesn't bundle `next.config.mjs`), so
12+
* we resolve the active platform via a dynamic import keyed on
13+
* `DEPLOY_TARGET` rather than a `@platform/*` alias (those only resolve
14+
* inside Turbopack/webpack).
15+
*
16+
* @type {{ default: import('./next.platform.config.d.ts').PlatformConfig }}
17+
*/
18+
const { default: platform } = await import(`${PLATFORM_ALIAS}/next.config.mjs`);
1719

1820
const platformImages = await platform.images?.();
1921
const platformNextConfig = await platform.nextConfig?.();
2022

23+
// Single wildcard alias: `@platform/<file>` resolves to
24+
// `@node-core/platform-${DEPLOY_TARGET}/<file>` so each deploy target's
25+
// files (analytics slot, instrumentation, MDX/Shiki config) are picked
26+
// up automatically without per-file mappings.
27+
const platformAliases = { '@platform': PLATFORM_ALIAS };
28+
2129
/** @type {import('next').NextConfig} */
2230
const nextConfig = {
2331
// Full Support of React 18 SSR and Streaming
@@ -29,7 +37,7 @@ const nextConfig = {
2937
basePath: BASE_PATH,
3038
images: getImagesConfig(platformImages),
3139
serverExternalPackages: ['twoslash'],
32-
transpilePackages: [`@node-core/platform-${DEPLOY_TARGET}`],
40+
transpilePackages: [PLATFORM_ALIAS],
3341
outputFileTracingIncludes: {
3442
// Twoslash needs TypeScript declarations to function, and, by default, Next.js
3543
// strips them for brevity. Therefore, they must be explicitly included.
@@ -82,13 +90,13 @@ const nextConfig = {
8290
turbopackFileSystemCacheForDev: true,
8391
},
8492
// Provide Turbopack Aliases for Platform Resolution
85-
turbopack: { resolveAlias: platform.aliases },
93+
turbopack: { resolveAlias: platformAliases },
8694
// Provide Webpack Aliases for Platform Resolution.
8795
webpack: ({ resolve, ...config }) => ({
8896
...config,
8997
resolve: {
9098
...resolve,
91-
alias: { ...resolve.alias, ...platform.aliases },
99+
alias: { ...resolve.alias, ...platformAliases },
92100
conditionNames: resolve.conditionNames
93101
.concat(DEPLOY_TARGET)
94102
.filter(Boolean),

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ type PlatformNextConfig = Pick<NextConfig, 'deploymentId' | 'env'>;
88
* Shared platform-config contract consumed by `apps/site/next.config.mjs`
99
* and implemented by each `@node-core/platform-<target>` package.
1010
*
11-
* `aliases` are surfaced as Turbopack/webpack aliases so that
12-
* `@platform/*` imports in bundled code (e.g. the `@analytics/`
13-
* parallel-route slot, `instrumentation.ts`, `mdx/plugins.mjs`) resolve
14-
* to the active platform's files.
15-
*
1611
* `nextConfig` and `images` are async thunks so that platform modules
1712
* that depend on Node-only tooling (e.g. `@opennextjs/cloudflare`,
1813
* `require.resolve`) can keep those imports out of the module's
@@ -21,7 +16,6 @@ type PlatformNextConfig = Pick<NextConfig, 'deploymentId' | 'env'>;
2116
* worker runtime free of build-only code.
2217
*/
2318
export type PlatformConfig = {
24-
aliases?: Record<string, string>;
2519
images?: () => Promise<NextConfig['images']>;
2620
mdx?: PlatformMdxConfig;
2721
nextConfig?: () => Promise<PlatformNextConfig>;

apps/site/next.platform.constants.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@
1313
* @type {'vercel' | 'cloudflare' | 'default'}
1414
*/
1515
export const DEPLOY_TARGET = process.env.NEXT_PUBLIC_DEPLOY_TARGET ?? 'default';
16+
17+
/**
18+
* The alias for the platform.
19+
*
20+
* @type {string}
21+
*/
22+
export const PLATFORM_ALIAS = `@node-core/platform-${DEPLOY_TARGET}`;
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { defineConfig, devices } from '@playwright/test';
22

3-
import { DEPLOY_TARGET } from './next.platform.constants.mjs';
3+
import { PLATFORM_ALIAS } from './next.platform.constants.mjs';
44

5-
// Playwright loads this config via Node, so resolve the active platform
6-
// via a dynamic import keyed on `DEPLOY_TARGET` rather than a
7-
// `@platform/*` alias (those only resolve inside Turbopack/webpack).
5+
/**
6+
* Playwright loads this config via Node, so resolve the active platform
7+
* via a dynamic import keyed on `DEPLOY_TARGET` rather than a
8+
* `@platform/*` alias (those only resolve inside Turbopack/webpack).
9+
*
10+
* @type {{ default: import('./playwright.platform.config.d.ts').PlatformPlaywrightConfig }}
11+
*/
812
const { default: platform } = await import(
9-
`@node-core/platform-${DEPLOY_TARGET}/playwright.config.mjs`
13+
`${PLATFORM_ALIAS}/playwright.config.mjs`
1014
);
1115

1216
const isCI = !!process.env.CI;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { PlaywrightTestConfig } from '@playwright/test';
22

33
/**
44
* Shared Playwright platform-config contract consumed by
5-
* `apps/site/playwright.config.ts` and implemented by each
5+
* `apps/site/playwright.config.mjs` and implemented by each
66
* `@node-core/platform-<target>` package.
77
*/
88
export type PlatformPlaywrightConfig = Pick<

platforms/cloudflare/next.config.mjs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
* @type {import('../../apps/site/next.platform.config').PlatformConfig}
55
*/
66
export default {
7-
aliases: {
8-
'@platform/analytics': '@node-core/platform-cloudflare/analytics.tsx',
9-
'@platform/instrumentation':
10-
'@node-core/platform-cloudflare/instrumentation.ts',
11-
'@platform/next.config.mjs':
12-
'@node-core/platform-cloudflare/next.config.mjs',
13-
},
147
mdx: {
158
// Cloudflare workers can't load `shiki/wasm` via `WebAssembly.instantiate`
169
// with custom imports (blocked for security), so fall back to the

platforms/cloudflare/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"build:cloudflare": "cross-env NEXT_PUBLIC_DEPLOY_TARGET=cloudflare pnpm --filter=@node-core/website exec opennextjs-cloudflare build --openNextConfigPath ../../platforms/cloudflare/open-next.config.ts --config ../../platforms/cloudflare/wrangler.jsonc",
1616
"deploy:cloudflare": "cross-env NEXT_PUBLIC_DEPLOY_TARGET=cloudflare pnpm --filter=@node-core/website exec opennextjs-cloudflare deploy --openNextConfigPath ../../platforms/cloudflare/open-next.config.ts --config ../../platforms/cloudflare/wrangler.jsonc",
1717
"dev:cloudflare": "pnpm --filter=@node-core/website exec wrangler dev --config ../../platforms/cloudflare/wrangler.jsonc",
18-
"lint:types": "tsc --noEmit"
18+
"lint:types": "tsc --noEmit",
19+
"playwright": "cross-env NEXT_PUBLIC_DEPLOY_TARGET=cloudflare pnpm --filter=@node-core/website playwright"
1920
},
2021
"dependencies": {
2122
"@flarelabs-net/wrangler-build-time-fs-assets-polyfilling": "^0.0.1",

platforms/default/next.config.mjs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
* @type {import('../../apps/site/next.platform.config').PlatformConfig}
55
*/
66
export default {
7-
aliases: {
8-
'@platform/analytics': '@node-core/platform-default/analytics.tsx',
9-
'@platform/instrumentation':
10-
'@node-core/platform-default/instrumentation.ts',
11-
'@platform/next.config.mjs': '@node-core/platform-default/next.config.mjs',
12-
},
137
mdx: {
148
// Defaults for local dev / static export / generic hosting. Platform
159
// packages override these via their own `next.config.mjs`.

platforms/vercel/next.config.mjs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
* @type {import('../../apps/site/next.platform.config').PlatformConfig}
55
*/
66
export default {
7-
aliases: {
8-
'@platform/analytics': '@node-core/platform-vercel/analytics.tsx',
9-
'@platform/instrumentation':
10-
'@node-core/platform-vercel/instrumentation.ts',
11-
'@platform/next.config.mjs': '@node-core/platform-vercel/next.config.mjs',
12-
},
137
mdx: {
148
// Vercel supports the fast Oniguruma WASM engine and twoslash transforms,
159
// so keep parity with the default standalone config.

0 commit comments

Comments
 (0)