Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
fix: fix typescript import issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 21, 2022
1 parent 13b8ed0 commit c4574dc
Showing 1 changed file with 14 additions and 7 deletions.
@@ -1,12 +1,10 @@
package com.thoughtworks.archguard.scanner.sourcecode

import chapi.app.frontend.path.ecmaImportConvert
import chapi.app.frontend.path.importConvert
import chapi.domain.core.*
import infrastructure.SourceBatch
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.io.File
import java.text.SimpleDateFormat
import java.util.*

Expand Down Expand Up @@ -153,18 +151,27 @@ class ClassRepository(systemId: String, language: String, workspace: String) {
for (clz in imports) {
var importSource = clz.Source
if (isJs()) {
importSource = importConvert(filePath, importSource)
if(importSource.startsWith("src/")) {
importSource = importSource.replaceFirst("src/", "@/")
}
importSource = importSource.replace("/", ".")
importSource = convertTypeScriptImport(importSource, filePath)
}

val clzDependenceId = saveOrGetDependentClass(importSource, DEFAULT_MODULE_NAME)
doSaveClassDependence(clzId, clzDependenceId, "${packageName}.${clzName}", importSource)
}
}

private fun convertTypeScriptImport(importSource: String, filePath: String): String {
var imp = importSource
if (!imp.startsWith("@")) {
imp = importConvert(filePath, imp)
if (imp.startsWith("src/")) {
imp = imp.replaceFirst("src/", "@/")
}
}

imp = imp.replace("/", ".")
return imp
}

private fun isJs() = language == "typescript" || language == "javascript"

private fun saveOrGetDependentClass(name: String, moduleName: String = DEFAULT_MODULE_NAME): String? {
Expand Down

0 comments on commit c4574dc

Please sign in to comment.