diff --git a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.ts b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.ts index 4485305db2bfd7..2dcd4c5ca5e40d 100644 --- a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.ts +++ b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.ts @@ -1,15 +1,15 @@ -import { defaultFileRead } from '../../../../project-graph/file-utils'; import { join } from 'path'; import { DependencyType, ProjectFileMap, ProjectGraph, } from '../../../../config/project-graph'; -import { parseJson } from '../../../../utils/json'; import { getImportPath, joinPathFragments } from '../../../../utils/path'; import { ProjectsConfigurations } from '../../../../config/workspace-json-project-json'; import { NxJsonConfiguration } from '../../../../config/nx-json'; import { ExplicitDependency } from './explicit-project-dependencies'; +import { PackageJson } from '../../../../utils/package-json'; +import { readJsonFile } from '../../../../utils/fileutils'; class ProjectGraphNodeRecords {} @@ -47,13 +47,8 @@ function createPackageNameMap( const res = {}; for (let projectName of Object.keys(projectsConfigurations.projects)) { try { - const packageJson = parseJson( - defaultFileRead( - join( - projectsConfigurations.projects[projectName].root, - 'package.json' - ) - ) + const packageJson = readJsonFile( + join(projectsConfigurations.projects[projectName].root, 'package.json') ); res[ packageJson.name ?? @@ -83,7 +78,7 @@ function processPackageJson( packageNameMap: { [packageName: string]: string } ) { try { - const deps = readDeps(parseJson(defaultFileRead(fileName))); + const deps = readJsonFile(fileName); // the name matches the import path deps.forEach((d) => { // package.json refers to another project in the monorepo @@ -110,10 +105,11 @@ function processPackageJson( } } -function readDeps(packageJsonDeps: any) { +function readDeps(packageJson: PackageJson) { return [ - ...Object.keys(packageJsonDeps?.dependencies ?? {}), - ...Object.keys(packageJsonDeps?.devDependencies ?? {}), - ...Object.keys(packageJsonDeps?.peerDependencies ?? {}), + ...Object.keys(packageJson?.dependencies ?? {}), + ...Object.keys(packageJson?.devDependencies ?? {}), + ...Object.keys(packageJson?.peerDependencies ?? {}), + ...Object.keys(packageJson?.optionalDependencies ?? {}), ]; }