-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't mix Vite plugins when spawning temporary Vite server (#6368)
* fix: don't mix Vite plugins when spawning temporary Vite server * chore: include command to `createVite` options * chore: use `command` and exclude `preview` * chore: add test * fix(test): remove command check from apply fn * chore: add hint about filtering vite plugins and command * chore: apply suggestion Co-authored-by: Ben Holmes <hey@bholmes.dev> --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> Co-authored-by: Ben Holmes <hey@bholmes.dev>
- Loading branch information
1 parent
95164bf
commit 02a7266
Showing
6 changed files
with
130 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fix regression that caused some stateful Vite plugins to assume they were running in `dev` mode during the `build` and vice versa. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { expect } from 'chai'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Static build: vite plugins included when required', () => { | ||
/** @type {Map<string, boolean>} */ | ||
const pluginsCalled = new Map(); | ||
/** @type {Map<string, boolean>} */ | ||
const expectedPluginResult = new Map([ | ||
['prepare-no-apply-plugin', true], | ||
['prepare-serve-plugin', false], | ||
['prepare-apply-fn-plugin', true], | ||
['prepare-dont-apply-fn-plugin', false], | ||
['prepare-build-plugin', true], | ||
]); | ||
before(async () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
const fixture = await loadFixture({ | ||
root: './fixtures/astro pages/', | ||
integrations: [ | ||
{ | ||
name: '@astrojs/prepare-vite-plugins', | ||
hooks: { | ||
'astro:config:setup': ({ updateConfig }) => { | ||
pluginsCalled.set('prepare-no-apply-plugin', false); | ||
pluginsCalled.set('prepare-serve-plugin', false); | ||
pluginsCalled.set('prepare-apply-fn-plugin', false); | ||
pluginsCalled.set('prepare-dont-apply-fn-plugin', false); | ||
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); | ||
} | ||
}] | ||
} | ||
}) | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
await fixture.build(); | ||
}); | ||
it('Vite Plugins are included/excluded properly', async () => { | ||
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`) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
// organize-imports-ignore | ||
export { pathToPosix } from './lib/utils'; | ||
export { alert, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js'; | ||
export declare const polyfill: { | ||
(target: any, options?: PolyfillOptions): any; | ||
internals(target: any, name: string): any; | ||
}; | ||
interface PolyfillOptions { | ||
exclude?: string | string[]; | ||
override?: Record<string, { | ||
(...args: any[]): any; | ||
}>; | ||
} | ||
export { pathToPosix } from './lib/utils'; | ||
export { alert, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js'; | ||
export declare const polyfill: { | ||
(target: any, options?: PolyfillOptions): any; | ||
internals(target: any, name: string): any; | ||
}; | ||
interface PolyfillOptions { | ||
exclude?: string | string[]; | ||
override?: Record<string, { | ||
(...args: any[]): any; | ||
}>; | ||
} |