@hkdigital/lib-core 0.5.74 → 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 +56 -0
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,10 +547,41 @@ 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
|
|
|
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;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
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
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
553
585
|
// Skip further validation for alias imports
|
|
554
586
|
continue;
|
|
555
587
|
}
|
|
@@ -570,6 +602,7 @@ async function validateFile(filePath) {
|
|
|
570
602
|
const importedNames = extractImportNames(line);
|
|
571
603
|
|
|
572
604
|
// Check each imported name for barrel exports
|
|
605
|
+
let foundBarrel = false;
|
|
573
606
|
for (const importedName of importedNames) {
|
|
574
607
|
const barrelPath = await findExternalBarrelExport(
|
|
575
608
|
importPath,
|
|
@@ -582,9 +615,32 @@ async function validateFile(filePath) {
|
|
|
582
615
|
` from '${importPath}'\n` +
|
|
583
616
|
` => from '${barrelPath}' (use barrel export)`
|
|
584
617
|
);
|
|
618
|
+
foundBarrel = true;
|
|
585
619
|
break; // Only report once per line
|
|
586
620
|
}
|
|
587
621
|
}
|
|
622
|
+
|
|
623
|
+
// Only check for missing extension if no barrel was found
|
|
624
|
+
if (!foundBarrel) {
|
|
625
|
+
const hasExtension = importPath.match(/\.[^/]+$/);
|
|
626
|
+
|
|
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);
|
|
632
|
+
|
|
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
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
588
644
|
}
|
|
589
645
|
|
|
590
646
|
// Skip further validation for external packages
|