From 045262ee9961286d21b486272764ed0f69153aa8 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Mon, 27 Feb 2023 21:28:07 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/core/create-vite.ts | 15 ++-- .../test/static-build-vite-plugins.test.js | 80 +++++++++++-------- 2 files changed, 55 insertions(+), 40 deletions(-) diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 478a7b5fd..7d83e731c 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -173,7 +173,7 @@ export async function createVite( // 4. command vite config, passed as the argument to this function let result = commonConfig; // PR #6238 Calls user integration `astro:config:setup` hooks when running `astro sync`. - // Without proper filtering, user integrations may run twice unexpectedly: + // Without proper filtering, user integrations may run twice unexpectedly: // - with `command` set to `build/dev` (src/core/build/index.ts L72) // - and again in the `sync` module to generate `Content Collections` (src/core/sync/index.ts L36) // We need to check if the command is `build` or `dev` before merging the user-provided vite config. @@ -183,17 +183,20 @@ export async function createVite( if (command) { let plugins = settings.config.vite?.plugins; if (plugins) { - const { plugins: _, ...rest } = settings.config.vite - const applyToFilter = command === 'build' ? 'serve' : 'build' - const applyArgs = [{...settings.config.vite, mode}, { command, mode }] - // @ts-expect-error ignore TS2589: Type instantiation is excessively deep and possibly infinite. + const { plugins: _, ...rest } = settings.config.vite; + const applyToFilter = command === 'build' ? 'serve' : 'build'; + const applyArgs = [ + { ...settings.config.vite, mode }, + { command, mode }, + ]; + // @ts-expect-error ignore TS2589: Type instantiation is excessively deep and possibly infinite. plugins = plugins.flat(Infinity).filter((p) => { if (!p || p?.apply === applyToFilter) { return false; } if (typeof p.apply === 'function') { - return p.apply(applyArgs[0], applyArgs[1]) + return p.apply(applyArgs[0], applyArgs[1]); } return true; diff --git a/packages/astro/test/static-build-vite-plugins.test.js b/packages/astro/test/static-build-vite-plugins.test.js index 10fe44957..171d390b0 100644 --- a/packages/astro/test/static-build-vite-plugins.test.js +++ b/packages/astro/test/static-build-vite-plugins.test.js @@ -28,38 +28,44 @@ describe('Static build: vite plugins included when required', () => { pluginsCalled.set('prepare-build-plugin', false); updateConfig({ vite: { - plugins: [{ - name: 'prepare-no-apply-plugin', - configResolved: () => { - pluginsCalled.set('prepare-no-apply-plugin', true); - } - }, { - name: 'prepare-serve-plugin', - apply: 'serve', - configResolved: () => { - pluginsCalled.set('prepare-serve-plugin', true); - } - }, { - name: 'prepare-apply-fn-plugin', - apply: (_, { command }) => command === 'build', - configResolved: () => { - pluginsCalled.set('prepare-apply-fn-plugin', true); - } - }, { - name: 'prepare-dont-apply-fn-plugin', - apply: (_, { command }) => command === 'serve', - configResolved: () => { - pluginsCalled.set('prepare-dont-apply-fn-plugin', true); - } - }, { - name: 'prepare-build-plugin', - apply: 'build', - configResolved: () => { - pluginsCalled.set('prepare-build-plugin', true); - } - }] - } - }) + plugins: [ + { + name: 'prepare-no-apply-plugin', + configResolved: () => { + pluginsCalled.set('prepare-no-apply-plugin', true); + }, + }, + { + name: 'prepare-serve-plugin', + apply: 'serve', + configResolved: () => { + pluginsCalled.set('prepare-serve-plugin', true); + }, + }, + { + name: 'prepare-apply-fn-plugin', + apply: (_, { command }) => command === 'build', + configResolved: () => { + pluginsCalled.set('prepare-apply-fn-plugin', true); + }, + }, + { + name: 'prepare-dont-apply-fn-plugin', + apply: (_, { command }) => command === 'serve', + configResolved: () => { + pluginsCalled.set('prepare-dont-apply-fn-plugin', true); + }, + }, + { + name: 'prepare-build-plugin', + apply: 'build', + configResolved: () => { + pluginsCalled.set('prepare-build-plugin', true); + }, + }, + ], + }, + }); }, }, }, @@ -68,9 +74,15 @@ describe('Static build: vite plugins included when required', () => { await fixture.build(); }); it('Vite Plugins are included/excluded properly', async () => { - expect(pluginsCalled.size).to.equal(expectedPluginResult.size, 'Not all plugins were initialized'); + expect(pluginsCalled.size).to.equal( + expectedPluginResult.size, + 'Not all plugins were initialized' + ); Array.from(expectedPluginResult.entries()).forEach(([plugin, called]) => - expect(pluginsCalled.get(plugin)).to.equal(called, `${plugin} was ${called ? 'not' : ''} called`) + expect(pluginsCalled.get(plugin)).to.equal( + called, + `${plugin} was ${called ? 'not' : ''} called` + ) ); }); });