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:
parent
f275d058fc
commit
30bb363713
4 changed files with 43 additions and 4 deletions
5
.changeset/cyan-vans-clap.md
Normal file
5
.changeset/cyan-vans-clap.md
Normal 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.
|
|
@ -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(
|
||||
|
|
|
@ -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({
|
||||
|
|
30
packages/astro/test/units/integrations/api.test.js
Normal file
30
packages/astro/test/units/integrations/api.test.js
Normal 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');
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue