Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-73744] npm scripts lint:fix do not work #9718

Merged
merged 10 commits into from
Sep 16, 2024
File renamed without changes.
24 changes: 22 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,27 @@ jenkins_*.changes
*.pkg
*.zip
push-build.sh
war/node_modules/
war/yarn-error.log
node_modules/
yarn-error.log
.java-version
.checkstyle

/rebel.xml
junit.xml

# Yarn
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.pnp.*
.yarn/*
.yarnrc.yml
!.yarn/patches
!.yarn/plugins
!.yarn/sdks
!.yarn/versions

# Node
node/
node_modules/

# Generated JavaScript Bundles
jsbundles
14 changes: 7 additions & 7 deletions war/.prettierignore → .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ node/
.yarnrc.yml

# libraries / external deps / generated files
src/main/js/plugin-setup-wizard/bootstrap-detached.js
src/main/webapp/scripts/yui
src/main/webapp/jsbundles/
src/main/scss/_bootstrap.scss
war/src/main/js/plugin-setup-wizard/bootstrap-detached.js
war/src/main/webapp/scripts/yui
war/src/main/webapp/jsbundles/
war/src/main/scss/_bootstrap.scss

# test files that we don't need formatted
../test/src/test/resources
../test/jmh-report.json
test/src/test/resources
test/jmh-report.json

# doesn't work, see https://github.com/prettier/prettier/issues/5340
*.hbs

.yarn

# Incorrectly flagging forwarding slashes in regex
../.github/renovate.json
.github/renovate.json
2 changes: 1 addition & 1 deletion war/.stylelintrc.js → .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
extends: "stylelint-config-standard",
customSyntax: "postcss-scss",
ignoreFiles: ["src/main/scss/_bootstrap.scss"],
ignoreFiles: ["war/src/main/scss/_bootstrap.scss"],
rules: {
"no-descending-specificity": null,
"selector-class-pattern": "[a-z]",
Expand Down
8 changes: 2 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ MAVEN_OPTS='--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/ja
To run the Yarn frontend build, after [building the WAR file](#building-the-war-file), add the downloaded versions of Node and Yarn to your path:

```sh
export PATH=$PWD/war/node:$PWD/war/node/yarn/dist/bin:$PATH
export PATH=$PWD/node:$PWD/node/yarn/dist/bin:$PATH
```

Then you can run Yarn with e.g.

```sh
cd war
yarn
```

Expand All @@ -75,10 +74,9 @@ On one terminal, start a development server that will not process frontend asset
MAVEN_OPTS='--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED' mvn -pl war jetty:run -Dskip.yarn
```

On another terminal, move to the `war` folder and start a [webpack](https://webpack.js.org/) dev server, after [adding Node and Yarn to your path](#running-the-yarn-frontend-build):
Open another terminal and start a [webpack](https://webpack.js.org/) dev server, after [adding Node and Yarn to your path](#running-the-yarn-frontend-build):

```sh
cd war
yarn start
```

Expand Down Expand Up @@ -113,14 +111,12 @@ mvn spotless:apply
To view frontend issues, after [adding Node and Yarn to your path](#running-the-yarn-frontend-build), run:

```sh
cd war
yarn lint
```

To fix frontend issues, after [adding Node and Yarn to your path](#running-the-yarn-frontend-build), run:

```sh
cd war
yarn lint:fix
```

Expand Down
6 changes: 3 additions & 3 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = [
"**/jsbundles/",

// External scripts
"war/.pnp.cjs",
"war/.pnp.loader.mjs",
".pnp.cjs",
".pnp.loader.mjs",
"war/src/main/js/plugin-setup-wizard/bootstrap-detached.js",
"war/src/main/webapp/scripts/yui/*",
],
Expand Down Expand Up @@ -93,7 +93,7 @@ module.exports = [
"eslint.config.cjs",
"war/postcss.config.js",
"war/webpack.config.js",
"war/.stylelintrc.js",
".stylelintrc.js",
],
languageOptions: {
globals: {
Expand Down
14 changes: 7 additions & 7 deletions war/package.json → package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
},
"private": true,
"scripts": {
"dev": "webpack --config webpack.config.js",
"prod": "webpack --config webpack.config.js --mode=production",
"dev": "webpack --config war/webpack.config.js",
"prod": "webpack --config war/webpack.config.js --mode=production",
"build": "yarn prod",
"start": "yarn dev --watch",
"lint:js": "eslint ../ && prettier --check ../",
"lint:js-ci": "eslint ../ -f checkstyle -o target/eslint-warnings.xml && prettier --check ../",
"lint:css": "stylelint src/main/scss",
"lint:css-ci": "stylelint src/main/scss --custom-formatter stylelint-checkstyle-reporter -o target/stylelint-warnings.xml",
"lint:js": "eslint . && prettier --check .",
"lint:js-ci": "eslint . -f checkstyle -o target/eslint-warnings.xml && prettier --check .",
"lint:css": "stylelint war/src/main/scss",
"lint:css-ci": "stylelint war/src/main/scss --custom-formatter stylelint-checkstyle-reporter -o target/stylelint-warnings.xml",
"lint:ci": "yarn lint:js-ci && yarn lint:css-ci",
"lint:fix": "eslint --fix ../ && prettier --write ../ && stylelint src/main/scss --fix",
"lint:fix": "eslint --fix . && prettier --write . && stylelint war/src/main/scss --fix",
"lint": "yarn lint:js && yarn lint:css"
},
"devDependencies": {
Expand Down
193 changes: 193 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ THE SOFTWARE.
<spotless.check.skip>false</spotless.check.skip>
<!-- Make sure to keep the jetty-ee9-maven-plugin version in war/pom.xml in sync with the Jetty release in Winstone: -->
<winstone.version>8.1</winstone.version>
<node.version>20.17.0</node.version>
<!-- frontend-maven-plugin will install this Yarn version as bootstrap, then hand over control to Yarn Berry. -->
<yarn.version>1.22.19</yarn.version>
<!-- maven-antrun-plugin will download this Yarn version. -->
<yarn-berry.version>4.4.1</yarn-berry.version>
<yarn-berry.sha256sum>920b4530755296dc2ce8b4351f057d4a26429524fcb2789d277560d94837c27e</yarn-berry.sha256sum>
</properties>

<!--
Expand Down Expand Up @@ -415,5 +421,192 @@ THE SOFTWARE.
<changelog.url>https://www.jenkins.io/changelog-stable</changelog.url>
</properties>
</profile>
<profile>
<id>yarn-ci-lint</id>
<activation>
<property>
<name>env.CI</name>
</property>
<file>
<exists>package.json</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.15.0</version>
<executions>
<execution>
<id>yarn lint:ci</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>lint:ci</arguments>
<skip>${yarn.lint.skip}</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>yarn-lint</id>
<activation>
<property>
<name>!env.CI</name>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this PR merged when the mandatory Testing Done section was blank?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have added notes in the PR description on the testing that I did in the comment. Tim noted in his comment that he tested locally, and Jan noted in his comment that he tested locally.

However, I did not test the Maven profile and should have done that.

</property>
<file>
<exists>package.json</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.15.0</version>
<executions>
<execution>
<id>yarn lint</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>lint</arguments>
<skip>${yarn.lint.skip}</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>yarn-execution</id>
<activation>
<file>
<exists>package.json</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>download-yarn</id>
<goals>
<goal>run</goal>
</goals>
<phase>initialize</phase>
<configuration>
<target>
<property name="yarn.dest" value="${project.basedir}/.yarn/releases/yarn-${yarn-berry.version}.cjs" />
<dirname file="${yarn.dest}" property="yarn.dest.dir" />
<mkdir dir="${yarn.dest.dir}" />
<get dest="${yarn.dest}" src="https://repo.yarnpkg.com/${yarn-berry.version}/packages/yarnpkg-cli/bin/yarn.js" usetimestamp="true" />
<checksum algorithm="SHA-256" file="${yarn.dest}" property="${yarn-berry.sha256sum}" verifyProperty="yarn.checksum.matches" />
<condition property="yarn.checksum.matches.fail">
<equals arg1="${yarn.checksum.matches}" arg2="false" />
</condition>
<fail if="yarn.checksum.matches.fail">Checksum error</fail>
<echo file="${project.basedir}/.yarnrc.yml">yarnPath: ${yarn.dest}</echo>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.15.0</version>
<executions>

<execution>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<phase>initialize</phase>
<configuration>
<nodeVersion>v${node.version}</nodeVersion>
<yarnVersion>v${yarn.version}</yarnVersion>
<nodeDownloadRoot>https://repo.jenkins-ci.org/nodejs-dist/</nodeDownloadRoot>
<!-- tried to create a mirror for yarnDownloadRoot but it did not work -->
</configuration>
</execution>

<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>initialize</phase>
</execution>

<execution>
<id>yarn build</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>

<execution>
<id>yarn lint</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>lint:ci</arguments>
<skip>${yarn.lint.skip}</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>clean-node</id>
<activation>
<property>
<name>cleanNode</name>
</property>
<file>
<exists>package.json</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<!-- Version specified in grandparent POM -->
<configuration>
<filesets>
<fileset>
<directory>node</directory>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>node_modules</directory>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Loading