node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
599 stars 117 forks source link

Gradle Plugin VS Node Terminal Command #311

Closed benore closed 3 months ago

benore commented 3 months ago

I am using node 22, npx 10.5.1, eslint 9.1.1. For gradle, I am using gradle v6.8.3 (although I get the same results with 8.7). I am also using the plugin: com.github.node-gradle:gradle-node-plugin:7.0.2

When I run from the terminal, everything works as expected. With gradle I get the error below. Keep in mind, I don't have any ignore rules defined (eslintignore file or eslintIgnore properties) :

/////BEGIN ERROR///// Oops! Something went wrong! 😦

ESLint: 9.1.1

You are linting " [pathto]/src/assets/js//*.js", but all of the files matching the glob pattern " [pathto]/src/assets/js//.js" are ignored.

If you don't want to lint these files, remove the pattern " [pathto]/src/assets/js/**/.js" from the list of arguments passed to ESLint.

If you do want to lint these files, try the following solutions:

Check your .eslintignore file, or the eslintIgnore property in package.json, to ensure that the files are not configured to be ignored. Explicitly list the files from this glob that you'd like to lint on the command-line, rather than providing a glob as an argument. /////END ERROR/////

Terminal Command: npx eslint [pathto]/src//*.js --format html --config [pathto]/config/node/eslint.config.js --output-file [pathto]/build/reports/eslint/eslint.html

Gradle:

task prepareEslint { doLast { mkdir "$project.buildDir/reports/eslint" } }

// runs eslint task eslint(type: NpxTask, group: 'verification') { dependsOn prepareEslint command = 'eslint' args = [ "${project.projectDir}/src//*.js", "--config", "${project.projectDir}/config/node/eslint.config.js", "--format","html", "--output-file","${project.buildDir}/reports/eslint/eslint.html" ] ignoreExitValue = false }

I have successfully run this without error on the terminal, but I am stumped on why this isn't working with the same config file in gradle.

deepy commented 3 months ago

I suspect that what you're seeing is from your shell doing the globbing (i.e. expanding the *.js to be all the files matching instead), try adding echo in front of npx in your terminal and see if it shows the asterisk in the output

benore commented 3 months ago

I think you misunderstood. This runs fine in the terminal. It's the plugin for gradle that craps out.

benore commented 3 months ago

I had everything in a subfolder (/config/node/node_modules) and it was not working. but when I moved it to the project root, it worked. for some reason it seems to be causing a problem when it is not in the root. this is not a issue with eslint 7.12.1, but it is with 8.x and 9.x.

Of course moving it to the root isn't great either. The "files" and "ignores" attributes seems to be ignored in the root eslint.config.js.

deepy commented 3 months ago

It's not the plugin that's crapping out, what you're configuring in Gradle and what you're doing command-line is two separate things and the reason it works in your terminal is because your shell expands the * for you. If you want to see how this looks, add an echo before npx and run it again in your terminal.

There's no post-processing done on the args, you'll need to tell eslint what you want it to do, it looks to me like you'd want to point eslint to the directory, but if you want to specify the exact files Gradle has a good documentation on working with files, the easiest is probably creating a fileTree and filtering it before providing it as arguments.

I'd recommend giving eslint a directory instead of a specific set of files, and configuring inputs/outputs so Gradle doesn't re-run the task if nothing has changed since the last time