@11ty/eleventy-plugin-webc 0.6.0 → 0.7.0

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.
@@ -15,7 +15,7 @@ module.exports = function(eleventyConfig, options = {}) {
15
15
  }, options.filters);
16
16
 
17
17
  options = Object.assign({
18
- components: false, // glob for no-import global components
18
+ components: "_components/**/*.webc", // glob for no-import global components
19
19
  useTransform: false, // global transform
20
20
  transformData: {}, // extra global data for transforms specifically
21
21
  }, options);
@@ -25,7 +25,9 @@ module.exports = function(eleventyConfig, options = {}) {
25
25
  if(options.components) {
26
26
  eleventyConfig.addWatchTarget(options.components);
27
27
 
28
- // TODO add to eleventy ignores (if not in _includes folder)
28
+ // Opt-out of Eleventy to process components
29
+ // Note that Eleventy’s default ignores already have _includes/**
30
+ eleventyConfig.ignores.add(options.components);
29
31
  }
30
32
 
31
33
  templatePlugin(eleventyConfig, options);
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@11ty/eleventy-plugin-webc",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "WebC support for Eleventy adds for Single File Web Components",
5
5
  "main": "eleventyWebcPlugin.js",
6
6
  "scripts": {
7
- "test": "npx ava"
7
+ "test": "npx ava --no-worker-threads"
8
8
  },
9
9
  "publishConfig": {
10
10
  "access": "public"
@@ -14,7 +14,7 @@
14
14
  "node": ">=14.18"
15
15
  },
16
16
  "11ty": {
17
- "compatibility": ">=2.0.0-canary.16"
17
+ "compatibility": ">=2.0.0-canary.17"
18
18
  },
19
19
  "funding": {
20
20
  "type": "opencollective",
@@ -38,8 +38,8 @@
38
38
  ]
39
39
  },
40
40
  "dependencies": {
41
- "@11ty/eleventy": "^2.0.0-canary.16",
42
- "@11ty/webc": "^0.6.0"
41
+ "@11ty/eleventy": "^2.0.0-canary.17",
42
+ "@11ty/webc": "^0.7.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "ava": "^5.0.1"
@@ -1,7 +1,7 @@
1
1
  const path = require("path");
2
2
 
3
3
  const { EleventyRenderPlugin } = require("@11ty/eleventy");
4
- const EleventyRenderManager = EleventyRenderPlugin.RenderManager;
4
+ const CompileString = EleventyRenderPlugin.String;
5
5
 
6
6
  const CodeManager = require("./codeManager.js");
7
7
  const WebCIncremental = require("./incremental.js");
@@ -22,19 +22,20 @@ function relativePath(inputPath, newGlob) {
22
22
  module.exports = function(eleventyConfig, options = {}) {
23
23
  eleventyConfig.addTemplateFormats("webc");
24
24
 
25
- let renderManager = new EleventyRenderManager();
26
25
  let cssManager = new CodeManager();
27
26
  let jsManager = new CodeManager();
28
27
  let incremental = new WebCIncremental();
29
28
  let componentsMap = false; // cache the glob search
30
29
  let componentsMapKey;
30
+ let moduleScript;
31
31
 
32
32
  eleventyConfig.on("eleventy.before", async () => {
33
33
  cssManager.reset();
34
34
  jsManager.reset();
35
35
 
36
36
  // For ESM in CJS
37
- let { WebC } = await import("@11ty/webc");
37
+ let { WebC, ModuleScript } = await import("@11ty/webc");
38
+ moduleScript = ModuleScript;
38
39
  incremental.setWebC(WebC);
39
40
 
40
41
  if(options.components) {
@@ -72,6 +73,7 @@ module.exports = function(eleventyConfig, options = {}) {
72
73
  }
73
74
 
74
75
  let {page, setup} = incremental.get(this.inputPath);
76
+
75
77
  if(page && setup) {
76
78
  let components = page.getComponents(setup);
77
79
  if(components.includes(incrementalFilePath)) {
@@ -87,6 +89,14 @@ module.exports = function(eleventyConfig, options = {}) {
87
89
  getCacheKey: function(contents, inputPath) {
88
90
  // if global components change, recompile!
89
91
  return contents + inputPath + componentsMapKey;
92
+ },
93
+ permalink: function(contents, inputPath) {
94
+ return (data) => {
95
+ return moduleScript.evaluateScript("permalink", contents, {
96
+ ...this,
97
+ ...data,
98
+ });
99
+ }
90
100
  }
91
101
  },
92
102
 
@@ -112,8 +122,10 @@ module.exports = function(eleventyConfig, options = {}) {
112
122
  page.setTransform("11ty", async function(content) {
113
123
  let syntax = this["11ty:type"];
114
124
  if(syntax) {
115
- let fn = await renderManager.compile(content, syntax);
116
- return renderManager.render(fn, this, {});
125
+ let fn = await CompileString(content, syntax, {
126
+ templateConfig: eleventyConfig
127
+ });
128
+ return fn(this);
117
129
  }
118
130
  return content;
119
131
  });
@@ -125,6 +137,10 @@ module.exports = function(eleventyConfig, options = {}) {
125
137
  setupObject.components = WebC.getComponentsMap(relativePath(data.page.inputPath, data.webc.components));
126
138
  }
127
139
 
140
+ if(options.before && typeof options.before === "function") {
141
+ await options.before(page);
142
+ }
143
+
128
144
  let setup = await page.setup(setupObject);
129
145
  incremental.addSetup(inputPath, setup);
130
146
 
@@ -26,10 +26,8 @@ class WebCIncremental {
26
26
  // Explicitly disable bundler mode for layouts
27
27
  if(this.layouts && this.layouts[inputPath]) {
28
28
  page.setBundlerMode(false);
29
- page.setReprocessingMode(false);
30
29
  } else {
31
30
  page.setBundlerMode(true);
32
- page.setReprocessingMode(true);
33
31
  }
34
32
 
35
33
  page.setContent(inputContent, inputPath);