Skip to content

Commit 1c0dc3d

Browse files
poppabluwy
andauthored
fix(config): improved warning when root path includes bad characters (#15761)
Co-authored-by: bluwy <[email protected]>
1 parent 3ee4e7b commit 1c0dc3d

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

.github/workflows/ci.yml

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

packages/vite/src/node/__tests__/config.spec.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { InlineConfig } from '..'
33
import type { PluginOption, UserConfig, UserConfigExport } from '../config'
44
import { defineConfig, resolveConfig } from '../config'
55
import { resolveEnvPrefix } from '../env'
6-
import { mergeConfig } from '../publicUtils'
6+
import { createLogger, mergeConfig } from '../publicUtils'
77

88
describe('mergeConfig', () => {
99
test('handles configs with different alias schemas', () => {
@@ -332,4 +332,17 @@ describe('resolveConfig', () => {
332332
expect(results1.clearScreen).toBe(false)
333333
expect(results2.clearScreen).toBe(false)
334334
})
335+
336+
test('resolveConfig with root path including "#" and "?" should warn ', async () => {
337+
expect.assertions(1)
338+
339+
const logger = createLogger('info')
340+
logger.warn = (str) => {
341+
expect(str).to.include(
342+
'Consider renaming the directory to remove the characters',
343+
)
344+
}
345+
346+
await resolveConfig({ root: './inc?ud#s', customLogger: logger }, 'build')
347+
})
335348
})

packages/vite/src/node/config.ts

+31-10
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,34 @@ export type ResolveFn = (
398398
ssr?: boolean,
399399
) => Promise<string | undefined>
400400

401+
/**
402+
* Check and warn if `path` includes characters that don't work well in Vite,
403+
* such as `#` and `?`.
404+
*/
405+
function checkBadCharactersInPath(path: string, logger: Logger): void {
406+
const badChars = []
407+
408+
if (path.includes('#')) {
409+
badChars.push('#')
410+
}
411+
if (path.includes('?')) {
412+
badChars.push('?')
413+
}
414+
415+
if (badChars.length > 0) {
416+
const charString = badChars.map((c) => `"${c}"`).join(' and ')
417+
const inflectedChars = badChars.length > 1 ? 'characters' : 'character'
418+
419+
logger.warn(
420+
colors.yellow(
421+
`The project root contains the ${charString} ${inflectedChars} (${colors.cyan(
422+
path,
423+
)}), which may not work when running Vite. Consider renaming the directory to remove the characters.`,
424+
),
425+
)
426+
}
427+
}
428+
401429
export async function resolveConfig(
402430
inlineConfig: InlineConfig,
403431
command: 'build' | 'serve',
@@ -477,15 +505,8 @@ export async function resolveConfig(
477505
const resolvedRoot = normalizePath(
478506
config.root ? path.resolve(config.root) : process.cwd(),
479507
)
480-
if (resolvedRoot.includes('#')) {
481-
logger.warn(
482-
colors.yellow(
483-
`The project root contains the "#" character (${colors.cyan(
484-
resolvedRoot,
485-
)}), which may not work when running Vite. Consider renaming the directory to remove the "#".`,
486-
),
487-
)
488-
}
508+
509+
checkBadCharactersInPath(resolvedRoot, logger)
489510

490511
const clientAlias = [
491512
{
@@ -1258,7 +1279,7 @@ function optimizeDepsDisabledBackwardCompatibility(
12581279
}
12591280
resolved.logger.warn(
12601281
colors.yellow(`(!) Experimental ${optimizeDepsPath}optimizeDeps.disabled and deps pre-bundling during build were removed in Vite 5.1.
1261-
To disable the deps optimizer, set ${optimizeDepsPath}optimizeDeps.noDiscovery to true and ${optimizeDepsPath}optimizeDeps.include as undefined or empty.
1282+
To disable the deps optimizer, set ${optimizeDepsPath}optimizeDeps.noDiscovery to true and ${optimizeDepsPath}optimizeDeps.include as undefined or empty.
12621283
Please remove ${optimizeDepsPath}optimizeDeps.disabled from your config.
12631284
${
12641285
commonjsPluginDisabled

0 commit comments

Comments
 (0)