@11ty/eleventy-plugin-webc 0.8.0 → 0.8.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@11ty/eleventy-plugin-webc",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "WebC support for Eleventy adds for Single File Web Components",
5
5
  "main": "eleventyWebcPlugin.js",
6
6
  "scripts": {
@@ -14,7 +14,7 @@
14
14
  "node": ">=14.18"
15
15
  },
16
16
  "11ty": {
17
- "compatibility": ">=2.0.0-canary.17"
17
+ "compatibility": ">=2.0.0-canary.19"
18
18
  },
19
19
  "funding": {
20
20
  "type": "opencollective",
@@ -38,10 +38,10 @@
38
38
  ]
39
39
  },
40
40
  "dependencies": {
41
- "@11ty/eleventy": "^2.0.0-canary.18",
41
+ "@11ty/eleventy": "^2.0.0-canary.19",
42
42
  "@11ty/webc": "^0.8.0"
43
43
  },
44
44
  "devDependencies": {
45
- "ava": "^5.0.1"
45
+ "ava": "^5.1.0"
46
46
  }
47
47
  }
@@ -4,7 +4,6 @@ const { EleventyRenderPlugin } = require("@11ty/eleventy");
4
4
  const CompileString = EleventyRenderPlugin.String;
5
5
 
6
6
  const CodeManager = require("./codeManager.js");
7
- const WebCIncremental = require("./incremental.js");
8
7
  const BundleAssetsToContent = require("./bundleAssets.js");
9
8
 
10
9
  function relativePath(inputPath, newGlob) {
@@ -25,9 +24,9 @@ module.exports = function(eleventyConfig, options = {}) {
25
24
 
26
25
  let cssManager = new CodeManager();
27
26
  let jsManager = new CodeManager();
28
- let incremental = new WebCIncremental();
27
+
28
+ let _WebC;
29
29
  let componentsMap = false; // cache the glob search
30
- let componentsMapKey;
31
30
  let moduleScript;
32
31
 
33
32
  eleventyConfig.on("eleventy.before", async () => {
@@ -37,11 +36,10 @@ module.exports = function(eleventyConfig, options = {}) {
37
36
  // For ESM in CJS
38
37
  let { WebC, ModuleScript } = await import("@11ty/webc");
39
38
  moduleScript = ModuleScript;
40
- incremental.setWebC(WebC);
39
+ _WebC = WebC;
41
40
 
42
41
  if(options.components) {
43
42
  componentsMap = WebC.getComponentsMap(options.components);
44
- componentsMapKey = JSON.stringify(componentsMap);
45
43
  }
46
44
  });
47
45
 
@@ -63,37 +61,10 @@ module.exports = function(eleventyConfig, options = {}) {
63
61
  eleventyConfig.addFilter(options.filters.js, (url, bucket) => getJs(url, bucket));
64
62
  }
65
63
 
66
- eleventyConfig.on("eleventy.layouts", layouts => {
67
- incremental.setLayouts(layouts);
68
- });
69
-
70
64
  eleventyConfig.addExtension("webc", {
71
65
  outputFileExtension: "html",
72
66
 
73
- isIncrementalMatch: function (incrementalFilePath) {
74
- // Eleventy layouts don’t appear directly in the WebC component graph, so we use the `eleventy.layouts` map here
75
- if(incremental.isFileUsingLayout(this.inputPath, incrementalFilePath)) {
76
- return true;
77
- }
78
-
79
- let {page, setup} = incremental.get(this.inputPath);
80
-
81
- if(page && setup) {
82
- let components = page.getComponents(setup);
83
- if(components.includes(incrementalFilePath)) {
84
- return true;
85
- }
86
- }
87
-
88
- return false;
89
- },
90
-
91
67
  compileOptions: {
92
- cache: true,
93
- getCacheKey: function(contents, inputPath) {
94
- // if global components change, recompile!
95
- return contents + inputPath + componentsMapKey;
96
- },
97
68
  permalink: function(contents, inputPath) {
98
69
  return (data) => {
99
70
  return moduleScript.evaluateScript("permalink", contents, {
@@ -105,7 +76,10 @@ module.exports = function(eleventyConfig, options = {}) {
105
76
  },
106
77
 
107
78
  compile: async function(inputContent, inputPath) {
108
- let page = incremental.add(inputContent, inputPath);
79
+ let page = new _WebC();
80
+
81
+ page.setBundlerMode(true);
82
+ page.setContent(inputContent, inputPath);
109
83
 
110
84
  if(componentsMap) {
111
85
  page.defineComponents(componentsMap);
@@ -138,20 +112,19 @@ module.exports = function(eleventyConfig, options = {}) {
138
112
  let setupObject = {
139
113
  data,
140
114
  };
115
+
141
116
  if(data.webc?.components) {
142
- let WebC = incremental.webc;
143
- setupObject.components = WebC.getComponentsMap(relativePath(data.page.inputPath, data.webc.components));
117
+ setupObject.components = _WebC.getComponentsMap(relativePath(data.page.inputPath, data.webc.components));
144
118
  }
145
119
 
146
120
  if(options.before && typeof options.before === "function") {
147
121
  await options.before(page);
148
122
  }
149
123
 
150
- let setup = await page.setup(setupObject);
151
- incremental.addSetup(inputPath, setup);
124
+ let { html, css, js, buckets, components } = await page.compile(setupObject);
152
125
 
153
- let { ast, serializer } = setup;
154
- let { html, css, js, buckets } = await serializer.compile(ast);
126
+ // 2.0.0-canary.19+
127
+ this.addDependencies(inputPath, components);
155
128
 
156
129
  cssManager.addToPage(data.page.url, css, "default");
157
130
 
@@ -1,54 +0,0 @@
1
- class WebCIncremental {
2
- constructor() {
3
- this.pages = {};
4
- this.setups = {};
5
- }
6
-
7
- setWebC(cls) {
8
- this.webc = cls;
9
- }
10
-
11
- setLayouts(layouts) {
12
- this.layouts = layouts;
13
- }
14
-
15
- isFileUsingLayout(templateFilePath, layoutFilePath) {
16
- if(this.layouts && this.layouts[layoutFilePath] && this.layouts[layoutFilePath].includes(templateFilePath)) {
17
- return true;
18
- }
19
- return false;
20
- }
21
-
22
- add(inputContent, inputPath) {
23
- let WebC = this.webc;
24
- let page = new WebC();
25
-
26
- page.setBundlerMode(true);
27
- page.setContent(inputContent, inputPath);
28
-
29
- this.pages[inputPath] = page;
30
-
31
- return page;
32
- }
33
-
34
- addSetup(inputPath, setup) {
35
- this.setups[inputPath] = setup;
36
- }
37
-
38
- get(inputPath) {
39
- let setup = this.setups[inputPath];
40
- let components = setup.serializer.components;
41
-
42
- if(setup && components) {
43
- setup.serializer.restorePreparsedComponents(components);
44
- }
45
-
46
- return {
47
- page: this.pages[inputPath],
48
- setup,
49
- components,
50
- }
51
- }
52
- }
53
-
54
- module.exports = WebCIncremental;