Skip to content

Commit

Permalink
[docs] Lint next.config.mjs (#3027)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Dec 28, 2023
1 parent 269163d commit eb1fe60
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 90 deletions.
178 changes: 89 additions & 89 deletions docs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
import * as path from 'path';
import * as url from 'url';
import { createRequire } from 'module';
Expand Down Expand Up @@ -33,101 +34,100 @@ const MONOREPO_PACKAGES = {
'@mui/utils': path.resolve(MONOREPO_PATH, './packages/mui-utils/src'),
};

export default withDocsInfra(
/** @type {import('next').NextConfig }} */ ({
transpilePackages: ['@mui/monorepo', '@mui/x-charts'],
// Avoid conflicts with the other Next.js apps hosted under https://mui.com/
assetPrefix: process.env.DEPLOY_ENV === 'development' ? undefined : '/toolpad',
env: {
LIB_VERSION: pkg.version,
// #default-branch-switch
// SOURCE_CODE_ROOT_URL: 'https://github.com/mui/mui-toolpad/blob/master',
SOURCE_CODE_REPO: 'https://github.com/mui/mui-toolpad',
SOURCE_GITHUB_BRANCH: 'master',
GITHUB_TEMPLATE_DOCS_FEEDBACK: '4.docs-feedback.yml',
},
webpack: (config, options) => {
return {
...config,
resolve: {
...config.resolve,
alias: {
...config.resolve.alias,
docs: path.resolve(MONOREPO_PATH, './docs'),
...MONOREPO_PACKAGES,
'@mui/toolpad-components': path.resolve(
currentDirectory,
'../packages/toolpad-components/src',
),
'@mui/toolpad-core': path.resolve(currentDirectory, '../packages/toolpad-core/src'),
'@mui/toolpad-utils': path.resolve(currentDirectory, '../packages/toolpad-utils/src'),
},
export default withDocsInfra({
transpilePackages: ['@mui/monorepo', '@mui/x-charts'],
// Avoid conflicts with the other Next.js apps hosted under https://mui.com/
assetPrefix: process.env.DEPLOY_ENV === 'development' ? undefined : '/toolpad',
env: {
// docs-infra
LIB_VERSION: pkg.version,
SOURCE_CODE_REPO: 'https://github.com/mui/mui-toolpad',
SOURCE_GITHUB_BRANCH: 'master', // #default-branch-switch
GITHUB_TEMPLATE_DOCS_FEEDBACK: '4.docs-feedback.yml',
// Toolpad related
// …
},
webpack: (config, options) => {
return {
...config,
resolve: {
...config.resolve,
alias: {
...config.resolve.alias,
docs: path.resolve(MONOREPO_PATH, './docs'),
...MONOREPO_PACKAGES,
'@mui/toolpad-components': path.resolve(
currentDirectory,
'../packages/toolpad-components/src',
),
'@mui/toolpad-core': path.resolve(currentDirectory, '../packages/toolpad-core/src'),
'@mui/toolpad-utils': path.resolve(currentDirectory, '../packages/toolpad-utils/src'),
},
module: {
...config.module,
rules: config.module.rules.concat([
// used in some /getting-started/templates
{
test: /\.md$/,
oneOf: [
{
resourceQuery: /@mui\/markdown/,
use: [
options.defaultLoaders.babel,
{
loader: require.resolve('@mui/monorepo/packages/markdown/loader'),
options: {
env: {
SOURCE_CODE_REPO: options.config.env.SOURCE_CODE_REPO,
LIB_VERSION: options.config.env.LIB_VERSION,
},
},
module: {
...config.module,
rules: config.module.rules.concat([
// used in some /getting-started/templates
{
test: /\.md$/,
oneOf: [
{
resourceQuery: /@mui\/markdown/,
use: [
options.defaultLoaders.babel,
{
loader: require.resolve('@mui/monorepo/packages/markdown/loader'),
options: {
env: {
SOURCE_CODE_REPO: options.config.env.SOURCE_CODE_REPO,
LIB_VERSION: options.config.env.LIB_VERSION,
},
},
],
},
],
},
]),
},
};
},
// 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.
exportPathMap: () => {
const pages = findPages();
const map = {};
},
],
},
],
},
]),
},
};
},
// 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.
exportPathMap: () => {
const pages = findPages();
const map = {};

function traverse(pages2, userLanguage) {
const prefix = userLanguage === 'en' ? '' : `/${userLanguage}`;
function traverse(pages2, userLanguage) {
const prefix = userLanguage === 'en' ? '' : `/${userLanguage}`;

pages2.forEach((page) => {
if (!page.children) {
map[`${prefix}${page.pathname.replace(/^\/api-docs\/(.*)/, '/api/$1')}`] = {
page: page.pathname,
query: {
userLanguage,
},
};
return;
}
pages2.forEach((page) => {
if (!page.children) {
map[`${prefix}${page.pathname.replace(/^\/api-docs\/(.*)/, '/api/$1')}`] = {
page: page.pathname,
query: {
userLanguage,
},
};
return;
}

traverse(page.children, userLanguage);
});
}
traverse(page.children, userLanguage);
});
}

// eslint-disable-next-line no-console
console.log('Considering only English for SSR');
traverse(pages, 'en');
// eslint-disable-next-line no-console
console.log('Considering only English for SSR');
traverse(pages, 'en');

return map;
return map;
},
// redirects only take effect in the development, not production (because of `next export`).
redirects: async () => [
{
source: '/',
destination: '/toolpad/',
permanent: false,
},
// redirects only take effect in the development, not production (because of `next export`).
redirects: async () => [
{
source: '/',
destination: '/toolpad/',
permanent: false,
},
],
}),
);
],
});
2 changes: 1 addition & 1 deletion docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"noImplicitAny": true,
"jsx": "preserve"
},
"include": ["docs-env.d.ts", "pages/**/*", "src/**/*", "data/**/*"],
"include": ["docs-env.d.ts", "pages/**/*", "src/**/*", "data/**/*", "next.config.mjs"],
"exclude": ["docs/.next", "docs/export"]
}

0 comments on commit eb1fe60

Please sign in to comment.