Skip to content

Commit

Permalink
further type reworks
Browse files Browse the repository at this point in the history
  • Loading branch information
noelforte committed Dec 10, 2024
1 parent c2e0bc7 commit 088fe72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
29 changes: 13 additions & 16 deletions src/types/vento.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import type { Merge } from 'type-fest';
// Vento library augmentations
import type { MergeDeep } from 'type-fest';
import type { Environment, Tag } from 'ventojs/src/environment.js';
import type { Token } from 'ventojs/src/tokenizer.js';

import type { EleventyTagInfo } from '../utils/create-vento-tag.ts';
import type { EleventyTagInfo, EleventyTag } from '../utils/create-vento-tag.ts';
import type { EleventyFunctionMap, EleventyDataCascade, EleventyFunction } from './eleventy.ts';

export type EleventyVentoEnvironment = Merge<Environment, VentoOverrides>;
// Filters
type EleventyVentoFilterThis = {
data: EleventyDataCascade;
env: EleventyVentoEnvironment;
};

type EleventyVentoFilter = EleventyFunction<EleventyVentoFilterThis>;

// Environment overrides
type VentoOverrides = {
tags: (Tag | EleventyTag)[];
filters: Record<string, EleventyVentoFilter>;
Expand All @@ -17,18 +23,9 @@ type VentoOverrides = {
};
};

export type EleventyVentoFilterThis = {
data: EleventyDataCascade;
env: EleventyVentoEnvironment;
};

export type EleventyTag = (
env: EleventyVentoEnvironment,
code: string,
output: string,
tokens: Token[]
) => string | undefined;
export type EleventyVentoEnvironment = MergeDeep<Environment, VentoOverrides>;

// Redeclare vento's default export declaration so we can use EleventyVentoEnvironment instead
declare module 'ventojs' {
export default function (options: Options): Merge<Environment, VentoOverrides>;
export default function (options: Options): EleventyVentoEnvironment;
}
10 changes: 9 additions & 1 deletion src/utils/create-vento-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
* @file Factory function that creates vento tags from eleventy functions
*/

import type { EleventyTag } from '../types/vento.js';
import type { EleventyVentoEnvironment } from '../types/vento.js';
import type { Token } from 'ventojs/src/tokenizer.js';

export type EleventyTag = (
env: EleventyVentoEnvironment,
code: string,
output: string,
tokens: Token[]
) => string | undefined;

export interface EleventyTagInfo {
name: string;
Expand Down

0 comments on commit 088fe72

Please sign in to comment.