From e1d43108db714c59ddb636e852dfa25f1a7cedac Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 6 Jan 2024 00:21:37 +0100 Subject: [PATCH] [docs-infra] Add types for withDocsInfra (#40301) --- docs/next.config.js | 26 ++++++++++++++++++-------- docs/nextConfigDocsInfra.js | 14 ++++++++++++++ docs/tsconfig.json | 2 +- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/docs/next.config.js b/docs/next.config.js index ec73e6ba66bb9c..946495b1d4b079 100644 --- a/docs/next.config.js +++ b/docs/next.config.js @@ -1,4 +1,6 @@ +// @ts-check const path = require('path'); +// @ts-ignore const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); const pkg = require('../package.json'); const withDocsInfra = require('./nextConfigDocsInfra'); @@ -12,7 +14,7 @@ const { const workspaceRoot = path.join(__dirname, '../'); -const l10nPRInNetlify = /^l10n_/.test(process.env.HEAD) && process.env.NETLIFY === 'true'; +const l10nPRInNetlify = /^l10n_/.test(process.env.HEAD || '') && process.env.NETLIFY === 'true'; const vercelDeploy = Boolean(process.env.VERCEL); const isDeployPreview = Boolean(process.env.PULL_REQUEST_ID); // For crowdin PRs we want to build all locales for testing. @@ -48,6 +50,7 @@ module.exports = withDocsInfra({ const [nextExternals, ...externals] = config.externals; config.externals = [ + // @ts-ignore (ctx, callback) => { const { request } = ctx; const hasDependencyOnRepoPackages = [ @@ -71,8 +74,9 @@ module.exports = withDocsInfra({ ]; } - config.module.rules.forEach((r) => { - r.resourceQuery = { not: [/raw/] }; + // @ts-ignore + config.module.rules.forEach((rule) => { + rule.resourceQuery = { not: [/raw/] }; }); return { @@ -83,6 +87,7 @@ module.exports = withDocsInfra({ // resolve .tsx first extensions: [ '.tsx', + // @ts-ignore ...config.resolve.extensions.filter((extension) => extension !== '.tsx'), ], }, @@ -171,25 +176,29 @@ module.exports = withDocsInfra({ }; }, env: { - GITHUB_AUTH: process.env.GITHUB_AUTH - ? `Basic ${Buffer.from(process.env.GITHUB_AUTH).toString('base64')}` - : null, + // docs-infra LIB_VERSION: pkg.version, - FEEDBACK_URL: process.env.FEEDBACK_URL, - SOURCE_GITHUB_BRANCH: 'master', // #default-branch-switch SOURCE_CODE_REPO: 'https://github.com/mui/material-ui', + SOURCE_GITHUB_BRANCH: 'master', // #default-branch-switch GITHUB_TEMPLATE_DOCS_FEEDBACK: '4.docs-feedback.yml', BUILD_ONLY_ENGLISH_LOCALE: String(buildOnlyEnglishLocale), + // MUI Core related + GITHUB_AUTH: process.env.GITHUB_AUTH + ? `Basic ${Buffer.from(process.env.GITHUB_AUTH).toString('base64')}` + : '', }, // Next.js provides a `defaultPathMap` argument, we could simplify the logic. // However, we don't in order to prevent any regression in the `findPages()` method. + // @ts-ignore exportPathMap: () => { const pages = findPages(); const map = {}; + // @ts-ignore function traverse(pages2, userLanguage) { const prefix = userLanguage === 'en' ? '' : `/${userLanguage}`; + // @ts-ignore pages2.forEach((page) => { // The experiments pages are only meant for experiments, they shouldn't leak to production. if ( @@ -206,6 +215,7 @@ module.exports = withDocsInfra({ // map api-docs to api // i: /api-docs/* > /api/* (old structure) // ii: /*/api-docs/* > /*/api/* (for new structure) + // @ts-ignore map[`${prefix}${page.pathname.replace(/^(\/[^/]+)?\/api-docs\/(.*)/, '$1/api/$2')}`] = { page: page.pathname, query: { diff --git a/docs/nextConfigDocsInfra.js b/docs/nextConfigDocsInfra.js index b92e6764a604e2..ba6e0690714473 100644 --- a/docs/nextConfigDocsInfra.js +++ b/docs/nextConfigDocsInfra.js @@ -33,6 +33,19 @@ if ( process.env.DEPLOY_ENV = DEPLOY_ENV; +/** + * @typedef {import('next').NextConfig} NextConfig + * @typedef {NextConfig['env']} NextConfigEnv + * @typedef {{env : { + * LIB_VERSION: string; + * SOURCE_CODE_REPO: string; + * SOURCE_GITHUB_BRANCH: string; + * GITHUB_TEMPLATE_DOCS_FEEDBACK: string; + * }} & NextConfig} NextConfigInput + + * @param {NextConfigInput} nextConfig + * @returns {NextConfig} + */ function withDocsInfra(nextConfig) { return { trailingSlash: true, @@ -44,6 +57,7 @@ function withDocsInfra(nextConfig) { BUILD_ONLY_ENGLISH_LOCALE: 'true', // disable translations by default // production | staging | pull-request | development DEPLOY_ENV, + FEEDBACK_URL: process.env.FEEDBACK_URL, ...nextConfig.env, // https://docs.netlify.com/configure-builds/environment-variables/#git-metadata // reference ID (also known as "SHA" or "hash") of the commit we're building. diff --git a/docs/tsconfig.json b/docs/tsconfig.json index b3282c841557ef..4dc232509b9b8b 100644 --- a/docs/tsconfig.json +++ b/docs/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.json", - "include": ["next-env.d.ts", "types", "src", "pages", "data"], + "include": ["next-env.d.ts", "types", "src", "pages", "data", "next.config.js"], "compilerOptions": { "allowJs": true, "isolatedModules": true,