Skip to content

Commit

Permalink
feat: update optionsSchema constraint (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lefebvre authored Feb 29, 2024
1 parent 2863031 commit c445660
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-dancers-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-integration-kit": patch
---

Updates the `optionsSchema` constraint to allow any schema shape
2 changes: 1 addition & 1 deletion package/src/core/define-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type { AnyPlugin, ExtendedHooks } from "./types.js";
* ```
*/
export const defineIntegration = <
TOptionsSchema extends z.AnyZodObject = z.AnyZodObject,
TOptionsSchema extends z.ZodTypeAny = z.ZodTypeAny,
TPlugins extends Array<AnyPlugin> = [],
>({
name,
Expand Down
2 changes: 1 addition & 1 deletion playground/astro.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
integrations: [
tailwind(),
testIntegration({
resource: "abc",
resource: "a",
}),
{ name: "integration-a", hooks: {} },
{ name: "integration-b", hooks: {} },
Expand Down
25 changes: 15 additions & 10 deletions playground/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ import Solid from "@astrojs/solid-js";
import Svelte from "@astrojs/svelte";
import Vue from "@astrojs/vue";

const OptionsSchema = z.object({
/**
* The name of the resource.
*/
resource: z
.string()
.default("abc")
.transform((val) => val.length),
});
const optionsSchema = z
.object({
/**
* The name of the resource.
*/
resource: z
.string()
.default("abc")
.transform((val) => val.length),
})
.refine((val) => val.resource > 1, {
message: "Must be at least 2 chars long",
path: ["resource"],
});

const testIntegration = defineIntegration({
name: "test-integration",
optionsSchema: OptionsSchema,
optionsSchema,
plugins: [...corePlugins],
setup: ({ options }) => {
const { resolve } = createResolver(import.meta.url);
Expand Down

0 comments on commit c445660

Please sign in to comment.