@foundrykit/cli 2.0.7 → 2.0.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foundrykit/cli",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
@@ -25,7 +25,7 @@
25
25
  "glob": "^10.3.10",
26
26
  "inquirer": "^9.2.15",
27
27
  "node-fetch": "^3.3.0",
28
- "@foundrykit/types": "2.0.3"
28
+ "@foundrykit/types": "2.0.4"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^20.19.9",
@@ -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,15 +731,22 @@ function transformRegistryBarrelImports(
723
731
  'g'
724
732
  );
725
733
 
726
- return content.replace(importPattern, (match, imports: string) => {
727
- const groupedImports = groupImportsByComponent(imports, config, category);
734
+ return content.replace(
735
+ importPattern,
736
+ (match, imports: string, source: string) => {
737
+ if (isPackageImportSpecifier(destinationBasePath)) {
738
+ return match.replace(source, destinationBasePath);
739
+ }
740
+
741
+ const groupedImports = groupImportsByComponent(imports, config, category);
728
742
 
729
- return Array.from(groupedImports.entries())
730
- .map(([componentPath, specifiers]) => {
731
- return `import { ${specifiers.join(', ')} } from "${destinationBasePath}/${componentPath}";`;
732
- })
733
- .join('\n');
734
- });
743
+ return Array.from(groupedImports.entries())
744
+ .map(([componentPath, specifiers]) => {
745
+ return `import { ${specifiers.join(', ')} } from "${destinationBasePath}/${componentPath}";`;
746
+ })
747
+ .join('\n');
748
+ }
749
+ );
735
750
  }
736
751
 
737
752
  function groupImportsByComponent(
@@ -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 EmptyStateBehavior,
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-behavior');
466
+ });
437
467
  });
438
468
  });