Skip to content

Commit a5baa44

Browse files
committed
chore(monorepo): break out platform-specific code
1 parent ee114b2 commit a5baa44

49 files changed

Lines changed: 517 additions & 863 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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ jobs:
5050
working-directory: apps/site
5151
run: node_modules/.bin/playwright install --with-deps
5252

53+
- name: Build OpenNext worker
54+
working-directory: platforms/cloudflare
55+
run: node --run build
56+
5357
- name: Run Playwright tests
54-
working-directory: apps/site
58+
working-directory: platforms/cloudflare
5559
run: node --run playwright
56-
env:
57-
PLAYWRIGHT_RUN_CLOUDFLARE_PREVIEW: true
58-
PLAYWRIGHT_BASE_URL: http://127.0.0.1:8787
5960

6061
- name: Upload Playwright test results
6162
if: always()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ 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+
working-directory: platforms/cloudflare
61+
run: node --run build
6262

6363
- name: Deploy open-next site
64-
working-directory: apps/site
65-
run: node --run cloudflare:deploy
64+
working-directory: platforms/cloudflare
65+
run: node --run deploy
6666
env:
6767
CF_WORKERS_SCRIPTS_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
6868
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

.gitignore

Lines changed: 3 additions & 3 deletions
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
@@ -44,8 +44,8 @@ tsconfig.tsbuildinfo
4444
dist/
4545

4646
# Cloudflare Build Output
47-
apps/site/.open-next
48-
apps/site/.wrangler
47+
.open-next
48+
.wrangler
4949

5050
## Playwright
5151
test-results

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
import PlatformAnalytics from '#platform/analytics.tsx';
12
import { availableLocales, defaultLocale } from '@node-core/website-i18n';
2-
import { Analytics } from '@vercel/analytics/react';
3-
import { SpeedInsights } from '@vercel/speed-insights/next';
43
import classNames from 'classnames';
54
import { NextIntlClientProvider } from 'next-intl';
65

76
import BaseLayout from '#site/layouts/Base';
8-
import { VERCEL_ENV } from '#site/next.constants.mjs';
97
import { IBM_PLEX_MONO, OPEN_SANS } from '#site/next.fonts';
108
import { ThemeProvider } from '#site/providers/themeProvider';
119

@@ -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: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
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' });
6-
}
7-
}
1+
export { register } from '#platform/instrumentation.ts';

apps/site/mdx/plugins.mjs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,17 @@
11
'use strict';
22

3+
import { shikiOptions } from '#platform/mdx.mjs';
34
import rehypeShikiji from '@node-core/rehype-shiki/plugin';
45
import remarkHeadings from '@vcarl/remark-headings';
56
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
67
import rehypeSlug from 'rehype-slug';
78
import remarkGfm from 'remark-gfm';
89
import readingTime from 'remark-reading-time';
910

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

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-
1913
// 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-
});
14+
const singletonShiki = await rehypeShikiji(shikiOptions);
3915

4016
/**
4117
* Provides all our Rehype Plugins that are used within MDX

apps/site/next.config.mjs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,21 @@
11
'use strict';
2+
3+
import platform from '#platform/next.config.mjs';
24
import createNextIntlPlugin from 'next-intl/plugin';
35

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

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');
14-
15-
return openNextAdapter.getDeploymentId();
16-
}
17-
18-
return undefined;
19-
};
20-
219
/** @type {import('next').NextConfig} */
2210
const nextConfig = {
11+
...platform,
2312
// Full Support of React 18 SSR and Streaming
2413
reactCompiler: true,
2514
// We don't want to redirect with trailing slashes
2615
skipTrailingSlashRedirect: true,
2716
// We allow the BASE_PATH to be overridden in case that the Website
2817
// is being built on a subdirectory (e.g. /nodejs-website)
2918
basePath: BASE_PATH,
30-
// Vercel/Next.js Image Optimization Settings
31-
images: getImagesConfig(),
3219
serverExternalPackages: ['twoslash'],
3320
outputFileTracingIncludes: {
3421
// Twoslash needs TypeScript declarations to function, and, by default, Next.js
@@ -81,7 +68,6 @@ const nextConfig = {
8168
// Faster Development Servers with Turbopack
8269
turbopackFileSystemCacheForDev: true,
8370
},
84-
deploymentId: await getDeploymentId(),
8571
};
8672

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

apps/site/next.constants.cloudflare.mjs

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

0 commit comments

Comments
 (0)