diff --git a/package.json b/package.json index 23556f62f19..8a36a9edc9e 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,15 @@ "private": "true", "devDependencies": { "array-uniq": "^1.0.3", - "async": "^1.4.2", + "async": "^2.0.1", "coveralls": "^2.11.2", "create-error-class": "^3.0.2", + "david": "^9.0.0", "dox": "0.8.1", "extend": "^3.0.0", "glob": "^5.0.9", "globby": "^3.0.1", + "is": "^3.1.0", "istanbul": "^0.3.5", "jscs": "^2.1.1", "jshint": "^2.9.1", @@ -18,6 +20,7 @@ "mitm": "^1.1.0", "mkdirp": "^0.5.1", "mocha": "^2.5.3", + "package-json": "^2.4.0", "propprop": "^0.3.1", "proxyquire": "^1.7.10", "request": "^2.70.0", @@ -28,6 +31,7 @@ }, "scripts": { "postinstall": "node ./scripts/install.js", + "update-deps": "node ./scripts/update-deps.js", "docs": "node ./scripts/docs/packages.js", "bundle": "node ./scripts/docs/bundle.js", "lint": "jshint scripts/ packages/ system-test/ test/ && jscs packages/ system-test/ test/", diff --git a/packages/bigtable/package.json b/packages/bigtable/package.json index 9d1eb93478b..28b4ac6abbe 100644 --- a/packages/bigtable/package.json +++ b/packages/bigtable/package.json @@ -56,7 +56,7 @@ "create-error-class": "^3.0.2", "dot-prop": "^3.0.0", "extend": "^3.0.0", - "google-proto-files": "^0.7.0", + "google-proto-files": "^0.8.0", "is": "^3.0.1", "lodash.flatten": "^4.2.0", "node-int64": "^0.4.0", diff --git a/packages/common/package.json b/packages/common/package.json index fffd5c7f828..822802ad0ff 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -47,7 +47,7 @@ "ent": "^2.2.0", "extend": "^3.0.0", "google-auto-auth": "^0.2.4", - "google-proto-files": "^0.7.0", + "google-proto-files": "^0.8.0", "grpc": "^1.0.0", "is": "^3.0.1", "methmeth": "^1.0.0", diff --git a/packages/compute/package.json b/packages/compute/package.json index bfbc21288c7..c84fe8f8fdb 100644 --- a/packages/compute/package.json +++ b/packages/compute/package.json @@ -52,8 +52,8 @@ "dependencies": { "@google-cloud/common": "^0.5.0", "arrify": "^1.0.0", - "async": "^1.4.2", - "create-error-class": "^2.0.1", + "async": "^2.0.1", + "create-error-class": "^3.0.2", "extend": "^3.0.0", "gce-images": "^0.3.0", "is": "^3.0.1", diff --git a/packages/logging/package.json b/packages/logging/package.json index 2137fcc173e..2f2dd738815 100644 --- a/packages/logging/package.json +++ b/packages/logging/package.json @@ -57,7 +57,7 @@ "arrify": "^1.0.0", "extend": "^3.0.0", "google-gax": "^0.6.0", - "google-proto-files": "^0.7.0", + "google-proto-files": "^0.8.0", "is": "^3.0.1", "string-format-obj": "^1.0.0" }, diff --git a/packages/speech/package.json b/packages/speech/package.json index c6b29efe1dd..d423b8316fc 100644 --- a/packages/speech/package.json +++ b/packages/speech/package.json @@ -57,7 +57,7 @@ "@google-cloud/common": "^0.5.0", "events-intercept": "^2.0.0", "extend": "^3.0.0", - "google-proto-files": "^0.7.0", + "google-proto-files": "^0.8.0", "is": "^3.1.0", "modelo": "^4.2.0", "propprop": "^0.3.1", diff --git a/packages/storage/package.json b/packages/storage/package.json index 425b7c814c3..692681e972e 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -52,9 +52,9 @@ "dependencies": { "@google-cloud/common": "^0.5.0", "arrify": "^1.0.0", - "async": "^1.4.2", + "async": "^2.0.1", "concat-stream": "^1.5.0", - "create-error-class": "^2.0.1", + "create-error-class": "^3.0.2", "duplexify": "^3.2.0", "extend": "^3.0.0", "gcs-resumable-upload": "^0.7.1", diff --git a/packages/vision/package.json b/packages/vision/package.json index 07f457bf0b8..1cec6800c7d 100644 --- a/packages/vision/package.json +++ b/packages/vision/package.json @@ -53,10 +53,10 @@ "@google-cloud/common": "^0.5.0", "arguejs": "^0.2.3", "arrify": "^1.0.0", - "async": "^1.4.2", + "async": "^2.0.1", "extend": "^3.0.0", "google-gax": "^0.6.0", - "google-proto-files": "^0.7.0", + "google-proto-files": "^0.8.0", "is": "^3.0.1", "propprop": "^0.3.0", "request": "^2.70.0", diff --git a/scripts/update-deps.js b/scripts/update-deps.js new file mode 100644 index 00000000000..f93d75f8c1b --- /dev/null +++ b/scripts/update-deps.js @@ -0,0 +1,145 @@ +/*! + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +var async = require('async'); +var david = require('david'); +var glob = require('globby'); +var is = require('is'); +var packageJson = require('package-json'); +var path = require('path'); +var semver = require('semver'); + +require('shelljs/global'); + +/*! Developer Documentation + * + * This file will dig through all of the sub-module's package.json's, check for + * any compatible updates, and run `npm install` to update them. + */ + +/** + * Dependencies not to update. + * + * @type {string[]} + */ +var BLACKLIST = [ + 'dns-zonefile' +]; + +/** + * The minimum version of Node that we support. This is compared against each + * depdendency's package.json.engines.node to confirm the newest version is + * compatible. + * + * @const {string} + */ +var MIN_SUPPORTED_NODE_VERSION = + require('../package.json').engines.node.replace(/^\D*/, ''); + +var pkgs = glob.sync('packages/*/package.json') + .map(function(packageJsonPath) { + return { + cwd: path.dirname(packageJsonPath), + json: require(path.join('..', packageJsonPath)), + depsToUpdate: [] // Updated in `populateDepsToUpdate` + }; + }); + +async.eachLimit(pkgs, 5, populateDepsToUpdate, function(err) { + if (err) { + console.error('Could not update dependencies', err); + return; + } + + async.eachLimit(pkgs, 5, updatePackage, function(err) { + if (err) { + console.error('Could not update dependencies', err); + return; + } + + console.log('Dependencies updated!'); + }); +}); + +function updatePackage(pkg, callback) { + if (!is.empty(pkg.depsToUpdate)) { + var updatedDeps = pkg.depsToUpdate.map(function(depToUpdate) { + return depToUpdate.name + '@^' + depToUpdate.stable; + }); + + exec('npm install --save ' + updatedDeps.join(' '), { + cwd: pkg.cwd + }); + } + + callback(); +} + +function shouldUpdateDep(dependency, callback) { + if (BLACKLIST.indexOf(dependency.name) > -1) { + setImmediate(function() { + callback(null, false); + }); + return; + } + + packageJson(dependency.name, dependency.stable).then(function(json) { + var minCompatibleNodeVersion = json.engines && json.engines.node; + + if (!minCompatibleNodeVersion) { + callback(null, true); + return; + } + + var isCompatible = semver.satisfies( + MIN_SUPPORTED_NODE_VERSION, + minCompatibleNodeVersion + ); + + callback(null, isCompatible); + }); +} + +function populateDepsToUpdate(pkg, callback) { + david.getUpdatedDependencies(pkg.json, function(err, updatedDeps) { + if (err) { + callback(err); + return; + } + + if (is.empty(updatedDeps)) { + callback(); + return; + } + + for (var updatedDep in updatedDeps) { + updatedDeps[updatedDep].name = updatedDep; + } + + async.filter(updatedDeps, shouldUpdateDep, function(err, depsToUpdate) { + if (err) { + callback(err); + return; + } + + pkg.depsToUpdate = depsToUpdate; + + callback(); + }); + }); +}