@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/cjs/index.js CHANGED
@@ -338,44 +338,37 @@ 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
- // 1) Try Node.js fs
342
- if (typeof process !== 'undefined' &&
343
- process.versions != null &&
344
- process.versions.node) {
341
+ if (typeof window === 'undefined') {
345
342
  try {
346
- const fs = yield import('fs');
347
- const path = yield import('path');
348
- const filePath = path.isAbsolute(relativeOrAbsolutePath)
343
+ const { readFile } = yield import('fs/promises');
344
+ const { isAbsolute, resolve } = yield import('path');
345
+ const filePath = isAbsolute(relativeOrAbsolutePath)
349
346
  ? relativeOrAbsolutePath
350
- : path.resolve(process.cwd(), relativeOrAbsolutePath);
351
- const text = yield fs.promises.readFile(filePath, 'utf8');
347
+ : resolve((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) ? new URL('.', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))).pathname : '', relativeOrAbsolutePath);
348
+ const text = yield readFile(filePath, 'utf8');
352
349
  return JSON.parse(text);
353
350
  }
354
351
  catch (_a) {
355
- // swallow and fall back to browser
352
+ return null;
356
353
  }
357
354
  }
358
- // 2) Try browser fetch
355
+ // Browser fallback
359
356
  const fetchFn = safeGlobalProp('fetch');
360
- if (typeof fetchFn !== 'function') {
357
+ if (typeof fetchFn !== 'function')
361
358
  return null;
362
- }
363
- // Resolve URL against document.baseURI if possible
364
359
  let url = relativeOrAbsolutePath;
365
360
  const baseURI = safeGlobalProp('document', 'baseURI');
366
361
  if (baseURI) {
367
362
  try {
368
363
  url = new URL(relativeOrAbsolutePath, baseURI).href;
369
364
  }
370
- catch (_b) {
371
- // keep url as-is
372
- }
365
+ catch (_b) { }
373
366
  }
374
367
  try {
375
368
  const res = yield fetchFn(url);
376
369
  if (!res.ok)
377
370
  return null;
378
- return (yield res.json());
371
+ return yield res.json();
379
372
  }
380
373
  catch (_c) {
381
374
  return null;
@@ -1340,9 +1333,12 @@ function fileURLToPath(fileUrl) {
1340
1333
  }
1341
1334
  }
1342
1335
  function getAbsolutePath() {
1336
+ if (typeof window !== 'undefined')
1337
+ return '';
1343
1338
  return fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
1344
1339
  }
1345
1340
 
1341
+ // path_utils.browser.ts
1346
1342
  function get_dirname(filePath) {
1347
1343
  if (!filePath)
1348
1344
  return '';
@@ -1569,47 +1565,12 @@ function Spinner() {
1569
1565
  */
1570
1566
  function getConfigJson() {
1571
1567
  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
1568
  try {
1605
- const disk = yield readJsonFile('config.json');
1606
- return disk !== null && disk !== void 0 ? disk : {};
1569
+ return (yield readJsonFile('config.json')) || {};
1607
1570
  }
1608
- catch (_c) {
1609
- // ignore
1571
+ catch (_a) {
1572
+ return {};
1610
1573
  }
1611
- // final fallback
1612
- return {};
1613
1574
  });
1614
1575
  }
1615
1576