@patch-adams/core 1.6.2 → 1.6.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.
package/dist/index.cjs CHANGED
@@ -252,8 +252,8 @@ export default config;
252
252
 
253
253
  // src/templates/css-before.ts
254
254
  function generateCssBeforeLoader(options) {
255
- const { remoteUrl, localPath, htmlClass, loadingClass } = options;
256
- return `<!-- === PATCH-ADAMS: CSS BEFORE (blocking) === -->
255
+ const { remoteUrl, localPath, htmlClass, loadingClass, assetVersionUrl } = options;
256
+ return `<!-- === PATCH-ARMS: CSS BEFORE (blocking) === -->
257
257
  <style data-pa="css-before-critical">
258
258
  /* Critical: Hide content until ready */
259
259
  html.${htmlClass}.${loadingClass} body {
@@ -263,6 +263,19 @@ html.${htmlClass}.${loadingClass} body {
263
263
  <script data-pa="css-before-loader">
264
264
  (function() {
265
265
  'use strict';
266
+ // Fetch asset version FIRST \u2014 this is the earliest loader, so it sets window.__pa_v for all others
267
+ if (typeof window.__pa_v === 'undefined') {
268
+ window.__pa_v = '';
269
+ var AVU = "${assetVersionUrl || ""}";
270
+ if (AVU) {
271
+ try {
272
+ var xhr = new XMLHttpRequest();
273
+ xhr.open('GET', AVU, false);
274
+ xhr.send();
275
+ if (xhr.status === 200) { window.__pa_v = JSON.parse(xhr.responseText).v || '1'; }
276
+ } catch(e) { window.__pa_v = '1'; }
277
+ }
278
+ }
266
279
  var v = window.__pa_v || '';
267
280
  var REMOTE_URL = "${remoteUrl}" + (v ? "?v=" + v : "");
268
281
  var LOCAL_PATH = "${localPath}";
@@ -296,7 +309,8 @@ function buildCssBeforeOptions(config) {
296
309
  remoteUrl: `${config.remoteDomain}/${config.localFolders.css}/${config.cssBefore.filename}`,
297
310
  localPath: `${config.localFolders.css}/${config.cssBefore.filename}`,
298
311
  htmlClass: config.htmlClass,
299
- loadingClass: config.loadingClass
312
+ loadingClass: config.loadingClass,
313
+ assetVersionUrl: config.assetVersionUrl
300
314
  };
301
315
  }
302
316
 
@@ -5972,7 +5986,6 @@ var HtmlInjector = class {
5972
5986
  inject(html) {
5973
5987
  let result = html;
5974
5988
  result = this.addHtmlAttributes(result);
5975
- result = this.injectVersionResolver(result);
5976
5989
  if (this.config.cssBefore.enabled) {
5977
5990
  result = this.injectCssBefore(result);
5978
5991
  }
@@ -6076,20 +6089,6 @@ ${pluginJs}
6076
6089
  escapeAttr(str) {
6077
6090
  return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
6078
6091
  }
6079
- /**
6080
- * Inject a tiny inline script that fetches the asset version BEFORE any loaders.
6081
- * Sets window.__pa_v so CSS Before, JS Before, and all other loaders get ?v= cache bust.
6082
- */
6083
- injectVersionResolver(html) {
6084
- const assetVersionUrl = this.config.assetVersionUrl || "";
6085
- if (!assetVersionUrl) return html;
6086
- const script = `<!-- === PATCH-ADAMS: VERSION RESOLVER === -->
6087
- <script data-pa="version-resolver">
6088
- (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'}})();
6089
- </script>`;
6090
- return html.replace(/<head([^>]*)>/i, `<head$1>
6091
- ${script}`);
6092
- }
6093
6092
  /**
6094
6093
  * Inject CSS Before loader at start of <head>
6095
6094
  */