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