diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d36cee2b5c875..f11129542d5c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -91,7 +91,8 @@ jobs: # We also use `--omit=dev` to avoid installing devDependencies as we don't need them during the build step run: npm i --no-audit --no-fund --userconfig=/dev/null --omit=dev - - name: Build Next.js + - name: Build Next.js (ISR) + # We want a ISR build on CI to ensure that regular Next.js builds work as expected. # We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user # the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job run: npx --package=turbo@latest -- turbo build ${{ needs.base.outputs.turbo_args }} @@ -100,9 +101,18 @@ jobs: # this should be a last resort in case by any chances the build memory gets too high # but in general this should never happen NODE_OPTIONS: '--max_old_space_size=4096' - # We want to avoid having Next.js's Telemetry to kick-in during this build - # See https://nextjs.org/telemetry - NEXT_TELEMETRY_DISABLED: 1 + + - name: Build Next.js (Static) + # We want a Static Buid on CI to ensure that the Static Exports are working as expected + # This build will use the existing cache created on the previous build above (ISR) + # We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user + # the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job + run: npx --package=turbo@latest -- turbo deploy ${{ needs.base.outputs.turbo_args }} + 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 + # but in general this should never happen + NODE_OPTIONS: '--max_old_space_size=4096' - name: Analyse Build id: analyse_build diff --git a/next.config.mjs b/next.config.mjs index ea3a751fdfcae..f0f3e3604abfb 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -42,11 +42,6 @@ const nextConfig = { // since we pass the fully-compiled MDX page from `MDXRemote` through // a page's static props. largePageDataBytes: 128 * 100000, - // We disable the bundling and tracing of some files on the Serverless & Edge Runtimes - // as otherwise they would explode the bundle size (server) and the tracing time - outputFileTracingExcludes: { - '*': ['./public/**', 'node_modules/**/@swc/core*'], - }, }, }; diff --git a/next.constants.mjs b/next.constants.mjs index 4d8041b92be8f..1949bd464ff39 100644 --- a/next.constants.mjs +++ b/next.constants.mjs @@ -91,6 +91,12 @@ export const DEFAULT_LOCALE_CODE = defaultLocale.code; */ export const LEGACY_JAVASCRIPT_FILE = `${BASE_PATH}/static/js/legacyMain.js`; +/** + * This is the current Node.js Working directory. We usually use it to resolve pathnames + * relative to the content of the Node.js Website. + */ +export const CURRENT_WORKING_DIRECTORY = process.cwd(); + /** * This is a list of all static routes or pages from the Website that we do not * want to allow to be statically built on our Static Export Build. diff --git a/next.dynamic.mjs b/next.dynamic.mjs index 1c64202530a62..685b58963b267 100644 --- a/next.dynamic.mjs +++ b/next.dynamic.mjs @@ -10,11 +10,15 @@ import rehypeSlug from 'rehype-slug'; import { serialize } from 'next-mdx-remote/serialize'; import { availableLocales } from './next.locales.mjs'; import { getMarkdownFiles } from './next.helpers.mjs'; -import { DEFAULT_LOCALE_CODE, MD_EXTENSION_REGEX } from './next.constants.mjs'; +import { + DEFAULT_LOCALE_CODE, + MD_EXTENSION_REGEX, + CURRENT_WORKING_DIRECTORY, +} from './next.constants.mjs'; // allows us to run a glob to get markdown files based on a language folder const getPathsByLanguage = async (locale = DEFAULT_LOCALE_CODE, ignored = []) => - getMarkdownFiles(process.cwd(), `pages/${locale}`, ignored); + getMarkdownFiles(CURRENT_WORKING_DIRECTORY, `pages/${locale}`, ignored); /** * This method is responsible for generating a Collection of all available paths that @@ -41,6 +45,7 @@ const getAllPaths = async () => { sourcePages.map(filename => { // remove the index.md(x) suffix from a pathname let pathname = filename.replace(MD_EXTENSION_REGEX, ''); + // remove trailing slash for correct Windows pathing of the index files if (pathname.length > 1 && pathname.endsWith(sep)) { pathname = pathname.substring(0, pathname.length - 1); @@ -110,7 +115,7 @@ export const getMarkdownFile = ( // gets the full pathname for the file (absolute path) metadata.filename = join( - process.cwd(), + CURRENT_WORKING_DIRECTORY, 'pages', localeToUse, route.filename diff --git a/pages/[...path].tsx b/pages/[...path].tsx index 2305f96c9561d..d9247e14438be 100644 --- a/pages/[...path].tsx +++ b/pages/[...path].tsx @@ -1,3 +1,4 @@ +import { sep } from 'node:path'; import Theme from '@/theme'; import * as nextDynamic from '@/next.dynamic.mjs'; import * as nextConstants from '@/next.constants.mjs'; @@ -28,7 +29,9 @@ const getRouteWrite = (pathname: string) => // This maps a pathname into an actual route object that can be used const mapPathnameToRoute = (pathname: string) => ({ - params: { path: pathname.split('/') }, + // we use a platform-specific separator to split the pathname + // since we're using filepaths here and not URL paths + params: { path: pathname.split(sep) }, }); // This method receives the props from `getStaticProps` and renders/builds the Markdown