diff --git a/packages/js/src/utils/package-json/update-package-json.spec.ts b/packages/js/src/utils/package-json/update-package-json.spec.ts index c627c25889fd9..0a8f44ca810dd 100644 --- a/packages/js/src/utils/package-json/update-package-json.spec.ts +++ b/packages/js/src/utils/package-json/update-package-json.spec.ts @@ -290,7 +290,7 @@ describe('updatePackageJson', () => { const fileMap = { '@org/lib1': [ { - file: 'test.ts', + file: 'libs/lib1/src/test.ts', hash: '', deps: ['npm:external1', 'npm:external2'], }, 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 c84ad7ea027a5..bdf376be4eb5d 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 @@ -16,6 +16,7 @@ import { import { readNxJson } from '../../../config/configuration'; import { readProjectFileMapCache } from '../../../project-graph/nx-deps-cache'; import { join } from 'path'; +import { file } from 'tmp'; interface NpmDeps { readonly dependencies: Record; @@ -222,6 +223,17 @@ export function findProjectsNpmDependencies( return npmDeps; } +// this function checks if the file path in in the root and not index.ts file +// these files are likely configuration files +function isIndexOrNonRoot(filePath: string, root: string): boolean { + if (filePath.slice(root.length + 1).includes('/')) { + return true; + } + return ['index.ts', 'index.js', 'index.jsx', 'index.tsx'].some( + (f) => `${root}/${f}` === filePath + ); +} + function findAllNpmDeps( projectFileMap: ProjectFileMap, projectNode: ProjectGraphProjectNode, @@ -240,7 +252,7 @@ function findAllNpmDeps( projectNode.data.root, projectFileMap[projectNode.name] || [], rootPatterns ?? dependencyPatterns - ); + ).filter((f) => isIndexOrNonRoot(f.file, projectNode.data.root)); const projectDependencies = new Set();