From f3fc658c7d9e02e4c4648acb2a639b5b0bded655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Fri, 30 Jun 2023 22:00:45 +0200 Subject: [PATCH] fix(linter): create-package-json should omit non-npm and ignored packages (#17883) (cherry picked from commit 3d77b4d40e743c65106c59c45e09c2631657c1d3) --- .../eslint-plugin/src/rules/dependency-checks.ts | 2 +- .../plugins/js/package-json/create-package-json.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/dependency-checks.ts b/packages/eslint-plugin/src/rules/dependency-checks.ts index 937f63e24c29d..84d6f38d55350 100644 --- a/packages/eslint-plugin/src/rules/dependency-checks.ts +++ b/packages/eslint-plugin/src/rules/dependency-checks.ts @@ -45,7 +45,7 @@ export default createESLintRule({ type: 'object', properties: { buildTargets: [{ type: 'string' }], - ignoreDependencies: [{ type: 'string' }], + ignoredDependencies: [{ type: 'string' }], checkMissingDependencies: { type: 'boolean' }, checkObsoleteDependencies: { type: 'boolean' }, checkVersionMismatches: { type: 'boolean' }, diff --git a/packages/nx/src/plugins/js/package-json/create-package-json.ts b/packages/nx/src/plugins/js/package-json/create-package-json.ts index 7d844b4ef63ff..c84ad7ea027a5 100644 --- a/packages/nx/src/plugins/js/package-json/create-package-json.ts +++ b/packages/nx/src/plugins/js/package-json/create-package-json.ts @@ -181,6 +181,7 @@ export function findProjectsNpmDependencies( target: string, options: { helperDependencies?: string[]; + ignoredDependencies?: string[]; }, fileMap?: ProjectFileMap ): NpmDeps { @@ -213,6 +214,7 @@ export function findProjectsNpmDependencies( graph, npmDeps, seen, + options.ignoredDependencies || [], dependencyInputs, selfInputs ); @@ -226,6 +228,7 @@ function findAllNpmDeps( graph: ProjectGraph, npmDeps: NpmDeps, seen: Set, + ignoredDependencies: string[], dependencyPatterns: string[], rootPatterns?: string[] ): void { @@ -260,6 +263,14 @@ function findAllNpmDeps( } else { if (node) { seen.add(dep); + // do not add ignored dependencies to the list or non-npm dependencies + if ( + ignoredDependencies.includes(node.data.packageName) || + node.type !== 'npm' + ) { + continue; + } + npmDeps.dependencies[node.data.packageName] = node.data.version; recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen); } else if (graph.nodes[dep]) { @@ -269,6 +280,7 @@ function findAllNpmDeps( graph, npmDeps, seen, + ignoredDependencies, dependencyPatterns ); }