From c93d6760d9424701326e5a653d8338dc2a2dcc61 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Thu, 27 Jul 2023 12:39:20 +0200 Subject: [PATCH] Fix TS error --- code/lib/core-server/src/presets/common-preset.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/code/lib/core-server/src/presets/common-preset.ts b/code/lib/core-server/src/presets/common-preset.ts index d4333d2847b0..2d0ba9ec61b4 100644 --- a/code/lib/core-server/src/presets/common-preset.ts +++ b/code/lib/core-server/src/presets/common-preset.ts @@ -29,6 +29,7 @@ import { SET_WHATS_NEW_CACHE, TOGGLE_WHATS_NEW_NOTIFICATIONS, } from '@storybook/core-events'; +import invariant from 'tiny-invariant'; import { parseStaticDir } from '../utils/server-statics'; import { defaultStaticDirs } from '../utils/constants'; import { sendTelemetryError } from '../withTelemetry'; @@ -313,19 +314,18 @@ export const experimental_serverChannel = async ( async ({ disableWhatsNewNotifications }: { disableWhatsNewNotifications: boolean }) => { const isTelemetryEnabled = coreOptions.disableTelemetry !== true; try { - const configFileName = findConfigFile('main', options.configDir); - if (!configFileName) - throw new Error(`unable to find storybook main file in ${options.configDir}`); - const main = await readConfig(configFileName); + const mainPath = findConfigFile('main', options.configDir); + invariant(mainPath, `unable to find storybook main file in ${options.configDir}`); + const main = await readConfig(mainPath); main.setFieldValue(['core', 'disableWhatsNewNotifications'], disableWhatsNewNotifications); - await fs.writeFile(main.fileName, printConfig(main).code); - + await fs.writeFile(mainPath, printConfig(main).code); if (isTelemetryEnabled) { await telemetry('core-config', { disableWhatsNewNotifications }); } } catch (error) { + invariant(error instanceof Error); if (isTelemetryEnabled) { - await sendTelemetryError(error as Error, 'core-config', { + await sendTelemetryError(error, 'core-config', { cliOptions: options, presetOptions: { ...options, corePresets: [], overridePresets: [] }, skipPrompt: true,