Skip to content

Commit fc5332f

Browse files
committed
1 parent 6ea2cd7 commit fc5332f

File tree

22 files changed

+879
-132
lines changed

22 files changed

+879
-132
lines changed

lib/utils/read-user-info.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const { promisify } = require('util')
2-
const readAsync = promisify(require('read'))
1+
const read = require('read')
32
const userValidate = require('npm-user-validate')
43
const log = require('./log-shim.js')
54

@@ -17,17 +16,17 @@ const passwordPrompt = 'npm password: '
1716
const usernamePrompt = 'npm username: '
1817
const emailPrompt = 'email (this IS public): '
1918

20-
function read (opts) {
19+
function readWithProgress (opts) {
2120
log.clearProgress()
22-
return readAsync(opts).finally(() => log.showProgress())
21+
return read(opts).finally(() => log.showProgress())
2322
}
2423

2524
function readOTP (msg = otpPrompt, otp, isRetry) {
2625
if (isRetry && otp && /^[\d ]+$|^[A-Fa-f0-9]{64,64}$/.test(otp)) {
2726
return otp.replace(/\s+/g, '')
2827
}
2928

30-
return read({ prompt: msg, default: otp || '' })
29+
return readWithProgress({ prompt: msg, default: otp || '' })
3130
.then((rOtp) => readOTP(msg, rOtp, true))
3231
}
3332

@@ -36,7 +35,7 @@ function readPassword (msg = passwordPrompt, password, isRetry) {
3635
return password
3736
}
3837

39-
return read({ prompt: msg, silent: true, default: password || '' })
38+
return readWithProgress({ prompt: msg, silent: true, default: password || '' })
4039
.then((rPassword) => readPassword(msg, rPassword, true))
4140
}
4241

@@ -50,7 +49,7 @@ function readUsername (msg = usernamePrompt, username, isRetry) {
5049
}
5150
}
5251

53-
return read({ prompt: msg, default: username || '' })
52+
return readWithProgress({ prompt: msg, default: username || '' })
5453
.then((rUsername) => readUsername(msg, rUsername, true))
5554
}
5655

@@ -64,6 +63,6 @@ function readEmail (msg = emailPrompt, email, isRetry) {
6463
}
6564
}
6665

67-
return read({ prompt: msg, default: email || '' })
66+
return readWithProgress({ prompt: msg, default: email || '' })
6867
.then((username) => readEmail(msg, username, true))
6968
}

node_modules/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@
114114
!/inherits
115115
!/ini
116116
!/init-package-json
117+
!/init-package-json/node_modules/
118+
/init-package-json/node_modules/*
119+
!/init-package-json/node_modules/mute-stream
120+
!/init-package-json/node_modules/read
117121
!/ip-regex
118122
!/ip
119123
!/is-cidr
@@ -227,6 +231,10 @@
227231
!/promise-inflight
228232
!/promise-retry
229233
!/promzard
234+
!/promzard/node_modules/
235+
/promzard/node_modules/*
236+
!/promzard/node_modules/mute-stream
237+
!/promzard/node_modules/read
230238
!/qrcode-terminal
231239
!/read-cmd-shim
232240
!/read-package-json-fast
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The ISC License
2+
3+
Copyright (c) Isaac Z. Schlueter and Contributors
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "mute-stream",
3+
"version": "0.0.8",
4+
"main": "mute.js",
5+
"directories": {
6+
"test": "test"
7+
},
8+
"devDependencies": {
9+
"tap": "^12.1.1"
10+
},
11+
"scripts": {
12+
"test": "tap test/*.js --cov"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "git://github.com/isaacs/mute-stream"
17+
},
18+
"keywords": [
19+
"mute",
20+
"stream",
21+
"pipe"
22+
],
23+
"author": "Isaac Z. Schlueter <[email protected]> (http://blog.izs.me/)",
24+
"license": "ISC",
25+
"description": "Bytes go in, but they don't come out (when muted).",
26+
"files": [
27+
"mute.js"
28+
]
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The ISC License
2+
3+
Copyright (c) Isaac Z. Schlueter and Contributors
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
module.exports = read
3+
4+
var readline = require('readline')
5+
var Mute = require('mute-stream')
6+
7+
function read (opts, cb) {
8+
if (opts.num) {
9+
throw new Error('read() no longer accepts a char number limit')
10+
}
11+
12+
if (typeof opts.default !== 'undefined' &&
13+
typeof opts.default !== 'string' &&
14+
typeof opts.default !== 'number') {
15+
throw new Error('default value must be string or number')
16+
}
17+
18+
var input = opts.input || process.stdin
19+
var output = opts.output || process.stdout
20+
var prompt = (opts.prompt || '').trim() + ' '
21+
var silent = opts.silent
22+
var editDef = false
23+
var timeout = opts.timeout
24+
25+
var def = opts.default || ''
26+
if (def) {
27+
if (silent) {
28+
prompt += '(<default hidden>) '
29+
} else if (opts.edit) {
30+
editDef = true
31+
} else {
32+
prompt += '(' + def + ') '
33+
}
34+
}
35+
var terminal = !!(opts.terminal || output.isTTY)
36+
37+
var m = new Mute({ replace: opts.replace, prompt: prompt })
38+
m.pipe(output, {end: false})
39+
output = m
40+
var rlOpts = { input: input, output: output, terminal: terminal }
41+
42+
if (process.version.match(/^v0\.6/)) {
43+
var rl = readline.createInterface(rlOpts.input, rlOpts.output)
44+
} else {
45+
var rl = readline.createInterface(rlOpts)
46+
}
47+
48+
49+
output.unmute()
50+
rl.setPrompt(prompt)
51+
rl.prompt()
52+
if (silent) {
53+
output.mute()
54+
} else if (editDef) {
55+
rl.line = def
56+
rl.cursor = def.length
57+
rl._refreshLine()
58+
}
59+
60+
var called = false
61+
rl.on('line', onLine)
62+
rl.on('error', onError)
63+
64+
rl.on('SIGINT', function () {
65+
rl.close()
66+
onError(new Error('canceled'))
67+
})
68+
69+
var timer
70+
if (timeout) {
71+
timer = setTimeout(function () {
72+
onError(new Error('timed out'))
73+
}, timeout)
74+
}
75+
76+
function done () {
77+
called = true
78+
rl.close()
79+
80+
if (process.version.match(/^v0\.6/)) {
81+
rl.input.removeAllListeners('data')
82+
rl.input.removeAllListeners('keypress')
83+
rl.input.pause()
84+
}
85+
86+
clearTimeout(timer)
87+
output.mute()
88+
output.end()
89+
}
90+
91+
function onError (er) {
92+
if (called) return
93+
done()
94+
return cb(er)
95+
}
96+
97+
function onLine (line) {
98+
if (called) return
99+
if (silent && terminal) {
100+
output.unmute()
101+
output.write('\r\n')
102+
}
103+
done()
104+
// truncate the \n at the end.
105+
line = line.replace(/\r?\n$/, '')
106+
var isDefault = !!(editDef && line === def)
107+
if (def && !line) {
108+
isDefault = true
109+
line = def
110+
}
111+
cb(null, line, isDefault)
112+
}
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "read",
3+
"version": "1.0.7",
4+
"main": "lib/read.js",
5+
"dependencies": {
6+
"mute-stream": "~0.0.4"
7+
},
8+
"devDependencies": {
9+
"tap": "^1.2.0"
10+
},
11+
"engines": {
12+
"node": ">=0.8"
13+
},
14+
"author": "Isaac Z. Schlueter <[email protected]> (http://blog.izs.me/)",
15+
"description": "read(1) for node programs",
16+
"repository": {
17+
"type": "git",
18+
"url": "git://github.com/isaacs/read.git"
19+
},
20+
"license": "ISC",
21+
"scripts": {
22+
"test": "tap test/*.js"
23+
},
24+
"files": [
25+
"lib/read.js"
26+
]
27+
}

0 commit comments

Comments
 (0)