diff --git a/packages/cli/src/lib/cmds/build.ts b/packages/cli/src/lib/cmds/build.ts index 4683aac0..e91f4aff 100644 --- a/packages/cli/src/lib/cmds/build.ts +++ b/packages/cli/src/lib/cmds/build.ts @@ -111,10 +111,16 @@ export async function build( if (!args.skipPwaValidation) { log.info('Checking PWA Quality Criteria...'); - const pwaValidationResult = (await pwaValidationPromise)!; - printValidationResult(pwaValidationResult, log); - if (pwaValidationResult.status === 'FAIL') { - log.warn('PWA Quality Criteria check failed.'); + try { + const pwaValidationResult = (await pwaValidationPromise)!; + printValidationResult(pwaValidationResult, log); + if (pwaValidationResult.status === 'FAIL') { + log.warn('PWA Quality Criteria check failed.'); + } + } catch (e) { + const message = 'Failed to run the PWA Quality Criteria checks. Skipping.'; + log.debug(e); + log.warn(message); } } diff --git a/packages/cli/src/lib/cmds/install.ts b/packages/cli/src/lib/cmds/install.ts index 94ab9d11..c4582c89 100644 --- a/packages/cli/src/lib/cmds/install.ts +++ b/packages/cli/src/lib/cmds/install.ts @@ -18,9 +18,10 @@ import {AndroidSdkTools, Config, JdkHelper, Log} from '@bubblewrap/core'; import {ParsedArgs} from 'minimist'; const APK_FILE_PARAM = '--apkFile'; -const VERBOSE_PARAM = '--verbose'; const DEFAULT_APK_FILE = './app-release-signed.apk'; +const PARAMETERS_TO_IGNORE = ['--verbose', '-r']; + export async function install( args: ParsedArgs, config: Config, log = new Log('install')): Promise { const jdkHelper = new JdkHelper(process, config); @@ -34,7 +35,7 @@ export async function install( // 2. So, we want to start collecting args from parameter 3 and ignore any a possible // `--apkFile`, which is specific to install. Extra parameters are passed through to `adb`. const originalArgs = process.argv.slice(3).filter( - (v) => !v.startsWith(APK_FILE_PARAM) && !v.startsWith(VERBOSE_PARAM)); + (v) => !v.startsWith(APK_FILE_PARAM) && PARAMETERS_TO_IGNORE.indexOf(v) < 0); await androidSdkTools.install(apkFile, originalArgs); return true; } diff --git a/packages/core/src/lib/Log.ts b/packages/core/src/lib/Log.ts index 909920a5..796bc7ff 100644 --- a/packages/core/src/lib/Log.ts +++ b/packages/core/src/lib/Log.ts @@ -76,9 +76,9 @@ export default class Log { * @param args extra arguments for the console. */ error(message: string, ...args: string[]): void { - this.output.log('\n'); + this.output.error('\n'); this.log(this.output.error, this.red('ERROR ' + message), ...args); - this.output.log('\n'); + this.output.error('\n'); } /** diff --git a/packages/core/src/lib/androidSdk/AndroidSdkTools.ts b/packages/core/src/lib/androidSdk/AndroidSdkTools.ts index 9bb367f0..b28f53b6 100644 --- a/packages/core/src/lib/androidSdk/AndroidSdkTools.ts +++ b/packages/core/src/lib/androidSdk/AndroidSdkTools.ts @@ -172,8 +172,9 @@ export class AndroidSdkTools { const env = this.getEnv(); const installCmd = [ `"${this.pathJoin(this.getAndroidHome(), '/platform-tools/adb')}"`, - ...passthroughArgs, 'install', + '-r', // Replace app if another with the same package id already installed. + ...passthroughArgs, apkFilePath, ]; await util.execute(installCmd, env, this.log); diff --git a/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts b/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts index 5a522f55..7f54e81b 100644 --- a/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts +++ b/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts @@ -154,18 +154,21 @@ describe('AndroidSdkTools', () => { expectedCwd: [ '"/home/user/android-sdk/platform-tools/adb"', 'install', + '-r', 'app-release-signed.apk', ]}, {platform: 'darwin', expectedCwd: [ '"/home/user/android-sdk/platform-tools/adb"', 'install', + '-r', 'app-release-signed.apk', ]}, {platform: 'win32', expectedCwd: [ '"C:\\Users\\user\\android-sdk\\platform-tools\\adb"', 'install', + '-r', 'app-release-signed.apk', ]}, ]; diff --git a/packages/validator/src/lib/PwaValidator.ts b/packages/validator/src/lib/PwaValidator.ts index cd230d1a..2ae883b4 100644 --- a/packages/validator/src/lib/PwaValidator.ts +++ b/packages/validator/src/lib/PwaValidator.ts @@ -62,7 +62,13 @@ export class PwaValidator { .setStrategy('mobile') .build(); - const psiResult = await this.psi.runPageSpeedInsights(psiRequest); + let psiResult; + try { + psiResult = await this.psi.runPageSpeedInsights(psiRequest); + } catch (e) { + throw new Error('Error calling the PageSpeed Insights API: ' + e); + } + const pwaScore = psiResult.lighthouseResult.categories.pwa.score; const performanceScore = psiResult.lighthouseResult.categories.performance.score; if (pwaScore === null || performanceScore === null || isNaN(pwaScore) ||