@@ -59,16 +59,34 @@ export class FileProcessor implements IFileProcessor {
5959 . filter ( ( node : any ) => node . source . value . startsWith ( "." ) ) // Filter out all library/non-relative imports
6060 for ( const i of imports ) {
6161 const importName = ( i as any ) . specifiers [ 0 ] . local . name
62+ const relativePath = ( i as any ) . source . value
6263
63- const projectPath = sourceFile . getProjectPath ( )
64- const targetFileAbsolutePath = path
65- . resolve ( path . join ( sourceFile . getFullPath ( ) , ( i as any ) . source . value ) )
66- . replace ( / \\ / g, "/" )
67- const targetFileRelativePath = targetFileAbsolutePath . slice (
68- projectPath . length
69- )
64+ const currentFileDirectory = sourceFile
65+ . getFullPath ( )
66+ . slice ( 0 , sourceFile . getFullPath ( ) . lastIndexOf ( "/" ) )
67+ console . log ( currentFileDirectory )
7068
71- parsedImports . set ( importName , targetFileRelativePath )
69+ let finalPath = ""
70+ const backSteps = relativePath . match ( / \. \. \/ / g)
71+ if ( backSteps ) {
72+ const backStepsCount = backSteps . length
73+ const currentFileDirectoryParts = currentFileDirectory . split ( "/" )
74+ const finalPathParts = currentFileDirectoryParts . slice (
75+ 0 ,
76+ currentFileDirectoryParts . length - backStepsCount
77+ )
78+ finalPath = path
79+ . join ( ...finalPathParts , relativePath )
80+ . replaceAll ( "\\" , "/" )
81+ } else {
82+ finalPath = path
83+ . join ( currentFileDirectory , relativePath )
84+ . replaceAll ( "\\" , "/" )
85+ }
86+
87+ console . log ( relativePath , finalPath )
88+
89+ parsedImports . set ( importName , finalPath )
7290 }
7391 }
7492
@@ -79,7 +97,7 @@ export class FileProcessor implements IFileProcessor {
7997 . filter ( ( x ) => x . name )
8098 . map ( ( x ) => {
8199 if ( parsedImports . has ( x . name ) ) {
82- x . name = `${ parsedImports . get ( x . name ) ! } :${ x . name } `
100+ x . name = `${ parsedImports . get ( x . name ) ! } .ts :${ x . name } `
83101 }
84102 return x
85103 } )
0 commit comments