Skip to content

Commit

Permalink
fix(web): Add strict mode for @nx/web
Browse files Browse the repository at this point in the history
Reference: #9238
  • Loading branch information
ndcunningham committed May 17, 2024
1 parent 217a349 commit eef3603
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/generated/packages/web/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
"default": false
},
"strict": {
"type": "boolean",
"description": "Creates an application with strict mode and strict type checking.",
"default": true
},
"standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside workspace.json",
"type": "boolean",
Expand Down
12 changes: 12 additions & 0 deletions packages/web/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,18 @@ describe('app', () => {
expect(tree.exists('my-app/.babelrc')).toBeFalsy();
expect(tree.exists('my-app/.swcrc')).toBeTruthy();
});

it('should be strict by default', async () => {
await applicationGenerator(tree, {
name: 'my-app',
compiler: 'swc',
projectNameAndRootFormat: 'as-provided',
addPlugin: true,
} as Schema);

const tsconfig = readJson(tree, 'my-app/tsconfig.json');
expect(tsconfig.compilerOptions.strict).toBeTruthy();
});
});

describe('setup web app with --bundler=vite', () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/web/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
runTasksInSerial,
TargetConfiguration,
Tree,
updateJson,
updateNxJson,
updateProjectConfiguration,
writeJson,
Expand Down Expand Up @@ -109,6 +110,19 @@ function createApplicationFiles(tree: Tree, options: NormalizedSchema) {
);
}
}
updateJson(
tree,
joinPathFragments(options.appProjectRoot, 'tsconfig.json'),
(json) => {
return {
...json,
compilerOptions: {
...(json.compilerOptions || {}),
strict: options.strict,
},
};
}
);
}

async function setupBundler(tree: Tree, options: NormalizedSchema) {
Expand Down Expand Up @@ -534,6 +548,7 @@ async function normalizeOptions(
compiler: options.compiler ?? 'babel',
bundler: options.bundler ?? 'webpack',
projectName: appProjectName,
strict: options.strict ?? true,
appProjectRoot,
e2eProjectRoot,
e2eProjectName,
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export interface Schema {
linter?: Linter;
standaloneConfig?: boolean;
setParserOptionsProject?: boolean;
strict?: boolean;
addPlugin?: boolean;
}
5 changes: 5 additions & 0 deletions packages/web/src/generators/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
"default": false
},
"strict": {
"type": "boolean",
"description": "Creates an application with strict mode and strict type checking.",
"default": true
},
"standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside workspace.json",
"type": "boolean",
Expand Down

0 comments on commit eef3603

Please sign in to comment.