fix(react): add emotion babel preset during migration (#3127)

This commit is contained in:
Jason Jean 2020-06-06 20:58:48 -04:00 committed by GitHub
parent 014dc4931d
commit 539c65c0be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -48,7 +48,7 @@ describe('Migrate babel setup', () => {
.toPromise();
const content = tree.read('/apps/demo/.babelrc').toString();
expect(content).toEqual('{}');
expect(content.trim()).toEqual('{}');
});
it(`should not migrate non-React projects`, async () => {

View File

@ -10,6 +10,9 @@ import {
stripIndents,
} from '@angular-devkit/core/src/utils/literals';
import { initRootBabelConfig } from '@nrwl/web/src/utils/rules';
import { addDepsToPackageJson, formatFiles } from '@nrwl/workspace';
let addedEmotionPreset = false;
/*
* This migration will do a few things:
@ -74,6 +77,11 @@ export default function update(): Rule {
You may want to update them to include the Nx preset "@nrwl/react/babel".
`);
}
updates.push((host) =>
addedEmotionPreset ? addEmotionPresetPackage : host
);
updates.push(formatFiles());
return chain(updates);
};
@ -93,6 +101,7 @@ function createBabelrc(host, context, babelrcPath, deps) {
if (deps.some((d) => d.target.startsWith('npm:@emotion'))) {
babelrc.presets.push('@emotion/babel-preset-css-prop');
addedEmotionPreset = true;
added++;
}
@ -108,3 +117,10 @@ function createBabelrc(host, context, babelrcPath, deps) {
host.create(babelrcPath, JSON.stringify(babelrc, null, 2));
}
const addEmotionPresetPackage = addDepsToPackageJson(
{},
{
'@emotion/babel-preset-css-prop': '10.0.27',
}
);