Skip to content

Commit

Permalink
Remove direct npm dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Nov 18, 2016
1 parent e0d3691 commit cbb1491
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
25 changes: 18 additions & 7 deletions lib/system/runner/initialize.js
Expand Up @@ -9,7 +9,6 @@ const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const Promise = require('bluebird');
const npm = require('npm');

const _ = require('lodash');
const log4js = require('log4js');
Expand Down Expand Up @@ -146,8 +145,9 @@ function getAppName(app) {
// Check list of applications, if application is
// missed - try to install it via npm.
//
const installAppsIfMissed = Promise.coroutine(function* (apps) {
let appName, appNpmPath;
const installAppsIfMissed = Promise.coroutine(function* (N, apps) {
let appName, appNpmPath,
missed = [];

for (let app of apps) {
if (_.isPlainObject(app)) {
Expand All @@ -160,11 +160,22 @@ const installAppsIfMissed = Promise.coroutine(function* (apps) {
try {
require.resolve(appName);
} catch (__) {
yield Promise.fromCallback(cb => npm.load({}, cb));
/*eslint-disable no-loop-func*/
yield Promise.fromCallback(cb => npm.commands.install([ appNpmPath ], cb));
missed.push(appNpmPath);
}
}

if (missed.length) {
/* eslint-disable no-console */
console.log(`Missed apps: ${missed.join(', ')}. Installing...`);

require('child_process').execSync(
`npm install ${missed.join(' ')} --production`,
{ stdio: 'inherit', cwd: N.mainApp.root }
);
}

// in node 6 `require()` for new packages start work in nextTick only.
yield Promise.fromCallback(cb => process.nextTick(cb));
});


Expand Down Expand Up @@ -624,7 +635,7 @@ module.exports = Promise.coroutine(function* (N) {

if (cluster.isMaster) {
// Ensure all required apps installed before read configs
yield installAppsIfMissed(mainConfig.applications || []);
yield installAppsIfMissed(N, mainConfig.applications || []);
}

initConfig(N, mainConfig);
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -56,7 +56,6 @@
"mdurl": "^1.0.1",
"mkdirp": "^0.5.1",
"mz": "^2.5.0",
"npm": "^3.10.9",
"pointer": "^1.0.1",
"postcss": "^5.2.5",
"pug": "^2.0.0-beta6",
Expand Down

0 comments on commit cbb1491

Please sign in to comment.