Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(project): update project to use React 18 #2661

Merged
merged 37 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ec8089a
chore(project): add script to set react version
joshblack Dec 6, 2022
175714e
chore: add ci check for test and type-check
joshblack Dec 6, 2022
b4c872b
chore: update workflow syntax
joshblack Dec 6, 2022
4b59e81
chore: update install step
joshblack Dec 6, 2022
61f9730
chore: add fail-fast option
joshblack Dec 6, 2022
8e77628
chore: add types packages to set-react-version
joshblack Dec 6, 2022
f1ff3ec
refactor(project): update TypeScript definitions for React 18
joshblack Dec 7, 2022
89a38c6
chore: update slots types
joshblack Dec 7, 2022
987964b
chore: add ts-ignore for package that needs to be updated for react 18
joshblack Dec 7, 2022
d051d9c
chore: add changeset
joshblack Dec 7, 2022
474cac4
chore: update ActionMenu story to use React.createElement
joshblack Dec 8, 2022
442fd91
chore: update unused import
joshblack Dec 9, 2022
70acaf1
test(ThemeProvider): update test to use userEvents
joshblack Dec 8, 2022
4140673
test(helpers): add TextEncoder for useMedia
joshblack Dec 8, 2022
b4b2a8d
test(MarkdownEditor): update tests for MarkdownEditor
joshblack Dec 9, 2022
b2d5520
test: update TextInputWithTokens test
joshblack Dec 9, 2022
58f0102
test(MarkdownEditor): enable skipped tests
joshblack Dec 9, 2022
23ec248
chore: add spy for console.error() in test
joshblack Dec 12, 2022
3feefab
chore: add globals for react version
joshblack Dec 12, 2022
914d222
chore: remove storybook-addon-html
joshblack Dec 9, 2022
6385ace
chore: update storybook deps
joshblack Dec 9, 2022
976d26f
chore: remove conditional install step from ci.yml
joshblack Dec 9, 2022
325345f
Revert "chore: remove conditional install step from ci.yml"
joshblack Dec 9, 2022
5b4850b
feat(project): update to React 18 for development
joshblack Dec 9, 2022
fa1a5a9
ci: update install step to use 18 by default
joshblack Dec 9, 2022
0d77e0c
chore: update lockfile
joshblack Dec 9, 2022
3f1504d
chore: update eslint to warn on useSSRSafeId
joshblack Dec 9, 2022
013bfdc
feat(project): add useId hook
joshblack Dec 9, 2022
c4c4221
feat(project): update useSSRSafeId to useId
joshblack Dec 9, 2022
4cc7e2e
chore: disable eslint violations
joshblack Dec 9, 2022
5aa9a4d
test: map useId() to useSSRSafeId() in test
joshblack Dec 12, 2022
6d78c16
test(storybook): update interaction tests for UnderlineNav
joshblack Dec 13, 2022
1efba24
chore: add changeset
joshblack Dec 13, 2022
f8bc3c0
Merge branch 'main' of github.com:primer/react into ci/add-react-18-test
joshblack Dec 16, 2022
2e99494
fix(PageHeader): add PropsWithChildren to ParentLinkProps
joshblack Dec 16, 2022
41c96c4
chore: update workflow file
joshblack Dec 16, 2022
9f25f74
chore(eslint): remove inferred type annotation
joshblack Dec 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
run: npm run lint

test:
strategy:
fail-fast: false
matrix:
react: [17, 18]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -38,7 +42,15 @@ jobs:
with:
node-version: 16

- name: Set React version
run: node script/set-react-version.js ${{ matrix.react }}

- name: Install dependencies
if: ${{ matrix.react == 18 }}
run: npm install --legacy-peer-deps

- name: Install dependencies
if: ${{ matrix.react == 17 }}
run: npm ci

- name: Build
Expand All @@ -48,6 +60,10 @@ jobs:
run: npm run test -- --coverage

type-check:
strategy:
fail-fast: false
matrix:
react: [17, 18]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -58,7 +74,15 @@ jobs:
with:
node-version: 16

- name: Set React version
run: node script/set-react-version.js ${{ matrix.react }}

- name: Install dependencies
if: ${{ matrix.react == 18 }}
run: npm install --legacy-peer-deps

- name: Install dependencies
if: ${{ matrix.react != 18 }}
run: npm ci

- name: Type check
Expand Down
88 changes: 88 additions & 0 deletions script/set-react-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'use strict'

const fs = require('node:fs/promises')
const os = require('node:os')
const path = require('node:path')

const versions = new Map([
[
'17',
{
devDependencies: [
{
name: 'react',
version: '17.0.2',
},
{
name: 'react-dom',
version: '17.0.2',
},
{
name: 'react-test-renderer',
version: '17.0.2',
},
{
name: '@testing-library/react',
version: '12.1.5',
},
],
},
],
[
'18',
{
devDependencies: [
joshblack marked this conversation as resolved.
Show resolved Hide resolved
{
name: '@types/react',
version: '18.0.26',
},
{
name: '@types/react-dom',
version: '18.0.9',
},
{
name: 'react',
version: '18.2.0',
},
{
name: 'react-dom',
version: '18.2.0',
},
{
name: 'react-test-renderer',
version: '18.2.0',
},
{
name: '@testing-library/react',
version: '13.4.0',
},
],
},
],
])

async function main(version = 17) {
if (!versions.has(version)) {
throw new Error(`No React version defined for input: ${version}`)
}

const {devDependencies} = versions.get(version)
const packageJsonPath = path.resolve(__dirname, '..', 'package.json')
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'))

for (const dependency of devDependencies) {
packageJson.devDependencies[dependency.name] = dependency.version
}

const contents = `${JSON.stringify(packageJson, null, 2)}${os.EOL}`
await fs.writeFile(packageJsonPath, contents)
}

const [version] = process.argv.slice(2)

// eslint-disable-next-line github/no-then
main(version).catch(error => {
// eslint-disable-next-line no-console
console.log(error)
process.exit(1)
})