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 strapiDependencies = Object.keys(dependencies).filter(key => key.indexOf('strapi') !== -1);
const othersDependencies = 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. // 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 = isStrapiInstalledWithNPM ? execSync('npm root -g') : execSync(packageManager.commands('root -g'));
// const globalRootPath = execSync('npm root -g'); // const globalRootPath = execSync('npm root -g');
@ -103,7 +103,7 @@ module.exports = (scope, cb) => {
pluginsInstallation(); pluginsInstallation();
} }
// Install default plugins and link dependencies. // Install default plugins and link dependencies.
function pluginsInstallation() { function pluginsInstallation() {
const strapiBin = path.join(scope.strapiRoot, scope.strapiPackageJSON.bin.strapi); const strapiBin = path.join(scope.strapiRoot, scope.strapiPackageJSON.bin.strapi);

View File

@ -214,7 +214,7 @@ module.exports = (scope, cb) => {
}); });
}), }),
new Promise(resolve => { 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 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`; // let cmd = `npm install --prefix "${scope.tmpPath}" ${scope.client.connector}@alpha`;
// Manually create the temp directory for yarn // Manually create the temp directory for yarn

View File

@ -1,3 +1,4 @@
const fs = require('fs');
const shell = require('shelljs'); const shell = require('shelljs');
const { includes } = require('lodash'); const { includes } = require('lodash');
@ -26,11 +27,14 @@ module.exports = {
if (process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1) { if (process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1) {
skipCheck = true; skipCheck = true;
} }
if (!skipCheck) { if (!skipCheck) {
try { try {
// Retrieve all the packages installed with NPM // 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 // Check if strapi is installed with NPM
isNPM = includes(data, 'strapi'); isNPM = includes(data, 'strapi');
@ -51,7 +55,7 @@ module.exports = {
commands: function (cmdType, path = '') { commands: function (cmdType, path = '') {
const isNPM = this.isStrapiInstalledWithNPM(); const isNPM = this.isStrapiInstalledWithNPM();
switch(cmdType) { switch(cmdType) {
case 'install --prefix': case 'install --prefix':
return isNPM ? `npm install --prefix ${path}` : `yarn --cwd ${path} add`; return isNPM ? `npm install --prefix ${path}` : `yarn --cwd ${path} add`;
@ -65,4 +69,4 @@ module.exports = {
return ''; return '';
} }
} }
}; };