Skip to content

Commit

Permalink
fix(react): fix init generators for react (#4787)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Feb 12, 2021
1 parent 18c8b2b commit 2bf04b4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
10 changes: 9 additions & 1 deletion packages/gatsby/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
convertNxGenerator,
GeneratorCallback,
Tree,
updateJson,
} from '@nrwl/devkit';
import { jestInitGenerator } from '@nrwl/jest';
import { cypressInitGenerator } from '@nrwl/cypress';
Expand Down Expand Up @@ -33,6 +34,13 @@ import { InitSchema } from './schema';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';

function updateDependencies(host: Tree) {
updateJson(host, 'package.json', (json) => {
if (json.dependencies && json.dependencies['@nrwl/gatsby']) {
delete json.dependencies['@nrwl/gatsby'];
}
return json;
});

const isPnpm = host.exists('pnpm-lock.yaml');
return addDependenciesToPackageJson(
host,
Expand All @@ -54,7 +62,7 @@ function updateDependencies(host: Tree) {
...(isPnpm ? { 'gatsby-plugin-pnpm': gatsbyPluginPnpm } : {}),
},
{
'@nrwl/react': nxVersion,
'@nrwl/gatsby': nxVersion,
'@testing-library/react': testingLibraryReactVersion,
'babel-plugin-module-resolver': babelPluginModuleResolverVersion,
'babel-preset-gatsby': babelPresetGatsbyVersion,
Expand Down
14 changes: 12 additions & 2 deletions packages/next/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ import {
convertNxGenerator,
GeneratorCallback,
Tree,
updateJson,
} from '@nrwl/devkit';
import { setDefaultCollection } from '@nrwl/workspace/src/utilities/set-default-collection';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
import { jestInitGenerator } from '@nrwl/jest';
import { cypressInitGenerator } from '@nrwl/cypress';
import { reactDomVersion, reactInitGenerator, reactVersion } from '@nrwl/react';

import { nextVersion } from '../../utils/versions';
import { nextVersion, nxVersion } from '../../utils/versions';
import { InitSchema } from './schema';

function updateDependencies(host: Tree) {
updateJson(host, 'package.json', (json) => {
if (json.dependencies && json.dependencies['@nrwl/gatsby']) {
delete json.dependencies['@nrwl/gatsby'];
}
return json;
});

return addDependenciesToPackageJson(
host,
{
Expand All @@ -22,7 +30,9 @@ function updateDependencies(host: Tree) {
'react-dom': reactDomVersion,
tslib: '^2.0.0',
},
{}
{
'@nrwl/next': nxVersion,
}
);
}

Expand Down
42 changes: 27 additions & 15 deletions packages/react/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GeneratorCallback,
readWorkspaceConfiguration,
Tree,
updateJson,
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import { jestInitGenerator } from '@nrwl/jest';
Expand Down Expand Up @@ -41,6 +42,31 @@ function setDefault(host: Tree) {
setDefaultCollection(host, '@nrwl/react');
}

function updateDependencies(host: Tree) {
updateJson(host, 'package.json', (json) => {
if (json.dependencies && json.dependencies['@nrwl/react']) {
delete json.dependencies['@nrwl/react'];
}
return json;
});

return addDependenciesToPackageJson(
host,
{
'core-js': '^3.6.5',
react: reactVersion,
'react-dom': reactDomVersion,
tslib: '^2.0.0',
},
{
'@nrwl/react': nxVersion,
'@types/react': typesReactVersion,
'@types/react-dom': typesReactDomVersion,
'@testing-library/react': testingLibraryReactVersion,
}
);
}

export async function reactInitGenerator(host: Tree, schema: InitSchema) {
const tasks: GeneratorCallback[] = [];

Expand All @@ -57,21 +83,7 @@ export async function reactInitGenerator(host: Tree, schema: InitSchema) {

const initTask = await webInitGenerator(host, schema);
tasks.push(initTask);
const installTask = addDependenciesToPackageJson(
host,
{
'core-js': '^3.6.5',
react: reactVersion,
'react-dom': reactDomVersion,
tslib: '^2.0.0',
},
{
'@nrwl/react': nxVersion,
'@types/react': typesReactVersion,
'@types/react-dom': typesReactDomVersion,
'@testing-library/react': testingLibraryReactVersion,
}
);
const installTask = updateDependencies(host);
tasks.push(installTask);

return runTasksInSerial(...tasks);
Expand Down

0 comments on commit 2bf04b4

Please sign in to comment.