@foundrykit/cli 2.0.7 → 2.0.8
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/CHANGELOG.md +6 -0
- package/dist/cli.js +10 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/add.ts +13 -1
- package/tests/dependency-resolution.test.ts +30 -0
package/package.json
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -641,6 +641,10 @@ function resolveImportBasePath(
|
|
|
641
641
|
config: Config,
|
|
642
642
|
options: { preferRootAlias?: boolean } = {}
|
|
643
643
|
): string {
|
|
644
|
+
if (isPackageImportSpecifier(filePath)) {
|
|
645
|
+
return filePath.replace(/\/$/, '');
|
|
646
|
+
}
|
|
647
|
+
|
|
644
648
|
const normalizedPath = normalizeConfigPath(filePath).replace(
|
|
645
649
|
/\.(ts|js)x?$/,
|
|
646
650
|
''
|
|
@@ -697,6 +701,10 @@ function normalizeConfigPath(filePath: string): string {
|
|
|
697
701
|
.replace(/\/$/, '');
|
|
698
702
|
}
|
|
699
703
|
|
|
704
|
+
function isPackageImportSpecifier(importPath: string): boolean {
|
|
705
|
+
return importPath.startsWith('@') && !importPath.startsWith('@/');
|
|
706
|
+
}
|
|
707
|
+
|
|
700
708
|
function joinImportPath(basePath: string, childPath: string): string {
|
|
701
709
|
const normalizedBase = basePath.replace(/\/$/, '');
|
|
702
710
|
const normalizedChild = childPath.replace(/^\//, '').replace(/\/$/, '');
|
|
@@ -723,7 +731,11 @@ function transformRegistryBarrelImports(
|
|
|
723
731
|
'g'
|
|
724
732
|
);
|
|
725
733
|
|
|
726
|
-
return content.replace(importPattern, (match, imports: string) => {
|
|
734
|
+
return content.replace(importPattern, (match, imports: string, source: string) => {
|
|
735
|
+
if (isPackageImportSpecifier(destinationBasePath)) {
|
|
736
|
+
return match.replace(source, destinationBasePath);
|
|
737
|
+
}
|
|
738
|
+
|
|
727
739
|
const groupedImports = groupImportsByComponent(imports, config, category);
|
|
728
740
|
|
|
729
741
|
return Array.from(groupedImports.entries())
|
|
@@ -434,5 +434,35 @@ import { cn } from "@foundrykit/utils";`;
|
|
|
434
434
|
'@/components/marketing/primitives/input-group'
|
|
435
435
|
);
|
|
436
436
|
});
|
|
437
|
+
|
|
438
|
+
it('should preserve package imports when hooks are configured as a package', () => {
|
|
439
|
+
const packageHooksConfig = {
|
|
440
|
+
...marketingConfig,
|
|
441
|
+
paths: {
|
|
442
|
+
...marketingConfig.paths,
|
|
443
|
+
hooks: '@foundrykit/hooks',
|
|
444
|
+
},
|
|
445
|
+
aliases: {
|
|
446
|
+
...marketingConfig.aliases,
|
|
447
|
+
'@/hooks': '@foundrykit/hooks',
|
|
448
|
+
},
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const source = `import {
|
|
452
|
+
useAdvancedSearch,
|
|
453
|
+
SearchContext,
|
|
454
|
+
type EmptyStateBehaviour,
|
|
455
|
+
} from '@foundrykit/hooks';`;
|
|
456
|
+
|
|
457
|
+
const transformed = transformImportsForConfig(
|
|
458
|
+
source,
|
|
459
|
+
packageHooksConfig
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
expect(transformed).toBe(source);
|
|
463
|
+
expect(transformed).not.toContain('@/hooks/use-advanced-search');
|
|
464
|
+
expect(transformed).not.toContain('@/hooks/search-context');
|
|
465
|
+
expect(transformed).not.toContain('@/hooks/empty-state-behaviour');
|
|
466
|
+
});
|
|
437
467
|
});
|
|
438
468
|
});
|