-
Notifications
You must be signed in to change notification settings - Fork 6.5k
refactor: split platform-specific code into platform-vercel and platform-cloudflare packages #8838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ovflowd
wants to merge
24
commits into
main
Choose a base branch
from
refactor/split-apps-by-deployment-target
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d7b6e7e
refactor: consolidate platform detection into NEXT_PUBLIC_DEPLOY_TARGET
ovflowd 641d0b9
refactor: split platform-specific code into platform-vercel and platf…
ovflowd c88bfc5
Merge branch 'main' into refactor/split-apps-by-deployment-target
ovflowd 1a61747
fix: use project-relative alias strings in default platform config
ovflowd 78a6852
fix(vercel): restore mdx defaults for shiki
cursoragent 517dfcb
chore(deps): catalog next versions across workspace
cursoragent 6664f19
refactor(config): restrict platform nextConfig overrides
cursoragent 0ac46dc
refactor(types): enforce platform nextConfig via type-only constraints
cursoragent 4641a0c
refactor: move platform workspaces from packages/ to apps/ and decoup…
ovflowd 23bfde7
docs: update Repository Structure to list apps/vercel and apps/cloudf…
ovflowd 87f739f
refactor(platform): resolve via #platform import map and unify type c…
ovflowd 35a58e3
fix(ci): build open-next in a dedicated step and skip turbo for wrangler
ovflowd ed3b670
fix(ci): invoke cloudflare:preview via pnpm filter so wrangler resolves
ovflowd 93751a4
fix(platform): defer Node-only config behind async thunks
ovflowd ecf659d
chore(cloudflare): drop cd-prefixed scripts and ignore wrangler state…
ovflowd 62528e8
refactor(platform): relocate deploy-target apps under platforms/
ovflowd 68b5524
fix(platform): restore platform-vercel next config test under platforms/
ovflowd 53b1ce5
Merge branch 'main' into refactor/split-apps-by-deployment-target
ovflowd 1c47205
refactor(platform): flatten platform packages and route via #platform
ovflowd df43651
fix(cloudflare): repair paths after platforms/cloudflare flatten
ovflowd c6e6ed4
refactor(platform): rename platform scripts and add default platform …
ovflowd 8318b5f
refactor(platform): collapse @platform aliases into a single wildcard
ovflowd b6fb2df
chore: tiny next.config.mjs simplification
ovflowd 4be6e5e
fix(platform): stop tsconfig paths from shadowing the @platform alias
ovflowd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { createRequire } from 'node:module'; | ||
| import { relative } from 'node:path'; | ||
|
|
||
| import { getDeploymentId } from '@opennextjs/cloudflare'; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
|
|
||
| /** | ||
| * Platform config contributed by the Cloudflare deployment target. | ||
| * | ||
| * Consumed by `apps/site/next.config.mjs` via the platform-config loader. | ||
| * Must export a default `{ nextConfig, aliases, images }` shape — any of | ||
| * which may be omitted when the platform has nothing to contribute. | ||
| * | ||
| * @type {import('../site/next.platform.config').PlatformConfig} | ||
| */ | ||
| export default { | ||
| nextConfig: { | ||
| // Skew protection: Cloudflare routes requests by deploymentId so that | ||
| // a client and the worker stay in sync across rolling deploys. | ||
| deploymentId: await getDeploymentId(), | ||
| }, | ||
| aliases: { | ||
| '@platform/analytics': '@node-core/platform-cloudflare/analytics', | ||
| '@platform/instrumentation': | ||
| '@node-core/platform-cloudflare/instrumentation', | ||
| }, | ||
| images: { | ||
| // Route optimized images through Cloudflare's Images service via the | ||
| // custom loader. `remotePatterns` do NOT apply here — Cloudflare | ||
| // enforces allowed origins at the edge instead. | ||
| loader: 'custom', | ||
| // Next.js joins `loaderFile` onto its own cwd (apps/site), so pass a | ||
| // path relative to that cwd rather than an absolute one. Resolving via | ||
| // `require.resolve` avoids the `new URL(..., import.meta.url)` pattern, | ||
| // which webpack rewrites as an asset reference and mangles at runtime. | ||
| loaderFile: relative( | ||
| process.cwd(), | ||
| require.resolve('@node-core/platform-cloudflare/image-loader') | ||
| ), | ||
| }, | ||
| mdx: { | ||
| // Cloudflare workers can't load `shiki/wasm` via `WebAssembly.instantiate` | ||
| // with custom imports (blocked for security), so fall back to the | ||
| // JavaScript RegEx engine. Twoslash also needs a VFS we don't have here. | ||
| wasm: false, | ||
| twoslash: false, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "name": "@node-core/platform-cloudflare", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "exports": { | ||
| "./analytics": "./src/analytics.tsx", | ||
| "./image-loader": "./src/image-loader.ts", | ||
| "./instrumentation": "./src/instrumentation.ts", | ||
| "./next.platform.config": "./next.platform.config.mjs", | ||
| "./playwright.platform.config": "./playwright.platform.config.mjs", | ||
| "./worker-entrypoint": "./src/worker-entrypoint.ts" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/nodejs/nodejs.org", | ||
| "directory": "apps/cloudflare" | ||
| }, | ||
| "scripts": { | ||
| "cloudflare:build:worker": "cd ../site && opennextjs-cloudflare build --openNextConfigPath ../cloudflare/open-next.config.ts --config ../cloudflare/wrangler.jsonc", | ||
| "cloudflare:deploy": "cd ../site && opennextjs-cloudflare deploy --openNextConfigPath ../cloudflare/open-next.config.ts --config ../cloudflare/wrangler.jsonc", | ||
| "cloudflare:preview": "cd ../site && wrangler dev --config ../cloudflare/wrangler.jsonc", | ||
|
ovflowd marked this conversation as resolved.
Outdated
|
||
| "lint:types": "tsc --noEmit" | ||
| }, | ||
| "dependencies": { | ||
| "@flarelabs-net/wrangler-build-time-fs-assets-polyfilling": "^0.0.1", | ||
| "@opennextjs/cloudflare": "^1.19.3", | ||
| "@sentry/cloudflare": "^10.49.0", | ||
| "wrangler": "^4.77.0" | ||
| }, | ||
| "peerDependencies": { | ||
| "next": "catalog:", | ||
| "react": "catalog:" | ||
| }, | ||
| "devDependencies": { | ||
| "@cloudflare/workers-types": "^4.20260418.1", | ||
| "@playwright/test": "^1.58.2", | ||
| "@types/node": "catalog:", | ||
| "@types/react": "catalog:", | ||
| "typescript": "catalog:" | ||
| }, | ||
| "engines": { | ||
| "node": ">=20" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /** | ||
| * Playwright overrides contributed by the Cloudflare deployment target. | ||
| * | ||
| * Consumed by `apps/site/playwright.config.ts` via the platform-config | ||
| * loader. Spins up the wrangler preview so E2E runs against the | ||
| * OpenNext worker artifact rather than `next dev`. | ||
| * | ||
| * @type {import('../site/playwright.platform.config').PlatformPlaywrightConfig} | ||
| */ | ||
| export default { | ||
| baseURL: 'http://127.0.0.1:8787', | ||
| webServer: { | ||
| stdout: 'pipe', | ||
| command: 'pnpm --filter=@node-core/platform-cloudflare cloudflare:preview', | ||
| url: 'http://127.0.0.1:8787', | ||
| timeout: 60_000 * 3, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export default () => null; |
5 changes: 2 additions & 3 deletions
5
apps/site/cloudflare/image-loader.ts → apps/cloudflare/src/image-loader.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const register = () => {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "esnext", | ||
| "lib": ["dom", "dom.iterable", "esnext"], | ||
| "skipLibCheck": true, | ||
| "strict": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "noEmit": true, | ||
| "esModuleInterop": true, | ||
| "module": "esnext", | ||
| "moduleResolution": "Bundler", | ||
| "customConditions": ["default"], | ||
| "isolatedModules": true, | ||
| "jsx": "react-jsx" | ||
| }, | ||
| "include": [ | ||
| "src", | ||
| "next.platform.config.mjs", | ||
| "playwright.platform.config.mjs" | ||
| ], | ||
| "exclude": ["src/worker-entrypoint.ts"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| { | ||
| "$schema": "https://turbo.build/schema.json", | ||
| "extends": ["//"], | ||
| "tasks": { | ||
| "cloudflare:build:worker": { | ||
| "dependsOn": ["@node-core/website#build:blog-data"], | ||
| "inputs": [ | ||
| "open-next.config.ts", | ||
| "wrangler.jsonc", | ||
| "src/**/*.ts", | ||
| "../site/{app,components,hooks,i18n,layouts,middlewares,pages,providers,types,util}/**/*.{ts,tsx}", | ||
| "../site/{app,components,layouts,pages,styles}/**/*.css", | ||
| "../site/{next-data,scripts,i18n}/**/*.{mjs,json}", | ||
| "../site/{app,pages}/**/*.{mdx,md}", | ||
| "../site/*.{md,mdx,json,ts,tsx,mjs,yml}" | ||
| ], | ||
| "outputs": ["../site/.open-next/**"], | ||
| "env": [ | ||
| "NEXT_PUBLIC_DEPLOY_TARGET", | ||
| "NEXT_PUBLIC_BASE_URL", | ||
| "NEXT_PUBLIC_DIST_URL", | ||
| "NEXT_PUBLIC_DOCS_URL", | ||
| "NEXT_PUBLIC_BASE_PATH", | ||
| "NEXT_PUBLIC_ORAMA_API_KEY", | ||
| "NEXT_PUBLIC_ORAMA_ENDPOINT", | ||
| "NEXT_PUBLIC_DATA_URL", | ||
| "NEXT_GITHUB_API_KEY" | ||
| ] | ||
| }, | ||
| "cloudflare:preview": { | ||
| "dependsOn": ["cloudflare:build:worker"], | ||
| "cache": false, | ||
| "persistent": true | ||
| }, | ||
| "cloudflare:deploy": { | ||
| "dependsOn": ["cloudflare:build:worker"], | ||
| "cache": false | ||
| }, | ||
| "lint:types": { | ||
| "cache": false | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from '@platform/analytics'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1 @@ | ||
| export async function register() { | ||
| if (!('Cloudflare' in globalThis)) { | ||
| // Note: we don't need to set up the Vercel OTEL if the application is running on Cloudflare | ||
| const { registerOTel } = await import('@vercel/otel'); | ||
| registerOTel({ serviceName: 'nodejs-org' }); | ||
| } | ||
| } | ||
| export { register } from '@platform/instrumentation'; | ||
|
ovflowd marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.