Skip to content

Commit 25eab56

Browse files
stephenpluspluscallmehiphop
authored andcommitted
maintenance: add auto-updating of npm packages (#1626)
1 parent f19eba0 commit 25eab56

File tree

9 files changed

+160
-11
lines changed

9 files changed

+160
-11
lines changed

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"private": "true",
44
"devDependencies": {
55
"array-uniq": "^1.0.3",
6-
"async": "^1.4.2",
6+
"async": "^2.0.1",
77
"coveralls": "^2.11.2",
88
"create-error-class": "^3.0.2",
9+
"david": "^9.0.0",
910
"dox": "0.8.1",
1011
"extend": "^3.0.0",
1112
"glob": "^5.0.9",
1213
"globby": "^3.0.1",
14+
"is": "^3.1.0",
1315
"istanbul": "^0.3.5",
1416
"jscs": "^2.1.1",
1517
"jshint": "^2.9.1",
@@ -18,6 +20,7 @@
1820
"mitm": "^1.1.0",
1921
"mkdirp": "^0.5.1",
2022
"mocha": "^2.5.3",
23+
"package-json": "^2.4.0",
2124
"propprop": "^0.3.1",
2225
"proxyquire": "^1.7.10",
2326
"request": "^2.70.0",
@@ -28,6 +31,7 @@
2831
},
2932
"scripts": {
3033
"postinstall": "node ./scripts/install.js",
34+
"update-deps": "node ./scripts/update-deps.js",
3135
"docs": "node ./scripts/docs/packages.js",
3236
"bundle": "node ./scripts/docs/bundle.js",
3337
"lint": "jshint scripts/ packages/ system-test/ test/ && jscs packages/ system-test/ test/",

packages/bigtable/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"create-error-class": "^3.0.2",
5757
"dot-prop": "^3.0.0",
5858
"extend": "^3.0.0",
59-
"google-proto-files": "^0.7.0",
59+
"google-proto-files": "^0.8.0",
6060
"is": "^3.0.1",
6161
"lodash.flatten": "^4.2.0",
6262
"node-int64": "^0.4.0",

packages/common/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"ent": "^2.2.0",
4848
"extend": "^3.0.0",
4949
"google-auto-auth": "^0.2.4",
50-
"google-proto-files": "^0.7.0",
50+
"google-proto-files": "^0.8.0",
5151
"grpc": "^1.0.0",
5252
"is": "^3.0.1",
5353
"methmeth": "^1.0.0",

packages/compute/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
"dependencies": {
5353
"@google-cloud/common": "^0.5.0",
5454
"arrify": "^1.0.0",
55-
"async": "^1.4.2",
56-
"create-error-class": "^2.0.1",
55+
"async": "^2.0.1",
56+
"create-error-class": "^3.0.2",
5757
"extend": "^3.0.0",
5858
"gce-images": "^0.3.0",
5959
"is": "^3.0.1",

packages/logging/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"arrify": "^1.0.0",
5858
"extend": "^3.0.0",
5959
"google-gax": "^0.6.0",
60-
"google-proto-files": "^0.7.0",
60+
"google-proto-files": "^0.8.0",
6161
"is": "^3.0.1",
6262
"string-format-obj": "^1.0.0"
6363
},

packages/speech/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@google-cloud/common": "^0.5.0",
5858
"events-intercept": "^2.0.0",
5959
"extend": "^3.0.0",
60-
"google-proto-files": "^0.7.0",
60+
"google-proto-files": "^0.8.0",
6161
"is": "^3.1.0",
6262
"modelo": "^4.2.0",
6363
"propprop": "^0.3.1",

packages/storage/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
"dependencies": {
5353
"@google-cloud/common": "^0.5.0",
5454
"arrify": "^1.0.0",
55-
"async": "^1.4.2",
55+
"async": "^2.0.1",
5656
"concat-stream": "^1.5.0",
57-
"create-error-class": "^2.0.1",
57+
"create-error-class": "^3.0.2",
5858
"duplexify": "^3.2.0",
5959
"extend": "^3.0.0",
6060
"gcs-resumable-upload": "^0.7.1",

packages/vision/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
"@google-cloud/common": "^0.5.0",
5454
"arguejs": "^0.2.3",
5555
"arrify": "^1.0.0",
56-
"async": "^1.4.2",
56+
"async": "^2.0.1",
5757
"extend": "^3.0.0",
5858
"google-gax": "^0.6.0",
59-
"google-proto-files": "^0.7.0",
59+
"google-proto-files": "^0.8.0",
6060
"is": "^3.0.1",
6161
"propprop": "^0.3.0",
6262
"request": "^2.70.0",

scripts/update-deps.js

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*!
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var async = require('async');
20+
var david = require('david');
21+
var glob = require('globby');
22+
var is = require('is');
23+
var packageJson = require('package-json');
24+
var path = require('path');
25+
var semver = require('semver');
26+
27+
require('shelljs/global');
28+
29+
/*! Developer Documentation
30+
*
31+
* This file will dig through all of the sub-module's package.json's, check for
32+
* any compatible updates, and run `npm install` to update them.
33+
*/
34+
35+
/**
36+
* Dependencies not to update.
37+
*
38+
* @type {string[]}
39+
*/
40+
var BLACKLIST = [
41+
'dns-zonefile'
42+
];
43+
44+
/**
45+
* The minimum version of Node that we support. This is compared against each
46+
* depdendency's package.json.engines.node to confirm the newest version is
47+
* compatible.
48+
*
49+
* @const {string}
50+
*/
51+
var MIN_SUPPORTED_NODE_VERSION =
52+
require('../package.json').engines.node.replace(/^\D*/, '');
53+
54+
var pkgs = glob.sync('packages/*/package.json')
55+
.map(function(packageJsonPath) {
56+
return {
57+
cwd: path.dirname(packageJsonPath),
58+
json: require(path.join('..', packageJsonPath)),
59+
depsToUpdate: [] // Updated in `populateDepsToUpdate`
60+
};
61+
});
62+
63+
async.eachLimit(pkgs, 5, populateDepsToUpdate, function(err) {
64+
if (err) {
65+
console.error('Could not update dependencies', err);
66+
return;
67+
}
68+
69+
async.eachLimit(pkgs, 5, updatePackage, function(err) {
70+
if (err) {
71+
console.error('Could not update dependencies', err);
72+
return;
73+
}
74+
75+
console.log('Dependencies updated!');
76+
});
77+
});
78+
79+
function updatePackage(pkg, callback) {
80+
if (!is.empty(pkg.depsToUpdate)) {
81+
var updatedDeps = pkg.depsToUpdate.map(function(depToUpdate) {
82+
return depToUpdate.name + '@^' + depToUpdate.stable;
83+
});
84+
85+
exec('npm install --save ' + updatedDeps.join(' '), {
86+
cwd: pkg.cwd
87+
});
88+
}
89+
90+
callback();
91+
}
92+
93+
function shouldUpdateDep(dependency, callback) {
94+
if (BLACKLIST.indexOf(dependency.name) > -1) {
95+
setImmediate(function() {
96+
callback(null, false);
97+
});
98+
return;
99+
}
100+
101+
packageJson(dependency.name, dependency.stable).then(function(json) {
102+
var minCompatibleNodeVersion = json.engines && json.engines.node;
103+
104+
if (!minCompatibleNodeVersion) {
105+
callback(null, true);
106+
return;
107+
}
108+
109+
var isCompatible = semver.satisfies(
110+
MIN_SUPPORTED_NODE_VERSION,
111+
minCompatibleNodeVersion
112+
);
113+
114+
callback(null, isCompatible);
115+
});
116+
}
117+
118+
function populateDepsToUpdate(pkg, callback) {
119+
david.getUpdatedDependencies(pkg.json, function(err, updatedDeps) {
120+
if (err) {
121+
callback(err);
122+
return;
123+
}
124+
125+
if (is.empty(updatedDeps)) {
126+
callback();
127+
return;
128+
}
129+
130+
for (var updatedDep in updatedDeps) {
131+
updatedDeps[updatedDep].name = updatedDep;
132+
}
133+
134+
async.filter(updatedDeps, shouldUpdateDep, function(err, depsToUpdate) {
135+
if (err) {
136+
callback(err);
137+
return;
138+
}
139+
140+
pkg.depsToUpdate = depsToUpdate;
141+
142+
callback();
143+
});
144+
});
145+
}

0 commit comments

Comments
 (0)