Developing applications and libraries with pnpm

Classis project driven by package.json

The LifecyclePnpmNodeWithPackageJson is the standard developmet model where everything is configured in package.json.

Minimal configuration

build.gradle
import org.ysb33r.gradle.jse.pnpm.toolchains.JsePnpmToolchain
import org.ysb33r.gradle.jse.pnpm.dev.models.LifecyclePnpmNodeWithPackageJson

plugins {
 id 'org.ysb33r.jsecosystem.pnpm.dev' version '5.1.1'
}

jsEcosystem {
  toolchains {
    pnpm(JsePnpmToolchain) { (1)
    }
  }
}

jsProjects {
  lifecycleManagers {
    pnpm(LifecyclePnpmNodeWithPackageJson) { (2)
      toolchain = 'pnpm' (3)
    }
  }

  sourceSets {
    main { (4)
        lifecycle('pnpnm', LifecyclePnpmNodeWithPackageJson) (5)
    }
  }
}
1 A pnpm toolchain is required. See Toolchains for pnpm for more details on toolchains.
2 Create the lifecycle manager toolchain.
3 Create a source set. See Basics of configuring projects on how to configure source sets.
4 Tell Gradle that the specific source set will use pnpm and package.json.

Tasks

For the main source set, the following tasks will be added to Gradle lifecycles:

  • assemble: jseAssemble.

  • check: jseTest.

For a list of available tasks classes see Task classes]

Publishing packages

There is currently not a registered task thar will publish a package to a PNPM registry. This will probably be added in a future release. However, it is easy to implement your own by extending AbstractPnpmLifecycleTask

Running scripts in package.json

The lifecycle manager already implements tasks for handling certain scripts within the package.json file. However, for any other scripts that are not covered by a defined task, there is support for using a Gradle rule to run any script defined in the scripts block.

The format of the rule is jseRun<ScriptName><sourceSetName> or if the source set is called main it is simply jseRun<ScriptName>. If you have a script called lint you can use a task jseRunLint.