From a530fe054944ca28bb49985c4334de20bca9c24c Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sun, 21 Nov 2021 15:41:28 +0100 Subject: build: move to yarn workspaces The root project (worktree) must have a valid package.json, .yarnrc.yaml, and have the gradle precompiled script plugin refinery-frontend-worktree applied to it. All frontend modules (workspaces) must have a valid package.json, be referenced in the worktree project.json, and be a valid gradle subproject with the gradle precompiled script plugin refinery-frontend-workspace applied to it. To reduce unnecessary downloads, we do the following workarounds: * The node version is pinned in gradle.properties and the installed node version is stored in .node/frontend.properties. A new node version is only downloaded if it differs from the installed one (or none is installed). This improves on the default gradle behavior, which would download a new node version if the classpath of the installNode task was changed. * The yarn classic version is pinned in gradle.properties and the installed yarn classic version is stored in .node/frontend.properties. This improves on the default gradle behavior, which would reinstall the yarn npm package at every build. * We disable the enableYarnBerry task, since a yarn berry version is already committed into the repository at .yarn/versions as it is recommended in http://yarnpkg.com/getting-started/qa/ * We use yarn set version --only-if-needed in the installYarn task. * The installFrontend task takes package.json and yarn.lock as inputs and produces .pnp.cjs and .pnp.loader.mjs as outputs. Whether this task is up-to-date can be checked by gradle quickly, since it doesn't have to traverse the node_module folder due to pnp resoltion: https://yarnpkg.com/features/pnp/ All workspaces have the installNode, installYarnGlobally, installYarn and installFrontend tasks disabled. However, these tasks depend on the task with the same name in the worktree project, so installation is still triggered globally. Moreover, the installFrontend task in the worktree has the package.json of the workspaces as inputs, so reinstallation is triggered when the workspace package.json changes. --- language-web/build.gradle | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'language-web/build.gradle') diff --git a/language-web/build.gradle b/language-web/build.gradle index b1ad86a7..a549288a 100644 --- a/language-web/build.gradle +++ b/language-web/build.gradle @@ -1,5 +1,5 @@ plugins { - alias libs.plugins.frontend + id 'refinery-frontend-workspace' id 'refinery-java-application' id 'refinery-xtext-conventions' } @@ -31,36 +31,12 @@ for (taskName in ['compileJava', 'processResources']) { def webpackOutputDir = "${buildDir}/webpack" def productionResources = "${webpackOutputDir}/production" def serverMainClass = 'tools.refinery.language.web.ServerLauncher' -def nodeDirectory = "${rootDir}/.gradle/node" frontend { - nodeVersion = project.ext['frontend.nodeVersion'] - nodeInstallDirectory = file('.node') - yarnEnabled = true - yarnVersion = project.ext['frontend.yarnVersion'] - assembleScript = 'run assemble:webpack' -} - -tasks.named('installYarnGlobally') { - // Do not check for updates all the time, since we only use yarn 1 for calling yarn berry. - outputs.dir "${frontend.nodeInstallDirectory.get()}/lib/node_modules/yarn" -} - -tasks.named('enableYarnBerry') { - // Yarn berry is checked into the repository, so there's no need to install it. - enabled = false -} - -tasks.named('installYarn') { - // Yarn berry is checked into the repository, so there's no need to install it. - enabled = false + assembleScript = 'assemble:webpack' } def installFrontend = tasks.named('installFrontend') -installFrontend.configure { - inputs.files('package.json', 'yarn.lock') - outputs.file '.pnp.cjs' -} def generateLezerGrammar = tasks.register('generateLezerGrammar', RunYarn) { dependsOn installFrontend -- cgit v1.2.3-70-g09d2