Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Jul 27, 2023
1 parent 508a268 commit ab3b54e
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 139 deletions.
23 changes: 23 additions & 0 deletions .changeset/odd-books-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'astro': minor
---

Integrations can now log messages using Astro’s built-in logger.

The logger is available to all hooks as an additional parameter:

```ts
import {AstroIntegration} from "./astro";

// integration.js
export function myIntegration(): AstroIntegration {
return {
name: "my-integration",
hooks: {
"astro:config:done": ({ logger }) => {
logger.info("Configure integration...");
}
}
}
}
```
139 changes: 61 additions & 78 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1857,87 +1857,70 @@ export interface AstroIntegration {
name: string;
/** The different hooks available to extend. */
hooks: {
'astro:config:setup'?: (
options: {
config: AstroConfig;
command: 'dev' | 'build' | 'preview';
isRestart: boolean;
updateConfig: (newConfig: Record<string, any>) => void;
addRenderer: (renderer: AstroRenderer) => void;
addWatchFile: (path: URL | string) => void;
injectScript: (stage: InjectedScriptStage, content: string) => void;
injectRoute: (injectRoute: InjectedRoute) => void;
addClientDirective: (directive: ClientDirectiveConfig) => void;
// TODO: Add support for `injectElement()` for full HTML element injection, not just scripts.
// This may require some refactoring of `scripts`, `styles`, and `links` into something
// more generalized. Consider the SSR use-case as well.
// injectElement: (stage: vite.HtmlTagDescriptor, element: string) => void;
},
bag: AstroIntegrationBag
) => void | Promise<void>;
'astro:config:done'?: (
options: {
config: AstroConfig;
setAdapter: (adapter: AstroAdapter) => void;
},
bag: AstroIntegrationBag
) => void | Promise<void>;
'astro:server:setup'?: (
options: { server: vite.ViteDevServer },
bag: AstroIntegrationBag
) => void | Promise<void>;
'astro:server:start'?: (
options: { address: AddressInfo },
bag: AstroIntegrationBag
) => void | Promise<void>;
'astro:server:done'?: (bag: AstroIntegrationBag) => void | Promise<void>;
'astro:build:ssr'?: (
options: {
manifest: SerializedSSRManifest;
/**
* This maps a {@link RouteData} to an {@link URL}, this URL represents
* the physical file you should import.
*/
entryPoints: Map<RouteData, URL>;
/**
* File path of the emitted middleware
*/
middlewareEntryPoint: URL | undefined;
},
bag: AstroIntegrationBag
) => void | Promise<void>;
'astro:build:start'?: (bag: AstroIntegrationBag) => void | Promise<void>;
'astro:build:setup'?: (
options: {
vite: vite.InlineConfig;
pages: Map<string, PageBuildData>;
target: 'client' | 'server';
updateConfig: (newConfig: vite.InlineConfig) => void;
},
bag: AstroIntegrationBag
) => void | Promise<void>;
'astro:build:generated'?: (
options: { dir: URL },
bag: AstroIntegrationBag
) => void | Promise<void>;
'astro:build:done'?: (
options: {
pages: { pathname: string }[];
dir: URL;
routes: RouteData[];
},
bag: AstroIntegrationBag
) => void | Promise<void>;
'astro:config:setup'?: (options: {
config: AstroConfig;
command: 'dev' | 'build' | 'preview';
isRestart: boolean;
updateConfig: (newConfig: Record<string, any>) => void;
addRenderer: (renderer: AstroRenderer) => void;
addWatchFile: (path: URL | string) => void;
injectScript: (stage: InjectedScriptStage, content: string) => void;
injectRoute: (injectRoute: InjectedRoute) => void;
addClientDirective: (directive: ClientDirectiveConfig) => void;
logger: AstroIntegrationLogger;
// TODO: Add support for `injectElement()` for full HTML element injection, not just scripts.
// This may require some refactoring of `scripts`, `styles`, and `links` into something
// more generalized. Consider the SSR use-case as well.
// injectElement: (stage: vite.HtmlTagDescriptor, element: string) => void;
}) => void | Promise<void>;
'astro:config:done'?: (options: {
config: AstroConfig;
setAdapter: (adapter: AstroAdapter) => void;
logger: AstroIntegrationLogger;
}) => void | Promise<void>;
'astro:server:setup'?: (options: {
server: vite.ViteDevServer;
logger: AstroIntegrationLogger;
}) => void | Promise<void>;
'astro:server:start'?: (options: {
address: AddressInfo;
logger: AstroIntegrationLogger;
}) => void | Promise<void>;
'astro:server:done'?: (options: { logger: AstroIntegrationLogger }) => void | Promise<void>;
'astro:build:ssr'?: (options: {
manifest: SerializedSSRManifest;
/**
* This maps a {@link RouteData} to an {@link URL}, this URL represents
* the physical file you should import.
*/
entryPoints: Map<RouteData, URL>;
/**
* File path of the emitted middleware
*/
middlewareEntryPoint: URL | undefined;
logger: AstroIntegrationLogger;
}) => void | Promise<void>;
'astro:build:start'?: (options: { logger: AstroIntegrationLogger }) => void | Promise<void>;
'astro:build:setup'?: (options: {
vite: vite.InlineConfig;
pages: Map<string, PageBuildData>;
target: 'client' | 'server';
updateConfig: (newConfig: vite.InlineConfig) => void;
logger: AstroIntegrationLogger;
}) => void | Promise<void>;
'astro:build:generated'?: (options: {
dir: URL;
logger: AstroIntegrationLogger;
}) => void | Promise<void>;
'astro:build:done'?: (options: {
pages: { pathname: string }[];
dir: URL;
routes: RouteData[];
logger: AstroIntegrationLogger;
}) => void | Promise<void>;
};
}

/**
* A set of utilities that are passed at each hook
*/
export type AstroIntegrationBag = {
logger: AstroIntegrationLogger;
};

export type MiddlewareNext<R> = () => Promise<R>;
export type MiddlewareHandler<R> = (
context: APIContext,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/logger/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class AstroIntegrationLogger {
}

/**
* Creates a new logger instances with a new label, but the same log options.
* Creates a new logger instance with a new label, but the same log options.
*/
fork(label: string): AstroIntegrationLogger {
return new AstroIntegrationLogger(this.options, label);
Expand Down
Loading

0 comments on commit ab3b54e

Please sign in to comment.