File tree Expand file tree Collapse file tree 2 files changed +50
-3
lines changed
packages/nx/src/project-graph/affected/locators Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -266,6 +266,45 @@ describe('getTouchedNpmPackages', () => {
266
266
'npm:awesome-nrwl' ,
267
267
] ) ;
268
268
} ) ;
269
+
270
+ it ( 'should handle and workspace packages when defined in dependencies' , ( ) => {
271
+ const result = getTouchedNpmPackages (
272
+ [
273
+ {
274
+ file : 'package.json' ,
275
+ hash : 'some-hash' ,
276
+ getChanges : ( ) => [
277
+ {
278
+ type : 'JsonPropertyAdded' ,
279
+ path : [ 'devDependencies' , 'changed-test-pkg-name-1' ] ,
280
+ value : { rhs : 'workspace:*' } ,
281
+ } ,
282
+ ] ,
283
+ } ,
284
+ ] ,
285
+ workspaceJson ,
286
+ nxJson ,
287
+ {
288
+ dependencies : {
289
+ 'happy-nrwl' : '0.0.1' ,
290
+ 'awesome-nrwl' : '0.0.1' ,
291
+ } ,
292
+ } ,
293
+ {
294
+ ...projectGraph ,
295
+ nodes : {
296
+ ...projectGraph . nodes ,
297
+ 'any-random-name' : {
298
+ name : 'changed-test-pkg-name-1' ,
299
+ type : 'lib' ,
300
+ data : { } ,
301
+ } ,
302
+ } ,
303
+ }
304
+ ) ;
305
+ expect ( result ) . toEqual ( [ 'changed-test-pkg-name-1' ] ) ;
306
+ } ) ;
307
+
269
308
it ( 'should handle and log workspace package.json changes when the changes are not in `npmPackages` (projectGraph.externalNodes)' , ( ) => {
270
309
jest . spyOn ( logger , 'warn' ) ;
271
310
expect ( ( ) => {
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ import {
6
6
} from '../../../utils/json-diff' ;
7
7
import { logger } from '../../../utils/logger' ;
8
8
import { TouchedProjectLocator } from '../affected-project-graph-models' ;
9
+ import {
10
+ ProjectGraphExternalNode ,
11
+ ProjectGraphProjectNode ,
12
+ } from 'nx/src/config/project-graph' ;
9
13
10
14
export const getTouchedNpmPackages : TouchedProjectLocator <
11
15
WholeFileChange | JsonChange
@@ -31,9 +35,13 @@ export const getTouchedNpmPackages: TouchedProjectLocator<
31
35
touched = Object . keys ( projectGraph . nodes ) ;
32
36
break ;
33
37
} else {
34
- const npmPackage = npmPackages . find (
35
- ( pkg ) => pkg . data . packageName === c . path [ 1 ]
36
- ) ;
38
+ let npmPackage : ProjectGraphProjectNode | ProjectGraphExternalNode =
39
+ npmPackages . find ( ( pkg ) => pkg . data . packageName === c . path [ 1 ] ) ;
40
+ if ( ! npmPackage ) {
41
+ // dependency can also point to a workspace project
42
+ const nodes = Object . values ( projectGraph . nodes ) ;
43
+ npmPackage = nodes . find ( ( n ) => n . name === c . path [ 1 ] ) ;
44
+ }
37
45
if ( ! npmPackage ) {
38
46
missingTouchedNpmPackages . push ( c . path [ 1 ] ) ;
39
47
continue ;
You can’t perform that action at this time.
0 commit comments