From e9a95096cc4d0aa1a7509602f451e75c1a9dd995 Mon Sep 17 00:00:00 2001 From: Martin Heidegger Date: Fri, 29 Apr 2022 13:57:28 +0900 Subject: [PATCH] feat: adding support fail loudly. --- README.md | 7 +++++++ index.ts | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index f551d01..18cb8fb 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,13 @@ If you still want to use these, you need to pass the `strict = false` option. await loadPlugins(plugins, { strict: false }) ``` +By default there will be also no error if the installation of the plugins happens +to fail. In order to enable errors you need to pass `failQuietly=false`. + +```js +await loadPlugins(plugins, { failQuietyl: false }) +``` + To install private packages you will need to specify an authentication token. ```js diff --git a/index.ts b/index.ts index f4ce051..ebec9e0 100644 --- a/index.ts +++ b/index.ts @@ -197,6 +197,9 @@ async function assertInstalled (plugins: FNOrResult, opts: Lo await writeFile(state.path, JSON.stringify(stateFs)) return installedNames } catch (err) { + if (!opts.failQuietly) { + throw Object.assign(new Error(`Error while installing the current plugins (${installedNames.join(', ')}): ${String(err)}`), { cause: err }) + } debug('Error while installing the current plugins: %s, %s', installedNames, err) return [] } @@ -344,6 +347,7 @@ export interface LoadPluginsOptions extends Omit { tmpDir: string maxAge: number strict: boolean + failQuietly: boolean /** * A list of registry tokens to access private npm registries */ @@ -354,6 +358,7 @@ export async function loadPlugins (plugins: FNOrResult, opts: const normalizedOpts = { tmpDir: DEFAULT_TMP_DIR, maxAge: DEFAULT_MAX_AGE, + failQuietly: true, strict: true, ...opts }