0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Fix astro:build:setup hook updateConfig utility (#7438)

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
This commit is contained in:
Bjorn Lu 2023-06-21 21:56:25 +08:00 committed by GitHub
parent f275d058fc
commit 30bb363713
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix `astro:build:setup` hook `updateConfig` utility, where the configuration wasn't correctly updated when the hook was fired.

View file

@ -207,7 +207,7 @@ async function ssrBuild(
base: settings.config.base,
};
await runHookBuildSetup({
const updatedViteBuildConfig = await runHookBuildSetup({
config: settings.config,
pages: internals.pagesByComponent,
vite: viteBuildConfig,
@ -215,7 +215,7 @@ async function ssrBuild(
logging: opts.logging,
});
return await vite.build(viteBuildConfig);
return await vite.build(updatedViteBuildConfig);
}
async function clientBuild(

View file

@ -286,7 +286,9 @@ export async function runHookBuildSetup({
pages: Map<string, PageBuildData>;
target: 'server' | 'client';
logging: LogOptions;
}) {
}): Promise<InlineConfig> {
let updatedConfig = vite;
for (const integration of config.integrations) {
if (integration?.hooks?.['astro:build:setup']) {
await withTakingALongTimeMsg({
@ -296,13 +298,15 @@ export async function runHookBuildSetup({
pages,
target,
updateConfig: (newConfig) => {
mergeConfig(vite, newConfig);
updatedConfig = mergeConfig(updatedConfig, newConfig);
},
}),
logging,
});
}
}
return updatedConfig;
}
export async function runHookBuildSsr({

View file

@ -0,0 +1,30 @@
import { expect } from 'chai';
import { runHookBuildSetup } from '../../../dist/integrations/index.js';
describe('Integration API', () => {
it('runHookBuildSetup should work', async () => {
const updatedViteConfig = await runHookBuildSetup({
config: {
integrations: [
{
name: 'test',
hooks: {
'astro:build:setup'({ updateConfig }) {
updateConfig({
define: {
foo: 'bar',
},
});
},
},
},
],
},
vite: {},
logging: {},
pages: new Map(),
target: 'server',
});
expect(updatedViteConfig).to.haveOwnProperty('define');
});
});