From 82e24405991497ebb571486f9f5e0f7a83c3593b Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Sat, 18 Apr 2020 17:44:39 +1000 Subject: [PATCH] Open to silently ignore failures --- CHANGELOG.md | 3 +++ src/main.test.ts | 5 ++++- src/main.ts | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05701fe0..ec0c9704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added +- Option to silently ignore errors, effectively skipping dependencies which cannot be processed. + ## [3.0.0] - 2020-03-14 ### Fixed diff --git a/src/main.test.ts b/src/main.test.ts index 4d2cc4f9..ef6758f3 100644 --- a/src/main.test.ts +++ b/src/main.test.ts @@ -48,6 +48,9 @@ test.serial("Throws when attempting to browserify non existant dependency", asyn ); }); -test.todo("Throws when attempting to browserify dependency with malformed input file"); +test.todo("Throws when attempting to browserify dependency with malformed input file without silent flag"); +test.todo("Doesn't throw when attempting to browserify dependency with malformed input file without silent flag"); + +// NOTE: Silent failures offers an alternative handling here, do we want to remove support? test.todo("Successfully runs against dependencies with an array for main"); diff --git a/src/main.ts b/src/main.ts index c5e16656..8805fc64 100644 --- a/src/main.ts +++ b/src/main.ts @@ -54,8 +54,15 @@ export default async function (userOptions: IOptions): Promise { if (ex.code !== "EEXIST") throw ex; } - // Add to queue - await BrowserifyDependency(depName, targetPath, depOptions); + // Process dependency + try { + await BrowserifyDependency(depName, targetPath, depOptions); + } catch (error) { + if (!depOptions.silentFailures) { + // Errors not silenced, interrupt processing. + throw error; + } + } } } @@ -112,6 +119,11 @@ export interface IOptions { * Path to output directory. */ outputDir: string; + + /** + * Silently ignore failed browserify runs. + */ + silentFailures?: boolean; } /** @@ -122,6 +134,7 @@ class Options implements IOptions { dependencies: string[]; inputDir: string; outputDir: string; + silentFailures: boolean; /** * @param userOptions User options to build instance from. @@ -131,6 +144,7 @@ class Options implements IOptions { this.dependencies = userOptions.dependencies; this.inputDir = userOptions.inputDir; this.outputDir = userOptions.outputDir; + this.silentFailures = userOptions.silentFailures ?? false; } /**