Skip to content

Commit

Permalink
fix(angular): install jsonc-eslint-parser only when @nx/dependency-ch…
Browse files Browse the repository at this point in the history
…ecks is used
  • Loading branch information
leosvelperez committed Mar 8, 2024
1 parent 97cc714 commit 985ba75
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 35 deletions.
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
);
}

0 comments on commit 985ba75

Please sign in to comment.