@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/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
- // 1) Try Node.js fs
339
- if (typeof process !== 'undefined' &&
340
- process.versions != null &&
341
- process.versions.node) {
338
+ if (typeof window === 'undefined') {
339
+ // Node environment
342
340
  try {
343
- const fs = yield import('fs');
344
- const path = yield import('path');
345
- const filePath = path.isAbsolute(relativeOrAbsolutePath)
341
+ const { readFile } = yield import('fs/promises');
342
+ const { isAbsolute, resolve } = yield import('path');
343
+ const filePath = isAbsolute(relativeOrAbsolutePath)
346
344
  ? relativeOrAbsolutePath
347
- : path.resolve(process.cwd(), relativeOrAbsolutePath);
348
- const text = yield fs.promises.readFile(filePath, 'utf8');
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
- // swallow and fall back to browser
350
+ return null;
353
351
  }
354
352
  }
355
- // 2) Try browser fetch
356
- const fetchFn = safeGlobalProp('fetch');
357
- if (typeof fetchFn !== 'function') {
358
- return null;
359
- }
360
- // Resolve URL against document.baseURI if possible
361
- let url = relativeOrAbsolutePath;
362
- const baseURI = safeGlobalProp('document', 'baseURI');
363
- if (baseURI) {
364
- try {
365
- url = new URL(relativeOrAbsolutePath, baseURI).href;
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
- catch (_b) {
368
- // keep url as-is
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
- return (yield res.json());
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
- const disk = yield readJsonFile('config.json');
1603
- return disk !== null && disk !== void 0 ? disk : {};
1570
+ return (yield readJsonFile('config.json')) || {};
1604
1571
  }
1605
- catch (_c) {
1606
- // ignore
1572
+ catch (_a) {
1573
+ return {};
1607
1574
  }
1608
- // final fallback
1609
- return {};
1610
1575
  });
1611
1576
  }
1612
1577