1
- import { byteSize } from '@utils' ;
1
+ import { byteSize , sortBy } from '@utils' ;
2
2
import type * as d from '../../declarations' ;
3
3
4
4
/**
@@ -10,14 +10,15 @@ import type * as d from '../../declarations';
10
10
*/
11
11
export function generateBuildStats ( config : d . Config , buildCtx : d . BuildCtx ) {
12
12
const buildResults = buildCtx . buildResults ;
13
- let jsonData : any ;
14
13
15
- if ( buildResults . hasError ) {
16
- jsonData = {
17
- diagnostics : buildResults . diagnostics ,
18
- } ;
19
- } else {
20
- try {
14
+ let jsonData : d . CompilerBuildStats | { diagnostics : d . Diagnostic [ ] } ;
15
+
16
+ try {
17
+ if ( buildResults . hasError ) {
18
+ jsonData = {
19
+ diagnostics : buildResults . diagnostics ,
20
+ } ;
21
+ } else {
21
22
const stats : d . CompilerBuildStats = {
22
23
timestamp : buildResults . timestamp ,
23
24
compiler : {
@@ -39,22 +40,27 @@ export function generateBuildStats(config: d.Config, buildCtx: d.BuildCtx) {
39
40
hashedFileNameLength : config . hashedFileNameLength ,
40
41
buildEs5 : config . buildEs5 ,
41
42
} ,
42
- esmBrowser : sanitizeBundlesForStats ( buildCtx . esmBrowserComponentBundle ) ,
43
- esm : sanitizeBundlesForStats ( buildCtx . esmComponentBundle ) ,
44
- es5 : sanitizeBundlesForStats ( buildCtx . es5ComponentBundle ) ,
45
- system : sanitizeBundlesForStats ( buildCtx . systemComponentBundle ) ,
46
- commonjs : sanitizeBundlesForStats ( buildCtx . commonJsComponentBundle ) ,
43
+ formats : {
44
+ esmBrowser : sanitizeBundlesForStats ( buildCtx . esmBrowserComponentBundle ) ,
45
+ esm : sanitizeBundlesForStats ( buildCtx . esmComponentBundle ) ,
46
+ es5 : sanitizeBundlesForStats ( buildCtx . es5ComponentBundle ) ,
47
+ system : sanitizeBundlesForStats ( buildCtx . systemComponentBundle ) ,
48
+ commonjs : sanitizeBundlesForStats ( buildCtx . commonJsComponentBundle ) ,
49
+ } ,
47
50
components : getComponentsFileMap ( config , buildCtx ) ,
48
51
entries : buildCtx . entryModules ,
49
- sourceGraph : buildResults . componentGraph ,
52
+ componentGraph : buildResults . componentGraph ,
53
+ sourceGraph : getSourceGraph ( config , buildCtx ) ,
50
54
rollupResults : buildCtx . rollupResults ,
51
55
collections : getCollections ( config , buildCtx ) ,
52
56
} ;
53
57
54
58
jsonData = stats ;
55
- } catch ( e ) {
56
- console . log ( e ) ;
57
59
}
60
+ } catch ( e ) {
61
+ jsonData = {
62
+ diagnostics : [ e . message ] ,
63
+ } ;
58
64
}
59
65
60
66
return jsonData ;
@@ -96,6 +102,17 @@ function sanitizeBundlesForStats(bundleArray: d.BundleModule[]): d.CompilerBuild
96
102
} ) ;
97
103
}
98
104
105
+ function getSourceGraph ( config : d . Config , buildCtx : d . BuildCtx ) {
106
+ let sourceGraph : d . BuildSourceGraph = { } ;
107
+
108
+ sortBy ( buildCtx . moduleFiles , ( m ) => m . sourceFilePath ) . forEach ( ( moduleFile ) => {
109
+ const key = relativePath ( config , moduleFile . sourceFilePath ) ;
110
+ sourceGraph [ key ] = moduleFile . localImports . map ( ( localImport ) => relativePath ( config , localImport ) ) . sort ( ) ;
111
+ } ) ;
112
+
113
+ return sourceGraph ;
114
+ }
115
+
99
116
function getAppOutputs ( config : d . Config , buildResults : d . CompilerBuildResults ) {
100
117
return buildResults . outputs . map ( ( output ) => {
101
118
return {
0 commit comments