diff --git a/lib/commands/init.js b/lib/commands/init.js index 16ece46589d7c..1e5661a7840f2 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -165,24 +165,20 @@ class Init extends BaseCommand { ].join('\n')) } - // XXX promisify init-package-json - await new Promise((res, rej) => { - initJson(path, initFile, this.npm.config, (er, data) => { - log.resume() - log.enableProgress() - log.silly('package data', data) - if (er && er.message === 'canceled') { - log.warn('init', 'canceled') - return res() - } - if (er) { - rej(er) - } else { - log.info('init', 'written successfully') - res(data) - } - }) - }) + try { + const data = await initJson(path, initFile, this.npm.config) + log.silly('package data', data) + return data + } catch (er) { + if (er.message === 'canceled') { + log.warn('init', 'canceled') + } else { + throw er + } + } finally { + log.resume() + log.enableProgress() + } } async setWorkspace (pkg, workspacePath) { diff --git a/node_modules/.gitignore b/node_modules/.gitignore index 4a9d72e2e5282..96bb81d8ba376 100644 --- a/node_modules/.gitignore +++ b/node_modules/.gitignore @@ -108,10 +108,6 @@ !/inherits !/ini !/init-package-json -!/init-package-json/node_modules/ -/init-package-json/node_modules/* -!/init-package-json/node_modules/mute-stream -!/init-package-json/node_modules/read !/ip-regex !/ip !/is-cidr @@ -223,10 +219,6 @@ !/promise-inflight !/promise-retry !/promzard -!/promzard/node_modules/ -/promzard/node_modules/* -!/promzard/node_modules/mute-stream -!/promzard/node_modules/read !/qrcode-terminal !/read-cmd-shim !/read-package-json-fast diff --git a/node_modules/init-package-json/lib/default-input.js b/node_modules/init-package-json/lib/default-input.js index fe5abfdd85e45..490e83c139887 100644 --- a/node_modules/init-package-json/lib/default-input.js +++ b/node_modules/init-package-json/lib/default-input.js @@ -1,190 +1,160 @@ -/* eslint-disable no-undef */ -var fs = require('fs') -var path = require('path') -var validateLicense = require('validate-npm-package-license') -var validateName = require('validate-npm-package-name') -var npa = require('npm-package-arg') -var semver = require('semver') +/* globals config, dirname, package, basename, yes, prompt */ + +const fs = require('fs/promises') +const path = require('path') +const validateLicense = require('validate-npm-package-license') +const validateName = require('validate-npm-package-name') +const npa = require('npm-package-arg') +const semver = require('semver') // more popular packages should go here, maybe? -function isTestPkg (p) { - return !!p.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/) -} +const isTestPkg = (p) => !!p.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/) -function niceName (n) { - return n.replace(/^node-|[.-]js$/g, '').replace(/\s+/g, ' ').replace(/ /g, '-').toLowerCase() -} +const invalid = (msg) => Object.assign(new Error(msg), { notValid: true }) -function readDeps (test, excluded) { - return function (cb) { - fs.readdir('node_modules', function (readdirErr, dir) { - if (readdirErr) { - return cb() - } - var deps = {} - var n = dir.length - if (n === 0) { - return cb(null, deps) - } - dir.forEach(function (d) { - if (d.match(/^\./)) { - return next() - } - if (test !== isTestPkg(d) || excluded[d]) { - return next() - } +const readDeps = (test, excluded) => async () => { + const dirs = await fs.readdir('node_modules').catch(() => null) - var dp = path.join(dirname, 'node_modules', d, 'package.json') - fs.readFile(dp, 'utf8', function (readFileErr, p) { - if (readFileErr) { - return next() - } - try { - p = JSON.parse(p) - } catch (e) { - return next() - } - if (!p.version) { - return next() - } - if (p._requiredBy) { - if (!p._requiredBy.some(function (req) { - return req === '#USER' - })) { - return next() - } - } - deps[d] = config.get('save-exact') ? p.version : config.get('save-prefix') + p.version - return next() - }) - }) - function next () { - if (--n === 0) { - return cb(null, deps) - } - } - }) + if (!dirs) { + return } + + const deps = {} + for (const dir of dirs) { + if (dir.match(/^\./) || test !== isTestPkg(dir) || excluded[dir]) { + continue + } + + const dp = path.join(dirname, 'node_modules', dir, 'package.json') + const p = await fs.readFile(dp, 'utf8').then((d) => JSON.parse(d)).catch(() => null) + + if (!p || !p.version || p?._requiredBy?.some((r) => r === '#USER')) { + continue + } + + deps[dir] = config.get('save-exact') ? p.version : config.get('save-prefix') + p.version + } + + return deps } -var name = niceName(package.name || basename) -var spec -try { - spec = npa(name) -} catch (e) { - spec = {} +const getConfig = (key) => { + // dots take precedence over dashes + const def = config?.defaults?.[`init.${key}`] + const val = config.get(`init.${key}`) + return (val !== def && val) ? val : config.get(`init-${key.replace(/\./g, '-')}`) } -var scope = config.get('scope') -if (scope) { - if (scope.charAt(0) !== '@') { - scope = '@' + scope + +const getName = () => { + const rawName = package.name || basename + let name = rawName + .replace(/^node-|[.-]js$/g, '') + .replace(/\s+/g, ' ') + .replace(/ /g, '-') + .toLowerCase() + + let spec + try { + spec = npa(name) + } catch { + spec = {} } - if (spec.scope) { - name = scope + '/' + spec.name.split('/')[1] - } else { - name = scope + '/' + name + + let scope = config.get('scope') + + if (scope) { + if (scope.charAt(0) !== '@') { + scope = '@' + scope + } + if (spec.scope) { + name = scope + '/' + spec.name.split('/')[1] + } else { + name = scope + '/' + name + } } + + return name } -exports.name = yes ? name : prompt('package name', name, function (data) { - var its = validateName(data) + +const name = getName() +exports.name = yes ? name : prompt('package name', name, (data) => { + const its = validateName(data) if (its.validForNewPackages) { return data } - var errors = (its.errors || []).concat(its.warnings || []) - var er = new Error('Sorry, ' + errors.join(' and ') + '.') - er.notValid = true - return er + const errors = (its.errors || []).concat(its.warnings || []) + return invalid(`Sorry, ${errors.join(' and ')}.`) }) -const defaultDottedInitVersion = config && - config.defaults && - config.defaults['init.version'] -const dottedInitVersion = - config.get('init.version') !== defaultDottedInitVersion && - config.get('init.version') -var version = package.version || - dottedInitVersion || - config.get('init-version') || - '1.0.0' -exports.version = yes ? - version : - prompt('version', version, function (promptedVersion) { - if (semver.valid(promptedVersion)) { - return promptedVersion - } - var er = new Error('Invalid version: "' + promptedVersion + '"') - er.notValid = true - return er - }) +const version = package.version || getConfig('version') || '1.0.0' +exports.version = yes ? version : prompt('version', version, (v) => { + if (semver.valid(v)) { + return v + } + return invalid(`Invalid version: "${v}"`) +}) if (!package.description) { exports.description = yes ? '' : prompt('description') } if (!package.main) { - exports.main = function (cb) { - fs.readdir(dirname, function (er, f) { - if (er) { - f = [] - } + exports.main = async () => { + const files = await fs.readdir(dirname) + .then(list => list.filter((f) => f.match(/\.js$/))) + .catch(() => []) - f = f.filter(function (filtered) { - return filtered.match(/\.js$/) - }) - - if (f.indexOf('index.js') !== -1) { - f = 'index.js' - } else if (f.indexOf('main.js') !== -1) { - f = 'main.js' - } else if (f.indexOf(basename + '.js') !== -1) { - f = basename + '.js' - } else { - f = f[0] - } + let index + if (files.includes('index.js')) { + index = 'index.js' + } else if (files.includes('main.js')) { + index = 'main.js' + } else if (files.includes(basename + '.js')) { + index = basename + '.js' + } else { + index = files[0] || 'index.js' + } - var index = f || 'index.js' - return cb(null, yes ? index : prompt('entry point', index)) - }) + return yes ? index : prompt('entry point', index) } } if (!package.bin) { - exports.bin = function (cb) { - fs.readdir(path.resolve(dirname, 'bin'), function (er, d) { - // no bins - if (er) { - return cb() - } + exports.bin = async () => { + try { + const d = await fs.readdir(path.resolve(dirname, 'bin')) // just take the first js file we find there, or nada let r = d.find(f => f.match(/\.js$/)) if (r) { r = `bin/${r}` } - return cb(null, r) - }) + return r + } catch { + // no bins + } } } -exports.directories = function (cb) { - fs.readdir(dirname, function (er, dirs) { - if (er) { - return cb(er) - } - var res = {} - dirs.forEach(function (d) { - switch (d) { - case 'example': case 'examples': return res.example = d - case 'test': case 'tests': return res.test = d - case 'doc': case 'docs': return res.doc = d - case 'man': return res.man = d - case 'lib': return res.lib = d - } - }) - if (Object.keys(res).length === 0) { - res = undefined +exports.directories = async () => { + const dirs = await fs.readdir(dirname) + + const res = dirs.reduce((acc, d) => { + if (/^examples?$/.test(d)) { + acc.example = d + } else if (/^tests?$/.test(d)) { + acc.test = d + } else if (/^docs?$/.test(d)) { + acc.doc = d + } else if (d === 'man') { + acc.man = d + } else if (d === 'lib') { + acc.lib = d } - return cb(null, res) - }) + + return acc + }, {}) + + return Object.keys(res).length === 0 ? undefined : res } if (!package.dependencies) { @@ -196,116 +166,97 @@ if (!package.devDependencies) { } // MUST have a test script! -var s = package.scripts || {} -var notest = 'echo "Error: no test specified" && exit 1' if (!package.scripts) { - exports.scripts = function (cb) { - fs.readdir(path.join(dirname, 'node_modules'), function (er, d) { - setupScripts(d || [], cb) - }) - } -} -function setupScripts (d, cb) { - // check to see what framework is in use, if any - function tx (test) { - return test || notest - } - if (!s.test || s.test === notest) { - var commands = { - tap: 'tap test/*.js', - expresso: 'expresso test', - mocha: 'mocha', - } - var command - Object.keys(commands).forEach(function (k) { - if (d.indexOf(k) !== -1) { - command = commands[k] + const scripts = package.scripts || {} + const notest = 'echo "Error: no test specified" && exit 1' + exports.scripts = async () => { + const d = await fs.readdir(path.join(dirname, 'node_modules')).catch(() => []) + + // check to see what framework is in use, if any + let command + if (!scripts.test || scripts.test === notest) { + const commands = { + tap: 'tap test/*.js', + expresso: 'expresso test', + mocha: 'mocha', + } + for (const [k, v] of Object.entries(commands)) { + if (d.includes(k)) { + command = v + } } - }) - var ps = 'test command' - if (yes) { - s.test = command || notest - } else { - s.test = command ? prompt(ps, command, tx) : prompt(ps, tx) } + + const promptArgs = ['test command', (t) => t || notest] + if (command) { + promptArgs.splice(1, 0, command) + } + scripts.test = yes ? command || notest : prompt(...promptArgs) + + return scripts } - return cb(null, s) } if (!package.repository) { - exports.repository = function (cb) { - fs.readFile('.git/config', 'utf8', function (er, gconf) { - if (er || !gconf) { - return cb(null, yes ? '' : prompt('git repository')) - } - gconf = gconf.split(/\r?\n/) - var i = gconf.indexOf('[remote "origin"]') - if (i !== -1) { - var u = gconf[i + 1] - if (!u.match(/^\s*url =/)) { - u = gconf[i + 2] - } - if (!u.match(/^\s*url =/)) { - u = null - } else { - u = u.replace(/^\s*url = /, '') - } + exports.repository = async () => { + const gconf = await fs.readFile('.git/config', 'utf8').catch(() => '') + const lines = gconf.split(/\r?\n/) + + let url + const i = lines.indexOf('[remote "origin"]') + + if (i !== -1) { + url = gconf[i + 1] + if (!url.match(/^\s*url =/)) { + url = gconf[i + 2] } - if (u && u.match(/^git@github.com:/)) { - u = u.replace(/^git@github.com:/, 'https://github.com/') + if (!url.match(/^\s*url =/)) { + url = null + } else { + url = url.replace(/^\s*url = /, '') } + } + + if (url && url.match(/^git@github.com:/)) { + url = url.replace(/^git@github.com:/, 'https://github.com/') + } - return cb(null, yes ? u : prompt('git repository', u)) - }) + return yes ? url || '' : prompt('git repository', url || undefined) } } if (!package.keywords) { - exports.keywords = yes ? '' : prompt('keywords', function (promptedKeywords) { - if (!promptedKeywords) { - return undefined + exports.keywords = yes ? '' : prompt('keywords', (data) => { + if (!data) { + return } - if (Array.isArray(promptedKeywords)) { - promptedKeywords = promptedKeywords.join(' ') + if (Array.isArray(data)) { + data = data.join(' ') } - if (typeof promptedKeywords !== 'string') { - return promptedKeywords + if (typeof data !== 'string') { + return data } - return promptedKeywords.split(/[\s,]+/) + return data.split(/[\s,]+/) }) } if (!package.author) { - exports.author = config.get('init.author.name') || - config.get('init-author-name') + const authorName = getConfig('author.name') + exports.author = authorName ? { - name: config.get('init.author.name') || - config.get('init-author-name'), - email: config.get('init.author.email') || - config.get('init-author-email'), - url: config.get('init.author.url') || - config.get('init-author-url'), + name: authorName, + email: getConfig('author.email'), + url: getConfig('author.url'), } : yes ? '' : prompt('author') } -const defaultDottedInitLicense = config && - config.defaults && - config.defaults['init.license'] -const dottedInitLicense = - config.get('init.license') !== defaultDottedInitLicense && - config.get('init.license') -var license = package.license || - dottedInitLicense || - config.get('init-license') || - 'ISC' -exports.license = yes ? license : prompt('license', license, function (data) { - var its = validateLicense(data) +const license = package.license || getConfig('license') || 'ISC' +exports.license = yes ? license : prompt('license', license, (data) => { + const its = validateLicense(data) if (its.validForNewPackages) { return data } - var errors = (its.errors || []).concat(its.warnings || []) - var er = new Error('Sorry, ' + errors.join(' and ') + '.') - er.notValid = true - return er + const errors = (its.errors || []).concat(its.warnings || []) + return invalid(`Sorry, ${errors.join(' and ')}.`) }) diff --git a/node_modules/init-package-json/lib/init-package-json.js b/node_modules/init-package-json/lib/init-package-json.js index 230bcd81747bd..077ebd96ffc52 100644 --- a/node_modules/init-package-json/lib/init-package-json.js +++ b/node_modules/init-package-json/lib/init-package-json.js @@ -1,184 +1,145 @@ -module.exports = init -module.exports.yes = yes - -var PZ = require('promzard').PromZard -var path = require('path') -var def = require.resolve('./default-input.js') +const promzard = require('promzard') +const path = require('path') +const fs = require('fs/promises') +const semver = require('semver') +const read = require('read') +const util = require('util') +const rpj = require('read-package-json') -var fs = require('fs') -var semver = require('semver') -var read = require('read') +const def = require.resolve('./default-input.js') // to validate the data object at the end as a worthwhile package // and assign default values for things. -var readJson = require('read-package-json') +const _extraSet = rpj.extraSet +const _rpj = util.promisify(rpj) +const _rpjExtras = util.promisify(rpj.extras) +const readPkgJson = async (file, pkg) => { + // only do a few of these. no need for mans or contributors if they're in the files + rpj.extraSet = _extraSet.filter(f => f.name !== 'authors' && f.name !== 'mans') + const p = pkg ? _rpjExtras(file, pkg) : _rpj(file) + return p.catch(() => ({})).finally(() => rpj.extraSet = _extraSet) +} + +const isYes = (c) => !!(c.get('yes') || c.get('y') || c.get('force') || c.get('f')) + +const getConfig = (c = {}) => { + // accept either a plain-jane object, or a config object with a "get" method. + if (typeof c.get !== 'function') { + const data = c + return { + get: (k) => data[k], + toJSON: () => data, + } + } + return c +} -function yes (conf) { - return !!( - conf.get('yes') || conf.get('y') || - conf.get('force') || conf.get('f') - ) +const stringifyPerson = (p) => { + if (typeof p === 'string') { + return p + } + const { name = '', url, web, email, mail } = p + const u = url || web + const e = email || mail + return `${name}${e ? ` <${e}>` : ''}${u ? ` (${u})` : ''}` } -function init (dir, input, config, cb) { - if (typeof config === 'function') { - cb = config - config = {} +async function init (dir, input = def, c = {}) { + const config = getConfig(c) + const yes = isYes(config) + const packageFile = path.resolve(dir, 'package.json') + + const pkg = await readPkgJson(packageFile) + + if (!semver.valid(pkg.version)) { + delete pkg.version } - // accept either a plain-jane object, or a config object - // with a "get" method. - if (typeof config.get !== 'function') { - var data = config - config = { - get: function (k) { - return data[k] - }, - toJSON: function () { - return data - }, + // make sure that the input is valid. if not, use the default + const pzData = await promzard(path.resolve(input), { + yes, + config, + filename: packageFile, + dirname: path.dirname(packageFile), + basename: path.basename(path.dirname(packageFile)), + package: pkg, + }, { backupFile: def }) + + for (const [k, v] of Object.entries(pzData)) { + if (v != null) { + pkg[k] = v } } - var packageFile = path.resolve(dir, 'package.json') - input = path.resolve(input) - var pkg - var ctx = { yes: yes(config) } - - var es = readJson.extraSet - readJson.extraSet = es.filter(function (fn) { - return fn.name !== 'authors' && fn.name !== 'mans' - }) - readJson(packageFile, function (er, d) { - readJson.extraSet = es - - if (er) { - pkg = {} - } else { - pkg = d - } + const pkgExtras = await readPkgJson(packageFile, pkg) + + // turn the objects into somewhat more humane strings. + if (pkgExtras.author) { + pkgExtras.author = stringifyPerson(pkgExtras.author) + } - ctx.filename = packageFile - ctx.dirname = path.dirname(packageFile) - ctx.basename = path.basename(ctx.dirname) - if (!pkg.version || !semver.valid(pkg.version)) { - delete pkg.version + for (const set of ['maintainers', 'contributors']) { + if (Array.isArray(pkgExtras[set])) { + pkgExtras[set] = pkgExtras[set].map(stringifyPerson) } + } - ctx.package = pkg - ctx.config = config || {} - - // make sure that the input is valid. - // if not, use the default - var pz = new PZ(input, ctx) - pz.backupFile = def - pz.on('error', cb) - pz.on('data', function (pzData) { - Object.keys(pzData).forEach(function (k) { - if (pzData[k] !== undefined && pzData[k] !== null) { - pkg[k] = pzData[k] - } - }) - - // only do a few of these. - // no need for mans or contributors if they're in the files - es = readJson.extraSet - readJson.extraSet = es.filter(function (fn) { - return fn.name !== 'authors' && fn.name !== 'mans' - }) - readJson.extras(packageFile, pkg, function (extrasErr, pkgWithExtras) { - if (extrasErr) { - return cb(extrasErr, pkgWithExtras) - } - readJson.extraSet = es - pkgWithExtras = unParsePeople(pkgWithExtras) - // no need for the readme now. - delete pkgWithExtras.readme - delete pkgWithExtras.readmeFilename - - // really don't want to have this lying around in the file - delete pkgWithExtras._id - - // ditto - delete pkgWithExtras.gitHead - - // if the repo is empty, remove it. - if (!pkgWithExtras.repository) { - delete pkgWithExtras.repository - } - - // readJson filters out empty descriptions, but init-package-json - // traditionally leaves them alone - if (!pkgWithExtras.description) { - pkgWithExtras.description = pzData.description - } - - var stringified = JSON.stringify(updateDeps(pkgWithExtras), null, 2) + '\n' - function write (writeYes) { - fs.writeFile(packageFile, stringified, 'utf8', function (writeFileErr) { - if (!writeFileErr && writeYes && !config.get('silent')) { - console.log('Wrote to %s:\n\n%s\n', packageFile, stringified) - } - return cb(writeFileErr, pkgWithExtras) - }) - } - if (ctx.yes) { - return write(true) - } - console.log('About to write to %s:\n\n%s\n', packageFile, stringified) - read({ prompt: 'Is this OK? ', default: 'yes' }, function (promptErr, ok) { - if (promptErr) { - return cb(promptErr) - } - if (!ok || ok.toLowerCase().charAt(0) !== 'y') { - console.log('Aborted.') - } else { - return write() - } - }) - }) - }) - }) -} + // no need for the readme now. + delete pkgExtras.readme + delete pkgExtras.readmeFilename + + // really don't want to have this lying around in the file + delete pkgExtras._id + + // ditto + delete pkgExtras.gitHead + + // if the repo is empty, remove it. + if (!pkgExtras.repository) { + delete pkgExtras.repository + } + + // readJson filters out empty descriptions, but init-package-json + // traditionally leaves them alone + if (!pkgExtras.description) { + pkgExtras.description = pzData.description + } -function updateDeps (depsData) { // optionalDependencies don't need to be repeated in two places - if (depsData.dependencies) { - if (depsData.optionalDependencies) { - for (const name of Object.keys(depsData.optionalDependencies)) { - delete depsData.dependencies[name] + if (pkgExtras.dependencies) { + if (pkgExtras.optionalDependencies) { + for (const name of Object.keys(pkgExtras.optionalDependencies)) { + delete pkgExtras.dependencies[name] } } - if (Object.keys(depsData.dependencies).length === 0) { - delete depsData.dependencies + if (Object.keys(pkgExtras.dependencies).length === 0) { + delete pkgExtras.dependencies } } - return depsData -} + const stringified = JSON.stringify(pkgExtras, null, 2) + '\n' + const msg = util.format('%s:\n\n%s\n', packageFile, stringified) + const write = () => fs.writeFile(packageFile, stringified, 'utf8') -// turn the objects into somewhat more humane strings. -function unParsePeople (data) { - if (data.author) { - data.author = unParsePerson(data.author) - }['maintainers', 'contributors'].forEach(function (set) { - if (!Array.isArray(data[set])) { - return + if (yes) { + await write() + if (!config.get('silent')) { + console.log(`Wrote to ${msg}`) } - data[set] = data[set].map(unParsePerson) - }) - return data -} + return pkgExtras + } -function unParsePerson (person) { - if (typeof person === 'string') { - return person + console.log(`About to write to ${msg}`) + const ok = await read({ prompt: 'Is this OK? ', default: 'yes' }) + if (!ok || !ok.toLowerCase().startsWith('y')) { + console.log('Aborted.') + return } - var name = person.name || '' - var u = person.url || person.web - var url = u ? (' (' + u + ')') : '' - var e = person.email || person.mail - var email = e ? (' <' + e + '>') : '' - return name + email + url + + await write() + return pkgExtras } + +module.exports = init +module.exports.yes = isYes diff --git a/node_modules/init-package-json/node_modules/mute-stream/LICENSE b/node_modules/init-package-json/node_modules/mute-stream/LICENSE deleted file mode 100644 index 19129e315fe59..0000000000000 --- a/node_modules/init-package-json/node_modules/mute-stream/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -The ISC License - -Copyright (c) Isaac Z. Schlueter and Contributors - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/node_modules/init-package-json/node_modules/mute-stream/mute.js b/node_modules/init-package-json/node_modules/mute-stream/mute.js deleted file mode 100644 index a24fc09975bb3..0000000000000 --- a/node_modules/init-package-json/node_modules/mute-stream/mute.js +++ /dev/null @@ -1,145 +0,0 @@ -var Stream = require('stream') - -module.exports = MuteStream - -// var out = new MuteStream(process.stdout) -// argument auto-pipes -function MuteStream (opts) { - Stream.apply(this) - opts = opts || {} - this.writable = this.readable = true - this.muted = false - this.on('pipe', this._onpipe) - this.replace = opts.replace - - // For readline-type situations - // This much at the start of a line being redrawn after a ctrl char - // is seen (such as backspace) won't be redrawn as the replacement - this._prompt = opts.prompt || null - this._hadControl = false -} - -MuteStream.prototype = Object.create(Stream.prototype) - -Object.defineProperty(MuteStream.prototype, 'constructor', { - value: MuteStream, - enumerable: false -}) - -MuteStream.prototype.mute = function () { - this.muted = true -} - -MuteStream.prototype.unmute = function () { - this.muted = false -} - -Object.defineProperty(MuteStream.prototype, '_onpipe', { - value: onPipe, - enumerable: false, - writable: true, - configurable: true -}) - -function onPipe (src) { - this._src = src -} - -Object.defineProperty(MuteStream.prototype, 'isTTY', { - get: getIsTTY, - set: setIsTTY, - enumerable: true, - configurable: true -}) - -function getIsTTY () { - return( (this._dest) ? this._dest.isTTY - : (this._src) ? this._src.isTTY - : false - ) -} - -// basically just get replace the getter/setter with a regular value -function setIsTTY (isTTY) { - Object.defineProperty(this, 'isTTY', { - value: isTTY, - enumerable: true, - writable: true, - configurable: true - }) -} - -Object.defineProperty(MuteStream.prototype, 'rows', { - get: function () { - return( this._dest ? this._dest.rows - : this._src ? this._src.rows - : undefined ) - }, enumerable: true, configurable: true }) - -Object.defineProperty(MuteStream.prototype, 'columns', { - get: function () { - return( this._dest ? this._dest.columns - : this._src ? this._src.columns - : undefined ) - }, enumerable: true, configurable: true }) - - -MuteStream.prototype.pipe = function (dest, options) { - this._dest = dest - return Stream.prototype.pipe.call(this, dest, options) -} - -MuteStream.prototype.pause = function () { - if (this._src) return this._src.pause() -} - -MuteStream.prototype.resume = function () { - if (this._src) return this._src.resume() -} - -MuteStream.prototype.write = function (c) { - if (this.muted) { - if (!this.replace) return true - if (c.match(/^\u001b/)) { - if(c.indexOf(this._prompt) === 0) { - c = c.substr(this._prompt.length); - c = c.replace(/./g, this.replace); - c = this._prompt + c; - } - this._hadControl = true - return this.emit('data', c) - } else { - if (this._prompt && this._hadControl && - c.indexOf(this._prompt) === 0) { - this._hadControl = false - this.emit('data', this._prompt) - c = c.substr(this._prompt.length) - } - c = c.toString().replace(/./g, this.replace) - } - } - this.emit('data', c) -} - -MuteStream.prototype.end = function (c) { - if (this.muted) { - if (c && this.replace) { - c = c.toString().replace(/./g, this.replace) - } else { - c = null - } - } - if (c) this.emit('data', c) - this.emit('end') -} - -function proxy (fn) { return function () { - var d = this._dest - var s = this._src - if (d && d[fn]) d[fn].apply(d, arguments) - if (s && s[fn]) s[fn].apply(s, arguments) -}} - -MuteStream.prototype.destroy = proxy('destroy') -MuteStream.prototype.destroySoon = proxy('destroySoon') -MuteStream.prototype.close = proxy('close') diff --git a/node_modules/init-package-json/node_modules/mute-stream/package.json b/node_modules/init-package-json/node_modules/mute-stream/package.json deleted file mode 100644 index 56ebb363b9251..0000000000000 --- a/node_modules/init-package-json/node_modules/mute-stream/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "mute-stream", - "version": "0.0.8", - "main": "mute.js", - "directories": { - "test": "test" - }, - "devDependencies": { - "tap": "^12.1.1" - }, - "scripts": { - "test": "tap test/*.js --cov" - }, - "repository": { - "type": "git", - "url": "git://github.com/isaacs/mute-stream" - }, - "keywords": [ - "mute", - "stream", - "pipe" - ], - "author": "Isaac Z. Schlueter (http://blog.izs.me/)", - "license": "ISC", - "description": "Bytes go in, but they don't come out (when muted).", - "files": [ - "mute.js" - ] -} diff --git a/node_modules/init-package-json/node_modules/read/LICENSE b/node_modules/init-package-json/node_modules/read/LICENSE deleted file mode 100644 index 19129e315fe59..0000000000000 --- a/node_modules/init-package-json/node_modules/read/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -The ISC License - -Copyright (c) Isaac Z. Schlueter and Contributors - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/node_modules/init-package-json/node_modules/read/lib/read.js b/node_modules/init-package-json/node_modules/read/lib/read.js deleted file mode 100644 index a93d1b3b532c0..0000000000000 --- a/node_modules/init-package-json/node_modules/read/lib/read.js +++ /dev/null @@ -1,113 +0,0 @@ - -module.exports = read - -var readline = require('readline') -var Mute = require('mute-stream') - -function read (opts, cb) { - if (opts.num) { - throw new Error('read() no longer accepts a char number limit') - } - - if (typeof opts.default !== 'undefined' && - typeof opts.default !== 'string' && - typeof opts.default !== 'number') { - throw new Error('default value must be string or number') - } - - var input = opts.input || process.stdin - var output = opts.output || process.stdout - var prompt = (opts.prompt || '').trim() + ' ' - var silent = opts.silent - var editDef = false - var timeout = opts.timeout - - var def = opts.default || '' - if (def) { - if (silent) { - prompt += '(