From 41027e3f8e726bbc2d90e8449db639aef0dec0f8 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 24 Mar 2020 01:04:43 +0000 Subject: [PATCH] Build/Test Tools: Introduce Install-changed. It keeps a hash of `package.json` and compares it when run. If it has any changes, it runs `npm install`. This keeps `node_modules` always updated and is useful not only when the packages have been updated, but also when the working copy has been "reverted" to an earlier revision. Fixes #49594. git-svn-id: https://develop.svn.wordpress.org/trunk@47497 602fd350-edb4-49c9-b593-d223f7449a82 --- .gitignore | 1 + Gruntfile.js | 4 ++++ package-lock.json | 6 ++++++ package.json | 1 + 4 files changed, 12 insertions(+) diff --git a/.gitignore b/.gitignore index 2f4d4eb9d2..01757f7a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ wp-tests-config.php /src/wp-includes/css/dist /src/wp-includes/css/*.min.css /src/wp-includes/css/*-rtl.css +/packagehash.txt # Files and folders that get created in wp-content /src/wp-content/blogs.dir diff --git a/Gruntfile.js b/Gruntfile.js index a490af6b4b..cb263c8bd8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,6 +2,7 @@ /* jshint esversion: 6 */ /* globals Set */ var webpackConfig = require( './webpack.config' ); +var installChanged = require( 'install-changed' ); module.exports = function(grunt) { var path = require('path'), @@ -41,6 +42,9 @@ module.exports = function(grunt) { ); } + // First do `npm install` if package.json has changed. + installChanged.watchPackage(); + // Load tasks. require('matchdep').filterDev(['grunt-*', '!grunt-legacy-util']).forEach( grunt.loadNpmTasks ); // Load legacy utils. diff --git a/package-lock.json b/package-lock.json index f5d5ef6880..f575ae788e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11784,6 +11784,12 @@ } } }, + "install-changed": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/install-changed/-/install-changed-1.1.0.tgz", + "integrity": "sha512-APUWMdQnwGcyv9bmuvgxCcrR6qtD996+hofEEAPGSjsvGIZuBpBF0yrYAKOl9tmhm2AzxJC4EXUbxZ/SId4NIA==", + "dev": true + }, "internal-ip": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/internal-ip/-/internal-ip-4.3.0.tgz", diff --git a/package.json b/package.json index 4913df6ac8..f7156cd3c1 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "grunt-sass": "~3.1.0", "grunt-webpack": "^3.1.3", "ink-docstrap": "1.3.2", + "install-changed": "1.1.0", "jquery-migrate": "1.4.1", "matchdep": "~2.0.0", "node-sass": "~4.13.1",