Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: relocated logger to respect config. #10787

Merged
merged 2 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'vitest'
import type { InlineConfig } from '..'
import type { UserConfig, UserConfigExport } from '../config'
import type { PluginOption, UserConfig, UserConfigExport } from '../config'
import { resolveConfig } from '../config'
import { resolveEnvPrefix } from '../env'
import { mergeConfig } from '../publicUtils'
Expand Down Expand Up @@ -266,3 +266,51 @@ describe('preview config', () => {
})
})
})

describe('resolveConfig', () => {
const keepScreenMergePlugin = (): PluginOption => {
return {
name: 'vite-plugin-keep-screen-merge',
config() {
return { clearScreen: false }
}
}
}

const keepScreenOverridePlugin = (): PluginOption => {
return {
name: 'vite-plugin-keep-screen-override',
config(config) {
config.clearScreen = false
}
}
}

test('plugin merges `clearScreen` option', async () => {
const config1: InlineConfig = { plugins: [keepScreenMergePlugin()] }
const config2: InlineConfig = {
plugins: [keepScreenMergePlugin()],
clearScreen: true
}

const results1 = await resolveConfig(config1, 'build')
const results2 = await resolveConfig(config2, 'build')

expect(results1.clearScreen).toBe(false)
expect(results2.clearScreen).toBe(false)
})

test('plugin overrides `clearScreen` option', async () => {
const config1: InlineConfig = { plugins: [keepScreenOverridePlugin()] }
const config2: InlineConfig = {
plugins: [keepScreenOverridePlugin()],
clearScreen: true
}

const results1 = await resolveConfig(config1, 'build')
const results2 = await resolveConfig(config2, 'build')

expect(results1.clearScreen).toBe(false)
expect(results2.clearScreen).toBe(false)
})
})
12 changes: 6 additions & 6 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,6 @@ export async function resolveConfig(
}
}

// Define logger
const logger = createLogger(config.logLevel, {
allowClearScreen: config.clearScreen,
customLogger: config.customLogger
})

// user config may provide an alternative mode. But --mode has a higher priority
mode = inlineConfig.mode || config.mode || mode
configEnv.mode = mode
Expand Down Expand Up @@ -457,6 +451,12 @@ export async function resolveConfig(
config.build.commonjsOptions = { include: [] }
}

// Define logger
const logger = createLogger(config.logLevel, {
allowClearScreen: config.clearScreen,
customLogger: config.customLogger
})

// resolve root
const resolvedRoot = normalizePath(
config.root ? path.resolve(config.root) : process.cwd()
Expand Down