@hkdigital/lib-core 0.5.80 → 0.5.81
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 +62 -9
package/package.json
CHANGED
|
@@ -559,28 +559,81 @@ async function validateFile(filePath) {
|
|
|
559
559
|
const isInLib = filePath.includes('/src/lib/');
|
|
560
560
|
const isInRoutes = filePath.includes('/src/routes/');
|
|
561
561
|
|
|
562
|
-
// Check each line for import statements
|
|
562
|
+
// Check each line for import statements and JSDoc type imports
|
|
563
563
|
const lines = content.split('\n');
|
|
564
564
|
for (let index = 0; index < lines.length; index++) {
|
|
565
565
|
const line = lines[index];
|
|
566
566
|
const lineNum = index + 1;
|
|
567
567
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
568
|
+
let importPathRaw = null;
|
|
569
|
+
let isJSDocImport = false;
|
|
570
|
+
|
|
571
|
+
// Check for regular import statements
|
|
572
|
+
if (line.trim().startsWith('import ')) {
|
|
573
|
+
const importMatch = line.match(/from ['"]([^'"]+)['"]/);
|
|
574
|
+
if (importMatch) {
|
|
575
|
+
importPathRaw = importMatch[1];
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
// Check for JSDoc type imports: import('path')
|
|
579
|
+
else if (line.includes('import(')) {
|
|
580
|
+
// Match import('...') or import("...")
|
|
581
|
+
const jsdocMatch = line.match(/import\(['"]([^'"]+)['"]\)/);
|
|
582
|
+
if (jsdocMatch) {
|
|
583
|
+
importPathRaw = jsdocMatch[1];
|
|
584
|
+
isJSDocImport = true;
|
|
585
|
+
}
|
|
571
586
|
}
|
|
572
587
|
|
|
573
|
-
//
|
|
574
|
-
|
|
575
|
-
if (!importMatch) {
|
|
588
|
+
// Skip if no import found
|
|
589
|
+
if (!importPathRaw) {
|
|
576
590
|
continue;
|
|
577
591
|
}
|
|
578
592
|
|
|
579
|
-
const importPathRaw = importMatch[1];
|
|
580
|
-
|
|
581
593
|
// Strip query parameters (Vite asset imports like ?preset=render)
|
|
582
594
|
let importPath = importPathRaw.split('?')[0];
|
|
583
595
|
|
|
596
|
+
// For JSDoc imports: only check unsafe aliases, skip other validations
|
|
597
|
+
if (isJSDocImport) {
|
|
598
|
+
// Check if using an unsafe alias
|
|
599
|
+
const isAliasImport = Object.keys(PROJECT_ALIASES).some(
|
|
600
|
+
alias => importPath === alias || importPath.startsWith(alias + '/')
|
|
601
|
+
);
|
|
602
|
+
|
|
603
|
+
if (isAliasImport && isInLib) {
|
|
604
|
+
let matchedAlias = null;
|
|
605
|
+
for (const alias of Object.keys(PROJECT_ALIASES)) {
|
|
606
|
+
if (importPath === alias || importPath.startsWith(alias + '/')) {
|
|
607
|
+
matchedAlias = alias;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
if (matchedAlias && UNSAFE_ALIASES.has(matchedAlias)) {
|
|
613
|
+
const suggestion = UNSAFE_ALIASES.get(matchedAlias);
|
|
614
|
+
const pathAfterAlias = importPath.slice(matchedAlias.length);
|
|
615
|
+
|
|
616
|
+
let errorMsg;
|
|
617
|
+
if (suggestion.startsWith('(')) {
|
|
618
|
+
errorMsg = `${relativePath}:${lineNum}\n` +
|
|
619
|
+
` JSDoc import('${importPath}')\n` +
|
|
620
|
+
` => ${suggestion}`;
|
|
621
|
+
} else {
|
|
622
|
+
const suggestedImport = suggestion + pathAfterAlias;
|
|
623
|
+
errorMsg = `${relativePath}:${lineNum}\n` +
|
|
624
|
+
` JSDoc import('${importPath}')\n` +
|
|
625
|
+
` => import('${suggestedImport}') ` +
|
|
626
|
+
`(alias resolves outside project)`;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
errors.push(errorMsg);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// Skip all other validations for JSDoc imports
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
|
|
584
637
|
// Check if using $src/lib when $lib is available (built-in SvelteKit)
|
|
585
638
|
// Report the issue and normalize the path for further validation
|
|
586
639
|
let hasSrcLibIssue = false;
|