Skip to content

Commit fd60793

Browse files
committed
fix: restore i18n.js cache busting via window.$C.BUILD_NUMBER
1 parent a6748d3 commit fd60793

File tree

8 files changed

+184
-32
lines changed

8 files changed

+184
-32
lines changed

splunk_add_on_ucc_framework/package/appserver/templates/base.html

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,30 @@
2222
<title>Loading</title>
2323
<meta name="viewport" content="width=device-width, initial-scale=1" />
2424
<script src="../../config?autoload=1" crossorigin="use-credentials"></script>
25-
<script src="../../static/js/i18n.js"></script>
26-
<script src="../../i18ncatalog?autoload=1"></script>
2725
</head>
2826

2927
<body>
30-
<script type="module" src="../../static/app/__APP_NAME__/js/build/entry_page.js"></script>
28+
<script>
29+
var _b = window.$C && window.$C.BUILD_NUMBER ? '/@' + window.$C.BUILD_NUMBER : '';
30+
var _p = _b && window.$C.BUILD_PUSH_NUMBER ? '.' + window.$C.BUILD_PUSH_NUMBER : '';
31+
function _loadScript(src, type) {
32+
return new Promise(function (resolve, reject) {
33+
var s = document.createElement('script');
34+
if (type) s.type = type;
35+
s.src = src;
36+
s.onload = resolve;
37+
s.onerror = reject;
38+
document.head.appendChild(s);
39+
});
40+
}
41+
_loadScript('../../static' + _b + _p + '/js/i18n.js')
42+
.then(function () { return _loadScript('../../i18ncatalog?autoload=1'); })
43+
.then(function () {
44+
return _loadScript(
45+
'../../static/app/__APP_NAME__/js/build/entry_page.js',
46+
'module'
47+
);
48+
});
49+
</script>
3150
</body>
3251
</html>

splunk_add_on_ucc_framework/package/appserver/templates/redirect.html

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,30 @@
2222
<title>Loading</title>
2323
<meta name="viewport" content="width=device-width, initial-scale=1" />
2424
<script src="../../config?autoload=1" crossorigin="use-credentials"></script>
25-
<script src="../../static/js/i18n.js"></script>
26-
<script src="../../i18ncatalog?autoload=1"></script>
2725
</head>
2826

2927
<body>
30-
<script
31-
type="module"
32-
src="../../static/app/__APP_NAME__/js/build/__TA_NAME___redirect_page.__TA_VERSION__.js"
33-
></script>
28+
<script>
29+
var _b = window.$C && window.$C.BUILD_NUMBER ? '/@' + window.$C.BUILD_NUMBER : '';
30+
var _p = _b && window.$C.BUILD_PUSH_NUMBER ? '.' + window.$C.BUILD_PUSH_NUMBER : '';
31+
function _loadScript(src, type) {
32+
return new Promise(function (resolve, reject) {
33+
var s = document.createElement('script');
34+
if (type) s.type = type;
35+
s.src = src;
36+
s.onload = resolve;
37+
s.onerror = reject;
38+
document.head.appendChild(s);
39+
});
40+
}
41+
_loadScript('../../static' + _b + _p + '/js/i18n.js')
42+
.then(function () { return _loadScript('../../i18ncatalog?autoload=1'); })
43+
.then(function () {
44+
return _loadScript(
45+
'../../static/app/__APP_NAME__/js/build/__TA_NAME___redirect_page.__TA_VERSION__.js',
46+
'module'
47+
);
48+
});
49+
</script>
3450
</body>
3551
</html>

tests/testdata/expected_addons/expected_addon_no_configuration/Splunk_TA_UCCExample/appserver/templates/base.html

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,30 @@
2222
<title>Loading</title>
2323
<meta name="viewport" content="width=device-width, initial-scale=1" />
2424
<script src="../../config?autoload=1" crossorigin="use-credentials"></script>
25-
<script src="../../static/js/i18n.js"></script>
26-
<script src="../../i18ncatalog?autoload=1"></script>
2725
</head>
2826

2927
<body>
30-
<script type="module" src="../../static/app/Splunk_TA_UCCExample/js/build/entry_page.js"></script>
28+
<script>
29+
var _b = window.$C && window.$C.BUILD_NUMBER ? '/@' + window.$C.BUILD_NUMBER : '';
30+
var _p = _b && window.$C.BUILD_PUSH_NUMBER ? '.' + window.$C.BUILD_PUSH_NUMBER : '';
31+
function _loadScript(src, type) {
32+
return new Promise(function (resolve, reject) {
33+
var s = document.createElement('script');
34+
if (type) s.type = type;
35+
s.src = src;
36+
s.onload = resolve;
37+
s.onerror = reject;
38+
document.head.appendChild(s);
39+
});
40+
}
41+
_loadScript('../../static' + _b + _p + '/js/i18n.js')
42+
.then(function () { return _loadScript('../../i18ncatalog?autoload=1'); })
43+
.then(function () {
44+
return _loadScript(
45+
'../../static/app/Splunk_TA_UCCExample/js/build/entry_page.js',
46+
'module'
47+
);
48+
});
49+
</script>
3150
</body>
3251
</html>

tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/appserver/templates/base.html

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,30 @@
2222
<title>Loading</title>
2323
<meta name="viewport" content="width=device-width, initial-scale=1" />
2424
<script src="../../config?autoload=1" crossorigin="use-credentials"></script>
25-
<script src="../../static/js/i18n.js"></script>
26-
<script src="../../i18ncatalog?autoload=1"></script>
2725
</head>
2826

2927
<body>
30-
<script type="module" src="../../static/app/Splunk_TA_UCCExample/js/build/entry_page.js"></script>
28+
<script>
29+
var _b = window.$C && window.$C.BUILD_NUMBER ? '/@' + window.$C.BUILD_NUMBER : '';
30+
var _p = _b && window.$C.BUILD_PUSH_NUMBER ? '.' + window.$C.BUILD_PUSH_NUMBER : '';
31+
function _loadScript(src, type) {
32+
return new Promise(function (resolve, reject) {
33+
var s = document.createElement('script');
34+
if (type) s.type = type;
35+
s.src = src;
36+
s.onload = resolve;
37+
s.onerror = reject;
38+
document.head.appendChild(s);
39+
});
40+
}
41+
_loadScript('../../static' + _b + _p + '/js/i18n.js')
42+
.then(function () { return _loadScript('../../i18ncatalog?autoload=1'); })
43+
.then(function () {
44+
return _loadScript(
45+
'../../static/app/Splunk_TA_UCCExample/js/build/entry_page.js',
46+
'module'
47+
);
48+
});
49+
</script>
3150
</body>
3251
</html>

tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/appserver/templates/splunk_ta_uccexample_redirect.html

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,30 @@
2222
<title>Loading</title>
2323
<meta name="viewport" content="width=device-width, initial-scale=1" />
2424
<script src="../../config?autoload=1" crossorigin="use-credentials"></script>
25-
<script src="../../static/js/i18n.js"></script>
26-
<script src="../../i18ncatalog?autoload=1"></script>
2725
</head>
2826

2927
<body>
30-
<script
31-
type="module"
32-
src="../../static/app/Splunk_TA_UCCExample/js/build/splunk_ta_uccexample_redirect_page.1.0.0.js"
33-
></script>
28+
<script>
29+
var _b = window.$C && window.$C.BUILD_NUMBER ? '/@' + window.$C.BUILD_NUMBER : '';
30+
var _p = _b && window.$C.BUILD_PUSH_NUMBER ? '.' + window.$C.BUILD_PUSH_NUMBER : '';
31+
function _loadScript(src, type) {
32+
return new Promise(function (resolve, reject) {
33+
var s = document.createElement('script');
34+
if (type) s.type = type;
35+
s.src = src;
36+
s.onload = resolve;
37+
s.onerror = reject;
38+
document.head.appendChild(s);
39+
});
40+
}
41+
_loadScript('../../static' + _b + _p + '/js/i18n.js')
42+
.then(function () { return _loadScript('../../i18ncatalog?autoload=1'); })
43+
.then(function () {
44+
return _loadScript(
45+
'../../static/app/Splunk_TA_UCCExample/js/build/splunk_ta_uccexample_redirect_page.1.0.0.js',
46+
'module'
47+
);
48+
});
49+
</script>
3450
</body>
3551
</html>

tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/appserver/templates/base.html

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,30 @@
2222
<title>Loading</title>
2323
<meta name="viewport" content="width=device-width, initial-scale=1" />
2424
<script src="../../config?autoload=1" crossorigin="use-credentials"></script>
25-
<script src="../../static/js/i18n.js"></script>
26-
<script src="../../i18ncatalog?autoload=1"></script>
2725
</head>
2826

2927
<body>
30-
<script type="module" src="../../static/app/Splunk_TA_UCCExample/js/build/entry_page.js"></script>
28+
<script>
29+
var _b = window.$C && window.$C.BUILD_NUMBER ? '/@' + window.$C.BUILD_NUMBER : '';
30+
var _p = _b && window.$C.BUILD_PUSH_NUMBER ? '.' + window.$C.BUILD_PUSH_NUMBER : '';
31+
function _loadScript(src, type) {
32+
return new Promise(function (resolve, reject) {
33+
var s = document.createElement('script');
34+
if (type) s.type = type;
35+
s.src = src;
36+
s.onload = resolve;
37+
s.onerror = reject;
38+
document.head.appendChild(s);
39+
});
40+
}
41+
_loadScript('../../static' + _b + _p + '/js/i18n.js')
42+
.then(function () { return _loadScript('../../i18ncatalog?autoload=1'); })
43+
.then(function () {
44+
return _loadScript(
45+
'../../static/app/Splunk_TA_UCCExample/js/build/entry_page.js',
46+
'module'
47+
);
48+
});
49+
</script>
3150
</body>
3251
</html>

tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/appserver/templates/splunk_ta_uccexample_redirect.html

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,30 @@
2222
<title>Loading</title>
2323
<meta name="viewport" content="width=device-width, initial-scale=1" />
2424
<script src="../../config?autoload=1" crossorigin="use-credentials"></script>
25-
<script src="../../static/js/i18n.js"></script>
26-
<script src="../../i18ncatalog?autoload=1"></script>
2725
</head>
2826

2927
<body>
30-
<script
31-
type="module"
32-
src="../../static/app/Splunk_TA_UCCExample/js/build/splunk_ta_uccexample_redirect_page.5.5.8R5fd76615.js"
33-
></script>
28+
<script>
29+
var _b = window.$C && window.$C.BUILD_NUMBER ? '/@' + window.$C.BUILD_NUMBER : '';
30+
var _p = _b && window.$C.BUILD_PUSH_NUMBER ? '.' + window.$C.BUILD_PUSH_NUMBER : '';
31+
function _loadScript(src, type) {
32+
return new Promise(function (resolve, reject) {
33+
var s = document.createElement('script');
34+
if (type) s.type = type;
35+
s.src = src;
36+
s.onload = resolve;
37+
s.onerror = reject;
38+
document.head.appendChild(s);
39+
});
40+
}
41+
_loadScript('../../static' + _b + _p + '/js/i18n.js')
42+
.then(function () { return _loadScript('../../i18ncatalog?autoload=1'); })
43+
.then(function () {
44+
return _loadScript(
45+
'../../static/app/Splunk_TA_UCCExample/js/build/splunk_ta_uccexample_redirect_page.5.5.8R5fd76615.js',
46+
'module'
47+
);
48+
});
49+
</script>
3450
</body>
3551
</html>

tests/unit/test_package_files_update.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ def test_package_files_update_replaces_legacy_base_template(tmp_path, caplog):
4949
handle_package_files_update(str(tmp_path))
5050

5151
assert '<script src="../../config?autoload=1"' in template_path.read_text()
52+
assert "window.$C.BUILD_NUMBER" in template_path.read_text()
5253
assert (
53-
'<script type="module" src="../../static/app/__APP_NAME__/js/build/entry_page.js"></script>'
54+
"'../../static/app/__APP_NAME__/js/build/entry_page.js'"
5455
in template_path.read_text()
5556
)
5657
assert "cherrypy.request.path_info" not in template_path.read_text()
@@ -70,8 +71,9 @@ def test_package_files_update_replaces_legacy_redirect_template(tmp_path, caplog
7071
handle_package_files_update(str(tmp_path))
7172

7273
assert '<script src="../../config?autoload=1"' in template_path.read_text()
74+
assert "window.$C.BUILD_NUMBER" in template_path.read_text()
7375
assert (
74-
"../../static/app/__APP_NAME__/js/build/__TA_NAME___redirect_page.__TA_VERSION__.js"
76+
"'../../static/app/__APP_NAME__/js/build/__TA_NAME___redirect_page.__TA_VERSION__.js'"
7577
in template_path.read_text()
7678
)
7779
assert "cherrypy.request.path_info" not in template_path.read_text()
@@ -100,3 +102,29 @@ def test_package_files_update_leaves_custom_template_unchanged(tmp_path, caplog)
100102

101103
def test_package_files_update_noop_when_templates_are_absent(tmp_path):
102104
handle_package_files_update(str(tmp_path))
105+
106+
107+
def test_base_template_cache_busting_script():
108+
from pathlib import Path
109+
110+
template = Path(
111+
"splunk_add_on_ucc_framework/package/appserver/templates/base.html"
112+
).read_text()
113+
114+
# BUILD_NUMBER is used for the cache buster path segment
115+
assert "window.$C.BUILD_NUMBER" in template
116+
# BUILD_PUSH_NUMBER is only appended when BUILD_NUMBER is present
117+
assert "_b && window.$C.BUILD_PUSH_NUMBER" in template
118+
# fallback to no cache buster when $C is unavailable
119+
assert "? '/@' + window.$C.BUILD_NUMBER : ''" in template
120+
assert "? '.' + window.$C.BUILD_PUSH_NUMBER : ''" in template
121+
# i18n.js URL is built using the cache buster
122+
assert "_loadScript('../../static' + _b + _p + '/js/i18n.js')" in template
123+
# i18ncatalog loads after i18n.js
124+
assert (
125+
".then(function () { return _loadScript('../../i18ncatalog?autoload=1'); })"
126+
in template
127+
)
128+
# entry_page.js loads last, as a module
129+
assert "'../../static/app/__APP_NAME__/js/build/entry_page.js'" in template
130+
assert "'module'" in template

0 commit comments

Comments
 (0)