@bookshop/hugo-engine 3.4.1 → 3.5.0-alpha.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.
Files changed (23) hide show
  1. package/.nyc_output/processinfo/0021c648-0cec-4195-a0dc-985b510e7b75.json +1 -0
  2. package/.nyc_output/processinfo/437debd8-2dd5-4b95-b772-f5bba688f936.json +1 -0
  3. package/.nyc_output/processinfo/4bd04565-b332-432b-8129-e9fed05110a9.json +1 -0
  4. package/.nyc_output/processinfo/a08fb26c-673c-4f78-bf68-a2615bce7bad.json +1 -0
  5. package/.nyc_output/processinfo/bf6f8f9b-7706-4a31-ba31-965369f4c4ce.json +1 -0
  6. package/.nyc_output/processinfo/index.json +1 -1
  7. package/full-hugo-renderer/go.mod +20 -16
  8. package/full-hugo-renderer/go.sum +35 -409
  9. package/full-hugo-renderer/hugo_renderer.wasm +0 -0
  10. package/full-hugo-renderer/hugo_renderer.wasm.gz +0 -0
  11. package/full-hugo-renderer/wasm_exec.js +5 -1
  12. package/lib/engine.js +60 -13
  13. package/package.json +2 -2
  14. package/.nyc_output/processinfo/229a6434-8446-4f8b-98c5-2b71c6b2eb87.json +0 -1
  15. package/.nyc_output/processinfo/2405260d-8f87-4702-a513-c39fc37b2ae7.json +0 -1
  16. package/.nyc_output/processinfo/27ed531c-5699-42a6-8c8c-2debe705576a.json +0 -1
  17. package/.nyc_output/processinfo/2e2d9437-5bb4-4cfc-9850-fddb27cec721.json +0 -1
  18. package/.nyc_output/processinfo/d293db7a-a9b9-470c-9ca5-5beabc3f323f.json +0 -1
  19. /package/.nyc_output/{229a6434-8446-4f8b-98c5-2b71c6b2eb87.json → 0021c648-0cec-4195-a0dc-985b510e7b75.json} +0 -0
  20. /package/.nyc_output/{2405260d-8f87-4702-a513-c39fc37b2ae7.json → 437debd8-2dd5-4b95-b772-f5bba688f936.json} +0 -0
  21. /package/.nyc_output/{27ed531c-5699-42a6-8c8c-2debe705576a.json → 4bd04565-b332-432b-8129-e9fed05110a9.json} +0 -0
  22. /package/.nyc_output/{2e2d9437-5bb4-4cfc-9850-fddb27cec721.json → a08fb26c-673c-4f78-bf68-a2615bce7bad.json} +0 -0
  23. /package/.nyc_output/{d293db7a-a9b9-470c-9ca5-5beabc3f323f.json → bf6f8f9b-7706-4a31-ba31-965369f4c4ce.json} +0 -0
@@ -48,7 +48,11 @@
48
48
  outputBuf += decoder.decode(buf);
49
49
  const nl = outputBuf.lastIndexOf("\n");
50
50
  if (nl != -1) {
51
- // Disable all logs from the WASM side
51
+ // Track logs for Bookshop to pick up later
52
+ window.hugo_wasm_logging = window.hugo_wasm_logging || [];
53
+ window.hugo_wasm_logging.push(outputBuf.substr(0, nl));
54
+
55
+ // Disable console logs from the WASM side
52
56
  if (window.log_hugo_wasm) {
53
57
  console.log(outputBuf.substr(0, nl));
54
58
  }
package/lib/engine.js CHANGED
@@ -201,6 +201,50 @@ export class Engine {
201
201
  window.writeHugoFiles(JSON.stringify(files));
202
202
  }
203
203
 
204
+ /**
205
+ * Tries to parse an error message and patch up the components
206
+ * in a rudimentary way before a rebuild.
207
+ */
208
+ async componentQuack(error_string = "", log_messages = []) {
209
+ try {
210
+ const component_regex = /execute of template failed: template: ([^:]+):\d/ig;
211
+ let file_stack = [...error_string.matchAll(component_regex)].map(([, file]) => `layouts/${file}`);
212
+ if (file_stack.length) {
213
+ const deepest_errored_component = file_stack[file_stack.length-1];
214
+ const error_chunks = error_string.split("execute of template failed:");
215
+ const error_msg = error_chunks[error_chunks.length-1] ?? "template error";
216
+ window.writeHugoFiles(JSON.stringify({
217
+ [deepest_errored_component]: [
218
+ `<div style="padding: 10px; background-color: lightcoral; color: black; font-weight: bold;">`,
219
+ `Failed to render ${deepest_errored_component}. <br/>`,
220
+ `<pre style="margin-top: 10px; background-color: lightcoral; border: solid 1px black;">`,
221
+ `<code style="font-family: monospace; color: black;">${error_msg.replace(/</, '&lt;')}</code></pre>`,
222
+ `</div>`
223
+ ].join('\n')
224
+ }));
225
+ return deepest_errored_component;
226
+ }
227
+
228
+ const error_logs = log_messages.filter(log => log.startsWith("ERROR")).join("\n");
229
+ const missing_regex = /Component "([^"]+)" does not exist/ig;
230
+ file_stack = [...error_logs.matchAll(missing_regex)].map(([, file]) => `layouts/partials/bookshop/components/${file}/${file}.hugo.html`);
231
+ if (file_stack.length) {
232
+ const deepest_errored_component = file_stack[file_stack.length-1];
233
+ window.writeHugoFiles(JSON.stringify({
234
+ [deepest_errored_component]: [
235
+ `<div class="bookshop_error" style="padding: 10px; background-color: lightcoral; color: black; font-weight: bold;">`,
236
+ `Failed to find component ${deepest_errored_component}`,
237
+ `</div>`
238
+ ].join('\n')
239
+ }));
240
+ return deepest_errored_component;
241
+ }
242
+ } catch (e) {
243
+ console.error(`ComponentQuack failed to patch things up: ${e}`);
244
+ return null;
245
+ }
246
+ }
247
+
204
248
  async render(target, name, props, globals, logger) {
205
249
  while (!window.buildHugo) {
206
250
  logger?.log?.(`Waiting for the Hugo WASM to be available...`);
@@ -233,9 +277,22 @@ export class Engine {
233
277
  }, null, 2) + "\n";
234
278
  window.writeHugoFiles(JSON.stringify(writeFiles));
235
279
 
236
- const buildResult = window.buildHugo();
237
- if (buildResult) {
238
- console.error(buildResult);
280
+ window.hugo_wasm_logging = [];
281
+ let render_attempts = 1;
282
+ let buildError = window.buildHugo();
283
+ while (buildError && render_attempts < 5) {
284
+ if (this.componentQuack(buildError, window.hugo_wasm_logging) === null) {
285
+ // Can't find a template to overwrite and re-render
286
+ break;
287
+ }
288
+ // Try render again with the problem template stubbed out
289
+ window.hugo_wasm_logging = [];
290
+ buildError = window.buildHugo();
291
+ render_attempts += 1;
292
+ }
293
+
294
+ if (buildError) {
295
+ console.error(buildError);
239
296
  return;
240
297
  }
241
298
 
@@ -245,16 +302,6 @@ export class Engine {
245
302
 
246
303
  target.innerHTML = output["public/index.html"];
247
304
  return;
248
-
249
- const outputs = window.renderHugo(source, JSON.stringify(props));
250
- if (/BKSHERR/.test(output)) {
251
- logger?.log?.(`Failed to render ${output}`);
252
- console.error(output);
253
- } else {
254
- target.innerHTML = output;
255
- logger?.log?.(`Rendered ${name} as:`);
256
- logger?.log?.(target.innerHTML);
257
- }
258
305
  }
259
306
 
260
307
  async eval(str, props = [{}], logger) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bookshop/hugo-engine",
3
3
  "packageManager": "yarn@3.0.0",
4
- "version": "3.4.1",
4
+ "version": "3.5.0-alpha.0",
5
5
  "description": "Bookshop frontend Hugo renderer",
6
6
  "type": "module",
7
7
  "sideEffects": false,
@@ -30,7 +30,7 @@
30
30
  "nyc": "^15.1.0"
31
31
  },
32
32
  "dependencies": {
33
- "@bookshop/helpers": "3.4.1",
33
+ "@bookshop/helpers": "3.5.0-alpha.0",
34
34
  "esbuild": "^0.13.10",
35
35
  "fflate": "^0.7.3",
36
36
  "liquidjs": "9.28.0"
@@ -1 +0,0 @@
1
- {"parent":"2405260d-8f87-4702-a513-c39fc37b2ae7","pid":5484,"argv":["/opt/hostedtoolcache/node/16.19.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1679549944033,"ppid":5467,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/229a6434-8446-4f8b-98c5-2b71c6b2eb87.json","externalId":"","uuid":"229a6434-8446-4f8b-98c5-2b71c6b2eb87","files":[]}
@@ -1 +0,0 @@
1
- {"parent":null,"pid":5467,"argv":["/opt/hostedtoolcache/node/16.19.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/cli.js","-v"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1679549943598,"ppid":5456,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/2405260d-8f87-4702-a513-c39fc37b2ae7.json","externalId":"","uuid":"2405260d-8f87-4702-a513-c39fc37b2ae7","files":[]}
@@ -1 +0,0 @@
1
- {"parent":"2405260d-8f87-4702-a513-c39fc37b2ae7","pid":5500,"argv":["/opt/hostedtoolcache/node/16.19.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1679549944390,"ppid":5467,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/27ed531c-5699-42a6-8c8c-2debe705576a.json","externalId":"","uuid":"27ed531c-5699-42a6-8c8c-2debe705576a","files":[]}
@@ -1 +0,0 @@
1
- {"parent":"2405260d-8f87-4702-a513-c39fc37b2ae7","pid":5506,"argv":["/opt/hostedtoolcache/node/16.19.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1679549944400,"ppid":5467,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/2e2d9437-5bb4-4cfc-9850-fddb27cec721.json","externalId":"","uuid":"2e2d9437-5bb4-4cfc-9850-fddb27cec721","files":[]}
@@ -1 +0,0 @@
1
- {"parent":"2405260d-8f87-4702-a513-c39fc37b2ae7","pid":5478,"argv":["/opt/hostedtoolcache/node/16.19.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1679549944028,"ppid":5467,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/d293db7a-a9b9-470c-9ca5-5beabc3f323f.json","externalId":"","uuid":"d293db7a-a9b9-470c-9ca5-5beabc3f323f","files":[]}