feat: add plugin configResolved (#2055)
This commit is contained in:
@@ -17,6 +17,9 @@ export async function build(
|
||||
// Create a directory for static assets produced during the build
|
||||
await Deno.mkdir(join(outDir, "static"));
|
||||
|
||||
await Promise.all(
|
||||
plugins.map((plugin) => plugin.configResolved?.(state.config)),
|
||||
);
|
||||
await Promise.all(plugins.map((plugin) => plugin.buildStart?.(state.config)));
|
||||
|
||||
// Bundle assets
|
||||
|
||||
@@ -45,6 +45,7 @@ export async function dev(
|
||||
);
|
||||
state.config.dev = false;
|
||||
state.loadSnapshot = false;
|
||||
state.build = true;
|
||||
await build(state);
|
||||
} else if (config) {
|
||||
const state = await getInternalFreshState(
|
||||
|
||||
@@ -105,6 +105,7 @@ export async function getInternalFreshState(
|
||||
loadSnapshot: !isLegacyDev,
|
||||
denoJsonPath,
|
||||
denoJson,
|
||||
build: false,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,13 @@ export async function getServerContext(state: InternalFreshState) {
|
||||
await import("preact/debug");
|
||||
}
|
||||
|
||||
// Plugins are already instantiated in build mode
|
||||
if (!state.build) {
|
||||
await Promise.all(
|
||||
config.plugins.map((plugin) => plugin.configResolved?.(state.config)),
|
||||
);
|
||||
}
|
||||
|
||||
const extractResult = await extractRoutes(state);
|
||||
|
||||
// Restore snapshot if available
|
||||
|
||||
@@ -42,6 +42,7 @@ export type {
|
||||
Plugin,
|
||||
PluginAsyncRenderContext,
|
||||
PluginAsyncRenderFunction,
|
||||
PluginMiddleware,
|
||||
PluginRenderContext,
|
||||
PluginRenderFunction,
|
||||
PluginRenderFunctionResult,
|
||||
@@ -49,6 +50,7 @@ export type {
|
||||
PluginRenderScripts,
|
||||
PluginRenderStyleTag,
|
||||
RenderFunction,
|
||||
ResolvedFreshConfig,
|
||||
RouteConfig,
|
||||
RouteContext,
|
||||
RouterOptions,
|
||||
|
||||
@@ -114,6 +114,7 @@ export interface InternalFreshState {
|
||||
loadSnapshot: boolean;
|
||||
denoJsonPath: string;
|
||||
denoJson: DenoConfig;
|
||||
build: boolean;
|
||||
}
|
||||
|
||||
export interface ResolvedFreshConfig {
|
||||
@@ -581,6 +582,11 @@ export interface Plugin<State = Record<string, unknown>> {
|
||||
*/
|
||||
buildEnd?(): Promise<void> | void;
|
||||
|
||||
/**
|
||||
* Called after configuration has been loaded
|
||||
*/
|
||||
configResolved?(config: ResolvedFreshConfig): Promise<void> | void;
|
||||
|
||||
routes?: PluginRoute[];
|
||||
|
||||
middlewares?: PluginMiddleware<State>[];
|
||||
|
||||
Reference in New Issue
Block a user