[Gradle, JS] KT-37207 Add constructor fot NpmDependency with only file
This commit is contained in:
+20
@@ -16,6 +16,7 @@ import org.gradle.api.internal.artifacts.dependencies.SelfResolvingDependencyInt
|
|||||||
import org.gradle.api.tasks.TaskDependency
|
import org.gradle.api.tasks.TaskDependency
|
||||||
import org.gradle.internal.component.local.model.DefaultLibraryBinaryIdentifier
|
import org.gradle.internal.component.local.model.DefaultLibraryBinaryIdentifier
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject.Companion.PACKAGE_JSON
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -39,6 +40,15 @@ data class NpmDependency(
|
|||||||
"$FILE_VERSION_PREFIX${directory.canonicalPath}"
|
"$FILE_VERSION_PREFIX${directory.canonicalPath}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
project: Project,
|
||||||
|
directory: File
|
||||||
|
) : this(
|
||||||
|
project,
|
||||||
|
moduleName(directory),
|
||||||
|
directory
|
||||||
|
)
|
||||||
|
|
||||||
enum class Scope {
|
enum class Scope {
|
||||||
NORMAL,
|
NORMAL,
|
||||||
DEV,
|
DEV,
|
||||||
@@ -136,4 +146,14 @@ data class NpmDependency(
|
|||||||
override fun getReason(): String? = reason
|
override fun getReason(): String? = reason
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun moduleName(directory: File): String {
|
||||||
|
val packageJson = directory.resolve(PACKAGE_JSON)
|
||||||
|
|
||||||
|
check(!packageJson.isFile) {
|
||||||
|
"There is no NPM module in $directory. Declare valid $PACKAGE_JSON in it."
|
||||||
|
}
|
||||||
|
|
||||||
|
return fromSrcPackageJson(packageJson)!!.name
|
||||||
|
}
|
||||||
|
|
||||||
const val FILE_VERSION_PREFIX = "file:"
|
const val FILE_VERSION_PREFIX = "file:"
|
||||||
Reference in New Issue
Block a user