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

Switch from yarn to pnpm for frontend dependency management. #1334

Merged
merged 4 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ jobs:

steps:
- uses: actions/checkout@v3 #Checkout the project from git
- name: Cache PNP #Pull the Yarn cache for PNP (package management strategy - see https://classic.yarnpkg.com/en/docs/pnp). This caches all dependencies assuming the yarn.lock file stays the same
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(./gradlew pnpmCacheDir -q)"
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: "**/.pnp.js"
key: ${{ runner.os }}-pnp-${{ hashFiles('**/yarn.lock') }}
- name: Cache yarn #Pull the cache for yarn. This caches all dependencies assuming the yarn.lock file stays the same
uses: actions/cache@v2
with:
path: "**/.yarn"
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Setup MySQL
uses: mirromutth/[email protected]
with:
Expand Down Expand Up @@ -97,16 +98,17 @@ jobs:

steps:
- uses: actions/checkout@v3 #Checkout the project from git
- name: Cache PNP #Pull the Yarn cache for PNP (package management strategy - see https://classic.yarnpkg.com/en/docs/pnp). This caches all dependencies assuming the yarn.lock file stays the same
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(./gradlew pnpmCacheDir -q)"
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: "**/.pnp.js"
key: ${{ runner.os }}-pnp-${{ hashFiles('**/yarn.lock') }}
- name: Cache yarn #Pull the cache for yarn. This caches all dependencies assuming the yarn.lock file stays the same
uses: actions/cache@v2
with:
path: "**/.yarn"
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Setup MySQL
uses: mirromutth/[email protected]
with:
Expand Down
11 changes: 2 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,8 @@ src/main/webapp/node_modules
/src/main/webapp/dist
/src/main/webapp/pages/templates/i18n/*.html

### YARN ###
/src/main/webapp/.pnp.*
/src/main/webapp/.yarn/*
!/src/main/webapp/.yarn/patches
!/src/main/webapp/.yarn/plugins
!/src/main/webapp/.yarn/releases
!/src/main/webapp/.yarn/sdks
!/src/main/webapp/.yarn/versions
/yarn.lock
### PNPM ###
/src/main/webapp/.pnpm-debug.log*

### MISC ###
/.theia/launch.json
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [UI]: Fixed user routes for admin panel. See [PR 1323](https://github.com/phac-nml/irida/pull/1323)
* [Developer/UI]: Added `eslint-prettier-pluggin`. See [PR 1328](https://github.com/phac-nml/irida/pull/1328)
* [Developer]: Replaced Maven with Gradle for build. See [PR 1300](https://github.com/phac-nml/irida/pull/1300)
* [Developer/UI]: Switched to pnpm from yarn for frontend dependency management. See [PR 1332](https://github.com/phac-nml/irida/pull/1334)

## [22.05.5] - 2022/06/28
* [UI]: Fixed bug preventing export of project samples table due to invalid url. [PR 1331](https://github.com/phac-nml/irida/pull/1331)
Expand Down
47 changes: 35 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.github.gradle.node.yarn.task.YarnTask
import com.github.gradle.node.pnpm.task.PnpmTask
import org.springframework.boot.gradle.tasks.run.BootRun

plugins {
Expand Down Expand Up @@ -255,13 +255,12 @@ tasks.bootWar { enabled = false }
tasks.war {
archiveClassifier.set("")
destinationDirectory.set(layout.buildDirectory.dir("dist"))
exclude("node")
exclude("node_modules/")
exclude(".yarn/")
exclude("resources/css/")
exclude("resources/js/")
exclude("webpack*")
exclude(".yarn*")
exclude(".npmrc")
exclude("pnpm-lock.yaml")
exclude("package.json")
exclude("styles.js")
exclude("entries.js")
Expand All @@ -272,20 +271,42 @@ tasks.war {
node {
download.set(true)
version.set("16.15.1")
yarnVersion.set("1.22.17") // we actualy use yarn 3 but we cannot specify that here
pnpmVersion.set("7.4.0")
workDir.set(file("${project.projectDir}/.gradle/nodejs"))
yarnWorkDir.set(file("${project.projectDir}/.gradle/yarn"))
nodeProjectDir.set(file("${projectDir}/src/main/webapp"))
nodeProjectDir.set(file("${project.projectDir}/src/main/webapp"))
}

tasks.register<YarnTask>("cleanWebapp") {
dependsOn("yarn_install")
yarnCommand.set(listOf("clean"))
tasks.register<PnpmTask>("pnpmCachePrune") {
group = "pnpm"
description = "Prune pnpm cache directory."
pnpmCommand.set(listOf("store", "prune"))
}

tasks.register<YarnTask>("buildWebapp") {
tasks.register<PnpmTask>("pnpmCacheDir") {
group = "pnpm"
description = "Report pnpm cache directory."
pnpmCommand.set(listOf("store", "path"))
}

tasks.named<PnpmTask>("pnpmInstall") {
finalizedBy(":pnpmCachePrune")
}

tasks.register<PnpmTask>("cleanWebapp") {
dependsOn(":pnpmInstall")
pnpmCommand.set(listOf("clean"))
}

tasks.register<PnpmTask>("buildWebapp") {
dependsOn(":cleanWebapp")
pnpmCommand.set(listOf("build"))
inputs.dir("${project.projectDir}/src/main/webapp/resources")
outputs.dir("${project.projectDir}/src/main/webapp/dist")
}

tasks.register<PnpmTask>("startWebapp") {
dependsOn(":cleanWebapp")
yarnCommand.set(listOf("build"))
pnpmCommand.set(listOf("start"))
inputs.dir("${project.projectDir}/src/main/webapp/resources")
outputs.dir("${project.projectDir}/src/main/webapp/dist")
}
Expand Down Expand Up @@ -320,6 +341,8 @@ val permittedTestSystemProperties = listOf(

fun createIntegrationTestTask(name: String, tags: String?, excludeListeners: String?): TaskProvider<Test> {
return tasks.register<Test>("${name}ITest") {
group = "verification"
description = "Runs the ${name} integration test suite."
val defaultSystemProperties = mapOf(
"junit.platform.execution.listeners.deactivate" to excludeListeners,
"spring.datasource.url" to "jdbc:mysql://localhost:3306/irida_integration_test",
Expand Down
4 changes: 2 additions & 2 deletions doc/administrator/web/building/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The following software is required to build IRIDA from source:
* Java 11 JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html)
* Git (http://git-scm.com/)
* Node (http://nodejs.org/)
* Yarn (https://yarnpkg.com/lang/en/)
* Pnpm (https://pnpm.io/)

Installing these dependencies varies greatly, depending on the host operating system that you are using, so no install instructions are provided. The following commands must be available on your `$PATH`:

Expand All @@ -41,7 +41,7 @@ git clone https://github.com/phac-nml/irida.git

### Installing dependencies

IRIDA uses Gradle and Yarn for managing external dependencies. Some of the libraries that we're using to build IRIDA are either not available in the Maven central repository, or we've had to seperately modify/update the code to accomplish the task we want, and the changes have not yet been accepted upstream.
IRIDA uses Gradle and Pnpm for managing external dependencies. Some of the libraries that we're using to build IRIDA are either not available in the Maven central repository, or we've had to seperately modify/update the code to accomplish the task we want, and the changes have not yet been accepted upstream.

These libraries are located in `/lib` folder and are automatically installed via gradle.

Expand Down
17 changes: 14 additions & 3 deletions doc/developer/interface/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ IRIDA uses the design system [Ant Design](https://ant.design/), a [React JS](htt

### Build Process:

#### Production Mode: `yarn build`
#### Production Mode: `./gradlew buildWebapp`
- Minimal source map
- File minification
- Bundle Chunking: Splits code into various bundles which can then me loaded on demand or in parallel. This makes for smaller bundle sizes and controls resource load prioritization. Bundle chunking also for code that is loaded on different pages be bundled together and cached by the browser.
- Hash code added to file name to allow for browser cache breaking.

#### Development Mode: `yarn start`
#### Development Mode: `./gradlew startWebapp`
- **watch** mode set; any changes to JavaScript of CSS files will be automatically compiled
- Extensive source map
- No file minification
Expand All @@ -49,6 +49,17 @@ Current babel plugins for UI development:
- [Export default from](https://babeljs.io/docs/en/babel-plugin-proposal-export-default-from)
- [Optional Chaining](https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining)

#### Adding dependencies

IRIDA uses [pnpm](https://pnpm.io/) to manage node dependencies.

To add a new dependency you can run the following command:
```bash
./gradlew pnpm_add DEPENDENCY
```

This follows the same argument structure as https://pnpm.io/cli/add.

### CSS

IRIDA uses [PostCSS](https://postcss.org/) to transform CSS:
Expand Down Expand Up @@ -86,7 +97,7 @@ For entries:

##### Webpack

- `yarn build`: runs webpack in production mode
- `./gradlew buildWebapp`: runs webpack in production mode
* Compilation, minification, and chunking of CSS and JavaScript assets.
* Extraction for internationalization strings.
* Creation of webpack manifest file
Expand Down
13 changes: 4 additions & 9 deletions doc/developer/setup/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ will cause Tomcat to start up much faster.

Other arguments can be be passed to the script:

* `--no-yarn`: Skip running the `yarn build` script along with the build, useful during development.
* `--no-webapp-build`: Skip running the `buildWebapp` task along with the build, useful during development.
* `--prod`: Run spring using the production profile.

#### Integration Testing
Expand All @@ -151,18 +151,13 @@ Please refer to the [Galaxy Install Guide][galaxy-install] for information on se
Front End Development Setup
---------------------------

IRIDA uses [Yarn 2](https://yarnpkg.com) for front-end dependency management. [Install yarn](https://yarnpkg.com/getting-started/install) by following the directions for your machine. For production, it is automatically installed during the build process.

From within `src/main/webapp/`:

You will need to run `yarn install` to install all dependencies required to run the following from the command line.
IRIDA uses [Pnpm](hhttps://pnpm.io/) for front-end dependency management. It is automatically installed when running gradle tasks that require the webapp to be built.

Tasks
=====

* `yarn sass` - compile all `.scss` files into `.css` files, with sourcemaps.
* `yarn build` - compile all es6 files to es2015.
* `yarn start` - use when developing front end code. Webpack will monitor for changes to the entry files, compile them, and then updates the browser with the changes.
* `./gradlew buildWebapp` - compile all es6 files to es2015.
* `./gradlew startWebapp` - use when developing front end code. Webpack will monitor for changes to the entry files, compile them, and then updates the browser with the changes.

JavaScript and SCSS Code Formatting and Linting
===============================================
Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ while [ $# -ne 0 ];
SPRING_BOOT_ARGS+=("--hbm.dev.auto=create")
ADD_DB=true
echo "Dropping then Creating/Recreating database schema"
elif [ "$1" = "--no-yarn" ];
elif [ "$1" = "--no-webapp-build" ];
then
GRADLE_ARGS+=("-xbuildWebapp")
elif [ "$1" = "--prod" ];
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginManagement {
gradlePluginPortal()
}
plugins {
id("com.github.node-gradle.node") version "3.3.0"
id("com.github.node-gradle.node") version "3.4.0"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("org.gradle.test-retry") version "1.4.0"
id("org.springframework.boot") version "2.6.6"
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shamefully-hoist=true
Loading