@bookshop/hugo-engine 3.4.0-beta.2 → 3.4.0-beta.4
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/{0d71b778-7933-4ad7-b3a3-a0ab8fb25087.json → 03de4e51-1d4a-4fd9-9b9b-16373435d314.json} +0 -0
- package/.nyc_output/{288189b4-5618-4616-9a86-8209c52bfa78.json → 16ae2f65-749d-4c56-9a3a-f6be5d68f55e.json} +0 -0
- package/.nyc_output/{3a20cbf5-03a8-4e28-9134-bcbe4e3999da.json → 201a26a0-e25c-49d0-9ef5-66a8702f9381.json} +0 -0
- package/.nyc_output/{440df8ed-01d8-4b4a-86a4-141986b1c583.json → 211ad0eb-0a74-4b71-85bd-f88086a3d42d.json} +0 -0
- package/.nyc_output/{df2bb669-e900-4e87-9cf0-f9673bdda2d5.json → 7f1e35c6-f1e9-42ef-8e7c-f57e5934081e.json} +0 -0
- package/.nyc_output/processinfo/03de4e51-1d4a-4fd9-9b9b-16373435d314.json +1 -0
- package/.nyc_output/processinfo/16ae2f65-749d-4c56-9a3a-f6be5d68f55e.json +1 -0
- package/.nyc_output/processinfo/201a26a0-e25c-49d0-9ef5-66a8702f9381.json +1 -0
- package/.nyc_output/processinfo/211ad0eb-0a74-4b71-85bd-f88086a3d42d.json +1 -0
- package/.nyc_output/processinfo/7f1e35c6-f1e9-42ef-8e7c-f57e5934081e.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/full-hugo-renderer/hugo_renderer.wasm +0 -0
- package/full-hugo-renderer/hugo_renderer.wasm.gz +0 -0
- package/lib/engine.js +66 -5
- package/lib/hugoIdentifierParser.js +0 -5
- package/package.json +2 -2
- package/.nyc_output/processinfo/0d71b778-7933-4ad7-b3a3-a0ab8fb25087.json +0 -1
- package/.nyc_output/processinfo/288189b4-5618-4616-9a86-8209c52bfa78.json +0 -1
- package/.nyc_output/processinfo/3a20cbf5-03a8-4e28-9134-bcbe4e3999da.json +0 -1
- package/.nyc_output/processinfo/440df8ed-01d8-4b4a-86a4-141986b1c583.json +0 -1
- package/.nyc_output/processinfo/df2bb669-e900-4e87-9cf0-f9673bdda2d5.json +0 -1
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"7f1e35c6-f1e9-42ef-8e7c-f57e5934081e","pid":5495,"argv":["/opt/hostedtoolcache/node/16.19.0/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":1674635759088,"ppid":5478,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/03de4e51-1d4a-4fd9-9b9b-16373435d314.json","externalId":"","uuid":"03de4e51-1d4a-4fd9-9b9b-16373435d314","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"7f1e35c6-f1e9-42ef-8e7c-f57e5934081e","pid":5489,"argv":["/opt/hostedtoolcache/node/16.19.0/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":1674635759071,"ppid":5478,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/16ae2f65-749d-4c56-9a3a-f6be5d68f55e.json","externalId":"","uuid":"16ae2f65-749d-4c56-9a3a-f6be5d68f55e","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"7f1e35c6-f1e9-42ef-8e7c-f57e5934081e","pid":5512,"argv":["/opt/hostedtoolcache/node/16.19.0/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":1674635759514,"ppid":5478,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/201a26a0-e25c-49d0-9ef5-66a8702f9381.json","externalId":"","uuid":"201a26a0-e25c-49d0-9ef5-66a8702f9381","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"7f1e35c6-f1e9-42ef-8e7c-f57e5934081e","pid":5511,"argv":["/opt/hostedtoolcache/node/16.19.0/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":1674635759513,"ppid":5478,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/211ad0eb-0a74-4b71-85bd-f88086a3d42d.json","externalId":"","uuid":"211ad0eb-0a74-4b71-85bd-f88086a3d42d","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":5478,"argv":["/opt/hostedtoolcache/node/16.19.0/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":1674635758554,"ppid":5467,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/7f1e35c6-f1e9-42ef-8e7c-f57e5934081e.json","externalId":"","uuid":"7f1e35c6-f1e9-42ef-8e7c-f57e5934081e","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"03de4e51-1d4a-4fd9-9b9b-16373435d314":{"parent":"7f1e35c6-f1e9-42ef-8e7c-f57e5934081e","children":[]},"16ae2f65-749d-4c56-9a3a-f6be5d68f55e":{"parent":"7f1e35c6-f1e9-42ef-8e7c-f57e5934081e","children":[]},"201a26a0-e25c-49d0-9ef5-66a8702f9381":{"parent":"7f1e35c6-f1e9-42ef-8e7c-f57e5934081e","children":[]},"211ad0eb-0a74-4b71-85bd-f88086a3d42d":{"parent":"7f1e35c6-f1e9-42ef-8e7c-f57e5934081e","children":[]},"7f1e35c6-f1e9-42ef-8e7c-f57e5934081e":{"parent":null,"children":["03de4e51-1d4a-4fd9-9b9b-16373435d314","16ae2f65-749d-4c56-9a3a-f6be5d68f55e","201a26a0-e25c-49d0-9ef5-66a8702f9381","211ad0eb-0a74-4b71-85bd-f88086a3d42d"]}},"files":{},"externalIds":{}}
|
|
Binary file
|
|
Binary file
|
package/lib/engine.js
CHANGED
|
@@ -15,6 +15,22 @@ const dig = (obj, path) => {
|
|
|
15
15
|
return obj;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
let mapHugoVariablesToParams = (obj, path) => {
|
|
19
|
+
let resolved = {};
|
|
20
|
+
for (let [k, v] of Object.entries(obj)) {
|
|
21
|
+
if (k.startsWith('$')) {
|
|
22
|
+
const remapped = `__bksh_${k.substring(1)}`;
|
|
23
|
+
obj[remapped] = v;
|
|
24
|
+
resolved[k] = `${path}.${remapped}`;
|
|
25
|
+
} else {
|
|
26
|
+
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
|
27
|
+
resolved = { ...resolved, ...mapHugoVariablesToParams(v, `${path}.${k}`) }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return resolved
|
|
32
|
+
}
|
|
33
|
+
|
|
18
34
|
export class Engine {
|
|
19
35
|
constructor(options) {
|
|
20
36
|
options = {
|
|
@@ -224,24 +240,69 @@ export class Engine {
|
|
|
224
240
|
}
|
|
225
241
|
}
|
|
226
242
|
|
|
227
|
-
async eval(str, props = [{}]) {
|
|
243
|
+
async eval(str, props = [{}], logger) {
|
|
228
244
|
while (!window.buildHugo) await sleep(10);
|
|
229
245
|
let props_obj = props.reduce((a, b) => { return { ...a, ...b } });
|
|
246
|
+
let full_props = props_obj;
|
|
230
247
|
|
|
231
248
|
// We're capable of looking up a simple variable
|
|
232
249
|
// (and it's hard to pass to wasm since we store variables on the context)
|
|
233
250
|
if (/^\$/.test(str)) {
|
|
234
|
-
return
|
|
251
|
+
logger?.log?.(`Trying to short circuit to return a variable`);
|
|
252
|
+
if (props_obj[str]) return props_obj[str];
|
|
235
253
|
}
|
|
236
254
|
|
|
237
255
|
// If we have assigned a root scope we need to pass that in as the context
|
|
238
|
-
if (props_obj["."])
|
|
256
|
+
if (props_obj["."]) {
|
|
257
|
+
logger?.log?.(`Nesting the props object into its dot scope`);
|
|
258
|
+
props_obj = props_obj["."];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (str === ".") {
|
|
262
|
+
logger?.log?.(`Short circuiting dot notation to return the scope`);
|
|
263
|
+
return props_obj;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let normalized = this.normalize(str);
|
|
267
|
+
if (typeof normalized === 'object') {
|
|
268
|
+
logger?.log?.(`Digging into the object ${JSON.stringify(normalized)}`);
|
|
269
|
+
const process = async (obj) => {
|
|
270
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
271
|
+
if (typeof v === "string") {
|
|
272
|
+
if (/^".*"$/.test(v)) {
|
|
273
|
+
// Normalized strings look like "\"string\""
|
|
274
|
+
logger?.log?.(`Unwrapping the string ${k}: ${v}`);
|
|
275
|
+
obj[k] = JSON.parse(v);
|
|
276
|
+
} else {
|
|
277
|
+
// No inner quotes means it needs to be evaled again
|
|
278
|
+
logger?.log?.(`Evaluating the inner ${k}: ${v}`);
|
|
279
|
+
obj[k] = await this.eval(v, [props_obj], logger.nested());
|
|
280
|
+
}
|
|
281
|
+
} else if (typeof v === "object") {
|
|
282
|
+
logger?.log?.(`Processing the inner object ${k}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
await process(normalized);
|
|
287
|
+
return normalized;
|
|
288
|
+
}
|
|
289
|
+
if (/^\w+(\.\w+)*$/.test(normalized)) {
|
|
290
|
+
logger?.log?.(`Trying to short circuit to return the dot notation ${normalized}`);
|
|
291
|
+
// We're capable of looking up a simple dot notation access
|
|
292
|
+
const result = dig(props_obj, normalized);
|
|
293
|
+
if (result !== undefined) return result
|
|
294
|
+
}
|
|
239
295
|
|
|
240
296
|
// Rewrite array.0 into index array 0
|
|
241
297
|
str = str.replace(/(.*)\.(\d+)$/, (_, obj, index) => {
|
|
242
298
|
return `index (${obj}) ${index}`;
|
|
243
299
|
})
|
|
244
300
|
|
|
301
|
+
const variable_pairs = mapHugoVariablesToParams(full_props, ".Params.full_props");
|
|
302
|
+
const variable_decl = Object.entries(variable_pairs).map(([k, v]) => {
|
|
303
|
+
return `{{ ${k} := ${v} }}`
|
|
304
|
+
}).join('');
|
|
305
|
+
|
|
245
306
|
const assignments = Object.entries(props_obj).filter(([key]) => key.startsWith('$')).map(([key, value]) => {
|
|
246
307
|
if (Array.isArray(value)) {
|
|
247
308
|
return `{{ ${key} := index ( \`{"a": ${JSON.stringify(value)}}\` | transform.Unmarshal ) "a" }}`
|
|
@@ -251,10 +312,10 @@ export class Engine {
|
|
|
251
312
|
return `{{ ${key} := ${JSON.stringify(value)} }}`
|
|
252
313
|
}
|
|
253
314
|
}).join('');
|
|
254
|
-
const eval_str =
|
|
315
|
+
const eval_str = `${variable_decl}{{ with .Params.props }}${assignments}{{ jsonify (${str}) }}{{ end }}`;
|
|
255
316
|
window.writeHugoFiles(JSON.stringify({
|
|
256
317
|
"layouts/index.html": eval_str,
|
|
257
|
-
"content/_index.md": JSON.stringify({ props: props_obj }, null, 2)
|
|
318
|
+
"content/_index.md": JSON.stringify({ props: props_obj, full_props: full_props }, null, 2)
|
|
258
319
|
}));
|
|
259
320
|
|
|
260
321
|
const buildError = window.buildHugo();
|
|
@@ -36,11 +36,6 @@ export class IdentifierParser {
|
|
|
36
36
|
return `${variable}.${index}`;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// strip the leading .Params. from basic variable references
|
|
40
|
-
// if (/^\s*\./.test(this.input)) {
|
|
41
|
-
// return this.input.replace(/^\s*\.Params\.([^\.\s])/, '$1');
|
|
42
|
-
// }
|
|
43
|
-
|
|
44
39
|
// strip the leading . from basic variable references
|
|
45
40
|
if (/^\s*\./.test(this.input)) {
|
|
46
41
|
return this.input.replace(/^\s*\.([^\.\s])/, '$1');
|
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.0-beta.
|
|
4
|
+
"version": "3.4.0-beta.4",
|
|
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.0-beta.
|
|
33
|
+
"@bookshop/helpers": "3.4.0-beta.4",
|
|
34
34
|
"esbuild": "^0.13.10",
|
|
35
35
|
"fflate": "^0.7.3",
|
|
36
36
|
"liquidjs": "9.28.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","pid":5524,"argv":["/opt/hostedtoolcache/node/16.18.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":1670976826633,"ppid":5513,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/0d71b778-7933-4ad7-b3a3-a0ab8fb25087.json","externalId":"","uuid":"0d71b778-7933-4ad7-b3a3-a0ab8fb25087","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":5513,"argv":["/opt/hostedtoolcache/node/16.18.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":1670976826223,"ppid":5502,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/288189b4-5618-4616-9a86-8209c52bfa78.json","externalId":"","uuid":"288189b4-5618-4616-9a86-8209c52bfa78","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","pid":5547,"argv":["/opt/hostedtoolcache/node/16.18.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":1670976826988,"ppid":5513,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/3a20cbf5-03a8-4e28-9134-bcbe4e3999da.json","externalId":"","uuid":"3a20cbf5-03a8-4e28-9134-bcbe4e3999da","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","pid":5530,"argv":["/opt/hostedtoolcache/node/16.18.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":1670976826639,"ppid":5513,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/440df8ed-01d8-4b4a-86a4-141986b1c583.json","externalId":"","uuid":"440df8ed-01d8-4b4a-86a4-141986b1c583","files":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","pid":5546,"argv":["/opt/hostedtoolcache/node/16.18.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":1670976826985,"ppid":5513,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/df2bb669-e900-4e87-9cf0-f9673bdda2d5.json","externalId":"","uuid":"df2bb669-e900-4e87-9cf0-f9673bdda2d5","files":[]}
|