@patch-adams/core 1.6.1 → 1.6.2

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/index.d.cts CHANGED
@@ -762,6 +762,11 @@ declare class HtmlInjector {
762
762
  * Escape a string for use in HTML attributes
763
763
  */
764
764
  private escapeAttr;
765
+ /**
766
+ * Inject a tiny inline script that fetches the asset version BEFORE any loaders.
767
+ * Sets window.__pa_v so CSS Before, JS Before, and all other loaders get ?v= cache bust.
768
+ */
769
+ private injectVersionResolver;
765
770
  /**
766
771
  * Inject CSS Before loader at start of <head>
767
772
  */
package/dist/index.d.ts CHANGED
@@ -762,6 +762,11 @@ declare class HtmlInjector {
762
762
  * Escape a string for use in HTML attributes
763
763
  */
764
764
  private escapeAttr;
765
+ /**
766
+ * Inject a tiny inline script that fetches the asset version BEFORE any loaders.
767
+ * Sets window.__pa_v so CSS Before, JS Before, and all other loaders get ?v= cache bust.
768
+ */
769
+ private injectVersionResolver;
765
770
  /**
766
771
  * Inject CSS Before loader at start of <head>
767
772
  */
package/dist/index.js CHANGED
@@ -5299,18 +5299,21 @@ window.pa_patcher = window.pa_patcher || {
5299
5299
 
5300
5300
  (function() {
5301
5301
  'use strict';
5302
- // Fetch server-controlled cache version (sync, once)
5303
- var ASSET_VERSION_URL = "${assetVersionUrl || ""}";
5304
- window.__pa_v = '';
5305
- if (ASSET_VERSION_URL) {
5306
- try {
5307
- var xhr = new XMLHttpRequest();
5308
- xhr.open('GET', ASSET_VERSION_URL, false);
5309
- xhr.send();
5310
- if (xhr.status === 200) {
5311
- window.__pa_v = JSON.parse(xhr.responseText).v || '1';
5312
- }
5313
- } catch(e) { window.__pa_v = '1'; }
5302
+ // Cache version \u2014 normally set by version resolver (injected before CSS Before).
5303
+ // Fallback: fetch here if version resolver didn't run (older patched packages).
5304
+ if (typeof window.__pa_v === 'undefined') {
5305
+ var ASSET_VERSION_URL = "${assetVersionUrl || ""}";
5306
+ window.__pa_v = '';
5307
+ if (ASSET_VERSION_URL) {
5308
+ try {
5309
+ var xhr = new XMLHttpRequest();
5310
+ xhr.open('GET', ASSET_VERSION_URL, false);
5311
+ xhr.send();
5312
+ if (xhr.status === 200) {
5313
+ window.__pa_v = JSON.parse(xhr.responseText).v || '1';
5314
+ }
5315
+ } catch(e) { window.__pa_v = '1'; }
5316
+ }
5314
5317
  }
5315
5318
 
5316
5319
  var REMOTE_URL = "${remoteUrl}" + (window.__pa_v ? "?v=" + window.__pa_v : "");
@@ -5960,6 +5963,7 @@ var HtmlInjector = class {
5960
5963
  inject(html) {
5961
5964
  let result = html;
5962
5965
  result = this.addHtmlAttributes(result);
5966
+ result = this.injectVersionResolver(result);
5963
5967
  if (this.config.cssBefore.enabled) {
5964
5968
  result = this.injectCssBefore(result);
5965
5969
  }
@@ -6063,6 +6067,20 @@ ${pluginJs}
6063
6067
  escapeAttr(str) {
6064
6068
  return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
6065
6069
  }
6070
+ /**
6071
+ * Inject a tiny inline script that fetches the asset version BEFORE any loaders.
6072
+ * Sets window.__pa_v so CSS Before, JS Before, and all other loaders get ?v= cache bust.
6073
+ */
6074
+ injectVersionResolver(html) {
6075
+ const assetVersionUrl = this.config.assetVersionUrl || "";
6076
+ if (!assetVersionUrl) return html;
6077
+ const script = `<!-- === PATCH-ADAMS: VERSION RESOLVER === -->
6078
+ <script data-pa="version-resolver">
6079
+ (function(){try{var x=new XMLHttpRequest();x.open('GET','${assetVersionUrl}',false);x.send();if(x.status===200){window.__pa_v=JSON.parse(x.responseText).v||'1'}}catch(e){window.__pa_v='1'}})();
6080
+ </script>`;
6081
+ return html.replace(/<head([^>]*)>/i, `<head$1>
6082
+ ${script}`);
6083
+ }
6066
6084
  /**
6067
6085
  * Inject CSS Before loader at start of <head>
6068
6086
  */