Skip to content

Commit

Permalink
fix: relocated logger to respect config. (#10787) (#10967)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Cordova <theqodesmith@gmail.com>
  • Loading branch information
leonheess and qodesmith authored Nov 17, 2022
1 parent 970538c commit bc3b5a9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
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

0 comments on commit bc3b5a9

Please sign in to comment.