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