@bookshop/hugo-engine 3.4.1 → 3.5.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.
- package/.nyc_output/processinfo/0abf820b-2028-4355-a51f-2ae7ceb14fc6.json +1 -0
- package/.nyc_output/processinfo/0c4785c3-d657-4de0-97e2-a5c8bed13440.json +1 -0
- package/.nyc_output/processinfo/5217b0dd-26fb-4b8d-af21-def9fd98ee74.json +1 -0
- package/.nyc_output/processinfo/5ab837f9-47fd-4613-be9e-8cad7f893cb6.json +1 -0
- package/.nyc_output/processinfo/6671a456-fd5a-43f9-8289-01bfd323ba6a.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/full-hugo-renderer/go.mod +20 -16
- package/full-hugo-renderer/go.sum +35 -409
- package/full-hugo-renderer/hugo_renderer.wasm +0 -0
- package/full-hugo-renderer/hugo_renderer.wasm.gz +0 -0
- package/full-hugo-renderer/wasm_exec.js +5 -1
- package/lib/engine.js +63 -13
- package/package.json +2 -2
- package/.nyc_output/processinfo/229a6434-8446-4f8b-98c5-2b71c6b2eb87.json +0 -1
- package/.nyc_output/processinfo/2405260d-8f87-4702-a513-c39fc37b2ae7.json +0 -1
- package/.nyc_output/processinfo/27ed531c-5699-42a6-8c8c-2debe705576a.json +0 -1
- package/.nyc_output/processinfo/2e2d9437-5bb4-4cfc-9850-fddb27cec721.json +0 -1
- package/.nyc_output/processinfo/d293db7a-a9b9-470c-9ca5-5beabc3f323f.json +0 -1
- /package/.nyc_output/{229a6434-8446-4f8b-98c5-2b71c6b2eb87.json → 0abf820b-2028-4355-a51f-2ae7ceb14fc6.json} +0 -0
- /package/.nyc_output/{2405260d-8f87-4702-a513-c39fc37b2ae7.json → 0c4785c3-d657-4de0-97e2-a5c8bed13440.json} +0 -0
- /package/.nyc_output/{27ed531c-5699-42a6-8c8c-2debe705576a.json → 5217b0dd-26fb-4b8d-af21-def9fd98ee74.json} +0 -0
- /package/.nyc_output/{2e2d9437-5bb4-4cfc-9850-fddb27cec721.json → 5ab837f9-47fd-4613-be9e-8cad7f893cb6.json} +0 -0
- /package/.nyc_output/{d293db7a-a9b9-470c-9ca5-5beabc3f323f.json → 6671a456-fd5a-43f9-8289-01bfd323ba6a.json} +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -48,7 +48,11 @@
|
|
|
48
48
|
outputBuf += decoder.decode(buf);
|
|
49
49
|
const nl = outputBuf.lastIndexOf("\n");
|
|
50
50
|
if (nl != -1) {
|
|
51
|
-
//
|
|
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,53 @@ 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; white-space: pre-line;">`,
|
|
221
|
+
`<code style="font-family: monospace; color: black;">${error_msg.replace(/</, '<')}</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]) => {
|
|
231
|
+
let filename = file.split('/').pop();
|
|
232
|
+
return `layouts/partials/bookshop/components/${file}/${filename}.hugo.html`;
|
|
233
|
+
});
|
|
234
|
+
if (file_stack.length) {
|
|
235
|
+
const deepest_errored_component = file_stack[file_stack.length-1];
|
|
236
|
+
window.writeHugoFiles(JSON.stringify({
|
|
237
|
+
[deepest_errored_component]: [
|
|
238
|
+
`<div class="bookshop_error" style="padding: 10px; background-color: lightcoral; color: black; font-weight: bold;">`,
|
|
239
|
+
`Failed to find component ${deepest_errored_component}`,
|
|
240
|
+
`</div>`
|
|
241
|
+
].join('\n')
|
|
242
|
+
}));
|
|
243
|
+
return deepest_errored_component;
|
|
244
|
+
}
|
|
245
|
+
} catch (e) {
|
|
246
|
+
console.error(`ComponentQuack failed to patch things up: ${e}`);
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
204
251
|
async render(target, name, props, globals, logger) {
|
|
205
252
|
while (!window.buildHugo) {
|
|
206
253
|
logger?.log?.(`Waiting for the Hugo WASM to be available...`);
|
|
@@ -233,9 +280,22 @@ export class Engine {
|
|
|
233
280
|
}, null, 2) + "\n";
|
|
234
281
|
window.writeHugoFiles(JSON.stringify(writeFiles));
|
|
235
282
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
283
|
+
window.hugo_wasm_logging = [];
|
|
284
|
+
let render_attempts = 1;
|
|
285
|
+
let buildError = window.buildHugo();
|
|
286
|
+
while (buildError && render_attempts < 5) {
|
|
287
|
+
if (this.componentQuack(buildError, window.hugo_wasm_logging) === null) {
|
|
288
|
+
// Can't find a template to overwrite and re-render
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
// Try render again with the problem template stubbed out
|
|
292
|
+
window.hugo_wasm_logging = [];
|
|
293
|
+
buildError = window.buildHugo();
|
|
294
|
+
render_attempts += 1;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (buildError) {
|
|
298
|
+
console.error(buildError);
|
|
239
299
|
return;
|
|
240
300
|
}
|
|
241
301
|
|
|
@@ -245,16 +305,6 @@ export class Engine {
|
|
|
245
305
|
|
|
246
306
|
target.innerHTML = output["public/index.html"];
|
|
247
307
|
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
308
|
}
|
|
259
309
|
|
|
260
310
|
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
|
+
"version": "3.5.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.
|
|
33
|
+
"@bookshop/helpers": "3.5.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":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|