@putkoff/abstract-utilities 0.1.215 → 0.1.216
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 +34 -69
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +34 -69
- package/dist/esm/index.js.map +1 -1
- package/package.json +4 -1
package/dist/esm/index.js
CHANGED
|
@@ -335,47 +335,47 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
335
335
|
*/
|
|
336
336
|
function readJsonFile(relativeOrAbsolutePath) {
|
|
337
337
|
return __awaiter(this, void 0, void 0, function* () {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
process.versions != null &&
|
|
341
|
-
process.versions.node) {
|
|
338
|
+
if (typeof window === 'undefined') {
|
|
339
|
+
// Node environment
|
|
342
340
|
try {
|
|
343
|
-
const
|
|
344
|
-
const
|
|
345
|
-
const filePath =
|
|
341
|
+
const { readFile } = yield import('fs/promises');
|
|
342
|
+
const { isAbsolute, resolve } = yield import('path');
|
|
343
|
+
const filePath = isAbsolute(relativeOrAbsolutePath)
|
|
346
344
|
? relativeOrAbsolutePath
|
|
347
|
-
:
|
|
348
|
-
const text = yield
|
|
345
|
+
: resolve(process.cwd(), relativeOrAbsolutePath);
|
|
346
|
+
const text = yield readFile(filePath, 'utf8');
|
|
349
347
|
return JSON.parse(text);
|
|
350
348
|
}
|
|
351
349
|
catch (_a) {
|
|
352
|
-
|
|
350
|
+
return null;
|
|
353
351
|
}
|
|
354
352
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
353
|
+
else {
|
|
354
|
+
// 2) Try browser fetch
|
|
355
|
+
const fetchFn = safeGlobalProp('fetch');
|
|
356
|
+
if (typeof fetchFn !== 'function') {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
// Resolve URL against document.baseURI if possible
|
|
360
|
+
let url = relativeOrAbsolutePath;
|
|
361
|
+
const baseURI = safeGlobalProp('document', 'baseURI');
|
|
362
|
+
if (baseURI) {
|
|
363
|
+
try {
|
|
364
|
+
url = new URL(relativeOrAbsolutePath, baseURI).href;
|
|
365
|
+
}
|
|
366
|
+
catch (_b) {
|
|
367
|
+
// keep url as-is
|
|
368
|
+
}
|
|
366
369
|
}
|
|
367
|
-
|
|
368
|
-
|
|
370
|
+
try {
|
|
371
|
+
const res = yield fetch(relativeOrAbsolutePath);
|
|
372
|
+
if (!res.ok)
|
|
373
|
+
return null;
|
|
374
|
+
return yield res.json();
|
|
369
375
|
}
|
|
370
|
-
|
|
371
|
-
try {
|
|
372
|
-
const res = yield fetchFn(url);
|
|
373
|
-
if (!res.ok)
|
|
376
|
+
catch (_c) {
|
|
374
377
|
return null;
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
catch (_c) {
|
|
378
|
-
return null;
|
|
378
|
+
}
|
|
379
379
|
}
|
|
380
380
|
});
|
|
381
381
|
}
|
|
@@ -1566,47 +1566,12 @@ function Spinner() {
|
|
|
1566
1566
|
*/
|
|
1567
1567
|
function getConfigJson() {
|
|
1568
1568
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1569
|
-
// Node environment: check if file exists
|
|
1570
|
-
if (typeof process !== 'undefined' &&
|
|
1571
|
-
process.versions != null &&
|
|
1572
|
-
process.versions.node) {
|
|
1573
|
-
try {
|
|
1574
|
-
// dynamically require fs to check existence
|
|
1575
|
-
const fs = yield import('fs');
|
|
1576
|
-
const path = yield import('path');
|
|
1577
|
-
const configPath = path.resolve(__dirname, 'config.json');
|
|
1578
|
-
if (fs.existsSync(configPath)) {
|
|
1579
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1580
|
-
return require(configPath);
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
catch (_a) {
|
|
1584
|
-
// fall through
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
// Browser or fallback: try fetching via HTTP
|
|
1588
|
-
const fetchFn = safeGlobalProp('fetch');
|
|
1589
|
-
if (typeof fetchFn === 'function') {
|
|
1590
|
-
try {
|
|
1591
|
-
const res = yield fetchFn('config.json');
|
|
1592
|
-
if (res.ok) {
|
|
1593
|
-
return (yield res.json());
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
catch (_b) {
|
|
1597
|
-
// ignore
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
// Node fallback: read from disk via readJsonFile
|
|
1601
1569
|
try {
|
|
1602
|
-
|
|
1603
|
-
return disk !== null && disk !== void 0 ? disk : {};
|
|
1570
|
+
return (yield readJsonFile('config.json')) || {};
|
|
1604
1571
|
}
|
|
1605
|
-
catch (
|
|
1606
|
-
|
|
1572
|
+
catch (_a) {
|
|
1573
|
+
return {};
|
|
1607
1574
|
}
|
|
1608
|
-
// final fallback
|
|
1609
|
-
return {};
|
|
1610
1575
|
});
|
|
1611
1576
|
}
|
|
1612
1577
|
|