Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react): update to react 18 (#9613)
- Loading branch information
Showing
11 changed files
with
212 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/react/src/migrations/update-13-10-0/update-13-10-0.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { writeJson, readJson, Tree } from '@nrwl/devkit'; | ||
import migrate from './update-13-10-0'; | ||
|
||
describe('Update tsconfig for React apps', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should update to React 18 if React Native is not installed', async () => { | ||
writeJson(tree, 'package.json', { | ||
dependencies: { | ||
react: '17.0.2', | ||
}, | ||
}); | ||
|
||
const installTask = await migrate(tree); | ||
expect(installTask).toBeDefined(); | ||
}); | ||
|
||
it('should update to React 18 if React Native 0.68.0-rc.4 is installed', async () => { | ||
writeJson(tree, 'package.json', { | ||
dependencies: { | ||
react: '17.0.2', | ||
'react-native': '0.68.0-rc.4', | ||
}, | ||
}); | ||
|
||
await migrate(tree); | ||
|
||
const installTask = await migrate(tree); | ||
expect(installTask).toBeDefined(); | ||
}); | ||
|
||
it('should skip update to React 18 if React Native 0.67.0 is installed', async () => { | ||
writeJson(tree, 'package.json', { | ||
dependencies: { | ||
react: '17.0.2', | ||
'react-native': '0.67.0', | ||
}, | ||
}); | ||
|
||
await migrate(tree); | ||
|
||
const installTask = await migrate(tree); | ||
expect(installTask).not.toBeDefined(); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/react/src/migrations/update-13-10-0/update-13-10-0.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
addDependenciesToPackageJson, | ||
readJson, | ||
logger, | ||
Tree, | ||
} from '@nrwl/devkit'; | ||
|
||
// Putting this here because React Native 0.67 is incompatible with React 18. | ||
// Waiting for 0.68 to come out with support for React 18. | ||
// TODO(jack): For Nx 14 let's add another migration for React 18 in migrations.json because by then React Native 0.68.0 should be released. | ||
export async function updateToReact18(host: Tree) { | ||
const { dependencies } = readJson(host, 'package.json'); | ||
if ( | ||
dependencies['react-native'] && | ||
!dependencies['react-native'].match(/[\^~]?0.68/) | ||
) { | ||
logger.info( | ||
`React Native ${dependencies['react-native']} is incompatible with React 18. Skipping update until React Native 0.68.0 is released.` | ||
); | ||
} else { | ||
return addDependenciesToPackageJson( | ||
host, | ||
{ | ||
react: '18.0.0', | ||
'react-dom': '18.0.0', | ||
'react-is': '18.0.0', | ||
'react-test-renderer': '18.0.0', | ||
}, | ||
{} | ||
); | ||
} | ||
} | ||
|
||
export default updateToReact18; |
Oops, something went wrong.