From 05740d184906801df50de08cb08c6028124c9d93 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Fri, 30 Jun 2023 13:35:39 +0200 Subject: [PATCH] fix(linter): create-package-json should omit non-npm and ignored packages --- .../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 ); }