diff --git a/.gitignore b/.gitignore index 4a9bde3abf58c..855c41a9a9e92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,19 @@ # Commonly ignored Node.js files -node_modules/ +node_modules npm-debug.log -.npm/ +.npm # OSX system files, the bane of our existence .DS_Store .AppleDouble .LSOverride -# Next.js files +# Next.js Build Output .next build + +# Next.js Generated Files +public/robots.txt public/sitemap.xml public/en/feed/*.xml pages/en/blog/year-[0-9][0-9][0-9][0-9].md @@ -26,8 +29,6 @@ coverage # Storybook storybook-static -# Vercel Config +# Vercel Files .vercel - -# TurboRepo .turbo diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 23c9cf520f327..eeb4c55d01b99 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -85,8 +85,9 @@ npx turbo format - `npx turbo serve` runs Next.js's Local Development Server, listening by default on `http://localhost:3000/`. - `npx turbo build` builds the Application on Production mode. The output is by default within `.next` folder. -- `npx turbo export` exports the website from the `.next` into a fully static website. The output is by default within `build` folder. - - This is what it's used to deploy the website on our current Node.js servers. + - This is used for the Node.js Vercel Deployments (Preview & Production) +- `npx turbo deploy` builds the Application on Export Production Mode. The output is by default within `build` folder. + - This is used for the Node.js Legacy Website Server (DigitalOcean) - `npx turbo start` starts a web server running serving the built content from `npx turbo build` #### Other CLI options diff --git a/next-sitemap.config.js b/next-sitemap.config.js deleted file mode 100644 index 5b3e66d1b9ccd..0000000000000 --- a/next-sitemap.config.js +++ /dev/null @@ -1,16 +0,0 @@ -/** @type {import('next-sitemap').IConfig} */ -module.exports = { - siteUrl: 'https://nodejs.org', - generateRobotsTxt: true, - trailingSlash: false, - generateIndexSitemap: false, - robotsTxtOptions: { - policies: [ - { - userAgent: '*', - disallow: ['/dist/', '/docs/'], - allow: ['/dist/latest/', '/dist/latest/docs/api/', '/api/'], - }, - ], - }, -}; diff --git a/next-sitemap.config.mjs b/next-sitemap.config.mjs new file mode 100644 index 0000000000000..5e29acebd0ca0 --- /dev/null +++ b/next-sitemap.config.mjs @@ -0,0 +1,26 @@ +// This is used for telling Next.js to to a Static Export Build of the Website +// We use this within this config file to determine the output directory of this generated sitemap files +const enableStaticExport = process.env.NEXT_STATIC_EXPORT === 'true'; + +/** @type {import('next-sitemap').IConfig} */ +const sitemapConfig = { + siteUrl: 'https://nodejs.org', + changefreq: 'always', + trailingSlash: false, + generateRobotsTxt: true, + generateIndexSitemap: false, + outDir: enableStaticExport ? 'build' : 'public', + sourceDir: enableStaticExport ? 'build' : '.next', + output: enableStaticExport ? 'export' : undefined, + robotsTxtOptions: { + policies: [ + { + userAgent: '*', + disallow: ['/dist/', '/docs/'], + allow: ['/dist/latest/', '/dist/latest/docs/api/', '/api/'], + }, + ], + }, +}; + +export default sitemapConfig; diff --git a/next.config.mjs b/next.config.mjs index 7579cee86f6f2..058ca6fc942b8 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -18,12 +18,22 @@ const withNextra = nextra({ }, }); -const enableImageOptimization = - process.env.NEXT_ENABLE_IMAGE_OPTIMIZATION === 'true'; +// This is used for telling Next.js to to a Static Export Build of the Website +// This is used for static/without a Node.js server hosting, such as on our +// legacy Website Build Environment on Node.js's DigitalOcean Droplet. +// Note.: Image optimization is also disabled through this process +const enableStaticExport = process.env.NEXT_STATIC_EXPORT === 'true'; + +// Supports a manuall override of the base path of the website +// This is useful when running the deployment on a subdirectory +// of a domain, such as when hosted on GitHub Pages. +const basePath = String(process.env.NEXT_BASE_PATH || ''); export default withNextra({ + basePath, trailingSlash: false, - images: { unoptimized: !enableImageOptimization }, outputFileTracing: false, - basePath: String(process.env.NEXT_BASE_PATH || ''), + distDir: enableStaticExport ? 'build' : '.next', + output: enableStaticExport ? 'export' : undefined, + images: { unoptimized: enableStaticExport }, }); diff --git a/package-lock.json b/package-lock.json index df1709ed937c1..3155b0b438c49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "highlight.js": "^11.8.0", "isomorphic-dompurify": "^1.3.0", "next": "^13.3.4", - "next-sitemap": "^4.0.9", + "next-sitemap": "^4.1.3", "next-themes": "^0.2.1", "nextra": "^2.4.2", "node-version-data": "^1.1.0", @@ -78,7 +78,7 @@ "stylelint-config-recommended-scss": "^11.0.0", "stylelint-order": "^6.0.3", "stylelint-selector-bem-pattern": "^2.1.1", - "turbo": "^1.9.3", + "turbo": "^1.9.8", "typescript": "^5.0.4" }, "engines": { @@ -19098,16 +19098,17 @@ } }, "node_modules/next-sitemap": { - "version": "4.0.9", - "resolved": "https://registry.npmjs.org/next-sitemap/-/next-sitemap-4.0.9.tgz", - "integrity": "sha512-8pbcEe4vrmgGEc3beVbrSqd8mTQ9lCsGxP+AOlArrGmeLkKD4TbSR41R2unQHHSTkBG8cQ/7gjKkdLBlzwtu6g==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/next-sitemap/-/next-sitemap-4.1.3.tgz", + "integrity": "sha512-eCvbXMCqbD/rYx912y4FzGOqPCbWOIBL4UkgVY5R15eCXygKFKWzEVZGPNVBDu2KVpRCeG943NibOchfyQGDhQ==", "funding": [ { "url": "https://github.com/iamvishnusankar/next-sitemap.git" } ], "dependencies": { - "@corex/deepmerge": "^4.0.37", + "@corex/deepmerge": "^4.0.43", + "fast-glob": "^3.2.12", "minimist": "^1.2.8" }, "bin": { @@ -24779,27 +24780,27 @@ } }, "node_modules/turbo": { - "version": "1.9.6", - "resolved": "https://registry.npmjs.org/turbo/-/turbo-1.9.6.tgz", - "integrity": "sha512-mLbCIAYNbSm60kVhBiAr+YA1BYpPObS/y7rqw1hjh36ZdJDp35lUSeqdBs6oGt0Y4hnmN4ZeIXu8zMVRR03/vw==", + "version": "1.9.8", + "resolved": "https://registry.npmjs.org/turbo/-/turbo-1.9.8.tgz", + "integrity": "sha512-dTouGZBm4a2fE0OPafcTQERCp4i3ZOow0Pr0JlOyxKmzJy0JRwXypH013kbZoK6k1ET5tS/g9rwUXIM/AmWXXQ==", "dev": true, "hasInstallScript": true, "bin": { "turbo": "bin/turbo" }, "optionalDependencies": { - "turbo-darwin-64": "1.9.6", - "turbo-darwin-arm64": "1.9.6", - "turbo-linux-64": "1.9.6", - "turbo-linux-arm64": "1.9.6", - "turbo-windows-64": "1.9.6", - "turbo-windows-arm64": "1.9.6" + "turbo-darwin-64": "1.9.8", + "turbo-darwin-arm64": "1.9.8", + "turbo-linux-64": "1.9.8", + "turbo-linux-arm64": "1.9.8", + "turbo-windows-64": "1.9.8", + "turbo-windows-arm64": "1.9.8" } }, "node_modules/turbo-darwin-64": { - "version": "1.9.6", - "resolved": "https://registry.npmjs.org/turbo-darwin-64/-/turbo-darwin-64-1.9.6.tgz", - "integrity": "sha512-9jmxyCAcPrJiPD/EmtK2tObrPGblmyORCgNgtcw1iozcfC7kqungWTfbnHrvTNUfUmVhH0sA3BGzshpuslbQHg==", + "version": "1.9.8", + "resolved": "https://registry.npmjs.org/turbo-darwin-64/-/turbo-darwin-64-1.9.8.tgz", + "integrity": "sha512-PkTdBjPfgpj/Dob/6SjkzP0BBP80/KmFjLEocXVEECCLJE6tHKbWLRdvc79B0N6SufdYdZ1uvvoU3KPtBokSPw==", "cpu": [ "x64" ], @@ -24810,9 +24811,9 @@ ] }, "node_modules/turbo-darwin-arm64": { - "version": "1.9.6", - "resolved": "https://registry.npmjs.org/turbo-darwin-arm64/-/turbo-darwin-arm64-1.9.6.tgz", - "integrity": "sha512-5f8ajEi8mOdAZ0AXavu/TzkHGEUi7tw+paefff7KK+XTUrdeyTlf8ULiTI+r97uH1jsYeTeL4JPu9IsEx+bL6g==", + "version": "1.9.8", + "resolved": "https://registry.npmjs.org/turbo-darwin-arm64/-/turbo-darwin-arm64-1.9.8.tgz", + "integrity": "sha512-sLwqOx3XV57QCEoJM9GnDDnnqidG8wf29ytxssBaWHBdeJTjupyrmzTUrX+tyKo3Q+CjWvbPLyqVqxT4g5NuXQ==", "cpu": [ "arm64" ], @@ -24823,9 +24824,9 @@ ] }, "node_modules/turbo-linux-64": { - "version": "1.9.6", - "resolved": "https://registry.npmjs.org/turbo-linux-64/-/turbo-linux-64-1.9.6.tgz", - "integrity": "sha512-UrCDMl2Nqd/kxNEJonqvDg8nmZU4UggVQTmqcdYyuOiCA3H98jxggQqZh1VGeF23XDbCWHSQjnbkLeoUvQJWKw==", + "version": "1.9.8", + "resolved": "https://registry.npmjs.org/turbo-linux-64/-/turbo-linux-64-1.9.8.tgz", + "integrity": "sha512-AMg6VT6sW7aOD1uOs5suxglXfTYz9T0uVyKGKokDweGOYTWmuTMGU5afUT1tYRUwQ+kVPJI+83Atl5Ob0oBsgw==", "cpu": [ "x64" ], @@ -24836,9 +24837,9 @@ ] }, "node_modules/turbo-linux-arm64": { - "version": "1.9.6", - "resolved": "https://registry.npmjs.org/turbo-linux-arm64/-/turbo-linux-arm64-1.9.6.tgz", - "integrity": "sha512-oOxAT6lNiMpYVZPWzFNsUvC2LQgKYyH4aBnkeoBnjuAUk8BK5AhUWSWl4QlfTcBWW4LnjDPeZQKrbnxvHhPVsw==", + "version": "1.9.8", + "resolved": "https://registry.npmjs.org/turbo-linux-arm64/-/turbo-linux-arm64-1.9.8.tgz", + "integrity": "sha512-tLnxFv+OIklwTjiOZ8XMeEeRDAf150Ry4BCivNwgTVFAqQGEqkFP6KGBy56hb5RRF1frPQpoPGipJNVm7c8m1w==", "cpu": [ "arm64" ], @@ -24849,9 +24850,9 @@ ] }, "node_modules/turbo-windows-64": { - "version": "1.9.6", - "resolved": "https://registry.npmjs.org/turbo-windows-64/-/turbo-windows-64-1.9.6.tgz", - "integrity": "sha512-65UxLL1vb5RItzJYNerO5c+yPMzSnD+GvJxfBZIvAwSnb+4ulhPRHzQOYinVq4PZ2DosBZOorWPRf97POmhvog==", + "version": "1.9.8", + "resolved": "https://registry.npmjs.org/turbo-windows-64/-/turbo-windows-64-1.9.8.tgz", + "integrity": "sha512-r3pCjvXTMR7kq2E3iqwFlN1R7pFO/TOsuUjMhOSPP7HwuuUIinAckU4I9foM3q7ZCQd1XXScBUt3niDyHijAqQ==", "cpu": [ "x64" ], @@ -24862,9 +24863,9 @@ ] }, "node_modules/turbo-windows-arm64": { - "version": "1.9.6", - "resolved": "https://registry.npmjs.org/turbo-windows-arm64/-/turbo-windows-arm64-1.9.6.tgz", - "integrity": "sha512-aF9VzYT+vaKNbZGDccN7AYrNhph4gr6yOFN7GtTr777IwS5FGW7evku7RScsua5r2HwVKvBO2WjyadpbXuoOOQ==", + "version": "1.9.8", + "resolved": "https://registry.npmjs.org/turbo-windows-arm64/-/turbo-windows-arm64-1.9.8.tgz", + "integrity": "sha512-CWzRbX2TM5IfHBC6uWM659qUOEDC4h0nn16ocG8yIq1IF3uZMzKRBHgGOT5m1BHom+R08V0NcjTmPRoqpiI0dg==", "cpu": [ "arm64" ], diff --git a/package.json b/package.json index 485444bcd7a6d..826d8f1183a90 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,10 @@ "node": "v18" }, "scripts": { - "serve": "cross-env NODE_ENV=development NODE_NO_WARNINGS=1 next dev", - "build": "cross-env NODE_ENV=production NODE_NO_WARNINGS=1 next build", - "postbuild": "next-sitemap", - "start": "cross-env NODE_ENV=production NODE_NO_WARNINGS=1 next start", - "export": "cross-env NODE_NO_WARNINGS=1 next export -o build", - "deploy": "npm run build && npm run export", + "serve": "cross-env NODE_NO_WARNINGS=1 next dev", + "build": "cross-env NODE_NO_WARNINGS=1 next build", + "start": "cross-env NODE_NO_WARNINGS=1 next start", + "deploy": "cross-env NEXT_STATIC_EXPORT=true npm run build && cross-env NEXT_STATIC_EXPORT=true npm run scripts:sitemap", "lint:js": "eslint \"**/*.{js,jsx,ts,tsx}\" --cache --cache-file .eslintjscache --report-unused-disable-directives", "lint:md": "eslint \"**/*.{md,mdx}\" --cache --cache-file .eslintmdcache", "lint:scss": "stylelint --config .stylelintrc \"**/*.{css,sass,scss}\"", @@ -25,13 +23,14 @@ "prettier": "prettier . --check --cache --cache-strategy metadata", "prettier:fix": "npm run prettier -- --write", "format": "npm run prettier:fix && npm run lint:fix", - "scripts:release-post": "NODE_NO_WARNINGS=1 node scripts/release-post/index.mjs", "test": "cross-env NODE_NO_WARNINGS=1 jest --passWithNoTests", - "test:watch": "npm run test -- --watch", "test:ci": "npm run test -- --coverage", + "test:watch": "npm run test -- --watch", "test:snapshot": "npm run test -- --updateSnapshot", - "storybook": "cross-env NODE_ENV=development NODE_NO_WARNINGS=1 storybook dev -p 6006", - "storybook:build": "cross-env NODE_ENV=production NODE_NO_WARNINGS=1 storybook build" + "storybook": "cross-env NODE_NO_WARNINGS=1 storybook dev -p 6006", + "storybook:build": "cross-env NODE_NO_WARNINGS=1 storybook build", + "scripts:release-post": "cross-env NODE_NO_WARNINGS=1 node scripts/release-post/index.mjs", + "scripts:sitemap": "cross-env NODE_NO_WARNINGS=1 next-sitemap --config next-sitemap.config.mjs" }, "dependencies": { "@mdx-js/react": "^2.3.0", @@ -45,7 +44,7 @@ "highlight.js": "^11.8.0", "isomorphic-dompurify": "^1.3.0", "next": "^13.3.4", - "next-sitemap": "^4.0.9", + "next-sitemap": "^4.1.3", "next-themes": "^0.2.1", "nextra": "^2.4.2", "node-version-data": "^1.1.0", @@ -103,7 +102,7 @@ "stylelint-config-recommended-scss": "^11.0.0", "stylelint-order": "^6.0.3", "stylelint-selector-bem-pattern": "^2.1.1", - "turbo": "^1.9.3", + "turbo": "^1.9.8", "typescript": "^5.0.4" } } diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index 2077a13e9cf34..0000000000000 --- a/public/robots.txt +++ /dev/null @@ -1,13 +0,0 @@ -# * -User-agent: * -Allow: /dist/latest/ -Allow: /dist/latest/docs/api/ -Allow: /api/ -Disallow: /dist/ -Disallow: /docs/ - -# Host -Host: https://nodejs.org - -# Sitemaps -Sitemap: https://nodejs.org/sitemap.xml diff --git a/scripts/next-data/generatePreBuildFiles.mjs b/scripts/next-data/generatePreBuildFiles.mjs index a6a3d2ef2c20d..fa89cadc8bb4d 100644 --- a/scripts/next-data/generatePreBuildFiles.mjs +++ b/scripts/next-data/generatePreBuildFiles.mjs @@ -1,6 +1,6 @@ // @TODO: This is a temporary hack until we migrate to the `nodejs/nodejs.dev` codebase -import { writeFile } from 'fs/promises'; -import { join } from 'path'; +import { writeFile } from 'node:fs/promises'; +import { join } from 'node:path'; import { Feed } from 'feed'; import { getRelativePath } from './_helpers.mjs'; diff --git a/scripts/next-data/getBlogData.mjs b/scripts/next-data/getBlogData.mjs index 6ae5c64b634ef..08a63b4fca1a5 100644 --- a/scripts/next-data/getBlogData.mjs +++ b/scripts/next-data/getBlogData.mjs @@ -1,5 +1,5 @@ -import { readFile, readdir } from 'fs/promises'; -import { basename, extname, join } from 'path'; +import { readFile, readdir } from 'node:fs/promises'; +import { basename, extname, join } from 'node:path'; import graymatter from 'gray-matter'; import { diff --git a/scripts/next-data/getLocalisationData.mjs b/scripts/next-data/getLocalisationData.mjs index 6a950bed49ff7..cd1e7f0c57a86 100644 --- a/scripts/next-data/getLocalisationData.mjs +++ b/scripts/next-data/getLocalisationData.mjs @@ -1,7 +1,7 @@ -import { readdirSync } from 'fs'; -import { readFile } from 'fs/promises'; -import { basename, extname, join } from 'path'; -import { fileURLToPath } from 'url'; +import { readdirSync } from 'node:fs'; +import { readFile } from 'node:fs/promises'; +import { basename, extname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; // this allows us to get the current module working directory const __dirname = fileURLToPath(new URL('.', import.meta.url)); diff --git a/scripts/release-post/index.mjs b/scripts/release-post/index.mjs index 3acbd7202e9c4..466cc807969ff 100644 --- a/scripts/release-post/index.mjs +++ b/scripts/release-post/index.mjs @@ -20,10 +20,10 @@ 'use strict'; -import fs from 'fs'; -import path from 'path'; +import fs from 'node:fs'; +import path from 'node:path'; +import url from 'node:url'; import handlebars from 'handlebars'; -import { fileURLToPath } from 'node:url'; import downloadsTable from './downloadsTable.mjs'; import { getRelativePath } from '../next-data/_helpers.mjs'; @@ -259,7 +259,7 @@ export { // This allows us to verify that the script is being run directly from node.js/cli if (import.meta.url.startsWith('file:')) { - const modulePath = fileURLToPath(import.meta.url); + const modulePath = url.fileURLToPath(import.meta.url); if (process.argv[1] === modulePath) { explicitVersion(process.argv[2]) diff --git a/turbo.json b/turbo.json index c06f6c7303bc3..d78eaca9619f9 100644 --- a/turbo.json +++ b/turbo.json @@ -58,7 +58,7 @@ "tsconfig.json", "next.config.mjs", "next.data.mjs", - "next-sitemap.config.js", + "next-sitemap.config.mjs", "theme.tsx", "middleware.ts" ], @@ -76,7 +76,7 @@ "tsconfig.json", "next.config.mjs", "next.data.mjs", - "next-sitemap.config.js", + "next-sitemap.config.mjs", "theme.tsx", "middleware.ts" ],