1
1
import { detectPackageManager , type CreateNodesContext } from '@nx/devkit' ;
2
2
import { TempFs } from '@nx/devkit/internal-testing-utils' ;
3
3
import { minimatch } from 'minimatch' ;
4
+ import { mkdirSync , rmdirSync } from 'node:fs' ;
4
5
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
5
6
import { getLockFileName } from 'nx/src/plugins/js/lock-file/lock-file' ;
6
7
import { setupWorkspaceContext } from 'nx/src/utils/workspace-context' ;
7
8
import { PLUGIN_NAME , createNodesV2 , type TscPluginOptions } from './plugin' ;
8
9
10
+ jest . mock ( 'nx/src/utils/cache-directory' , ( ) => ( {
11
+ ...jest . requireActual ( 'nx/src/utils/cache-directory' ) ,
12
+ workspaceDataDirectory : 'tmp/project-graph-cache' ,
13
+ } ) ) ;
14
+
9
15
describe ( `Plugin: ${ PLUGIN_NAME } ` , ( ) => {
10
16
let context : CreateNodesContext ;
11
17
let cwd = process . cwd ( ) ;
12
18
let tempFs : TempFs ;
13
19
let originalCacheProjectGraph : string | undefined ;
14
20
15
21
beforeEach ( ( ) => {
22
+ mkdirSync ( 'tmp/project-graph-cache' , { recursive : true } ) ;
16
23
tempFs = new TempFs ( 'typescript-plugin' ) ;
17
24
context = {
18
25
nxJsonConfiguration : {
@@ -38,6 +45,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
38
45
tempFs . cleanup ( ) ;
39
46
process . chdir ( cwd ) ;
40
47
process . env . NX_CACHE_PROJECT_GRAPH = originalCacheProjectGraph ;
48
+ rmdirSync ( 'tmp/project-graph-cache' , { recursive : true } ) ;
41
49
} ) ;
42
50
43
51
it ( 'should not create nodes for root tsconfig.json files' , async ( ) => {
@@ -59,7 +67,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
59
67
it ( 'should create a node with a typecheck target for a project level tsconfig.json file by default (when there is a sibling package.json or project.json)' , async ( ) => {
60
68
// Sibling package.json
61
69
await applyFilesToTempFsAndContext ( tempFs , context , {
62
- 'libs/my-lib/tsconfig.json' : `{}` ,
70
+ 'libs/my-lib/tsconfig.json' : JSON . stringify ( { files : [ ] } ) ,
63
71
'libs/my-lib/package.json' : `{}` ,
64
72
} ) ;
65
73
expect ( await invokeCreateNodesOnMatchingFiles ( context , { } ) )
@@ -114,7 +122,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
114
122
115
123
// Sibling project.json
116
124
await applyFilesToTempFsAndContext ( tempFs , context , {
117
- 'libs/my-lib/tsconfig.json' : `{}` ,
125
+ 'libs/my-lib/tsconfig.json' : JSON . stringify ( { files : [ ] } ) ,
118
126
'libs/my-lib/project.json' : `{}` ,
119
127
} ) ;
120
128
expect ( await invokeCreateNodesOnMatchingFiles ( context , { } ) )
@@ -169,7 +177,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
169
177
170
178
// Other tsconfigs present
171
179
await applyFilesToTempFsAndContext ( tempFs , context , {
172
- 'libs/my-lib/tsconfig.json' : `{}` ,
180
+ 'libs/my-lib/tsconfig.json' : JSON . stringify ( { files : [ ] } ) ,
173
181
'libs/my-lib/tsconfig.lib.json' : `{}` ,
174
182
'libs/my-lib/tsconfig.build.json' : `{}` ,
175
183
'libs/my-lib/tsconfig.spec.json' : `{}` ,
@@ -229,7 +237,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
229
237
it ( 'should create a node with a typecheck target with "--verbose" flag when the "verboseOutput" plugin option is true' , async ( ) => {
230
238
// Sibling package.json
231
239
await applyFilesToTempFsAndContext ( tempFs , context , {
232
- 'libs/my-lib/tsconfig.json' : `{}` ,
240
+ 'libs/my-lib/tsconfig.json' : JSON . stringify ( { files : [ ] } ) ,
233
241
'libs/my-lib/package.json' : `{}` ,
234
242
} ) ;
235
243
expect (
@@ -285,7 +293,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
285
293
286
294
// Sibling project.json
287
295
await applyFilesToTempFsAndContext ( tempFs , context , {
288
- 'libs/my-lib/tsconfig.json' : `{}` ,
296
+ 'libs/my-lib/tsconfig.json' : JSON . stringify ( { files : [ ] } ) ,
289
297
'libs/my-lib/project.json' : `{}` ,
290
298
} ) ;
291
299
expect (
@@ -341,7 +349,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
341
349
342
350
// Other tsconfigs present
343
351
await applyFilesToTempFsAndContext ( tempFs , context , {
344
- 'libs/my-lib/tsconfig.json' : `{}` ,
352
+ 'libs/my-lib/tsconfig.json' : JSON . stringify ( { files : [ ] } ) ,
345
353
'libs/my-lib/tsconfig.lib.json' : `{}` ,
346
354
'libs/my-lib/tsconfig.build.json' : `{}` ,
347
355
'libs/my-lib/tsconfig.spec.json' : `{}` ,
@@ -446,6 +454,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
446
454
await applyFilesToTempFsAndContext ( tempFs , context , {
447
455
'libs/my-lib/tsconfig.json' : JSON . stringify ( {
448
456
compilerOptions : { noEmit : true } ,
457
+ files : [ ] ,
449
458
} ) ,
450
459
'libs/my-lib/package.json' : `{}` ,
451
460
} ) ;
@@ -506,6 +515,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
506
515
} ) ,
507
516
'libs/my-lib/tsconfig.json' : JSON . stringify ( {
508
517
extends : '../../tsconfig.base.json' ,
518
+ files : [ ] ,
509
519
} ) ,
510
520
'libs/my-lib/package.json' : `{}` ,
511
521
} ) ;
@@ -568,6 +578,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
568
578
} ) ,
569
579
'libs/my-lib/tsconfig.lib.json' : JSON . stringify ( {
570
580
compilerOptions : { noEmit : true } ,
581
+ files : [ ] ,
571
582
} ) ,
572
583
'libs/my-lib/package.json' : `{}` ,
573
584
} ) ;
@@ -641,6 +652,8 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
641
652
'libs/my-lib/tsconfig.json' : JSON . stringify ( {
642
653
include : [ 'src/**/*.ts' ] ,
643
654
exclude : [ 'src/**/foo.ts' ] ,
655
+ // set this to keep outputs smaller
656
+ compilerOptions : { outDir : 'dist' } ,
644
657
} ) ,
645
658
'libs/my-lib/package.json' : `{}` ,
646
659
} ) ;
@@ -686,7 +699,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
686
699
"options": {
687
700
"cwd": "libs/my-lib",
688
701
},
689
- "outputs": [],
702
+ "outputs": [
703
+ "{projectRoot}/dist",
704
+ ],
690
705
"syncGenerators": [
691
706
"@nx/js:typescript-sync",
692
707
],
@@ -709,6 +724,8 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
709
724
'libs/my-lib/tsconfig.json' : JSON . stringify ( {
710
725
extends : '../../tsconfig.foo.json' ,
711
726
include : [ 'src/**/*.ts' ] ,
727
+ // set this to keep outputs smaller
728
+ compilerOptions : { outDir : 'dist' } ,
712
729
} ) ,
713
730
'libs/my-lib/package.json' : `{}` ,
714
731
} ) ;
@@ -757,7 +774,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
757
774
"options": {
758
775
"cwd": "libs/my-lib",
759
776
},
760
- "outputs": [],
777
+ "outputs": [
778
+ "{projectRoot}/dist",
779
+ ],
761
780
"syncGenerators": [
762
781
"@nx/js:typescript-sync",
763
782
],
@@ -781,6 +800,8 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
781
800
'libs/my-lib/tsconfig.json' : JSON . stringify ( {
782
801
extends : '../../tsconfig.foo.json' ,
783
802
include : [ 'src/**/*.ts' ] ,
803
+ // set this to keep outputs smaller
804
+ compilerOptions : { outDir : 'dist' } ,
784
805
} ) ,
785
806
'libs/my-lib/package.json' : `{}` ,
786
807
} ) ;
@@ -835,7 +856,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
835
856
"options": {
836
857
"cwd": "libs/my-lib",
837
858
},
838
- "outputs": [],
859
+ "outputs": [
860
+ "{projectRoot}/dist",
861
+ ],
839
862
"syncGenerators": [
840
863
"@nx/js:typescript-sync",
841
864
],
@@ -859,23 +882,33 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
859
882
{ path : './nested-project/tsconfig.json' } , // external project reference in a nested directory
860
883
{ path : '../other-lib' } , // external project reference, it causes `dependentTasksOutputFiles` to be set
861
884
] ,
885
+ // set this to keep outputs smaller
886
+ compilerOptions : { outDir : 'dist' } ,
862
887
} ) ,
863
888
'libs/my-lib/tsconfig.lib.json' : JSON . stringify ( {
864
889
include : [ 'src/**/*.ts' ] ,
865
890
exclude : [ 'src/**/*.spec.ts' ] ,
891
+ // set this to keep outputs smaller
892
+ compilerOptions : { outDir : 'dist' } ,
866
893
} ) ,
867
894
'libs/my-lib/tsconfig.spec.json' : JSON . stringify ( {
868
895
include : [ 'src/**/*.spec.ts' ] ,
869
896
references : [ { path : './tsconfig.lib.json' } ] ,
897
+ // set this to keep outputs smaller
898
+ compilerOptions : { outDir : 'dist' } ,
870
899
} ) ,
871
900
'libs/my-lib/cypress/tsconfig.json' : JSON . stringify ( {
872
901
include : [ '**/*.ts' , '../cypress.config.ts' , '../**/*.cy.ts' ] ,
873
902
references : [ { path : '../tsconfig.lib.json' } ] ,
903
+ // set this to keep outputs smaller
904
+ compilerOptions : { outDir : 'dist' } ,
874
905
} ) ,
875
906
'libs/my-lib/package.json' : `{}` ,
876
907
'libs/my-lib/nested-project/package.json' : `{}` ,
877
908
'libs/my-lib/nested-project/tsconfig.json' : JSON . stringify ( {
878
909
include : [ 'lib/**/*.ts' ] , // different pattern that should not be included in my-lib because it's an external project reference
910
+ // set this to keep outputs smaller
911
+ compilerOptions : { outDir : 'dist' } ,
879
912
} ) ,
880
913
'libs/other-lib/tsconfig.json' : JSON . stringify ( {
881
914
include : [ '**/*.ts' ] , // different pattern that should not be included because it's an external project
@@ -931,7 +964,10 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
931
964
"options": {
932
965
"cwd": "libs/my-lib",
933
966
},
934
- "outputs": [],
967
+ "outputs": [
968
+ "{projectRoot}/dist",
969
+ "{projectRoot}/cypress/dist",
970
+ ],
935
971
"syncGenerators": [
936
972
"@nx/js:typescript-sync",
937
973
],
@@ -975,7 +1011,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
975
1011
"options": {
976
1012
"cwd": "libs/my-lib/nested-project",
977
1013
},
978
- "outputs": [],
1014
+ "outputs": [
1015
+ "{projectRoot}/dist",
1016
+ ],
979
1017
"syncGenerators": [
980
1018
"@nx/js:typescript-sync",
981
1019
],
@@ -2803,6 +2841,8 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
2803
2841
} ) ,
2804
2842
'libs/my-lib/tsconfig.other.json' : JSON . stringify ( {
2805
2843
include : [ 'other/**/*.ts' , 'src/**/foo.ts' ] ,
2844
+ // set this to keep outputs smaller
2845
+ compilerOptions : { outDir : 'dist' } ,
2806
2846
} ) ,
2807
2847
'libs/other-lib/tsconfig.json' : JSON . stringify ( {
2808
2848
include : [ '**/*.ts' ] , // different pattern that should not be included because it's an external project
0 commit comments