Skip to content

Commit

Permalink
Implement hack for KGP ESM main file name bug
Browse files Browse the repository at this point in the history
Closes #152
  • Loading branch information
mpetuska committed Dec 27, 2023
1 parent 51024ff commit b505ea8
Show file tree
Hide file tree
Showing 28 changed files with 618 additions and 1,146 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
name: Check
defaults:
run:
defaults:
run:
shell: bash

on:
on:
workflow_dispatch:
workflow_call:

jobs:
check:
jobs:
check:
name: Check on ubuntu-latest
runs-on: ubuntu-latest
env:
env:
GRADLE_OPTS: "-Dorg.gradle.daemon=true"
steps:
steps:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
with:
distribution: 'adopt'
java-version: 11

- name: Restore Gradle cache
id: cache
uses: actions/cache@v3
with:
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
Expand All @@ -51,7 +51,7 @@ jobs:
- uses: github/codeql-action/upload-sarif@v2
if: ${{ always() }}
with:
with:
sarif_file: ${{ github.workspace }}/detekt.sarif.json
checkout_path: ${{ github.workspace }}

Expand All @@ -60,30 +60,30 @@ jobs:

- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
with:
name: reports-${{ runner.os }}
path: |
**/build/reports
- name: Gradle Check Sandbox
working-directory: sandbox
run: ./gradlew check assemble pack publish --scan
run: ../gradlew check assemble pack publish --scan

- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
with:
name: sandbox-${{ runner.os }}
path: |
sandbox/**/build/reports
sandbox/**/build/publications
- name: Gradle Check Samples
working-directory: samples
run: ./gradlew check assemble pack publish --scan
run: ../gradlew check assemble pack publish --scan

- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
with:
name: samples-${{ runner.os }}
path: |
samples/**/build/reports
Expand All @@ -103,7 +103,7 @@ jobs:

- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
with:
name: ts-consumer-${{ runner.os }}
path: |
sandbox/ts-consumer/build
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/sandbox-publish.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
name: Publish Sandbox to GitHub Packages
on:
workflow_dispatch:
inputs:
version:
on:
workflow_dispatch:
inputs:
version:
required: true
description: Package version to publish under
sandbox-module:
sandbox-module:
required: false
default: both
description: Sandbox module to publish
jobs:
publish:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
permissions:
contents: read
packages: write
steps:
steps:
- uses: actions/checkout@v3

- name: Restore Gradle cache
id: cache
uses: actions/cache@v3
with:
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
Expand All @@ -33,15 +33,15 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v3
with:
with:
java-version: 11
distribution: 'adopt'

- name: Publish
working-directory: sandbox
run: |
VERSION=${VERSION:=${{ github.event.inputs.version }}}
./gradlew :${{ github.event.inputs.sandbox-module }}:publishJsNpmPublicationToGitHub \
-Pnpm.publish.repository.GitHub.authToken="${{ github.token }}" \
-Pnpm.publish.version=${VERSION/v} \
-Pnpm.publish.organization=${{ github.repository_owner }}
../gradlew :${{ github.event.inputs.sandbox-module }}:publishJsNpmPublicationToGitHub \
-Pnpm.publish.repository.GitHub.authToken="${{ github.token }}" \
-Pnpm.publish.version=${VERSION/v} \
-Pnpm.publish.organization=${{ github.repository_owner }}
46 changes: 45 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Verified Versions

- Kotlin: 1.9.22
- Gradle: 8.5
- JDK: 11

### Added

### Changed

### Removed

---

## [3.4.2]

This is a maintenance release with a few minor bugfixes.

### Verified Versions

- Kotlin: 1.9.22
- Gradle: 8.5
- JDK: 11

### Added

### Changed

- Upgraded dependencies
- Switched out `com.netflix.nebula.node` plugin hook for node autoconfig to `com.github.node-gradle.node` plugin which
it depends on
- Implemented a patch for older KGP users to remedy https://youtrack.jetbrains.com/issue/KT-59523 when using ESM

### Removed

---

## [3.4.1]

### Verified Versions

- Kotlin: 1.9.0
- Gradle: 8.2.1
- JDK: 11

### Added

- Utility DSL to set NpmRegistry::uri via Provider<String>

### Changed

- Added trailing slashes to npmjs and github registry convenience DSL URIs
- Fixed configuration cache issues with Boolean property chains

### Removed

---
Expand Down Expand Up @@ -406,7 +448,9 @@ This is a maintenance release with a few minor bugfixes.

---

[Unreleased]: https://github.com/mpetuska/npm-publish/compare/3.4.1...HEAD
[Unreleased]: https://github.com/mpetuska/npm-publish/compare/3.4.2...HEAD

[3.4.2]: https://github.com/mpetuska/npm-publish/compare/3.4.1...3.4.2

[3.4.1]: https://github.com/mpetuska/npm-publish/compare/3.4.0...3.4.1

Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ tasks:

```kotlin title="build.gradle.kts"
plugins {
id("dev.petuska.npm.publish") version "<VERSION>"
kotlin("multiplatform") version "<VERSION>>" // Optional, also supports "js"
id("dev.petuska.npm.publish") version "<VERSION>"
kotlin("multiplatform") version "<VERSION>>" // Optional, also supports "js"
}

kotlin {
js(IR) {
binaries.library()
browser() // or nodejs()
}
js(IR) {
binaries.library()
browser() // or nodejs()
}
}

npmPublish {
registries {
register("npmjs") {
uri.set("https://registry.npmjs.org")
authToken.set("obfuscated")
registries {
register("npmjs") {
uri.set("https://registry.npmjs.org")
authToken.set("obfuscated")
}
}
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion build-conventions/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("com.gradle.enterprise") version "3.14"
id("com.gradle.enterprise") version "+"
}

@Suppress("UnstableApiUsage")
Expand Down
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ plugins {
id("convention.git-hooks")
}

nexusPublishing.repositories {
sonatype {
nexusUrl by uri("https://s01.oss.sonatype.org/service/local/")
snapshotRepositoryUrl by uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
nexusPublishing {
repositories {
sonatype {
nexusUrl by uri("https://s01.oss.sonatype.org/service/local/")
snapshotRepositoryUrl by uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
detekt = "1.23.0"
dokka = "1.8.20"
detekt = "1.23.4"
dokka = "1.9.10"
java = "11"
junit-jupiter = "5.10.0"
kotest = "5.6.2"
kotlin = "1.9.0"
junit-jupiter = "5.10.1"
kotest = "5.8.0"
kotlin = "1.9.22"

[libraries]
detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
Expand All @@ -16,7 +16,7 @@ plugin-container-tasks = "dev.petuska:container-tasks-gradle-plugin:0.0.4"
plugin-detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
plugin-git-hooks = "com.github.jakemarsden:git-hooks-gradle-plugin:0.0.2"
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
plugin-nebula-node = "com.netflix.nebula:nebula-node-plugin:3.0.0"
plugin-node-gradle = "com.github.node-gradle:gradle-node-plugin:7.0.1"
plugin-versions = "com.github.ben-manes:gradle-versions-plugin:0.47.0"
plugin-versions-update = "nl.littlerobots.vcu:plugin:0.8.1"

Expand All @@ -29,4 +29,4 @@ kotest-assertions = [
[plugins]
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
nexus-publish = "io.github.gradle-nexus.publish-plugin:1.3.0"
plugin-publish = "com.gradle.plugin-publish:1.2.0"
plugin-publish = "com.gradle.plugin-publish:1.2.1"
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion npm-publish-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kotlin {
explicitApi()
dependencies {
compileOnly(libs.plugin.kotlin)
compileOnly(libs.plugin.nebula.node)
compileOnly(libs.plugin.node.gradle)

testImplementation(libs.plugin.kotlin)
}
Expand Down
13 changes: 6 additions & 7 deletions npm-publish-gradle-plugin/src/main/kotlin/NpmPublishPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.petuska.npm.publish

import com.moowork.gradle.node.task.SetupTask
import com.github.gradle.node.task.NodeSetupTask
import dev.petuska.npm.publish.config.configure
import dev.petuska.npm.publish.extension.NpmPublishExtension
import dev.petuska.npm.publish.task.NodeExecTask
Expand Down Expand Up @@ -28,11 +28,10 @@ public class NpmPublishPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = with(project) {
val extension = extensions.create(NpmPublishExtension.NAME, NpmPublishExtension::class.java)
configure(extension)
pluginManager.withPlugin(NEBULA_NODE_PLUGIN) {
val nebulaNodeHome = project.tasks.named<SetupTask>(SetupTask.NAME)
.map { it.takeIf { it.enabled }.unsafeCast<SetupTask>() }
.map(SetupTask::getNodeDir)
.let(layout::dir)
pluginManager.withPlugin(NODE_GRADLE_PLUGIN) {
val nebulaNodeHome = project.tasks.named<NodeSetupTask>(NodeSetupTask.NAME)
.map { it.takeIf { it.enabled }.unsafeCast<NodeSetupTask>() }
.flatMap(NodeSetupTask::nodeDir)
extension.nodeHome.convention(
sysProjectEnvPropertyConvention(
name = "nodeHome",
Expand Down Expand Up @@ -87,6 +86,6 @@ public class NpmPublishPlugin : Plugin<Project> {
private companion object {
private const val KOTLIN_JS_PLUGIN = "org.jetbrains.kotlin.js"
private const val KOTLIN_MPP_PLUGIN = "org.jetbrains.kotlin.multiplatform"
private const val NEBULA_NODE_PLUGIN = "com.netflix.nebula.node"
private const val NODE_GRADLE_PLUGIN = "com.github.node-gradle.node"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal fun Project.configure(target: KotlinJsTargetDsl): Unit = with(PluginLog
)
pkg.dependencies.addAllLater(resolveDependencies(target.name, binary))
pkg.files { files ->
files.from(outputFile.map { it.parentFile })
files.from(outputFile.map(File::getParentFile))
files.from(processResourcesTask.map(Copy::getDestinationDir))
}
}
Expand Down
Loading

0 comments on commit b505ea8

Please sign in to comment.