From 88dab328660d2f3705f1bda113dd549d91160af0 Mon Sep 17 00:00:00 2001 From: VandeurenGlenn <8685280+VandeurenGlenn@users.noreply.github.com> Date: Sun, 11 Aug 2024 16:53:19 +0200 Subject: [PATCH] main: try catch scan errors --- src/main.ts | 64 ++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/src/main.ts b/src/main.ts index 056def5..2e9c819 100644 --- a/src/main.ts +++ b/src/main.ts @@ -196,43 +196,47 @@ async function runModuleReplacements(): Promise { scanSpinner.message('Scanning files'); - const files = await traverseFiles(options.filesDir); + try { + const files = await traverseFiles(options.filesDir); - const scanFilesResult = await scanFiles( - files, - manifestReplacements, - scanSpinner - ); + const scanFilesResult = await scanFiles( + files, + manifestReplacements, + scanSpinner + ); - if (scanFilesResult.length > 0) { - dependenciesFound = true; - } + if (scanFilesResult.length > 0) { + dependenciesFound = true; + } - if (dependenciesFound) { - scanSpinner.stop('Replaceable modules found.', 2); - } else { - scanSpinner.stop('No replaceable modules found.'); - } + if (dependenciesFound) { + scanSpinner.stop('Replaceable modules found.', 2); + } else { + scanSpinner.stop('No replaceable modules found.'); + } - if ( - options.autoUninstall && - (dependenciesToRemove.length > 0 || devDependenciesToRemove.length > 0) - ) { - const npmSpinner = cl.spinner(); + if ( + options.autoUninstall && + (dependenciesToRemove.length > 0 || devDependenciesToRemove.length > 0) + ) { + const npmSpinner = cl.spinner(); - npmSpinner.start('Removing npm dependencies'); + npmSpinner.start('Removing npm dependencies'); - if (dependenciesToRemove.length > 0) { - await x('npm', ['rm', '-S', ...dependenciesToRemove]); - } - if (devDependenciesToRemove.length > 0) { - await x('npm', ['rm', '-D', ...devDependenciesToRemove]); - } + if (dependenciesToRemove.length > 0) { + await x('npm', ['rm', '-S', ...dependenciesToRemove]); + } + if (devDependenciesToRemove.length > 0) { + await x('npm', ['rm', '-D', ...devDependenciesToRemove]); + } - npmSpinner.stop('npm dependencies removed'); - } + npmSpinner.stop('npm dependencies removed'); + } - if (options.fix) { - await fixFiles(scanFilesResult); + if (options.fix) { + await fixFiles(scanFilesResult); + } + } catch (error) { + scanSpinner.stop(error as string, 1); } }