1- import { workspaceRoot } from '@nx/devkit' ;
1+ import {
2+ ProjectGraph ,
3+ ProjectsConfigurations ,
4+ workspaceRoot ,
5+ } from '@nx/devkit' ;
26import { join } from 'path' ;
37import { qwikNxVite } from './qwik-nx-vite.plugin' ;
48import { QwikNxVitePluginOptions } from './models/qwik-nx-vite' ;
59
610// 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 ' ) ;
812// eslint-disable-next-line @typescript-eslint/no-var-requires
913const fs = require ( 'fs' ) ;
1014// eslint-disable-next-line @typescript-eslint/no-var-requires
1115const getProjectDependenciesModule = require ( './utils/get-project-dependencies' ) ;
1216
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 > {
1465 return {
1566 projects : {
1667 'tmp-test-app-a' : {
1768 root : 'apps/test-app-a' ,
1869 name : 'tmp-test-app-a' ,
1970 projectType : 'application' ,
2071 sourceRoot : 'apps/test-app-a/src' ,
21- prefix : 'tmp' ,
2272 tags : [ 'tag1' , 'tag2' ] ,
2373 } ,
2474 'tmp-test-lib-a' : {
2575 root : 'libs/test-lib-a' ,
2676 name : 'tmp-test-lib-a' ,
2777 projectType : 'library' ,
2878 sourceRoot : 'libs/test-lib-a/src' ,
29- prefix : 'tmp' ,
3079 tags : [ 'tag2' ] ,
3180 } ,
3281 'tmp-test-lib-b' : {
3382 root : 'libs/test-lib-b' ,
3483 name : 'tmp-test-lib-b' ,
3584 projectType : 'library' ,
3685 sourceRoot : 'libs/test-lib-b/src' ,
37- prefix : 'tmp' ,
3886 tags : [ 'tag2' , 'tag3' ] ,
3987 } ,
4088 'tmp-test-lib-c-nested-1' : {
4189 root : 'libs/test-lib-c/nested' ,
4290 name : 'tmp-test-lib-c-nested-1' ,
4391 projectType : 'library' ,
4492 sourceRoot : 'libs/test-lib-c/nested-1/src' ,
45- prefix : 'tmp' ,
4693 tags : [ 'tag4' ] ,
4794 } ,
4895 'tmp-test-lib-c-nested-2' : {
4996 root : 'libs/test-lib-c/nested' ,
5097 name : 'tmp-test-lib-c-nested-2' ,
5198 projectType : 'library' ,
5299 sourceRoot : 'libs/test-lib-c/nested-2/src' ,
53- prefix : 'tmp' ,
54100 tags : [ 'tag1' , 'tag2' , 'tag3' ] ,
55101 } ,
56102 'tmp-other-test-lib-a' : {
57103 root : 'libs/other/test-lib-a' ,
58104 name : 'tmp-other-test-lib-a' ,
59105 projectType : 'library' ,
60106 sourceRoot : 'libs/other/test-lib-a/src' ,
61- prefix : 'tmp' ,
62107 tags : [ ] ,
63108 } ,
64109 // it will be excluded because it is not set in our mock tsconfig.json
@@ -67,7 +112,6 @@ function getWorkspaceConfig() {
67112 name : 'tmp-always-excluded' ,
68113 projectType : 'library' ,
69114 sourceRoot : 'libs/always/excluded/src' ,
70- prefix : 'tmp' ,
71115 tags : [ ] ,
72116 } ,
73117 } ,
@@ -90,8 +134,11 @@ function getTsConfigString() {
90134
91135describe ( 'qwik-nx-vite plugin' , ( ) => {
92136 jest
93- . spyOn ( fileUtils , 'readWorkspaceConfig ' )
137+ . spyOn ( nxDevkit , 'readProjectsConfigurationFromProjectGraph ' )
94138 . mockReturnValue ( getWorkspaceConfig ( ) ) ;
139+ jest
140+ . spyOn ( nxDevkit , 'readCachedProjectGraph' )
141+ . mockReturnValue ( getProjectsGraph ( ) ) ;
95142 const originalReadFileSync = jest . requireActual ( 'fs' ) . readFileSync ;
96143 jest . spyOn ( fs , 'readFileSync' ) . mockImplementation ( ( fileName , ...args ) => {
97144 if (
@@ -105,7 +152,7 @@ describe('qwik-nx-vite plugin', () => {
105152 jest
106153 . spyOn ( getProjectDependenciesModule , 'getProjectDependencies' )
107154 . mockReturnValue (
108- Promise . resolve ( new Set ( Object . keys ( getWorkspaceConfig ( ) . projects ) ) )
155+ Promise . resolve ( new Set ( Object . keys ( getWorkspaceConfig ( ) . projects ! ) ) )
109156 ) ;
110157
111158 /**
0 commit comments