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: respect top-level server.preTransformRequests #19272

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
94 changes: 94 additions & 0 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,97 @@ test('config compat 3', async () => {
]
`)
})

test('preTransformRequests', async () => {
async function testConfig(inlineConfig: InlineConfig) {
return Object.fromEntries(
Object.entries(
(await resolveConfig(inlineConfig, 'serve')).environments,
).map(([name, e]) => [name, e.dev.preTransformRequests]),
)
}

expect(
await testConfig({
environments: {
custom: {},
customTrue: {
dev: {
preTransformRequests: true,
},
},
customFalse: {
dev: {
preTransformRequests: false,
},
},
},
}),
).toMatchInlineSnapshot(`
{
"client": true,
"custom": false,
"customFalse": false,
"customTrue": true,
"ssr": false,
}
`)

expect(
await testConfig({
server: {
preTransformRequests: true,
},
environments: {
custom: {},
customTrue: {
dev: {
preTransformRequests: true,
},
},
customFalse: {
dev: {
preTransformRequests: false,
},
},
},
}),
).toMatchInlineSnapshot(`
{
"client": true,
"custom": true,
"customFalse": false,
"customTrue": true,
"ssr": true,
}
`)

expect(
await testConfig({
server: {
preTransformRequests: false,
},
environments: {
custom: {},
customTrue: {
dev: {
preTransformRequests: true,
},
},
customFalse: {
dev: {
preTransformRequests: false,
},
},
},
}),
).toMatchInlineSnapshot(`
{
"client": false,
"custom": false,
"customFalse": false,
"customTrue": true,
"ssr": false,
}
`)
})
6 changes: 5 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,12 +739,13 @@ export function resolveDevEnvironmentOptions(
consumer: 'client' | 'server' | undefined,
// Backward compatibility
skipSsrTransform?: boolean,
preTransformRequest?: boolean,
): ResolvedDevEnvironmentOptions {
const resolved = mergeWithDefaults(
{
...configDefaults.dev,
sourcemapIgnoreList: isInNodeModules,
preTransformRequests: consumer === 'client',
preTransformRequests: preTransformRequest ?? consumer === 'client',
createEnvironment:
environmentName === 'client'
? defaultCreateClientDevEnvironment
Expand Down Expand Up @@ -775,6 +776,7 @@ function resolveEnvironmentOptions(
// Backward compatibility
skipSsrTransform?: boolean,
isSsrTargetWebworkerSet?: boolean,
preTransformRequests?: boolean,
): ResolvedEnvironmentOptions {
const isClientEnvironment = environmentName === 'client'
const consumer =
Expand Down Expand Up @@ -806,6 +808,7 @@ function resolveEnvironmentOptions(
environmentName,
consumer,
skipSsrTransform,
preTransformRequests,
),
build: resolveBuildEnvironmentOptions(
options.build ?? {},
Expand Down Expand Up @@ -1196,6 +1199,7 @@ export async function resolveConfig(
environmentName,
config.experimental?.skipSsrTransform,
config.ssr?.target === 'webworker',
config.server?.preTransformRequests,
)
}

Expand Down
Loading