Download Yarn Berry with Corepack rather than Yarn 1.x (#9772)

* Use eirslett/frontend-maven-plugin#1157

* Test 1

* Test 2

* Test 3

* Testing is finished

* https://github.com/jenkinsci/jenkins/pull/9772#discussion_r1771275590

* https://github.com/jenkinsci/jenkins/pull/9772#discussion_r1771977848
This commit is contained in:
Basil Crow 2024-10-02 07:49:10 -07:00 committed by GitHub
parent 4759f1a6f0
commit ddad8afc30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 20 additions and 73 deletions

7
.gitignore vendored
View File

@ -65,9 +65,7 @@ junit.xml
# Yarn
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.pnp.*
.yarn/*
.yarnrc.yml
!.yarn/patches
!.yarn/plugins
!.yarn/sdks
@ -78,7 +76,4 @@ node/
node_modules/
# Generated JavaScript Bundles
jsbundles
# In case someone accidentally runs npm install instead of yarn install
package-lock.json
war/src/main/webapp/jsbundles/

View File

@ -7,8 +7,6 @@ node/
.git
.yarnrc.yml
# libraries / external deps / generated files
war/src/main/js/plugin-setup-wizard/bootstrap-detached.js
war/src/main/webapp/scripts/yui

2
.yarnrc.yml Normal file
View File

@ -0,0 +1,2 @@
enableGlobalCache: false
nodeLinker: node-modules

View File

@ -53,12 +53,12 @@ MAVEN_OPTS='--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/ja
### Running the Yarn frontend build
> [!TIP]
> If you already have Node.js installed, you do not need to change your path. Start using `yarn` by enabling [Corepack](https://yarnpkg.com/corepack) with `corepack enable`, if it isn't already; this will add the `yarn` binary to your PATH.
> If you already have Node.js installed, you do not need to change your path. Start using Yarn by enabling [Corepack](https://yarnpkg.com/corepack) with `corepack enable`, if it isn't already; this will add the `yarn` binary to your path.
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/node:$PWD/node/yarn/dist/bin:$PATH
export PATH=$PWD/node:$PWD/node/node_modules/corepack/shims:$PATH
```
Then you can run Yarn with e.g.

View File

@ -65,5 +65,8 @@
"defaults",
"not IE 11"
],
"engines": {
"node": ">=20.0.0"
},
"packageManager": "yarn@4.5.0"
}

55
pom.xml
View File

@ -99,11 +99,6 @@ THE SOFTWARE.
<!-- 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.5.0</yarn-berry.version>
<yarn-berry.sha256sum>cc00dce5de4f68d11450519a0f69eadf2a1cbe5cc0d8e740bfac817a31d76874</yarn-berry.sha256sum>
</properties>
<!--
@ -430,66 +425,40 @@ THE SOFTWARE.
</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.1</version>
<executions>
<execution>
<id>install node and yarn</id>
<id>install node and corepack</id>
<goals>
<goal>install-node-and-yarn</goal>
<goal>install-node-and-corepack</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>
<goal>corepack</goal>
</goals>
<phase>initialize</phase>
<configuration>
<arguments>yarn install</arguments>
</configuration>
</execution>
<execution>
<id>yarn build</id>
<goals>
<goal>yarn</goal>
<goal>corepack</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<arguments>build</arguments>
<arguments>yarn build</arguments>
</configuration>
</execution>
</executions>
@ -517,11 +486,11 @@ THE SOFTWARE.
<execution>
<id>yarn lint:ci</id>
<goals>
<goal>yarn</goal>
<goal>corepack</goal>
</goals>
<phase>test</phase>
<configuration>
<arguments>lint:ci</arguments>
<arguments>yarn lint:ci</arguments>
<skip>${yarn.lint.skip}</skip>
</configuration>
</execution>
@ -550,11 +519,11 @@ THE SOFTWARE.
<execution>
<id>yarn lint</id>
<goals>
<goal>yarn</goal>
<goal>corepack</goal>
</goals>
<phase>test</phase>
<configuration>
<arguments>lint</arguments>
<arguments>yarn lint</arguments>
<skip>${yarn.lint.skip}</skip>
</configuration>
</execution>

20
war/.gitignore vendored
View File

@ -1,20 +0,0 @@
work
/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