Move from NPM to PNPM (#19839)

This commit is contained in:
Jon Koops 2023-05-05 16:03:24 +00:00 committed by GitHub
parent e44464d3b8
commit 2a18bcb246
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 7317 additions and 11318 deletions

View file

@ -39,10 +39,6 @@ runs:
name: PhantomJS cache
uses: ./.github/actions/phantomjs-cache
- id: npm-cache
name: NPM cache
uses: ./.github/actions/npm-cache
- id: build-keycloak
name: Build Keycloak
shell: bash

View file

@ -1,17 +0,0 @@
name: NPM Cache
description: Caches NPM artifacts
runs:
using: composite
steps:
- id: weekly-cache-key
name: Key for weekly rotation of cache
shell: bash
run: echo "key=npm-`date -u "+%Y-%U"`" >> $GITHUB_OUTPUT
- id: cache-npm-repository
name: NPM cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ steps.weekly-cache-key.outputs.key }}

View file

@ -1,29 +0,0 @@
name: Setup NPM
description: Sets up Node.js and runs NPM so dependencies are installed.
inputs:
node-version:
description: Node.js version
required: false
default: "18"
working-directory:
description: The working directory where the `package-lock.json` is located.
required: false
default: ""
runs:
using: composite
steps:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
check-latest: true
cache: npm
cache-dependency-path: ${{ inputs.working-directory }}/package-lock.json
- name: Install dependencies
working-directory: ${{ inputs.working-directory }}
shell: bash
run: npm ci

48
.github/actions/pnpm-setup/action.yml vendored Normal file
View file

@ -0,0 +1,48 @@
name: Setup PNPM
description: Sets up Node.js and runs PNPM so dependencies are installed.
inputs:
node-version:
description: Node.js version
required: false
default: "18"
working-directory:
description: The working directory where the `pnpm-lock.yaml` file is located.
required: false
default: ""
runs:
using: composite
steps:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
check-latest: true
- name: Enable Corepack
shell: bash
run: corepack enable
- name: Get PNPM store directory
id: pnpm-cache
shell: bash
run: |
echo "store-path=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup PNPM cache
with:
# Also cache Cypress binary.
path: |
~/.cache/Cypress
${{ steps.pnpm-cache.outputs.store-path }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('${{ inputs.working-directory }}/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
working-directory: ${{ inputs.working-directory }}
shell: bash
run: pnpm install --frozen-lockfile

View file

@ -24,26 +24,3 @@ updates:
ignore:
- dependency-name: bootstrap
update-types: ["version-update:semver-major"]
- package-ecosystem: npm
directory: js
open-pull-requests-limit: 999
rebase-strategy: disabled
versioning-strategy: increase
schedule:
interval: weekly
labels:
- area/dependencies
- team/ui
ignore:
- dependency-name: react
update-types: ["version-update:semver-major"]
- dependency-name: react-dom
update-types: ["version-update:semver-major"]
- dependency-name: "@types/react"
update-types: ["version-update:semver-major"]
- dependency-name: "@types/react-dom"
update-types: ["version-update:semver-major"]
- dependency-name: vite
update-types: ["version-update:semver-major"]
- dependency-name: "@vitejs/plugin-react"
update-types: ["version-update:semver-major"]

View file

@ -69,14 +69,14 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/npm-setup
- uses: ./.github/actions/pnpm-setup
with:
working-directory: js
- run: npm run lint --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run lint
working-directory: js
- run: npm run build --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run build
working-directory: js
keycloak-js:
@ -89,11 +89,11 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/npm-setup
- uses: ./.github/actions/pnpm-setup
with:
working-directory: js
- run: npm run build --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run build
working-directory: js
keycloak-masthead:
@ -106,14 +106,14 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/npm-setup
- uses: ./.github/actions/pnpm-setup
with:
working-directory: js
- run: npm run lint --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run lint
working-directory: js
- run: npm run build --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run build
working-directory: js
ui-shared:
@ -126,14 +126,14 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/npm-setup
- uses: ./.github/actions/pnpm-setup
with:
working-directory: js
- run: npm run lint --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run lint
working-directory: js
- run: npm run build --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run build
working-directory: js
account-ui:
@ -146,14 +146,14 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/npm-setup
- uses: ./.github/actions/pnpm-setup
with:
working-directory: js
- run: npm run lint --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run lint
working-directory: js
- run: npm run build --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run build
working-directory: js
admin-ui:
@ -166,20 +166,20 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/npm-setup
- uses: ./.github/actions/pnpm-setup
with:
working-directory: js
- run: npm run lint --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run lint
working-directory: js
- run: npm run test --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run test
working-directory: js
- run: npm run build --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run build
working-directory: js
- run: npm run cy:check-types --workspace=${{ env.WORKSPACE }}
- run: pnpm --filter=${{ env.WORKSPACE }} run cy:check-types
working-directory: js
admin-ui-e2e:
@ -202,12 +202,12 @@ jobs:
with:
chrome-version: stable
- uses: ./.github/actions/npm-setup
- uses: ./.github/actions/pnpm-setup
with:
working-directory: js
- name: Compile Admin Client
run: npm run build --workspace=@keycloak/keycloak-admin-client
run: pnpm --filter=@keycloak/keycloak-admin-client run build
working-directory: js
- name: Download Keycloak server
@ -224,7 +224,7 @@ jobs:
KEYCLOAK_ADMIN_PASSWORD: admin
- name: Start LDAP server
run: npm run cy:ldap-server --workspace=${{ env.WORKSPACE }} &
run: pnpm --filter=${{ env.WORKSPACE }} run cy:ldap-server &
working-directory: js
- name: Run Cypress

View file

@ -50,31 +50,33 @@
<executions>
<execution>
<goals>
<goal>install-node-and-npm</goal>
<goal>install-node-and-pnpm</goal>
</goals>
</execution>
<execution>
<id>npm-ci</id>
<id>pnpm-install</id>
<goals>
<goal>npm</goal>
<goal>pnpm</goal>
</goals>
<configuration>
<arguments>ci --ignore-scripts</arguments>
<arguments>install --frozen-lockfile --ignore-scripts</arguments>
</configuration>
</execution>
<execution>
<id>npm-build</id>
<id>run-build</id>
<goals>
<goal>npm</goal>
<goal>pnpm</goal>
</goals>
<configuration>
<arguments>run build --workspace=keycloak-js</arguments>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<workingDirectory>${js.projectDir}</workingDirectory>
<pnpmVersion>${pnpm.version}</pnpmVersion>
<installDirectory>${js.projectDir}</installDirectory>
<workingDirectory>${js.projectDir}/libs/keycloak-js</workingDirectory>
</configuration>
</plugin>
</plugins>

View file

@ -2,13 +2,15 @@
## Package managers
The default package manager for the Keycloak UI projects is NPM. There are several reasons why NPM is used over other package managers (such as Yarn and PNPM):
The default package manager for the Keycloak UI projects is PNPM, we recommend installing it with [Corepack](https://nodejs.org/api/corepack.html) for the best compatibility.
- It comes included with NodeJS by default, meaning it does not have to be installed manually.
- Most contributors are familiar with the NPM ecosystem and tooling.
- We do not use any of the 'advanced' features of other package managers (such as [Yarn's PNP](https://yarnpkg.com/features/pnp)).
There are several reasons why PNPM is used over other package managers (such as NPM and Yarn):
If you submit a pull request that changes the dependencies, make sure that you also update the `package-lock.json` as well.
- The reasons mentioned in [pnpm vs npm](https://pnpm.io/pnpm-vs-npm), mostly it avoids [silly bugs](https://www.kochan.io/nodejs/pnpms-strictness-helps-to-avoid-silly-bugs.html).
- Unlike [`npm ci`](https://docs.npmjs.com/cli/v9/commands/npm-ci) it preserves the `node_modules` directory between installs, allowing for faster install times (especially in Maven builds).
- Unlike NPM it does not require workspace dependencies to be [explicitly versioned](https://pnpm.io/workspaces#publishing-workspace-packages), simplifying release versioning.
If you submit a pull request that changes the dependencies, make sure that you also update the `pnpm-lock.yaml` as well.
## Typescript

View file

@ -11,16 +11,17 @@
"@patternfly/react-core": "^4.276.8",
"@patternfly/react-icons": "^4.93.6",
"i18next": "^22.4.15",
"@patternfly/react-table": "^4.113.0",
"i18next-http-backend": "^2.2.0",
"keycloak-js": "999.0.0-SNAPSHOT",
"keycloak-masthead": "999.0.0-SNAPSHOT",
"keycloak-js": "workspace:*",
"keycloak-masthead": "workspace:*",
"lodash-es": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.43.9",
"react-i18next": "^12.2.2",
"react-router-dom": "6.11.1",
"ui-shared": "999.0.0-SNAPSHOT"
"ui-shared": "workspace:*"
},
"devDependencies": {
"@types/lodash-es": "^4.17.7",

View file

@ -34,17 +34,17 @@
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<id>npm-build</id>
<id>run-build</id>
<goals>
<goal>npm</goal>
<goal>pnpm</goal>
</goals>
<configuration>
<arguments>run build --workspace=account-ui</arguments>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
<configuration>
<workingDirectory>../..</workingDirectory>
<installDirectory>../..</installDirectory>
</configuration>
</plugin>
<plugin>

View file

@ -27,7 +27,7 @@ Now that the Keycloak sever is running it's time to run the development server f
To start the development server run the following command:
```bash
npm run dev
pnpm run dev
```
Once the process of optimization is done your browser will automatically open your local host on port `8080`. From here you will be redirected to the Keycloak server to authenticate, which you can do with the default username and password (`admin`).
@ -43,7 +43,7 @@ If you want to build the application using Maven and produce a JAR that can be i
Every time you create a commit it should be automatically linted and formatted for you. It is also possible to trigger the linting manually:
```bash
npm run lint
pnpm run lint
```
## Integration testing with Cypress
@ -59,13 +59,13 @@ Ensure the Keycloak and development server are running as [outlined previously](
You can run the tests using the interactive graphical user interface using the following command:
```bash
npm run cy:open
pnpm run cy:open
```
Alternatively the tests can also run headless as follows:
```
npm run cy:run
pnpm run cy:run
```
For more information about the Cypress command-line interface consult [the documentation](https://docs.cypress.io/guides/guides/command-line).

View file

@ -60,29 +60,33 @@
}
},
"dependencies": {
"@keycloak/keycloak-admin-client": "999.0.0-SNAPSHOT",
"@keycloak/keycloak-admin-client": "workspace:*",
"@patternfly/patternfly": "^4.224.2",
"@patternfly/react-code-editor": "^4.82.115",
"@patternfly/react-core": "^4.276.8",
"@patternfly/react-icons": "^4.93.6",
"@patternfly/react-styles": "^4.92.6",
"@patternfly/react-table": "^4.113.0",
"admin-ui": "file:",
"dagre": "^0.8.5",
"file-saver": "^2.0.5",
"file-selector": "^0.6.0",
"flat": "^5.0.2",
"i18next": "^22.4.15",
"i18next-http-backend": "^2.2.0",
"keycloak-js": "999.0.0-SNAPSHOT",
"keycloak-js": "workspace:*",
"lodash-es": "^4.17.21",
"monaco-editor": "^0.34.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-error-boundary": "^3.1.4",
"react-hook-form": "^7.43.9",
"react-i18next": "^12.2.2",
"react-router": "^6.11.1",
"react-router-dom": "6.11.1",
"reactflow": "^11.7.0",
"ui-shared": "999.0.0-SNAPSHOT",
"ui-shared": "workspace:*",
"use-react-router-breadcrumbs": "^4.0.1"
},
"devDependencies": {

View file

@ -78,17 +78,17 @@
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<id>npm-build</id>
<id>run-build</id>
<goals>
<goal>npm</goal>
<goal>pnpm</goal>
</goals>
<configuration>
<arguments>run build --workspace=admin-ui</arguments>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
<configuration>
<workingDirectory>../..</workingDirectory>
<installDirectory>../..</installDirectory>
</configuration>
</plugin>
<plugin>

View file

@ -4,16 +4,16 @@ This app allows you to run a local development version of the Keycloak server.
### Running the Keycloak server
First, ensure that all dependencies are installed locally using NPM by running:
First, ensure that all dependencies are installed locally using PNPM by running:
```bash
npm install
pnpm install
```
After the dependencies are installed we can start the Keycloak server by running the following command:
```bash
npm run start
pnpm run start
```
This will download the [Nightly version](https://github.com/keycloak/keycloak/releases/tag/nightly) of the Keycloak server and run it locally on port `8180`. If a previously downloaded version was found in the `server/` directory then that one will be used instead. If you want to download the latest Nightly version you can remove the server directory before running the command to start the server.
@ -23,7 +23,7 @@ In order for the development version of the Admin UI to work you will have to im
Wait for the Keycloak server to be up and running and run the following command in a new terminal:
```bash
npm run import-client
pnpm run import-client
```
You'll only have to run this command once, unless you remove the server directory or Keycloak server data.

View file

@ -14,6 +14,7 @@
}
},
"dependencies": {
"@keycloak/keycloak-admin-client": "workspace:*",
"@octokit/rest": "^19.0.7",
"@types/gunzip-maybe": "^1.4.0",
"@types/tar-fs": "^2.0.1",

View file

@ -107,20 +107,20 @@ setInterval(() => kcAdminClient.auth(credentials), 58 * 1000); // 58 seconds
To build the source do a build:
```bash
npm run build
pnpm run build
```
Start the Keycloak server:
```bash
npm run server:start
pnpm run server:start
```
If you started your container manually make sure there is an admin user named 'admin' with password 'admin'.
Then start the tests with:
```bash
npm test
pnpm test
```
## Supported APIs

View file

@ -15,7 +15,7 @@
"build": "wireit",
"lint": "wireit",
"test": "wireit",
"prepublishOnly": "npm run build"
"prepublishOnly": "pnpm run build"
},
"wireit": {
"build": {

View file

@ -47,27 +47,27 @@
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<id>npm-prepublish</id>
<id>run-build</id>
<goals>
<goal>npm</goal>
<goal>pnpm</goal>
</goals>
<configuration>
<arguments>run prepublishOnly --workspace=@keycloak/keycloak-admin-client</arguments>
<arguments>run build</arguments>
</configuration>
</execution>
<execution>
<id>npm-pack</id>
<id>pack</id>
<phase>package</phase>
<goals>
<goal>npm</goal>
<goal>pnpm</goal>
</goals>
<configuration>
<arguments>pack --workspace=@keycloak/keycloak-admin-client --pack-destination=libs/keycloak-admin-client/target</arguments>
<arguments>pack --pack-destination=target</arguments>
</configuration>
</execution>
</executions>
<configuration>
<workingDirectory>../..</workingDirectory>
<installDirectory>../..</installDirectory>
</configuration>
</plugin>
</plugins>

View file

@ -10,7 +10,7 @@
],
"scripts": {
"build": "wireit",
"prepublishOnly": "npm run build"
"prepublishOnly": "pnpm run build"
},
"wireit": {
"build": {

View file

@ -47,27 +47,27 @@
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<id>npm-prepublish</id>
<id>run-build</id>
<goals>
<goal>npm</goal>
<goal>pnpm</goal>
</goals>
<configuration>
<arguments>run prepublishOnly --workspace=keycloak-js</arguments>
<arguments>run build</arguments>
</configuration>
</execution>
<execution>
<id>npm-pack</id>
<id>pack</id>
<phase>package</phase>
<goals>
<goal>npm</goal>
<goal>pnpm</goal>
</goals>
<configuration>
<arguments>pack --workspace=keycloak-js --pack-destination=libs/keycloak-js/target</arguments>
<arguments>pack --pack-destination=target</arguments>
</configuration>
</execution>
</executions>
<configuration>
<workingDirectory>../..</workingDirectory>
<installDirectory>../..</installDirectory>
</configuration>
</plugin>
</plugins>

View file

@ -1,6 +1,5 @@
{
"name": "keycloak-masthead",
"version": "999.0.0-SNAPSHOT",
"type": "module",
"main": "./dist/keycloak-masthead.js",
"types": "./dist/keycloak-masthead.d.ts",
@ -42,7 +41,8 @@
},
"dependencies": {
"@patternfly/react-core": "^4.276.8",
"keycloak-js": "999.0.0-SNAPSHOT",
"@patternfly/react-styles": "^4.11.8",
"keycloak-js": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},

View file

@ -1,6 +1,5 @@
{
"name": "ui-shared",
"version": "999.0.0-SNAPSHOT",
"type": "module",
"main": "./dist/ui-shared.js",
"types": "./dist/ui-shared.d.ts",
@ -36,9 +35,10 @@
},
"dependencies": {
"@patternfly/react-core": "^4.276.8",
"react-hook-form": "7.43.9",
"@patternfly/react-icons": "^4.93.6",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-hook-form": "7.43.9"
},
"devDependencies": {
"@types/react": "^18.2.4",
@ -47,6 +47,7 @@
"rollup-plugin-peer-deps-external": "^2.2.4",
"vite": "^4.3.4",
"vite-plugin-checker": "^0.6.0",
"vite-plugin-dts": "^2.3.0"
"vite-plugin-dts": "^2.3.0",
"vitest": "^0.31.0"
}
}

11141
js/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,5 @@
{
"name": "root",
"workspaces": [
"libs/ui-shared",
"libs/keycloak-admin-client",
"libs/keycloak-js",
"libs/keycloak-masthead",
"apps/account-ui",
"apps/admin-ui",
"apps/keycloak-server"
],
"scripts": {
"prepare": "cd .. && husky install js/.husky"
},
@ -28,9 +19,11 @@
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"prettier": "^2.8.8",
"tslib": "^2.5.0",
"typescript": "^5.0.4",
"wireit": "^0.9.5"
},
"packageManager": "pnpm@8.4.0",
"lint-staged": {
"*.{js,jsx,mjs,ts,tsx}": "eslint --cache --fix"
}

7158
js/pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff

3
js/pnpm-workspace.yaml Normal file
View file

@ -0,0 +1,3 @@
packages:
- 'apps/*'
- 'libs/**'

View file

@ -13,7 +13,7 @@
<packaging>pom</packaging>
<name>Keycloak JavaScript Parent</name>
<description>Parent of all JavaScript related code, sets up Node.js and NPM and installs dependencies for all projects in the workspace.</description>
<description>Parent of all JavaScript related code, sets up Node.js and PNPM and installs dependencies for all projects in the workspace.</description>
<modules>
<module>apps/account-ui</module>
@ -30,21 +30,22 @@
<executions>
<execution>
<goals>
<goal>install-node-and-npm</goal>
<goal>install-node-and-pnpm</goal>
</goals>
</execution>
<execution>
<id>npm-ci</id>
<id>pnpm-install</id>
<goals>
<goal>npm</goal>
<goal>pnpm</goal>
</goals>
<configuration>
<arguments>ci --ignore-scripts</arguments>
<arguments>install --frozen-lockfile --ignore-scripts</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<pnpmVersion>${pnpm.version}</pnpmVersion>
</configuration>
</plugin>
</plugins>

View file

@ -239,6 +239,7 @@
<!-- Frontend -->
<node.version>v18.16.0</node.version>
<pnpm.version>8.4.0</pnpm.version>
</properties>
<url>http://keycloak.org</url>

View file

@ -8,13 +8,6 @@ mvn versions:set -DnewVersion=$NEW_VERSION -DgenerateBackupPoms=false -DgroupId=
# Docker
sed -i "s/ENV KEYCLOAK_VERSION .*/ENV KEYCLOAK_VERSION $NEW_VERSION/" quarkus/container/Dockerfile
# NPM
cd js
npm --workspace=admin-ui --workspace=account-ui --workspace=keycloak-masthead pkg set "dependencies.keycloak-js=$NEW_VERSION"
npm --workspace=admin-ui pkg set "dependencies.@keycloak/keycloak-admin-client=$NEW_VERSION"
npm --workspace=keycloak-js --workspace=@keycloak/keycloak-admin-client version $NEW_VERSION --allow-same-version --no-git-tag-version
cd -
# Documentation
cd docs/documentation
SHORT_VERSION=`echo $NEW_VERSION | awk -F '.' '{ print $1"."$2 }'`
@ -24,3 +17,8 @@ sed -i 's/:project_versionNpm: .*/:project_versionNpm: '$NEW_VERSION'/' topics/t
sed -i 's/:project_versionDoc: .*/:project_versionDoc: '$SHORT_VERSION'/' topics/templates/document-attributes.adoc
cd -
# Keycloak JS
echo "$(jq '. += {"version": "'$NEW_VERSION'"}' js/libs/keycloak-js/package.json)" > js/libs/keycloak-js/package.json
# Keycloak Admin Client
echo "$(jq '. += {"version": "'$NEW_VERSION'"}' js/libs/keycloak-admin-client/package.json)" > js/libs/keycloak-admin-client/package.json