fix(config): improved warning when root path includes bad characters (#15761)

Co-authored-by: bluwy <bjornlu.dev@gmail.com>
This commit is contained in:
Pontus Östlund 2024-02-07 10:56:36 +01:00 committed by GitHub
parent 3ee4e7b083
commit 1c0dc3db2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 46 additions and 12 deletions

View File

@ -93,7 +93,7 @@ jobs:
if: runner.os == 'Windows' && steps.changed-files.outputs.only_changed != 'true'
run: |
echo "PLAYWRIGHT_BROWSERS_PATH=$HOME\.cache\playwright-bin" >> $env:GITHUB_ENV
$env:PLAYWRIGHT_VERSION="$(pnpm ls --depth 0 --json -w playwright-chromium | jq --raw-output '.[0].devDependencies[\"playwright-chromium\"].version')"
$env:PLAYWRIGHT_VERSION="$(pnpm ls --depth 0 --json -w playwright-chromium | jq --raw-output '.[0].devDependencies["playwright-chromium"].version')"
echo "PLAYWRIGHT_VERSION=$env:PLAYWRIGHT_VERSION" >> $env:GITHUB_ENV
- name: Cache Playwright's binary

View File

@ -3,7 +3,7 @@ import type { InlineConfig } from '..'
import type { PluginOption, UserConfig, UserConfigExport } from '../config'
import { defineConfig, resolveConfig } from '../config'
import { resolveEnvPrefix } from '../env'
import { mergeConfig } from '../publicUtils'
import { createLogger, mergeConfig } from '../publicUtils'
describe('mergeConfig', () => {
test('handles configs with different alias schemas', () => {
@ -332,4 +332,17 @@ describe('resolveConfig', () => {
expect(results1.clearScreen).toBe(false)
expect(results2.clearScreen).toBe(false)
})
test('resolveConfig with root path including "#" and "?" should warn ', async () => {
expect.assertions(1)
const logger = createLogger('info')
logger.warn = (str) => {
expect(str).to.include(
'Consider renaming the directory to remove the characters',
)
}
await resolveConfig({ root: './inc?ud#s', customLogger: logger }, 'build')
})
})

View File

@ -398,6 +398,34 @@ export type ResolveFn = (
ssr?: boolean,
) => Promise<string | undefined>
/**
* Check and warn if `path` includes characters that don't work well in Vite,
* such as `#` and `?`.
*/
function checkBadCharactersInPath(path: string, logger: Logger): void {
const badChars = []
if (path.includes('#')) {
badChars.push('#')
}
if (path.includes('?')) {
badChars.push('?')
}
if (badChars.length > 0) {
const charString = badChars.map((c) => `"${c}"`).join(' and ')
const inflectedChars = badChars.length > 1 ? 'characters' : 'character'
logger.warn(
colors.yellow(
`The project root contains the ${charString} ${inflectedChars} (${colors.cyan(
path,
)}), which may not work when running Vite. Consider renaming the directory to remove the characters.`,
),
)
}
}
export async function resolveConfig(
inlineConfig: InlineConfig,
command: 'build' | 'serve',
@ -477,15 +505,8 @@ export async function resolveConfig(
const resolvedRoot = normalizePath(
config.root ? path.resolve(config.root) : process.cwd(),
)
if (resolvedRoot.includes('#')) {
logger.warn(
colors.yellow(
`The project root contains the "#" character (${colors.cyan(
resolvedRoot,
)}), which may not work when running Vite. Consider renaming the directory to remove the "#".`,
),
)
}
checkBadCharactersInPath(resolvedRoot, logger)
const clientAlias = [
{
@ -1258,7 +1279,7 @@ function optimizeDepsDisabledBackwardCompatibility(
}
resolved.logger.warn(
colors.yellow(`(!) Experimental ${optimizeDepsPath}optimizeDeps.disabled and deps pre-bundling during build were removed in Vite 5.1.
To disable the deps optimizer, set ${optimizeDepsPath}optimizeDeps.noDiscovery to true and ${optimizeDepsPath}optimizeDeps.include as undefined or empty.
To disable the deps optimizer, set ${optimizeDepsPath}optimizeDeps.noDiscovery to true and ${optimizeDepsPath}optimizeDeps.include as undefined or empty.
Please remove ${optimizeDepsPath}optimizeDeps.disabled from your config.
${
commonjsPluginDisabled