@interface-technologies/check-for-js-bundle-update-saga 6.0.2 → 6.0.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/checkForJsBundleUpdateSaga.js +14 -22
- package/dist/index.js +1 -5
- package/package.json +4 -3
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.getIndexHtml = getIndexHtml;
|
|
7
|
-
exports.reload = reload;
|
|
8
|
-
exports.checkForJsBundleUpdateSaga = checkForJsBundleUpdateSaga;
|
|
9
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
10
|
-
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
11
|
-
const effects_1 = require("redux-saga/effects");
|
|
12
|
-
const iti_react_1 = require("@interface-technologies/iti-react");
|
|
13
|
-
const defaultDelayDuration = moment_timezone_1.default.duration(4, 'minutes');
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import moment from 'moment-timezone';
|
|
3
|
+
import { delay, call } from 'redux-saga/effects';
|
|
4
|
+
import { alert } from '@interface-technologies/iti-react';
|
|
5
|
+
const defaultDelayDuration = moment.duration(4, 'minutes');
|
|
14
6
|
const forceRefreshAfterAlertCount = 3;
|
|
15
7
|
/** @internal */
|
|
16
|
-
function getIndexHtml() {
|
|
8
|
+
export function getIndexHtml() {
|
|
17
9
|
return (fetch('/')
|
|
18
10
|
.then((response) => {
|
|
19
11
|
if (!response.ok)
|
|
@@ -24,7 +16,7 @@ function getIndexHtml() {
|
|
|
24
16
|
.catch(() => undefined));
|
|
25
17
|
}
|
|
26
18
|
/** @internal */
|
|
27
|
-
function reload() {
|
|
19
|
+
export function reload() {
|
|
28
20
|
window.location.reload();
|
|
29
21
|
}
|
|
30
22
|
function getBundleSrcFromDocument(doc, bundleSrcPattern) {
|
|
@@ -78,17 +70,17 @@ function getBundleSrcFromDocument(doc, bundleSrcPattern) {
|
|
|
78
70
|
* }
|
|
79
71
|
* ```
|
|
80
72
|
*/
|
|
81
|
-
function* checkForJsBundleUpdateSaga({ delayDuration = defaultDelayDuration, onError, bundleSrcPattern = /app\.\S+\.js/, }) {
|
|
73
|
+
export function* checkForJsBundleUpdateSaga({ delayDuration = defaultDelayDuration, onError, bundleSrcPattern = /app\.\S+\.js/, }) {
|
|
82
74
|
const bundleSrc = getBundleSrcFromDocument(document, bundleSrcPattern);
|
|
83
75
|
if (!bundleSrc) {
|
|
84
76
|
onError(new Error('Could not get bundle src from current document.'));
|
|
85
77
|
return;
|
|
86
78
|
}
|
|
87
|
-
yield
|
|
79
|
+
yield delay(delayDuration.asMilliseconds());
|
|
88
80
|
let alertShownCount = 0;
|
|
89
81
|
for (;;) {
|
|
90
82
|
try {
|
|
91
|
-
const indexHtml = (yield
|
|
83
|
+
const indexHtml = (yield call(getIndexHtml));
|
|
92
84
|
if (indexHtml) {
|
|
93
85
|
const retrievedDocument = new DOMParser().parseFromString(indexHtml, 'text/html');
|
|
94
86
|
const retrievedBundleSrc = getBundleSrcFromDocument(retrievedDocument, bundleSrcPattern);
|
|
@@ -97,13 +89,13 @@ function* checkForJsBundleUpdateSaga({ delayDuration = defaultDelayDuration, onE
|
|
|
97
89
|
return;
|
|
98
90
|
}
|
|
99
91
|
if (bundleSrc !== retrievedBundleSrc) {
|
|
100
|
-
const content = ((
|
|
92
|
+
const content = (_jsxs("div", { children: [_jsx("p", { children: "Please save your work and refresh the page." }), _jsx("p", { className: "mb-0", children: "You may encounter errors if you do not refresh the page." })] }));
|
|
101
93
|
if (alertShownCount >= forceRefreshAfterAlertCount) {
|
|
102
94
|
window.onbeforeunload = null;
|
|
103
|
-
yield
|
|
95
|
+
yield call(reload);
|
|
104
96
|
return;
|
|
105
97
|
}
|
|
106
|
-
yield
|
|
98
|
+
yield call(alert, content, { title: 'Website Update Available!' });
|
|
107
99
|
alertShownCount += 1;
|
|
108
100
|
}
|
|
109
101
|
}
|
|
@@ -111,6 +103,6 @@ function* checkForJsBundleUpdateSaga({ delayDuration = defaultDelayDuration, onE
|
|
|
111
103
|
catch (e) {
|
|
112
104
|
onError(e);
|
|
113
105
|
}
|
|
114
|
-
yield
|
|
106
|
+
yield delay(delayDuration.asMilliseconds());
|
|
115
107
|
}
|
|
116
108
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkForJsBundleUpdateSaga = void 0;
|
|
4
|
-
var checkForJsBundleUpdateSaga_1 = require("./checkForJsBundleUpdateSaga");
|
|
5
|
-
Object.defineProperty(exports, "checkForJsBundleUpdateSaga", { enumerable: true, get: function () { return checkForJsBundleUpdateSaga_1.checkForJsBundleUpdateSaga; } });
|
|
1
|
+
export { checkForJsBundleUpdateSaga } from './checkForJsBundleUpdateSaga';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interface-technologies/check-for-js-bundle-update-saga",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"description": "Redux saga for checking if a JavaScript app has been deployed.",
|
|
5
5
|
"homepage": "https://github.com/srmagura/iti-react",
|
|
6
6
|
"repository": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"author": "Interface Technologies, Inc.",
|
|
12
|
+
"type": "module",
|
|
12
13
|
"main": "dist/index.js",
|
|
13
14
|
"types": "dist/index.d.ts",
|
|
14
15
|
"files": [
|
|
@@ -22,8 +23,8 @@
|
|
|
22
23
|
"redux-saga": "^1.3.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@interface-technologies/iti-react": "6.0.
|
|
26
|
-
"@interface-technologies/tsconfig": "6.0.
|
|
26
|
+
"@interface-technologies/iti-react": "6.0.3",
|
|
27
|
+
"@interface-technologies/tsconfig": "6.0.3",
|
|
27
28
|
"@redux-saga/is": "^1.1.3",
|
|
28
29
|
"@redux-saga/symbols": "^1.1.3",
|
|
29
30
|
"react": "^19.2.4",
|