@bookshop/eleventy-engine
Advanced tools
Comparing version 3.4.1 to 3.5.0-alpha.0
@@ -1,1 +0,1 @@ | ||
{"processes":{"0da458ac-20a8-4a98-9118-36f4133947b5":{"parent":"a95ce79c-4520-45ce-9411-6363123457f2","children":[]},"30a0e641-fe89-4b37-8063-bbfbcb18f49f":{"parent":"a95ce79c-4520-45ce-9411-6363123457f2","children":[]},"6c56484b-184e-4e80-8d13-e481f44ac46a":{"parent":"a95ce79c-4520-45ce-9411-6363123457f2","children":[]},"a95ce79c-4520-45ce-9411-6363123457f2":{"parent":null,"children":["0da458ac-20a8-4a98-9118-36f4133947b5","30a0e641-fe89-4b37-8063-bbfbcb18f49f","6c56484b-184e-4e80-8d13-e481f44ac46a"]}},"files":{},"externalIds":{}} | ||
{"processes":{"1463b78f-06f1-4a33-86ad-8dc6d0d53dad":{"parent":"79dee488-0f90-4c0e-a29c-01bc6bace36f","children":[]},"79dee488-0f90-4c0e-a29c-01bc6bace36f":{"parent":null,"children":["1463b78f-06f1-4a33-86ad-8dc6d0d53dad","a099a612-e40d-47fc-b236-0c1d6238899a","ec2def07-34c8-44c2-a6c2-61d4cca679b7"]},"a099a612-e40d-47fc-b236-0c1d6238899a":{"parent":"79dee488-0f90-4c0e-a29c-01bc6bace36f","children":[]},"ec2def07-34c8-44c2-a6c2-61d4cca679b7":{"parent":"79dee488-0f90-4c0e-a29c-01bc6bace36f","children":[]}},"files":{},"externalIds":{}} |
@@ -59,9 +59,28 @@ import { Liquid, Context } from 'liquidjs'; | ||
async retrieveInclude(file) { | ||
let not_found = (name) => { | ||
return [ | ||
`<div class="bookshop_error" style="padding: 10px; background-color: lightcoral; color: black; font-weight: bold;">`, | ||
`Failed to find component ${name}`, | ||
`</div>` | ||
].join('\n'); | ||
} | ||
let content; | ||
if (/_bookshop_include_/.test(file)) { | ||
content = this.getShared(file.replace(/^.*_bookshop_include_/, "")); | ||
if (!content && content !== "") { | ||
content = not_found(file); | ||
} | ||
} else if (/_bookshop_/.test(file)) { | ||
content = this.getComponent(file.replace(/^.*_bookshop_/, "")); | ||
if (!content && content !== "") { | ||
content = not_found(file); | ||
} | ||
} else { | ||
content = this.files?.[file]; | ||
if (!content && content !== "") { | ||
content = not_found(file); | ||
} | ||
} | ||
@@ -82,3 +101,3 @@ if (!content && content !== "") { | ||
getShared(name) { | ||
const key = `shared/eleventy/${name}.eleventy.liquid` | ||
const key = `shared/eleventy/${name}.eleventy.liquid`; | ||
return this.files?.[key]; | ||
@@ -146,2 +165,27 @@ } | ||
/** | ||
* Tries to parse an error message and patch up the components | ||
* in a rudimentary way before a rebuild. | ||
*/ | ||
async componentQuack(error_string = "") { | ||
try { | ||
const component_regex = /file:._bookshop_([^,]+),/ig; | ||
let file_stack = [...error_string.matchAll(component_regex)]; | ||
if (file_stack.length) { | ||
const deepest_errored_component = file_stack[file_stack.length-1]; | ||
const component_key = this.getComponentKey(deepest_errored_component[1]); | ||
this.files = this.files || {}; | ||
this.files[component_key] = [ | ||
`<div style="padding: 10px; background-color: lightcoral; color: black; font-weight: bold;">`, | ||
`Failed to render ${deepest_errored_component[1]}. <br/>`, | ||
`<pre style="margin-top: 10px; background-color: lightcoral; border: solid 1px black;">`, | ||
`<code style="font-family: monospace; color: black;">${error_string.replace(/</, '<')}</code></pre>`, | ||
`</div>` | ||
].join('\n'); | ||
return deepest_errored_component; | ||
} | ||
} catch(e) {} | ||
return null; | ||
} | ||
async render(target, name, props, globals, logger) { | ||
@@ -162,3 +206,16 @@ let source = this.getComponent(name); | ||
props = this.injectInfo({ ...globals, ...props }); | ||
target.innerHTML = await this.liquid.parseAndRender(source || "", props); | ||
let rendered = false, render_attempts = 1, max_renders = 5; | ||
while (!rendered && render_attempts < max_renders) { | ||
try { | ||
target.innerHTML = await this.liquid.parseAndRender(source || "", props); | ||
rendered = true; | ||
} catch(e) { | ||
if (!this.componentQuack(e.toString())) { | ||
max_renders = render_attempts; | ||
target.innerHTML = `<code>Bookshop failed to render: ${e.toString()}</code>` | ||
} | ||
} | ||
render_attempts += 1; | ||
} | ||
logger?.log?.(`Rendered ${name} as:`); | ||
@@ -165,0 +222,0 @@ logger?.log?.(target.innerHTML); |
{ | ||
"name": "@bookshop/eleventy-engine", | ||
"packageManager": "yarn@3.0.0", | ||
"version": "3.4.1", | ||
"version": "3.5.0-alpha.0", | ||
"description": "Bookshop frontend Eleventy renderer", | ||
@@ -30,3 +30,3 @@ "type": "module", | ||
"dependencies": { | ||
"@bookshop/helpers": "3.4.1", | ||
"@bookshop/helpers": "3.5.0-alpha.0", | ||
"esbuild": "^0.13.10", | ||
@@ -33,0 +33,0 @@ "liquidjs": "9.28.0", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
26695
557
2
+ Added@bookshop/helpers@3.5.0-alpha.0(transitive)
- Removed@bookshop/helpers@3.4.1(transitive)