Skip to content

Commit

Permalink
0.8.4
Browse files Browse the repository at this point in the history
- Catch tsconfig parsing errors and guide user (fixes #48)
- Disable unused manual serialization dependency
  • Loading branch information
WarningImHack3r committed Jun 20, 2024
1 parent 0570b19 commit f4676a2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

## [Unreleased]

### Changed

- Temporarily reduce back bundle size by removing unused dependencies

### Fixed

- Fix a crash due to an edge case with tsconfig.json files with JSON5 patterns (#48)

## [0.8.3] - 2024-06-17

### Added
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {

// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
implementation(libs.serialization)
// implementation(libs.serialization)
}

// Set the JVM language level used to build the project.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = com.github.warningimhack3r.intellijshadcnplugin
pluginName = intellij-shadcn-plugin
pluginRepositoryUrl = https://github.com/WarningImHack3r/intellij-shadcn-plugin
# SemVer format -> https://semver.org
pluginVersion = 0.8.3
pluginVersion = 0.8.4

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 213
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ abstract class Source<C : Config>(val project: Project, private val serializer:
private val tsConfigJson = Json {
// Lax parsing (unquoted keys, formatting, etc.)
isLenient = true
// Allow trailing commas
// Allow trailing commas (1.6.1+)
// allowTrailingComma = true
// Allow comments
// Allow comments (1.7.0+)
// allowComments = true
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ abstract class Source<C : Config>(val project: Project, private val serializer:

protected open fun adaptFileExtensionToConfig(extension: String): String = extension

protected fun parseTsConfig(config: String): JsonElement {
protected fun parseTsConfig(config: String, fileName: String = "tsconfig.json"): JsonElement {
// Temporary workaround until kotlinx.serialization is upgraded
val cleanConfig = config
// Remove /* */ comments
Expand All @@ -117,7 +117,20 @@ abstract class Source<C : Config>(val project: Project, private val serializer:
// Remove trailing commas
.replace(Regex(",\\s*}"), "\n}")
.replace(Regex(",\\s*]"), "\n]")
return tsConfigJson.parseToJsonElement(cleanConfig)
return try {
tsConfigJson.parseToJsonElement(cleanConfig)
} catch (e: Exception) {
log.warn("Failed to parse $fileName using replacements", e)
try {
tsConfigJson.parseToJsonElement(config)
} catch (e: Exception) {
log.error(
"Failed to parse $fileName. Please try removing comments and trailing commas from it and try again.",
e
)
throw e
}
}
}

protected abstract fun adaptFileToConfig(file: PsiFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ open class VueSource(project: Project) : Source<VueConfig>(project, VueConfig.se
return alias
}

fun resolvePath(configFile: String): String? {
return parseTsConfig(configFile)
fun resolvePath(configFile: String, fileName: String): String? {
return parseTsConfig(configFile, fileName)
.jsonObject["compilerOptions"]
?.jsonObject?.get("paths")
?.jsonObject?.get("${alias.substringBefore("/")}/*")
Expand All @@ -54,8 +54,8 @@ open class VueSource(project: Project) : Source<VueConfig>(project, VueConfig.se

val tsConfig = FileManager(project).getFileContentsAtPath(tsConfigLocation)
?: throw NoSuchFileException("$tsConfigLocation not found")
val aliasPath = (resolvePath(tsConfig) ?: if (config.typescript) {
resolvePath("tsconfig.app.json")
val aliasPath = (resolvePath(tsConfig, tsConfigLocation) ?: if (config.typescript) {
resolvePath("tsconfig.app.json", "tsconfig.app.json")
} else null) ?: throw Exception("Cannot find alias $alias in $tsConfig")
return aliasPath.replace(Regex("^\\.+/"), "")
.replace(Regex("\\*$"), alias.substringAfter("/")).also {
Expand Down

0 comments on commit f4676a2

Please sign in to comment.