Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(angular): fix root-project support for Angular (#13534)
- Loading branch information
Showing
12 changed files
with
222 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 34 additions & 16 deletions
50
packages/angular/src/generators/add-linting/add-linting.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,51 @@ | ||
import type { GeneratorCallback, Tree } from '@nrwl/devkit'; | ||
import { formatFiles } from '@nrwl/devkit'; | ||
import { Linter, lintInitGenerator } from '@nrwl/linter'; | ||
import { | ||
GeneratorCallback, | ||
joinPathFragments, | ||
Tree, | ||
updateJson, | ||
} from '@nrwl/devkit'; | ||
import { Linter, lintProjectGenerator } from '@nrwl/linter'; | ||
import { mapLintPattern } from '@nrwl/linter/src/generators/lint-project/lint-project'; | ||
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial'; | ||
import { addAngularEsLintDependencies } from './lib/add-angular-eslint-dependencies'; | ||
import { addProjectLintTarget } from './lib/add-project-lint-target'; | ||
import { createEsLintConfiguration } from './lib/create-eslint-configuration'; | ||
import { extendAngularEslintJson } from './lib/create-eslint-configuration'; | ||
import type { AddLintingGeneratorSchema } from './schema'; | ||
|
||
export async function addLintingGenerator( | ||
tree: Tree, | ||
options: AddLintingGeneratorSchema | ||
): Promise<GeneratorCallback> { | ||
const installTask = lintInitGenerator(tree, { | ||
const tasks: GeneratorCallback[] = []; | ||
const rootProject = options.projectRoot === '.' || options.projectRoot === ''; | ||
const lintTask = await lintProjectGenerator(tree, { | ||
linter: Linter.EsLint, | ||
project: options.projectName, | ||
tsConfigPaths: [ | ||
joinPathFragments(options.projectRoot, 'tsconfig.app.json'), | ||
], | ||
unitTestRunner: options.unitTestRunner, | ||
skipPackageJson: options.skipPackageJson, | ||
eslintFilePatterns: [ | ||
mapLintPattern(options.projectRoot, 'ts', rootProject), | ||
mapLintPattern(options.projectRoot, 'html', rootProject), | ||
], | ||
setParserOptionsProject: options.setParserOptionsProject, | ||
skipFormat: true, | ||
rootProject: rootProject, | ||
}); | ||
tasks.push(lintTask); | ||
|
||
if (!options.skipPackageJson) { | ||
addAngularEsLintDependencies(tree); | ||
} | ||
updateJson( | ||
tree, | ||
joinPathFragments(options.projectRoot, '.eslintrc.json'), | ||
(json) => extendAngularEslintJson(json, options) | ||
); | ||
|
||
createEsLintConfiguration(tree, options); | ||
addProjectLintTarget(tree, options); | ||
|
||
if (!options.skipFormat) { | ||
await formatFiles(tree); | ||
if (!options.skipPackageJson) { | ||
const installTask = await addAngularEsLintDependencies(tree); | ||
tasks.push(installTask); | ||
} | ||
|
||
return installTask; | ||
return runTasksInSerial(...tasks); | ||
} | ||
|
||
export default addLintingGenerator; |
6 changes: 3 additions & 3 deletions
6
packages/angular/src/generators/add-linting/lib/add-angular-eslint-dependencies.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/angular/src/generators/add-linting/lib/create-eslint-configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.