Skip to content

Commit

Permalink
[core] Config cleanup (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak authored Apr 30, 2024
1 parent e46f7f2 commit 95ccd92
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 154 deletions.
4 changes: 0 additions & 4 deletions .browserslistrc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@ node 18.0
# same as `node`
[test]
node 18.0

# same as `node`
[benchmark]
node 18.0
22 changes: 0 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,22 +392,6 @@ jobs:
- run:
name: Upload screenshots to Argos CI
command: pnpm test:argos
test_benchmark:
<<: *default-job
docker:
- image: mcr.microsoft.com/playwright:v1.43.1-focal
environment:
NODE_ENV: development # Needed if playwright is in `devDependencies`
steps:
- checkout
- install_js:
react-version: << parameters.react-version >>
browsers: true
- run: pnpm benchmark:browser
- store_artifacts:
name: Publish benchmark results as a pipeline artifact.
path: tmp/benchmarks
destination: benchmarks
workflows:
version: 2
pipeline:
Expand Down Expand Up @@ -494,9 +478,3 @@ workflows:
jobs:
- test_types_next:
<<: *default-context
benchmark:
when:
equal: [benchmark, << pipeline.parameters.workflow >>]
jobs:
- test_benchmark:
<<: *default-context
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/.git
/.yarn
/benchmark/**/dist
/coverage
/docs/export
/docs/pages/playground/
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*.tsbuildinfo
/.eslintcache
/.nyc_output
/benchmark/**/dist
/coverage
/docs/.env.local
/docs/export
Expand Down
21 changes: 0 additions & 21 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,6 @@ module.exports = function getBabelConfig(api) {
],
],
},
rollup: {
plugins: [
[
'babel-plugin-module-resolver',
{
alias: defaultAlias,
},
],
],
},
test: {
sourceMaps: 'both',
plugins: [
Expand All @@ -143,17 +133,6 @@ module.exports = function getBabelConfig(api) {
],
],
},
benchmark: {
plugins: [
...productionPlugins,
[
'babel-plugin-module-resolver',
{
alias: defaultAlias,
},
],
],
},
},
};
};
19 changes: 3 additions & 16 deletions docs/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@ const fse = require('fs-extra');

const errorCodesPath = path.resolve(__dirname, './public/static/error-codes.json');

const alias = {
docs: '../node_modules/@mui/monorepo/docs',
'docs-base': './',
};

const { version: transformRuntimeVersion } = fse.readJSONSync(
require.resolve('@babel/runtime-corejs2/package.json'),
);

module.exports = {
// TODO: Enable once nextjs uses babel 7.13
// assumptions: {
// noDocumentAll: true,
// },
assumptions: {
noDocumentAll: true,
},
presets: [
// backport of https://github.com/vercel/next.js/pull/9511
[
Expand All @@ -36,13 +30,6 @@ module.exports = {
},
},
],
[
'babel-plugin-module-resolver',
{
alias,
transformFunctions: ['require', 'require.context'],
},
],
'babel-plugin-optimize-clsx',
],
ignore: [/@babel[\\|/]runtime/], // Fix a Windows issue.
Expand Down
169 changes: 81 additions & 88 deletions docs/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import * as path from 'path';
import * as url from 'url';
import * as fs from 'fs';
import { createRequire } from 'module';
// eslint-disable-next-line no-restricted-imports
import withDocsInfra from '@mui/monorepo/docs/nextConfigDocsInfra.js';
import { findPages } from './src/utils/findPages.mjs';
Expand All @@ -14,35 +13,31 @@ import {
} from './config.js';

const currentDirectory = url.fileURLToPath(new URL('.', import.meta.url));
const require = createRequire(import.meta.url);

const workspaceRoot = path.join(currentDirectory, '../');
const workspaceRoot = path.resolve(currentDirectory, '../');

/**
* @param {string} pkgPath
* @returns {{version: string}}
*/
function loadPkg(pkgPath) {
const pkgContent = fs.readFileSync(path.resolve(workspaceRoot, pkgPath, 'package.json'), 'utf8');
function loadPackageJson() {
const pkgContent = fs.readFileSync(path.resolve(workspaceRoot, 'package.json'), 'utf8');
return JSON.parse(pkgContent);
}

const pkg = loadPkg('.');
const rootPackage = loadPackageJson();

export default withDocsInfra({
/** @type {import('next').NextConfig} */
const nextConfig = {
// Avoid conflicts with the other Next.js apps hosted under https://mui.com/
assetPrefix: process.env.DEPLOY_ENV === 'development' ? undefined : '/base-ui/',
env: {
// docs-infra
LIB_VERSION: pkg.version,
LIB_VERSION: rootPackage.version,
SOURCE_CODE_REPO: 'https://github.com/mui/base-ui',
SOURCE_GITHUB_BRANCH: 'master',
GITHUB_TEMPLATE_DOCS_FEEDBACK: '6.docs-feedback.yml',
},
// @ts-ignore
webpack: (config, options) => {
const plugins = config.plugins.slice();

const includesMonorepo = [/(@mui[\\/]monorepo)$/, /(@mui[\\/]monorepo)[\\/](?!.*node_modules)/];

return {
Expand All @@ -52,39 +47,35 @@ export default withDocsInfra({
...config.resolve,
alias: {
...config.resolve.alias,
'docs-base': path.resolve(currentDirectory, '../docs'),
docs: path.resolve(currentDirectory, '../node_modules/@mui/monorepo/docs'),
'docs-base': path.resolve(workspaceRoot, 'docs'),
docs: path.resolve(workspaceRoot, 'node_modules/@mui/monorepo/docs'),
},
},
module: {
...config.module,
rules: config.module.rules.concat([
{
test: /\.md$/,
oneOf: [
resourceQuery: /@mui\/markdown/,
use: [
options.defaultLoaders.babel,
{
resourceQuery: /@mui\/markdown/,
use: [
options.defaultLoaders.babel,
{
loader: require.resolve('@mui/internal-markdown/loader'),
options: {
workspaceRoot,
ignoreLanguagePages: LANGUAGES_IGNORE_PAGES,
languagesInProgress: LANGUAGES_IN_PROGRESS,
packages: [
{
productId: 'base-ui',
paths: [path.join(workspaceRoot, 'packages/mui-base/src')],
},
],
env: {
SOURCE_CODE_REPO: options.config.env.SOURCE_CODE_REPO,
LIB_VERSION: options.config.env.LIB_VERSION,
},
loader: '@mui/internal-markdown/loader',
options: {
workspaceRoot,
ignoreLanguagePages: LANGUAGES_IGNORE_PAGES,
languagesInProgress: LANGUAGES_IN_PROGRESS,
packages: [
{
productId: 'base-ui',
paths: [path.join(workspaceRoot, 'packages/mui-base/src')],
},
],
env: {
SOURCE_CODE_REPO: options.config.env.SOURCE_CODE_REPO,
LIB_VERSION: options.config.env.LIB_VERSION,
},
],
},
},
],
},
Expand All @@ -93,65 +84,15 @@ export default withDocsInfra({
include: includesMonorepo,
use: options.defaultLoaders.babel,
},
{
test: /\.(js|mjs|ts|tsx)$/,
include: [workspaceRoot],
exclude: /node_modules/,
use: options.defaultLoaders.babel,
},
]),
},
};
},
distDir: 'export',
// 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 = {};

// @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 (page.pathname.includes('/experiments/') && process.env.DEPLOY_ENV === 'production') {
return;
}

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

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

// We want to speed-up the build of pull requests.
if (process.env.PULL_REQUEST === 'true') {
// eslint-disable-next-line no-console
console.log('Considering only English for SSR');
traverse(pages, 'en');
} else {
// eslint-disable-next-line no-console
console.log('Considering various locales for SSR');
LANGUAGES_SSR.forEach((userLanguage) => {
traverse(pages, userLanguage);
});
}

return map;
},
transpilePackages: ['@mui/docs'],
exportPathMap,
transpilePackages: ['@mui/docs', '@mui/monorepo'],
...(process.env.NODE_ENV === 'production'
? {
output: 'export',
Expand All @@ -172,4 +113,56 @@ export default withDocsInfra({
},
],
}),
});
};

function exportPathMap() {
const allPages = findPages();
/**
* @type {Record<string, {page: string, query: {userLanguage: string}}>}
*/
const map = {};

/**
* @param {import('./src/utils/findPages.mjs').NextJSPage[]} pages
* @param {string} userLanguage
*/
function traverse(pages, userLanguage) {
const prefix = userLanguage === 'en' ? '' : `/${userLanguage}`;

pages.forEach((page) => {
// The experiments pages are only meant for experiments, they shouldn't leak to production.
if (page.pathname.includes('/experiments/') && process.env.DEPLOY_ENV === 'production') {
return;
}

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

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

// We want to speed-up the build of pull requests.
if (process.env.PULL_REQUEST === 'true') {
// eslint-disable-next-line no-console
console.log('Considering only English for SSR');
traverse(allPages, 'en');
} else {
// eslint-disable-next-line no-console
console.log('Considering various locales for SSR');
LANGUAGES_SSR.forEach((userLanguage) => {
traverse(allPages, userLanguage);
});
}

return map;
}

export default withDocsInfra(nextConfig);
1 change: 0 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
packages:
- 'benchmark'
- 'packages/*'
- 'docs'
- 'test'

0 comments on commit 95ccd92

Please sign in to comment.