[ci] format
This commit is contained in:
parent
02a7266e3c
commit
045262ee99
2 changed files with 55 additions and 40 deletions
|
@ -183,9 +183,12 @@ export async function createVite(
|
||||||
if (command) {
|
if (command) {
|
||||||
let plugins = settings.config.vite?.plugins;
|
let plugins = settings.config.vite?.plugins;
|
||||||
if (plugins) {
|
if (plugins) {
|
||||||
const { plugins: _, ...rest } = settings.config.vite
|
const { plugins: _, ...rest } = settings.config.vite;
|
||||||
const applyToFilter = command === 'build' ? 'serve' : 'build'
|
const applyToFilter = command === 'build' ? 'serve' : 'build';
|
||||||
const applyArgs = [{...settings.config.vite, mode}, { command, mode }]
|
const applyArgs = [
|
||||||
|
{ ...settings.config.vite, mode },
|
||||||
|
{ command, mode },
|
||||||
|
];
|
||||||
// @ts-expect-error ignore TS2589: Type instantiation is excessively deep and possibly infinite.
|
// @ts-expect-error ignore TS2589: Type instantiation is excessively deep and possibly infinite.
|
||||||
plugins = plugins.flat(Infinity).filter((p) => {
|
plugins = plugins.flat(Infinity).filter((p) => {
|
||||||
if (!p || p?.apply === applyToFilter) {
|
if (!p || p?.apply === applyToFilter) {
|
||||||
|
@ -193,7 +196,7 @@ export async function createVite(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof p.apply === 'function') {
|
if (typeof p.apply === 'function') {
|
||||||
return p.apply(applyArgs[0], applyArgs[1])
|
return p.apply(applyArgs[0], applyArgs[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -28,38 +28,44 @@ describe('Static build: vite plugins included when required', () => {
|
||||||
pluginsCalled.set('prepare-build-plugin', false);
|
pluginsCalled.set('prepare-build-plugin', false);
|
||||||
updateConfig({
|
updateConfig({
|
||||||
vite: {
|
vite: {
|
||||||
plugins: [{
|
plugins: [
|
||||||
|
{
|
||||||
name: 'prepare-no-apply-plugin',
|
name: 'prepare-no-apply-plugin',
|
||||||
configResolved: () => {
|
configResolved: () => {
|
||||||
pluginsCalled.set('prepare-no-apply-plugin', true);
|
pluginsCalled.set('prepare-no-apply-plugin', true);
|
||||||
}
|
},
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
name: 'prepare-serve-plugin',
|
name: 'prepare-serve-plugin',
|
||||||
apply: 'serve',
|
apply: 'serve',
|
||||||
configResolved: () => {
|
configResolved: () => {
|
||||||
pluginsCalled.set('prepare-serve-plugin', true);
|
pluginsCalled.set('prepare-serve-plugin', true);
|
||||||
}
|
},
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
name: 'prepare-apply-fn-plugin',
|
name: 'prepare-apply-fn-plugin',
|
||||||
apply: (_, { command }) => command === 'build',
|
apply: (_, { command }) => command === 'build',
|
||||||
configResolved: () => {
|
configResolved: () => {
|
||||||
pluginsCalled.set('prepare-apply-fn-plugin', true);
|
pluginsCalled.set('prepare-apply-fn-plugin', true);
|
||||||
}
|
},
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
name: 'prepare-dont-apply-fn-plugin',
|
name: 'prepare-dont-apply-fn-plugin',
|
||||||
apply: (_, { command }) => command === 'serve',
|
apply: (_, { command }) => command === 'serve',
|
||||||
configResolved: () => {
|
configResolved: () => {
|
||||||
pluginsCalled.set('prepare-dont-apply-fn-plugin', true);
|
pluginsCalled.set('prepare-dont-apply-fn-plugin', true);
|
||||||
}
|
},
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
name: 'prepare-build-plugin',
|
name: 'prepare-build-plugin',
|
||||||
apply: 'build',
|
apply: 'build',
|
||||||
configResolved: () => {
|
configResolved: () => {
|
||||||
pluginsCalled.set('prepare-build-plugin', true);
|
pluginsCalled.set('prepare-build-plugin', true);
|
||||||
}
|
},
|
||||||
}]
|
},
|
||||||
}
|
],
|
||||||
})
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -68,9 +74,15 @@ describe('Static build: vite plugins included when required', () => {
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
it('Vite Plugins are included/excluded properly', async () => {
|
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]) =>
|
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`
|
||||||
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue