Skip to content

Commit

Permalink
fix: add debug logs for faulty setups (#1450)
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Jan 21, 2024
1 parent 9ef164b commit 2746aa6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions vike/utils/assertIsNotProductionRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions vike/utils/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Flag =
| 'vike:glob'
| 'vike:pageFiles'
| 'vike:stem'
| 'vike:setup'
type Debug = ReturnType<typeof createDebugger>
type Options = {
serialization?: {
Expand Down

0 comments on commit 2746aa6

Please sign in to comment.