@hkdigital/lib-core 0.5.75 → 0.5.77

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.5.75",
3
+ "version": "0.5.77",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"
@@ -286,6 +286,7 @@ async function findExternalBarrelExport(importPath, targetName) {
286
286
  // 1. Explicit index.js imports
287
287
  // 2. Component files (.svelte)
288
288
  // 3. Class files (capitalized .js)
289
+ // 4. Imports without extension (missing extension or directory)
289
290
  let shouldCheck = false;
290
291
 
291
292
  if (lastPart === 'index.js') {
@@ -294,6 +295,9 @@ async function findExternalBarrelExport(importPath, targetName) {
294
295
  shouldCheck = true;
295
296
  } else if (lastPart.match(/^[A-Z][^/]*\.js$/)) {
296
297
  shouldCheck = true;
298
+ } else if (!lastPart.includes('.')) {
299
+ // No extension - could be missing or directory import
300
+ shouldCheck = true;
297
301
  }
298
302
 
299
303
  if (!shouldCheck) return null;
@@ -421,6 +425,7 @@ async function findAliasBarrelExport(importPath, targetName) {
421
425
  // 1. Explicit index.js imports
422
426
  // 2. Component files (.svelte)
423
427
  // 3. Class files (capitalized .js)
428
+ // 4. Imports without extension (missing extension or directory)
424
429
  let shouldCheck = false;
425
430
 
426
431
  if (lastPart === 'index.js') {
@@ -429,6 +434,9 @@ async function findAliasBarrelExport(importPath, targetName) {
429
434
  shouldCheck = true;
430
435
  } else if (lastPart.match(/^[A-Z][^/]*\.js$/)) {
431
436
  shouldCheck = true;
437
+ } else if (!lastPart.includes('.')) {
438
+ // No extension - could be missing or directory import
439
+ shouldCheck = true;
432
440
  }
433
441
 
434
442
  if (!shouldCheck) return null;
@@ -534,6 +542,7 @@ async function validateFile(filePath) {
534
542
  const importedNames = extractImportNames(line);
535
543
 
536
544
  // Check each imported name for barrel exports
545
+ let foundBarrel = false;
537
546
  for (const importedName of importedNames) {
538
547
  const barrelPath = await findAliasBarrelExport(
539
548
  importPath,
@@ -546,35 +555,38 @@ async function validateFile(filePath) {
546
555
  ` from '${importPath}'\n` +
547
556
  ` => from '${barrelPath}' (use barrel export)`
548
557
  );
558
+ foundBarrel = true;
549
559
  break; // Only report once per line
550
560
  }
551
561
  }
552
562
 
553
- // Check if alias import is missing file extension
554
- // Allow any extension (not just .js/.svelte) to support assets
555
- const hasExtension = importPath.match(/\.[^/]+$/);
556
-
557
- if (!hasExtension) {
558
- // Extract path after alias to check if it's not just the alias
559
- let pathAfterAlias = null;
560
- for (const alias of Object.keys(PROJECT_ALIASES)) {
561
- if (importPath === alias || importPath.startsWith(alias + '/')) {
562
- pathAfterAlias = importPath.slice(alias.length);
563
- if (pathAfterAlias.startsWith('/')) {
564
- pathAfterAlias = pathAfterAlias.slice(1);
563
+ // Only check for missing extension if no barrel was found
564
+ if (!foundBarrel) {
565
+ const hasExtension = importPath.match(/\.[^/]+$/);
566
+
567
+ if (!hasExtension) {
568
+ // Extract path after alias
569
+ let pathAfterAlias = null;
570
+ for (const alias of Object.keys(PROJECT_ALIASES)) {
571
+ if (importPath === alias ||
572
+ importPath.startsWith(alias + '/')) {
573
+ pathAfterAlias = importPath.slice(alias.length);
574
+ if (pathAfterAlias.startsWith('/')) {
575
+ pathAfterAlias = pathAfterAlias.slice(1);
576
+ }
577
+ break;
565
578
  }
566
- break;
567
579
  }
568
- }
569
580
 
570
- // Only error if there's a path after the alias
571
- if (pathAfterAlias && pathAfterAlias.length > 0) {
572
- errors.push(
573
- `${relativePath}:${lineNum}\n` +
574
- ` from '${importPath}'\n` +
575
- ` => Missing file extension (add .js, .svelte, ` +
576
- `or .svelte.js)`
577
- );
581
+ // Only error if there's a path after the alias
582
+ if (pathAfterAlias && pathAfterAlias.length > 0) {
583
+ errors.push(
584
+ `${relativePath}:${lineNum}\n` +
585
+ ` from '${importPath}'\n` +
586
+ ` => Missing file extension ` +
587
+ `(add .js, .svelte, or .svelte.js)`
588
+ );
589
+ }
578
590
  }
579
591
  }
580
592
 
@@ -598,6 +610,7 @@ async function validateFile(filePath) {
598
610
  const importedNames = extractImportNames(line);
599
611
 
600
612
  // Check each imported name for barrel exports
613
+ let foundBarrel = false;
601
614
  for (const importedName of importedNames) {
602
615
  const barrelPath = await findExternalBarrelExport(
603
616
  importPath,
@@ -610,28 +623,30 @@ async function validateFile(filePath) {
610
623
  ` from '${importPath}'\n` +
611
624
  ` => from '${barrelPath}' (use barrel export)`
612
625
  );
626
+ foundBarrel = true;
613
627
  break; // Only report once per line
614
628
  }
615
629
  }
616
630
 
617
- // Check if external import is missing file extension
618
- // Allow any extension (not just .js/.svelte) to support assets
619
- const hasExtension = importPath.match(/\.[^/]+$/);
631
+ // Only check for missing extension if no barrel was found
632
+ if (!foundBarrel) {
633
+ const hasExtension = importPath.match(/\.[^/]+$/);
620
634
 
621
- if (!hasExtension) {
622
- // Extract package name and check if there's a path
623
- const pkgName = importPath.startsWith('@') ?
624
- `${parts[0]}/${parts[1]}` : parts[0];
625
- const pathInPackage = importPath.slice(pkgName.length);
635
+ if (!hasExtension) {
636
+ // Extract package name and check if there's a path
637
+ const pkgName = importPath.startsWith('@') ?
638
+ `${parts[0]}/${parts[1]}` : parts[0];
639
+ const pathInPackage = importPath.slice(pkgName.length);
626
640
 
627
- // Only error if there's a path in the package (not just pkg name)
628
- if (pathInPackage && pathInPackage.length > 1) {
629
- errors.push(
630
- `${relativePath}:${lineNum}\n` +
631
- ` from '${importPath}'\n` +
632
- ` => Missing file extension (add .js, .svelte, ` +
633
- `or .svelte.js)`
634
- );
641
+ // Only error if path exists in the package (not just pkg name)
642
+ if (pathInPackage && pathInPackage.length > 1) {
643
+ errors.push(
644
+ `${relativePath}:${lineNum}\n` +
645
+ ` from '${importPath}'\n` +
646
+ ` => Missing file extension ` +
647
+ `(add .js, .svelte, or .svelte.js)`
648
+ );
649
+ }
635
650
  }
636
651
  }
637
652
  }