eleventy-plugin-vento 3.0.1 → 3.0.2

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,17 @@
1
1
  # eleventy-plugin-vento
2
2
 
3
+ ## 3.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - e46ce6e: Integrate eleventy and vento caching.
8
+
9
+ There have been a few issues around managing Vento's cache that have yielded uninteded results when compiling templates (ie #10, #34). This update integrates Vento's cache with Eleventy's custom extension API.
10
+
11
+ This means that whether running Eleventy in `--serve` mode or compiling dynamic permalinks, stale cache data actually gets removed so Vento can compile the template from source again.
12
+
13
+ Raise any issues if caching behavior continues to be an issue!
14
+
3
15
  ## 3.0.1
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-plugin-vento",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Adds support for the Vento templating language to Eleventy.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,15 +35,15 @@
35
35
  "ventojs": "1.12.10"
36
36
  },
37
37
  "devDependencies": {
38
- "@11ty/eleventy": "3.0.0-beta.1",
39
- "@changesets/cli": "2.27.8",
40
- "eslint": "9.11.1",
38
+ "@11ty/eleventy": "3.0.0",
39
+ "@changesets/cli": "2.27.9",
40
+ "eslint": "9.12.0",
41
41
  "eslint-config-flat-gitignore": "0.3.0",
42
42
  "eslint-config-prettier": "9.1.0",
43
- "eslint-plugin-unicorn": "55.0.0",
44
- "globals": "15.9.0",
45
- "vitest": "2.1.1",
46
- "zx": "8.1.8"
43
+ "eslint-plugin-unicorn": "56.0.0",
44
+ "globals": "15.11.0",
45
+ "vitest": "2.1.2",
46
+ "zx": "8.1.9"
47
47
  },
48
48
  "prettier": {
49
49
  "bracketSameLine": true,
@@ -54,7 +54,7 @@
54
54
  "scripts": {
55
55
  "test": "vitest --run",
56
56
  "lint": "eslint '**/*.js'",
57
- "ci:version": "npm audit signatures && changeset version && pnpm install --no-frozen-lockfile",
57
+ "ci:version": "changeset version && pnpm install --no-frozen-lockfile",
58
58
  "ci:publish": "changeset publish",
59
59
  "ci:generate-changesets": "node ./scripts/generate-changesets.js",
60
60
  "format": "pnpm dlx prettier --config ./package.json --write ."
package/src/engine.js CHANGED
@@ -25,9 +25,14 @@ export function createVentoEngine(options) {
25
25
  env.utils._11ty = { ctx: {}, functions: {} };
26
26
 
27
27
  return {
28
- /** @param {string?} key */
29
- emptyCache(key) {
30
- return key ? env.cache.delete(key) : env.cache.clear();
28
+ /** @param {string} path */
29
+ getCachedSource(path) {
30
+ return env.cache.get(path)?.source;
31
+ },
32
+
33
+ /** @param {string} path */
34
+ emptyCache(path) {
35
+ return path ? env.cache.delete(path) : env.cache.clear();
31
36
  },
32
37
 
33
38
  /** @param {import('ventojs/src/environment.js').Plugin[]} plugins */
@@ -63,20 +68,13 @@ export function createVentoEngine(options) {
63
68
  }
64
69
  },
65
70
 
66
- /**
67
- * @param {PageData} data
68
- * @param {string} content
69
- * @param {string} path
70
- */
71
- async process(data, content, path) {
71
+ /** @param {{data: PageData, source: string, path: string}} input */
72
+ async process(input) {
72
73
  // Reload context
73
- this.loadContext(data);
74
+ this.loadContext(input.data);
74
75
 
75
76
  // Process the templates
76
- const result = await env.runString(content, data, path);
77
-
78
- // Clear the cache for this path if the input doesn't match
79
- if (data.page?.rawInput !== content) env.cache.clear(path);
77
+ const result = await env.runString(input.source, input.data, input.path);
80
78
 
81
79
  return result.content;
82
80
  },
package/src/index.js CHANGED
@@ -113,17 +113,25 @@ export function VentoPlugin(eleventyConfig, userOptions) {
113
113
 
114
114
  // Main compile function
115
115
  async compile(inputContent, inputPath) {
116
- return async (data) => engine.process(data, inputContent, inputPath);
116
+ return async (data) => await engine.process({ data, source: inputContent, path: inputPath });
117
117
  },
118
118
 
119
119
  // Custom permalink compilation
120
120
  compileOptions: {
121
+ cache: true,
122
+ getCacheKey(inputContent, inputPath) {
123
+ if (engine.getCachedSource(inputPath) !== inputContent) {
124
+ engine.emptyCache(inputPath);
125
+ }
126
+
127
+ return engine.getCachedSource(inputPath);
128
+ },
121
129
  permalink(linkContents) {
122
130
  if (typeof linkContents !== 'string') {
123
131
  return linkContents;
124
132
  }
125
133
 
126
- return async (data) => engine.process(data, linkContents);
134
+ return async (data) => engine.process({ data, source: linkContents });
127
135
  },
128
136
  },
129
137
  });