Skip to content

hasIntegration

hasIntegration checks whether an integration has already been added to the Astro config. For example:

my-integration/index.ts
import { defineIntegration } from "astro-integration-kit";
import { hasIntegrationPlugin } from "astro-integration-kit/plugins";
export default defineIntegration({
name: "my-integration",
plugins: [hasIntegrationPlugin],
setup() {
return {
"astro:config:setup": ({ hasIntegration, logger }) => {
if (hasIntegration("@astrojs/tailwind")) {
logger.info("Tailwind is installed!");
}
}
}
}
})

Relative position check

Sometimes two integrations must be installed in an specific order to work together correctly.

For that use-case, this utility accepts optional position and relativeTo parameters to check for the presence of one integration in relation to another.

Checking for the presence of an integration in relation to an uninstalled integration will result in an error.

With extended hooks, hasIntegration can receive the position and relative reference as optional positional parameters. If a relative reference is not given the result will be relative to the current integration being defined.

my-integration/index.ts
import { defineIntegration } from "astro-integration-kit";
export default defineIntegration({
name: "my-integration",
setup() {
return {
"astro:config:setup": ({ hasIntegration, logger }) => {
if (hasIntegration("@astrojs/tailwind", "before")) {
logger.info("Tailwind is installed before my-integration");
}
if (hasIntegration("astro-env", "after")) {
logger.info("AstroEnv is installed after my-integration");
}
if (hasIntegration("astro-expressive-code", "before", "@astrojs/mdx")) {
logger.info("Expressice Code is installed before MDX");
}
if (hasIntegration("astro-expressive-code", "after", "@astrojs/tailwind")) {
logger.info("Expressice Code is installed after Tailwind");
}
}
}
}
})