Skip to content

Commit cda1e89

Browse files
committed
fixup!
1 parent c086c54 commit cda1e89

48 files changed

Lines changed: 583 additions & 318 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CODEOWNERS

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ apps/site/next.config.mjs @nodejs/web-infra
1717
apps/site/next.dynamic.mjs @nodejs/web-infra
1818
apps/site/middleware.ts @nodejs/web-infra
1919
apps/site/navigation.mjs @nodejs/web-infra
20-
apps/site/playwright.config.ts @nodejs/web-infra
20+
apps/site/playwright.config.mjs @nodejs/web-infra
2121

2222
# Package Ecosystem
2323
package.json @nodejs/nodejs-website
@@ -27,9 +27,7 @@ turbo.json @nodejs/nodejs-website @nodejs/web-infra
2727
crowdin.yml @nodejs/web-infra
2828
apps/site/redirects.json @nodejs/web-infra
2929
apps/site/site.json @nodejs/web-infra
30-
apps/site/wrangler.jsonc @nodejs/web-infra
31-
apps/site/open-next.config.ts @nodejs/web-infra
32-
apps/site/redirects.json @nodejs/web-infra
30+
platforms @nodejs/web-infra
3331

3432
# Critical Documents
3533
LICENSE @nodejs/tsc

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ jobs:
5050
working-directory: apps/site
5151
run: node_modules/.bin/playwright install --with-deps
5252

53+
- name: Build OpenNext worker
54+
run: pnpm --filter=@node-core/platform-cloudflare build:worker
55+
5356
- name: Run Playwright tests
54-
working-directory: apps/site
55-
run: node --run playwright
56-
env:
57-
PLAYWRIGHT_RUN_CLOUDFLARE_PREVIEW: true
58-
PLAYWRIGHT_BASE_URL: http://127.0.0.1:8787
57+
run: pnpm --filter=@node-core/platform-cloudflare test:e2e
5958

6059
- name: Upload Playwright test results
6160
if: always()

.github/workflows/tmp-cloudflare-open-next-deploy.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ jobs:
5757
run: node --run build:blog-data
5858

5959
- name: Build open-next site
60-
working-directory: apps/site
61-
run: node --run cloudflare:build:worker
60+
run: pnpm --filter=@node-core/platform-cloudflare build:worker
6261

6362
- name: Deploy open-next site
64-
working-directory: apps/site
65-
run: node --run cloudflare:deploy
63+
run: pnpm --filter=@node-core/platform-cloudflare deploy:worker
6664
env:
6765
CF_WORKERS_SCRIPTS_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
6866
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ apps/site/public/blog-data.json
1515
apps/site/next-env.d.ts
1616

1717
# Generated Build Artifacts
18-
apps/site/generated
18+
platforms/cloudflare/generated
1919

2020
# Test Runner
2121
junit.xml

apps/site/app/[locale]/layout.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { availableLocales, defaultLocale } from '@node-core/website-i18n';
2-
import { Analytics } from '@vercel/analytics/react';
3-
import { SpeedInsights } from '@vercel/speed-insights/next';
42
import classNames from 'classnames';
53
import { NextIntlClientProvider } from 'next-intl';
64

75
import BaseLayout from '#site/layouts/Base';
8-
import { VERCEL_ENV } from '#site/next.constants.mjs';
96
import { IBM_PLEX_MONO, OPEN_SANS } from '#site/next.fonts';
7+
import PlatformAnalytics from '#site/platform/analytics';
108
import { ThemeProvider } from '#site/providers/themeProvider';
119

1210
import type { FC, PropsWithChildren } from 'react';
@@ -46,12 +44,7 @@ const RootLayout: FC<RootLayoutProps> = async ({ children, params }) => {
4644
href="https://social.lfx.dev/@nodejs"
4745
/>
4846

49-
{VERCEL_ENV && (
50-
<>
51-
<Analytics />
52-
<SpeedInsights />
53-
</>
54-
)}
47+
<PlatformAnalytics />
5548
</body>
5649
</html>
5750
);

apps/site/eslint.config.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@ import baseConfig from '../../eslint.config.js';
66

77
export default baseConfig.concat([
88
{
9-
ignores: [
10-
'pages/en/blog/**/*.{md,mdx}/**',
11-
'public',
12-
'next-env.d.ts',
13-
// The worker entrypoint is bundled by wrangler, not tsc. Its imports
14-
// trigger a tsc crash (see tsconfig.json), so it is excluded from both
15-
// type checking and ESLint's type-aware linting.
16-
'cloudflare/worker-entrypoint.ts',
17-
],
9+
ignores: ['pages/en/blog/**/*.{md,mdx}/**', 'public', 'next-env.d.ts'],
1810
},
1911

2012
eslintReact.configs['recommended-typescript'],

apps/site/instrumentation.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
export async function register() {
2-
if (!('Cloudflare' in globalThis)) {
3-
// Note: we don't need to set up the Vercel OTEL if the application is running on Cloudflare
4-
const { registerOTel } = await import('@vercel/otel');
5-
registerOTel({ serviceName: 'nodejs-org' });
1+
export const register = async () => {
2+
// `NEXT_PUBLIC_DEPLOYMENT_PLATFORM` is a build-time constant (see
3+
// `next.config.mjs`), so the platforms we are not building for are never
4+
// bundled. Only Vercel currently provides instrumentation.
5+
if (process.env.NEXT_PUBLIC_DEPLOYMENT_PLATFORM === 'vercel') {
6+
const { register } =
7+
await import('@node-core/platform-vercel/instrumentation');
8+
9+
register();
610
}
7-
}
11+
};

apps/site/mdx/plugins.mjs

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

10-
import { createVfsTwoslasher } from './create-vfs-twoslasher.mjs';
1110
import remarkTableTitles from '../util/table';
1211

13-
// TODO(@avivkeller): When available, use `OPEN_NEXT_CLOUDFLARE` environment
14-
// variable for detection instead of current method, which will enable better
15-
// tree-shaking.
16-
// Reference: https://github.com/nodejs/nodejs.org/pull/7896#issuecomment-3009480615
17-
const OPEN_NEXT_CLOUDFLARE = 'Cloudflare' in global;
18-
19-
// Shiki is created out here to avoid an async rehype plugin
20-
const singletonShiki = await rehypeShikiji({
21-
// We use the faster WASM engine on the server instead of the web-optimized version.
22-
//
23-
// Currently we fall back to the JavaScript RegEx engine
24-
// on Cloudflare workers because `shiki/wasm` requires loading via
25-
// `WebAssembly.instantiate` with custom imports, which Cloudflare doesn't support
26-
// for security reasons.
27-
wasm: !OPEN_NEXT_CLOUDFLARE,
28-
29-
twoslash: true,
30-
31-
// On Cloudflare Workers, the default filesystem-backed Twoslash cannot work
32-
// because there is no real filesystem. Instead, we provide a custom twoslasher
33-
// backed by an in-memory VFS pre-populated at build time with TypeScript
34-
// lib declarations and @types/node.
35-
twoslashOptions: OPEN_NEXT_CLOUDFLARE
36-
? { twoslasher: await createVfsTwoslasher() }
37-
: undefined,
38-
});
12+
// Shiki is created out here to avoid an async rehype plugin.
13+
//
14+
// `NEXT_PUBLIC_DEPLOYMENT_PLATFORM` is a build-time constant (see
15+
// `next.config.mjs`), so the Cloudflare-specific options (which cannot use
16+
// the WASM engine nor a filesystem-backed Twoslash) are only bundled on
17+
// Cloudflare builds; everywhere else we use the faster WASM engine.
18+
const singletonShiki = await rehypeShikiji(
19+
process.env.NEXT_PUBLIC_DEPLOYMENT_PLATFORM === 'cloudflare'
20+
? (await import('@node-core/platform-cloudflare/shiki.mjs')).shikiOptions
21+
: { wasm: true, twoslash: true }
22+
);
3923

4024
/**
4125
* Provides all our Rehype Plugins that are used within MDX

apps/site/next.config.mjs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
'use strict';
22
import createNextIntlPlugin from 'next-intl/plugin';
33

4-
import { OPEN_NEXT_CLOUDFLARE } from './next.constants.cloudflare.mjs';
54
import { BASE_PATH, ENABLE_STATIC_EXPORT } from './next.constants.mjs';
6-
import { getImagesConfig } from './next.image.config.mjs';
75
import { redirects, rewrites } from './next.rewrites.mjs';
86

9-
const getDeploymentId = async () => {
10-
if (OPEN_NEXT_CLOUDFLARE) {
11-
// If we're building for the Cloudflare deployment we want to set
12-
// an appropriate deploymentId (needed for skew protection)
13-
const openNextAdapter = await import('@opennextjs/cloudflare');
7+
/**
8+
* The deployment platform this build targets. All platform-specific behavior
9+
* lives in the `platforms/*` workspace packages; see `platforms/README.md`.
10+
*
11+
* Vercel deployments are detected automatically; the Cloudflare build scripts
12+
* set the variable themselves.
13+
*/
14+
const DEPLOYMENT_PLATFORM =
15+
process.env.NEXT_PUBLIC_DEPLOYMENT_PLATFORM ||
16+
(process.env.VERCEL ? 'vercel' : 'default');
1417

15-
return openNextAdapter.getDeploymentId();
16-
}
17-
18-
return undefined;
19-
};
18+
const { default: platformConfig } = await import(
19+
`@node-core/platform-${DEPLOYMENT_PLATFORM}/next.config.mjs`
20+
);
2021

2122
/** @type {import('next').NextConfig} */
2223
const nextConfig = {
@@ -27,8 +28,19 @@ const nextConfig = {
2728
// We allow the BASE_PATH to be overridden in case that the Website
2829
// is being built on a subdirectory (e.g. /nodejs-website)
2930
basePath: BASE_PATH,
30-
// Vercel/Next.js Image Optimization Settings
31-
images: getImagesConfig(),
31+
images: {
32+
// We disable image optimisation during static export builds
33+
unoptimized: ENABLE_STATIC_EXPORT,
34+
// We add it to the remote pattern for the static images we use from multiple sources
35+
// to be marked as safe sources (these come from Markdown files)
36+
remotePatterns: [
37+
'https://avatars.githubusercontent.com/**',
38+
'https://bestpractices.coreinfrastructure.org/**',
39+
'https://raw.githubusercontent.com/nodejs/**',
40+
'https://user-images.githubusercontent.com/**',
41+
'https://website-assets.oramasearch.com/**',
42+
].map(url => new URL(url)),
43+
},
3244
serverExternalPackages: ['twoslash'],
3345
outputFileTracingIncludes: {
3446
// Twoslash needs TypeScript declarations to function, and, by default, Next.js
@@ -81,8 +93,18 @@ const nextConfig = {
8193
// Faster Development Servers with Turbopack
8294
turbopackFileSystemCacheForDev: true,
8395
},
84-
deploymentId: await getDeploymentId(),
8596
};
8697

8798
const withNextIntl = createNextIntlPlugin('./i18n.tsx');
88-
export default withNextIntl(nextConfig);
99+
100+
export default withNextIntl({
101+
...nextConfig,
102+
...platformConfig,
103+
env: {
104+
// Inlined into the bundles at build time so runtime code (e.g.
105+
// `#site/platform/analytics`) can branch on the platform, letting
106+
// bundlers drop the branches (and packages) of the other platforms.
107+
NEXT_PUBLIC_DEPLOYMENT_PLATFORM: DEPLOYMENT_PLATFORM,
108+
...platformConfig.env,
109+
},
110+
});

apps/site/next.constants.cloudflare.mjs

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

0 commit comments

Comments
 (0)