Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(angular): install jsonc-eslint-parser only when @nx/dependency-checks is used #22231

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions packages/angular/src/generators/add-linting/add-linting.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {
formatFiles,
GeneratorCallback,
joinPathFragments,
readProjectConfiguration,
runTasksInSerial,
Tree,
type GeneratorCallback,
type Tree,
} from '@nx/devkit';
import { camelize, dasherize } from '@nx/devkit/src/utils/string-utils';
import { Linter, lintProjectGenerator } from '@nx/eslint';
import { addAngularEsLintDependencies } from './lib/add-angular-eslint-dependencies';
import type { AddLintingGeneratorSchema } from './schema';
import {
javaScriptOverride,
typeScriptOverride,
} from '@nx/eslint/src/generators/init/global-eslint-config';
import {
findEslintFile,
isEslintConfigSupported,
replaceOverridesInLintConfig,
} from '@nx/eslint/src/generators/utils/eslint-file';
import { camelize, dasherize } from '@nx/devkit/src/utils/string-utils';
import {
javaScriptOverride,
typeScriptOverride,
} from '@nx/eslint/src/generators/init/global-eslint-config';
import { addAngularEsLintDependencies } from './lib/add-angular-eslint-dependencies';
import { isBuildableLibraryProject } from './lib/buildable-project';
import type { AddLintingGeneratorSchema } from './schema';

export async function addLintingGenerator(
tree: Tree,
Expand Down Expand Up @@ -106,7 +106,7 @@ export async function addLintingGenerator(
}

if (!options.skipPackageJson) {
const installTask = addAngularEsLintDependencies(tree);
const installTask = addAngularEsLintDependencies(tree, options.projectName);
tasks.push(installTask);
}

Expand All @@ -117,13 +117,4 @@ export async function addLintingGenerator(
return runTasksInSerial(...tasks);
}

function isBuildableLibraryProject(tree: Tree, projectName: string): boolean {
const projectConfig = readProjectConfiguration(tree, projectName);
return (
projectConfig.projectType === 'library' &&
projectConfig.targets?.build &&
!!projectConfig.targets.build
);
}

export default addLintingGenerator;
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import type { GeneratorCallback, Tree } from '@nx/devkit';
import { addDependenciesToPackageJson } from '@nx/devkit';
import {
addDependenciesToPackageJson,
type GeneratorCallback,
type Tree,
} from '@nx/devkit';
import { versions } from '../../utils/version-utils';
import { isBuildableLibraryProject } from './buildable-project';

export function addAngularEsLintDependencies(tree: Tree): GeneratorCallback {
export function addAngularEsLintDependencies(
tree: Tree,
projectName: string
): GeneratorCallback {
const angularEslintVersionToInstall = versions(tree).angularEslintVersion;
const jsoncEslintParserVersionToInstall =
versions(tree).jsoncEslintParserVersion;
return addDependenciesToPackageJson(
tree,
{},
{
'@angular-eslint/eslint-plugin': angularEslintVersionToInstall,
'@angular-eslint/eslint-plugin-template': angularEslintVersionToInstall,
'@angular-eslint/template-parser': angularEslintVersionToInstall,
'jsonc-eslint-parser': jsoncEslintParserVersionToInstall,
}
);
const devDependencies = {
'@angular-eslint/eslint-plugin': angularEslintVersionToInstall,
'@angular-eslint/eslint-plugin-template': angularEslintVersionToInstall,
'@angular-eslint/template-parser': angularEslintVersionToInstall,
};

if (isBuildableLibraryProject(tree, projectName)) {
const jsoncEslintParserVersionToInstall =
versions(tree).jsoncEslintParserVersion;
devDependencies['jsonc-eslint-parser'] = jsoncEslintParserVersionToInstall;
}

return addDependenciesToPackageJson(tree, {}, devDependencies);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { readProjectConfiguration, type Tree } from '@nx/devkit';

export function isBuildableLibraryProject(
tree: Tree,
projectName: string
): boolean {
const projectConfig = readProjectConfiguration(tree, projectName);

return (
projectConfig.projectType === 'library' && !!projectConfig.targets?.build
leosvelperez marked this conversation as resolved.
Show resolved Hide resolved
);
}