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
18 changes: 4 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,9 @@ MAVEN_OPTS='--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/ja

### Running the Yarn frontend build

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:
To run the Yarn frontend build, after [building the WAR file](#building-the-war-file), you simply run:

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

Then you can run Yarn with e.g.

```sh
cd war
yarn
```

Expand All @@ -75,10 +68,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):
On another terminal and start a [webpack](https://webpack.js.org/) dev server:
scherler marked this conversation as resolved.
Show resolved Hide resolved

```sh
cd war
yarn start
```

Expand Down Expand Up @@ -110,17 +102,15 @@ To automatically fix backend issues, run:
mvn spotless:apply
```

To view frontend issues, after [adding Node and Yarn to your path](#running-the-yarn-frontend-build), run:
To view frontend issues run:
scherler marked this conversation as resolved.
Show resolved Hide resolved

```sh
cd war
yarn lint
```

To fix frontend issues, after [adding Node and Yarn to your path](#running-the-yarn-frontend-build), run:
To fix frontend issues run:
scherler marked this conversation as resolved.
Show resolved Hide resolved

```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
129 changes: 129 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,128 @@ THE SOFTWARE.
<changelog.url>https://www.jenkins.io/changelog-stable</changelog.url>
</properties>
</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