Skip to content

Commit 1566191

Browse files
Janpotthomasmoon
authored andcommitted
[code-infra] Move next config to ESM (mui#11882)
1 parent 976fb0d commit 1566191

File tree

9 files changed

+71
-36
lines changed

9 files changed

+71
-36
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ module.exports = {
122122
'filenames/match-exported': ['error'],
123123
},
124124
},
125+
{
126+
files: ['**/*.mjs'],
127+
rules: {
128+
'import/extensions': ['error', 'ignorePackages'],
129+
},
130+
},
125131
{
126132
files: ['packages/*/src/**/*{.ts,.tsx,.js}'],
127133
excludedFiles: ['*.d.ts', '*.spec.ts', '*.spec.tsx'],

docs/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// These are also loaded by scripts that only undestand CommonJS. (l10n)
2+
3+
module.exports = {
4+
SOURCE_CODE_REPO: 'https://github.com/mui/mui-x',
5+
SOURCE_GITHUB_BRANCH: 'next', // #default-branch-switch
6+
};

docs/next.config.js renamed to docs/next.config.mjs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
11
// @ts-check
2-
const path = require('path');
3-
// @ts-ignore
4-
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
5-
// const withTM = require('next-transpile-modules')(['@mui/monorepo']);
2+
import * as path from 'path';
3+
import * as url from 'url';
4+
import * as fs from 'fs';
5+
import { createRequire } from 'module';
6+
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
7+
// const withTM from 'next-transpile-modules')(['@mui/monorepo'];
68
// @ts-expect-error This expected error should be gone once we update the monorepo
7-
const withDocsInfra = require('@mui/monorepo/docs/nextConfigDocsInfra');
8-
const pkg = require('../package.json');
9-
const dataGridPkg = require('../packages/grid/x-data-grid/package.json');
10-
const datePickersPkg = require('../packages/x-date-pickers/package.json');
11-
const chartsPkg = require('../packages/x-charts/package.json');
12-
const treeViewPkg = require('../packages/x-tree-view/package.json');
13-
const { findPages } = require('./src/modules/utils/find');
14-
const { LANGUAGES, LANGUAGES_SSR } = require('./config');
9+
import withDocsInfra from '@mui/monorepo/docs/nextConfigDocsInfra.js';
10+
import { findPages } from './src/modules/utils/find.mjs';
11+
import { LANGUAGES, LANGUAGES_SSR } from './config.js';
12+
import constants from './constants.js';
1513

16-
const workspaceRoot = path.join(__dirname, '../');
14+
const currentDirectory = url.fileURLToPath(new URL('.', import.meta.url));
15+
const require = createRequire(import.meta.url);
1716

18-
module.exports = withDocsInfra({
17+
const workspaceRoot = path.join(currentDirectory, '../');
18+
19+
/**
20+
* @param {string} pkgPath
21+
* @returns {{version: string}}
22+
*/
23+
function loadPkg(pkgPath) {
24+
const pkgContent = fs.readFileSync(path.resolve(workspaceRoot, pkgPath, 'package.json'), 'utf8');
25+
return JSON.parse(pkgContent);
26+
}
27+
28+
const pkg = loadPkg('.');
29+
const dataGridPkg = loadPkg('./packages/grid/x-data-grid');
30+
const datePickersPkg = loadPkg('./packages/x-date-pickers');
31+
const chartsPkg = loadPkg('./packages/x-charts');
32+
const treeViewPkg = loadPkg('./packages/x-tree-view');
33+
34+
export default withDocsInfra({
1935
// Avoid conflicts with the other Next.js apps hosted under https://mui.com/
2036
assetPrefix: process.env.DEPLOY_ENV === 'development' ? undefined : '/x',
2137
env: {
2238
// docs-infra
2339
LIB_VERSION: pkg.version,
24-
SOURCE_CODE_REPO: 'https://github.com/mui/mui-x',
25-
SOURCE_GITHUB_BRANCH: 'next', // #default-branch-switch
40+
SOURCE_CODE_REPO: constants.SOURCE_CODE_REPO,
41+
SOURCE_GITHUB_BRANCH: constants.SOURCE_GITHUB_BRANCH,
2642
GITHUB_TEMPLATE_DOCS_FEEDBACK: '6.docs-feedback.yml',
2743
// MUI X related
2844
DATA_GRID_VERSION: dataGridPkg.version,
@@ -56,8 +72,8 @@ module.exports = withDocsInfra({
5672
...config.resolve,
5773
alias: {
5874
...config.resolve.alias,
59-
docs: path.resolve(__dirname, '../node_modules/@mui/monorepo/docs'),
60-
docsx: path.resolve(__dirname, '../docs'),
75+
docs: path.resolve(currentDirectory, '../node_modules/@mui/monorepo/docs'),
76+
docsx: path.resolve(currentDirectory, '../docs'),
6177
},
6278
},
6379
module: {

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"@babel/preset-typescript": "^7.23.3",
9595
"@types/doctrine": "^0.0.9",
9696
"@types/stylis": "^4.2.5",
97+
"@types/webpack-bundle-analyzer": "^4.6.3",
9798
"cpy-cli": "^5.0.0",
9899
"gm": "^1.25.0",
99100
"typescript-to-proptypes": "^2.2.1"

docs/src/modules/utils/find.js renamed to docs/src/modules/utils/find.mjs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
import * as url from 'url';
4+
5+
const currentDirectory = url.fileURLToPath(new URL('.', import.meta.url));
36

47
const jsRegex = /\.js$/;
58
const blackList = ['/.eslintrc', '/_document', '/_app'];
69

710
// Returns the Next.js pages available in a nested format.
811
// The output is in the next.js format.
912
// Each pathname is a route you can navigate to.
10-
function findPages(
13+
export function findPages(
1114
options = {},
12-
directory = path.resolve(__dirname, '../../../pages'),
15+
directory = path.resolve(currentDirectory, '../../../pages'),
1316
pages = [],
1417
) {
1518
fs.readdirSync(directory).forEach((item) => {
@@ -71,7 +74,3 @@ function findPages(
7174

7275
return pages;
7376
}
74-
75-
module.exports = {
76-
findPages,
77-
};

docs/src/modules/utils/findPages.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
4+
"allowJs": true,
45
"isolatedModules": true,
56
/* files are emitted by babel */
67
"noEmit": true,
@@ -14,7 +15,7 @@
1415
"pages/**/*.ts*",
1516
"data/**/*",
1617
"src/modules/components/**/*",
17-
"next.config.js",
18+
"next.config.mjs",
1819
"../node_modules/@mui/material/themeCssVarsAugmentation",
1920
"../node_modules/dayjs/plugin/utc.d.ts",
2021
"../node_modules/dayjs/plugin/timezone.d.ts",

scripts/l10n.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import * as yargs from 'yargs';
99
import { Octokit } from '@octokit/rest';
1010
import { retry } from '@octokit/plugin-retry';
1111
import localeNames from './localeNames';
12-
import nextConfig from '../docs/next.config';
12+
import {
13+
SOURCE_CODE_REPO as DOCS_SOURCE_CODE_REPO,
14+
SOURCE_GITHUB_BRANCH as DOCS_SOURCE_GITHUB_BRANCH,
15+
} from '../docs/constants';
1316

1417
const MyOctokit = Octokit.plugin(retry);
1518

@@ -344,7 +347,7 @@ const generateDocReport = async (
344347
localeName,
345348
missingKeysCount: infoPerPackage[packageKey].missingKeys.length,
346349
totalKeysCount: baseTranslationsNumber[packageKey],
347-
githubLink: `${nextConfig.env.SOURCE_CODE_REPO}/blob/${nextConfig.env.SOURCE_GITHUB_BRANCH}/${info.path}`,
350+
githubLink: `${DOCS_SOURCE_CODE_REPO}/blob/${DOCS_SOURCE_GITHUB_BRANCH}/${info.path}`,
348351
});
349352
});
350353

yarn.lock

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3373,6 +3373,15 @@
33733373
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.10.tgz#04ffa7f406ab628f7f7e97ca23e290cd8ab15efc"
33743374
integrity sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==
33753375

3376+
"@types/webpack-bundle-analyzer@^4.6.3":
3377+
version "4.6.3"
3378+
resolved "https://registry.yarnpkg.com/@types/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.6.3.tgz#53c26f21134ca2e5049fd2af4f2ffbf8dfe87b4f"
3379+
integrity sha512-XYU3m7oRb1tlE8YhwkKLi1xba2buNB9V4VkQtOVTfJuUm/413pE/UCMVcPDFFBwpzGkr9y1WbSEvdPjKVPt0gw==
3380+
dependencies:
3381+
"@types/node" "*"
3382+
tapable "^2.2.0"
3383+
webpack "^5"
3384+
33763385
"@types/ws@^7.4.7":
33773386
version "7.4.7"
33783387
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-7.4.7.tgz#f7c390a36f7a0679aa69de2d501319f4f8d9b702"
@@ -14852,7 +14861,7 @@ webpack-sources@^3.2.3:
1485214861
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
1485314862
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==
1485414863

14855-
webpack@^5.90.0:
14864+
webpack@^5, webpack@^5.90.0:
1485614865
version "5.90.0"
1485714866
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.90.0.tgz#313bfe16080d8b2fee6e29b6c986c0714ad4290e"
1485814867
integrity sha512-bdmyXRCXeeNIePv6R6tGPyy20aUobw4Zy8r0LUS2EWO+U+Ke/gYDgsCh7bl5rB6jPpr4r0SZa6dPxBxLooDT3w==

0 commit comments

Comments
 (0)