Skip to content

Commit

Permalink
fix: should not enable ora when detail enable
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 25, 2017
1 parent 77fd8c2 commit 92a94ba
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 31 deletions.
6 changes: 0 additions & 6 deletions bin/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const globalConfig = require('../lib/config');
const installLocal = require('..').installLocal;
const installGlobal = require('..').installGlobal;

const spinner = utils.spinner();

const orignalArgv = process.argv.slice(2);
const argv = parseArgs(orignalArgv, {
string: [
Expand Down Expand Up @@ -213,9 +211,6 @@ co(function* () {
};
}

if (!config.detail) {
spinner.start();
}
// -g install to npm's global prefix
if (argv.global) {
// support custom prefix for global install
Expand Down Expand Up @@ -250,7 +245,6 @@ co(function* () {
}
}
}
spinner.stop();

process.on('exit', code => {
if (code !== 0) {
Expand Down
2 changes: 2 additions & 0 deletions lib/format_install_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const await = require('await-event');
const assert = require('assert');
const path = require('path');
const EventEmitter = require('events');
const ora = require('ora');

module.exports = function formatInstallOptions(options) {
options.spinner = options.detail ? null : ora();
options.events = new EventEmitter();
// close EventEmitter memory leak warning
options.events.setMaxListeners(0);
Expand Down
6 changes: 3 additions & 3 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const bin = require('./bin');
const link = require('./link');
const dependencies = require('./dependencies');

const spinner = utils.spinner();

module.exports = install;

function* install(parentDir, pkg, ancestors, options) {
Expand Down Expand Up @@ -44,7 +42,9 @@ function* _install(parentDir, pkg, ancestors, options) {
options.progresses.finishedInstallTasks,
options.progresses.installTasks,
pkg.name, pkg.version, parentDir);
spinner.text = `[${options.progresses.finishedInstallTasks}/${options.progresses.installTasks}] Installing ${pkg.name}@${pkg.version}`;
if (options.spinner) {
options.spinner.text = `[${options.progresses.finishedInstallTasks}/${options.progresses.installTasks}] Installing ${pkg.name}@${pkg.version}`;
}
const p = npa(pkg.name ? `${pkg.name}@${pkg.version}` : pkg.version);

const key = `install:${pkg.name}@${pkg.version}`;
Expand Down
24 changes: 13 additions & 11 deletions lib/local_install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ const bytes = require('bytes');
const Module = require('module');
const fs = require('mz/fs');
const moment = require('moment');
const utils = require('./utils');
const util = require('util');
const utils = require('./utils');
const postinstall = require('./postinstall');
const preinstall = require('./preinstall');
const prepublish = require('./prepublish');
const install = require('./install');
const dependencies = require('./dependencies');
const formatInstallOptions = require('./format_install_options');

const spinner = utils.spinner();

/**
* npm install
* @param {Object} options - install options
Expand All @@ -46,6 +44,8 @@ const spinner = utils.spinner();
module.exports = function* (options) {
options = formatInstallOptions(options);

options.spinner && options.spinner.start();

const rootPkgFile = path.join(options.root, 'package.json');
const rootPkg = yield utils.readJSON(rootPkgFile);
const displayName = `${rootPkg.name}@${rootPkg.version}`;
Expand Down Expand Up @@ -80,7 +80,7 @@ module.exports = function* (options) {

yield parallel(tasks, 10);

spinner.stop();
options.spinner && options.spinner.succeed(`Installed ${tasks.length} packages`);

const linkTasks = [];
for (const item of options.latestVersions) {
Expand All @@ -100,9 +100,12 @@ module.exports = function* (options) {
yield parallel(linkTasks, 20);
}

options.spinner && options.spinner.succeed(`Linked ${linkTasks.length} latest versions`);

if (options.installRoot) yield postinstall(rootPkg, options.root, false, displayName, options);

yield runPostInstallTasks(options);
options.spinner && options.spinner.succeed(`Run ${options.postInstallTasks.length} scripts`);

// local install trigger prepublish when no packages and non-production mode
// see:
Expand Down Expand Up @@ -134,9 +137,8 @@ module.exports = function* (options) {
bytes(options.totalJSONSize),
bytes(options.totalTarballSize),
];
if (!options.detail) {
spinner.text = util.format.apply(util, logArguments);
spinner.succeed();
if (options.spinner) {
options.spinner.succeed(util.format.apply(util, logArguments));
} else {
options.console.info.apply(console, logArguments);
}
Expand Down Expand Up @@ -320,31 +322,31 @@ function* runPostInstallTasks(options) {
const postinstallScript = pkg.scripts.postinstall;
try {
if (installScript) {
options.console.log(
options.console.info(
'%s %s run %j',
chalk.yellow(`[${count}/${total}] scripts.install`),
chalk.gray(displayName),
installScript
);
const start = Date.now();
yield utils.runScript(root, installScript, options);
options.console.log(
options.console.info(
'%s %s finished in %s',
chalk.yellow(`[${count}/${total}] scripts.install`),
chalk.gray(displayName),
ms(Date.now() - start)
);
}
if (postinstallScript) {
options.console.log(
options.console.info(
'%s %s run %j',
chalk.yellow(`[${count}/${total}] scripts.postinstall`),
chalk.gray(displayName),
postinstallScript
);
const start = Date.now();
yield utils.runScript(root, postinstallScript, options);
options.console.log(
options.console.info(
'%s %s finished in %s',
chalk.yellow(`[${count}/${total}] scripts.postinstall`),
chalk.gray(displayName),
Expand Down
7 changes: 0 additions & 7 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const runscript = require('runscript');
const homedir = require('node-homedir');
const fse = require('co-fs-extra');
const destroy = require('destroy');
const ora = require('ora');
const config = require('./config');
const get = require('./get');
const debug = require('debug')('npminstall:utils');
Expand Down Expand Up @@ -385,12 +384,6 @@ exports.sleep = ms => {
});
};

const spinner = ora();

exports.spinner = () => {
return spinner;
};

exports.formatPath = pathname => {
if (pathname[0] === '~') {
// convert '~/foo/path' => '$HOME/foo/path'
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
"co": "^4.6.0",
"co-fs-extra": "^1.2.1",
"co-parallel": "^1.0.0",
"debug": "^2.4.5",
"debug": "^2.6.0",
"destroy": "^1.0.4",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"moment": "^2.17.1",
"ms": "^0.7.2",
"mz": "^2.6.0",
"node-gyp": "^3.4.0",
"node-gyp": "^3.5.0",
"node-homedir": "^1.0.0",
"normalize-git-url": "^3.0.2",
"npm-package-arg": "^4.2.0",
"ora": "^0.4.0",
"ora": "^1.1.0",
"rimraf": "^2.5.4",
"runscript": "^1.1.0",
"semver": "^5.3.0",
Expand All @@ -60,7 +60,7 @@
"eslint-config-egg": "3",
"intelli-espower-loader": "1",
"istanbul": "*",
"mm": "^2.0.0",
"mm": "^2.1.0",
"mocha": "3",
"power-assert": "^1.4.2",
"thunk-mocha": "1"
Expand Down

0 comments on commit 92a94ba

Please sign in to comment.