diff --git a/docs/config.d.ts b/docs/config.d.ts new file mode 100644 index 00000000000000..12950f0e05064d --- /dev/null +++ b/docs/config.d.ts @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/prefer-default-export +export const LANGUAGES: string[]; diff --git a/docs/config.js b/docs/config.js new file mode 100644 index 00000000000000..4718083cf6aec2 --- /dev/null +++ b/docs/config.js @@ -0,0 +1,6 @@ +module.exports = { + /** + * Valid languages to server-side render in production + */ + LANGUAGES: ['en', 'zh', 'pt'], +}; diff --git a/docs/package.json b/docs/package.json index d539ce62c473b4..5e8fed8b18f855 100644 --- a/docs/package.json +++ b/docs/package.json @@ -60,7 +60,6 @@ "@types/react-virtualized": "^9.21.21", "@types/react-window": "^1.8.5", "@types/styled-components": "5.1.26", - "ast-types": "^0.14.2", "autoprefixer": "^10.4.13", "autosuggest-highlight": "^3.3.4", "babel-plugin-module-resolver": "^4.1.0", @@ -75,7 +74,6 @@ "css-mediaquery": "^0.1.2", "date-fns": "^2.29.3", "date-fns-jalali": "^2.21.3-1", - "doctrine": "^3.0.0", "exceljs": "^4.3.0", "express": "^4.18.2", "fg-loadcss": "^3.1.0", @@ -96,7 +94,6 @@ "postcss": "^8.4.19", "prop-types": "^15.8.1", "react": "^18.2.0", - "react-docgen": "^5.4.3", "react-dom": "^18.2.0", "react-draggable": "^4.4.5", "react-final-form": "^6.5.9", @@ -112,7 +109,6 @@ "react-transition-group": "^4.4.5", "react-virtualized": "^9.22.3", "react-window": "^1.8.8", - "recast": "^0.21.5", "recharts": "2.1.16", "rimraf": "^3.0.2", "styled-components": "^5.3.6", diff --git a/docs/packages/markdown/index.d.ts b/docs/packages/markdown/index.d.ts new file mode 100644 index 00000000000000..e01dd2fc94caf1 --- /dev/null +++ b/docs/packages/markdown/index.d.ts @@ -0,0 +1,18 @@ +interface TableOfContentsEntry { + children: TableOfContentsEntry; + hash: string; + level: number; + text: string; +} + +export function createRender(context: { + headingHashes: Record; + toc: TableOfContentsEntry[]; + userLanguage: string; +}): (markdown: string) => string; + +export function getHeaders(markdown: string): Record; + +export function getTitle(markdown: string): string; + +export function renderInline(markdown: string): string; diff --git a/docs/packages/markdown/package.json b/docs/packages/markdown/package.json index 5679bb4b28fbb4..4ecd528670c3b4 100644 --- a/docs/packages/markdown/package.json +++ b/docs/packages/markdown/package.json @@ -3,6 +3,7 @@ "version": "5.0.0", "private": true, "main": "./index.js", + "types": "./index.d.ts", "exports": { ".": "./index.js", "./loader": "./loader.js", diff --git a/docs/packages/markdown/parseMarkdown.js b/docs/packages/markdown/parseMarkdown.js index a1c8c219e32289..2ef070fee80f36 100644 --- a/docs/packages/markdown/parseMarkdown.js +++ b/docs/packages/markdown/parseMarkdown.js @@ -130,7 +130,7 @@ function getTitle(markdown) { const matches = markdown.match(titleRegExp); if (matches === null) { - return undefined; + return ''; } return matches[1].replace(/`/g, ''); diff --git a/docs/packages/markdown/prism.d.ts b/docs/packages/markdown/prism.d.ts new file mode 100644 index 00000000000000..cdc055519484ab --- /dev/null +++ b/docs/packages/markdown/prism.d.ts @@ -0,0 +1 @@ +export default function highlight(code: string, language: string): string; diff --git a/docs/scripts/formattedTSDemos.js b/docs/scripts/formattedTSDemos.js index 988782873999f0..cdce47d9fa36b1 100644 --- a/docs/scripts/formattedTSDemos.js +++ b/docs/scripts/formattedTSDemos.js @@ -17,7 +17,7 @@ const babel = require('@babel/core'); const prettier = require('prettier'); const typescriptToProptypes = require('typescript-to-proptypes'); const yargs = require('yargs'); -const { fixBabelGeneratorIssues, fixLineEndings } = require('./helpers'); +const { fixBabelGeneratorIssues, fixLineEndings } = require('@mui-internal/docs-utilities'); const tsConfig = typescriptToProptypes.loadConfig(path.resolve(__dirname, '../tsconfig.json')); diff --git a/docs/scripts/tsconfig.json b/docs/scripts/tsconfig.json index 642093a4d30cab..c30167c66d748e 100644 --- a/docs/scripts/tsconfig.json +++ b/docs/scripts/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "../../tsconfig.json", - "include": ["../types/react-docgen.d.ts", "buildApi.ts", "i18n.js", "ApiBuilders/**/*"], + "include": ["*.ts", "i18n.js"], "compilerOptions": { "allowJs": true, "isolatedModules": true, @@ -10,6 +10,5 @@ "skipLibCheck": true, "esModuleInterop": true, "types": ["node"] - }, - "exclude": ["node_modules"] + } } diff --git a/docs/src/modules/constants.js b/docs/src/modules/constants.js index 4863975d18e2f9..3a356d0cced23f 100644 --- a/docs/src/modules/constants.js +++ b/docs/src/modules/constants.js @@ -1,11 +1,10 @@ +const { LANGUAGES } = require('../../config'); + const CODE_VARIANTS = { JS: 'JS', TS: 'TS', }; -// Valid languages to server-side render in production -const LANGUAGES = ['en']; - // Server side rendered languages const LANGUAGES_SSR = ['en']; diff --git a/docs/src/modules/utils/find.js b/docs/src/modules/utils/find.js index 952852e4bba698..1c9ca0a1dff28c 100644 --- a/docs/src/modules/utils/find.js +++ b/docs/src/modules/utils/find.js @@ -1,80 +1,6 @@ const fs = require('fs'); const path = require('path'); -/** - * Returns the markdowns of the documentation in a flat array. - * @param {string} [directory] - * @param {Array<{ filename: string, pathname: string }>} [pagesMarkdown] - * @returns {Array<{ filename: string, pathname: string }>} - */ -function findPagesMarkdownNew( - directory = path.resolve(__dirname, '../../../data'), - pagesMarkdown = [], -) { - const items = fs.readdirSync(directory); - - items.forEach((item) => { - const itemPath = path.resolve(directory, item); - - if (fs.statSync(itemPath).isDirectory()) { - findPagesMarkdownNew(itemPath, pagesMarkdown); - return; - } - - if (!/\.md$/.test(item) || /-(zh|pt)\.md/.test(item)) { - // neglect translation markdown - return; - } - - let pathname = itemPath - .replace(new RegExp(`\\${path.sep}`, 'g'), '/') - .replace(/^.*\/data/, '') - .replace('.md', ''); - - // Remove the last pathname segment. - pathname = pathname.split('/').slice(0, 4).join('/'); - - pagesMarkdown.push({ - // Relative location in the path (URL) system. - pathname, - // Relative location in the file system. - filename: itemPath, - }); - }); - - return pagesMarkdown; -} - -const componentRegex = /^(Unstable_)?([A-Z][a-z]+)+\.(js|tsx)/; - -/** - * Returns the component source in a flat array. - * @param {string} directory - * @param {Array<{ filename: string }>} components - */ -function findComponents(directory, components = []) { - const items = fs.readdirSync(directory); - - items.forEach((item) => { - const itemPath = path.resolve(directory, item); - - if (fs.statSync(itemPath).isDirectory()) { - findComponents(itemPath, components); - return; - } - - if (!componentRegex.test(item)) { - return; - } - - components.push({ - filename: itemPath, - }); - }); - - return components; -} - const pageRegex = /(\.js|\.tsx)$/; const blackList = ['/.eslintrc', '/_document', '/_app']; @@ -157,6 +83,4 @@ function findPages( module.exports = { findPages, - findPagesMarkdownNew, - findComponents, }; diff --git a/docs/src/modules/utils/helpers.ts b/docs/src/modules/utils/helpers.ts index e4c53e2746e9a4..d1d61e9851a363 100644 --- a/docs/src/modules/utils/helpers.ts +++ b/docs/src/modules/utils/helpers.ts @@ -106,8 +106,3 @@ export function pathnameToLanguage(pathname: string): { canonicalPathname, }; } - -export function escapeCell(value: string): string { - // As the pipe is use for the table structure - return value.replace(/ { function findApiPages(relativeFolder: string) { let pages: Array<{ pathname: string }> = []; - let filePaths = []; + let filePaths: string[] = []; try { filePaths = getAllFiles(path.join(process.cwd(), relativeFolder)); } catch (error) { diff --git a/docs/scripts/buildApiUtils.test.ts b/packages/api-docs-builder/buildApiUtils.test.ts similarity index 100% rename from docs/scripts/buildApiUtils.test.ts rename to packages/api-docs-builder/buildApiUtils.test.ts diff --git a/docs/scripts/buildApiUtils.ts b/packages/api-docs-builder/buildApiUtils.ts similarity index 98% rename from docs/scripts/buildApiUtils.ts rename to packages/api-docs-builder/buildApiUtils.ts index 9817589bb47fb6..66ddb814f4e292 100644 --- a/docs/scripts/buildApiUtils.ts +++ b/packages/api-docs-builder/buildApiUtils.ts @@ -2,9 +2,9 @@ import fs from 'fs'; import path from 'path'; import kebabCase from 'lodash/kebabCase'; import { getHeaders, getTitle } from '@mui/markdown'; -import { findPagesMarkdownNew } from 'docs/src/modules/utils/find'; -import { getLineFeed } from 'docs/scripts/helpers'; -import { replaceComponentLinks } from 'docs/src/modules/utils/replaceUrl'; +import { getLineFeed } from '@mui-internal/docs-utilities'; +import { replaceComponentLinks } from './utils/replaceUrl'; +import findPagesMarkdownNew from './utils/findPagesMarkdown'; const systemComponents = fs .readdirSync(path.resolve('packages', 'mui-system', 'src')) diff --git a/packages/api-docs-builder/package.json b/packages/api-docs-builder/package.json new file mode 100644 index 00000000000000..5d8e65ed2a4f92 --- /dev/null +++ b/packages/api-docs-builder/package.json @@ -0,0 +1,28 @@ +{ + "name": "@mui-internal/api-docs-builder", + "version": "1.0.0", + "private": "true", + "main": "./buildApi.ts", + "scripts": { + "typescript": "tsc -p tsconfig.json" + }, + "dependencies": { + "@babel/core": "^7.20.2", + "@mui-internal/docs-utilities": "*", + "@mui/markdown": "*", + "ast-types": "^0.14.2", + "doctrine": "^3.0.0", + "lodash": "^4.17.21", + "react-docgen": "^5.4.3", + "recast": "^0.21.5", + "typescript-to-proptypes": "*", + "yargs": "^17.6.2" + }, + "devDependencies": { + "@types/mocha": "^10.0.0", + "@types/node": "^18.11.9", + "chai": "^4.3.7", + "sinon": "^14.0.2", + "typescript": "^4.9.3" + } +} diff --git a/docs/types/react-docgen.d.ts b/packages/api-docs-builder/react-docgen.d.ts similarity index 100% rename from docs/types/react-docgen.d.ts rename to packages/api-docs-builder/react-docgen.d.ts diff --git a/packages/api-docs-builder/tsconfig.json b/packages/api-docs-builder/tsconfig.json new file mode 100644 index 00000000000000..6e20e117b41e8d --- /dev/null +++ b/packages/api-docs-builder/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "allowJs": true, + "isolatedModules": true, + "noEmit": true, + "noUnusedLocals": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "esModuleInterop": true, + "types": ["node", "mocha"], + "target": "ES2020", + "module": "CommonJS", + "moduleResolution": "node", + "strict": true, + "baseUrl": "./", + "paths": { + "react-docgen": ["./react-docgen.d.ts"] + } + }, + "include": ["./**/*.ts", "./**/*.js"], + "exclude": ["node_modules"] +} diff --git a/docs/src/modules/utils/createDescribeableProp.ts b/packages/api-docs-builder/utils/createDescribeableProp.ts similarity index 100% rename from docs/src/modules/utils/createDescribeableProp.ts rename to packages/api-docs-builder/utils/createDescribeableProp.ts diff --git a/docs/src/modules/utils/defaultPropsHandler.js b/packages/api-docs-builder/utils/defaultPropsHandler.ts similarity index 54% rename from docs/src/modules/utils/defaultPropsHandler.js rename to packages/api-docs-builder/utils/defaultPropsHandler.ts index 44367191af71ee..a31d1095312f4d 100644 --- a/docs/src/modules/utils/defaultPropsHandler.js +++ b/packages/api-docs-builder/utils/defaultPropsHandler.ts @@ -1,34 +1,21 @@ -// @ts-check -const astTypes = require('ast-types'); -const { parse: parseDoctrine } = require('doctrine'); -const { utils: docgenUtils } = require('react-docgen'); +import { namedTypes as types } from 'ast-types'; +import { parse as parseDoctrine, Annotation } from 'doctrine'; +import { utils as docgenUtils, NodePath, Documentation, Importer, Handler } from 'react-docgen'; const { getPropertyName, isReactForwardRefCall, printValue, resolveToValue } = docgenUtils; // based on https://github.com/reactjs/react-docgen/blob/735f39ef784312f4c0e740d4bfb812f0a7acd3d5/src/handlers/defaultPropsHandler.js#L1-L112 // adjusted for material-ui getThemedProps -const { namedTypes: types } = astTypes; - -/** - * @param {import('react-docgen').NodePath} propertyPath - * @param {import('react-docgen').Importer} importer - * @returns {{ value: string; computed: boolean } | null} - */ -function getDefaultValue(propertyPath, importer) { +function getDefaultValue(propertyPath: NodePath, importer: Importer) { if (!types.AssignmentPattern.check(propertyPath.get('value').node)) { return null; } - /** - * @type import('react-docgen').NodePath - */ - let path = propertyPath.get('value', 'right'); + + let path: NodePath = propertyPath.get('value', 'right'); let node = path.node; - /** - * @type {string|undefined} - */ - let defaultValue; + let defaultValue: string | undefined; if (types.Literal.check(path.node)) { // @ts-expect-error TODO upstream fix defaultValue = node.raw; @@ -68,11 +55,7 @@ function getDefaultValue(propertyPath, importer) { return null; } -/** - * @param {import('doctrine').Annotation} jsdoc - * @return {{ value: string } | undefined} - */ -function getJsdocDefaultValue(jsdoc) { +function getJsdocDefaultValue(jsdoc: Annotation): { value: string } | undefined { const defaultTag = jsdoc.tags.find((tag) => tag.title === 'default'); if (defaultTag === undefined) { return undefined; @@ -80,37 +63,21 @@ function getJsdocDefaultValue(jsdoc) { return { value: defaultTag.description || '' }; } -/** - * @param {import('react-docgen').NodePath} properties - * @param {import('react-docgen').Documentation} documentation - * @param {import('react-docgen').Importer} importer - * @returns {void} - */ -function getDefaultValuesFromProps(properties, documentation, importer) { +function getDefaultValuesFromProps( + properties: NodePath, + documentation: Documentation, + importer: Importer, +) { const { props: documentedProps } = documentation.toObject(); - /** - * @type Record - */ - const implementedProps = {}; + const implementedProps: Record = {}; properties - .filter( - /** - * @param {import('react-docgen').NodePath} propertyPath - */ - (propertyPath) => types.Property.check(propertyPath.node), - undefined, - ) - .forEach( - /** - * @param {import('react-docgen').NodePath} propertyPath - */ - (propertyPath) => { - const propName = getPropertyName(propertyPath); - if (propName) { - implementedProps[propName] = propertyPath; - } - }, - ); + .filter((propertyPath: NodePath) => types.Property.check(propertyPath.node), undefined) + .forEach((propertyPath: NodePath) => { + const propName = getPropertyName(propertyPath); + if (propName) { + implementedProps[propName] = propertyPath; + } + }); // Sometimes we list props in .propTypes even though they're implemented by another component // These props are spread so they won't appear in the component implementation. @@ -142,12 +109,7 @@ function getDefaultValuesFromProps(properties, documentation, importer) { }); } -/** - * @param {import('react-docgen').NodePath} componentDefinition - * @param {import('react-docgen').Importer} importer - * @returns import('react-docgen').NodePath - */ -function getRenderBody(componentDefinition, importer) { +function getRenderBody(componentDefinition: NodePath, importer: Importer): NodePath { const value = resolveToValue(componentDefinition, importer); if (isReactForwardRefCall(value, importer)) { return value.get('arguments', 0, 'body', 'body'); @@ -155,50 +117,29 @@ function getRenderBody(componentDefinition, importer) { return value.get('body', 'body'); } -/** - * @param {import('react-docgen').NodePath} functionBody - * @returns import('react-docgen').NodePath | undefined - */ -function getPropsPath(functionBody) { - /** - * @type import('react-docgen').NodePath | undefined - */ - let propsPath; +function getPropsPath(functionBody: NodePath): NodePath | undefined { + let propsPath: NodePath | undefined; // visitVariableDeclarator, can't use visit body.node since it looses scope information functionBody - .filter( - /** - * @param {import('react-docgen').NodePath} path - */ - (path) => { - return types.VariableDeclaration.check(path.node); - }, - undefined, - ) - .forEach( - /** - * @param {import('react-docgen').NodePath} path - */ - (path) => { - const declaratorPath = path.get('declarations', 0); - // find `const {} = props` - // but not `const ownerState = props` - if ( - declaratorPath.get('init', 'name').value === 'props' && - declaratorPath.get('id', 'type').value === 'ObjectPattern' - ) { - propsPath = declaratorPath.get('id'); - } - }, - ); + .filter((path: NodePath) => { + return types.VariableDeclaration.check(path.node); + }, undefined) + .forEach((path: NodePath) => { + const declaratorPath = path.get('declarations', 0); + // find `const {} = props` + // but not `const ownerState = props` + if ( + declaratorPath.get('init', 'name').value === 'props' && + declaratorPath.get('id', 'type').value === 'ObjectPattern' + ) { + propsPath = declaratorPath.get('id'); + } + }); return propsPath; } -/** - * @type {import('react-docgen').Handler} - */ -const defaultPropsHandler = (documentation, componentDefinition, importer) => { +const defaultPropsHandler: Handler = (documentation, componentDefinition, importer) => { const renderBody = getRenderBody(componentDefinition, importer); const props = getPropsPath(renderBody); if (props !== undefined) { @@ -206,4 +147,4 @@ const defaultPropsHandler = (documentation, componentDefinition, importer) => { } }; -module.exports = defaultPropsHandler; +export default defaultPropsHandler; diff --git a/packages/api-docs-builder/utils/escapeCell.ts b/packages/api-docs-builder/utils/escapeCell.ts new file mode 100644 index 00000000000000..336895a52bc2c8 --- /dev/null +++ b/packages/api-docs-builder/utils/escapeCell.ts @@ -0,0 +1,4 @@ +export default function escapeCell(value: string): string { + // As the pipe is use for the table structure + return value.replace(/} components + */ +export default function findComponents(directory: string, components: { filename: string }[] = []) { + const items = fs.readdirSync(directory); + + items.forEach((item) => { + const itemPath = path.resolve(directory, item); + + if (fs.statSync(itemPath).isDirectory()) { + findComponents(itemPath, components); + return; + } + + if (!componentRegex.test(item)) { + return; + } + + components.push({ + filename: itemPath, + }); + }); + + return components; +} diff --git a/packages/api-docs-builder/utils/findPagesMarkdown.ts b/packages/api-docs-builder/utils/findPagesMarkdown.ts new file mode 100644 index 00000000000000..83724113c9c633 --- /dev/null +++ b/packages/api-docs-builder/utils/findPagesMarkdown.ts @@ -0,0 +1,48 @@ +import fs from 'fs'; +import path from 'path'; + +interface MarkdownPage { + filename: string; + pathname: string; +} + +/** + * Returns the markdowns of the documentation in a flat array. + */ +export default function findPagesMarkdownNew( + directory: string = path.resolve(__dirname, '../../../docs/data'), + pagesMarkdown: MarkdownPage[] = [], +) { + const items = fs.readdirSync(directory); + + items.forEach((item) => { + const itemPath = path.resolve(directory, item); + + if (fs.statSync(itemPath).isDirectory()) { + findPagesMarkdownNew(itemPath, pagesMarkdown); + return; + } + + if (!/\.md$/.test(item) || /-(zh|pt)\.md/.test(item)) { + // neglect translation markdown + return; + } + + let pathname = itemPath + .replace(new RegExp(`\\${path.sep}`, 'g'), '/') + .replace(/^.*\/data/, '') + .replace('.md', ''); + + // Remove the last pathname segment. + pathname = pathname.split('/').slice(0, 4).join('/'); + + pagesMarkdown.push({ + // Relative location in the path (URL) system. + pathname, + // Relative location in the file system. + filename: itemPath, + }); + }); + + return pagesMarkdown; +} diff --git a/docs/src/modules/utils/generatePropDescription.ts b/packages/api-docs-builder/utils/generatePropDescription.ts similarity index 97% rename from docs/src/modules/utils/generatePropDescription.ts rename to packages/api-docs-builder/utils/generatePropDescription.ts index 4b41e15deb5d9f..3fd2b93fd24a44 100644 --- a/docs/src/modules/utils/generatePropDescription.ts +++ b/packages/api-docs-builder/utils/generatePropDescription.ts @@ -4,9 +4,9 @@ import { PropTypeDescriptor } from 'react-docgen'; import { isElementTypeAcceptingRefProp, isElementAcceptingRefProp, -} from 'docs/src/modules/utils/generatePropTypeDescription'; +} from './generatePropTypeDescription'; import { DescribeablePropDescriptor } from './createDescribeableProp'; -import { escapeCell } from './helpers'; +import escapeCell from './escapeCell'; function resolveType(type: NonNullable): string { if (type.type === 'AllLiteral') { diff --git a/docs/src/modules/utils/generatePropTypeDescription.ts b/packages/api-docs-builder/utils/generatePropTypeDescription.ts similarity index 98% rename from docs/src/modules/utils/generatePropTypeDescription.ts rename to packages/api-docs-builder/utils/generatePropTypeDescription.ts index 8b42bca1c57a03..66fdf8335e078a 100644 --- a/docs/src/modules/utils/generatePropTypeDescription.ts +++ b/packages/api-docs-builder/utils/generatePropTypeDescription.ts @@ -1,6 +1,6 @@ import * as recast from 'recast'; import { parse as docgenParse, PropTypeDescriptor } from 'react-docgen'; -import { escapeCell } from './helpers'; +import escapeCell from './escapeCell'; function getDeprecatedInfo(type: PropTypeDescriptor) { const marker = /deprecatedPropType\((\r*\n)*\s*PropTypes\./g; diff --git a/docs/src/modules/utils/parseStyles.ts b/packages/api-docs-builder/utils/parseStyles.ts similarity index 100% rename from docs/src/modules/utils/parseStyles.ts rename to packages/api-docs-builder/utils/parseStyles.ts diff --git a/docs/src/modules/utils/parseTest.ts b/packages/api-docs-builder/utils/parseTest.ts similarity index 98% rename from docs/src/modules/utils/parseTest.ts rename to packages/api-docs-builder/utils/parseTest.ts index ce88c0a05f3767..496a9114a8e53b 100644 --- a/docs/src/modules/utils/parseTest.ts +++ b/packages/api-docs-builder/utils/parseTest.ts @@ -2,7 +2,7 @@ import * as babel from '@babel/core'; import { readFile, existsSync } from 'fs-extra'; import * as path from 'path'; -const workspaceRoot = path.join(__dirname, '../../../../'); +const workspaceRoot = path.join(__dirname, '../../../'); const babelConfigPath = path.join(workspaceRoot, 'babel.config.js'); function withExtension(filepath: string, extension: string) { diff --git a/docs/src/modules/utils/replaceUrl.test.js b/packages/api-docs-builder/utils/replaceUrl.test.js similarity index 100% rename from docs/src/modules/utils/replaceUrl.test.js rename to packages/api-docs-builder/utils/replaceUrl.test.js diff --git a/docs/src/modules/utils/replaceUrl.ts b/packages/api-docs-builder/utils/replaceUrl.ts similarity index 100% rename from docs/src/modules/utils/replaceUrl.ts rename to packages/api-docs-builder/utils/replaceUrl.ts diff --git a/packages/docs-utilities/README.md b/packages/docs-utilities/README.md new file mode 100644 index 00000000000000..4f6c361f66aaa3 --- /dev/null +++ b/packages/docs-utilities/README.md @@ -0,0 +1,5 @@ +# @mui-internal/docs-utilities + +This package contains utilities shared between docs generation scripts. + +It is private and not meant to be published. diff --git a/packages/docs-utilities/index.d.ts b/packages/docs-utilities/index.d.ts new file mode 100644 index 00000000000000..51b6c86fe0b7b3 --- /dev/null +++ b/packages/docs-utilities/index.d.ts @@ -0,0 +1,7 @@ +export function getLineFeed(source: string): string; + +export function fixBabelGeneratorIssues(source: string): string; + +export function fixLineEndings(source: string, target: string): string; + +export function getUnstyledFilename(filename: string, definitionFile: boolean = false): string; diff --git a/docs/scripts/helpers.js b/packages/docs-utilities/index.js similarity index 91% rename from docs/scripts/helpers.js rename to packages/docs-utilities/index.js index 27b95d16c6e41c..5e85f7acf48d84 100644 --- a/docs/scripts/helpers.js +++ b/packages/docs-utilities/index.js @@ -1,11 +1,11 @@ -const os = require('os'); +const { EOL } = require('os'); /** * @param {string} source */ function getLineFeed(source) { const match = source.match(/\r?\n/); - return match === null ? os.EOL : match[0]; + return match === null ? EOL : match[0]; } const fixBabelIssuesRegExp = /(?<=(\/>)|,)(\r?\n){2}/g; @@ -73,9 +73,4 @@ function getUnstyledFilename(filename, definitionFile = false) { return definitionFile ? `${unstyledFile}.d.ts` : `${unstyledFile}.js`; } -module.exports = { - getLineFeed, - fixBabelGeneratorIssues, - fixLineEndings, - getUnstyledFilename, -}; +export { getLineFeed, fixBabelGeneratorIssues, fixLineEndings, getUnstyledFilename }; diff --git a/packages/docs-utilities/package.json b/packages/docs-utilities/package.json new file mode 100644 index 00000000000000..740cec8962e5ce --- /dev/null +++ b/packages/docs-utilities/package.json @@ -0,0 +1,6 @@ +{ + "name": "@mui-internal/docs-utilities", + "version": "1.0.0", + "private": "true", + "main": "index.js" +} diff --git a/packages/mui-system/src/ThemeProvider/ThemeProvider.test.js b/packages/mui-system/src/ThemeProvider/ThemeProvider.test.js index dbf974f6e35542..4572c1d001b4e6 100644 --- a/packages/mui-system/src/ThemeProvider/ThemeProvider.test.js +++ b/packages/mui-system/src/ThemeProvider/ThemeProvider.test.js @@ -22,7 +22,8 @@ describe('ThemeProvider', () => { , ); - expect(theme).to.deep.equal({ foo: 'foo' }); + + expect(theme).to.include({ foo: 'foo' }); }); it('should provide the theme to the styled engine theme context', () => { @@ -39,6 +40,6 @@ describe('ThemeProvider', () => { , ); - expect(theme).to.deep.equal({ foo: 'foo' }); + expect(theme).to.include({ foo: 'foo' }); }); }); diff --git a/packages/typescript-to-proptypes/package.json b/packages/typescript-to-proptypes/package.json index 7b030b910c22a1..e38f5ca0926a4e 100644 --- a/packages/typescript-to-proptypes/package.json +++ b/packages/typescript-to-proptypes/package.json @@ -8,6 +8,7 @@ "url": "https://github.com/mui/material-ui.git", "directory": "packages/typescript-to-proptypes" }, + "main": "src/index.ts", "author": "merceyz ", "license": "MIT", "keywords": [ diff --git a/scripts/generateProptypes.ts b/scripts/generateProptypes.ts index 5a67fc82178292..3f06821d90d4f6 100644 --- a/scripts/generateProptypes.ts +++ b/scripts/generateProptypes.ts @@ -10,7 +10,7 @@ import { fixBabelGeneratorIssues, fixLineEndings, getUnstyledFilename, -} from '../docs/scripts/helpers'; +} from '@mui-internal/docs-utilities'; const useExternalPropsFromInputBase = [ 'autoComplete', @@ -356,7 +356,7 @@ async function run(argv: HandlerArgv) { const sourceFile = tsFile.includes('.d.ts') ? tsFile.replace('.d.ts', '.js') : tsFile; try { await generateProptypes(program, sourceFile, tsFile); - } catch (error) { + } catch (error: any) { error.message = `${tsFile}: ${error.message}`; throw error; } @@ -377,7 +377,7 @@ async function run(argv: HandlerArgv) { } yargs - .command({ + .command({ command: '$0', describe: 'Generates Component.propTypes from TypeScript declarations', builder: (command) => { diff --git a/yarn.lock b/yarn.lock index a79306da6efbac..59034b01b93565 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3130,7 +3130,21 @@ dependencies: type-detect "4.0.8" -"@sinonjs/fake-timers@>=5", "@sinonjs/fake-timers@^9.1.2": +"@sinonjs/commons@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-2.0.0.tgz#fd4ca5b063554307e8327b4564bd56d3b73924a3" + integrity sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg== + dependencies: + type-detect "4.0.8" + +"@sinonjs/fake-timers@^7.0.4": + version "7.1.2" + resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-7.1.2.tgz#2524eae70c4910edccf99b2f4e6efc5894aff7b5" + integrity sha512-iQADsW4LBMISqZ6Ci1dupJL9pprqwcVFTcOsEmQOEhW+KLCVn/Y4Jrvg2k19fIHCp+iFprriYPTdRcQR8NbUPg== + dependencies: + "@sinonjs/commons" "^1.7.0" + +"@sinonjs/fake-timers@^9.1.2": version "9.1.2" resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-9.1.2.tgz#4eaab737fab77332ab132d396a3c0d364bd0ea8c" integrity sha512-BPS4ynJW/o92PUR4wgriz2Ud5gpST5vz6GQfMixEDK0Z8ZCUv2M7SkBLykH56T++Xs+8ln9zTGbOvNGIe02/jw== @@ -3146,6 +3160,15 @@ lodash.get "^4.4.2" type-detect "^4.0.8" +"@sinonjs/samsam@^7.0.1": + version "7.0.1" + resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-7.0.1.tgz#5b5fa31c554636f78308439d220986b9523fc51f" + integrity sha512-zsAk2Jkiq89mhZovB2LLOdTCxJF4hqqTToGP0ASWlhp4I1hqOjcfmZGafXntCN7MDC6yySH0mFHrYtHceOeLmw== + dependencies: + "@sinonjs/commons" "^2.0.0" + lodash.get "^4.4.2" + type-detect "^4.0.8" + "@sinonjs/text-encoding@^0.7.1": version "0.7.2" resolved "https://registry.yarnpkg.com/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz#5981a8db18b56ba38ef0efb7d995b12aa7b51918" @@ -3691,7 +3714,7 @@ resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.0.tgz#3d9018c575f0e3f7386c1de80ee66cc21fbb7a52" integrity sha512-rADY+HtTOA52l9VZWtgQfn4p+UDVM2eDVkMZT1I6syp0YKxW2F9v+0pbRZLsvskhQv/vMb6ZfCay81GHbz5SHg== -"@types/node@*", "@types/node@>=10.0.0": +"@types/node@*", "@types/node@>=10.0.0", "@types/node@^18.11.9": version "18.11.9" resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.9.tgz#02d013de7058cea16d36168ef2fc653464cfbad4" integrity sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg== @@ -5426,14 +5449,14 @@ chai-dom@^1.11.0: resolved "https://registry.yarnpkg.com/chai-dom/-/chai-dom-1.11.0.tgz#aa3af405b3d9b0470d185b17081ed23ca5fdaeb4" integrity sha512-ZzGlEfk1UhHH5+N0t9bDqstOxPEXmn3EyXvtsok5rfXVDOFDJbHVy12rED6ZwkJAUDs2w7/Da4Hlq2LB63kltg== -chai@^4.3.6: - version "4.3.6" - resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.6.tgz#ffe4ba2d9fa9d6680cc0b370adae709ec9011e9c" - integrity sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q== +chai@^4.3.6, chai@^4.3.7: + version "4.3.7" + resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.7.tgz#ec63f6df01829088e8bf55fca839bcd464a8ec51" + integrity sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A== dependencies: assertion-error "^1.1.0" check-error "^1.0.2" - deep-eql "^3.0.1" + deep-eql "^4.1.2" get-func-name "^2.0.0" loupe "^2.3.1" pathval "^1.1.1" @@ -6669,10 +6692,10 @@ dedent@^0.7.0: resolved "https://registry.yarnpkg.com/dedent/-/dedent-0.7.0.tgz#2495ddbaf6eb874abb0e1be9df22d2e5a544326c" integrity sha512-Q6fKUPqnAHAyhiUgFU7BUzLiv0kd8saH9al7tnu5Q/okj6dnupxyTgFIBjVzJATdfIAm9NAsvXNzjaKa+bxVyA== -deep-eql@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df" - integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw== +deep-eql@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.2.tgz#270ceb902f87724077e6f6449aed81463f42fc1c" + integrity sha512-gT18+YW4CcW/DBNTwAmqTtkJh7f9qqScu2qFVlx7kCoeY9tlBu9cUcr7+I+Z/noG8INehS3xQgLpTtd/QUTn4w== dependencies: type-detect "^4.0.0" @@ -11565,13 +11588,13 @@ nice-try@^1.0.4: resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== -nise@^5.1.1: - version "5.1.1" - resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.1.tgz#ac4237e0d785ecfcb83e20f389185975da5c31f3" - integrity sha512-yr5kW2THW1AkxVmCnKEh4nbYkJdB3I7LUkiUgOvEkOp414mc2UMaHMA7pjq1nYowhdoJZGwEKGaQVbxfpWj10A== +nise@^5.1.1, nise@^5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.2.tgz#a7b8909c216b3491fd4fc0b124efb69f3939b449" + integrity sha512-+gQjFi8v+tkfCuSCxfURHLhRhniE/+IaYbIphxAN2JRR9SHKhY8hgXpaXiYfHdw+gcGe4buxgbprBQFab9FkhA== dependencies: - "@sinonjs/commons" "^1.8.3" - "@sinonjs/fake-timers" ">=5" + "@sinonjs/commons" "^2.0.0" + "@sinonjs/fake-timers" "^7.0.4" "@sinonjs/text-encoding" "^0.7.1" just-extend "^4.0.2" path-to-regexp "^1.7.0" @@ -14404,6 +14427,18 @@ sinon@^13.0.2: nise "^5.1.1" supports-color "^7.2.0" +sinon@^14.0.2: + version "14.0.2" + resolved "https://registry.yarnpkg.com/sinon/-/sinon-14.0.2.tgz#585a81a3c7b22cf950762ac4e7c28eb8b151c46f" + integrity sha512-PDpV0ZI3ZCS3pEqx0vpNp6kzPhHrLx72wA0G+ZLaaJjLIYeE0n8INlgaohKuGy7hP0as5tbUd23QWu5U233t+w== + dependencies: + "@sinonjs/commons" "^2.0.0" + "@sinonjs/fake-timers" "^9.1.2" + "@sinonjs/samsam" "^7.0.1" + diff "^5.0.0" + nise "^5.1.2" + supports-color "^7.2.0" + sirv@^1.0.7: version "1.0.19" resolved "https://registry.yarnpkg.com/sirv/-/sirv-1.0.19.tgz#1d73979b38c7fe91fcba49c85280daa9c2363b49"