diff --git a/.editorconfig b/.editorconfig index cdc2ca9c..dec1dc47 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,4 +3,4 @@ root = true [*] indent_size = 2 continuation_indent_size = 4 -ij_kotlin_name_count_to_use_star_import = unset +ij_kotlin_name_count_to_use_star_import = 9000 diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d0c8d5e..f213df14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ -# v2.0.4 +# v2.1.0 ## Versions * Kotlin: 1.5.21 +* Gradle: 7.2.0 +* JDK: 11 + +## Changes +* Fixed [#24](https://github.com/mpetuska/npm-publish/issues/24): `types` configuration property was ignored +* Added support for setting configuration properties via environment variables too +* Kotlin version bumped to `1.5.21` + +# v2.0.4 +## Versions +* Kotlin: 1.5.10 * Gradle: 7.1.1 * JDK: 11 diff --git a/README.md b/README.md index 6c2e3762..f9a3759a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Gradle plugin enabling NPM publishing (essentially `maven-publish` for NPM packages). Integrates seamlessly with Kotlin/JS/MPP plugin if applied, providing auto configurations. -> The plugin was last tested with `JDK 11`, `Kotlin 1.5.21` & `Gradle 7.1.1` +> The plugin was last tested with `JDK 11`, `Kotlin 1.5.21` & `Gradle 7.2.0` ## Setup @@ -43,7 +43,7 @@ kotlin { npmPublishing { repositories { - repository("npmjs") { + repository("npmjs") { registry = uri("https://registry.npmjs.org") authToken = "asdhkjsdfjvhnsdrishdl" } @@ -164,39 +164,44 @@ npmPublishing { #### Properties Most of the DSL configuration options can also be set/overridden via gradle -properties (`./gradlew task -Pprop.name=propValue`), `gradle.properties` or `local.properties`. Bellow is the full list -of supported properties: - -Extension: - -* `npm.publish.readme` -* `npm.publish.organization` -* `npm.publish.access` -* `npm.publish.bundleKotlinDependencies` -* `npm.publish.shrinkwrapBundledDependencies` -* `npm.publish.dry` -* `npm.publish.version` - -Publication: - -* `npm.publish.publication..bundleKotlinDependencies` -* `npm.publish.publication..shrinkwrapBundledDependencies` -* `npm.publish.publication..scope` -* `npm.publish.publication..moduleName` -* `npm.publish.publication..version` -* `npm.publish.publication..main` -* `npm.publish.publication..types` -* `npm.publish.publication..readme` -* `npm.publish.publication..nodeJsDir` -* `npm.publish.publication..destinationDir` - -Repository: - -* `npm.publish.repository..dry` -* `npm.publish.repository..access` -* `npm.publish.repository..registry` -* `npm.publish.repository..otp` -* `npm.publish.repository..authToken` +properties (`./gradlew task -Pprop.name=propValue`), `gradle.properties` or `local.properties`. These properties can +also be set via environment variables by replacing `.`, ` ` & `-` with `_` and capitalising all names. Properties are +resolved in the following priority: + +1. DSL +2. Gradle Properties +3. Environment Variables + +##### Extension + +* `npm.publish.readme (NPM_PUBLISH_README)` +* `npm.publish.organization (NPM_PUBLISH_ORGANIZATION)` +* `npm.publish.access (NPM_PUBLISH_ACCESS)` +* `npm.publish.bundleKotlinDependencies (NPM_PUBLISH_BUNDLEKOTLINDEPENDENCIES)` +* `npm.publish.shrinkwrapBundledDependencies (NPM_PUBLISH_SHRINKWRAPBUNDLEDDEPENDENCIES)` +* `npm.publish.dry (NPM_PUBLISH_DRY)` +* `npm.publish.version (NPM_PUBLISH_VERSION)` + +##### Publication + +* `npm.publish.publication..bundleKotlinDependencies (NPM_PUBLISH_PUBLICATION__BUNDLEKOTLINDEPENDENCIES)` +* `npm.publish.publication..shrinkwrapBundledDependencies (NPM_PUBLISH_PUBLICATION__SHRINKWRAPBUNDLEDDEPENDENCIES)` +* `npm.publish.publication..scope (NPM_PUBLISH_PUBLICATION__SCOPE)` +* `npm.publish.publication..moduleName (NPM_PUBLISH_PUBLICATION__MODULENAME)` +* `npm.publish.publication..version (NPM_PUBLISH_PUBLICATION__VERSION)` +* `npm.publish.publication..main (NPM_PUBLISH_PUBLICATION__MAIN)` +* `npm.publish.publication..types (NPM_PUBLISH_PUBLICATION__TYPES)` +* `npm.publish.publication..readme (NPM_PUBLISH_PUBLICATION__README)` +* `npm.publish.publication..nodeJsDir (NPM_PUBLISH_PUBLICATION__NODEJSDIR)` +* `npm.publish.publication..destinationDir (NPM_PUBLISH_PUBLICATION__DESTINATIONDIR)` + +##### Repository + +* `npm.publish.repository..dry (NPM_PUBLISH_REPOSITORY__DRY)` +* `npm.publish.repository..access (NPM_PUBLISH_REPOSITORY__ACCESS)` +* `npm.publish.repository..registry (NPM_PUBLISH_REPOSITORY__REGISTRY)` +* `npm.publish.repository..otp (NPM_PUBLISH_REPOSITORY__OTP)` +* `npm.publish.repository..authToken (NPM_PUBLISH_REPOSITORY__AUTHTOKEN)` ## Tasks @@ -207,9 +212,7 @@ The plugin generates the following gradle tasks for various configuration elemen * NpmPackTask: generated for each publication and named as `packNpmPublication` * NpmPublishTask: generated for each publication + repository combination and named as `publishNpmPublicationTo` - -All created tasks are added as dependencies to grouping tasks to allow for group-invocation: - + All created tasks are added as dependencies to grouping tasks to allow for group-invocation: * NpmPackageAssembleTask: `assemble` task in `build` group * NpmPackTask: `pack` task in `build` group * NpmPublishTask: `publish` task in `publishing` group @@ -222,14 +225,12 @@ priority order by their name (descending priority): 1. Optional 2. Peer 3. Dev -4. Normal - -This ensures that any given dependency does not appear in multiple dependency scopes. +4. Normal This ensures that any given dependency does not appear in multiple dependency scopes. ## Known Issues -* [#6435](https://github.com/npm/npm/issues/6435): (Only applies to legacy backend) npm and yarn tries to download bundled dependencies. Can be overcome - for npm (sadly not yarn) with `shrinkwrapBundledDependencies` option. Note that it works fine for both package - managers when installing from a tarball. Bug [#2143](https://github.com/npm/cli/issues/2143) on the new npm repo, so - please vote for that to get it fixed. Bug [#8436](https://github.com/yarnpkg/yarn/issues/8436) on the yarn repo, so - please vote for that to get it fixed. +* [#6435](https://github.com/npm/npm/issues/6435): (Only applies to legacy backend) npm and yarn tries to download + bundled dependencies. Can be overcome for npm (sadly not yarn) with `shrinkwrapBundledDependencies` option. Note that + it works fine for both package managers when installing from a tarball. + Bug [#2143](https://github.com/npm/cli/issues/2143) on the new npm repo, so please vote for that to get it fixed. + Bug [#8436](https://github.com/yarnpkg/yarn/issues/8436) on the yarn repo, so please vote for that to get it fixed. diff --git a/build.gradle.kts b/build.gradle.kts index 96a6c289..ab4d9c37 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,8 @@ +import de.fayard.refreshVersions.core.versionFor import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.4.30" + kotlin("jvm") version "1.4.31" `java-gradle-plugin` `maven-publish` id("com.gradle.plugin-publish") @@ -26,6 +27,11 @@ idea { } } +ktlint { + version by versionFor("version.ktlint") + additionalEditorconfigFile.set(rootDir.resolve(".editorconfig")) +} + gradleEnterprise { buildScan { termsOfServiceUrl = "https://gradle.com/terms-of-service" @@ -157,7 +163,7 @@ afterEvaluate { "Built-By" to System.getProperty("user.name"), "Build-Jdk" to System.getProperty("java.version"), "Implementation-Version" to project.version, - "Created-By" to "Gradle v${org.gradle.util.GradleVersion.current()}", + "Created-By" to "Gradle v${GradleVersion.current()}", "Created-From" to Git.headCommitHash ) } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c0..7454180f 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 05679dc3..ffed3a25 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0c..744e882e 100755 --- a/gradlew +++ b/gradlew @@ -72,7 +72,7 @@ case "`uname`" in Darwin* ) darwin=true ;; - MINGW* ) + MSYS* | MINGW* ) msys=true ;; NONSTOP* ) diff --git a/sandbox/gradlew b/sandbox/gradlew new file mode 120000 index 00000000..502f5a2d --- /dev/null +++ b/sandbox/gradlew @@ -0,0 +1 @@ +../gradlew \ No newline at end of file diff --git a/sandbox/gradlew.bat b/sandbox/gradlew.bat new file mode 120000 index 00000000..28401328 --- /dev/null +++ b/sandbox/gradlew.bat @@ -0,0 +1 @@ +../gradlew.bat \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 47aeac49..adab3420 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("de.fayard.refreshVersions") version "0.10.1" - id("com.gradle.enterprise") version "3.6.3" + id("de.fayard.refreshVersions") version "0.11.0" + id("com.gradle.enterprise") version "3.6.4" } rootProject.name = "npm-publish" diff --git a/src/main/kotlin/NpmPublishPlugin.kt b/src/main/kotlin/NpmPublishPlugin.kt index aeef9b3e..8188de91 100644 --- a/src/main/kotlin/NpmPublishPlugin.kt +++ b/src/main/kotlin/NpmPublishPlugin.kt @@ -8,7 +8,7 @@ import dev.petuska.npm.publish.task.NpmPublishTask import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.tasks.Copy -import org.gradle.util.GUtil +import org.gradle.util.internal.GUtil import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode @@ -64,7 +64,7 @@ class NpmPublishPlugin : Plugin { publications(0) { publication(target.name) { this.binary = binary - this.main = compileKotlinTask?.outputFile?.name + this.main = compileKotlinTask?.outputFileProperty?.orNull?.name dependencies { addAll(deps) } @@ -130,7 +130,7 @@ class NpmPublishPlugin : Plugin { val packTaskName = "pack${upperName}NpmPublication" val assemblePackageTask = tasks.findByName(assembleTaskName) as NpmPackageAssembleTask? ?: tasks.create(assembleTaskName, NpmPackageAssembleTask::class.java, pub).also { task -> - task.onlyIf { pub.compileKotlinTask?.outputFile?.exists() ?: true } + task.onlyIf { pub.compileKotlinTask?.outputFileProperty?.orNull?.exists() ?: true } task.dependsOn( *listOfNotNull( processResourcesTask, diff --git a/src/main/kotlin/delegate/PropertyDelegate.kt b/src/main/kotlin/delegate/PropertyDelegate.kt index 5a6fb180..1ccfd1a2 100644 --- a/src/main/kotlin/delegate/PropertyDelegate.kt +++ b/src/main/kotlin/delegate/PropertyDelegate.kt @@ -14,16 +14,31 @@ internal class PropertyDelegate( private var value: V? = null override fun getValue(thisRef: Any, property: KProperty<*>): V { - value = value ?: project.propertyOrNull("$PROP_BASE${prefix?.removeSuffix(".")?.removePrefix(".")?.let { ".$it" } ?: ""}.${property.name}") - ?.toString()?.let(converter) + value = value ?: property.findValue()?.let(converter) return value ?: default } override fun setValue(thisRef: Any, property: KProperty<*>, value: V) { - this.value = project.propertyOrNull("$PROP_BASE${prefix?.removeSuffix(".")?.removePrefix(".")?.let { ".$it" } ?: ""}.${property.name}") - ?.toString()?.let(converter) ?: value + this.value = property.findValue()?.let(converter) ?: value } + private fun KProperty<*>.findValue(): String? = findProperty() ?: findEnv() + + private fun KProperty<*>.findProperty(): String? { + return project.propertyOrNull(buildPropertyKey())?.toString() + } + + private fun KProperty<*>.findEnv(): String? { + return System.getenv(buildPropertyKey().toUpperCase().replace("[.\\- ]".toRegex(), "_"))?.toString() + } + + private fun KProperty<*>.buildPropertyKey() = + "$PROP_BASE${ + prefix?.removeSuffix(".") + ?.removePrefix(".") + ?.let { ".$it" } ?: "" + }.$name" + companion object { private const val PROP_BASE = "npm.publish" } diff --git a/src/main/kotlin/dsl/NpmPublication.kt b/src/main/kotlin/dsl/NpmPublication.kt index 5dcbc527..7f8b1b06 100644 --- a/src/main/kotlin/dsl/NpmPublication.kt +++ b/src/main/kotlin/dsl/NpmPublication.kt @@ -99,7 +99,7 @@ class NpmPublication internal constructor( internal val kotlinDestinationDir: File? get() = kotlinMainTask?.let { when (it) { - is Kotlin2JsCompile -> it.outputFile.parentFile + is Kotlin2JsCompile -> it.outputFileProperty.orNull?.parentFile is Copy -> it.destinationDir else -> null } diff --git a/src/main/kotlin/task/NpmPackageAssembleTask.kt b/src/main/kotlin/task/NpmPackageAssembleTask.kt index 90291d15..ed97960c 100644 --- a/src/main/kotlin/task/NpmPackageAssembleTask.kt +++ b/src/main/kotlin/task/NpmPackageAssembleTask.kt @@ -136,7 +136,7 @@ open class NpmPackageAssembleTask @Inject constructor( packageJson!!.invoke(this@PackageJson) } else { main = this@with.main - types = resolveTypes() + types = this@with.types ?: resolveTypes() if (binary is JsIrBinary) { kotlinDependencies?.flatMap { @@ -214,7 +214,7 @@ open class NpmPackageAssembleTask @Inject constructor( } } - private fun NpmPublication.resolveTypes() = compileKotlinTask?.outputFile?.let { + private fun NpmPublication.resolveTypes() = compileKotlinTask?.outputFileProperty?.orNull?.let { kotlinDestinationDir?.resolve("${it.nameWithoutExtension}.d.ts")?.let { dtsFile -> if (dtsFile.exists()) { "${dtsFile.relativeTo(dtsFile.parentFile)}" diff --git a/versions.properties b/versions.properties index 959cd152..6f78dd13 100644 --- a/versions.properties +++ b/versions.properties @@ -11,17 +11,18 @@ plugin.com.github.jakemarsden.git-hooks=0.0.2 plugin.com.gradle.plugin-publish=0.15.0 -plugin.org.jetbrains.dokka=1.4.32 +plugin.org.jetbrains.dokka=1.5.0 -plugin.org.jlleitschuh.gradle.ktlint=10.0.0 +plugin.org.jlleitschuh.gradle.ktlint=10.1.0 plugin.io.github.gradle-nexus.publish-plugin=1.1.0 -version.com.google.code.gson..gson=2.8.7 +version.com.google.code.gson..gson=2.8.8 -version.kotest=4.6.0 +version.ktlint=0.42.1 -version.kotlin=1.5.10 -## # available=1.5.20-M1 +version.kotest=4.6.1 + +version.kotlin=1.5.21 version.ktor=1.6.1