@putkoff/abstract-utilities 0.1.172 → 0.1.173
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/esm/index.js
CHANGED
|
@@ -1141,28 +1141,30 @@ let _cachedConfig = null;
|
|
|
1141
1141
|
function loadConfig() {
|
|
1142
1142
|
return __awaiter(this, arguments, void 0, function* (filePath = null) {
|
|
1143
1143
|
var _a;
|
|
1144
|
-
// 1)
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
//
|
|
1144
|
+
// 1) If already cached, return it.
|
|
1145
|
+
if (_cachedConfig)
|
|
1146
|
+
return _cachedConfig;
|
|
1147
|
+
// 2) Build a base for URL.resolve:
|
|
1148
|
+
// try document.baseURI → window.location.href → "/"
|
|
1149
|
+
const docBase = safeGlobalProp("document", "baseURI");
|
|
1150
|
+
const winHref = typeof window !== "undefined" ? window.location.href : undefined;
|
|
1151
|
+
const base = (_a = docBase !== null && docBase !== void 0 ? docBase : winHref) !== null && _a !== void 0 ? _a : "/";
|
|
1152
|
+
// 3) Compute configUrl
|
|
1153
|
+
const relative = filePath || "config.json";
|
|
1149
1154
|
let configUrl;
|
|
1150
1155
|
try {
|
|
1151
|
-
configUrl = new URL(
|
|
1156
|
+
configUrl = new URL(relative, base).href;
|
|
1152
1157
|
}
|
|
1153
1158
|
catch (err) {
|
|
1154
|
-
console.warn(`[loadConfig]
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
// 4) return cached if we have it
|
|
1158
|
-
if (_cachedConfig) {
|
|
1159
|
-
return _cachedConfig;
|
|
1159
|
+
console.warn(`[loadConfig] invalid URL with base=${base} and file=${relative}:`, err);
|
|
1160
|
+
// abort early in Node / bad base
|
|
1161
|
+
return {};
|
|
1160
1162
|
}
|
|
1161
|
-
//
|
|
1163
|
+
// 4) Attempt fetch & parse, but swallow all errors
|
|
1162
1164
|
try {
|
|
1163
1165
|
const res = yield fetch(configUrl);
|
|
1164
1166
|
if (!res.ok) {
|
|
1165
|
-
console.warn(`[loadConfig]
|
|
1167
|
+
console.warn(`[loadConfig] fetch failed ${res.status} ${res.statusText} @`, configUrl);
|
|
1166
1168
|
return {};
|
|
1167
1169
|
}
|
|
1168
1170
|
const json = (yield res.json());
|
|
@@ -1170,7 +1172,7 @@ function loadConfig() {
|
|
|
1170
1172
|
return json;
|
|
1171
1173
|
}
|
|
1172
1174
|
catch (err) {
|
|
1173
|
-
console.warn(`[loadConfig] error
|
|
1175
|
+
console.warn(`[loadConfig] network/json error for ${configUrl}:`, err);
|
|
1174
1176
|
return {};
|
|
1175
1177
|
}
|
|
1176
1178
|
});
|