@hyperframes/inspector 0.8.177 → 0.8.179

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/dist/live.js CHANGED
@@ -570,11 +570,14 @@ function sourceFiles(project) {
570
570
  visit(project);
571
571
  return files.sort();
572
572
  }
573
- function fingerprint(project) {
573
+ var HF_ID_ATTRIBUTE = /\sdata-hf-id\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/g;
574
+ function fingerprint(project, { ignoreHfIds = false } = {}) {
574
575
  const hash = createHash2("sha256");
575
576
  for (const path of sourceFiles(project)) {
576
577
  hash.update(relative(project, path));
577
- hash.update(readFileSync(path));
578
+ hash.update(
579
+ ignoreHfIds && extname(path) === ".html" ? readFileSync(path, "utf8").replace(HF_ID_ATTRIBUTE, "") : readFileSync(path)
580
+ );
578
581
  }
579
582
  return hash.digest("hex");
580
583
  }
@@ -1333,7 +1336,7 @@ function assertGeneration(requested, current) {
1333
1336
  var runtime = () => readFileSync2(new URL(`./inspection.${"js"}`, import.meta.url), "utf8");
1334
1337
  function prepareLiveInspection(projectDir, html, provenance, sourceVersion) {
1335
1338
  const project = realpathSync(projectDir);
1336
- if (fingerprint(project) !== sourceVersion) throw new Error("source_changed_during_load");
1339
+ if (fingerprint2(project) !== sourceVersion) throw new Error("source_changed_during_load");
1337
1340
  if (!/<head\b[^>]*>/i.test(html)) throw new Error("preview_head_missing");
1338
1341
  const generation = randomUUID();
1339
1342
  const stamp = `window.__hfLiveInspection=${JSON.stringify({ generation, project })};`;
@@ -1359,7 +1362,7 @@ ${runtime()}`.replace(/<\/script/gi, "<\\/script");
1359
1362
  return authored ??= authoredHtml(project);
1360
1363
  },
1361
1364
  async assertCurrent() {
1362
- if (fingerprint(project) !== sourceVersion)
1365
+ if (fingerprint2(project) !== sourceVersion)
1363
1366
  throw new Error("stale_preview: the project changed; query again once the preview reloads");
1364
1367
  }
1365
1368
  };
@@ -1401,8 +1404,11 @@ ${runtime()}`.replace(/<\/script/gi, "<\\/script");
1401
1404
  function previewGeneration(runner) {
1402
1405
  return runner.run(liveGenerationPage, void 0);
1403
1406
  }
1407
+ function fingerprint2(project) {
1408
+ return fingerprint(project, { ignoreHfIds: true });
1409
+ }
1404
1410
  export {
1405
- fingerprint,
1411
+ fingerprint2 as fingerprint,
1406
1412
  prepareLiveInspection,
1407
1413
  previewGeneration
1408
1414
  };