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