@putkoff/abstract-utilities 0.1.215 → 0.1.218

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,44 +335,37 @@ 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') {
342
339
  try {
343
- const fs = yield import('fs');
344
- const path = yield import('path');
345
- const filePath = path.isAbsolute(relativeOrAbsolutePath)
340
+ const { readFile } = yield import('fs/promises');
341
+ const { isAbsolute, resolve } = yield import('path');
342
+ const filePath = isAbsolute(relativeOrAbsolutePath)
346
343
  ? relativeOrAbsolutePath
347
- : path.resolve(process.cwd(), relativeOrAbsolutePath);
348
- const text = yield fs.promises.readFile(filePath, 'utf8');
344
+ : resolve(import.meta.url ? new URL('.', import.meta.url).pathname : '', relativeOrAbsolutePath);
345
+ const text = yield readFile(filePath, 'utf8');
349
346
  return JSON.parse(text);
350
347
  }
351
348
  catch (_a) {
352
- // swallow and fall back to browser
349
+ return null;
353
350
  }
354
351
  }
355
- // 2) Try browser fetch
352
+ // Browser fallback
356
353
  const fetchFn = safeGlobalProp('fetch');
357
- if (typeof fetchFn !== 'function') {
354
+ if (typeof fetchFn !== 'function')
358
355
  return null;
359
- }
360
- // Resolve URL against document.baseURI if possible
361
356
  let url = relativeOrAbsolutePath;
362
357
  const baseURI = safeGlobalProp('document', 'baseURI');
363
358
  if (baseURI) {
364
359
  try {
365
360
  url = new URL(relativeOrAbsolutePath, baseURI).href;
366
361
  }
367
- catch (_b) {
368
- // keep url as-is
369
- }
362
+ catch (_b) { }
370
363
  }
371
364
  try {
372
365
  const res = yield fetchFn(url);
373
366
  if (!res.ok)
374
367
  return null;
375
- return (yield res.json());
368
+ return yield res.json();
376
369
  }
377
370
  catch (_c) {
378
371
  return null;
@@ -1337,9 +1330,12 @@ function fileURLToPath(fileUrl) {
1337
1330
  }
1338
1331
  }
1339
1332
  function getAbsolutePath() {
1333
+ if (typeof window !== 'undefined')
1334
+ return '';
1340
1335
  return fileURLToPath(import.meta.url);
1341
1336
  }
1342
1337
 
1338
+ // path_utils.browser.ts
1343
1339
  function get_dirname(filePath) {
1344
1340
  if (!filePath)
1345
1341
  return '';
@@ -1566,47 +1562,12 @@ function Spinner() {
1566
1562
  */
1567
1563
  function getConfigJson() {
1568
1564
  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
1565
  try {
1602
- const disk = yield readJsonFile('config.json');
1603
- return disk !== null && disk !== void 0 ? disk : {};
1566
+ return (yield readJsonFile('config.json')) || {};
1604
1567
  }
1605
- catch (_c) {
1606
- // ignore
1568
+ catch (_a) {
1569
+ return {};
1607
1570
  }
1608
- // final fallback
1609
- return {};
1610
1571
  });
1611
1572
  }
1612
1573