Skip to content

Commit 30197c8

Browse files
committed
Fallback to NPM when yarn fails.
1 parent 724da41 commit 30197c8

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ dump.rdb
66
logs/
77
*.iml
88
.idea/
9-
.nyc_output
9+
.nyc_output
10+
yarn.lock

scripts/install

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
var async = require('async');
17-
var path = require('path');
16+
const async = require('async');
17+
const path = require('path');
1818

1919
require('shelljs/global');
2020

2121
// Install NPM dependencies, in up to 7 directories at a time
22-
var queue = async.queue(function (directory, callback) {
23-
installForDirectory(directory, callback);
22+
const queue = async.queue((directory, cb) => {
23+
installForDirectory(directory, cb);
2424
}, 7);
2525

2626
queueDirectories('appengine');
@@ -47,16 +47,39 @@ queue.push('vision');
4747
* Install NPM dependencies within a single directory.
4848
*
4949
* @param {string} directory The name of the directory in which to install dependencies.
50-
* @param {function} callback The callback function.
50+
* @param {function} cb The callback function.
5151
*/
52-
function installForDirectory(directory, callback) {
53-
console.log(directory + '...installing dependencies');
52+
function installForDirectory (directory, cb) {
53+
console.log(`${directory}...installing dependencies`);
5454
exec('yarn install', {
5555
async: true,
5656
cwd: path.join(__dirname, '../', directory)
57-
}, function (err) {
58-
console.log(directory + '...done');
59-
callback(err);
57+
}, (err) => {
58+
if (err) {
59+
cd(directory);
60+
61+
// Uninstall dependencies
62+
console.log(`Retrying in ${directory} with NPM...`);
63+
rm('-rf', 'node_modules');
64+
65+
// Move out of the directory
66+
cd('..');
67+
exec('npm install', {
68+
async: true,
69+
cwd: path.join(__dirname, '../', directory)
70+
}, (err) => {
71+
if (err) {
72+
console.error(`Failed to install dependencies in ${directory}!`);
73+
throw err;
74+
} else {
75+
console.log(`${directory}...done`);
76+
cb();
77+
}
78+
});
79+
} else {
80+
console.log(`${directory}...done`);
81+
cb();
82+
}
6083
});
6184
}
6285

@@ -65,19 +88,17 @@ function installForDirectory(directory, callback) {
6588
*
6689
* @param {string} directory The name of the directory in which to recursively install dependencies.
6790
*/
68-
function queueDirectories(directory) {
91+
function queueDirectories (directory) {
6992
// Move into the directory
7093
cd(directory);
7194

7295
// List the files in the directory
7396
ls('-dl', '*')
74-
.filter(function (file) {
97+
.filter((file) => {
7598
// Find the directories within the directory
7699
return file.isDirectory() && file.name !== 'test' && file.name !== 'system-test';
77100
})
78-
.forEach(function (file) {
79-
queue.push(directory + '/' + file.name);
80-
});
101+
.forEach((file) => queue.push(`${directory}/${file.name}`));
81102

82103
// Move out of the directory
83104
cd('..');

0 commit comments

Comments
 (0)