Skip to content

maintenance: add auto-updating of npm packages #1626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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/",
Expand Down
2 changes: 1 addition & 1 deletion packages/bigtable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/compute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/logging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/speech/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/vision/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
145 changes: 145 additions & 0 deletions scripts/update-deps.js
Original file line number Diff line number Diff line change
@@ -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');

This comment was marked as spam.

This comment was marked as spam.

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();
});
});
}