@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 +1 -1
- package/scripts/validate-imports.mjs +53 -38
package/package.json
CHANGED
|
@@ -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
|
-
//
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
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
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
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
|
-
//
|
|
618
|
-
|
|
619
|
-
|
|
631
|
+
// Only check for missing extension if no barrel was found
|
|
632
|
+
if (!foundBarrel) {
|
|
633
|
+
const hasExtension = importPath.match(/\.[^/]+$/);
|
|
620
634
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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
|
}
|