Это потрясающая функция, которую мы можем использовать «npm программно», но я сталкиваюсь с некоторыми проблемами. Функция «npm.load», похоже, не срабатывает. Я не получаю никаких консольных журналов, которые находятся внутри моих функций «npm.load» или «npm.commands.install».Проблемы с использованием программ «npm install» программно
var npm = require('npm');
// There is another promise here
.then(function(path) {
// this is working the way I intend it to
cache[requestId].package = JSON.parse(path);
// This is firing
if (cache[requestId].package.name && cache[requestId].package.version && cache[requestId].package.scripts.start) {
// console logs and an array [ 'keystone', 'async', 'underscore', 'swig', 'node-sass', 'node-sass-middleware', 'dotenv' ]
console.log(Object.keys(cache[requestId].package.dependencies));
// console logs as /Users/207004/Desktop/github/mothership/server/app/routes/tractor-beam/ms-apps/my_site
console.log(localPath);
// console logs as a [Function]
console.log(npm.load);
// *** Here is the issue! This is not firing! ***
npm.load({}, function(err) {
// no console log
console.log(npm.commands.install);
// no console log
console.log(err);
npm.commands.install(localPath, Object.keys(cache[requestId].package.dependencies), function(err, done) {
// no console log
console.log('loaded');
// no console log
console.log(err, done);
// I am assuming that this is not firing, but my code does fire the console log in the next promise
return PM2.connectAsync();
});
});
} else {
console.log('else');
}
})
// Another promise chained here. A console log inside of this promise is firing.
Любая помощь будет оценена по достоинству. Пожалуйста, дай мне знать, если возникнут какие-либо вопросы.
Спасибо,