From 2746aa64056ae432fce093fb2211102354909034 Mon Sep 17 00:00:00 2001 From: Romuald Brillout Date: Sun, 21 Jan 2024 11:05:15 +0100 Subject: [PATCH] fix: add debug logs for faulty setups (#1450) --- vike/utils/assertIsNotProductionRuntime.ts | 10 ++++++++-- vike/utils/debug.ts | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/vike/utils/assertIsNotProductionRuntime.ts b/vike/utils/assertIsNotProductionRuntime.ts index 88adbc6fa4f..2e3b5c4ce57 100644 --- a/vike/utils/assertIsNotProductionRuntime.ts +++ b/vike/utils/assertIsNotProductionRuntime.ts @@ -8,10 +8,11 @@ export { assertEnv } import { assert } from './assert.js' import { assertIsNotBrowser } from './assertIsNotBrowser.js' +import { createDebugger } from './debug.js' import { getGlobalObject } from './getGlobalObject.js' import { isVitest } from './isVitest.js' - assertIsNotBrowser() +const debug = createDebugger('vike:setup') const env = getGlobalObject<{ shouldBeVite?: true @@ -20,25 +21,30 @@ const env = getGlobalObject<{ isVite?: true }>('utils/assertIsNotProductionRuntime.ts', {}) -// Called by *.ts that want to ensure that they aren't loaded by the server runtime in production +// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production function assertIsNotProductionRuntime(): void | undefined { + if (debug.isEnabled) debug('assertIsNotProductionRuntime()', new Error().stack) env.shouldBeVite = true } // Called by Vite hook configureServer() function markEnvAsDev(): void | undefined { + if (debug.isEnabled) debug('markEnvAsDev()', new Error().stack) env.isDev = true } // Called by Vite hook configurePreviewServer() function markEnvAsPreview(): void | undefined { + if (debug.isEnabled) debug('markEnvAsPreview()', new Error().stack) env.isPreview = true } // Called by ../node/plugin/index.ts function markEnvAsVite() { + if (debug.isEnabled) debug('markEnvAsVite()', new Error().stack) env.isVite = true } // Called by ../node/runtime/index.ts function assertEnv(): void | undefined { + if (debug.isEnabled) debug('assertEnv()', new Error().stack) if (isVitest()) return if (env.isDev || env.isPreview) { assert(env.isVite) diff --git a/vike/utils/debug.ts b/vike/utils/debug.ts index 528a3686da3..55d0a6b671d 100644 --- a/vike/utils/debug.ts +++ b/vike/utils/debug.ts @@ -25,6 +25,7 @@ type Flag = | 'vike:glob' | 'vike:pageFiles' | 'vike:stem' + | 'vike:setup' type Debug = ReturnType type Options = { serialization?: {