@bookshop/hugo-engine 3.4.0 → 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.
- package/.nyc_output/processinfo/0021c648-0cec-4195-a0dc-985b510e7b75.json +1 -0
- package/.nyc_output/processinfo/437debd8-2dd5-4b95-b772-f5bba688f936.json +1 -0
- package/.nyc_output/processinfo/4bd04565-b332-432b-8129-e9fed05110a9.json +1 -0
- package/.nyc_output/processinfo/a08fb26c-673c-4f78-bf68-a2615bce7bad.json +1 -0
- package/.nyc_output/processinfo/bf6f8f9b-7706-4a31-ba31-965369f4c4ce.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 +60 -13
- package/package.json +2 -2
- package/.nyc_output/processinfo/291349da-7931-43c2-9bbc-7a053fc82d3d.json +0 -1
- package/.nyc_output/processinfo/2b8c242a-2f07-4ab1-af29-e2fd4b106050.json +0 -1
- package/.nyc_output/processinfo/36ce7622-ead0-43c1-9645-c6982c5f8bf9.json +0 -1
- package/.nyc_output/processinfo/6f99cf0a-8997-40d5-916d-e4d005a7049c.json +0 -1
- package/.nyc_output/processinfo/8253377e-527a-4385-a9fc-5b38f5c5ba29.json +0 -1
- /package/.nyc_output/{291349da-7931-43c2-9bbc-7a053fc82d3d.json → 0021c648-0cec-4195-a0dc-985b510e7b75.json} +0 -0
- /package/.nyc_output/{2b8c242a-2f07-4ab1-af29-e2fd4b106050.json → 437debd8-2dd5-4b95-b772-f5bba688f936.json} +0 -0
- /package/.nyc_output/{36ce7622-ead0-43c1-9645-c6982c5f8bf9.json → 4bd04565-b332-432b-8129-e9fed05110a9.json} +0 -0
- /package/.nyc_output/{6f99cf0a-8997-40d5-916d-e4d005a7049c.json → a08fb26c-673c-4f78-bf68-a2615bce7bad.json} +0 -0
- /package/.nyc_output/{8253377e-527a-4385-a9fc-5b38f5c5ba29.json → bf6f8f9b-7706-4a31-ba31-965369f4c4ce.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,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(/</, '<')}</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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
+
"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.
|
|
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":"6f99cf0a-8997-40d5-916d-e4d005a7049c","pid":5438,"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":1678322855752,"ppid":5426,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/291349da-7931-43c2-9bbc-7a053fc82d3d.json","externalId":"","uuid":"291349da-7931-43c2-9bbc-7a053fc82d3d","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"6f99cf0a-8997-40d5-916d-e4d005a7049c","pid":5460,"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":1678322856105,"ppid":5426,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/2b8c242a-2f07-4ab1-af29-e2fd4b106050.json","externalId":"","uuid":"2b8c242a-2f07-4ab1-af29-e2fd4b106050","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"6f99cf0a-8997-40d5-916d-e4d005a7049c","pid":5461,"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":1678322856110,"ppid":5426,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/36ce7622-ead0-43c1-9645-c6982c5f8bf9.json","externalId":"","uuid":"36ce7622-ead0-43c1-9645-c6982c5f8bf9","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":5426,"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":1678322855333,"ppid":5415,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/6f99cf0a-8997-40d5-916d-e4d005a7049c.json","externalId":"","uuid":"6f99cf0a-8997-40d5-916d-e4d005a7049c","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"6f99cf0a-8997-40d5-916d-e4d005a7049c","pid":5444,"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":1678322855761,"ppid":5426,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/8253377e-527a-4385-a9fc-5b38f5c5ba29.json","externalId":"","uuid":"8253377e-527a-4385-a9fc-5b38f5c5ba29","files":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|