Skip to content

Commit

Permalink
Remove defineOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni committed Feb 14, 2024
1 parent 39ecdb1 commit 4754b6f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 60 deletions.
16 changes: 7 additions & 9 deletions package/src/core/define-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,24 @@ import type { AnyOptions, AnyPlugin, ExtendedHooks } from "./types.js";
* ```
*/
export const defineIntegration = <
TOptions extends AnyOptions = never,
TOptions extends import("astro/zod").AnyZodObject,
TPlugins extends Array<AnyPlugin> = [],
>({
name,
options: optionsDef,
optionsSchema,
setup,
plugins: _plugins,
}: {
name: string;
options?: TOptions;
optionsSchema?: TOptions;
plugins?: TPlugins;
setup: (params: {
name: string;
options: z.output<TOptions["schema"]>;
options: z.output<TOptions>;
}) => ExtendedHooks<TPlugins>;
}): ((options?: z.input<TOptions["schema"]>) => AstroIntegration) => {
return (_options?: z.input<TOptions["schema"]>) => {
const options = optionsDef?.schema.parse(_options ?? {}) as z.output<
TOptions["schema"]
>;
}): ((options?: z.input<TOptions>) => AstroIntegration) => {
return (_options?: z.input<TOptions>) => {
const options = optionsSchema?.parse(_options ?? {}) as z.output<TOptions>;

const resolvedPlugins = Object.values(
(() => {
Expand Down
29 changes: 0 additions & 29 deletions package/src/core/define-options.ts

This file was deleted.

9 changes: 4 additions & 5 deletions package/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { createResolver } from "./create-resolver.js"
export { defineIntegration } from "./define-integration.js"
export { defineOptions } from "./define-options.js"
export { definePlugin } from "./define-plugin.js"
export * from "./types.js"
export { createResolver } from "./create-resolver.js";
export { defineIntegration } from "./define-integration.js";
export { definePlugin } from "./define-plugin.js";
export * from "./types.js";
6 changes: 0 additions & 6 deletions package/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,3 @@ export interface ExtendedHooks<TPlugins extends Array<AnyPlugin>> {
AddedParam<TPlugins, "astro:build:done">
>;
}

export type Options<Schema extends import("astro/zod").AnyZodObject> = {
schema: Schema;
};

export type AnyOptions = Options<any>;
4 changes: 3 additions & 1 deletion playground/astro.config.mjs → playground/astro.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import testIntegration from "./integration";
export default defineConfig({
integrations: [
tailwind(),
testIntegration({ name: "ced" }),
testIntegration({
resource: "abc",
}),
{ name: "integration-a", hooks: {} },
{ name: "integration-b", hooks: {} },
],
Expand Down
18 changes: 8 additions & 10 deletions playground/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ import { corePlugins } from "astro-integration-kit/plugins";
import { z } from "astro/zod";

const OptionsSchema = z.object({
name: z.string().optional().default("abc")
})

type Options = {
/**
* An important comment
* The name of the resource.
*/
name?: z.infer<typeof OptionsSchema>["name"]
};
resource: z
.string()
.default("abc")
.transform((val) => val.length),
});

const testIntegration = defineIntegration({
name: "test-integration",
options: defineOptions<Options>({
schema: OptionsSchema
}),
options: OptionsSchema,
plugins: [...corePlugins],
setup: ({ options }) => {
const { resolve } = createResolver(import.meta.url);
options.resource;

const pluginPath = resolve("./plugin.ts");
console.log({ options, pluginPath });
Expand Down

0 comments on commit 4754b6f

Please sign in to comment.