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