Improve find npm global strapi performance

This commit is contained in:
Jim LAURIE 2018-07-03 16:43:08 +02:00
parent d383a75154
commit 13013a40b4
3 changed files with 11 additions and 7 deletions

View File

@ -40,7 +40,7 @@ module.exports = (scope, cb) => {
const strapiDependencies = Object.keys(dependencies).filter(key => key.indexOf('strapi') !== -1);
const othersDependencies = Object.keys(dependencies).filter(key => key.indexOf('strapi') === -1);
// Add this check to know if we are in development mode so the creation is faster.
const isStrapiInstalledWithNPM = process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1 || packageManager.isStrapiInstalledWithNPM();
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM();
const globalRootPath = isStrapiInstalledWithNPM ? execSync('npm root -g') : execSync(packageManager.commands('root -g'));
// const globalRootPath = execSync('npm root -g');

View File

@ -214,7 +214,7 @@ module.exports = (scope, cb) => {
});
}),
new Promise(resolve => {
const isStrapiInstalledWithNPM = process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1 || packageManager.isStrapiInstalledWithNPM();
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM();
let packageCmd = isStrapiInstalledWithNPM ? `npm install --prefix "${scope.tmpPath}" ${scope.client.connector}@alpha` : packageManager.commands('install --prefix', scope.tmpPath);
// let cmd = `npm install --prefix "${scope.tmpPath}" ${scope.client.connector}@alpha`;
// Manually create the temp directory for yarn

View File

@ -1,3 +1,4 @@
const fs = require('fs');
const shell = require('shelljs');
const { includes } = require('lodash');
@ -30,7 +31,10 @@ module.exports = {
if (!skipCheck) {
try {
// Retrieve all the packages installed with NPM
const data = watcher('npm -g ls');
const npmPath = watcher('npm root -g');
const data = fs.readdirSync(npmPath.trim());
// Check if strapi is installed with NPM
isNPM = includes(data, 'strapi');