pantheon-se/node-composer

Installs Node.js, NPM, and Yarn into vendor/bin

Installs: 3 325

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 9

Forks: 0

Type:composer-plugin

v2.1.6 2023-07-12 20:55 UTC

README

License Packagist Version Tests

Node Composer

Composer Plugin to implement asset compilation via Composer with Node.js.

Based on node-composer by mariusbuescher, this Composer plugin will install Node.js, NPM, and/or Yarn into your vendor/bin directory so that they are available to use during your Composer builds. This plugin helps automate the download of the binaries which are linked to the bin-directory specified in your composer.json.

Once installed, you can then use Node, NPM, and Yarn commands in your composer-scripts.

Setup

Simply install the plugin, and the latest Node.js LTS with NPM will be installed - no other configurations are necessary. Optionally, you can specify the node-version in your composer.json extra configs to declare a specific version of Node.js. For Yarn, yarn-version can either be set to true to install the latest, or can be set to a specific version.

Example composer.json with Yarn

{
  "name": "my/project",
  "type": "project",
  "license": "MIT",
  "require": {
    "pantheon-se/node-composer": "*"
  },
  "extra": {
    "pantheon-se": {
      "node-composer": {
        "yarn-version": true
      }
    }
  },
  "config": {
    "allow-plugins": {
      "pantheon-se/node-composer": true
    }
  },
  "scripts": {
    "post-install-cmd": ["@build"],
    "post-update-cmd": ["@build"],
    "build": "cd web/themes/my_theme && yarn build"
  }
}

Configuration

There are three parameters you can configure:

  • Node version (node-version)
  • Yarn version (yarn-version)
  • The download url template for the Node.js binary archives (node-download-url).

In the Node download url, replace the following placeholders with your specific needs:

  • version: ${version}
  • type of your os: ${osType}
  • system architecture: ${architecture}
  • file format ${format}

Example composer.json with specific versions of Node and Yarn

{
  "extra": {
    "pantheon-se": {
      "node-composer": {
        "node-version": "16.14.0",
        "yarn-version": "1.22.18",
        "node-download-url": "https://nodejs.org/dist/v${version}/node-v${version}-${osType}-${architecture}.${format}"
      }
    }
  }
}