@bookshop/hugo-engine 3.4.0-beta.2 → 3.4.0-beta.3

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 (17) hide show
  1. package/.nyc_output/{0d71b778-7933-4ad7-b3a3-a0ab8fb25087.json → 344d16a6-acc4-4349-b4c7-ffdc41d3e64f.json} +0 -0
  2. package/.nyc_output/{288189b4-5618-4616-9a86-8209c52bfa78.json → ad191300-a822-422a-892c-f6bdd9f65622.json} +0 -0
  3. package/.nyc_output/{3a20cbf5-03a8-4e28-9134-bcbe4e3999da.json → b63e9a5b-2daa-4333-9cbc-511e31b8dec0.json} +0 -0
  4. package/.nyc_output/{440df8ed-01d8-4b4a-86a4-141986b1c583.json → c1702c73-10b3-4031-a62b-78de0f5a0eda.json} +0 -0
  5. package/.nyc_output/{df2bb669-e900-4e87-9cf0-f9673bdda2d5.json → d9c4bafc-f898-4591-b134-c70616d033a8.json} +0 -0
  6. package/.nyc_output/processinfo/{0d71b778-7933-4ad7-b3a3-a0ab8fb25087.json → 344d16a6-acc4-4349-b4c7-ffdc41d3e64f.json} +1 -1
  7. package/.nyc_output/processinfo/{3a20cbf5-03a8-4e28-9134-bcbe4e3999da.json → ad191300-a822-422a-892c-f6bdd9f65622.json} +1 -1
  8. package/.nyc_output/processinfo/{440df8ed-01d8-4b4a-86a4-141986b1c583.json → b63e9a5b-2daa-4333-9cbc-511e31b8dec0.json} +1 -1
  9. package/.nyc_output/processinfo/c1702c73-10b3-4031-a62b-78de0f5a0eda.json +1 -0
  10. package/.nyc_output/processinfo/{df2bb669-e900-4e87-9cf0-f9673bdda2d5.json → d9c4bafc-f898-4591-b134-c70616d033a8.json} +1 -1
  11. package/.nyc_output/processinfo/index.json +1 -1
  12. package/full-hugo-renderer/hugo_renderer.wasm +0 -0
  13. package/full-hugo-renderer/hugo_renderer.wasm.gz +0 -0
  14. package/lib/engine.js +66 -5
  15. package/lib/hugoIdentifierParser.js +0 -5
  16. package/package.json +2 -2
  17. package/.nyc_output/processinfo/288189b4-5618-4616-9a86-8209c52bfa78.json +0 -1
@@ -1 +1 @@
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
+ {"parent":"c1702c73-10b3-4031-a62b-78de0f5a0eda","pid":5464,"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":1671138230217,"ppid":5424,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/344d16a6-acc4-4349-b4c7-ffdc41d3e64f.json","externalId":"","uuid":"344d16a6-acc4-4349-b4c7-ffdc41d3e64f","files":[]}
@@ -1 +1 @@
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
+ {"parent":"c1702c73-10b3-4031-a62b-78de0f5a0eda","pid":5441,"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":1671138229848,"ppid":5424,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/ad191300-a822-422a-892c-f6bdd9f65622.json","externalId":"","uuid":"ad191300-a822-422a-892c-f6bdd9f65622","files":[]}
@@ -1 +1 @@
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
+ {"parent":"c1702c73-10b3-4031-a62b-78de0f5a0eda","pid":5435,"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":1671138229841,"ppid":5424,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/b63e9a5b-2daa-4333-9cbc-511e31b8dec0.json","externalId":"","uuid":"b63e9a5b-2daa-4333-9cbc-511e31b8dec0","files":[]}
@@ -0,0 +1 @@
1
+ {"parent":null,"pid":5424,"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":1671138229402,"ppid":5413,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/c1702c73-10b3-4031-a62b-78de0f5a0eda.json","externalId":"","uuid":"c1702c73-10b3-4031-a62b-78de0f5a0eda","files":[]}
@@ -1 +1 @@
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":[]}
1
+ {"parent":"c1702c73-10b3-4031-a62b-78de0f5a0eda","pid":5457,"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":1671138230206,"ppid":5424,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/d9c4bafc-f898-4591-b134-c70616d033a8.json","externalId":"","uuid":"d9c4bafc-f898-4591-b134-c70616d033a8","files":[]}
@@ -1 +1 @@
1
- {"processes":{"0d71b778-7933-4ad7-b3a3-a0ab8fb25087":{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","children":[]},"288189b4-5618-4616-9a86-8209c52bfa78":{"parent":null,"children":["0d71b778-7933-4ad7-b3a3-a0ab8fb25087","3a20cbf5-03a8-4e28-9134-bcbe4e3999da","440df8ed-01d8-4b4a-86a4-141986b1c583","df2bb669-e900-4e87-9cf0-f9673bdda2d5"]},"3a20cbf5-03a8-4e28-9134-bcbe4e3999da":{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","children":[]},"440df8ed-01d8-4b4a-86a4-141986b1c583":{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","children":[]},"df2bb669-e900-4e87-9cf0-f9673bdda2d5":{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","children":[]}},"files":{},"externalIds":{}}
1
+ {"processes":{"344d16a6-acc4-4349-b4c7-ffdc41d3e64f":{"parent":"c1702c73-10b3-4031-a62b-78de0f5a0eda","children":[]},"ad191300-a822-422a-892c-f6bdd9f65622":{"parent":"c1702c73-10b3-4031-a62b-78de0f5a0eda","children":[]},"b63e9a5b-2daa-4333-9cbc-511e31b8dec0":{"parent":"c1702c73-10b3-4031-a62b-78de0f5a0eda","children":[]},"c1702c73-10b3-4031-a62b-78de0f5a0eda":{"parent":null,"children":["344d16a6-acc4-4349-b4c7-ffdc41d3e64f","ad191300-a822-422a-892c-f6bdd9f65622","b63e9a5b-2daa-4333-9cbc-511e31b8dec0","d9c4bafc-f898-4591-b134-c70616d033a8"]},"d9c4bafc-f898-4591-b134-c70616d033a8":{"parent":"c1702c73-10b3-4031-a62b-78de0f5a0eda","children":[]}},"files":{},"externalIds":{}}
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 (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 props_obj[str] ?? null;
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["."]) props_obj = 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 = `{{ with .Params.props }}${assignments}{{ jsonify (${str}) }}{{ end }}`;
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.2",
4
+ "version": "3.4.0-beta.3",
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.2",
33
+ "@bookshop/helpers": "3.4.0-beta.3",
34
34
  "esbuild": "^0.13.10",
35
35
  "fflate": "^0.7.3",
36
36
  "liquidjs": "9.28.0"
@@ -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":[]}