@hkdigital/lib-core 0.5.75 → 0.5.76
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 +1 -1
- package/scripts/validate-imports.mjs +45 -38
package/package.json
CHANGED
|
@@ -534,6 +534,7 @@ async function validateFile(filePath) {
|
|
|
534
534
|
const importedNames = extractImportNames(line);
|
|
535
535
|
|
|
536
536
|
// Check each imported name for barrel exports
|
|
537
|
+
let foundBarrel = false;
|
|
537
538
|
for (const importedName of importedNames) {
|
|
538
539
|
const barrelPath = await findAliasBarrelExport(
|
|
539
540
|
importPath,
|
|
@@ -546,35 +547,38 @@ async function validateFile(filePath) {
|
|
|
546
547
|
` from '${importPath}'\n` +
|
|
547
548
|
` => from '${barrelPath}' (use barrel export)`
|
|
548
549
|
);
|
|
550
|
+
foundBarrel = true;
|
|
549
551
|
break; // Only report once per line
|
|
550
552
|
}
|
|
551
553
|
}
|
|
552
554
|
|
|
553
|
-
//
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
555
|
+
// Only check for missing extension if no barrel was found
|
|
556
|
+
if (!foundBarrel) {
|
|
557
|
+
const hasExtension = importPath.match(/\.[^/]+$/);
|
|
558
|
+
|
|
559
|
+
if (!hasExtension) {
|
|
560
|
+
// Extract path after alias
|
|
561
|
+
let pathAfterAlias = null;
|
|
562
|
+
for (const alias of Object.keys(PROJECT_ALIASES)) {
|
|
563
|
+
if (importPath === alias ||
|
|
564
|
+
importPath.startsWith(alias + '/')) {
|
|
565
|
+
pathAfterAlias = importPath.slice(alias.length);
|
|
566
|
+
if (pathAfterAlias.startsWith('/')) {
|
|
567
|
+
pathAfterAlias = pathAfterAlias.slice(1);
|
|
568
|
+
}
|
|
569
|
+
break;
|
|
565
570
|
}
|
|
566
|
-
break;
|
|
567
571
|
}
|
|
568
|
-
}
|
|
569
572
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
573
|
+
// Only error if there's a path after the alias
|
|
574
|
+
if (pathAfterAlias && pathAfterAlias.length > 0) {
|
|
575
|
+
errors.push(
|
|
576
|
+
`${relativePath}:${lineNum}\n` +
|
|
577
|
+
` from '${importPath}'\n` +
|
|
578
|
+
` => Missing file extension ` +
|
|
579
|
+
`(add .js, .svelte, or .svelte.js)`
|
|
580
|
+
);
|
|
581
|
+
}
|
|
578
582
|
}
|
|
579
583
|
}
|
|
580
584
|
|
|
@@ -598,6 +602,7 @@ async function validateFile(filePath) {
|
|
|
598
602
|
const importedNames = extractImportNames(line);
|
|
599
603
|
|
|
600
604
|
// Check each imported name for barrel exports
|
|
605
|
+
let foundBarrel = false;
|
|
601
606
|
for (const importedName of importedNames) {
|
|
602
607
|
const barrelPath = await findExternalBarrelExport(
|
|
603
608
|
importPath,
|
|
@@ -610,28 +615,30 @@ async function validateFile(filePath) {
|
|
|
610
615
|
` from '${importPath}'\n` +
|
|
611
616
|
` => from '${barrelPath}' (use barrel export)`
|
|
612
617
|
);
|
|
618
|
+
foundBarrel = true;
|
|
613
619
|
break; // Only report once per line
|
|
614
620
|
}
|
|
615
621
|
}
|
|
616
622
|
|
|
617
|
-
//
|
|
618
|
-
|
|
619
|
-
|
|
623
|
+
// Only check for missing extension if no barrel was found
|
|
624
|
+
if (!foundBarrel) {
|
|
625
|
+
const hasExtension = importPath.match(/\.[^/]+$/);
|
|
620
626
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
627
|
+
if (!hasExtension) {
|
|
628
|
+
// Extract package name and check if there's a path
|
|
629
|
+
const pkgName = importPath.startsWith('@') ?
|
|
630
|
+
`${parts[0]}/${parts[1]}` : parts[0];
|
|
631
|
+
const pathInPackage = importPath.slice(pkgName.length);
|
|
626
632
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
633
|
+
// Only error if path exists in the package (not just pkg name)
|
|
634
|
+
if (pathInPackage && pathInPackage.length > 1) {
|
|
635
|
+
errors.push(
|
|
636
|
+
`${relativePath}:${lineNum}\n` +
|
|
637
|
+
` from '${importPath}'\n` +
|
|
638
|
+
` => Missing file extension ` +
|
|
639
|
+
`(add .js, .svelte, or .svelte.js)`
|
|
640
|
+
);
|
|
641
|
+
}
|
|
635
642
|
}
|
|
636
643
|
}
|
|
637
644
|
}
|