Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apps/site/next.config.mjs @nodejs/web-infra
apps/site/next.dynamic.mjs @nodejs/web-infra
apps/site/middleware.ts @nodejs/web-infra
apps/site/navigation.mjs @nodejs/web-infra
apps/site/playwright.config.ts @nodejs/web-infra
apps/site/playwright.config.mjs @nodejs/web-infra

# Package Ecosystem
package.json @nodejs/nodejs-website
Expand All @@ -27,9 +27,7 @@ turbo.json @nodejs/nodejs-website @nodejs/web-infra
crowdin.yml @nodejs/web-infra
apps/site/redirects.json @nodejs/web-infra
apps/site/site.json @nodejs/web-infra
apps/site/wrangler.jsonc @nodejs/web-infra
apps/site/open-next.config.ts @nodejs/web-infra
apps/site/redirects.json @nodejs/web-infra
platforms @nodejs/web-infra

# Critical Documents
LICENSE @nodejs/tsc
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:

- name: Build Next.js
# We want a ISR build on CI to ensure that regular Next.js builds work as expected.
run: node_modules/.bin/turbo build --cache-dir=.turbo/cache
run: node_modules/.bin/turbo build --filter=@node-core/website --cache-dir=.turbo/cache
env:
# We want to ensure we have enough RAM allocated to the Node.js process
# this should be a last resort in case by any chances the build memory gets too high
Expand All @@ -76,7 +76,7 @@ jobs:

- name: Build Next.js (Static Export)
# We want to generate a static build, as it is a requirement of our website.
run: node_modules/.bin/turbo deploy --cache-dir=.turbo/cache
run: node_modules/.bin/turbo deploy --filter=@node-core/website --cache-dir=.turbo/cache
env:
# We want to ensure we have enough RAM allocated to the Node.js process
# this should be a last resort in case by any chances the build memory gets too high
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/playwright-cloudflare-open-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ jobs:
working-directory: apps/site
run: node_modules/.bin/playwright install --with-deps

- name: Build open-next site
run: node_modules/.bin/turbo build --filter=@node-core/platform-cloudflare --cache-dir=.turbo/cache

- name: Run Playwright tests
working-directory: apps/site
run: node --run playwright
env:
PLAYWRIGHT_RUN_CLOUDFLARE_PREVIEW: true
PLAYWRIGHT_BASE_URL: http://127.0.0.1:8787
run: pnpm --filter=@node-core/platform-cloudflare test:e2e

- name: Upload Playwright test results
if: always()
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/tmp-cloudflare-open-next-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,11 @@ jobs:
- name: Install packages
run: pnpm install --frozen-lockfile

- name: Build blog data
working-directory: apps/site
run: node --run build:blog-data

- name: Build open-next site
working-directory: apps/site
run: node --run cloudflare:build:worker
run: node_modules/.bin/turbo build --filter=@node-core/platform-cloudflare --cache-dir=.turbo/cache

- name: Deploy open-next site
working-directory: apps/site
run: node --run cloudflare:deploy
run: pnpm --filter=@node-core/platform-cloudflare deploy
env:
CF_WORKERS_SCRIPTS_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apps/site/public/blog-data.json
apps/site/next-env.d.ts

# Generated Build Artifacts
apps/site/generated
platforms/cloudflare/generated

# Test Runner
junit.xml
Expand Down
11 changes: 2 additions & 9 deletions apps/site/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import PlatformAnalytics from '#platform/analytics';
import { availableLocales, defaultLocale } from '@node-core/website-i18n';
import { Analytics } from '@vercel/analytics/react';
import { SpeedInsights } from '@vercel/speed-insights/next';
import classNames from 'classnames';
import { NextIntlClientProvider } from 'next-intl';

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

Expand Down Expand Up @@ -46,12 +44,7 @@ const RootLayout: FC<RootLayoutProps> = async ({ children, params }) => {
href="https://social.lfx.dev/@nodejs"
/>

{VERCEL_ENV && (
<>
<Analytics />
<SpeedInsights />
</>
)}
<PlatformAnalytics />
</body>
</html>
);
Expand Down
10 changes: 1 addition & 9 deletions apps/site/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ import baseConfig from '../../eslint.config.js';

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

eslintReact.configs['recommended-typescript'],
Expand Down
8 changes: 1 addition & 7 deletions apps/site/instrumentation.ts
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';
30 changes: 3 additions & 27 deletions apps/site/mdx/plugins.mjs
Original file line number Diff line number Diff line change
@@ -1,41 +1,17 @@
'use strict';

import { shikiOptions } from '#platform/shiki.mjs';
import rehypeShikiji from '@node-core/rehype-shiki/plugin';
import remarkHeadings from '@vcarl/remark-headings';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypeSlug from 'rehype-slug';
import remarkGfm from 'remark-gfm';
import readingTime from 'remark-reading-time';

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

// TODO(@avivkeller): When available, use `OPEN_NEXT_CLOUDFLARE` environment
// variable for detection instead of current method, which will enable better
// tree-shaking.
// Reference: https://github.com/nodejs/nodejs.org/pull/7896#issuecomment-3009480615
const OPEN_NEXT_CLOUDFLARE = 'Cloudflare' in global;

// Shiki is created out here to avoid an async rehype plugin
const singletonShiki = await rehypeShikiji({
// We use the faster WASM engine on the server instead of the web-optimized version.
//
// Currently we fall back to the JavaScript RegEx engine
// on Cloudflare workers because `shiki/wasm` requires loading via
// `WebAssembly.instantiate` with custom imports, which Cloudflare doesn't support
// for security reasons.
wasm: !OPEN_NEXT_CLOUDFLARE,

twoslash: true,

// On Cloudflare Workers, the default filesystem-backed Twoslash cannot work
// because there is no real filesystem. Instead, we provide a custom twoslasher
// backed by an in-memory VFS pre-populated at build time with TypeScript
// lib declarations and @types/node.
twoslashOptions: OPEN_NEXT_CLOUDFLARE
? { twoslasher: await createVfsTwoslasher() }
: undefined,
});
// Shiki is created out here to avoid an async rehype plugin.
const singletonShiki = await rehypeShikiji(shikiOptions);

/**
* Provides all our Rehype Plugins that are used within MDX
Expand Down
34 changes: 16 additions & 18 deletions apps/site/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
'use strict';
import platformConfig from '#platform/next.config.mjs';
import createNextIntlPlugin from 'next-intl/plugin';

import { OPEN_NEXT_CLOUDFLARE } from './next.constants.cloudflare.mjs';
import { BASE_PATH, ENABLE_STATIC_EXPORT } from './next.constants.mjs';
import { getImagesConfig } from './next.image.config.mjs';
import { redirects, rewrites } from './next.rewrites.mjs';

const getDeploymentId = async () => {
if (OPEN_NEXT_CLOUDFLARE) {
// If we're building for the Cloudflare deployment we want to set
// an appropriate deploymentId (needed for skew protection)
const openNextAdapter = await import('@opennextjs/cloudflare');

return openNextAdapter.getDeploymentId();
}

return undefined;
};

/** @type {import('next').NextConfig} */
const nextConfig = {
// Full Support of React 18 SSR and Streaming
Expand All @@ -27,8 +14,19 @@ const nextConfig = {
// We allow the BASE_PATH to be overridden in case that the Website
// is being built on a subdirectory (e.g. /nodejs-website)
basePath: BASE_PATH,
// Vercel/Next.js Image Optimization Settings
images: getImagesConfig(),
images: {
// We disable image optimisation during static export builds
unoptimized: ENABLE_STATIC_EXPORT,
// We add it to the remote pattern for the static images we use from multiple sources
// to be marked as safe sources (these come from Markdown files)
remotePatterns: [
'https://avatars.githubusercontent.com/**',
'https://bestpractices.coreinfrastructure.org/**',
'https://raw.githubusercontent.com/nodejs/**',
'https://user-images.githubusercontent.com/**',
'https://website-assets.oramasearch.com/**',
].map(url => new URL(url)),
},
serverExternalPackages: ['twoslash'],
outputFileTracingIncludes: {
// Twoslash needs TypeScript declarations to function, and, by default, Next.js
Expand Down Expand Up @@ -81,8 +79,8 @@ const nextConfig = {
// Faster Development Servers with Turbopack
turbopackFileSystemCacheForDev: true,
},
deploymentId: await getDeploymentId(),
};

const withNextIntl = createNextIntlPlugin('./i18n.tsx');
export default withNextIntl(nextConfig);

export default withNextIntl({ ...nextConfig, ...platformConfig });
12 changes: 0 additions & 12 deletions apps/site/next.constants.cloudflare.mjs

This file was deleted.

23 changes: 2 additions & 21 deletions apps/site/next.constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
*/
export const IS_DEV_ENV = process.env.NODE_ENV === 'development';

/**
* This is used for telling Next.js if the Website is deployed on Vercel
*
* Can be used for conditionally enabling features that we know are Vercel only
*
* @see https://vercel.com/docs/projects/environment-variables/system-environment-variables#VERCEL_ENV
*/
export const VERCEL_ENV = process.env.VERCEL_ENV || undefined;

/**
* This is used for telling Next.js to do a Static Export Build of the Website
*
Expand All @@ -39,19 +30,9 @@ export const ENABLE_STATIC_EXPORT_LOCALE =

/**
* This is used for any place that requires the full canonical URL path for the Node.js Website (and its deployment), such as for example, the Node.js RSS Feed.
*
* This variable can either come from the Vercel Deployment as `NEXT_PUBLIC_VERCEL_URL` or from the `NEXT_PUBLIC_BASE_URL` Environment Variable that is manually defined
* by us if necessary. Otherwise it will fallback to the default Node.js Website URL.
*
* @TODO: We should get rid of needing to rely on `VERCEL_URL` for deployment URL.
*
* @see https://vercel.com/docs/concepts/projects/environment-variables/system-environment-variables#framework-environment-variables
*/
export const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL
? process.env.NEXT_PUBLIC_BASE_URL
: process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: 'https://nodejs.org';
export const BASE_URL =
process.env.NEXT_PUBLIC_BASE_URL || 'https://nodejs.org';

/**
* This is used for any place that requires the Node.js distribution URL (which by default is nodejs.org/dist)
Expand Down
33 changes: 0 additions & 33 deletions apps/site/next.image.config.mjs

This file was deleted.

Loading
Loading