From 218c38d4dfeeafa452da3a3408682ea6dfe3940a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Mon, 29 Jan 2024 11:16:25 +0100 Subject: [PATCH 1/6] Publish @mui-internal/docs-utils to npm --- .codesandbox/ci.json | 6 +- babel.config.js | 1 + docs/package.json | 2 +- docs/scripts/formattedTSDemos.js | 2 +- .../components/ApiPage/list/ClassesList.tsx | 2 +- .../ApiPage/sections/ClassesSection.tsx | 2 +- .../components/ApiPage/table/ClassesTable.tsx | 2 +- package.json | 8 +- .../ApiBuilders/ComponentApiBuilder.ts | 2 +- packages/api-docs-builder/ProjectSettings.ts | 2 +- packages/api-docs-builder/buildApiUtils.ts | 2 +- packages/api-docs-builder/package.json | 2 +- packages/api-docs-builder/tsconfig.json | 2 +- .../utils/parseSlotsAndClasses.ts | 2 +- packages/docs-utilities/README.md | 5 - packages/docs-utilities/index.d.ts | 9 - packages/docs-utilities/package.json | 6 - packages/docs-utilities/tsconfig.json | 19 - packages/docs-utils/CHANGELOG.md | 5 + packages/docs-utils/README.md | 9 + packages/docs-utils/package.json | 27 ++ .../src}/ComponentClassDefinition.ts | 0 .../docs-utils/src/createTypeScriptProject.ts | 131 +++++++ .../src/getPropsFromComponentNode.ts | 358 ++++++++++++++++++ .../index.js => docs-utils/src/index.ts} | 29 +- packages/docs-utils/tsconfig.build.json | 15 + packages/docs-utils/tsconfig.json | 11 + pnpm-lock.yaml | 25 +- scripts/generateProptypes.ts | 2 +- tsconfig.json | 1 + webpackBaseConfig.js | 1 + 31 files changed, 606 insertions(+), 84 deletions(-) delete mode 100644 packages/docs-utilities/README.md delete mode 100644 packages/docs-utilities/index.d.ts delete mode 100644 packages/docs-utilities/package.json delete mode 100644 packages/docs-utilities/tsconfig.json create mode 100644 packages/docs-utils/CHANGELOG.md create mode 100644 packages/docs-utils/README.md create mode 100644 packages/docs-utils/package.json rename packages/{docs-utilities => docs-utils/src}/ComponentClassDefinition.ts (100%) create mode 100644 packages/docs-utils/src/createTypeScriptProject.ts create mode 100644 packages/docs-utils/src/getPropsFromComponentNode.ts rename packages/{docs-utilities/index.js => docs-utils/src/index.ts} (66%) create mode 100644 packages/docs-utils/tsconfig.build.json create mode 100644 packages/docs-utils/tsconfig.json diff --git a/.codesandbox/ci.json b/.codesandbox/ci.json index d2b89fcb8f7adc..04e30677f9fb1c 100644 --- a/.codesandbox/ci.json +++ b/.codesandbox/ci.json @@ -18,7 +18,8 @@ "packages/mui-styles", "packages/mui-system", "packages/mui-types", - "packages/mui-utils" + "packages/mui-utils", + "packages/docs-utils" ], "publishDirectory": { "@mui/base": "packages/mui-base/build", @@ -36,7 +37,8 @@ "@mui/styles": "packages/mui-styles/build", "@mui/system": "packages/mui-system/build", "@mui/types": "packages/mui-types/build", - "@mui/utils": "packages/mui-utils/build" + "@mui/utils": "packages/mui-utils/build", + "@mui-internal/docs-utils": "packages/docs-utils" }, "sandboxes": [ "material-ui-issue-latest-s2dsx", diff --git a/babel.config.js b/babel.config.js index eca2870ce49edb..f04e19b097f92f 100644 --- a/babel.config.js +++ b/babel.config.js @@ -33,6 +33,7 @@ module.exports = function getBabelConfig(api) { '@mui/material-next': resolveAliasPath('./packages/mui-material-next/src'), '@mui/joy': resolveAliasPath('./packages/mui-joy/src'), '@mui/zero-runtime': resolveAliasPath('./packages/zero-runtime/src'), + '@mui-internal/docs-utils': resolveAliasPath('./packages/docs-utils/src'), docs: resolveAliasPath('./docs'), test: resolveAliasPath('./test'), }; diff --git a/docs/package.json b/docs/package.json index a7d3b9c16b9042..445bb4edaea388 100644 --- a/docs/package.json +++ b/docs/package.json @@ -117,7 +117,7 @@ "devDependencies": { "@babel/plugin-transform-react-constant-elements": "^7.23.3", "@babel/preset-typescript": "^7.23.3", - "@mui-internal/docs-utilities": "workspace:^", + "@mui-internal/docs-utils": "workspace:^", "@mui-internal/test-utils": "workspace:^", "@types/autosuggest-highlight": "^3.2.3", "@types/chai": "^4.3.11", diff --git a/docs/scripts/formattedTSDemos.js b/docs/scripts/formattedTSDemos.js index 31e9cce36ea25d..ebc2f5a1b9dc06 100644 --- a/docs/scripts/formattedTSDemos.js +++ b/docs/scripts/formattedTSDemos.js @@ -20,7 +20,7 @@ const { createTypeScriptProjectBuilder, } = require('@mui-internal/api-docs-builder/utils/createTypeScriptProject'); const yargs = require('yargs'); -const { fixBabelGeneratorIssues, fixLineEndings } = require('@mui-internal/docs-utilities'); +const { fixBabelGeneratorIssues, fixLineEndings } = require('@mui-internal/docs-utils'); const { default: CORE_TYPESCRIPT_PROJECTS } = require('../../scripts/coreTypeScriptProjects'); const babelConfig = { diff --git a/docs/src/modules/components/ApiPage/list/ClassesList.tsx b/docs/src/modules/components/ApiPage/list/ClassesList.tsx index ed4fc21b901be7..b10494b62882f3 100644 --- a/docs/src/modules/components/ApiPage/list/ClassesList.tsx +++ b/docs/src/modules/components/ApiPage/list/ClassesList.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { styled } from '@mui/material/styles'; import kebabCase from 'lodash/kebabCase'; -import { ComponentClassDefinition } from '@mui-internal/docs-utilities'; +import { ComponentClassDefinition } from '@mui-internal/docs-utils'; import { useTranslate } from 'docs/src/modules/utils/i18n'; import ExpandableApiItem, { ApiItemContaier, diff --git a/docs/src/modules/components/ApiPage/sections/ClassesSection.tsx b/docs/src/modules/components/ApiPage/sections/ClassesSection.tsx index 318c159fc6e78d..8c1a714b58d022 100644 --- a/docs/src/modules/components/ApiPage/sections/ClassesSection.tsx +++ b/docs/src/modules/components/ApiPage/sections/ClassesSection.tsx @@ -1,7 +1,7 @@ /* eslint-disable react/no-danger */ import * as React from 'react'; import { useTranslate } from 'docs/src/modules/utils/i18n'; -import { ComponentClassDefinition } from '@mui-internal/docs-utilities'; +import { ComponentClassDefinition } from '@mui-internal/docs-utils'; import Box from '@mui/material/Box'; import ToggleDisplayOption, { API_LAYOUT_STORAGE_KEYS, diff --git a/docs/src/modules/components/ApiPage/table/ClassesTable.tsx b/docs/src/modules/components/ApiPage/table/ClassesTable.tsx index 881be9202db048..604259f7682599 100644 --- a/docs/src/modules/components/ApiPage/table/ClassesTable.tsx +++ b/docs/src/modules/components/ApiPage/table/ClassesTable.tsx @@ -1,6 +1,6 @@ /* eslint-disable react/no-danger */ import * as React from 'react'; -import { ComponentClassDefinition } from '@mui-internal/docs-utilities'; +import { ComponentClassDefinition } from '@mui-internal/docs-utils'; import { styled, alpha } from '@mui/material/styles'; import { brandingDarkTheme as darkTheme, diff --git a/package.json b/package.json index d48f0129b3ab65..529b97e2f2be42 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,13 @@ "private": true, "scripts": { "preinstall": "npx only-allow pnpm", - "proptypes": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" ./scripts/generateProptypes.ts", + "proptypes": "tsx ./scripts/generateProptypes.ts", "deduplicate": "pnpm dedupe", "benchmark:browser": "pnpm --filter benchmark browser", "build": "lerna run --scope \"@mui/*\" build", "build:zero": "lerna run --scope \"@mui/zero-*\" build", "clean:zero": "pnpm --filter \"@mui/zero-*\" clean", - "build:codesandbox": "NODE_OPTIONS=\"–max_old_space_size=4096\" lerna run --concurrency 8 --scope \"@mui/*\" build", + "build:codesandbox": "NODE_OPTIONS=\"--max_old_space_size=4096\" lerna run --concurrency 8 --scope \"@mui/*\" --scope \"@mui-internal/*\" --no-private build", "release:version": "lerna version --no-changelog --no-push --no-git-tag-version --no-private --force-publish=@mui/core-downloads-tracker", "release:build": "lerna run --concurrency 8 --scope \"@mui/*\" build --skip-nx-cache", "release:changelog": "node scripts/releaseChangelog.mjs", @@ -33,7 +33,7 @@ "docs:link-check": "pnpm --filter docs link-check", "docs:typescript": "pnpm docs:typescript:formatted --watch", "docs:typescript:check": "pnpm --filter docs typescript", - "docs:typescript:formatted": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" ./docs/scripts/formattedTSDemos", + "docs:typescript:formatted": "tsx ./docs/scripts/formattedTSDemos", "docs:mdicons:synonyms": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js,.mjs\" ./docs/scripts/updateIconSynonyms && pnpm prettier", "extract-error-codes": "cross-env MUI_EXTRACT_ERROR_CODES=true lerna run --concurrency 8 build:modern", "rsc:build": "tsx ./packages/rsc-builder/buildRsc.ts", @@ -102,7 +102,7 @@ "@mnajdova/enzyme-adapter-react-18": "^0.2.0", "@mui-internal/api-docs-builder": "workspace:^", "@mui-internal/api-docs-builder-core": "workspace:^", - "@mui-internal/docs-utilities": "workspace:^", + "@mui-internal/docs-utils": "workspace:^", "@mui-internal/test-utils": "workspace:^", "@mui/joy": "workspace:*", "@mui/material": "workspace:^", diff --git a/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts b/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts index 8a425543ce8e3d..a0921b4325c1ed 100644 --- a/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts +++ b/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts @@ -10,7 +10,7 @@ import remarkVisit from 'unist-util-visit'; import type { Link } from 'mdast'; import { defaultHandlers, parse as docgenParse, ReactDocgenApi } from 'react-docgen'; import { renderMarkdown } from '@mui/markdown'; -import { ComponentClassDefinition } from '@mui-internal/docs-utilities'; +import { ComponentClassDefinition } from '@mui-internal/docs-utils'; import { ProjectSettings, SortingStrategiesType } from '../ProjectSettings'; import { ComponentInfo, toGitHubPath, writePrettifiedFile } from '../buildApiUtils'; import muiDefaultPropsHandler from '../utils/defaultPropsHandler'; diff --git a/packages/api-docs-builder/ProjectSettings.ts b/packages/api-docs-builder/ProjectSettings.ts index f7a210a03b1377..3a848328893462 100644 --- a/packages/api-docs-builder/ProjectSettings.ts +++ b/packages/api-docs-builder/ProjectSettings.ts @@ -1,4 +1,4 @@ -import { ComponentClassDefinition } from '@mui-internal/docs-utilities/ComponentClassDefinition'; +import { ComponentClassDefinition } from '@mui-internal/docs-utils'; import { ComponentInfo, HookInfo } from './buildApiUtils'; import { CreateTypeScriptProjectOptions } from './utils/createTypeScriptProject'; import { CreateDescribeablePropSettings } from './utils/createDescribeableProp'; diff --git a/packages/api-docs-builder/buildApiUtils.ts b/packages/api-docs-builder/buildApiUtils.ts index 6afbfdd2d99565..1ef45d3484ca66 100644 --- a/packages/api-docs-builder/buildApiUtils.ts +++ b/packages/api-docs-builder/buildApiUtils.ts @@ -3,7 +3,7 @@ import path from 'path'; import * as ts from 'typescript'; import * as prettier from 'prettier'; import kebabCase from 'lodash/kebabCase'; -import { getLineFeed } from '@mui-internal/docs-utilities'; +import { getLineFeed } from '@mui-internal/docs-utils'; import { replaceComponentLinks } from './utils/replaceUrl'; import { TypeScriptProject } from './utils/createTypeScriptProject'; diff --git a/packages/api-docs-builder/package.json b/packages/api-docs-builder/package.json index e82d3e68475c74..fbfde5233bca91 100644 --- a/packages/api-docs-builder/package.json +++ b/packages/api-docs-builder/package.json @@ -11,7 +11,7 @@ "@babel/core": "^7.23.9", "@babel/preset-typescript": "^7.23.3", "@babel/traverse": "^7.23.9", - "@mui-internal/docs-utilities": "workspace:^", + "@mui-internal/docs-utils": "workspace:^", "@mui/markdown": "workspace:^", "ast-types": "^0.14.2", "doctrine": "^3.0.0", diff --git a/packages/api-docs-builder/tsconfig.json b/packages/api-docs-builder/tsconfig.json index f3d2e445296da4..41e0c9ff506e27 100644 --- a/packages/api-docs-builder/tsconfig.json +++ b/packages/api-docs-builder/tsconfig.json @@ -14,7 +14,7 @@ "strict": true, "baseUrl": "./", "paths": { - "@mui/utils": ["../mui-utils/src"] + "@mui-internal/docs-utils": ["../docs-utils/src"] } }, "include": ["./**/*.ts", "./**/*.js"], diff --git a/packages/api-docs-builder/utils/parseSlotsAndClasses.ts b/packages/api-docs-builder/utils/parseSlotsAndClasses.ts index dc9718adc605f8..d2e44deda109cd 100644 --- a/packages/api-docs-builder/utils/parseSlotsAndClasses.ts +++ b/packages/api-docs-builder/utils/parseSlotsAndClasses.ts @@ -1,5 +1,5 @@ import * as ts from 'typescript'; -import { ComponentClassDefinition } from '@mui-internal/docs-utilities'; +import { ComponentClassDefinition } from '@mui-internal/docs-utils'; import { renderMarkdown } from '@mui/markdown'; import { getSymbolDescription, getSymbolJSDocTags } from '../buildApiUtils'; import { TypeScriptProject } from './createTypeScriptProject'; diff --git a/packages/docs-utilities/README.md b/packages/docs-utilities/README.md deleted file mode 100644 index 4f6c361f66aaa3..00000000000000 --- a/packages/docs-utilities/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# @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 deleted file mode 100644 index 1f3c455258ef5c..00000000000000 --- a/packages/docs-utilities/index.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -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): string; - -export * from './ComponentClassDefinition'; diff --git a/packages/docs-utilities/package.json b/packages/docs-utilities/package.json deleted file mode 100644 index 740cec8962e5ce..00000000000000 --- a/packages/docs-utilities/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "@mui-internal/docs-utilities", - "version": "1.0.0", - "private": "true", - "main": "index.js" -} diff --git a/packages/docs-utilities/tsconfig.json b/packages/docs-utilities/tsconfig.json deleted file mode 100644 index 4a58f12da89c7e..00000000000000 --- a/packages/docs-utilities/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "allowJs": true, - "isolatedModules": true, - "noEmit": true, - "noUnusedLocals": false, - "resolveJsonModule": true, - "skipLibCheck": true, - "esModuleInterop": true, - "types": ["node", "mocha"], - "target": "ES2020", - "module": "CommonJS", - "moduleResolution": "node", - "strict": true, - "baseUrl": "./" - }, - "include": ["./**/*.ts", "./**/*.js"], - "exclude": ["node_modules"] -} diff --git a/packages/docs-utils/CHANGELOG.md b/packages/docs-utils/CHANGELOG.md new file mode 100644 index 00000000000000..a6c93f9bf457a6 --- /dev/null +++ b/packages/docs-utils/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 1.0.0 + +Initial release as an npm package. diff --git a/packages/docs-utils/README.md b/packages/docs-utils/README.md new file mode 100644 index 00000000000000..8a19bc3cbc5e1a --- /dev/null +++ b/packages/docs-utils/README.md @@ -0,0 +1,9 @@ +# @mui-internal/docs-utils + +This package contains utilities shared between MUI docs generation scripts. +This is an internal package not meant for general use. + +## Release + +1. Build the project: `pnpm build` +2. Publish the build artifacts to npm: `pnpm release:publish` diff --git a/packages/docs-utils/package.json b/packages/docs-utils/package.json new file mode 100644 index 00000000000000..3210c4509a408a --- /dev/null +++ b/packages/docs-utils/package.json @@ -0,0 +1,27 @@ +{ + "name": "@mui-internal/docs-utils", + "version": "1.0.0", + "author": "MUI Team", + "description": "Utilities for MUI docs. This is an internal package not meant for general use.", + "main": "./build/index.js", + "exports": { + ".": "./build/index.js" + }, + "types": "./build/index.d.ts", + "repository": { + "type": "git", + "url": "https://github.com/mui/material-ui.git", + "directory": "packages/docs-utils" + }, + "scripts": { + "prebuild": "rimraf ./build", + "build": "tsc -b tsconfig.build.json", + "typescript": "tsc -b tsconfig.json", + "release:publish": "pnpm publish --tag latest", + "release:publish:dry-run": "pnpm publish --tag latest --registry=\"http://localhost:4873/\"" + }, + "dependencies": { + "rimraf": "^5.0.5", + "typescript": "^5.1.6" + } +} diff --git a/packages/docs-utilities/ComponentClassDefinition.ts b/packages/docs-utils/src/ComponentClassDefinition.ts similarity index 100% rename from packages/docs-utilities/ComponentClassDefinition.ts rename to packages/docs-utils/src/ComponentClassDefinition.ts diff --git a/packages/docs-utils/src/createTypeScriptProject.ts b/packages/docs-utils/src/createTypeScriptProject.ts new file mode 100644 index 00000000000000..ba3b64e54df3c2 --- /dev/null +++ b/packages/docs-utils/src/createTypeScriptProject.ts @@ -0,0 +1,131 @@ +import path from 'path'; +import fs from 'fs'; +import * as ts from 'typescript'; + +export interface TypeScriptProject { + name: string; + rootPath: string; + exports: Record; + program: ts.Program; + checker: ts.TypeChecker; +} + +export interface CreateTypeScriptProjectOptions { + name: string; + rootPath: string; + /** + * Config to use to build this package. + * The path must be relative to the root path. + * @default 'tsconfig.build.json` + */ + tsConfigPath?: string; + /** + * File used as root of the package. + * This property is used to gather the exports of the project. + * The path must be relative to the root path. + */ + entryPointPath?: string; + /** + * Files to include in the project. + * By default, it will use the files defined in the tsconfig. + */ + files?: string[]; +} + +export const createTypeScriptProject = ( + options: CreateTypeScriptProjectOptions, +): TypeScriptProject => { + const { + name, + rootPath, + tsConfigPath: inputTsConfigPath = 'tsconfig.build.json', + entryPointPath: inputEntryPointPath, + files, + } = options; + + const tsConfigPath = path.join(rootPath, inputTsConfigPath); + + const tsConfigFile = ts.readConfigFile(tsConfigPath, (filePath) => + fs.readFileSync(filePath).toString(), + ); + + if (tsConfigFile.error) { + throw tsConfigFile.error; + } + + // The build config does not parse the `.d.ts` files, but we sometimes need them to get the exports. + if (tsConfigFile.config.exclude) { + tsConfigFile.config.exclude = tsConfigFile.config.exclude.filter( + (pattern: string) => pattern !== 'src/**/*.d.ts', + ); + } + + const tsConfigFileContent = ts.parseJsonConfigFileContent( + tsConfigFile.config, + ts.sys, + path.dirname(tsConfigPath), + ); + + if (tsConfigFileContent.errors.length > 0) { + throw tsConfigFileContent.errors[0]; + } + + const program = ts.createProgram({ + rootNames: files ?? tsConfigFileContent.fileNames, + options: tsConfigFileContent.options, + }); + + const checker = program.getTypeChecker(); + + let exports: TypeScriptProject['exports']; + if (inputEntryPointPath) { + const entryPointPath = path.join(rootPath, inputEntryPointPath); + const sourceFile = program.getSourceFile(entryPointPath); + + exports = Object.fromEntries( + checker.getExportsOfModule(checker.getSymbolAtLocation(sourceFile!)!).map((symbol) => { + return [symbol.name, symbol]; + }), + ); + } else { + exports = {}; + } + + return { + name, + rootPath, + exports, + program, + checker, + }; +}; + +export type TypeScriptProjectBuilder = ( + projectName: string, + options?: { files?: string[] }, +) => TypeScriptProject; + +export const createTypeScriptProjectBuilder = ( + projectsConfig: Record>, +): TypeScriptProjectBuilder => { + const projects = new Map(); + + return (projectName: string, options: { files?: string[] } = {}) => { + const cachedProject = projects.get(projectName); + if (cachedProject != null) { + return cachedProject; + } + + // eslint-disable-next-line no-console + console.log(`Building new TS project: ${projectName}`); + + const project = createTypeScriptProject({ + name: projectName, + ...projectsConfig[projectName], + ...options, + }); + + projects.set(projectName, project); + return project; + }; +}; diff --git a/packages/docs-utils/src/getPropsFromComponentNode.ts b/packages/docs-utils/src/getPropsFromComponentNode.ts new file mode 100644 index 00000000000000..2e2036fcaa9472 --- /dev/null +++ b/packages/docs-utils/src/getPropsFromComponentNode.ts @@ -0,0 +1,358 @@ +import * as ts from 'typescript'; +import { TypeScriptProject } from './createTypeScriptProject'; + +export interface ParsedProp { + /** + * If `true`, some signatures do not contain this property. + * e.g: `id` in `{ id: number, value: string } | { value: string }` + */ + onlyUsedInSomeSignatures: boolean; + signatures: { symbol: ts.Symbol; componentType: ts.Type }[]; +} + +export interface ParsedComponent { + name: string; + location: ts.Node; + type: ts.Type; + sourceFile: ts.SourceFile | undefined; + props: Record; +} + +function isTypeJSXElementLike(type: ts.Type, project: TypeScriptProject): boolean { + const symbol = type.symbol ?? type.aliasSymbol; + if (symbol) { + const name = project.checker.getFullyQualifiedName(symbol); + return ( + // Remove once global JSX namespace is no longer used by React + name === 'global.JSX.Element' || + name === 'React.JSX.Element' || + name === 'React.ReactElement' || + name === 'React.ReactNode' + ); + } + + if (type.isUnion()) { + return type.types.every( + // eslint-disable-next-line no-bitwise + (subType) => subType.flags & ts.TypeFlags.Null || isTypeJSXElementLike(subType, project), + ); + } + + return false; +} + +function isStyledFunction(node: ts.VariableDeclaration): boolean { + return ( + !!node.initializer && + ts.isCallExpression(node.initializer) && + ts.isCallExpression(node.initializer.expression) && + ts.isIdentifier(node.initializer.expression.expression) && + node.initializer.expression.expression.escapedText === 'styled' + ); +} + +function getJSXLikeReturnValueFromFunction(type: ts.Type, project: TypeScriptProject) { + return type + .getCallSignatures() + .filter((signature) => isTypeJSXElementLike(signature.getReturnType(), project)); +} + +function parsePropsType({ + name, + type, + shouldInclude = () => true, + location, + sourceFile, +}: { + name: string; + type: ts.Type; + location: ts.Node; + shouldInclude?: (data: { name: string; depth: number }) => boolean; + sourceFile: ts.SourceFile | undefined; +}): ParsedComponent { + const parsedProps: Record = {}; + + type + .getProperties() + .filter((property) => shouldInclude({ name: property.getName(), depth: 1 })) + .forEach((property) => { + parsedProps[property.getName()] = { + signatures: [ + { + symbol: property, + componentType: type, + }, + ], + onlyUsedInSomeSignatures: false, + }; + }); + + return { + name, + location, + type, + sourceFile, + props: parsedProps, + }; +} + +function parseFunctionComponent({ + node, + shouldInclude, + project, +}: { + node: ts.VariableDeclaration | ts.FunctionDeclaration; + shouldInclude?: (data: { name: string; depth: number }) => boolean; + project: TypeScriptProject; +}): ParsedComponent | null { + if (!node.name) { + return null; + } + + const symbol = project.checker.getSymbolAtLocation(node.name); + if (!symbol) { + return null; + } + const componentName = node.name.getText(); + + // Discriminate render functions to components + if (componentName[0].toUpperCase() !== componentName[0]) { + return null; + } + + const signatures = getJSXLikeReturnValueFromFunction( + project.checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration!), + project, + ); + if (signatures.length === 0) { + return null; + } + + const parsedComponents = signatures.map((signature) => + parsePropsType({ + shouldInclude, + name: componentName, + type: project.checker.getTypeOfSymbolAtLocation( + signature.parameters[0], + signature.parameters[0].valueDeclaration!, + ), + location: signature.parameters[0].valueDeclaration!, + sourceFile: node.getSourceFile(), + }), + ); + + const squashedProps: Record = {}; + parsedComponents.forEach((parsedComponent) => { + Object.keys(parsedComponent.props).forEach((propName) => { + if (!squashedProps[propName]) { + squashedProps[propName] = parsedComponent.props[propName]; + } else { + squashedProps[propName].signatures = [ + ...squashedProps[propName].signatures, + ...parsedComponent.props[propName].signatures, + ]; + } + }); + }); + + const squashedParsedComponent: ParsedComponent = { + ...parsedComponents[0], + props: squashedProps, + }; + + Object.keys(squashedParsedComponent.props).forEach((propName) => { + squashedParsedComponent.props[propName].onlyUsedInSomeSignatures = + squashedParsedComponent.props[propName].signatures.length < signatures.length; + }); + + return squashedParsedComponent; +} + +export interface GetPropsFromComponentDeclarationOptions { + project: TypeScriptProject; + node: ts.Node; + /** + * Called before a PropType is added to a component/object + * @returns true to include the prop, false to skip it + */ + shouldInclude?: (data: { name: string; depth: number }) => boolean; + /** + * Control if const declarations should be checked + * @default false + * @example declare const Component: React.JSXElementConstructor; + */ + checkDeclarations?: boolean; +} + +function getPropsFromVariableDeclaration({ + node, + project, + checkDeclarations, + shouldInclude, +}: { node: ts.VariableDeclaration } & Pick< + GetPropsFromComponentDeclarationOptions, + 'project' | 'checkDeclarations' | 'shouldInclude' +>) { + const type = project.checker.getTypeAtLocation(node.name); + if (!node.initializer) { + if ( + checkDeclarations && + type.aliasSymbol && + type.aliasTypeArguments && + project.checker.getFullyQualifiedName(type.aliasSymbol) === 'React.JSXElementConstructor' + ) { + const propsType = type.aliasTypeArguments[0]; + if (propsType === undefined) { + throw new TypeError( + 'Unable to find symbol for `props`. This is a bug in @mui-internal/typescript-to-proptypes.', + ); + } + return parsePropsType({ + name: node.name.getText(), + type: propsType, + location: node.name, + shouldInclude, + sourceFile: node.getSourceFile(), + }); + } + + if (checkDeclarations) { + return parseFunctionComponent({ + node, + shouldInclude, + project, + }); + } + + return null; + } + + if ( + (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer)) && + node.initializer.parameters.length === 1 + ) { + return parseFunctionComponent({ + node, + shouldInclude, + project, + }); + } + // x = React.memo((props:type) { return
}) + // x = React.forwardRef((props:type) { return
}) + if (ts.isCallExpression(node.initializer) && node.initializer.arguments.length > 0) { + const potentialComponent = node.initializer.arguments[0]; + if ( + (ts.isArrowFunction(potentialComponent) || ts.isFunctionExpression(potentialComponent)) && + potentialComponent.parameters.length > 0 && + getJSXLikeReturnValueFromFunction( + project.checker.getTypeAtLocation(potentialComponent), + project, + ).length > 0 + ) { + const propsSymbol = project.checker.getSymbolAtLocation( + potentialComponent.parameters[0].name, + ); + if (propsSymbol) { + return parsePropsType({ + name: node.name.getText(), + type: project.checker.getTypeOfSymbolAtLocation( + propsSymbol, + propsSymbol.valueDeclaration!, + ), + location: propsSymbol.valueDeclaration!, + shouldInclude, + sourceFile: node.getSourceFile(), + }); + } + } + } + + // handle component factories: x = createComponent() + if ( + checkDeclarations && + node.initializer && + !isStyledFunction(node) && + getJSXLikeReturnValueFromFunction(type, project).length > 0 + ) { + return parseFunctionComponent({ + node, + shouldInclude, + project, + }); + } + + return null; +} + +export function getPropsFromComponentNode({ + node, + shouldInclude, + project, + checkDeclarations, +}: GetPropsFromComponentDeclarationOptions): ParsedComponent | null { + let parsedComponent: ParsedComponent | null = null; + // function x(props: type) { return
} + if ( + ts.isFunctionDeclaration(node) && + node.name && + node.parameters.length === 1 && + getJSXLikeReturnValueFromFunction(project.checker.getTypeAtLocation(node.name), project) + .length > 0 + ) { + parsedComponent = parseFunctionComponent({ node, shouldInclude, project }); + } else if (ts.isVariableDeclaration(node)) { + parsedComponent = getPropsFromVariableDeclaration({ + node, + project, + checkDeclarations, + shouldInclude, + }); + } else if (ts.isVariableStatement(node)) { + // const x = ... + ts.forEachChild(node.declarationList, (variableNode) => { + if (parsedComponent != null) { + return; + } + + // x = (props: type) => { return
} + // x = function(props: type) { return
} + // x = function y(props: type) { return
} + // x = react.memo((props:type) { return
}) + if (ts.isVariableDeclaration(variableNode) && variableNode.name) { + parsedComponent = getPropsFromVariableDeclaration({ + node: variableNode, + project, + checkDeclarations, + shouldInclude, + }); + } + + if ( + ts.isClassDeclaration(variableNode) && + variableNode.name && + variableNode.heritageClauses && + variableNode.heritageClauses.length === 1 + ) { + const heritage = variableNode.heritageClauses[0]; + if (heritage.types.length !== 1) { + return; + } + + const arg = heritage.types[0]; + if (!arg.typeArguments) { + return; + } + + parsedComponent = parsePropsType({ + shouldInclude, + name: variableNode.name.getText(), + location: arg.typeArguments[0], + type: project.checker.getTypeAtLocation(arg.typeArguments[0]), + sourceFile: node.getSourceFile(), + }); + } + }); + } + + return parsedComponent; +} diff --git a/packages/docs-utilities/index.js b/packages/docs-utils/src/index.ts similarity index 66% rename from packages/docs-utilities/index.js rename to packages/docs-utils/src/index.ts index e2629893b9242a..f056c1cf5aad07 100644 --- a/packages/docs-utilities/index.js +++ b/packages/docs-utils/src/index.ts @@ -1,34 +1,29 @@ -const { EOL } = require('os'); +import { EOL } from 'os'; -/** - * @param {string} source - */ -function getLineFeed(source) { +export * from './createTypeScriptProject'; +export { type ComponentClassDefinition } from './ComponentClassDefinition'; +export * from './getPropsFromComponentNode'; + +export function getLineFeed(source: string): string { const match = source.match(/\r?\n/); return match === null ? EOL : match[0]; } const fixBabelIssuesRegExp = /(?<=(\/>)|,)(\r?\n){2}/g; -/** - * @param {string} source - */ -function fixBabelGeneratorIssues(source) { + +export function fixBabelGeneratorIssues(source: string): string { return source.replace(fixBabelIssuesRegExp, '\n'); } -/** - * @param {string} source - * @param {string} target - */ -function fixLineEndings(source, target) { +export function fixLineEndings(source: string, target: string): string { return target.replace(/\r?\n/g, getLineFeed(source)); } /** * Converts styled or regular component d.ts file to unstyled d.ts - * @param {string} filename - the file of the styled or regular mui component + * @param filename - the file of the styled or regular mui component */ -function getUnstyledFilename(filename, definitionFile = false) { +export function getUnstyledFilename(filename: string, definitionFile: boolean = false): string { if (filename.indexOf('mui-base') > -1) { return filename; } @@ -58,5 +53,3 @@ function getUnstyledFilename(filename, definitionFile = false) { return definitionFile ? `${unstyledFile}.d.ts` : `${unstyledFile}.js`; } - -export { getLineFeed, fixBabelGeneratorIssues, fixLineEndings, getUnstyledFilename }; diff --git a/packages/docs-utils/tsconfig.build.json b/packages/docs-utils/tsconfig.build.json new file mode 100644 index 00000000000000..8992c3d55a7be0 --- /dev/null +++ b/packages/docs-utils/tsconfig.build.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./build", + "declaration": true, + "noEmit": false, + "composite": true, + "tsBuildInfoFile": "./build/.tsbuildinfo", + "target": "ES2020", + "module": "commonjs", + "types": ["node"] + }, + "exclude": ["./test/*.ts"] +} diff --git a/packages/docs-utils/tsconfig.json b/packages/docs-utils/tsconfig.json new file mode 100644 index 00000000000000..16c32dce4d09be --- /dev/null +++ b/packages/docs-utils/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "noEmit": true, + "moduleResolution": "node", + "types": ["node"], + "strict": true, + "esModuleInterop": true, + "isolatedModules": true + }, + "include": ["./src/**/*.ts"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 50b7cc7884be7c..6ec0447f53a22a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -95,9 +95,9 @@ importers: '@mui-internal/api-docs-builder-core': specifier: workspace:^ version: link:packages/api-docs-builder-core - '@mui-internal/docs-utilities': + '@mui-internal/docs-utils': specifier: workspace:^ - version: link:packages/docs-utilities + version: link:packages/docs-utils '@mui-internal/test-utils': specifier: workspace:^ version: link:packages/test-utils @@ -830,9 +830,9 @@ importers: '@babel/preset-typescript': specifier: ^7.23.3 version: 7.23.3(@babel/core@7.23.9) - '@mui-internal/docs-utilities': + '@mui-internal/docs-utils': specifier: workspace:^ - version: link:../packages/docs-utilities + version: link:../packages/docs-utils '@mui-internal/test-utils': specifier: workspace:^ version: link:../packages/test-utils @@ -914,9 +914,9 @@ importers: '@babel/traverse': specifier: ^7.23.9 version: 7.23.9 - '@mui-internal/docs-utilities': + '@mui-internal/docs-utils': specifier: workspace:^ - version: link:../docs-utilities + version: link:../docs-utils '@mui/markdown': specifier: workspace:^ version: link:../markdown @@ -1025,7 +1025,14 @@ importers: specifier: ^5.3.3 version: 5.3.3 - packages/docs-utilities: {} + packages/docs-utils: + dependencies: + rimraf: + specifier: ^5.0.5 + version: 5.0.5 + typescript: + specifier: ^5.1.6 + version: 5.3.3 packages/eslint-plugin-material-ui: dependencies: @@ -2245,9 +2252,9 @@ importers: '@babel/types': specifier: ^7.23.9 version: 7.23.9 - '@mui-internal/api-docs-builder': + '@mui-internal/docs-utils': specifier: workspace:* - version: link:../api-docs-builder + version: link:../docs-utils doctrine: specifier: ^3.0.0 version: 3.0.0 diff --git a/scripts/generateProptypes.ts b/scripts/generateProptypes.ts index c0409553545ed3..ee997a89b83863 100644 --- a/scripts/generateProptypes.ts +++ b/scripts/generateProptypes.ts @@ -10,7 +10,7 @@ import { fixBabelGeneratorIssues, fixLineEndings, getUnstyledFilename, -} from '@mui-internal/docs-utilities'; +} from '@mui-internal/docs-utils'; import { getPropTypesFromFile, injectPropTypesInFile, diff --git a/tsconfig.json b/tsconfig.json index 532d36d97c5a9d..f9346d8a8e44e9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -51,6 +51,7 @@ "@mui/zero-tag-processor/*": ["./packages/zero-tag-processor/src/*"], "@mui/zero-vite-plugin": ["./packages/zero-vite-plugin/src"], "@mui/zero-vite-plugin/*": ["./packages/zero-vite-plugin/src/*"], + "@mui-internal/docs-utils": ["./packages/docs-utils/src"], "typescript-to-proptypes": ["./packages/typescript-to-proptypes/src"] }, // Otherwise we get react-native typings which conflict with dom.lib. diff --git a/webpackBaseConfig.js b/webpackBaseConfig.js index 4feb6aa97b14e2..a1aebe9d413871 100644 --- a/webpackBaseConfig.js +++ b/webpackBaseConfig.js @@ -25,6 +25,7 @@ module.exports = { '@mui/material-nextjs': path.resolve(__dirname, './packages/mui-material-nextjs/src'), '@mui/joy': path.resolve(__dirname, './packages/mui-joy/src'), '@mui/zero-runtime': path.resolve(__dirname, './packages/zero-runtime/src'), + '@mui-internal/docs-utils': path.resolve(__dirname, './packages/docs-utils/src'), 'typescript-to-proptypes': path.resolve(__dirname, './packages/typescript-to-proptypes/src'), docs: path.resolve(__dirname, './docs'), }, From f9dffaa39d8a9a1a3be66e09a848106bc4d4335e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Mon, 29 Jan 2024 13:03:43 +0100 Subject: [PATCH 2/6] Publish @mui-internal/typescript-to-proptypes to npm --- .codesandbox/ci.json | 6 +- docs/package.json | 2 +- docs/scripts/formattedTSDemos.js | 5 +- package.json | 2 +- packages/typescript-to-proptypes/CHANGELOG.md | 176 +---------------- .../typescript-to-proptypes/CHANGELOG.old.md | 179 ++++++++++++++++++ packages/typescript-to-proptypes/README.md | 12 +- packages/typescript-to-proptypes/package.json | 36 ++-- .../src/getPropTypesFromFile.ts | 4 +- .../tsconfig.build.json | 15 ++ .../typescript-to-proptypes/tsconfig.json | 14 +- pnpm-lock.yaml | 14 +- scripts/generateProptypes.ts | 2 +- tsconfig.json | 2 +- webpackBaseConfig.js | 5 +- 15 files changed, 260 insertions(+), 214 deletions(-) create mode 100644 packages/typescript-to-proptypes/CHANGELOG.old.md create mode 100644 packages/typescript-to-proptypes/tsconfig.build.json diff --git a/.codesandbox/ci.json b/.codesandbox/ci.json index 04e30677f9fb1c..c086cfc1cc843a 100644 --- a/.codesandbox/ci.json +++ b/.codesandbox/ci.json @@ -19,7 +19,8 @@ "packages/mui-system", "packages/mui-types", "packages/mui-utils", - "packages/docs-utils" + "packages/docs-utils", + "packages/typescript-to-proptypes" ], "publishDirectory": { "@mui/base": "packages/mui-base/build", @@ -38,7 +39,8 @@ "@mui/system": "packages/mui-system/build", "@mui/types": "packages/mui-types/build", "@mui/utils": "packages/mui-utils/build", - "@mui-internal/docs-utils": "packages/docs-utils" + "@mui-internal/docs-utils": "packages/docs-utils", + "@mui-internal/typescript-to-proptypes": "packages/typescript-to-proptypes" }, "sandboxes": [ "material-ui-issue-latest-s2dsx", diff --git a/docs/package.json b/docs/package.json index 445bb4edaea388..52445aab867592 100644 --- a/docs/package.json +++ b/docs/package.json @@ -119,6 +119,7 @@ "@babel/preset-typescript": "^7.23.3", "@mui-internal/docs-utils": "workspace:^", "@mui-internal/test-utils": "workspace:^", + "@mui-internal/typescript-to-proptypes": "workspace:^", "@types/autosuggest-highlight": "^3.2.3", "@types/chai": "^4.3.11", "@types/css-mediaquery": "^0.1.4", @@ -139,7 +140,6 @@ "playwright": "^1.41.1", "prettier": "^2.8.8", "tailwindcss": "^3.4.1", - "typescript-to-proptypes": "workspace:^", "yargs": "^17.7.2" } } diff --git a/docs/scripts/formattedTSDemos.js b/docs/scripts/formattedTSDemos.js index ebc2f5a1b9dc06..818bd67e6c4159 100644 --- a/docs/scripts/formattedTSDemos.js +++ b/docs/scripts/formattedTSDemos.js @@ -15,7 +15,10 @@ const path = require('path'); const fse = require('fs-extra'); const babel = require('@babel/core'); const prettier = require('prettier'); -const { getPropTypesFromFile, injectPropTypesInFile } = require('typescript-to-proptypes'); +const { + getPropTypesFromFile, + injectPropTypesInFile, +} = require('@mui-internal/typescript-to-proptypes'); const { createTypeScriptProjectBuilder, } = require('@mui-internal/api-docs-builder/utils/createTypeScriptProject'); diff --git a/package.json b/package.json index 529b97e2f2be42..86277485ebb7ac 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "@mui-internal/api-docs-builder-core": "workspace:^", "@mui-internal/docs-utils": "workspace:^", "@mui-internal/test-utils": "workspace:^", + "@mui-internal/typescript-to-proptypes": "workspace:^", "@mui/joy": "workspace:*", "@mui/material": "workspace:^", "@mui/utils": "workspace:^", @@ -180,7 +181,6 @@ "tsx": "^4.7.0", "tsup": "^8.0.1", "typescript": "^5.3.3", - "typescript-to-proptypes": "workspace:^", "webpack": "^5.90.0", "webpack-bundle-analyzer": "^4.10.1", "webpack-cli": "^5.1.4", diff --git a/packages/typescript-to-proptypes/CHANGELOG.md b/packages/typescript-to-proptypes/CHANGELOG.md index 05bcc91e529f42..9a611104556b62 100644 --- a/packages/typescript-to-proptypes/CHANGELOG.md +++ b/packages/typescript-to-proptypes/CHANGELOG.md @@ -1,176 +1,10 @@ # Changelog -All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +This file documents changes in the `@mui-internal/typescript-to-proptypes` package. +For changes before the package was forked, while it was and published as `typescript-to-proptypes`, see [CHANGELOG.old.md](./CHANGELOG.old.md). -## [2.0.1](https://github.com/merceyz/typescript-to-proptypes/compare/v2.0.0...v2.0.1) (2020-06-02) +Unfortunately changes done between forking the `typescript-to-proptypes` and publishing `@mui-internal/typescript-to-proptypes` are not documented. -### Bug Fixes +## 1.0.0 -- Use symbol type when there's no baseconstraint ([#23](https://github.com/merceyz/typescript-to-proptypes/issues/23)) ([0b170af](https://github.com/merceyz/typescript-to-proptypes/commit/0b170afb02a2edd1ea0b80406f1a86375c3a13f3)) - -## [2.0.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.5.0...v2.0.0) (2020-05-31) - -### ⚠ BREAKING CHANGES - -- Support for Node versions less than 10.3.0 has been dropped - -### Features - -- consider squashed call signatures of function components ([#20](https://github.com/merceyz/typescript-to-proptypes/issues/20)) ([514d8ed](https://github.com/merceyz/typescript-to-proptypes/commit/514d8ed55375406a70640d64c4a166aa52e24ae2)) - -### Bug Fixes - -- allow non-string literals ([#21](https://github.com/merceyz/typescript-to-proptypes/issues/21)) ([546e7ad](https://github.com/merceyz/typescript-to-proptypes/commit/546e7addc86198e641d3bfd3dd08ecb55c970600)) - -### Build System - -- drop support for node versions less than 10.3.0 ([2fbca64](https://github.com/merceyz/typescript-to-proptypes/commit/2fbca64e0964509e1a74d29f564be41a78e9fa29)) - -## [1.5.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.4.2...v1.5.0) (2020-04-06) - -### Features - -- **injector:** add reconcilePropTypes ([#10](https://github.com/merceyz/typescript-to-proptypes/issues/10)) ([7b0bff9](https://github.com/merceyz/typescript-to-proptypes/commit/7b0bff9666d1beb1bde445e92fbb702cf1fb3d89)) -- add `filenames` to component and proptype nodes ([#9](https://github.com/merceyz/typescript-to-proptypes/issues/9)) ([ce9a700](https://github.com/merceyz/typescript-to-proptypes/commit/ce9a7002c7fda27965b50e0b1af3ecef540a90e5)) -- **injector:** add `component` to `shouldInclude` ([#8](https://github.com/merceyz/typescript-to-proptypes/issues/8)) ([18a7fce](https://github.com/merceyz/typescript-to-proptypes/commit/18a7fcee1b3f7d64541fb0f9bd1de72e0ea0db5b)) -- **injector:** allow providing babel options ([2ab6f43](https://github.com/merceyz/typescript-to-proptypes/commit/2ab6f43ef4b785d20dd6f951b2f4b928a5521b53)) - -### Bug Fixes - -- check nodeType for dom elements ([#13](https://github.com/merceyz/typescript-to-proptypes/issues/13)) ([fd028e6](https://github.com/merceyz/typescript-to-proptypes/commit/fd028e639bb28383d6e4f925368b6e2afacdbf23)) -- replace existing propTypes when removeExistingPropTypes ([#15](https://github.com/merceyz/typescript-to-proptypes/issues/15)) ([3166104](https://github.com/merceyz/typescript-to-proptypes/commit/3166104889d4f58fc22f85800664d2bb1fce6aff)) -- **injector:** always call injectPropTypes to allow shouldInclude to run ([277258d](https://github.com/merceyz/typescript-to-proptypes/commit/277258ddc73c3da816aba6fccb739c69dfe8e83a)) -- handle all props getting ignored by shouldInclude ([b69112e](https://github.com/merceyz/typescript-to-proptypes/commit/b69112e1011f089b6d5cb60f88ce75b6394252be)) -- **parser:** export ParserOptions ([3a5d55e](https://github.com/merceyz/typescript-to-proptypes/commit/3a5d55e68a723208a4b76e79d4bafe92ddf4f85a)) - -## [1.4.2](https://github.com/merceyz/typescript-to-proptypes/compare/v1.4.1...v1.4.2) (2020-03-27) - -### Bug Fixes - -- build had a broken output ([97b0326](https://github.com/merceyz/typescript-to-proptypes/commit/97b0326c8b3b811fd5167cefa95a5dc1aa22a212)) - -## [1.4.1](https://github.com/merceyz/typescript-to-proptypes/compare/v1.4.0...v1.4.1) (2020-03-27) - -### Bug Fixes - -- include string literal object keys as used ([#5](https://github.com/merceyz/typescript-to-proptypes/issues/5)) ([3fd7b70](https://github.com/merceyz/typescript-to-proptypes/commit/3fd7b703d30e650e6692f87d3929d4ae67314cb6)) -- unknown can be optional ([#7](https://github.com/merceyz/typescript-to-proptypes/issues/7)) ([c5e8ca3](https://github.com/merceyz/typescript-to-proptypes/commit/c5e8ca31e2cae20216b1f7e45c9f3ef5198b2f93)) - -## [1.4.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.3.0...v1.4.0) (2019-11-16) - -### Bug Fixes - -- **parser:** handle prop of type ReactElement ([adfcca4](https://github.com/merceyz/typescript-to-proptypes/commit/adfcca4)) - -### Features - -- **parser:** support forwardRef ([3f5c0c9](https://github.com/merceyz/typescript-to-proptypes/commit/3f5c0c9)), closes [#2](https://github.com/merceyz/typescript-to-proptypes/issues/2) - -## [1.3.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.5...v1.3.0) (2019-09-03) - -### Features - -- **generator:** add comment to proptype blocks ([2c5627e](https://github.com/merceyz/typescript-to-proptypes/commit/2c5627e)) - -### [1.2.5](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.4...v1.2.5) (2019-09-03) - -### Bug Fixes - -- **parser:** use doctrine to unwrap comments ([53a9d43](https://github.com/merceyz/typescript-to-proptypes/commit/53a9d43)) - -### Tests - -- add missing test config ([d00c7f2](https://github.com/merceyz/typescript-to-proptypes/commit/d00c7f2)) - -## [1.2.4](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.3...v1.2.4) (2019-08-16) - -### Bug Fixes - -- **injector:** use require.resolve ([b9d04ea](https://github.com/merceyz/typescript-to-proptypes/commit/b9d04ea)) - -## [1.2.3](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.2...v1.2.3) (2019-07-24) - -### Bug Fixes - -- **parser:** handle return type of JSX.Element | null ([cbe5564](https://github.com/merceyz/typescript-to-proptypes/commit/cbe5564)) - -## [1.2.2](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.1...v1.2.2) (2019-07-23) - -### Bug Fixes - -- **parser:** remove leftover asterisk ([2e720df](https://github.com/merceyz/typescript-to-proptypes/commit/2e720df)) - -## [1.2.1](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.0...v1.2.1) (2019-07-23) - -### Bug Fixes - -- **parser:** handle single line comments ([0025d53](https://github.com/merceyz/typescript-to-proptypes/commit/0025d53)) - -## [1.2.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.1.0...v1.2.0) (2019-07-23) - -### Bug Fixes - -- **generator:** multiline comments ([d576597](https://github.com/merceyz/typescript-to-proptypes/commit/d576597)) -- **generator:** sort interface correctly ([f88c5fb](https://github.com/merceyz/typescript-to-proptypes/commit/f88c5fb)) -- **generator:** wrap prop name in quotes ([709a819](https://github.com/merceyz/typescript-to-proptypes/commit/709a819)) -- **parser:** don't modify comments ([95cd63e](https://github.com/merceyz/typescript-to-proptypes/commit/95cd63e)) -- **parser:** fallback to object if element is undefined ([eadaf3f](https://github.com/merceyz/typescript-to-proptypes/commit/eadaf3f)) -- **parser:** handle comments with just tags ([d0b0a82](https://github.com/merceyz/typescript-to-proptypes/commit/d0b0a82)) -- **parser:** handle comments with tags ([ad4dddd](https://github.com/merceyz/typescript-to-proptypes/commit/ad4dddd)) -- **parser:** handle optional any ([30f56ec](https://github.com/merceyz/typescript-to-proptypes/commit/30f56ec)) -- **parser:** handle optional React.ElementType ([c7a87fd](https://github.com/merceyz/typescript-to-proptypes/commit/c7a87fd)) -- **parser:** treat ComponentType as elementType ([53f1e21](https://github.com/merceyz/typescript-to-proptypes/commit/53f1e21)) -- export typescript as ts ([ba90e22](https://github.com/merceyz/typescript-to-proptypes/commit/ba90e22)) - -### Features - -- **generator:** support instanceOf ([6bd563a](https://github.com/merceyz/typescript-to-proptypes/commit/6bd563a)) -- **injector:** control included props ([4f8eaa1](https://github.com/merceyz/typescript-to-proptypes/commit/4f8eaa1)) -- **injector:** remove existing proptypes ([d2a978c](https://github.com/merceyz/typescript-to-proptypes/commit/d2a978c)) -- **parser:** check const declarations of React.ComponentType ([cbd2eb6](https://github.com/merceyz/typescript-to-proptypes/commit/cbd2eb6)) -- **parser:** handle React.Component and Element instanceOf ([570d73b](https://github.com/merceyz/typescript-to-proptypes/commit/570d73b)) -- **parser:** support elementType ([448d5a6](https://github.com/merceyz/typescript-to-proptypes/commit/448d5a6)) - -## [1.1.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.0.4...v1.1.0) (2019-07-15) - -### Bug Fixes - -- **generator:** don't pass shouldInclude on interfaceNode ([1302502](https://github.com/merceyz/typescript-to-proptypes/commit/1302502)) - -### Features - -- **parser:** circular references ([7de51cc](https://github.com/merceyz/typescript-to-proptypes/commit/7de51cc)) -- **parser:** control included proptypes ([2952e78](https://github.com/merceyz/typescript-to-proptypes/commit/2952e78)) -- **parser:** objects / shapes ([81f1a82](https://github.com/merceyz/typescript-to-proptypes/commit/81f1a82)) - -## [1.0.4](https://github.com/merceyz/typescript-to-proptypes/compare/v1.0.3...v1.0.4) (2019-07-10) - -### Bug Fixes - -- **generator:** omit null if proptype is optional ([21351a4](https://github.com/merceyz/typescript-to-proptypes/commit/21351a4)) -- **parser:** reactnode should make proptype optional ([c84b611](https://github.com/merceyz/typescript-to-proptypes/commit/c84b611)) - -## [1.0.3](https://github.com/merceyz/typescript-to-proptypes/compare/v1.0.2...v1.0.3) (2019-07-10) - -### Bug Fixes - -- export types ([7583291](https://github.com/merceyz/typescript-to-proptypes/commit/7583291)) - -## [1.0.2](https://github.com/merceyz/typescript-to-proptypes/compare/v1.0.1...v1.0.2) (2019-07-09) - -### Bug Fixes - -- **injector:** don't visit FunctionDeclarations more than once ([236276b](https://github.com/merceyz/typescript-to-proptypes/commit/236276b)) - -## [1.0.1](https://github.com/merceyz/typescript-to-proptypes/compare/v1.0.0...v1.0.1) (2019-07-09) - -### Bug Fixes - -- **injector:** don't import prop-types if it's already imported ([9d4dfd1](https://github.com/merceyz/typescript-to-proptypes/commit/9d4dfd1)) -- **injector:** insert import after the first one ([6cb31a0](https://github.com/merceyz/typescript-to-proptypes/commit/6cb31a0)) - -## 1.0.0 (2019-07-08) - -### Build System - -- disable incremental ([37b0277](https://github.com/merceyz/typescript-to-proptypes/commit/37b0277)) +Initial release as a `@mui-internal/typescript-to-proptypes` package. diff --git a/packages/typescript-to-proptypes/CHANGELOG.old.md b/packages/typescript-to-proptypes/CHANGELOG.old.md new file mode 100644 index 00000000000000..38d10c92ae4789 --- /dev/null +++ b/packages/typescript-to-proptypes/CHANGELOG.old.md @@ -0,0 +1,179 @@ +# Changelog + +This file documents changes in the @merceyz's `typescript-to-proptypes` package. +For changes after the package was forked and published as `@mui-internal/typescript-to-proptypes`, see [CHANGELOG.md](./CHANGELOG.md). + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## [2.0.1](https://github.com/merceyz/typescript-to-proptypes/compare/v2.0.0...v2.0.1) (2020-06-02) + +### Bug Fixes + +- Use symbol type when there's no baseconstraint ([#23](https://github.com/merceyz/typescript-to-proptypes/issues/23)) ([0b170af](https://github.com/merceyz/typescript-to-proptypes/commit/0b170afb02a2edd1ea0b80406f1a86375c3a13f3)) + +## [2.0.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.5.0...v2.0.0) (2020-05-31) + +### ⚠ BREAKING CHANGES + +- Support for Node versions less than 10.3.0 has been dropped + +### Features + +- consider squashed call signatures of function components ([#20](https://github.com/merceyz/typescript-to-proptypes/issues/20)) ([514d8ed](https://github.com/merceyz/typescript-to-proptypes/commit/514d8ed55375406a70640d64c4a166aa52e24ae2)) + +### Bug Fixes + +- allow non-string literals ([#21](https://github.com/merceyz/typescript-to-proptypes/issues/21)) ([546e7ad](https://github.com/merceyz/typescript-to-proptypes/commit/546e7addc86198e641d3bfd3dd08ecb55c970600)) + +### Build System + +- drop support for node versions less than 10.3.0 ([2fbca64](https://github.com/merceyz/typescript-to-proptypes/commit/2fbca64e0964509e1a74d29f564be41a78e9fa29)) + +## [1.5.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.4.2...v1.5.0) (2020-04-06) + +### Features + +- **injector:** add reconcilePropTypes ([#10](https://github.com/merceyz/typescript-to-proptypes/issues/10)) ([7b0bff9](https://github.com/merceyz/typescript-to-proptypes/commit/7b0bff9666d1beb1bde445e92fbb702cf1fb3d89)) +- add `filenames` to component and proptype nodes ([#9](https://github.com/merceyz/typescript-to-proptypes/issues/9)) ([ce9a700](https://github.com/merceyz/typescript-to-proptypes/commit/ce9a7002c7fda27965b50e0b1af3ecef540a90e5)) +- **injector:** add `component` to `shouldInclude` ([#8](https://github.com/merceyz/typescript-to-proptypes/issues/8)) ([18a7fce](https://github.com/merceyz/typescript-to-proptypes/commit/18a7fcee1b3f7d64541fb0f9bd1de72e0ea0db5b)) +- **injector:** allow providing babel options ([2ab6f43](https://github.com/merceyz/typescript-to-proptypes/commit/2ab6f43ef4b785d20dd6f951b2f4b928a5521b53)) + +### Bug Fixes + +- check nodeType for dom elements ([#13](https://github.com/merceyz/typescript-to-proptypes/issues/13)) ([fd028e6](https://github.com/merceyz/typescript-to-proptypes/commit/fd028e639bb28383d6e4f925368b6e2afacdbf23)) +- replace existing propTypes when removeExistingPropTypes ([#15](https://github.com/merceyz/typescript-to-proptypes/issues/15)) ([3166104](https://github.com/merceyz/typescript-to-proptypes/commit/3166104889d4f58fc22f85800664d2bb1fce6aff)) +- **injector:** always call injectPropTypes to allow shouldInclude to run ([277258d](https://github.com/merceyz/typescript-to-proptypes/commit/277258ddc73c3da816aba6fccb739c69dfe8e83a)) +- handle all props getting ignored by shouldInclude ([b69112e](https://github.com/merceyz/typescript-to-proptypes/commit/b69112e1011f089b6d5cb60f88ce75b6394252be)) +- **parser:** export ParserOptions ([3a5d55e](https://github.com/merceyz/typescript-to-proptypes/commit/3a5d55e68a723208a4b76e79d4bafe92ddf4f85a)) + +## [1.4.2](https://github.com/merceyz/typescript-to-proptypes/compare/v1.4.1...v1.4.2) (2020-03-27) + +### Bug Fixes + +- build had a broken output ([97b0326](https://github.com/merceyz/typescript-to-proptypes/commit/97b0326c8b3b811fd5167cefa95a5dc1aa22a212)) + +## [1.4.1](https://github.com/merceyz/typescript-to-proptypes/compare/v1.4.0...v1.4.1) (2020-03-27) + +### Bug Fixes + +- include string literal object keys as used ([#5](https://github.com/merceyz/typescript-to-proptypes/issues/5)) ([3fd7b70](https://github.com/merceyz/typescript-to-proptypes/commit/3fd7b703d30e650e6692f87d3929d4ae67314cb6)) +- unknown can be optional ([#7](https://github.com/merceyz/typescript-to-proptypes/issues/7)) ([c5e8ca3](https://github.com/merceyz/typescript-to-proptypes/commit/c5e8ca31e2cae20216b1f7e45c9f3ef5198b2f93)) + +## [1.4.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.3.0...v1.4.0) (2019-11-16) + +### Bug Fixes + +- **parser:** handle prop of type ReactElement ([adfcca4](https://github.com/merceyz/typescript-to-proptypes/commit/adfcca4)) + +### Features + +- **parser:** support forwardRef ([3f5c0c9](https://github.com/merceyz/typescript-to-proptypes/commit/3f5c0c9)), closes [#2](https://github.com/merceyz/typescript-to-proptypes/issues/2) + +## [1.3.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.5...v1.3.0) (2019-09-03) + +### Features + +- **generator:** add comment to proptype blocks ([2c5627e](https://github.com/merceyz/typescript-to-proptypes/commit/2c5627e)) + +### [1.2.5](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.4...v1.2.5) (2019-09-03) + +### Bug Fixes + +- **parser:** use doctrine to unwrap comments ([53a9d43](https://github.com/merceyz/typescript-to-proptypes/commit/53a9d43)) + +### Tests + +- add missing test config ([d00c7f2](https://github.com/merceyz/typescript-to-proptypes/commit/d00c7f2)) + +## [1.2.4](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.3...v1.2.4) (2019-08-16) + +### Bug Fixes + +- **injector:** use require.resolve ([b9d04ea](https://github.com/merceyz/typescript-to-proptypes/commit/b9d04ea)) + +## [1.2.3](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.2...v1.2.3) (2019-07-24) + +### Bug Fixes + +- **parser:** handle return type of JSX.Element | null ([cbe5564](https://github.com/merceyz/typescript-to-proptypes/commit/cbe5564)) + +## [1.2.2](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.1...v1.2.2) (2019-07-23) + +### Bug Fixes + +- **parser:** remove leftover asterisk ([2e720df](https://github.com/merceyz/typescript-to-proptypes/commit/2e720df)) + +## [1.2.1](https://github.com/merceyz/typescript-to-proptypes/compare/v1.2.0...v1.2.1) (2019-07-23) + +### Bug Fixes + +- **parser:** handle single line comments ([0025d53](https://github.com/merceyz/typescript-to-proptypes/commit/0025d53)) + +## [1.2.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.1.0...v1.2.0) (2019-07-23) + +### Bug Fixes + +- **generator:** multiline comments ([d576597](https://github.com/merceyz/typescript-to-proptypes/commit/d576597)) +- **generator:** sort interface correctly ([f88c5fb](https://github.com/merceyz/typescript-to-proptypes/commit/f88c5fb)) +- **generator:** wrap prop name in quotes ([709a819](https://github.com/merceyz/typescript-to-proptypes/commit/709a819)) +- **parser:** don't modify comments ([95cd63e](https://github.com/merceyz/typescript-to-proptypes/commit/95cd63e)) +- **parser:** fallback to object if element is undefined ([eadaf3f](https://github.com/merceyz/typescript-to-proptypes/commit/eadaf3f)) +- **parser:** handle comments with just tags ([d0b0a82](https://github.com/merceyz/typescript-to-proptypes/commit/d0b0a82)) +- **parser:** handle comments with tags ([ad4dddd](https://github.com/merceyz/typescript-to-proptypes/commit/ad4dddd)) +- **parser:** handle optional any ([30f56ec](https://github.com/merceyz/typescript-to-proptypes/commit/30f56ec)) +- **parser:** handle optional React.ElementType ([c7a87fd](https://github.com/merceyz/typescript-to-proptypes/commit/c7a87fd)) +- **parser:** treat ComponentType as elementType ([53f1e21](https://github.com/merceyz/typescript-to-proptypes/commit/53f1e21)) +- export typescript as ts ([ba90e22](https://github.com/merceyz/typescript-to-proptypes/commit/ba90e22)) + +### Features + +- **generator:** support instanceOf ([6bd563a](https://github.com/merceyz/typescript-to-proptypes/commit/6bd563a)) +- **injector:** control included props ([4f8eaa1](https://github.com/merceyz/typescript-to-proptypes/commit/4f8eaa1)) +- **injector:** remove existing proptypes ([d2a978c](https://github.com/merceyz/typescript-to-proptypes/commit/d2a978c)) +- **parser:** check const declarations of React.ComponentType ([cbd2eb6](https://github.com/merceyz/typescript-to-proptypes/commit/cbd2eb6)) +- **parser:** handle React.Component and Element instanceOf ([570d73b](https://github.com/merceyz/typescript-to-proptypes/commit/570d73b)) +- **parser:** support elementType ([448d5a6](https://github.com/merceyz/typescript-to-proptypes/commit/448d5a6)) + +## [1.1.0](https://github.com/merceyz/typescript-to-proptypes/compare/v1.0.4...v1.1.0) (2019-07-15) + +### Bug Fixes + +- **generator:** don't pass shouldInclude on interfaceNode ([1302502](https://github.com/merceyz/typescript-to-proptypes/commit/1302502)) + +### Features + +- **parser:** circular references ([7de51cc](https://github.com/merceyz/typescript-to-proptypes/commit/7de51cc)) +- **parser:** control included proptypes ([2952e78](https://github.com/merceyz/typescript-to-proptypes/commit/2952e78)) +- **parser:** objects / shapes ([81f1a82](https://github.com/merceyz/typescript-to-proptypes/commit/81f1a82)) + +## [1.0.4](https://github.com/merceyz/typescript-to-proptypes/compare/v1.0.3...v1.0.4) (2019-07-10) + +### Bug Fixes + +- **generator:** omit null if proptype is optional ([21351a4](https://github.com/merceyz/typescript-to-proptypes/commit/21351a4)) +- **parser:** reactnode should make proptype optional ([c84b611](https://github.com/merceyz/typescript-to-proptypes/commit/c84b611)) + +## [1.0.3](https://github.com/merceyz/typescript-to-proptypes/compare/v1.0.2...v1.0.3) (2019-07-10) + +### Bug Fixes + +- export types ([7583291](https://github.com/merceyz/typescript-to-proptypes/commit/7583291)) + +## [1.0.2](https://github.com/merceyz/typescript-to-proptypes/compare/v1.0.1...v1.0.2) (2019-07-09) + +### Bug Fixes + +- **injector:** don't visit FunctionDeclarations more than once ([236276b](https://github.com/merceyz/typescript-to-proptypes/commit/236276b)) + +## [1.0.1](https://github.com/merceyz/typescript-to-proptypes/compare/v1.0.0...v1.0.1) (2019-07-09) + +### Bug Fixes + +- **injector:** don't import prop-types if it's already imported ([9d4dfd1](https://github.com/merceyz/typescript-to-proptypes/commit/9d4dfd1)) +- **injector:** insert import after the first one ([6cb31a0](https://github.com/merceyz/typescript-to-proptypes/commit/6cb31a0)) + +## 1.0.0 (2019-07-08) + +### Build System + +- disable incremental ([37b0277](https://github.com/merceyz/typescript-to-proptypes/commit/37b0277)) diff --git a/packages/typescript-to-proptypes/README.md b/packages/typescript-to-proptypes/README.md index 9e00c1692dadd0..4521bd893bca63 100644 --- a/packages/typescript-to-proptypes/README.md +++ b/packages/typescript-to-proptypes/README.md @@ -1,6 +1,9 @@ -# typescript-to-proptypes +# @mui-internal/typescript-to-proptypes -An API for converting [TypeScript](https://www.npmjs.com/package/typescript) definitions to [PropTypes](https://www.npmjs.com/package/prop-types) using the TypeScript Compiler API +An API for converting [TypeScript](https://www.npmjs.com/package/typescript) definitions to [PropTypes](https://www.npmjs.com/package/prop-types) using the TypeScript Compiler API. + +This package has been adapted for MUI needs. +It is not meant for general use. ## Support @@ -15,3 +18,8 @@ An API for converting [TypeScript](https://www.npmjs.com/package/typescript) def ## License This project is licensed under the terms of the [MIT license](/LICENSE). + +## Release + +1. Build the project: `pnpm build` +2. Publish the build artifacts to npm: `pnpm release:publish` diff --git a/packages/typescript-to-proptypes/package.json b/packages/typescript-to-proptypes/package.json index 6146ecaeedb2e1..1dd15c859acf5b 100644 --- a/packages/typescript-to-proptypes/package.json +++ b/packages/typescript-to-proptypes/package.json @@ -1,32 +1,34 @@ { - "name": "typescript-to-proptypes", - "version": "5.0.0", - "private": true, - "description": "Generate proptypes from TypeScript declarations", + "name": "@mui-internal/typescript-to-proptypes", + "version": "1.0.0", + "author": "MUI Team", + "description": "Generate proptypes from TypeScript declarations. This is a fork of the typescript-to-proptypes package adapted for MUI needs. This is an internal package not meant for general use.", + "main": "build/index.js", + "exports": { + ".": "./build/index.js" + }, + "types": "./build/index.d.ts", "repository": { "type": "git", "url": "https://github.com/mui/material-ui.git", "directory": "packages/typescript-to-proptypes" }, - "main": "src/index.ts", - "author": "merceyz ", "license": "MIT", - "keywords": [ - "proptypes", - "typescript", - "react" - ], "scripts": { + "prepublish": "rimraf ./build", + "build": "tsc -b tsconfig.build.json", + "release:publish": "pnpm publish --tag latest", + "release:publish:dry-run": "pnpm publish --tag latest --registry=\"http://localhost:4873/\"", "test": "cd ../../ && cross-env NODE_ENV=test mocha --config packages/typescript-to-proptypes/.mocharc.js 'packages/typescript-to-proptypes/**/*.test.ts'", - "typescript": "tsc -p tsconfig.json" + "typescript": "tsc -b tsconfig.json" }, "dependencies": { - "@babel/core": "^7.23.9", + "@babel/core": "^7.23.7", "@babel/plugin-syntax-class-properties": "^7.12.13", "@babel/plugin-syntax-jsx": "^7.23.3", "@babel/plugin-syntax-typescript": "^7.23.3", - "@babel/types": "^7.23.9", - "@mui-internal/api-docs-builder": "workspace:*", + "@babel/types": "^7.23.6", + "@mui-internal/docs-utils": "workspace:*", "doctrine": "^3.0.0", "lodash": "^4.17.21", "typescript": "^5.3.3", @@ -38,10 +40,10 @@ "@types/chai": "^4.3.11", "@types/doctrine": "^0.0.9", "@types/lodash": "^4.14.202", - "@types/node": "^18.19.10", + "@types/node": "^18.19.8", "@types/prettier": "^2.7.3", "@types/react": "^18.2.48", - "@types/uuid": "^9.0.8", + "@types/uuid": "^9.0.7", "chai": "^4.4.1", "fast-glob": "^3.3.2", "prettier": "^2.8.8", diff --git a/packages/typescript-to-proptypes/src/getPropTypesFromFile.ts b/packages/typescript-to-proptypes/src/getPropTypesFromFile.ts index 04214f5ca1290b..faecb397b603a4 100644 --- a/packages/typescript-to-proptypes/src/getPropTypesFromFile.ts +++ b/packages/typescript-to-proptypes/src/getPropTypesFromFile.ts @@ -3,8 +3,8 @@ import * as doctrine from 'doctrine'; import { GetPropsFromComponentDeclarationOptions, getPropsFromComponentNode, -} from '@mui-internal/api-docs-builder/utils/getPropsFromComponentNode'; -import { TypeScriptProject } from '@mui-internal/api-docs-builder/utils/createTypeScriptProject'; + TypeScriptProject, +} from '@mui-internal/docs-utils'; import { createUnionType, createUndefinedType, diff --git a/packages/typescript-to-proptypes/tsconfig.build.json b/packages/typescript-to-proptypes/tsconfig.build.json new file mode 100644 index 00000000000000..8992c3d55a7be0 --- /dev/null +++ b/packages/typescript-to-proptypes/tsconfig.build.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./build", + "declaration": true, + "noEmit": false, + "composite": true, + "tsBuildInfoFile": "./build/.tsbuildinfo", + "target": "ES2020", + "module": "commonjs", + "types": ["node"] + }, + "exclude": ["./test/*.ts"] +} diff --git a/packages/typescript-to-proptypes/tsconfig.json b/packages/typescript-to-proptypes/tsconfig.json index 9a70107eff7e6c..9939012a1f603f 100644 --- a/packages/typescript-to-proptypes/tsconfig.json +++ b/packages/typescript-to-proptypes/tsconfig.json @@ -1,12 +1,12 @@ { "compilerOptions": { - "module": "commonjs", - "esModuleInterop": true, - "lib": ["ES2018"], - "strict": true, + "noEmit": true, "moduleResolution": "node", - "types": ["node"], - "noEmit": true + "types": ["node", "mocha"], + "strict": true, + "esModuleInterop": true, + "isolatedModules": true }, - "include": ["src"] + "include": ["./src/*.ts", "./test/*.ts"], + "references": [{ "path": "../docs-utils/tsconfig.build.json" }] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6ec0447f53a22a..7379218aebf565 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -101,6 +101,9 @@ importers: '@mui-internal/test-utils': specifier: workspace:^ version: link:packages/test-utils + '@mui-internal/typescript-to-proptypes': + specifier: workspace:^ + version: link:packages/typescript-to-proptypes '@mui/joy': specifier: workspace:* version: link:packages/mui-joy/build @@ -329,9 +332,6 @@ importers: typescript: specifier: ^5.3.3 version: 5.3.3 - typescript-to-proptypes: - specifier: workspace:^ - version: link:packages/typescript-to-proptypes webpack: specifier: ^5.90.0 version: 5.90.0(esbuild@0.19.11)(webpack-cli@5.1.4) @@ -836,6 +836,9 @@ importers: '@mui-internal/test-utils': specifier: workspace:^ version: link:../packages/test-utils + '@mui-internal/typescript-to-proptypes': + specifier: workspace:^ + version: link:../packages/typescript-to-proptypes '@types/autosuggest-highlight': specifier: ^3.2.3 version: 3.2.3 @@ -896,9 +899,6 @@ importers: tailwindcss: specifier: ^3.4.1 version: 3.4.1 - typescript-to-proptypes: - specifier: workspace:^ - version: link:../packages/typescript-to-proptypes yargs: specifier: ^17.7.2 version: 17.7.2 @@ -2293,7 +2293,7 @@ importers: specifier: ^18.2.48 version: 18.2.48 '@types/uuid': - specifier: ^9.0.8 + specifier: ^9.0.7 version: 9.0.8 chai: specifier: ^4.4.1 diff --git a/scripts/generateProptypes.ts b/scripts/generateProptypes.ts index ee997a89b83863..aa9d7d63766a14 100644 --- a/scripts/generateProptypes.ts +++ b/scripts/generateProptypes.ts @@ -15,7 +15,7 @@ import { getPropTypesFromFile, injectPropTypesInFile, InjectPropTypesInFileOptions, -} from 'typescript-to-proptypes'; +} from '@mui-internal/typescript-to-proptypes'; import { createTypeScriptProjectBuilder, TypeScriptProject, diff --git a/tsconfig.json b/tsconfig.json index f9346d8a8e44e9..991d9c8a764455 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -52,7 +52,7 @@ "@mui/zero-vite-plugin": ["./packages/zero-vite-plugin/src"], "@mui/zero-vite-plugin/*": ["./packages/zero-vite-plugin/src/*"], "@mui-internal/docs-utils": ["./packages/docs-utils/src"], - "typescript-to-proptypes": ["./packages/typescript-to-proptypes/src"] + "@mui-internal/typescript-to-proptypes": ["./packages/typescript-to-proptypes/src"] }, // Otherwise we get react-native typings which conflict with dom.lib. "types": ["node", "react"] diff --git a/webpackBaseConfig.js b/webpackBaseConfig.js index a1aebe9d413871..ac26167c3cabd7 100644 --- a/webpackBaseConfig.js +++ b/webpackBaseConfig.js @@ -26,7 +26,10 @@ module.exports = { '@mui/joy': path.resolve(__dirname, './packages/mui-joy/src'), '@mui/zero-runtime': path.resolve(__dirname, './packages/zero-runtime/src'), '@mui-internal/docs-utils': path.resolve(__dirname, './packages/docs-utils/src'), - 'typescript-to-proptypes': path.resolve(__dirname, './packages/typescript-to-proptypes/src'), + '@mui-internal/typescript-to-proptypes': path.resolve( + __dirname, + './packages/typescript-to-proptypes/src', + ), docs: path.resolve(__dirname, './docs'), }, extensions: ['.js', '.ts', '.tsx', '.d.ts'], From 0a1db7b3bc3cba9d4708007eb2b45a6e9e066970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Fri, 2 Feb 2024 09:46:00 +0100 Subject: [PATCH 3/6] Exclude tsbuildinfo from package contents --- packages/docs-utils/.npmignore | 1 + packages/typescript-to-proptypes/.npmignore | 1 + 2 files changed, 2 insertions(+) create mode 100644 packages/docs-utils/.npmignore create mode 100644 packages/typescript-to-proptypes/.npmignore diff --git a/packages/docs-utils/.npmignore b/packages/docs-utils/.npmignore new file mode 100644 index 00000000000000..81f0fda795522a --- /dev/null +++ b/packages/docs-utils/.npmignore @@ -0,0 +1 @@ +.tsbuildinfo diff --git a/packages/typescript-to-proptypes/.npmignore b/packages/typescript-to-proptypes/.npmignore new file mode 100644 index 00000000000000..81f0fda795522a --- /dev/null +++ b/packages/typescript-to-proptypes/.npmignore @@ -0,0 +1 @@ +.tsbuildinfo From 86c519346b5e077e6dfa6a0d8f27d3428f51131c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Fri, 2 Feb 2024 09:51:09 +0100 Subject: [PATCH 4/6] Add access: public to packages --- packages/docs-utils/package.json | 3 +++ packages/typescript-to-proptypes/package.json | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/docs-utils/package.json b/packages/docs-utils/package.json index 3210c4509a408a..5054f175df2ef5 100644 --- a/packages/docs-utils/package.json +++ b/packages/docs-utils/package.json @@ -23,5 +23,8 @@ "dependencies": { "rimraf": "^5.0.5", "typescript": "^5.1.6" + }, + "publishConfig": { + "access": "public" } } diff --git a/packages/typescript-to-proptypes/package.json b/packages/typescript-to-proptypes/package.json index 1dd15c859acf5b..1ebc835222d7c6 100644 --- a/packages/typescript-to-proptypes/package.json +++ b/packages/typescript-to-proptypes/package.json @@ -48,5 +48,8 @@ "fast-glob": "^3.3.2", "prettier": "^2.8.8", "rimraf": "^5.0.5" + }, + "publishConfig": { + "access": "public" } } From cbf67a3c51c80cf143c5453b93a4686e98cc073b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Fri, 2 Feb 2024 10:09:01 +0100 Subject: [PATCH 5/6] Bump TTP version --- packages/typescript-to-proptypes/CHANGELOG.md | 4 ++++ packages/typescript-to-proptypes/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/typescript-to-proptypes/CHANGELOG.md b/packages/typescript-to-proptypes/CHANGELOG.md index 9a611104556b62..c1a940856b12fe 100644 --- a/packages/typescript-to-proptypes/CHANGELOG.md +++ b/packages/typescript-to-proptypes/CHANGELOG.md @@ -5,6 +5,10 @@ For changes before the package was forked, while it was and published as `typesc Unfortunately changes done between forking the `typescript-to-proptypes` and publishing `@mui-internal/typescript-to-proptypes` are not documented. +## 1.0.1 + +Fix the incorrectly published package. + ## 1.0.0 Initial release as a `@mui-internal/typescript-to-proptypes` package. diff --git a/packages/typescript-to-proptypes/package.json b/packages/typescript-to-proptypes/package.json index 1ebc835222d7c6..daa6d227e93373 100644 --- a/packages/typescript-to-proptypes/package.json +++ b/packages/typescript-to-proptypes/package.json @@ -1,6 +1,6 @@ { "name": "@mui-internal/typescript-to-proptypes", - "version": "1.0.0", + "version": "1.0.1", "author": "MUI Team", "description": "Generate proptypes from TypeScript declarations. This is a fork of the typescript-to-proptypes package adapted for MUI needs. This is an internal package not meant for general use.", "main": "build/index.js", From 076f99fa387d7875d10bafc3ff19d94e68008edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Fri, 2 Feb 2024 10:13:47 +0100 Subject: [PATCH 6/6] Bump TTP version --- packages/typescript-to-proptypes/CHANGELOG.md | 4 ++++ packages/typescript-to-proptypes/package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/typescript-to-proptypes/CHANGELOG.md b/packages/typescript-to-proptypes/CHANGELOG.md index c1a940856b12fe..92be29c879bcf8 100644 --- a/packages/typescript-to-proptypes/CHANGELOG.md +++ b/packages/typescript-to-proptypes/CHANGELOG.md @@ -5,6 +5,10 @@ For changes before the package was forked, while it was and published as `typesc Unfortunately changes done between forking the `typescript-to-proptypes` and publishing `@mui-internal/typescript-to-proptypes` are not documented. +## 1.0.2 + +Fix the incorrectly published package. + ## 1.0.1 Fix the incorrectly published package. diff --git a/packages/typescript-to-proptypes/package.json b/packages/typescript-to-proptypes/package.json index daa6d227e93373..4cbcbda402c33b 100644 --- a/packages/typescript-to-proptypes/package.json +++ b/packages/typescript-to-proptypes/package.json @@ -1,6 +1,6 @@ { "name": "@mui-internal/typescript-to-proptypes", - "version": "1.0.1", + "version": "1.0.2", "author": "MUI Team", "description": "Generate proptypes from TypeScript declarations. This is a fork of the typescript-to-proptypes package adapted for MUI needs. This is an internal package not meant for general use.", "main": "build/index.js", @@ -15,7 +15,7 @@ }, "license": "MIT", "scripts": { - "prepublish": "rimraf ./build", + "prebuild": "rimraf ./build", "build": "tsc -b tsconfig.build.json", "release:publish": "pnpm publish --tag latest", "release:publish:dry-run": "pnpm publish --tag latest --registry=\"http://localhost:4873/\"",