-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): add babel/core when babel/preset-react is preset (#18462)
- Loading branch information
Showing
7 changed files
with
72 additions
and
2 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
32 changes: 32 additions & 0 deletions
32
packages/react/src/migrations/update-16-7-0/add-babel-core.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,32 @@ | ||
import { Tree, readJson, updateJson } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import addBabelCore from './add-babel-core'; | ||
|
||
describe('update-16-7-0-add-babel-core', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should add @babel/core to package.json', async () => { | ||
updateJson(tree, 'package.json', (json) => { | ||
json.devDependencies['@babel/preset-react'] = '*'; | ||
return json; | ||
}); | ||
|
||
await addBabelCore(tree); | ||
|
||
expect( | ||
readJson(tree, 'package.json').devDependencies['@babel/core'] | ||
).toBeDefined(); | ||
}); | ||
|
||
it('should not add @babel/core to package.json if preset-react is not available', async () => { | ||
await addBabelCore(tree); | ||
|
||
expect( | ||
readJson(tree, 'package.json').devDependencies['@babel/core'] | ||
).not.toBeDefined(); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/react/src/migrations/update-16-7-0/add-babel-core.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,21 @@ | ||
import { | ||
Tree, | ||
addDependenciesToPackageJson, | ||
formatFiles, | ||
readJson, | ||
} from '@nx/devkit'; | ||
import { babelCoreVersion } from '../../utils/versions'; | ||
|
||
export default async function addBabelCore(tree: Tree): Promise<void> { | ||
const packageJson = readJson(tree, 'package.json'); | ||
if (packageJson?.devDependencies['@babel/preset-react']) { | ||
addDependenciesToPackageJson( | ||
tree, | ||
{}, | ||
{ | ||
'@babel/core': babelCoreVersion, | ||
} | ||
); | ||
await formatFiles(tree); | ||
} | ||
} |
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
b317458
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app