Skip to content

Commit

Permalink
Drop stdin support
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslawzalewski committed Feb 19, 2019
1 parent 46d2b93 commit 1113f5f
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 54 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ Below you will find the most common known issues. Otherwise search the [issues p

- `Cannot find module 'X'`. Cannot reproduce. TLDR; Seems to be fixed by fresh installs of node and npm. See [#144](https://github.com/tjunnone/npm-check-updates/issues/144#issuecomment-148499121).

- Windows: If npm-check-updates hangs, run `ncu --loglevel verbose` to see if it is waiting for stdin. If so, try setting the package file explicitly: `ncu -g --packageFile package.json`. See [#136](https://github.com/tjunnone/npm-check-updates/issues/136#issuecomment-155721102).

Development Notes
--------------

Expand Down
31 changes: 1 addition & 30 deletions lib/npm-check-updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var cint = require('cint');
var path = require('path');
var findUp = require('find-up');
var _ = require('lodash');
var getstdin = require('get-stdin');
var Table = require('cli-table');
var chalk = require('chalk');
var fs = require('fs');
Expand All @@ -31,10 +30,6 @@ var logLevels = {
silly: 6
};

// time to wait for stdin before printing a warning
var stdinWarningTime = 5000;
var stdinWarningMessage = 'Hmmmmm... this is taking a long time. Your console is telling me to wait for input \non stdin, but maybe that is not what you want.\nTry specifying a package file explicitly with ' + chalk.cyan('--packageFile package.json') + '. \nSee https://github.com/tjunnone/npm-check-updates/issues/136#issuecomment-155721102';

//
// Helper functions
//
Expand Down Expand Up @@ -340,14 +335,12 @@ function initOptions(options) {
Searches as follows:
--packageData flag
--packageFile flag
--stdin
--findUp
*/
function findPackage(options) {

var pkgData;
var pkgFile;
var stdinTimer;

print(options, 'Running in local mode...', 'verbose');
print(options, 'Finding package file data...', 'verbose');
Expand Down Expand Up @@ -387,7 +380,7 @@ function findPackage(options) {
print(options, 'Using ' + relPathToPackage);
}
} else {
programError(options, chalk.red('No ' + pkgFileName) + '\n\nPlease add a ' + pkgFileName + ' to the current directory, specify the ' + chalk.cyan('--packageFile') + ' or ' + chalk.cyan('--packageData') + ' options, or pipe a ' + pkgFileName + ' to stdin.');
programError(options, chalk.red('No ' + pkgFileName) + '\n\nPlease add a ' + pkgFileName + ' to the current directory, specify the ' + chalk.cyan('--packageFile') + ' or ' + chalk.cyan('--packageData') + ' options.');
}

return readPackageFile(pkgFile);
Expand All @@ -399,28 +392,6 @@ function findPackage(options) {
} else if (options.packageFile) {
pkgFile = options.packageFile;
pkgData = getPackageDataFromFile(pkgFile, pkgFileName);
} else if (!process.stdin.isTTY) {
print(options, 'Waiting for package data on stdin...', 'verbose');

// warn the user after a while if still waiting for stdin
// this is a way to mitigate #136 where Windows unexpectedly waits for stdin
stdinTimer = setTimeout(function () {
console.log(stdinWarningMessage);
}, stdinWarningTime);

// clear the warning timer once stdin returns and fallback to scanning pwd if no content from stdin
pkgData = getstdin().then(function (_pkgData) {
clearTimeout(stdinTimer);

var isEmptyStdin = _pkgData.length === 0 || (_pkgData.length === 1 && _pkgData.charCodeAt(0) === 10);
// if no stdin content fall back to searching for package.json from pwd and up to root
if (isEmptyStdin) {
pkgFile = findUp.sync(pkgFileName);
return getPackageDataFromFile(pkgFile, pkgFileName);
} else {
return _pkgData;
}
});
} else {
// find the closest package starting from the current working directory and going up to the root
pkgFile = findUp.sync(pkgFileName);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"commander": "2.19.0",
"fast-diff": "1.2.0",
"find-up": "3.0.0",
"get-stdin": "6.0.0",
"json-parse-helpfulerror": "1.0.3",
"lodash": "4.17.11",
"node-alias": "1.0.4",
Expand Down
21 changes: 0 additions & 21 deletions test/test-ncu.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,6 @@ describe('npm-check-updates', function () {

describe('cli', function () {

it('should accept stdin', function () {
return spawn('node', ['bin/ncu'], '{ "dependencies": { "express": "1" } }')
.then(function (output) {
output.trim().should.startWith('express');
});
});

it('should fall back to package.json search when receiving empty content on stdin', function () {
return spawn('node', ['bin/ncu']).then(function (stdout) {
stdout.toString().trim().should.match(/^Using .+package.json/);
});
});

it('should handle no package.json to analyze when receiving empty content on stdin', function () {
// run from tmp dir to avoid ncu analyzing the project's package.json
return spawn('node', [process.cwd() + '/bin/ncu'], {cwd: tmp.dirSync().name})
.catch(function (stderr) {
stderr.toString().trim().should.startWith('No package.json');
});
});

it('should output json with --jsonAll', function () {
return spawn('node', ['bin/ncu', '--jsonAll'], '{ "dependencies": { "express": "1" } }')
.then(JSON.parse)
Expand Down

0 comments on commit 1113f5f

Please sign in to comment.