Skip to content

Commit

Permalink
fix(core): ignore dependencies from non-index root files for create-p…
Browse files Browse the repository at this point in the history
…ackage-json
  • Loading branch information
meeroslav committed Jul 3, 2023
1 parent 50d01d1 commit d399c2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
Expand Down
14 changes: 13 additions & 1 deletion packages/nx/src/plugins/js/package-json/create-package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
Expand Down Expand Up @@ -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,
Expand All @@ -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<string>();

Expand Down

0 comments on commit d399c2c

Please sign in to comment.