Skip to content

Commit a6eb823

Browse files
committed
Deprecate default stdin. Mitigates #136.
1113f5f
1 parent 3f28ecd commit a6eb823

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ ncu "/^(?!react-).*$/" # windows
205205
--retry <n> Number of times to retry failed requests for
206206
package info. (default: 3)
207207
-s, --silent Don't output anything (--loglevel silent).
208+
--stdin Read package.json from stdin.
208209
-t, --target <value> Target version or function that returns version
209210
to upgrade to: latest, newest, greatest, minor,
210211
patch. Run "ncu --help --target" for details.

src/cli-options.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ As a comparison: without using the --peer option, ncu will suggest the latest ve
344344
description: "Don't output anything (--loglevel silent).",
345345
type: 'boolean',
346346
},
347+
{
348+
long: 'stdin',
349+
description: 'Read package.json from stdin.',
350+
type: 'string',
351+
},
347352
{
348353
long: 'target',
349354
short: 't',

src/lib/findPackage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ async function findPackage(options: Options) {
6666
pkgFile = options.packageFile
6767
pkgData = getPackageDataFromFile(pkgFile, pkgFileName)
6868
} else if (!process.stdin.isTTY) {
69+
if (!options.stdin) {
70+
print(options, chalk.yellow('Default stdin handling is deprecated. Please add the --stdin option.'), 'warn')
71+
}
6972
print(options, 'Waiting for package data on stdin', 'verbose')
7073

7174
// warn the user after a while if still waiting for stdin

src/types/RunOptions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ export interface RunOptions {
114114
/** Don't output anything (--loglevel silent). */
115115
silent?: boolean
116116

117+
/** Read package.json from stdin. */
118+
stdin?: string
119+
117120
/** Target version or function that returns version to upgrade to: latest, newest, greatest, minor, patch. Run "ncu --help --target" for details. (default: "latest") */
118121
target?: 'latest' | 'newest' | 'greatest' | 'minor' | 'patch' | TargetFunction
119122

test/bin.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ describe('bin', function () {
2424
}
2525

2626
it('accept stdin', () => {
27-
return spawn('node', [bin], '{ "dependencies": { "express": "1" } }').then((output: string) => {
27+
return spawn('node', [bin, '--stdin'], '{ "dependencies": { "express": "1" } }').then((output: string) => {
2828
output.trim().should.startWith('express')
2929
})
3030
})
3131

3232
it('reject out-of-date stdin with errorLevel 2', () => {
3333
return spawn(
3434
'node',
35-
[bin, '--errorLevel', '2'],
35+
[bin, '--stdin', '--errorLevel', '2'],
3636
'{ "dependencies": { "express": "1" } }',
3737
).should.eventually.be.rejectedWith('Dependencies not up-to-date')
3838
})
3939

4040
it('fall back to package.json search when receiving empty content on stdin', async () => {
41-
const stdout = await spawn('node', [bin])
41+
const stdout = await spawn('node', [bin, '--stdin'])
4242
stdout
4343
.toString()
4444
.trim()
@@ -141,7 +141,7 @@ describe('bin', function () {
141141
const tempFile = getTempFile()
142142
fs.writeFileSync(tempFile, '{ "dependencies": { "express": "1" } }', 'utf-8')
143143
try {
144-
await spawn('node', [bin, '-u', '--packageFile', tempFile], '{ "dependencies": {}}')
144+
await spawn('node', [bin, '-u', '--stdin', '--packageFile', tempFile], '{ "dependencies": {}}')
145145
const upgradedPkg = JSON.parse(fs.readFileSync(tempFile, 'utf-8'))
146146
upgradedPkg.should.have.property('dependencies')
147147
upgradedPkg.dependencies.should.have.property('express')
@@ -373,7 +373,7 @@ describe('bin', function () {
373373
const dependencies = {
374374
'ncu-test-v2': 'https://github.com/raineorshine/ncu-test-v2.git#v1.0.0',
375375
}
376-
const output = await spawn('node', [bin], JSON.stringify({ dependencies }))
376+
const output = await spawn('node', [bin, '--stdin'], JSON.stringify({ dependencies }))
377377
stripAnsi(output)
378378
.trim()
379379
.should.equal('ncu-test-v2 https://github.com/raineorshine/ncu-test-v2.git#v1.0.0 → v2.0.0')
@@ -383,7 +383,7 @@ describe('bin', function () {
383383
const dependencies = {
384384
request: 'npm:ncu-test-v2@1.0.0',
385385
}
386-
const output = await spawn('node', [bin], JSON.stringify({ dependencies }))
386+
const output = await spawn('node', [bin, '--stdin'], JSON.stringify({ dependencies }))
387387
stripAnsi(output).trim().should.equal('request npm:ncu-test-v2@1.0.0 → 2.0.0')
388388
})
389389
})

0 commit comments

Comments
 (0)