1
1
import * as fs from 'fs' ;
2
- import { readJsonFile , writeJsonFile } from '../utils/fileutils' ;
3
- import { unlinkSync } from 'fs' ;
2
+ import {
3
+ directoryExists ,
4
+ readJsonFile ,
5
+ writeJsonFile ,
6
+ } from '../utils/fileutils' ;
7
+ import { existsSync , unlinkSync } from 'fs' ;
4
8
import { ProjectGraphNode } from '../core/project-graph' ;
9
+ import { join } from 'path' ;
10
+ import { appRootPath } from '@nrwl/workspace/src/utils/app-root' ;
11
+ import * as fsExtra from 'fs-extra' ;
5
12
6
- const RESULTS_FILE = 'dist/.nx-results' ;
13
+ const resultsDir = join ( appRootPath , 'node_modules' , '.cache' , 'nx' ) ;
14
+ const resultsFile = join ( resultsDir , 'results.json' ) ;
7
15
8
16
interface NxResults {
9
17
command : string ;
@@ -31,11 +39,11 @@ export class WorkspaceResults {
31
39
private command : string ,
32
40
private projects : Record < string , ProjectGraphNode >
33
41
) {
34
- const resultsExists = fs . existsSync ( RESULTS_FILE ) ;
42
+ const resultsExists = fs . existsSync ( resultsFile ) ;
35
43
this . startedWithFailedProjects = false ;
36
44
if ( resultsExists ) {
37
45
try {
38
- const commandResults = readJsonFile ( RESULTS_FILE ) ;
46
+ const commandResults = readJsonFile ( resultsFile ) ;
39
47
this . startedWithFailedProjects = commandResults . command === command ;
40
48
if ( this . startedWithFailedProjects ) {
41
49
this . commandResults = commandResults ;
@@ -56,10 +64,19 @@ export class WorkspaceResults {
56
64
}
57
65
58
66
saveResults ( ) {
67
+ try {
68
+ if ( ! existsSync ( resultsDir ) ) {
69
+ fsExtra . ensureDirSync ( resultsDir ) ;
70
+ }
71
+ } catch ( e ) {
72
+ if ( ! directoryExists ( resultsDir ) ) {
73
+ throw new Error ( `Failed to create directory: ${ resultsDir } ` ) ;
74
+ }
75
+ }
59
76
if ( Object . values < boolean > ( this . commandResults . results ) . includes ( false ) ) {
60
- writeJsonFile ( RESULTS_FILE , this . commandResults ) ;
61
- } else if ( fs . existsSync ( RESULTS_FILE ) ) {
62
- unlinkSync ( RESULTS_FILE ) ;
77
+ writeJsonFile ( resultsFile , this . commandResults ) ;
78
+ } else if ( fs . existsSync ( resultsFile ) ) {
79
+ unlinkSync ( resultsFile ) ;
63
80
}
64
81
}
65
82
0 commit comments