Skip to content

Commit

Permalink
feat(core): remove @types/node from default workspace (#9853)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Jean <[email protected]>
  • Loading branch information
FrozenPandaz authored Apr 20, 2022
1 parent 8171e68 commit cb7fb22
Show file tree
Hide file tree
Showing 27 changed files with 105 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["**/*.ts"],
"compilerOptions": {
"types": [
<% if (unitTestRunner === 'jest') { %>"jest",<% } %>
<% if (unitTestRunner === 'karma') { %>"jasmine",<% } %>
"node"
]
}
"compilerOptions": {}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
import type { Tree } from '@nrwl/devkit';
import type { NormalizedSchema } from './normalized-schema';

import { joinPathFragments, updateJson } from '@nrwl/devkit';
import { joinPathFragments, readJson, updateJson } from '@nrwl/devkit';

interface TsConfig {
compilerOptions: { types: string[] };
}

function getCompilerOptionsTypes(tsConfig: TsConfig): string[] {
return tsConfig?.compilerOptions?.types ?? [];
}

export function updateEditorTsConfig(tree: Tree, options: NormalizedSchema) {
const types = getCompilerOptionsTypes(
readJson<TsConfig>(
tree,
joinPathFragments(options.appProjectRoot, 'tsconfig.app.json')
)
);

if (options.unitTestRunner !== 'none') {
types.concat(
getCompilerOptionsTypes(
readJson<TsConfig>(
tree,
joinPathFragments(options.appProjectRoot, 'tsconfig.spec.json')
)
)
);
}

updateJson(
tree,
joinPathFragments(options.appProjectRoot, 'tsconfig.editor.json'),
(json) => {
json.compilerOptions.types = types;
return json;
}
);

export function updateEditorTsConfig(host: Tree, options: NormalizedSchema) {
// This should be the last tsconfig references so it's not in the template
updateJson(
host,
tree,
joinPathFragments(options.appProjectRoot, 'tsconfig.json'),
(json) => {
json.references.push({
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/generators/karma/karma.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('karma', () => {
expect(devDependencies['jasmine-core']).toBeDefined();
expect(devDependencies['jasmine-spec-reporter']).toBeDefined();
expect(devDependencies['@types/jasmine']).toBeDefined();
expect(devDependencies['@types/node']).toBeDefined();
});

it('should add karma configuration', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/generators/karma/karma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function karmaGenerator(tree: Tree, options: GeneratorOptions) {
'jasmine-core': '~3.10.0',
'jasmine-spec-reporter': '~5.0.0',
'@types/jasmine': '~3.5.0',
'@types/node': '16.11.7',
}
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/cypress/src/generators/init/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('init', () => {

expect(packageJson.devDependencies.cypress).toBeDefined();
expect(packageJson.devDependencies['@nrwl/cypress']).toBeDefined();
expect(packageJson.devDependencies['@types/node']).toBeDefined();
expect(packageJson.devDependencies[existing]).toBeDefined();
expect(packageJson.dependencies['@nrwl/cypress']).toBeUndefined();
expect(packageJson.dependencies[existing]).toBeDefined();
Expand Down
7 changes: 6 additions & 1 deletion packages/cypress/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import {
removeDependenciesFromPackageJson,
Tree,
} from '@nrwl/devkit';
import { cypressVersion, nxVersion } from '../../utils/versions';
import {
cypressVersion,
nxVersion,
typesNodeVersion,
} from '../../utils/versions';
import { Schema } from './schema';

function updateDependencies(host: Tree) {
Expand All @@ -16,6 +20,7 @@ function updateDependencies(host: Tree) {
{
['@nrwl/cypress']: nxVersion,
cypress: cypressVersion,
'@types/node': typesNodeVersion,
}
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/cypress/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const nxVersion = '*';
export const cypressVersion = '^9.1.0';
export const eslintPluginCypressVersion = '^2.10.3';
export const typesNodeVersion = '16.11.7';
1 change: 1 addition & 0 deletions packages/detox/src/generators/init/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('init', () => {
await detoxInitGenerator(tree, {});
const packageJson = readJson(tree, 'package.json');
expect(packageJson.devDependencies['@nrwl/detox']).toBeDefined();
expect(packageJson.devDependencies['@types/node']).toBeDefined();
expect(packageJson.devDependencies['detox']).toBeDefined();
});
});
3 changes: 2 additions & 1 deletion packages/detox/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
removeDependenciesFromPackageJson,
Tree,
} from '@nrwl/devkit';
import { jestVersion } from '@nrwl/jest/src/utils/versions';
import { jestVersion, typesNodeVersion } from '@nrwl/jest/src/utils/versions';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
import { Schema } from './schema';
import {
Expand All @@ -32,6 +32,7 @@ export function updateDependencies(host: Tree) {
'@nrwl/detox': nxVersion,
detox: detoxVersion,
'@testing-library/jest-dom': testingLibraryJestDom,
'@types/node': typesNodeVersion,
'jest-circus': jestVersion,
}
);
Expand Down
1 change: 1 addition & 0 deletions packages/jest/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function updateDependencies(tree: Tree, options: NormalizedSchema) {
'@nrwl/jest': nxVersion,
jest: jestVersion,
'@types/jest': jestTypesVersion,
'@types/node': '16.11.7',
// because the default jest-preset uses ts-jest,
// jest will throw an error if it's not installed
// even if not using it in overriding transformers
Expand Down
1 change: 1 addition & 0 deletions packages/jest/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const tslibVersion = '^2.0.0';
export const tsJestVersion = '27.0.5';
export const babelJestVersion = '27.2.3';
export const swcJestVersion = '0.2.15';
export const typesNodeVersion = '16.11.7';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"types": ["node", "jest"],
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
Expand Down
33 changes: 28 additions & 5 deletions packages/next/src/generators/application/lib/add-jest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tree, updateJson } from '@nrwl/devkit';
import { joinPathFragments, readJson, Tree, updateJson } from '@nrwl/devkit';
import { jestProjectGenerator } from '@nrwl/jest';
import { NormalizedSchema } from './normalize-options';

Expand All @@ -15,10 +15,33 @@ export async function addJest(host: Tree, options: NormalizedSchema) {
compiler: 'babel',
});

updateJson(host, `${options.appProjectRoot}/tsconfig.spec.json`, (json) => {
json.compilerOptions.jsx = 'react';
return json;
});
const tsConfigSpecJson = readJson(
host,
joinPathFragments(options.appProjectRoot, 'tsconfig.spec.json')
);

updateJson(
host,
joinPathFragments(options.appProjectRoot, 'tsconfig.json'),
(json) => {
json.compilerOptions ??= {};
json.compilerOptions.types ??= [];
json.compilerOptions.types.push(
...(tsConfigSpecJson?.compilerOptions?.types ?? [])
);

return json;
}
);

updateJson(
host,
joinPathFragments(options.appProjectRoot, 'tsconfig.spec.json'),
(json) => {
json.compilerOptions.jsx = 'react';
return json;
}
);

return jestTask;
}
8 changes: 6 additions & 2 deletions packages/node/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
} from '@nrwl/devkit';
import { jestInitGenerator } from '@nrwl/jest';
import { setDefaultCollection } from '@nrwl/workspace/src/utilities/set-default-collection';
import { nxVersion, tslibVersion } from '../../utils/versions';
import {
nxVersion,
tslibVersion,
typesNodeVersion,
} from '../../utils/versions';
import { Schema } from './schema';

function updateDependencies(tree: Tree) {
Expand All @@ -19,7 +23,7 @@ function updateDependencies(tree: Tree) {
{
tslib: tslibVersion,
},
{ '@nrwl/node': nxVersion }
{ '@nrwl/node': nxVersion, '@types/node': typesNodeVersion }
);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const nxVersion = '*';

export const tslibVersion = '^2.0.0';

export const typesNodeVersion = '16.11.7';
1 change: 1 addition & 0 deletions packages/react-native/src/generators/init/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('init', () => {
const packageJson = readJson(tree, 'package.json');
expect(packageJson.dependencies['react']).toBeDefined();
expect(packageJson.dependencies['react-native']).toBeDefined();
expect(packageJson.devDependencies['@types/node']).toBeDefined();
expect(packageJson.devDependencies['@types/react']).toBeDefined();
expect(packageJson.devDependencies['@types/react-native']).toBeDefined();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
reactVersion,
testingLibraryJestNativeVersion,
testingLibraryReactNativeVersion,
typesNodeVersion,
typesReactNativeVersion,
} from '../../utils/versions';

Expand Down Expand Up @@ -80,6 +81,7 @@ export function updateDependencies(host: Tree) {
},
{
'@nrwl/react-native': nxVersion,
'@types/node': typesNodeVersion,
'@types/react': typesReactVersion,
'@types/react-native': typesReactNativeVersion,
'@react-native-community/cli': reactNativeCommunityCli,
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export const nxVersion = '*';
export const reactNativeVersion = '0.67.4';
export const typesReactNativeVersion = '0.67.3';

export const typesNodeVersion = '16.11.7';

export const metroVersion = '0.70.0';

// TODO(jack): Remove this once react-native 0.68.0 is released.
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/generators/init/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('init', () => {
const packageJson = readJson(tree, 'package.json');
expect(packageJson.dependencies['react']).toBeDefined();
expect(packageJson.dependencies['react-dom']).toBeDefined();
expect(packageJson.devDependencies['@types/node']).toBeDefined();
expect(packageJson.devDependencies['@types/react']).toBeDefined();
expect(packageJson.devDependencies['@types/react-dom']).toBeDefined();
expect(packageJson.devDependencies['@testing-library/react']).toBeDefined();
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
reactTestRendererVersion,
reactVersion,
testingLibraryReactVersion,
typesNodeVersion,
typesReactDomVersion,
typesReactVersion,
} from '../../utils/versions';
Expand Down Expand Up @@ -57,6 +58,7 @@ function updateDependencies(host: Tree) {
},
{
'@nrwl/react': nxVersion,
'@types/node': typesNodeVersion,
'@types/react': typesReactVersion,
'@types/react-dom': typesReactDomVersion,
'@testing-library/react': testingLibraryReactVersion,
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const typesReactVersion = '18.0.1';
export const typesReactDomVersion = '18.0.0';
export const typesReactIsVersion = '17.0.3';

export const typesNodeVersion = '16.11.7';

export const styledComponentsVersion = '5.3.5';
export const typesStyledComponentsVersion = '5.1.25';

Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { jestInitGenerator } from '@nrwl/jest';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
import { setDefaultCollection } from '@nrwl/workspace/src/utilities/set-default-collection';
import { nxVersion } from '../../utils/versions';
import { nxVersion, typesNodeVersion } from '../../utils/versions';
import { Schema } from './schema';

function updateDependencies(tree: Tree) {
Expand All @@ -26,6 +26,7 @@ function updateDependencies(tree: Tree) {
},
{
'@nrwl/web': nxVersion,
'@types/node': typesNodeVersion,
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const nxVersion = '*';

export const swcLoaderVersion = '0.1.15';
export const sassVersion = '1.43.2';
export const typesNodeVersion = '16.11.7';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Object {
"devDependencies": Object {
"@nrwl/cli": "*",
"@nrwl/workspace": "*",
"@types/node": "16.11.7",
"nx": "*",
"prettier": "^2.5.1",
"typescript": "~4.6.2",
Expand All @@ -31,7 +30,6 @@ Object {
"devDependencies": Object {
"@nrwl/cli": "*",
"@nrwl/workspace": "*",
"@types/node": "16.11.7",
"nx": "*",
"prettier": "^2.5.1",
"typescript": "~4.6.2",
Expand All @@ -55,7 +53,6 @@ Object {
"@nrwl/cli": "*",
"@nrwl/react": "*",
"@nrwl/workspace": "*",
"@types/node": "16.11.7",
"nx": "*",
"prettier": "^2.5.1",
"typescript": "~4.6.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"nx": "<%= nxVersion %>",
"@nrwl/cli": "<%= nxVersion %>",
"@nrwl/workspace": "<%= nxVersion %>",
"@types/node": "16.11.7",
"typescript": "<%= typescriptVersion %>",
"prettier": "<%= prettierVersion %>"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Object {
expect(tree.exists('/proj/apps/.gitkeep')).toBe(false);
expect(tree.exists('/proj/libs/.gitkeep')).toBe(false);
const nx = readJson(tree, '/proj/nx.json');
expect(nx.extends).toEqual('@nrwl/workspace/presets/core.json');
expect(nx.extends).toEqual('nx/presets/core.json');

const { scripts } = readJson(tree, '/proj/package.json');
expect(scripts).toMatchInlineSnapshot(`Object {}`);
Expand Down
6 changes: 1 addition & 5 deletions packages/workspace/src/generators/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ function setPresetProperty(tree: Tree, options: Schema) {
options.preset === Preset.TS ||
options.preset === Preset.NPM
) {
addPropertyWithStableKeys(
json,
'extends',
'@nrwl/workspace/presets/core.json'
);
addPropertyWithStableKeys(json, 'extends', 'nx/presets/core.json');
delete json.implicitDependencies;
delete json.targetDependencies;
delete json.workspaceLayout;
Expand Down

0 comments on commit cb7fb22

Please sign in to comment.