diff --git a/.circleci/config.yml b/.circleci/config.yml index 05cc3abd94bca..47451d54470b8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,13 +59,6 @@ commands: description: 'Set to true if you intend to any browser (for example with playwright).' steps: - - run: - name: Resolve React version - command: | - node scripts/useReactVersion.mjs - # log a patch for maintainers who want to check out this change - git --no-pager diff HEAD - - when: condition: << parameters.browsers >> steps: @@ -97,16 +90,14 @@ commands: pnpm --version - run: name: Install js dependencies + command: pnpm install + + - run: + name: Resolve React version command: | - echo "React version $REACT_VERSION" - if [ $REACT_VERSION == "stable" ]; - then - echo "pnpm install" - pnpm install - else - echo "pnpm install --no-frozen-lockfile" - pnpm install --no-frozen-lockfile - fi + pnpm use-react-version + # log a patch for maintainers who want to check out this change + git --no-pager diff HEAD - when: condition: << parameters.browsers >> diff --git a/package.json b/package.json index bddc1f0ede496..f89b4b1fd44b9 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "test:argos": "node ./scripts/pushArgos.mjs", "typescript": "lerna run --no-bail --parallel typescript", "typescript:ci": "lerna run --concurrency 3 --no-bail --no-sort typescript", + "use-react-version": "node scripts/useReactVersion.mjs", "build:codesandbox": "pnpm release:build", "install:codesandbox": "pnpm install --no-frozen-lockfile", "release:changelog": "node scripts/releaseChangelog.mjs", @@ -89,7 +90,7 @@ "@mui/internal-markdown": "^1.0.7", "@mui/internal-test-utils": "^1.0.4", "@mui/material": "^5.16.2", - "@mui/monorepo": "github:mui/material-ui#d3d1675b919e937a46e7991856dd8edfa9b53a3e", + "@mui/monorepo": "github:mui/material-ui#288863bd2f8681a82c4bfbaf13215b41043bc551", "@mui/utils": "^5.16.2", "@next/eslint-plugin-next": "14.2.5", "@octokit/plugin-retry": "^7.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6324af6629e53..ae385deecd9a1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -90,8 +90,8 @@ importers: specifier: ^5.16.2 version: 5.16.2(@emotion/react@11.11.4(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.11.5(@emotion/react@11.11.4(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@mui/monorepo': - specifier: github:mui/material-ui#d3d1675b919e937a46e7991856dd8edfa9b53a3e - version: https://codeload.github.com/mui/material-ui/tar.gz/d3d1675b919e937a46e7991856dd8edfa9b53a3e(encoding@0.1.13) + specifier: github:mui/material-ui#288863bd2f8681a82c4bfbaf13215b41043bc551 + version: https://codeload.github.com/mui/material-ui/tar.gz/288863bd2f8681a82c4bfbaf13215b41043bc551(encoding@0.1.13) '@mui/utils': specifier: ^5.16.2 version: 5.16.2(@types/react@18.3.3)(react@18.3.1) @@ -2881,8 +2881,8 @@ packages: '@types/react': optional: true - '@mui/monorepo@https://codeload.github.com/mui/material-ui/tar.gz/d3d1675b919e937a46e7991856dd8edfa9b53a3e': - resolution: {tarball: https://codeload.github.com/mui/material-ui/tar.gz/d3d1675b919e937a46e7991856dd8edfa9b53a3e} + '@mui/monorepo@https://codeload.github.com/mui/material-ui/tar.gz/288863bd2f8681a82c4bfbaf13215b41043bc551': + resolution: {tarball: https://codeload.github.com/mui/material-ui/tar.gz/288863bd2f8681a82c4bfbaf13215b41043bc551} version: 6.0.0-beta.2 engines: {pnpm: 9.5.0} @@ -11084,7 +11084,7 @@ snapshots: '@emotion/styled': 11.11.5(@emotion/react@11.11.4(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1) '@types/react': 18.3.3 - '@mui/monorepo@https://codeload.github.com/mui/material-ui/tar.gz/d3d1675b919e937a46e7991856dd8edfa9b53a3e(encoding@0.1.13)': + '@mui/monorepo@https://codeload.github.com/mui/material-ui/tar.gz/288863bd2f8681a82c4bfbaf13215b41043bc551(encoding@0.1.13)': dependencies: '@googleapis/sheets': 8.0.0(encoding@0.1.13) '@netlify/functions': 2.8.1 diff --git a/scripts/useReactVersion.mjs b/scripts/useReactVersion.mjs index 1a36599fce680..366bd770e53c9 100644 --- a/scripts/useReactVersion.mjs +++ b/scripts/useReactVersion.mjs @@ -1,109 +1 @@ -/* eslint-disable no-console */ -/** - * Given the dist tag fetch the corresponding - * version and make sure this version is used throughout the repository. - * - * If you work on this file: - * WARNING: This script can only use built-in modules since it has to run before - * `pnpm install` - */ -import childProcess from 'child_process'; -import fs from 'fs'; -import os from 'os'; -import path from 'path'; -import { promisify } from 'util'; -import { getWorkspaceRoot } from './utils.mjs'; - -// TODO: reuse the `useReactVersion.mjs` from the monorepo - -const exec = promisify(childProcess.exec); - -// packages published from the react monorepo using the same version -const reactPackageNames = ['react', 'react-dom', 'react-is', 'react-test-renderer', 'scheduler']; -const devDependenciesPackageNames = ['@testing-library/react']; - -// if we need to support more versions we will need to add new mapping here -const additionalVersionsMappings = { - 17: { - '@testing-library/react': '^12.1.0', - }, - 19: {}, -}; - -async function main(version) { - if (typeof version !== 'string') { - throw new TypeError(`expected version: string but got '${version}'`); - } - - if (version === 'stable') { - console.log('Nothing to do with stable'); - return; - } - - const packageJsonPath = path.resolve(getWorkspaceRoot(), 'package.json'); - const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' })); - - // the version is something in format: "17.0.0" - let majorVersion = null; - - if (version.startsWith('^') || version.startsWith('~') || !Number.isNaN(version.charAt(0))) { - majorVersion = version.replace('^', '').replace('~', '').split('.')[0]; - } - - await Promise.all( - reactPackageNames.map(async (reactPackageName) => { - const { stdout: versions } = await exec(`npm dist-tag ls ${reactPackageName} ${version}`); - const tagMapping = versions.split('\n').find((mapping) => { - return mapping.startsWith(`${version}: `); - }); - - let packageVersion = null; - - if (tagMapping === undefined) { - // Some specific version is being requested - if (majorVersion) { - packageVersion = version; - if (reactPackageName === 'scheduler') { - // get the scheduler version from the react-dom's dependencies entry - const { stdout: reactDOMDependenciesString } = await exec( - `npm view --json react-dom@${version} dependencies`, - ); - packageVersion = JSON.parse(reactDOMDependenciesString).scheduler; - } - } else { - throw new Error(`Could not find '${version}' in "${versions}"`); - } - } else { - packageVersion = tagMapping.replace(`${version}: `, ''); - } - - packageJson.resolutions[reactPackageName] = packageVersion; - }), - ); - - // At this moment all dist tags reference React 18 version, so we don't need - // to update these dependencies unless an older version is used, or when the - // next/experimental dist tag reference to a future version of React - // packageJson.devDependencies['@testing-library/react'] = 'alpha'; - - if (majorVersion && additionalVersionsMappings[majorVersion]) { - devDependenciesPackageNames.forEach((packageName) => { - if (!additionalVersionsMappings[majorVersion][packageName]) { - throw new Error( - `Version ${majorVersion} does not have version defined for the ${packageName}`, - ); - } - packageJson.devDependencies[packageName] = - additionalVersionsMappings[majorVersion][packageName]; - }); - } - - // add newline for clean diff - fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}${os.EOL}`); -} - -const [version = process.env.REACT_VERSION] = process.argv.slice(2); -main(version).catch((error) => { - console.error(error); - process.exit(1); -}); +import '@mui/monorepo/scripts/useReactVersion.mjs'; diff --git a/test/README.md b/test/README.md index e2bb080720fb7..f2cf5858e304c 100644 --- a/test/README.md +++ b/test/README.md @@ -4,7 +4,7 @@ You can check integration of different versions of React (for example different [release channels](https://react.dev/community/versioning-policy) or PRs to React) by running the following commands: -1. `node scripts/useReactVersion.mjs `. +1. `pnpm use-react-version `. Possible values for `version`: