siouan / frontend-gradle-plugin

All-in-one Gradle Node/NPM/PNPM/Yarn plugin to build, test, deploy Javascript applications using a Corepack-enabled package manager.
https://siouan.github.io/frontend-gradle-plugin/
Apache License 2.0
158 stars 23 forks source link

RunNpx task silently removed in 7.0.0 #214

Closed mjustin closed 12 months ago

mjustin commented 12 months ago

Description

I have a Gradle project which has custom tasks defined of type RunNpx. When I upgrade my org.siouan.frontend-jdk11 plugin version to 8.0.0 (or 7.0.0), I get a build failure on my file import since org.siouan.frontendgradleplugin.infrastructure.gradle.RunNpx no longer exists. However, I see no notice (in the release notes, GitHub project issues, or otherwise) that this task was removed.

My expectation is that if a public, previously documented task is removed from the API, its removal would be called out so that users know that they need to change their application in order to migrate, and so they know the migration steps needed.

Build file

import org.siouan.frontendgradleplugin.infrastructure.gradle.RunNpx

plugins {
    id 'org.siouan.frontend-jdk11' version '6.0.0' // Fails if changed to '7.0.0' or '8.0.0'
}

frontend {
    nodeVersion = '20.9.0'
}

tasks.register('issueExample', RunNpx) {
    script = 'tldr tldr'
}

Failure

$ ./gradlew issueExample

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/me/projects/issues/frontend-gradle-plugin-7-import-issue/build.gradle' line: 1

* What went wrong:
Could not compile build file '/Users/me/projects/issues/frontend-gradle-plugin-7-import-issue/build.gradle'.
> startup failed:
  build file '/Users/me/projects/issues/frontend-gradle-plugin-7-import-issue/build.gradle': 1: unable to resolve class org.siouan.frontendgradleplugin.infrastructure.gradle.RunNpx
   @ line 1, column 1.
     import org.siouan.frontendgradleplugin.infrastructure.gradle.RunNpx
     ^

  1 error

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 851ms

Workaround

A workaround is to switch from npx to npm exec --:

import org.siouan.frontendgradleplugin.infrastructure.gradle.RunNpm

plugins {
    id 'org.siouan.frontend-jdk11' version '8.0.0'
}

frontend {
    nodeVersion = '20.9.0'
}

tasks.register('issueExample', RunNpm) {
    script = 'exec -- tldr tldr'
}

Environment

Settings in build.gradle[.kts] file:

frontend {
    nodeVersion = '20.9.0'
}
v1nc3n4 commented 12 months ago

Hello @mjustin,

Thanks for pointing out notes for release 7.0.0 are missing this information. It has been completed accordingly.

BR

bric3 commented 11 months ago

Thank you @mjustin for the workaround I had to do that as well

    val updateBrowserList by registering(RunNpm::class) {
        group = "frontend"
        description = "npx update-browserslist-db@latest"
        // Browserslist: caniuse-lite is outdated. Please run:
        //   npx update-browserslist-db@latest
        //   Why you should do it regularly: https://github.com/browserslist/update-db#readme
        script = "exec -- update-browserslist-db@latest"
    }

    installFrontend {
        dependsOn(updateBrowserList)
    }
mjustin commented 11 months ago

Thanks. The updated 7.0.0 release notes definitely call this out now.

  • Task type RunNpx was removed after command npx became deprecated. Command npm exec should be used instead.