@@ -3,7 +3,7 @@ import {join} from 'path';
3
3
import { statSync } from 'fs' ;
4
4
import { DIST_ROOT } from '../build-config' ;
5
5
import { isTravisBuild , isTravisMasterBuild } from '../util/travis-ci' ;
6
- import { openFirebaseDashboardApp } from '../util/firebase' ;
6
+ import { openFirebaseDashboardApp , openFirebaseDashboardAppAsGuest } from '../util/firebase' ;
7
7
8
8
// These imports lack of type definitions.
9
9
const request = require ( 'request' ) ;
@@ -32,7 +32,9 @@ task('payload', ['material:clean-build'], async () => {
32
32
33
33
if ( isTravisBuild ( ) ) {
34
34
// Open a connection to Firebase. For PRs the connection will be established as a guest.
35
- const firebaseApp = openFirebaseDashboardApp ( ! isTravisMasterBuild ( ) ) ;
35
+ const firebaseApp = isTravisMasterBuild ( ) ?
36
+ openFirebaseDashboardApp ( ) :
37
+ openFirebaseDashboardAppAsGuest ( ) ;
36
38
const database = firebaseApp . database ( ) ;
37
39
const currentSha = process . env [ 'TRAVIS_PULL_REQUEST_SHA' ] || process . env [ 'TRAVIS_COMMIT' ] ;
38
40
@@ -74,6 +76,12 @@ async function calculatePayloadDiff(database: any, currentSha: string, currentPa
74
76
75
77
const previousPayload = await getLastPayloadResults ( database ) ;
76
78
79
+ if ( ! previousPayload ) {
80
+ console . warn ( 'There are no previous payload results uploaded. Cannot calculate payload ' +
81
+ 'difference for this job' ) ;
82
+ return ;
83
+ }
84
+
77
85
// Calculate library sizes by combining the CDK and Material FESM 2015 bundles.
78
86
const previousSize = previousPayload . cdk_fesm_2015 + previousPayload . material_fesm_2015 ;
79
87
const currentSize = currentPayload . cdk_fesm_2015 + currentPayload . material_fesm_2015 ;
@@ -125,7 +133,9 @@ async function getLastPayloadResults(database: admin.database.Database) {
125
133
. limitToLast ( 1 )
126
134
. once ( 'value' ) ;
127
135
128
- // The value of the DataSnapshot is an object with the SHA as a key. Only return the
129
- // value of the object because the SHA is not necessary.
130
- return snapshot . val ( ) [ Object . keys ( snapshot . val ( ) ) [ 0 ] ] ;
136
+ // The value of the DataSnapshot is an object with the SHA as a key. Later only the
137
+ // first value of the object will be returned because the SHA is unnecessary.
138
+ const results = snapshot . val ( ) ;
139
+
140
+ return results . length ? results [ Object . keys ( results ) [ 0 ] ] : null ;
131
141
}
0 commit comments