-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): mark all projects as affected when npm package is deleted (#…
- Loading branch information
Showing
2 changed files
with
47 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 23 additions & 16 deletions
39
packages/workspace/src/core/affected-project-graph/locators/npm-packages.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
import { isWholeFileChange, WholeFileChange } from '../../file-utils'; | ||
import { isJsonChange, JsonChange } from '../../../utils/json-diff'; | ||
import { DiffType, isJsonChange, JsonChange } from '../../../utils/json-diff'; | ||
import { TouchedProjectLocator } from '../affected-project-graph-models'; | ||
|
||
export const getTouchedNpmPackages: TouchedProjectLocator< | ||
WholeFileChange | JsonChange | ||
> = (touchedFiles, workspaceJson, nxJson, packageJson): string[] => { | ||
const packageJsonChange = touchedFiles.find(f => f.file === 'package.json'); | ||
const touched = []; | ||
if (packageJsonChange) { | ||
const changes = packageJsonChange.getChanges(); | ||
changes.forEach(c => { | ||
if ( | ||
isJsonChange(c) && | ||
(c.path[0] === 'dependencies' || c.path[0] === 'devDependencies') && | ||
c.value.rhs // If rhs is blank then dep was deleted and does not exist in project graph | ||
) { | ||
touched.push(c.path[1]); | ||
} else if (isWholeFileChange(c)) { | ||
Object.keys({ | ||
if (!packageJsonChange) return []; | ||
|
||
let touched = []; | ||
const changes = packageJsonChange.getChanges(); | ||
|
||
for (const c of changes) { | ||
if ( | ||
isJsonChange(c) && | ||
(c.path[0] === 'dependencies' || c.path[0] === 'devDependencies') | ||
) { | ||
// A package was deleted so mark all packages as touched | ||
// so projects with any package dependency will be affected. | ||
if (c.type === DiffType.Deleted) { | ||
touched = Object.keys({ | ||
...(packageJson.dependencies || {}), | ||
...(packageJson.devDependencies || {}) | ||
}).forEach(p => { | ||
touched.push(p); | ||
}); | ||
break; | ||
} else { | ||
touched.push(c.path[1]); | ||
} | ||
}); | ||
} else if (isWholeFileChange(c)) { | ||
touched = Object.keys(workspaceJson.projects); | ||
break; | ||
} | ||
} | ||
|
||
return touched; | ||
}; |