From 5642ef9029890fc29793c160321f78f62cdaafcb Mon Sep 17 00:00:00 2001 From: koyopro Date: Tue, 29 Oct 2024 13:14:20 +0900 Subject: [PATCH 1/2] Fix: The problem getViteConfig() duplicates some config (#12312) Co-authored-by: Emanuele Stoppa Co-authored-by: bluwy --- .changeset/slimy-sloths-fry.md | 5 +++++ packages/astro/src/core/middleware/vite-plugin.ts | 3 +-- packages/astro/test/config-vite.test.js | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 .changeset/slimy-sloths-fry.md diff --git a/.changeset/slimy-sloths-fry.md b/.changeset/slimy-sloths-fry.md new file mode 100644 index 0000000000000..b2d81f1d7bc37 --- /dev/null +++ b/.changeset/slimy-sloths-fry.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue where using `getViteConfig()` returns incorrect and duplicate configuration diff --git a/packages/astro/src/core/middleware/vite-plugin.ts b/packages/astro/src/core/middleware/vite-plugin.ts index bb7b54e727d3b..7ac8bf2ed17ff 100644 --- a/packages/astro/src/core/middleware/vite-plugin.ts +++ b/packages/astro/src/core/middleware/vite-plugin.ts @@ -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) { diff --git a/packages/astro/test/config-vite.test.js b/packages/astro/test/config-vite.test.js index 6f9b20599d270..3212172d2f362 100644 --- a/packages/astro/test/config-vite.test.js +++ b/packages/astro/test/config-vite.test.js @@ -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; @@ -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"]); + }) +}); From feb87c21be37e508ec8b23cfbb47056fd0971dfc Mon Sep 17 00:00:00 2001 From: koyopro Date: Tue, 29 Oct 2024 04:15:08 +0000 Subject: [PATCH 2/2] [ci] format --- packages/astro/test/config-vite.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/astro/test/config-vite.test.js b/packages/astro/test/config-vite.test.js index 3212172d2f362..abf2d71bc5770 100644 --- a/packages/astro/test/config-vite.test.js +++ b/packages/astro/test/config-vite.test.js @@ -1,9 +1,9 @@ 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'; +import { getViteConfig } from '../dist/config/index.js'; +import { loadFixture } from './test-utils.js'; describe('Vite Config', async () => { let fixture; @@ -24,13 +24,13 @@ describe('Vite Config', async () => { }); }); -describe("getViteConfig", () => { - it("Does not change the default config.", async () => { - const command = "serve"; - const mode = "test"; +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"]); - }) + assert.deepStrictEqual(resolvedConfig.resolve.conditions, ['astro']); + }); });