[Gradle, JS] Remove possibility to declare npm dependency w/o version
#KT-38683 fixed
This commit is contained in:
+7
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -54,7 +54,9 @@ interface KotlinDependencyHandler {
|
||||
|
||||
fun project(notation: Map<String, Any?>): ProjectDependency
|
||||
|
||||
fun npm(name: String, version: String = "*"): Dependency
|
||||
fun npm(name: String): Dependency
|
||||
|
||||
fun npm(name: String, version: String): Dependency
|
||||
|
||||
fun npm(name: String, directory: File): Dependency
|
||||
|
||||
@@ -65,19 +67,19 @@ interface KotlinDependencyHandler {
|
||||
)
|
||||
fun npm(org: String? = null, packageName: String, version: String = "*"): Dependency
|
||||
|
||||
fun devNpm(name: String, version: String = "*"): Dependency
|
||||
fun devNpm(name: String, version: String): Dependency
|
||||
|
||||
fun devNpm(name: String, directory: File): Dependency
|
||||
|
||||
fun devNpm(directory: File): Dependency
|
||||
|
||||
fun optionalNpm(name: String, version: String = "*"): Dependency
|
||||
fun optionalNpm(name: String, version: String): Dependency
|
||||
|
||||
fun optionalNpm(name: String, directory: File): Dependency
|
||||
|
||||
fun optionalNpm(directory: File): Dependency
|
||||
|
||||
fun peerNpm(name: String, version: String = "*"): Dependency
|
||||
fun peerNpm(name: String, version: String): Dependency
|
||||
}
|
||||
|
||||
interface HasKotlinDependencies {
|
||||
|
||||
+9
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
|
||||
import org.gradle.api.Project
|
||||
@@ -59,6 +64,10 @@ class DefaultKotlinDependencyHandler(
|
||||
override fun project(notation: Map<String, Any?>): ProjectDependency =
|
||||
project.dependencies.project(notation) as ProjectDependency
|
||||
|
||||
override fun npm(name: String): Dependency {
|
||||
throw IllegalArgumentException("NPM dependency '$name' doesn't have version. Please, set version explicitly.")
|
||||
}
|
||||
|
||||
private fun addDependencyByAnyNotation(
|
||||
configurationName: String,
|
||||
dependencyNotation: Any
|
||||
|
||||
+12
-7
@@ -13,7 +13,9 @@ import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import java.io.File
|
||||
|
||||
interface NpmDependencyExtension {
|
||||
operator fun invoke(name: String, version: String = "*"): NpmDependency
|
||||
operator fun invoke(name: String): NpmDependency
|
||||
|
||||
operator fun invoke(name: String, version: String): NpmDependency
|
||||
|
||||
operator fun invoke(name: String, directory: File): NpmDependency
|
||||
|
||||
@@ -24,6 +26,9 @@ private class DefaultNpmDependencyExtension(
|
||||
private val project: Project,
|
||||
private val scope: NpmDependency.Scope
|
||||
) : NpmDependencyExtension, Closure<NpmDependency>(project.dependencies) {
|
||||
override fun invoke(name: String): NpmDependency =
|
||||
throw IllegalArgumentException("NPM dependency '$name' doesn't have version. Please, set version explicitly.")
|
||||
|
||||
override operator fun invoke(name: String, version: String): NpmDependency =
|
||||
NpmDependency(
|
||||
project = project,
|
||||
@@ -34,7 +39,7 @@ private class DefaultNpmDependencyExtension(
|
||||
|
||||
override operator fun invoke(name: String, directory: File): NpmDependency {
|
||||
check(directory.isDirectory) {
|
||||
"Dependency on local path should point on directory but $directory found"
|
||||
"Dependency '$name' on local path should point on directory but '$directory' found"
|
||||
}
|
||||
return invoke(
|
||||
name = name,
|
||||
@@ -49,7 +54,7 @@ private class DefaultNpmDependencyExtension(
|
||||
)
|
||||
|
||||
override fun call(vararg args: Any?): NpmDependency {
|
||||
if (args.size > 2) throw npmDeclarationException(args)
|
||||
if (args.size > 2) npmDeclarationException(args)
|
||||
|
||||
val arg = args[0]
|
||||
return when (arg) {
|
||||
@@ -58,7 +63,7 @@ private class DefaultNpmDependencyExtension(
|
||||
args = *args
|
||||
)
|
||||
is File -> invoke(arg)
|
||||
else -> throw npmDeclarationException(args)
|
||||
else -> npmDeclarationException(args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,12 +81,12 @@ private class DefaultNpmDependencyExtension(
|
||||
name = name,
|
||||
directory = arg
|
||||
)
|
||||
else -> throw npmDeclarationException(args)
|
||||
else -> npmDeclarationException(args)
|
||||
}
|
||||
}
|
||||
|
||||
private fun npmDeclarationException(args: Array<out Any?>): IllegalArgumentException {
|
||||
return IllegalArgumentException(
|
||||
private fun npmDeclarationException(args: Array<out Any?>): Nothing {
|
||||
throw IllegalArgumentException(
|
||||
"""
|
||||
Unable to add NPM dependency by $args
|
||||
- npm('name') -> name:*
|
||||
|
||||
Reference in New Issue
Block a user