Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/slimy-sloths-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue where using `getViteConfig()` returns incorrect and duplicate configuration
3 changes: 1 addition & 2 deletions packages/astro/src/core/middleware/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export function vitePluginMiddleware({ settings }: { settings: AstroSettings }):

return {
name: '@astro/plugin-middleware',
config(opts, { command }) {
config(_, { command }) {
isCommandBuild = command === 'build';
return opts;
},
async resolveId(id) {
if (id === MIDDLEWARE_MODULE_ID) {
Expand Down
13 changes: 13 additions & 0 deletions packages/astro/test/config-vite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { getViteConfig } from '../dist/config/index.js'
import { resolveConfig } from 'vite';

describe('Vite Config', async () => {
let fixture;
Expand All @@ -21,3 +23,14 @@ describe('Vite Config', async () => {
assert.match($('link').attr('href'), /\/assets\/testing-[a-z\d]+\.css/);
});
});

describe("getViteConfig", () => {
it("Does not change the default config.", async () => {
const command = "serve";
const mode = "test";
const configFn = getViteConfig({});
const config = await configFn({ command, mode });
const resolvedConfig = await resolveConfig(config, command, mode);
assert.deepStrictEqual(resolvedConfig.resolve.conditions, ["astro"]);
Comment on lines +27 to +34
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the fix, the test fails as follows. (The contents of the array are duplicated)

image

})
});
Loading