@michalrakus/x-react-web-lib 1.32.10 → 1.32.11

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.
@@ -113,6 +113,7 @@ export declare class XUtils {
113
113
  static clearStorage(): void;
114
114
  static reloadIfNewVersion(): void;
115
115
  static reloadIfNewVersionNow(): Promise<void>;
116
+ static isLocalhost(): boolean;
116
117
  static isNewVersion(): Promise<boolean>;
117
118
  static reload(): void;
118
119
  }
@@ -781,9 +781,12 @@ var XUtils = /** @class */ (function () {
781
781
  });
782
782
  });
783
783
  };
784
+ XUtils.isLocalhost = function () {
785
+ return window.location.hostname === 'localhost';
786
+ };
784
787
  XUtils.isNewVersion = function () {
785
788
  return __awaiter(this, void 0, void 0, function () {
786
- var response, text, r, remoteMainScript, localMainScript, scripts, scripts_1, scripts_1_1, script, rl, err_1;
789
+ var response, text, remoteMainScript, r, localMainScript, scripts, scripts_1, scripts_1_1, script, rl, err_1;
787
790
  var e_7, _a;
788
791
  return __generator(this, function (_b) {
789
792
  switch (_b.label) {
@@ -795,25 +798,28 @@ var XUtils = /** @class */ (function () {
795
798
  return [4 /*yield*/, response.text()];
796
799
  case 2:
797
800
  text = _b.sent();
801
+ remoteMainScript = null;
798
802
  r = /^.*<script.*\/(main.*\.js).*$/gim.exec(text);
799
- if (!r || r.length < 2) {
800
- return [2 /*return*/, false];
803
+ if (r && r.length >= 2) {
804
+ remoteMainScript = r[1];
801
805
  }
802
- remoteMainScript = r.length > 1 ? r[1] : null;
803
806
  if (remoteMainScript === null) {
807
+ if (!XUtils.isLocalhost()) {
808
+ console.log("XUtils.isNewVersion(): Unexpected error - remoteMainScript (e.g. main.9d782ae7.js) not found in index.html from server. Content of index.html:");
809
+ console.log(text);
810
+ }
804
811
  return [2 /*return*/, false];
805
812
  }
806
813
  localMainScript = null;
807
- scripts = document.body.getElementsByTagName('script');
814
+ scripts = document.head.getElementsByTagName('script');
808
815
  try {
809
816
  for (scripts_1 = __values(scripts), scripts_1_1 = scripts_1.next(); !scripts_1_1.done; scripts_1_1 = scripts_1.next()) {
810
817
  script = scripts_1_1.value;
811
818
  rl = /^.*\/(main.*\.js).*$/gim.exec(script.src);
812
- if (!rl || rl.length < 2) {
813
- continue;
819
+ if (rl && rl.length >= 2) {
820
+ localMainScript = rl[1];
821
+ break;
814
822
  }
815
- localMainScript = rl[1];
816
- break;
817
823
  }
818
824
  }
819
825
  catch (e_7_1) { e_7 = { error: e_7_1 }; }
@@ -824,6 +830,10 @@ var XUtils = /** @class */ (function () {
824
830
  finally { if (e_7) throw e_7.error; }
825
831
  }
826
832
  if (localMainScript === null) {
833
+ if (!XUtils.isLocalhost()) {
834
+ console.log("XUtils.isNewVersion(): Unexpected error - localMainScript (e.g. main.9d782ae7.js) not found in element <head>...<script src=\"->here<-\"/>...</head>");
835
+ console.log(document.head);
836
+ }
827
837
  return [2 /*return*/, false];
828
838
  }
829
839
  return [2 /*return*/, remoteMainScript !== localMainScript];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michalrakus/x-react-web-lib",
3
- "version": "1.32.10",
3
+ "version": "1.32.11",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rimraf lib",