@hkdigital/lib-core 0.5.73 → 0.5.75
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 +57 -6
package/package.json
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
4
4
|
import { join, relative, resolve, dirname, isAbsolute } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
5
6
|
|
|
6
7
|
const PROJECT_ROOT = process.cwd();
|
|
7
8
|
const SRC_DIR = join(PROJECT_ROOT, 'src');
|
|
9
|
+
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const LIB_ROOT = dirname(SCRIPT_DIR);
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Scopes to validate for barrel exports
|
|
@@ -547,6 +550,34 @@ async function validateFile(filePath) {
|
|
|
547
550
|
}
|
|
548
551
|
}
|
|
549
552
|
|
|
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);
|
|
565
|
+
}
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
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
|
+
);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
550
581
|
// Skip further validation for alias imports
|
|
551
582
|
continue;
|
|
552
583
|
}
|
|
@@ -582,6 +613,27 @@ async function validateFile(filePath) {
|
|
|
582
613
|
break; // Only report once per line
|
|
583
614
|
}
|
|
584
615
|
}
|
|
616
|
+
|
|
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(/\.[^/]+$/);
|
|
620
|
+
|
|
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);
|
|
626
|
+
|
|
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
|
+
);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
585
637
|
}
|
|
586
638
|
|
|
587
639
|
// Skip further validation for external packages
|
|
@@ -895,14 +947,13 @@ async function validateFile(filePath) {
|
|
|
895
947
|
* Main validation function
|
|
896
948
|
*/
|
|
897
949
|
async function main() {
|
|
898
|
-
// Load package version
|
|
899
|
-
const pkgJsonPath = join(
|
|
950
|
+
// Load package version from lib-core's package.json
|
|
951
|
+
const pkgJsonPath = join(LIB_ROOT, 'package.json');
|
|
900
952
|
const pkgJsonContent = await readFile(pkgJsonPath, 'utf-8');
|
|
901
953
|
const pkgJson = JSON.parse(pkgJsonContent);
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
);
|
|
954
|
+
|
|
955
|
+
console.log(`Using script from @hkdigital/lib-core v${pkgJson.version}`);
|
|
956
|
+
console.log(`Validating import paths...`);
|
|
906
957
|
|
|
907
958
|
// Load project aliases from svelte.config.js
|
|
908
959
|
PROJECT_ALIASES = await loadAliases();
|