From f02332cd1cd00af1e7dc836e293edf1b5243eebb Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette Date: Thu, 13 Oct 2022 15:59:44 +0200 Subject: [PATCH 1/5] import link checker from core --- .circleci/config.yml | 5 +++ docs/.link-check-errors.txt | 5 +++ docs/package.json | 3 +- docs/scripts/reportBrokenLinks.js | 68 +++++++++++++++++++++++++++++++ package.json | 1 + 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 docs/.link-check-errors.txt create mode 100644 docs/scripts/reportBrokenLinks.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 6f97721194e2..ef8ae95ca9c9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -181,6 +181,11 @@ jobs: - run: name: '`yarn l10n` changes committed?' command: git diff --exit-code + - run: + name: '`yarn docs:link-check` changes committed?' + command: | + yarn docs:link-check + git diff --exit-code test_browser: <<: *defaults docker: diff --git a/docs/.link-check-errors.txt b/docs/.link-check-errors.txt new file mode 100644 index 000000000000..e316dac4e771 --- /dev/null +++ b/docs/.link-check-errors.txt @@ -0,0 +1,5 @@ +Broken links found by `yarn docs:link-check` that exist: + +- https://mui.com/blog/material-ui-v4-is-out/#premium-themes-store-✨ +- https://mui.com/react-date-pickers/validation +- https://mui.com/size-snapshot diff --git a/docs/package.json b/docs/package.json index b2456d9d67a2..bfb9545a09b1 100644 --- a/docs/package.json +++ b/docs/package.json @@ -14,7 +14,8 @@ "icons": "rimraf public/static/icons/* && node ./scripts/buildIcons.js", "typescript": "tsc -p tsconfig.json", "typescript:transpile": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" scripts/formattedTSDemos", - "typescript:transpile:dev": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" scripts/formattedTSDemos --watch" + "typescript:transpile:dev": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" scripts/formattedTSDemos --watch", + "link-check": "node ./scripts/reportBrokenLinks.js" }, "dependencies": { "@babel/core": "^7.19.3", diff --git a/docs/scripts/reportBrokenLinks.js b/docs/scripts/reportBrokenLinks.js new file mode 100644 index 000000000000..7898f6f52a46 --- /dev/null +++ b/docs/scripts/reportBrokenLinks.js @@ -0,0 +1,68 @@ +/* eslint-disable no-console */ +const path = require('path'); +const fse = require('fs-extra'); +const { parseDocFolder, getAnchor } = require('@mui/monorepo/docs/scripts/reportBrokenLinks'); + +const docsSpaceRoot = path.join(__dirname, '../'); + +function save(lines) { + const fileContents = [...lines, ''].join('\n'); + fse.writeFileSync(path.join(docsSpaceRoot, '.link-check-errors.txt'), fileContents); +} + +const UNSUPPORTED_PATHS = ['/api/', '/careers/', '/store/']; + +const buffer = []; + +function write(text) { + buffer.push(text); +} + +// {[url with hash]: true} +const availableLinksX = {}; +const availableLinksCore = {}; + +// {[url with hash]: list of files using this link} +const usedLinksX = {}; +const usedLinksCore = {}; + +parseDocFolder(path.join(docsSpaceRoot, './pages/'), availableLinksX, usedLinksX, ''); +parseDocFolder( + path.resolve(__dirname, '../../node_modules/@mui/monorepo/docs/pages/'), + availableLinksCore, + usedLinksCore, + '', +); + +function getPageUrlFromLink(link) { + const [rep] = link.split('/#'); + return rep; +} + +const usedLinks = { ...usedLinksCore, ...usedLinksX }; +const availableLinks = { ...availableLinksCore, ...availableLinksX }; + +write('Broken links found by `yarn docs:link-check` that exist:\n'); +Object.keys(usedLinks) + .filter((link) => link.startsWith('/')) + .filter((link) => !availableLinks[link]) + // unstyled sections are added by scripts (can not be found in markdown) + .filter((link) => !link.includes('#unstyled')) + .filter((link) => UNSUPPORTED_PATHS.every((unsupportedPath) => !link.includes(unsupportedPath))) + .sort() + .forEach((linkKey) => { + write(`- https://mui.com${linkKey}`); + console.log(`https://mui.com${linkKey}`); + console.log(`used in`); + usedLinks[linkKey].forEach((f) => console.log(`- ${path.relative(docsSpaceRoot, f)}`)); + console.log('available anchors on the same page:'); + console.log( + Object.keys(availableLinks) + .filter((link) => getPageUrlFromLink(link) === getPageUrlFromLink(linkKey)) + .sort() + .map(getAnchor) + .join('\n'), + ); + console.log('\n\n'); + }); +save(buffer); diff --git a/package.json b/package.json index 2f37f78e13a6..486f200a59f4 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "docs:importDocsStatic": "node scripts/importDocsStatic.js", "docs:size-why": "cross-env DOCS_STATS_ENABLED=true yarn docs:build", "docs:deploy": "yarn workspace docs deploy", + "docs:link-check": "yarn workspace docs link-check", "deduplicate": "node scripts/deduplicate.js", "dataset:file-tree": "babel-node -x .ts ./scripts/treeDataFromFileTree.ts", "l10n": "babel-node -x .ts ./scripts/l10n.ts", From 474a37c0f8367df5ba105744b38485f49a757eff Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette Date: Thu, 13 Oct 2022 15:59:51 +0200 Subject: [PATCH 2/5] fix links --- docs/data/data-grid/components/components.md | 2 +- .../migration/migration-data-grid-v4/migration-data-grid-v4.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/data/data-grid/components/components.md b/docs/data/data-grid/components/components.md index 17a02beb41c9..ff318676de05 100644 --- a/docs/data/data-grid/components/components.md +++ b/docs/data/data-grid/components/components.md @@ -39,7 +39,7 @@ The grid exposes two hooks to help you to access the grid data while overriding They can be used as below: -- `useGridApiContext`: returns the `apiRef` object (more details in the [API object page](/x/react-data-grid/api-object/#use-it-inside-the-grid)). +- `useGridApiContext`: returns the `apiRef` object (more details in the [API object page](/x/react-data-grid/api-object/#inside-the-data-grid)). - `useGridSelector`: returns the result of a selector on the current state (more details in the [State page](/x/react-data-grid/state/#access-the-state)). ```tsx diff --git a/docs/data/migration/migration-data-grid-v4/migration-data-grid-v4.md b/docs/data/migration/migration-data-grid-v4/migration-data-grid-v4.md index 155e5ca4c15c..d2c6e3b30ae0 100644 --- a/docs/data/migration/migration-data-grid-v4/migration-data-grid-v4.md +++ b/docs/data/migration/migration-data-grid-v4/migration-data-grid-v4.md @@ -19,7 +19,7 @@ Most breaking changes are renaming of CSS classes or variables to improve the co Using MUI Core v4 with v5 can be achieved with the following steps: 1. First, make sure you have MUI Core v5 installed. If not, install it with these [instructions](/material-ui/getting-started/installation/). -1. Add a custom [`createGenerateClassName`](/system/styles/api/#heading-creategenerateclassname-options-class-name-generator) to disable the generation of global class names in JSS. +1. Add a custom [`createGenerateClassName`](/system/styles/api/#creategenerateclassname-options-class-name-generator) to disable the generation of global class names in JSS. ```jsx import { createGenerateClassName } from '@material-ui/core/styles'; From 9befd997ef98d8f58d34e09a8d9e449b192b8dba Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette Date: Tue, 18 Oct 2022 11:03:48 +0200 Subject: [PATCH 3/5] upgrade monorepo --- yarn.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index 9e8eae35e20e..a0f13f2696f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2545,8 +2545,8 @@ react-transition-group "^4.4.5" "@mui/monorepo@https://github.com/mui/material-ui.git#master": - version "5.10.9" - resolved "https://github.com/mui/material-ui.git#27f9a61821a3d4d76ca0a085f9c779356ccd7753" + version "5.10.10" + resolved "https://github.com/mui/material-ui.git#639224a3e3600cb0e04755d89aab250297b6d851" "@mui/private-theming@^5.10.6", "@mui/private-theming@^5.10.9": version "5.10.9" From 1091501a77382bf341345b94668b079144485ad7 Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette Date: Wed, 19 Oct 2022 09:57:09 +0200 Subject: [PATCH 4/5] fix next config --- docs/.link-check-errors.txt | 3 ++- docs/next.config.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/.link-check-errors.txt b/docs/.link-check-errors.txt index e316dac4e771..9764c384dbc8 100644 --- a/docs/.link-check-errors.txt +++ b/docs/.link-check-errors.txt @@ -1,5 +1,6 @@ Broken links found by `yarn docs:link-check` that exist: - https://mui.com/blog/material-ui-v4-is-out/#premium-themes-store-✨ -- https://mui.com/react-date-pickers/validation - https://mui.com/size-snapshot +- https://mui.com/x/react-data-grid/migration-v4 +- https://mui.com/x/react-date-pickers/migration-lab diff --git a/docs/next.config.js b/docs/next.config.js index 64e2e8ae6d43..19cde13ef7ec 100644 --- a/docs/next.config.js +++ b/docs/next.config.js @@ -43,6 +43,14 @@ module.exports = withDocsInfra({ return { ...config, plugins, + resolve: { + ...config.resolve, + alias: { + ...config.resolve.alias, + docs: path.resolve(__dirname, '../node_modules/@mui/monorepo/docs'), + docsx: path.resolve(__dirname, '../docs'), + }, + }, module: { ...config.module, rules: config.module.rules.concat([ From 700e683a833c4f7d307e695b970daac84a32593b Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Fri, 21 Oct 2022 17:43:42 +0200 Subject: [PATCH 5/5] fix script --- babel.config.js | 1 + docs/package.json | 3 +-- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/babel.config.js b/babel.config.js index 681816176532..7c3c81afdbd9 100644 --- a/babel.config.js +++ b/babel.config.js @@ -14,6 +14,7 @@ const defaultAlias = { '@mui/x-license-pro': resolveAliasPath('./packages/x-license-pro/src'), '@mui/x-date-pickers': resolveAliasPath('./packages/x-date-pickers/src'), '@mui/x-date-pickers-pro': resolveAliasPath('./packages/x-date-pickers-pro/src'), + '@mui/markdown': '@mui/monorepo/docs/packages/markdown', 'typescript-to-proptypes': '@mui/monorepo/packages/typescript-to-proptypes/src', docs: resolveAliasPath('./node_modules/@mui/monorepo/docs'), test: resolveAliasPath('./test'), diff --git a/docs/package.json b/docs/package.json index b6fc49e021c9..c3957616c369 100644 --- a/docs/package.json +++ b/docs/package.json @@ -14,8 +14,7 @@ "icons": "rimraf public/static/icons/* && node ./scripts/buildIcons.js", "typescript": "tsc -p tsconfig.json", "typescript:transpile": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" scripts/formattedTSDemos", - "typescript:transpile:dev": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" scripts/formattedTSDemos --watch", - "link-check": "node ./scripts/reportBrokenLinks.js" + "typescript:transpile:dev": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" scripts/formattedTSDemos --watch" }, "dependencies": { "@babel/core": "^7.19.3", diff --git a/package.json b/package.json index 1c0a74291583..c20aadfe5a34 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,13 @@ "docs:dev": "yarn workspace docs dev", "docs:api": "yarn docs:api:build", "docs:api:build": "cross-env BABEL_ENV=development babel-node -i \"/node_modules/(?!@mui)/\" -x .ts,.tsx,.js ./docs/scripts/api/buildApi.ts", + "docs:link-check": "cross-env BABEL_ENV=development babel-node -i \"/node_modules/(?!@mui)/\" --extensions \".tsx,.ts,.js\" ./docs/scripts/reportBrokenLinks.js", "docs:build": "yarn workspace docs build", "docs:export": "yarn workspace docs export", "docs:typescript:formatted": "yarn workspace docs typescript:transpile", "docs:importDocsStatic": "node scripts/importDocsStatic.js", "docs:size-why": "cross-env DOCS_STATS_ENABLED=true yarn docs:build", "docs:deploy": "yarn workspace docs deploy", - "docs:link-check": "yarn workspace docs link-check", "deduplicate": "node scripts/deduplicate.js", "dataset:file-tree": "babel-node -x .ts ./scripts/treeDataFromFileTree.ts", "l10n": "babel-node -x .ts ./scripts/l10n.ts",