Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

NPM: Difference between revisions

From MoodleDocs
No edit summary
Line 21: Line 21:


==== Switching NPM versions ====
==== Switching NPM versions ====
We have discovered upstream npm bugs  (MDL-59103) when upgrading NPM version with a previously installed node_modules directory. It is recommended to clear the node_modules directory and re-installing when changing npm version to avoid these problems.
We have discovered upstream npm bugs  (MDL-59103) when upgrading NPM version with a previously installed node_modules directory. It is recommended to clear the node_modules directory and re-running `npm install` when changing npm version to avoid these problems.

Revision as of 09:04, 1 June 2017

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.

NPM is a package manager for JavaScript. It is used by Moodle developers to install a number of cli tools, primarily those related with Grunt.

npm dependency management

Tools installed by npm include things like our css/js compressors, post-processors and integrity checks. As differences in output from these tools would cause different results for different developers working on the same code, we need to ensure installed packages are the same.

npm shrinkwrap

We use a npm-shrinkwrap.json to ensure that all versions of packages are consistent for developers when they run `npm install`. See https://docs.npmjs.com/files/package-locks for further details on this mechanism. Note: The npm package lock mechanics changed significantly in NPM version 5.

Updating npm dependencies

Periodically we will update our npm dependencies, the process for doing this is:

  1. Ensure you use npm >= 5 - node version 8 (see MDL-59094 for details of why we require this version)
  2. Run
    npm install packages-name@version
    (e.g.
    npm install eslint@3.8.0
    )
  3. Verify that both the package.json and npm-shrinkwrap.json have been updated
  4. Commit to source control

NPM versions

In general, you will get the best results when using the latest stable NPM version for install node dependencies with Moodle.

Switching NPM versions

We have discovered upstream npm bugs (MDL-59103) when upgrading NPM version with a previously installed node_modules directory. It is recommended to clear the node_modules directory and re-running `npm install` when changing npm version to avoid these problems.