eleventy-plugin-vento 5.4.2 → 5.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # eleventy-plugin-vento
2
2
 
3
+ ## 5.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 138db0f: Refactor Vento engine internal methods, should not introduce any functionally breaking changes
8
+ - 2f42cc1: Refactor render function declaration
9
+ - Replaced `getTemplateFunction` with `getRenderFunction`
10
+ - New method now returns the render function signature Eleventy expects with all error handling logic built in, eliminating the need for a separate render function handler
11
+
3
12
  ## 5.4.2
4
13
 
5
14
  ### Patch Changes
package/dist/plugin.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  /// <reference types="node" />
2
- import * as ventojs from "ventojs";
2
+ import * as ventojs$1 from "ventojs";
3
3
  import _UserConfig from "@11ty/eleventy/UserConfig";
4
4
  import { Plugin } from "ventojs/core/environment.js";
5
5
 
6
- //#region node_modules/.pnpm/11ty.ts@0.0.7_@11ty+eleventy@3.1.2/node_modules/11ty.ts/dist/index.d.ts
6
+ //#region node_modules/.pnpm/11ty.ts@0.0.7_@11ty+eleventy@3.1.5/node_modules/11ty.ts/dist/index.d.ts
7
7
  declare global {
8
8
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
9
9
  interface SymbolConstructor {
@@ -96,7 +96,7 @@ interface PluginOptions {
96
96
  * includes: eleventyConfig.directories.includes
97
97
  * }
98
98
  */
99
- ventoOptions: ventojs.Options;
99
+ ventoOptions: ventojs$1.Options;
100
100
  }
101
101
  //#endregion
102
102
  //#region src/plugin.d.ts
package/dist/plugin.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import path from "node:path";
2
2
  import autotrimPlugin, { defaultTags } from "ventojs/plugins/auto_trim.js";
3
- import createVentoEnv from "ventojs";
3
+ import ventojs from "ventojs";
4
4
  import { VentoError } from "ventojs/core/errors.js";
5
5
  import { styleText } from "node:util";
6
6
  import createDebugger from "debug";
7
7
  //#region src/utils/create-vento-tag.ts
8
8
  function createVentoTag(tagInfo) {
9
9
  let LEVEL = 1;
10
- const IS_PAIRED = tagInfo.group === "pairedShortcodes";
10
+ const IS_PAIRED = tagInfo.group === "paired";
11
11
  const tag = (env, token, output, tokens) => {
12
12
  const code = token[1];
13
13
  if (!(code === tagInfo.name || code.startsWith(`${tagInfo.name} `))) return;
@@ -16,7 +16,7 @@ function createVentoTag(tagInfo) {
16
16
  page: ${dataVarname}.page,
17
17
  eleventy: ${dataVarname}.eleventy
18
18
  }`;
19
- const fn = `__env.utils.eleventyFunctions.${tagInfo.group}.${tagInfo.name}`;
19
+ const fn = `__env.utils.eleventyFunctions.get('${tagInfo.group}:${tagInfo.name}')`;
20
20
  const args = [code.replace(tagInfo.name, "").trim()];
21
21
  const compiled = [];
22
22
  if (IS_PAIRED) {
@@ -102,14 +102,16 @@ function locateInCode(lines, position) {
102
102
  //#endregion
103
103
  //#region src/engine.ts
104
104
  function createVentoEngine(options) {
105
- const env = createVentoEnv(options);
106
- env.utils.eleventyFunctions = {
107
- shortcodes: {},
108
- pairedShortcodes: {}
109
- };
105
+ const env = ventojs(options);
106
+ /**
107
+ * Load plugins into Vento environment
108
+ */
110
109
  function loadPlugins(plugins) {
111
110
  for (const plugin of plugins) env.use(plugin);
112
111
  }
112
+ /**
113
+ * Load filters into Vento environment
114
+ */
113
115
  function loadFilters(filters) {
114
116
  for (const [name, fn] of Object.entries(filters)) env.filters[name] = function(...args) {
115
117
  const { page, eleventy } = this.data;
@@ -120,61 +122,67 @@ function createVentoEngine(options) {
120
122
  }, args);
121
123
  };
122
124
  }
123
- function loadShortcodes(shortcodes) {
125
+ /**
126
+ * Load shortcodes (tags) into Vento environment
127
+ */
128
+ function loadShortcodes(group, shortcodes) {
129
+ if (!(env.utils.eleventyFunctions instanceof Map)) env.utils.eleventyFunctions = /* @__PURE__ */ new Map();
124
130
  for (const [name, fn] of Object.entries(shortcodes)) {
125
- env.utils.eleventyFunctions.shortcodes[name] = fn;
126
- const shortcodeTag = createVentoTag({
131
+ env.utils.eleventyFunctions.set(`${group}:${name}`, fn);
132
+ env.tags.push(createVentoTag({
127
133
  name,
128
- group: "shortcodes"
129
- });
130
- env.tags.push(shortcodeTag);
134
+ group
135
+ }));
131
136
  }
132
137
  }
133
- function loadPairedShortcodes(pairedShortcodes) {
134
- for (const [name, fn] of Object.entries(pairedShortcodes)) {
135
- env.utils.eleventyFunctions.pairedShortcodes[name] = fn;
136
- const shortcodeTag = createVentoTag({
137
- name,
138
- group: "pairedShortcodes"
139
- });
140
- env.tags.push(shortcodeTag);
138
+ /**
139
+ * Clear one or more items from Vento's cache
140
+ */
141
+ function removeCachedItems(items) {
142
+ for (let item of items) {
143
+ item = path.normalize(item);
144
+ debug.cache("Delete cache entry for %s", item);
145
+ env.cache.delete(item);
141
146
  }
142
147
  }
143
- async function getTemplateFunction(source, file, useVentoCache = true) {
148
+ /**
149
+ * Given a source string and file, compile or get a cached template function,
150
+ * then produce an Eleventy render function for it and return it.
151
+ */
152
+ async function getRenderFunction(source, file, options) {
153
+ debug.main("Getting render function for `%s`", file);
144
154
  let template = await env.cache.get(file);
145
- if (template?.source === source) {
146
- debug.cache("Cache HIT for `%s`, using precompiled template", file);
147
- return template;
148
- }
149
- try {
150
- debug.cache("Cache MISS for `%s`, will compile new template function", file);
151
- template = env.compile(source, file);
152
- if (useVentoCache) env.cache.set(file, template);
153
- return template;
154
- } catch (error) {
155
- if (error instanceof VentoError) throw await EleventyVentoError.createFromContext(error);
156
- throw error;
155
+ if (template?.source === source) debug.cache("Cache HIT for `%s`, using precompiled template", file);
156
+ else {
157
+ try {
158
+ debug.cache("Cache MISS for `%s`, will compile new template function", file);
159
+ template = env.compile(source, file);
160
+ } catch (error) {
161
+ if (error instanceof VentoError) throw await EleventyVentoError.createFromContext(error);
162
+ throw error;
163
+ }
164
+ if (options?.cache !== false) env.cache.set(file, template);
157
165
  }
166
+ const render = async (data) => {
167
+ try {
168
+ debug.render("Rendering %s", file);
169
+ const { content } = await template(data);
170
+ return content;
171
+ } catch (error) {
172
+ if (error instanceof VentoError) throw await EleventyVentoError.createFromContext(error);
173
+ throw error;
174
+ }
175
+ };
176
+ return render;
158
177
  }
159
178
  return {
160
- cache: env.cache,
161
179
  loadPlugins,
162
180
  loadFilters,
163
181
  loadShortcodes,
164
- loadPairedShortcodes,
165
- getTemplateFunction
182
+ removeCachedItems,
183
+ getRenderFunction
166
184
  };
167
185
  }
168
- async function renderVentoTemplate(template, data, from) {
169
- try {
170
- debug.render("Rendering `%s`", from);
171
- const { content } = await template(data);
172
- return content;
173
- } catch (error) {
174
- if (error instanceof VentoError) throw await EleventyVentoError.createFromContext(error);
175
- throw error;
176
- }
177
- }
178
186
  //#endregion
179
187
  //#region src/plugin.ts
180
188
  function VentoPlugin(eleventyConfig, userOptions) {
@@ -219,20 +227,14 @@ function VentoPlugin(eleventyConfig, userOptions) {
219
227
  }
220
228
  if (options.shortcodes) {
221
229
  debug.main("Loading shortcodes: %o", shortcodes);
222
- engine.loadShortcodes(shortcodes);
230
+ engine.loadShortcodes("single", shortcodes);
223
231
  }
224
232
  if (options.pairedShortcodes) {
225
233
  debug.main("Loading paired shortcodes: %o", pairedShortcodes);
226
- engine.loadPairedShortcodes(pairedShortcodes);
234
+ engine.loadShortcodes("paired", pairedShortcodes);
227
235
  }
228
- debug.main("Registering Vento cache handler on eleventy.beforeWatch event");
229
- eleventyConfig.on("eleventy.beforeWatch", async (updatedFiles) => {
230
- for (let file of updatedFiles) {
231
- file = path.normalize(file);
232
- debug.cache("Delete cache entry for %s", file);
233
- engine.cache.delete(file);
234
- }
235
- });
236
+ debug.main("Adding Vento cache handler for eleventy.beforeWatch event");
237
+ eleventyConfig.on("eleventy.beforeWatch", engine.removeCachedItems);
236
238
  debug.main("Registering .vto as a template format");
237
239
  eleventyConfig.addTemplateFormats("vto");
238
240
  debug.main("Registering .vto extension with eleventy");
@@ -241,16 +243,12 @@ function VentoPlugin(eleventyConfig, userOptions) {
241
243
  read: true,
242
244
  async compile(inputContent, inputPath) {
243
245
  inputPath = path.normalize(inputPath);
244
- debug.main("Getting template function for `%s`", inputPath);
245
- const template = await engine.getTemplateFunction(inputContent, inputPath, false);
246
- return async (data) => await renderVentoTemplate(template, data, inputPath);
246
+ return await engine.getRenderFunction(inputContent, inputPath, { cache: false });
247
247
  },
248
248
  compileOptions: { async permalink(permalinkContent, inputPath) {
249
249
  if (typeof permalinkContent !== "string" || !/\{\{\s+.+\s+\}\}/.test(permalinkContent)) return permalinkContent;
250
250
  inputPath = "EleventyVentoDynamicPermalink:".concat(path.normalize(inputPath));
251
- debug.main("Getting template function for `%s`", inputPath);
252
- const template = await engine.getTemplateFunction(permalinkContent, inputPath);
253
- return async (data) => await renderVentoTemplate(template, data, inputPath);
251
+ return await engine.getRenderFunction(permalinkContent, inputPath);
254
252
  } }
255
253
  });
256
254
  debug.main("eleventy-plugin-vento initialized");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-plugin-vento",
3
- "version": "5.4.2",
3
+ "version": "5.4.3",
4
4
  "description": "Adds support for the Vento templating language to Eleventy.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -41,20 +41,20 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "11ty.ts": "0.0.7",
44
- "@11ty/eleventy": "3.1.2",
44
+ "@11ty/eleventy": "3.1.5",
45
45
  "@changesets/cli": "2.30.0",
46
46
  "@eslint/js": "10.0.1",
47
- "@types/debug": "4.1.12",
47
+ "@types/debug": "4.1.13",
48
48
  "@types/node": "24.12.0",
49
- "eslint": "10.0.3",
49
+ "eslint": "10.1.0",
50
50
  "eslint-config-prettier": "10.1.8",
51
- "eslint-plugin-unicorn": "63.0.0",
51
+ "eslint-plugin-unicorn": "64.0.0",
52
52
  "globals": "17.4.0",
53
- "knip": "5.86.0",
53
+ "knip": "6.0.6",
54
54
  "prettier": "3.8.1",
55
- "tsdown": "0.21.1",
56
- "typescript": "5.9.3",
57
- "typescript-eslint": "8.57.0",
58
- "vitest": "4.0.18"
55
+ "tsdown": "0.21.4",
56
+ "typescript": "6.0.2",
57
+ "typescript-eslint": "8.57.2",
58
+ "vitest": "4.1.2"
59
59
  }
60
60
  }