An installer package that let's you install NodeJS and NPM as a Composer dependency.

Overview

Latest Stable Version Latest Unstable Version License Scrutinizer Code Quality

NodeJS installer for Composer

This is an installer that will download NodeJS and NPM and install them in your Composer dependencies. Installation is skipped if NodeJS is already available on your machine.

Why?

NodeJS is increasingly becoming a part of the tool-chain of modern web developers. Tools like Bower, Grunt, Gulp... are used everyday to build applications. For the PHP developer, this means PHP projects have build dependencies on NodeJS or Bower / NPM packages. The NodeJS-installer attempts to bridge the gap between NodeJS and PHP by making NodeJS easily installable as a Composer dependency.

Building on this package, other packages like koala-framework/composer-extra-assets can be used to automatically fetch Bower / NPM packages, run Gulp / Grunt tasks, etc...

How does it work?

Simply include this package in your composer.json requirements:

{
    "require": {
        "mouf/nodejs-installer": "~1.0"
    }
}

By default, if NodeJS is not available on your computer, it will be downloaded and installed in vendor/nodejs/nodejs.

You should access NodeJS and NPM using the scripts created into the vendor/bin directory:

  • vendor/bin/node (vendor/bin/node.bat on Windows)
  • vendor/bin/npm (vendor/bin/npm.bat on Windows)

Options

A number of options are available to customize NodeJS installation:

{
    "require": {
        "mouf/nodejs-installer": "~1.0"
    },
    "extra": {
        "mouf": {
            "nodejs": {
                "version": "~0.12",
                "targetDir": "vendor/nodejs/nodejs",
                "forceLocal": false
            }
        }
    }
}

Available options:

  • version: This is the version number of NodeJS that will be downloaded and installed. You can specify version constraints in the usual Composer format (for instance "~0.12" or ">0.11").
    Default value: * The latest stable version of NodeJS is installed by default.
  • targetDir: The target directory NodeJS will be installed in. Relative to project root.
    This option is only available in the root package.
    Default value: vendor/nodejs/nodejs
  • forceLocal (boolean): If set to true, NodeJS will always be downloaded and installed locally, even if NodeJS is already available on your computer.
    This option is only available in the root package.
    Default value: false
  • includeBinInPath (boolean): After the plugin is run in Composer, the vendor/bin directory can optionally be added to the PATH. This is useful if other plugins rely on "node" or "npm" being available globally on the computer. Using this option, these other plugins will automatically find the node/npm version that has been downloaded. Please note that the PATH is only set for the duration of the Composer script. Your global environment is not impacted by this option.
    This option is only available in the root package.
    Default value: false

Custom script

The installer listens to the following composer scripts to be launched:

{
    "post-install-cmd": {
        // ...
    },
    "post-update-cmd": {
        // ...
    }
}

If you need to launch the installer manually, you can run the following command:

$ composer run-script download-nodejs
Comments
  • Not work on Windows

    Not work on Windows

    Hi!

    I have a problem with wrapper script - it not works correctly on my WAMP:

    C:\OpenServer\domains\aviashelf\vendor\koala-framework\kwf-modernizr>C:\OpenServer\domains\aviashelf/vendor/bin/npm install
    "install" is not an internal or external
    command, operable program or batch file.
    

    Node.JS and NPM installed globally.

    More info here: https://github.com/koala-framework/koala-framework/issues/327

    opened by Sogl 9
  • nodejs-installer fails on arm (Raspberry pi)

    nodejs-installer fails on arm (Raspberry pi)

    nodejs-installer doesn't work on by raspberry pi

    $ uname -a
    Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux
    

    it tires to download x86 binaries:

    Installing NodeJS v0.12.7
      Downloading from http://nodejs.org/dist/v0.12.7/node-v0.12.7-linux-x86.tar.gz
        Downloading: 100%         
    

    but those obviously won't work:

    $ ./vendor/nodejs/nodejs/bin/node 
    -bash: ./node: Kann die Datei nicht ausführen.
    
    opened by kaufmo 4
  • Fix relative path in bin script on windows

    Fix relative path in bin script on windows

    Fixes issue with realpath() returning upper case drive letter, with that creation of relative path doesn't work correctly.

    Use realpath also for $binDir to have both in the same casing.

    Fixes also possible problem when realpath for $targetDir resolves symlinks.

    opened by nsams 4
  • Not working on Windows anymore

    Not working on Windows anymore

            "mouf": {
                "nodejs": {
                    "version": "8.10.0",
                    "forceLocal": false
                }
            }
    
    npm WARN engine [email protected]: wanted: {"node":">=10"} (current: {"node":"v8.10.0","npm":"1.4.12"})
    ...
    npm ERR! node -v v8.10.0
    npm ERR! npm -v 1.4.12
    npm ERR! code E405
    npm ERR!
    npm ERR! not ok code 0
    
                                                               
      [Mouf\NodeJsInstaller\NodeJsInstallerException]          
      An error occurred while updating NPM to latest version. 
    

    It seems that when calling the update on npm it tries to update to a version that requires a higer version than the one installed. node version needed: v8.10.0 npm tries to update to 7.0.6 wich requires node >=10

    https://github.com/thecodingmachine/nodejs-installer/blob/4ffc71c79e013fbf34fc0a4331d24649343f928f/src/NodeJsInstaller.php#L251

    opened by delmicio 3
  • fix when composer bin dir is in path

    fix when composer bin dir is in path

    thanks a lot for this installer, this just saved us from building a custom cloudfoundry buildpack!

    we noticed two problems that this PR fixes:

    • When the bin-dir of composer is configured to somewhere else than vendor/bin, the local installation is not found
    • When the composer bin directory is in $PATH, the local installation is considered global, leading to write a script that endlessly calls itself.
    opened by dbu 3
  • NodeJS v4.0.0 fails using Vagrant (Linux)

    NodeJS v4.0.0 fails using Vagrant (Linux)

    After experiencing issue #20 I tried on a Vagrant box I have set up but had issues extracting the package with TAR. The following was my output:

    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Nothing to install or update
    Generating autoload files
    Installing NodeJS v4.0.0
      Downloading from https://nodejs.org/dist/v4.0.0/node-v4.0.0-linux-x64.tar.gz
        Downloading: Connecting...
        Downloading: 0%           
        Downloading: 100%
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property: Cannot mkdir: Protocol error
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property: Cannot mkdir: Protocol error
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property/is-property.js: Cannot open: No such file or directory
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property: Cannot mkdir: Protocol error
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property/package.json: Cannot open: No such file or directory
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property: Cannot mkdir: Protocol error
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property/LICENSE: Cannot open: No such file or directory
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property: Cannot mkdir: Protocol error
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property/README.md: Cannot open: No such file or directory
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property: Cannot mkdir: Protocol error
    tar: lib/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/node_modules/is-property/.npmignore: Cannot open: No such file or directory
    tar: bin/npm: Cannot create symlink to ‘../lib/node_modules/npm/bin/npm-cli.js’: Protocol error
    tar: Exiting with failure status due to previous errors
    
    
    
      [Mouf\NodeJsInstaller\NodeJsInstallerException]                              
      An error occurred while untaring NodeJS (vendor/node-v4.0.0-linux-x64.tar.g  
      z) to vendor/nodejs/nodejs                         
    
    opened by jakejackson1 3
  • Detection of local nodejs by priority

    Detection of local nodejs by priority

    In my enviroment I have /usr/bin/node and /usr/local/bin/node

    The current code for this project search first for /usr/bin/node when I think it should give preference to /usr/local/bin/node

    opened by rodrigoaguilera 2
  • Alias packages can now be used

    Alias packages can now be used

    Hi everyone.

    A quick fix. The problem was the banch alias. In my case, I have a symfony application, and the composer.json contains a banch alias :

    {
        ...
        "extra": {
            "symfony-app-dir": "app",
            "symfony-web-dir": "web",
            "symfony-assets-install": "relative",
            "mouf": {
                "nodejs": {
                    "version": ">4.0",
                    "forceLocal": true
                }
            }
        }
    

    In that case, the instance of package returns by composer is a RootAliasPackage wrapper, so I've just unwrapped the package.

    opened by PedroTroller 2
  • NodeJS v4.0.0 Install fails on Windows

    NodeJS v4.0.0 Install fails on Windows

    Hi,

    Just trying to get this composer package functioning correctly. My composer file has the following:

        "require-dev": {
            "mouf/nodejs-installer": "~1.0",
            "koala-framework/composer-extra-assets": "~1.1"
        },
    

    And when I run composer update I get the following error:

    Installing NodeJS v4.0.0
       Downloading from https://nodejs/org/dist/v4.0.0/node.exe
          Downloading: Connecting....
    
      [Composer\Downloader\TransportException]
      The "https://nodejs/org/dist/v4.0.0/node.exe" file could not be downloaded
       (HTTP/1.1 404 Not Found)
    

    Any help would be appreciated.

    opened by jakejackson1 2
  • broken vendor/bin/npm if node is installed globally but without npm

    broken vendor/bin/npm if node is installed globally but without npm

    This happened to me on archlinux where npm is an optional package. (I think also for debian)

    Possible options:

    • install node+npm locally
    • fail with an error (telling the user that he has to install npm)
    • generate only vendor/bin/node and no /vendor/bin/npm

    The last option should be configurable as composer-extra-assets will always require npm.

    opened by nsams 2
  • NPM seems to fail on Windows with no NodeJS install

    NPM seems to fail on Windows with no NodeJS install

    I'm on Windows, no NodeJS install. I'm using koala composer asset extra. NPM fails when launched by Koala. However, it does work if Node/NPM are installed globally.

    opened by xhuberty 2
  • Add context options for requests in composer extra configuration.

    Add context options for requests in composer extra configuration.

    I work in an org that intercepts SSL requests and I unfortunately require special context values for many requests. Because the composer RemoteFilesystem object is not using a curl object, which can be controlled with a global curlrc file, the only way to get things to work is to pass in certain context options. I specifically need SSL context options for the internal SSL cert that is being used.

    opened by granville-dev 0
  • Added --no-same-owner flag when extracting the NodeJs archive

    Added --no-same-owner flag when extracting the NodeJs archive

    Added --no-same-owner flag when extracting the NodeJs archive, so that it can behaves as expected when composer runs as root.

    Rationale

    When tar extracts an archive as root, it attempts to set the owner UID/GID of the extracted files to the UID/GID, which is for the NodeJS archives is 500.

    For the NodeJS iInstaller, this behaviour is not desirable, as it results in the extracted files being owned by a different user than the user that runs composer commands. It can even result in the failure to extract.

    Although normally composer shouldn't be run as root, this is not necessarily true for applications that run in containers, such as Docker containers.

    Solution

    Add the --no-same-owner flag to the tar command, so that it will behave identical regardless of whether composer runs as root or as a normal user.

    For reference, see https://linux.die.net/man/1/tar

    opened by driq 1
  • Detect aarch64 for Arm Platform

    Detect aarch64 for Arm Platform

    I'd like to say a big thank you for your software. This pull request will detect aarch64 for Arm Platform.

    (nodejs-installer v1.0.14 doesn't detect aarch64.)

    $ php -r 'print php_uname("m")."\n";'
    aarch64
    
    opened by matsuo 0
  • Feature Request: Install for other OS

    Feature Request: Install for other OS

    Hello,

    I would like to request that we be able to install a version of Node for an architecture other than the one on which the Composer script is currently running. For example, I would like to be able to install the Linux version of Node even when running the Composer install on Mac OS.

    This is useful in situations where the logical host on which the PHP app will be running is different than the platform on which the build process occurs. Think, for example, a dev environment where composer is executed on a physical MacOS host, but the PHP app is running inside of a Vagrant machine running Linux.

    enhancement 
    opened by bradharms 1
  • tar: bin/npx: Cannot utime: Operation not permitted

    tar: bin/npx: Cannot utime: Operation not permitted

    Hi, I'm getting this error when using composer install:

    Installing NodeJS v8.10.0                                                                                                                                                                               
      Downloading from https://nodejs.org/dist/v8.10.0/node-v8.10.0-linux-x64.tar.gz                                                                                                                        
    Downloading (100%)tar: bin/npx: Cannot utime: Operation not permitted                                                                                                                                   
    tar: bin/npm: Cannot utime: Operation not permitted                                                                                                                                                     
    tar: Exiting with failure status due to previous errors                                                                                                                                                 
                                                                                                                                                                                                            
                                                                                                                                                                                                            
      [Mouf\NodeJsInstaller\NodeJsInstallerException]                                                                                                                                                       
      An error occurred while untaring NodeJS (vendor/node-v8.10.0-linux-x64.tar.gz) to vendor/nodejs/nodejs
    

    I'm using this config:

    "mouf": {
                "nodejs": {
                    "version": "8.10.0",
                    "forceLocal": true
                }
            }
    

    BTW it was working when using root user but now I'm using a non roor user.

    opened by delmicio 6
  • Fail for alpine linux

    Fail for alpine linux

    Since there is no compiled packages that support musl intead of gcc this package is trying to download binaries that can't be executed giving messages that are not very useful like:

    node: No such file or directory
    

    Is it possible to detect this in the environment and fail with a message in this case?

    opened by rodrigoaguilera 0
Releases(v1.0.14)
Owner
TheCodingMachine
TheCodingMachine
Textpattern-installer - Textpattern plugin and theme installer for Composer

Textpattern Installer for Composer Package directory | Issues Install plugins and themes to Textpattern CMS with Composer. $ composer require rah/rah_

Jukka Svahn 7 Apr 14, 2022
A fast, reliable, and secure NPM/Yarn bridge for Composer

Foxy is a Composer plugin to automate the validation, installation, updating and removing of PHP libraries asset dependencies (javaScript, stylesheets

Fxp 160 Dec 2, 2022
A composer plugin, to install differenty types of composer packages in custom directories outside the default composer default installation path which is in the vendor folder.

composer-custom-directory-installer A composer plugin, to install differenty types of composer packages in custom directories outside the default comp

Mina Nabil Sami 136 Dec 30, 2022
Dependency graph visualization for composer.json (PHP + Composer)

clue/graph-composer Graph visualization for your project's composer.json and its dependencies: Table of contents Usage graph-composer show graph-compo

Christian Lück 797 Jan 5, 2023
Ip2region is a offline IP location library with accuracy rate of 99.9% and 0.0x millseconds searching performance. DB file is ONLY a few megabytes with all IP address stored. binding for Java,PHP,C,Python,Nodejs,Golang,C#,lua. Binary,B-tree,Memory searching algorithm

Ip2region是什么? ip2region - 准确率99.9%的离线IP地址定位库,0.0x毫秒级查询,ip2region.db数据库只有数MB,提供了java,php,c,python,nodejs,golang,c#等查询绑定和Binary,B树,内存三种查询算法。 Ip2region特性

Lion 12.6k Dec 30, 2022
Composer installer for PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

Dealerdirect 462 Dec 22, 2022
This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

PHPCSStandards 393 Feb 25, 2022
This module adds a command to easily generate "modules" in Laravel and install them using composer.

Laravel Module Create This module adds a command to easily generate "modules" in Laravel and install them using composer Installation Simply install t

null 2 Feb 18, 2022
A small CLI tool to check missing dependency declarations in the composer.json and module.xml

Integrity checker Package allows to run static analysis on Magento 2 Module Packages to provide an integrity check of package. Supported tools: Compos

run_as_root GmbH 13 Dec 19, 2022
LendCash is a cash lending service that lets you take loans against your stocks portfolio value and pay back on a prorated basis.

LendCash is a cash lending service that lets you take loans against your stocks portfolio value and pay back on a prorated basis.

Teniola Fatunmbi 2 Aug 22, 2022
Composer registry manager that help to easily switch to the composer repository you want

CRM - Composer Registry Manager Composer Registry Manager can help you easily and quickly switch between different composer repositories. 简体中文 Install

Tao 500 Dec 29, 2022
An open source tool that lets you create a SaaS website from docker images in 10 minutes.

简体中文 Screenshots for members ( who subscribe the plan ) for admin ⚠️ This document was translated into English by deepl and can be improved by PR An o

Easy 669 Jan 5, 2023
This simple code lets you to get how many % of this year had passed

Year-Percent-PHP This simple code lets you to get how many % of this year had passed Code is part of Telegram bot and was made for Telegram channel Ye

Puzzak 1 Jan 3, 2022
A PocketMine-MP plugin that lets you teleport among offline players

OfflinePlayerTP A PocketMine-MP plugin that lets you teleport among offline players. Commands Command Description /otp <player> Teleport to (offline)

Muqsit Rayyan 8 Sep 23, 2022
This Pocketmine-MP plugin lets you implement the ultimate birthday wishing system on your server.

BirthdaysPE This Pocketmine-MP plugin will let you wish player(s) a happy birthday and notify others to wish them too. Commands /birthday <set/reset>

MCA7 3 Jul 25, 2022
Laravel Larex lets you translate your whole Laravel application with a single CSV file.

Laravel Larex Laravel Larex lets you translate your whole Laravel application with a single CSV file. You can import translation entries from lang fol

Luca Patera 68 Dec 12, 2022