Skip to content

Commit facc2fb

Browse files
authored
fix: remove input option unescaping for now (#23694)
1 parent 70d56ea commit facc2fb

2 files changed

Lines changed: 12 additions & 83 deletions

File tree

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

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,56 +1543,20 @@ describe('resolveConfig', () => {
15431543
})
15441544
})
15451545

1546-
test('reserves glob characters in input', async () => {
1547-
const cases: { name: string; input: UserConfig['input'] }[] = [
1548-
{ name: 'wildcard', input: 'src/*.ts' },
1549-
{ name: 'single char', input: 'src/page?.ts' },
1550-
{ name: 'character class', input: 'src/[id].ts' },
1551-
{ name: 'brace expansion', input: 'src/{a,b}.ts' },
1552-
{ name: 'extglob group', input: 'src/?(group).ts' },
1553-
{ name: 'negation', input: 'src/!(main).ts' },
1554-
{ name: 'extglob prefix +', input: 'src/+(page).ts' },
1555-
{ name: 'extglob prefix @', input: 'src/@(page).ts' },
1556-
{ name: 'array element', input: ['src/main.ts', 'src/*.ts'] },
1557-
{ name: 'record', input: { main: 'src/*.ts' } },
1558-
]
1546+
test('allows glob characters in input', async () => {
1547+
const input = 'src/*.ts'
15591548

1560-
for (const { name, input } of cases) {
1561-
await expect(resolveConfig({ input }, 'serve'), name).rejects.toThrow(
1562-
/`input` cannot contain glob characters/,
1563-
)
1564-
}
1549+
await expect(resolveConfig({ input }, 'serve')).resolves.toMatchObject({
1550+
input,
1551+
})
15651552
})
15661553

1567-
test('support escaped input', async () => {
1568-
const cases: {
1569-
name: string
1570-
input: UserConfig['input']
1571-
expected: UserConfig['input']
1572-
}[] = [
1573-
{
1574-
name: 'glob',
1575-
input: 'src/\\*.ts',
1576-
expected: 'src/*.ts',
1577-
},
1578-
{
1579-
name: 'array element',
1580-
input: ['src/\\*.ts'],
1581-
expected: ['src/*.ts'],
1582-
},
1583-
{
1584-
name: 'record',
1585-
input: { main: 'src/\\*.ts' },
1586-
expected: { main: 'src/*.ts' },
1587-
},
1588-
]
1554+
test('preserves input escaping', async () => {
1555+
const inputs = ['src/\\*.ts', 'C:\\root\\@src\\index.html']
15891556

1590-
for (const { name, input, expected } of cases) {
1591-
await expect(
1592-
resolveConfig({ input }, 'serve'),
1593-
name,
1594-
).resolves.toMatchObject({
1595-
input: expected,
1557+
for (const input of inputs) {
1558+
await expect(resolveConfig({ input }, 'serve')).resolves.toMatchObject({
1559+
input,
15961560
})
15971561
}
15981562
})

‎packages/vite/src/node/config.ts‎

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
type RolldownOutput,
2424
rolldown,
2525
} from 'rolldown'
26-
import { isDynamicPattern } from 'tinyglobby'
2726
import type { Alias, AliasOptions } from '#dep-types/alias'
2827
import type {
2928
DevToolsConfig,
@@ -959,39 +958,6 @@ const configDefaults = Object.freeze({
959958
appType: 'spa',
960959
} satisfies UserConfig)
961960

962-
function normalizeInput(
963-
input: InputOption | undefined,
964-
): InputOption | undefined {
965-
if (input === undefined) {
966-
return undefined
967-
}
968-
if (typeof input === 'string') {
969-
return unescapeGlobCharacters(input)
970-
}
971-
if (Array.isArray(input)) {
972-
return input.map(unescapeGlobCharacters)
973-
}
974-
const resolved: Record<string, string> = {}
975-
for (const key in input) {
976-
resolved[key] = unescapeGlobCharacters(input[key])
977-
}
978-
return resolved
979-
}
980-
981-
const escapedGlobCharactersRE = /\\([*?[\]{}()!+@|])/g
982-
983-
function unescapeGlobCharacters(value: string): string {
984-
if (isDynamicPattern(value)) {
985-
// so that it could later be changed to accept globs without a breaking change
986-
throw new Error(
987-
`\`input\` cannot contain glob characters. They are reserved, ` +
988-
`so the ${JSON.stringify(value)} is not allowed. Please escape them with a backslash (\\)`,
989-
)
990-
}
991-
// unescape glob characters
992-
return value.replace(escapedGlobCharactersRE, '$1')
993-
}
994-
995961
export function resolveDevEnvironmentOptions(
996962
dev: DevEnvironmentOptions | undefined,
997963
environmentName: string | undefined,
@@ -1073,7 +1039,7 @@ function resolveEnvironmentOptions(
10731039
isSsrTargetWebworkerEnvironment,
10741040
)
10751041
return {
1076-
input: normalizeInput(options.input),
1042+
input: options.input,
10771043
define: options.define,
10781044
resolve,
10791045
keepProcessEnv:
@@ -1919,7 +1885,6 @@ export async function resolveConfig(
19191885
)
19201886
: ''
19211887

1922-
const input = normalizeInput(config.input)
19231888
const server = await resolveServerOptions(resolvedRoot, config.server, logger)
19241889

19251890
const builder = resolveBuilderOptions(config.builder)
@@ -2163,7 +2128,7 @@ export async function resolveConfig(
21632128

21642129
ssr,
21652130

2166-
input,
2131+
input: config.input,
21672132
optimizeDeps: backwardCompatibleOptimizeDeps,
21682133
resolve: resolvedDefaultResolve,
21692134
dev: resolvedDevEnvironmentOptions,

0 commit comments

Comments
 (0)