feat(react): add strict option to react application generator (#5248)
This commit is contained in:
parent
111a7cfeaf
commit
6cb1dc65d0
@ -142,6 +142,14 @@ Type: `boolean`
|
||||
|
||||
Skip updating workspace.json with default options based on values provided to this app (e.g. babel, style).
|
||||
|
||||
### strict
|
||||
|
||||
Default: `false`
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Creates an application with stricter type checking and build optimization options.
|
||||
|
||||
### style
|
||||
|
||||
Alias(es): s
|
||||
|
||||
@ -142,6 +142,14 @@ Type: `boolean`
|
||||
|
||||
Skip updating workspace.json with default options based on values provided to this app (e.g. babel, style).
|
||||
|
||||
### strict
|
||||
|
||||
Default: `false`
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Creates an application with stricter type checking and build optimization options.
|
||||
|
||||
### style
|
||||
|
||||
Alias(es): s
|
||||
|
||||
@ -142,6 +142,14 @@ Type: `boolean`
|
||||
|
||||
Skip updating workspace.json with default options based on values provided to this app (e.g. babel, style).
|
||||
|
||||
### strict
|
||||
|
||||
Default: `false`
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Creates an application with stricter type checking and build optimization options.
|
||||
|
||||
### style
|
||||
|
||||
Alias(es): s
|
||||
|
||||
@ -20,6 +20,7 @@ describe('app', () => {
|
||||
name: 'myApp',
|
||||
linter: Linter.EsLint,
|
||||
style: 'css',
|
||||
strict: false,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@ -75,6 +76,14 @@ describe('app', () => {
|
||||
path: './tsconfig.spec.json',
|
||||
},
|
||||
]);
|
||||
expect(tsconfig.compilerOptions.strict).not.toBeDefined();
|
||||
expect(
|
||||
tsconfig.compilerOptions.forceConsistentCasingInFileNames
|
||||
).not.toBeDefined();
|
||||
expect(tsconfig.compilerOptions.noImplicitReturns).not.toBeDefined();
|
||||
expect(
|
||||
tsconfig.compilerOptions.noFallthroughCasesInSwitch
|
||||
).not.toBeDefined();
|
||||
|
||||
const tsconfigApp = JSON.parse(
|
||||
stripJsonComments(
|
||||
@ -669,4 +678,40 @@ describe('app', () => {
|
||||
expect(appTree.exists('/apps/my-app/src/main.js')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('--strict', () => {
|
||||
it('should update tsconfig.json', async () => {
|
||||
await applicationGenerator(appTree, {
|
||||
...schema,
|
||||
strict: true,
|
||||
});
|
||||
const tsconfigJson = readJson(appTree, '/apps/my-app/tsconfig.json');
|
||||
|
||||
expect(tsconfigJson.compilerOptions.strict).toBeTruthy();
|
||||
expect(
|
||||
tsconfigJson.compilerOptions.forceConsistentCasingInFileNames
|
||||
).toBeTruthy();
|
||||
expect(tsconfigJson.compilerOptions.noImplicitReturns).toBeTruthy();
|
||||
expect(
|
||||
tsconfigJson.compilerOptions.noFallthroughCasesInSwitch
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should update budgets in workspace.json', async () => {
|
||||
await applicationGenerator(appTree, {
|
||||
...schema,
|
||||
strict: true,
|
||||
});
|
||||
const workspaceJson = getProjects(appTree);
|
||||
const targetConfig = workspaceJson.get('my-app').targets;
|
||||
|
||||
expect(targetConfig.build.configurations.production.budgets).toEqual([
|
||||
{
|
||||
type: 'initial',
|
||||
maximumWarning: '500kb',
|
||||
maximumError: '1mb',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -87,7 +87,15 @@ function createBuildTarget(options: NormalizedSchema): TargetConfiguration {
|
||||
namedChunks: false,
|
||||
extractLicenses: true,
|
||||
vendorChunk: false,
|
||||
budgets: [
|
||||
budgets: options.strict
|
||||
? [
|
||||
{
|
||||
type: 'initial',
|
||||
maximumWarning: '500kb',
|
||||
maximumError: '1mb',
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
type: 'initial',
|
||||
maximumWarning: '2mb',
|
||||
|
||||
@ -1,7 +1,35 @@
|
||||
import { NormalizedSchema } from '../schema';
|
||||
import { names, offsetFromRoot, Tree, toJS, generateFiles } from '@nrwl/devkit';
|
||||
import {
|
||||
names,
|
||||
offsetFromRoot,
|
||||
Tree,
|
||||
toJS,
|
||||
generateFiles,
|
||||
joinPathFragments,
|
||||
updateJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { join } from 'path';
|
||||
|
||||
function updateTsConfig(host: Tree, options: NormalizedSchema) {
|
||||
updateJson(
|
||||
host,
|
||||
joinPathFragments(options.appProjectRoot, 'tsconfig.json'),
|
||||
(json) => {
|
||||
if (options.strict) {
|
||||
json.compilerOptions = {
|
||||
...json.compilerOptions,
|
||||
forceConsistentCasingInFileNames: true,
|
||||
strict: true,
|
||||
noImplicitReturns: true,
|
||||
noFallthroughCasesInSwitch: true,
|
||||
};
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function createApplicationFiles(host: Tree, options: NormalizedSchema) {
|
||||
let styleSolutionSpecificAppFiles: string;
|
||||
if (options.styledModule && options.style !== 'styled-jsx') {
|
||||
@ -45,4 +73,6 @@ export function createApplicationFiles(host: Tree, options: NormalizedSchema) {
|
||||
if (options.js) {
|
||||
toJS(host);
|
||||
}
|
||||
|
||||
updateTsConfig(host, options);
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ export interface Schema {
|
||||
skipWorkspaceJson?: boolean;
|
||||
js?: boolean;
|
||||
globalCss?: boolean;
|
||||
strict?: boolean;
|
||||
}
|
||||
|
||||
export interface NormalizedSchema extends Schema {
|
||||
|
||||
@ -135,6 +135,11 @@
|
||||
"type": "boolean",
|
||||
"description": "Default is false. When true, the component is generated with *.css/*.scss instead of *.module.css/*.module.scss",
|
||||
"default": false
|
||||
},
|
||||
"strict": {
|
||||
"type": "boolean",
|
||||
"description": "Creates an application with stricter type checking and build optimization options.",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user