Skip to content

Commit f7a5333

Browse files
committed
Fix module paths generation
1 parent bef533f commit f7a5333

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/Writers/ModuleWriter.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,19 @@ public function format(TypesCollection $collection): string {
7575
)
7676
);
7777
$commonPrefix = NamespacedType::commonPrefix($tsNamespace, $currentModuleTsNamespace);
78-
$thatRest = ltrim(substr($tsNamespace, strlen($commonPrefix)), '\\');
78+
$importedRest = ltrim(substr($tsNamespace, strlen($commonPrefix)), '\\');
7979
$currentRest = ltrim(substr($currentModuleTsNamespace, strlen($commonPrefix)), '\\');
80+
$backParts = array_fill(0, substr_count($currentRest, '\\'), '..');
8081
$sourceModulePath =
81-
join(
82-
'/',
83-
array_fill(0, substr_count($currentRest, '\\') + 1, '..')
82+
(
83+
count($backParts) === 0
84+
? '.'
85+
: join('/', $backParts)
8486
)
8587
. '/'
8688
. join(
8789
'/',
88-
explode('\\', $thatRest)
90+
explode('\\', $importedRest)
8991
);
9092

9193
$import .= '} from "' . $sourceModulePath . "\";\n";

tests/__snapshots__/IntegrationTest__it_can_transform_to_es_modules__1.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {RegularEnum} from "../Enum";
2-
import {YetAnotherDto} from "../LevelUp";
1+
import {RegularEnum} from "./Enum";
2+
import {YetAnotherDto} from "./LevelUp";
33
export type Dto = {
44
string: string;
55
nullbable: string | null;

0 commit comments

Comments
 (0)