1
- import { workspaceRoot } from '@nx/devkit' ;
1
+ import {
2
+ ProjectGraph ,
3
+ ProjectsConfigurations ,
4
+ workspaceRoot ,
5
+ } from '@nx/devkit' ;
2
6
import { join } from 'path' ;
3
7
import { qwikNxVite } from './qwik-nx-vite.plugin' ;
4
8
import { QwikNxVitePluginOptions } from './models/qwik-nx-vite' ;
5
9
6
10
// eslint-disable-next-line @typescript-eslint/no-var-requires
7
- const fileUtils = require ( 'nx/src/project-graph/file-utils ' ) ;
11
+ const nxDevkit = require ( '@ nx/devkit ' ) ;
8
12
// eslint-disable-next-line @typescript-eslint/no-var-requires
9
13
const fs = require ( 'fs' ) ;
10
14
// eslint-disable-next-line @typescript-eslint/no-var-requires
11
15
const getProjectDependenciesModule = require ( './utils/get-project-dependencies' ) ;
12
16
13
- function getWorkspaceConfig ( ) {
17
+ function getProjectsGraph ( ) : Partial < ProjectGraph > {
18
+ return {
19
+ nodes : {
20
+ 'tmp-test-app-a' : {
21
+ name : 'tmp-test-app-a' ,
22
+ type : 'app' ,
23
+ data : {
24
+ root : 'apps/test-app-a' ,
25
+ sourceRoot : 'apps/test-app-a/src' ,
26
+ projectType : 'application' ,
27
+ tags : [ 'tag1' , 'tag2' ] ,
28
+ } ,
29
+ } ,
30
+ 'tmp-test-lib-a' : {
31
+ name : 'tmp-test-lib-a' ,
32
+ type : 'lib' ,
33
+ data : {
34
+ root : 'libs/test-lib-a' ,
35
+ sourceRoot : 'libs/test-lib-a/src' ,
36
+ projectType : 'library' ,
37
+ tags : [ 'tag2' ] ,
38
+ } ,
39
+ } ,
40
+ 'tmp-test-lib-b' : {
41
+ name : 'tmp-test-lib-b' ,
42
+ type : 'lib' ,
43
+ data : {
44
+ root : 'libs/test-lib-b' ,
45
+ sourceRoot : 'libs/test-lib-b/src' ,
46
+ projectType : 'library' ,
47
+ tags : [ 'tag2' , 'tag3' ] ,
48
+ } ,
49
+ } ,
50
+ 'tmp-test-lib-c-nested-1' : {
51
+ name : 'tmp-test-lib-c-nested-1' ,
52
+ type : 'lib' ,
53
+ data : {
54
+ root : 'libs/test-lib-c/nested' ,
55
+ sourceRoot : 'libs/test-lib-c/nested-1/src' ,
56
+ projectType : 'library' ,
57
+ tags : [ 'tag4' ] ,
58
+ } ,
59
+ } ,
60
+ } ,
61
+ } ;
62
+ }
63
+
64
+ function getWorkspaceConfig ( ) : Partial < ProjectsConfigurations > {
14
65
return {
15
66
projects : {
16
67
'tmp-test-app-a' : {
17
68
root : 'apps/test-app-a' ,
18
69
name : 'tmp-test-app-a' ,
19
70
projectType : 'application' ,
20
71
sourceRoot : 'apps/test-app-a/src' ,
21
- prefix : 'tmp' ,
22
72
tags : [ 'tag1' , 'tag2' ] ,
23
73
} ,
24
74
'tmp-test-lib-a' : {
25
75
root : 'libs/test-lib-a' ,
26
76
name : 'tmp-test-lib-a' ,
27
77
projectType : 'library' ,
28
78
sourceRoot : 'libs/test-lib-a/src' ,
29
- prefix : 'tmp' ,
30
79
tags : [ 'tag2' ] ,
31
80
} ,
32
81
'tmp-test-lib-b' : {
33
82
root : 'libs/test-lib-b' ,
34
83
name : 'tmp-test-lib-b' ,
35
84
projectType : 'library' ,
36
85
sourceRoot : 'libs/test-lib-b/src' ,
37
- prefix : 'tmp' ,
38
86
tags : [ 'tag2' , 'tag3' ] ,
39
87
} ,
40
88
'tmp-test-lib-c-nested-1' : {
41
89
root : 'libs/test-lib-c/nested' ,
42
90
name : 'tmp-test-lib-c-nested-1' ,
43
91
projectType : 'library' ,
44
92
sourceRoot : 'libs/test-lib-c/nested-1/src' ,
45
- prefix : 'tmp' ,
46
93
tags : [ 'tag4' ] ,
47
94
} ,
48
95
'tmp-test-lib-c-nested-2' : {
49
96
root : 'libs/test-lib-c/nested' ,
50
97
name : 'tmp-test-lib-c-nested-2' ,
51
98
projectType : 'library' ,
52
99
sourceRoot : 'libs/test-lib-c/nested-2/src' ,
53
- prefix : 'tmp' ,
54
100
tags : [ 'tag1' , 'tag2' , 'tag3' ] ,
55
101
} ,
56
102
'tmp-other-test-lib-a' : {
57
103
root : 'libs/other/test-lib-a' ,
58
104
name : 'tmp-other-test-lib-a' ,
59
105
projectType : 'library' ,
60
106
sourceRoot : 'libs/other/test-lib-a/src' ,
61
- prefix : 'tmp' ,
62
107
tags : [ ] ,
63
108
} ,
64
109
// it will be excluded because it is not set in our mock tsconfig.json
@@ -67,7 +112,6 @@ function getWorkspaceConfig() {
67
112
name : 'tmp-always-excluded' ,
68
113
projectType : 'library' ,
69
114
sourceRoot : 'libs/always/excluded/src' ,
70
- prefix : 'tmp' ,
71
115
tags : [ ] ,
72
116
} ,
73
117
} ,
@@ -90,8 +134,11 @@ function getTsConfigString() {
90
134
91
135
describe ( 'qwik-nx-vite plugin' , ( ) => {
92
136
jest
93
- . spyOn ( fileUtils , 'readWorkspaceConfig ' )
137
+ . spyOn ( nxDevkit , 'readProjectsConfigurationFromProjectGraph ' )
94
138
. mockReturnValue ( getWorkspaceConfig ( ) ) ;
139
+ jest
140
+ . spyOn ( nxDevkit , 'readCachedProjectGraph' )
141
+ . mockReturnValue ( getProjectsGraph ( ) ) ;
95
142
const originalReadFileSync = jest . requireActual ( 'fs' ) . readFileSync ;
96
143
jest . spyOn ( fs , 'readFileSync' ) . mockImplementation ( ( fileName , ...args ) => {
97
144
if (
@@ -105,7 +152,7 @@ describe('qwik-nx-vite plugin', () => {
105
152
jest
106
153
. spyOn ( getProjectDependenciesModule , 'getProjectDependencies' )
107
154
. mockReturnValue (
108
- Promise . resolve ( new Set ( Object . keys ( getWorkspaceConfig ( ) . projects ) ) )
155
+ Promise . resolve ( new Set ( Object . keys ( getWorkspaceConfig ( ) . projects ! ) ) )
109
156
) ;
110
157
111
158
/**
0 commit comments