eleventy-plugin-vento 5.4.1 → 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,20 @@
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
+
12
+ ## 5.4.2
13
+
14
+ ### Patch Changes
15
+
16
+ - 3ae32e5: Revise error creation method to explicitly check for `undefined` in `ctx.position` and `ctx.file` as opposed to coercing to booleans. This resolves edge cases where errors thrown with a position of `0` would incorrectly log position warnings.
17
+
3
18
  ## 5.4.1
4
19
 
5
20
  ### 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,14 +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
-
8
7
  //#region src/utils/create-vento-tag.ts
9
8
  function createVentoTag(tagInfo) {
10
9
  let LEVEL = 1;
11
- const IS_PAIRED = tagInfo.group === "pairedShortcodes";
10
+ const IS_PAIRED = tagInfo.group === "paired";
12
11
  const tag = (env, token, output, tokens) => {
13
12
  const code = token[1];
14
13
  if (!(code === tagInfo.name || code.startsWith(`${tagInfo.name} `))) return;
@@ -17,7 +16,7 @@ function createVentoTag(tagInfo) {
17
16
  page: ${dataVarname}.page,
18
17
  eleventy: ${dataVarname}.eleventy
19
18
  }`;
20
- const fn = `__env.utils.eleventyFunctions.${tagInfo.group}.${tagInfo.name}`;
19
+ const fn = `__env.utils.eleventyFunctions.get('${tagInfo.group}:${tagInfo.name}')`;
21
20
  const args = [code.replace(tagInfo.name, "").trim()];
22
21
  const compiled = [];
23
22
  if (IS_PAIRED) {
@@ -32,7 +31,6 @@ function createVentoTag(tagInfo) {
32
31
  };
33
32
  return Object.defineProperty(tag, "name", { value: `${tagInfo.name}_${IS_PAIRED ? `EleventyPairedTag` : `EleventyTag`}` });
34
33
  }
35
-
36
34
  //#endregion
37
35
  //#region src/utils/logging.ts
38
36
  const debug = {
@@ -50,7 +48,6 @@ const debug = {
50
48
  function warn(...messages) {
51
49
  for (const message of messages) console.error(styleText("gray", "[warning]"), styleText("yellow", message));
52
50
  }
53
-
54
51
  //#endregion
55
52
  //#region src/utils/errors.ts
56
53
  const LINE_TERMINATOR = /(\r\n?|[\n\u2028\u2029])/;
@@ -62,7 +59,7 @@ var EleventyVentoError = class extends Error {
62
59
  static async createFromContext(error) {
63
60
  const ctx = await error.getContext();
64
61
  const err = new this("An unknown error occured processing Vento templates", ctx, error);
65
- if (!ctx.position || !ctx.file) warn(`A \`${ctx.type}\` was thrown, but the exact position within the source code cannot be obtained`, "Use DEBUG=\"Eleventy:Vento*\" to view raw `ErrorContext` information");
62
+ if (ctx.position === void 0 || ctx.file === void 0) warn(`A \`${ctx.type}\` was thrown, but the exact position within the source code cannot be obtained`, "Use DEBUG=\"Eleventy:Vento*\" to view raw `ErrorContext` information");
66
63
  debug.error("Received `ErrorContext` from Vento: %O", ctx);
67
64
  if (ctx.file === void 0) return err;
68
65
  err.message = `${ctx.type} in ${ctx.file}`;
@@ -102,18 +99,19 @@ function locateInCode(lines, position) {
102
99
  }
103
100
  throw new Error(`Positon ${position} is out of bounds for the provided source`);
104
101
  }
105
-
106
102
  //#endregion
107
103
  //#region src/engine.ts
108
104
  function createVentoEngine(options) {
109
- const env = createVentoEnv(options);
110
- env.utils.eleventyFunctions = {
111
- shortcodes: {},
112
- pairedShortcodes: {}
113
- };
105
+ const env = ventojs(options);
106
+ /**
107
+ * Load plugins into Vento environment
108
+ */
114
109
  function loadPlugins(plugins) {
115
110
  for (const plugin of plugins) env.use(plugin);
116
111
  }
112
+ /**
113
+ * Load filters into Vento environment
114
+ */
117
115
  function loadFilters(filters) {
118
116
  for (const [name, fn] of Object.entries(filters)) env.filters[name] = function(...args) {
119
117
  const { page, eleventy } = this.data;
@@ -124,62 +122,67 @@ function createVentoEngine(options) {
124
122
  }, args);
125
123
  };
126
124
  }
127
- 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();
128
130
  for (const [name, fn] of Object.entries(shortcodes)) {
129
- env.utils.eleventyFunctions.shortcodes[name] = fn;
130
- const shortcodeTag = createVentoTag({
131
+ env.utils.eleventyFunctions.set(`${group}:${name}`, fn);
132
+ env.tags.push(createVentoTag({
131
133
  name,
132
- group: "shortcodes"
133
- });
134
- env.tags.push(shortcodeTag);
134
+ group
135
+ }));
135
136
  }
136
137
  }
137
- function loadPairedShortcodes(pairedShortcodes) {
138
- for (const [name, fn] of Object.entries(pairedShortcodes)) {
139
- env.utils.eleventyFunctions.pairedShortcodes[name] = fn;
140
- const shortcodeTag = createVentoTag({
141
- name,
142
- group: "pairedShortcodes"
143
- });
144
- 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);
145
146
  }
146
147
  }
147
- 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);
148
154
  let template = await env.cache.get(file);
149
- if (template?.source === source) {
150
- debug.cache("Cache HIT for `%s`, using precompiled template", file);
151
- return template;
152
- }
153
- try {
154
- debug.cache("Cache MISS for `%s`, will compile new template function", file);
155
- template = env.compile(source, file);
156
- if (useVentoCache) env.cache.set(file, template);
157
- return template;
158
- } catch (error) {
159
- if (error instanceof VentoError) throw await EleventyVentoError.createFromContext(error);
160
- 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);
161
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;
162
177
  }
163
178
  return {
164
- cache: env.cache,
165
179
  loadPlugins,
166
180
  loadFilters,
167
181
  loadShortcodes,
168
- loadPairedShortcodes,
169
- getTemplateFunction
182
+ removeCachedItems,
183
+ getRenderFunction
170
184
  };
171
185
  }
172
- async function renderVentoTemplate(template, data, from) {
173
- try {
174
- debug.render("Rendering `%s`", from);
175
- const { content } = await template(data);
176
- return content;
177
- } catch (error) {
178
- if (error instanceof VentoError) throw await EleventyVentoError.createFromContext(error);
179
- throw error;
180
- }
181
- }
182
-
183
186
  //#endregion
184
187
  //#region src/plugin.ts
185
188
  function VentoPlugin(eleventyConfig, userOptions) {
@@ -224,20 +227,14 @@ function VentoPlugin(eleventyConfig, userOptions) {
224
227
  }
225
228
  if (options.shortcodes) {
226
229
  debug.main("Loading shortcodes: %o", shortcodes);
227
- engine.loadShortcodes(shortcodes);
230
+ engine.loadShortcodes("single", shortcodes);
228
231
  }
229
232
  if (options.pairedShortcodes) {
230
233
  debug.main("Loading paired shortcodes: %o", pairedShortcodes);
231
- engine.loadPairedShortcodes(pairedShortcodes);
234
+ engine.loadShortcodes("paired", pairedShortcodes);
232
235
  }
233
- debug.main("Registering Vento cache handler on eleventy.beforeWatch event");
234
- eleventyConfig.on("eleventy.beforeWatch", async (updatedFiles) => {
235
- for (let file of updatedFiles) {
236
- file = path.normalize(file);
237
- debug.cache("Delete cache entry for %s", file);
238
- engine.cache.delete(file);
239
- }
240
- });
236
+ debug.main("Adding Vento cache handler for eleventy.beforeWatch event");
237
+ eleventyConfig.on("eleventy.beforeWatch", engine.removeCachedItems);
241
238
  debug.main("Registering .vto as a template format");
242
239
  eleventyConfig.addTemplateFormats("vto");
243
240
  debug.main("Registering .vto extension with eleventy");
@@ -246,20 +243,15 @@ function VentoPlugin(eleventyConfig, userOptions) {
246
243
  read: true,
247
244
  async compile(inputContent, inputPath) {
248
245
  inputPath = path.normalize(inputPath);
249
- debug.main("Getting template function for `%s`", inputPath);
250
- const template = await engine.getTemplateFunction(inputContent, inputPath, false);
251
- return async (data) => await renderVentoTemplate(template, data, inputPath);
246
+ return await engine.getRenderFunction(inputContent, inputPath, { cache: false });
252
247
  },
253
248
  compileOptions: { async permalink(permalinkContent, inputPath) {
254
249
  if (typeof permalinkContent !== "string" || !/\{\{\s+.+\s+\}\}/.test(permalinkContent)) return permalinkContent;
255
250
  inputPath = "EleventyVentoDynamicPermalink:".concat(path.normalize(inputPath));
256
- debug.main("Getting template function for `%s`", inputPath);
257
- const template = await engine.getTemplateFunction(permalinkContent, inputPath);
258
- return async (data) => await renderVentoTemplate(template, data, inputPath);
251
+ return await engine.getRenderFunction(permalinkContent, inputPath);
259
252
  } }
260
253
  });
261
254
  debug.main("eleventy-plugin-vento initialized");
262
255
  }
263
-
264
256
  //#endregion
265
- export { VentoPlugin };
257
+ export { VentoPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-plugin-vento",
3
- "version": "5.4.1",
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",
45
- "@changesets/cli": "2.29.8",
44
+ "@11ty/eleventy": "3.1.5",
45
+ "@changesets/cli": "2.30.0",
46
46
  "@eslint/js": "10.0.1",
47
- "@types/debug": "4.1.12",
48
- "@types/node": "24.11.0",
49
- "eslint": "10.0.2",
47
+ "@types/debug": "4.1.13",
48
+ "@types/node": "24.12.0",
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.85.0",
53
+ "knip": "6.0.6",
54
54
  "prettier": "3.8.1",
55
- "tsdown": "0.20.3",
56
- "typescript": "5.9.3",
57
- "typescript-eslint": "8.56.1",
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
  }