UNPKG

snyk

Version:

snyk library and cli utility

1,992 lines (1,668 loc) 134 kB
exports.id = 31; exports.ids = [31]; exports.modules = { /***/ 53692: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val); const identity = val => val; /* eslint-disable no-control-regex */ // this is a modified version of https://github.com/chalk/ansi-regex (MIT License) const ANSI_REGEX = /[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g; const create = () => { const colors = { enabled: true, visible: true, styles: {}, keys: {} }; if ('FORCE_COLOR' in process.env) { colors.enabled = process.env.FORCE_COLOR !== '0'; } const ansi = style => { let open = style.open = `\u001b[${style.codes[0]}m`; let close = style.close = `\u001b[${style.codes[1]}m`; let regex = style.regex = new RegExp(`\\u001b\\[${style.codes[1]}m`, 'g'); style.wrap = (input, newline) => { if (input.includes(close)) input = input.replace(regex, close + open); let output = open + input + close; // see https://github.com/chalk/chalk/pull/92, thanks to the // chalk contributors for this fix. However, we've confirmed that // this issue is also present in Windows terminals return newline ? output.replace(/\r*\n/g, `${close}$&${open}`) : output; }; return style; }; const wrap = (style, input, newline) => { return typeof style === 'function' ? style(input) : style.wrap(input, newline); }; const style = (input, stack) => { if (input === '' || input == null) return ''; if (colors.enabled === false) return input; if (colors.visible === false) return ''; let str = '' + input; let nl = str.includes('\n'); let n = stack.length; if (n > 0 && stack.includes('unstyle')) { stack = [...new Set(['unstyle', ...stack])].reverse(); } while (n-- > 0) str = wrap(colors.styles[stack[n]], str, nl); return str; }; const define = (name, codes, type) => { colors.styles[name] = ansi({ name, codes }); let keys = colors.keys[type] || (colors.keys[type] = []); keys.push(name); Reflect.defineProperty(colors, name, { configurable: true, enumerable: true, set(value) { colors.alias(name, value); }, get() { let color = input => style(input, color.stack); Reflect.setPrototypeOf(color, colors); color.stack = this.stack ? this.stack.concat(name) : [name]; return color; } }); }; define('reset', [0, 0], 'modifier'); define('bold', [1, 22], 'modifier'); define('dim', [2, 22], 'modifier'); define('italic', [3, 23], 'modifier'); define('underline', [4, 24], 'modifier'); define('inverse', [7, 27], 'modifier'); define('hidden', [8, 28], 'modifier'); define('strikethrough', [9, 29], 'modifier'); define('black', [30, 39], 'color'); define('red', [31, 39], 'color'); define('green', [32, 39], 'color'); define('yellow', [33, 39], 'color'); define('blue', [34, 39], 'color'); define('magenta', [35, 39], 'color'); define('cyan', [36, 39], 'color'); define('white', [37, 39], 'color'); define('gray', [90, 39], 'color'); define('grey', [90, 39], 'color'); define('bgBlack', [40, 49], 'bg'); define('bgRed', [41, 49], 'bg'); define('bgGreen', [42, 49], 'bg'); define('bgYellow', [43, 49], 'bg'); define('bgBlue', [44, 49], 'bg'); define('bgMagenta', [45, 49], 'bg'); define('bgCyan', [46, 49], 'bg'); define('bgWhite', [47, 49], 'bg'); define('blackBright', [90, 39], 'bright'); define('redBright', [91, 39], 'bright'); define('greenBright', [92, 39], 'bright'); define('yellowBright', [93, 39], 'bright'); define('blueBright', [94, 39], 'bright'); define('magentaBright', [95, 39], 'bright'); define('cyanBright', [96, 39], 'bright'); define('whiteBright', [97, 39], 'bright'); define('bgBlackBright', [100, 49], 'bgBright'); define('bgRedBright', [101, 49], 'bgBright'); define('bgGreenBright', [102, 49], 'bgBright'); define('bgYellowBright', [103, 49], 'bgBright'); define('bgBlueBright', [104, 49], 'bgBright'); define('bgMagentaBright', [105, 49], 'bgBright'); define('bgCyanBright', [106, 49], 'bgBright'); define('bgWhiteBright', [107, 49], 'bgBright'); colors.ansiRegex = ANSI_REGEX; colors.hasColor = colors.hasAnsi = str => { colors.ansiRegex.lastIndex = 0; return typeof str === 'string' && str !== '' && colors.ansiRegex.test(str); }; colors.alias = (name, color) => { let fn = typeof color === 'string' ? colors[color] : color; if (typeof fn !== 'function') { throw new TypeError('Expected alias to be the name of an existing color (string) or a function'); } if (!fn.stack) { Reflect.defineProperty(fn, 'name', { value: name }); colors.styles[name] = fn; fn.stack = [name]; } Reflect.defineProperty(colors, name, { configurable: true, enumerable: true, set(value) { colors.alias(name, value); }, get() { let color = input => style(input, color.stack); Reflect.setPrototypeOf(color, colors); color.stack = this.stack ? this.stack.concat(fn.stack) : fn.stack; return color; } }); }; colors.theme = custom => { if (!isObject(custom)) throw new TypeError('Expected theme to be an object'); for (let name of Object.keys(custom)) { colors.alias(name, custom[name]); } return colors; }; colors.alias('unstyle', str => { if (typeof str === 'string' && str !== '') { colors.ansiRegex.lastIndex = 0; return str.replace(colors.ansiRegex, ''); } return ''; }); colors.alias('noop', str => str); colors.none = colors.clear = colors.noop; colors.stripColor = colors.unstyle; colors.symbols = __webpack_require__(17142); colors.define = define; return colors; }; module.exports = create(); module.exports.create = create; /***/ }), /***/ 17142: /***/ ((module) => { "use strict"; const isHyper = process.env.TERM_PROGRAM === 'Hyper'; const isWindows = process.platform === 'win32'; const isLinux = process.platform === 'linux'; const common = { ballotDisabled: '☒', ballotOff: '☐', ballotOn: '☑', bullet: '•', bulletWhite: '◦', fullBlock: '█', heart: '❤', identicalTo: '≡', line: '─', mark: '※', middot: '·', minus: '-', multiplication: '×', obelus: '÷', pencilDownRight: '✎', pencilRight: '✏', pencilUpRight: '✐', percent: '%', pilcrow2: '❡', pilcrow: '¶', plusMinus: '±', section: '§', starsOff: '☆', starsOn: '★', upDownArrow: '↕' }; const windows = Object.assign({}, common, { check: '√', cross: '×', ellipsisLarge: '...', ellipsis: '...', info: 'i', question: '?', questionSmall: '?', pointer: '>', pointerSmall: '»', radioOff: '( )', radioOn: '(*)', warning: '‼' }); const other = Object.assign({}, common, { ballotCross: '✘', check: '✔', cross: '✖', ellipsisLarge: '⋯', ellipsis: '…', info: 'ℹ', question: '?', questionFull: '?', questionSmall: '﹖', pointer: isLinux ? '▸' : '❯', pointerSmall: isLinux ? '‣' : '›', radioOff: '◯', radioOn: '◉', warning: '⚠' }); module.exports = (isWindows && !isHyper) ? windows : other; Reflect.defineProperty(module.exports, 'common', { enumerable: false, value: common }); Reflect.defineProperty(module.exports, 'windows', { enumerable: false, value: windows }); Reflect.defineProperty(module.exports, 'other', { enumerable: false, value: other }); /***/ }), /***/ 84031: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; const assert = __webpack_require__(42357); const Events = __webpack_require__(28614); const utils = __webpack_require__(83546); /** * Create an instance of `Enquirer`. * * ```js * const Enquirer = require('enquirer'); * const enquirer = new Enquirer(); * ``` * @name Enquirer * @param {Object} `options` (optional) Options to use with all prompts. * @param {Object} `answers` (optional) Answers object to initialize with. * @api public */ class Enquirer extends Events { constructor(options, answers) { super(); this.options = utils.merge({}, options); this.answers = { ...answers }; } /** * Register a custom prompt type. * * ```js * const Enquirer = require('enquirer'); * const enquirer = new Enquirer(); * enquirer.register('customType', require('./custom-prompt')); * ``` * @name register() * @param {String} `type` * @param {Function|Prompt} `fn` `Prompt` class, or a function that returns a `Prompt` class. * @return {Object} Returns the Enquirer instance * @api public */ register(type, fn) { if (utils.isObject(type)) { for (let key of Object.keys(type)) this.register(key, type[key]); return this; } assert.equal(typeof fn, 'function', 'expected a function'); let name = type.toLowerCase(); if (fn.prototype instanceof this.Prompt) { this.prompts[name] = fn; } else { this.prompts[name] = fn(this.Prompt, this); } return this; } /** * Prompt function that takes a "question" object or array of question objects, * and returns an object with responses from the user. * * ```js * const Enquirer = require('enquirer'); * const enquirer = new Enquirer(); * * const response = await enquirer.prompt({ * type: 'input', * name: 'username', * message: 'What is your username?' * }); * console.log(response); * ``` * @name prompt() * @param {Array|Object} `questions` Options objects for one or more prompts to run. * @return {Promise} Promise that returns an "answers" object with the user's responses. * @api public */ async prompt(questions = []) { for (let question of [].concat(questions)) { try { if (typeof question === 'function') question = await question.call(this); await this.ask(utils.merge({}, this.options, question)); } catch (err) { return Promise.reject(err); } } return this.answers; } async ask(question) { if (typeof question === 'function') { question = await question.call(this); } let opts = utils.merge({}, this.options, question); let { type, name } = question; let { set, get } = utils; if (typeof type === 'function') { type = await type.call(this, question, this.answers); } if (!type) return this.answers[name]; assert(this.prompts[type], `Prompt "${type}" is not registered`); let prompt = new this.prompts[type](opts); let value = get(this.answers, name); prompt.state.answers = this.answers; prompt.enquirer = this; if (name) { prompt.on('submit', value => { this.emit('answer', name, value, prompt); set(this.answers, name, value); }); } // bubble events let emit = prompt.emit.bind(prompt); prompt.emit = (...args) => { this.emit.call(this, ...args); return emit(...args); }; this.emit('prompt', prompt, this); if (opts.autofill && value != null) { prompt.value = prompt.input = value; // if "autofill=show" render the prompt, otherwise stay "silent" if (opts.autofill === 'show') { await prompt.submit(); } } else { value = prompt.value = await prompt.run(); } return value; } /** * Use an enquirer plugin. * * ```js * const Enquirer = require('enquirer'); * const enquirer = new Enquirer(); * const plugin = enquirer => { * // do stuff to enquire instance * }; * enquirer.use(plugin); * ``` * @name use() * @param {Function} `plugin` Plugin function that takes an instance of Enquirer. * @return {Object} Returns the Enquirer instance. * @api public */ use(plugin) { plugin.call(this, this); return this; } set Prompt(value) { this._Prompt = value; } get Prompt() { return this._Prompt || this.constructor.Prompt; } get prompts() { return this.constructor.prompts; } static set Prompt(value) { this._Prompt = value; } static get Prompt() { return this._Prompt || __webpack_require__(232); } static get prompts() { return __webpack_require__(29594); } static get types() { return __webpack_require__(29920); } /** * Prompt function that takes a "question" object or array of question objects, * and returns an object with responses from the user. * * ```js * const { prompt } = require('enquirer'); * const response = await prompt({ * type: 'input', * name: 'username', * message: 'What is your username?' * }); * console.log(response); * ``` * @name Enquirer#prompt * @param {Array|Object} `questions` Options objects for one or more prompts to run. * @return {Promise} Promise that returns an "answers" object with the user's responses. * @api public */ static get prompt() { const fn = (questions, ...rest) => { let enquirer = new this(...rest); let emit = enquirer.emit.bind(enquirer); enquirer.emit = (...args) => { fn.emit(...args); return emit(...args); }; return enquirer.prompt(questions); }; utils.mixinEmitter(fn, new Events()); return fn; } } utils.mixinEmitter(Enquirer, new Events()); const prompts = Enquirer.prompts; for (let name of Object.keys(prompts)) { let key = name.toLowerCase(); let run = options => new prompts[name](options).run(); Enquirer.prompt[key] = run; Enquirer[key] = run; if (!Enquirer[name]) { Reflect.defineProperty(Enquirer, name, { get: () => prompts[name] }); } } const exp = name => { utils.defineExport(Enquirer, name, () => Enquirer.types[name]); }; exp('ArrayPrompt'); exp('AuthPrompt'); exp('BooleanPrompt'); exp('NumberPrompt'); exp('StringPrompt'); module.exports = Enquirer; /***/ }), /***/ 94907: /***/ ((module, exports, __webpack_require__) => { "use strict"; const isTerm = process.env.TERM_PROGRAM === 'Apple_Terminal'; const colors = __webpack_require__(53692); const utils = __webpack_require__(83546); const ansi = module.exports = exports; const ESC = '\u001b['; const BEL = '\u0007'; let hidden = false; const code = ansi.code = { bell: BEL, beep: BEL, beginning: `${ESC}G`, down: `${ESC}J`, esc: ESC, getPosition: `${ESC}6n`, hide: `${ESC}?25l`, line: `${ESC}2K`, lineEnd: `${ESC}K`, lineStart: `${ESC}1K`, restorePosition: ESC + (isTerm ? '8' : 'u'), savePosition: ESC + (isTerm ? '7' : 's'), screen: `${ESC}2J`, show: `${ESC}?25h`, up: `${ESC}1J` }; const cursor = ansi.cursor = { get hidden() { return hidden; }, hide() { hidden = true; return code.hide; }, show() { hidden = false; return code.show; }, forward: (count = 1) => `${ESC}${count}C`, backward: (count = 1) => `${ESC}${count}D`, nextLine: (count = 1) => `${ESC}E`.repeat(count), prevLine: (count = 1) => `${ESC}F`.repeat(count), up: (count = 1) => count ? `${ESC}${count}A` : '', down: (count = 1) => count ? `${ESC}${count}B` : '', right: (count = 1) => count ? `${ESC}${count}C` : '', left: (count = 1) => count ? `${ESC}${count}D` : '', to(x, y) { return y ? `${ESC}${y + 1};${x + 1}H` : `${ESC}${x + 1}G`; }, move(x = 0, y = 0) { let res = ''; res += (x < 0) ? cursor.left(-x) : (x > 0) ? cursor.right(x) : ''; res += (y < 0) ? cursor.up(-y) : (y > 0) ? cursor.down(y) : ''; return res; }, restore(state = {}) { let { after, cursor, initial, input, prompt, size, value } = state; initial = utils.isPrimitive(initial) ? String(initial) : ''; input = utils.isPrimitive(input) ? String(input) : ''; value = utils.isPrimitive(value) ? String(value) : ''; if (size) { let codes = ansi.cursor.up(size) + ansi.cursor.to(prompt.length); let diff = input.length - cursor; if (diff > 0) { codes += ansi.cursor.left(diff); } return codes; } if (value || after) { let pos = (!input && !!initial) ? -initial.length : -input.length + cursor; if (after) pos -= after.length; if (input === '' && initial && !prompt.includes(initial)) { pos += initial.length; } return ansi.cursor.move(pos); } } }; const erase = ansi.erase = { screen: code.screen, up: code.up, down: code.down, line: code.line, lineEnd: code.lineEnd, lineStart: code.lineStart, lines(n) { let str = ''; for (let i = 0; i < n; i++) { str += ansi.erase.line + (i < n - 1 ? ansi.cursor.up(1) : ''); } if (n) str += ansi.code.beginning; return str; } }; ansi.clear = (input = '', columns = process.stdout.columns) => { if (!columns) return erase.line + cursor.to(0); let width = str => [...colors.unstyle(str)].length; let lines = input.split(/\r?\n/); let rows = 0; for (let line of lines) { rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / columns); } return (erase.line + cursor.prevLine()).repeat(rows - 1) + erase.line + cursor.to(0); }; /***/ }), /***/ 64726: /***/ ((__unused_webpack_module, exports) => { "use strict"; /** * Actions are mappings from keypress event names to method names * in the prompts. */ exports.ctrl = { a: 'first', b: 'backward', c: 'cancel', d: 'deleteForward', e: 'last', f: 'forward', g: 'reset', i: 'tab', k: 'cutForward', l: 'reset', n: 'newItem', m: 'cancel', j: 'submit', p: 'search', r: 'remove', s: 'save', u: 'undo', w: 'cutLeft', x: 'toggleCursor', v: 'paste' }; exports.shift = { up: 'shiftUp', down: 'shiftDown', left: 'shiftLeft', right: 'shiftRight', tab: 'prev' }; exports.fn = { up: 'pageUp', down: 'pageDown', left: 'pageLeft', right: 'pageRight', delete: 'deleteForward' }; // <alt> on Windows exports.option = { b: 'backward', f: 'forward', d: 'cutRight', left: 'cutLeft', up: 'altUp', down: 'altDown' }; exports.keys = { pageup: 'pageUp', // <fn>+<up> (mac), <Page Up> (windows) pagedown: 'pageDown', // <fn>+<down> (mac), <Page Down> (windows) home: 'home', // <fn>+<left> (mac), <home> (windows) end: 'end', // <fn>+<right> (mac), <end> (windows) cancel: 'cancel', delete: 'deleteForward', backspace: 'delete', down: 'down', enter: 'submit', escape: 'cancel', left: 'left', space: 'space', number: 'number', return: 'submit', right: 'right', tab: 'next', up: 'up' }; /***/ }), /***/ 73736: /***/ ((module) => { "use strict"; const unique = arr => arr.filter((v, i) => arr.lastIndexOf(v) === i); const compact = arr => unique(arr).filter(Boolean); module.exports = (action, data = {}, value = '') => { let { past = [], present = '' } = data; let rest, prev; switch (action) { case 'prev': case 'undo': rest = past.slice(0, past.length - 1); prev = past[past.length - 1] || ''; return { past: compact([value, ...rest]), present: prev }; case 'next': case 'redo': rest = past.slice(1); prev = past[0] || ''; return { past: compact([...rest, value]), present: prev }; case 'save': return { past: compact([...past, value]), present: '' }; case 'remove': prev = compact(past.filter(v => v !== value)); present = ''; if (prev.length) { present = prev.pop(); } return { past: prev, present }; default: { throw new Error(`Invalid action: "${action}"`); } } }; /***/ }), /***/ 27189: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; const colors = __webpack_require__(53692); const clean = (str = '') => { return typeof str === 'string' ? str.replace(/^['"]|['"]$/g, '') : ''; }; /** * This file contains the interpolation and rendering logic for * the Snippet prompt. */ class Item { constructor(token) { this.name = token.key; this.field = token.field || {}; this.value = clean(token.initial || this.field.initial || ''); this.message = token.message || this.name; this.cursor = 0; this.input = ''; this.lines = []; } } const tokenize = async(options = {}, defaults = {}, fn = token => token) => { let unique = new Set(); let fields = options.fields || []; let input = options.template; let tabstops = []; let items = []; let keys = []; let line = 1; if (typeof input === 'function') { input = await input(); } let i = -1; let next = () => input[++i]; let peek = () => input[i + 1]; let push = token => { token.line = line; tabstops.push(token); }; push({ type: 'bos', value: '' }); while (i < input.length - 1) { let value = next(); if (/^[^\S\n ]$/.test(value)) { push({ type: 'text', value }); continue; } if (value === '\n') { push({ type: 'newline', value }); line++; continue; } if (value === '\\') { value += next(); push({ type: 'text', value }); continue; } if ((value === '$' || value === '#' || value === '{') && peek() === '{') { let n = next(); value += n; let token = { type: 'template', open: value, inner: '', close: '', value }; let ch; while ((ch = next())) { if (ch === '}') { if (peek() === '}') ch += next(); token.value += ch; token.close = ch; break; } if (ch === ':') { token.initial = ''; token.key = token.inner; } else if (token.initial !== void 0) { token.initial += ch; } token.value += ch; token.inner += ch; } token.template = token.open + (token.initial || token.inner) + token.close; token.key = token.key || token.inner; if (defaults.hasOwnProperty(token.key)) { token.initial = defaults[token.key]; } token = fn(token); push(token); keys.push(token.key); unique.add(token.key); let item = items.find(item => item.name === token.key); token.field = fields.find(ch => ch.name === token.key); if (!item) { item = new Item(token); items.push(item); } item.lines.push(token.line - 1); continue; } let last = tabstops[tabstops.length - 1]; if (last.type === 'text' && last.line === line) { last.value += value; } else { push({ type: 'text', value }); } } push({ type: 'eos', value: '' }); return { input, tabstops, unique, keys, items }; }; module.exports = async prompt => { let options = prompt.options; let required = new Set(options.required === true ? [] : (options.required || [])); let defaults = { ...options.values, ...options.initial }; let { tabstops, items, keys } = await tokenize(options, defaults); let result = createFn('result', prompt, options); let format = createFn('format', prompt, options); let isValid = createFn('validate', prompt, options, true); let isVal = prompt.isValue.bind(prompt); return async(state = {}, submitted = false) => { let index = 0; state.required = required; state.items = items; state.keys = keys; state.output = ''; let validate = async(value, state, item, index) => { let error = await isValid(value, state, item, index); if (error === false) { return 'Invalid field ' + item.name; } return error; }; for (let token of tabstops) { let value = token.value; let key = token.key; if (token.type !== 'template') { if (value) state.output += value; continue; } if (token.type === 'template') { let item = items.find(ch => ch.name === key); if (options.required === true) { state.required.add(item.name); } let val = [item.input, state.values[item.value], item.value, value].find(isVal); let field = item.field || {}; let message = field.message || token.inner; if (submitted) { let error = await validate(state.values[key], state, item, index); if ((error && typeof error === 'string') || error === false) { state.invalid.set(key, error); continue; } state.invalid.delete(key); let res = await result(state.values[key], state, item, index); state.output += colors.unstyle(res); continue; } item.placeholder = false; let before = value; value = await format(value, state, item, index); if (val !== value) { state.values[key] = val; value = prompt.styles.typing(val); state.missing.delete(message); } else { state.values[key] = void 0; val = `<${message}>`; value = prompt.styles.primary(val); item.placeholder = true; if (state.required.has(key)) { state.missing.add(message); } } if (state.missing.has(message) && state.validating) { value = prompt.styles.warning(val); } if (state.invalid.has(key) && state.validating) { value = prompt.styles.danger(val); } if (index === state.index) { if (before !== value) { value = prompt.styles.underline(value); } else { value = prompt.styles.heading(colors.unstyle(value)); } } index++; } if (value) { state.output += value; } } let lines = state.output.split('\n').map(l => ' ' + l); let len = items.length; let done = 0; for (let item of items) { if (state.invalid.has(item.name)) { item.lines.forEach(i => { if (lines[i][0] !== ' ') return; lines[i] = state.styles.danger(state.symbols.bullet) + lines[i].slice(1); }); } if (prompt.isValue(state.values[item.name])) { done++; } } state.completed = ((done / len) * 100).toFixed(0); state.output = lines.join('\n'); return state.output; }; }; function createFn(prop, prompt, options, fallback) { return (value, state, item, index) => { if (typeof item.field[prop] === 'function') { return item.field[prop].call(prompt, value, state, item, index); } return [fallback, value].find(v => prompt.isValue(v)); }; } /***/ }), /***/ 28914: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; const readline = __webpack_require__(51058); const combos = __webpack_require__(64726); /* eslint-disable no-control-regex */ const metaKeyCodeRe = /^(?:\x1b)([a-zA-Z0-9])$/; const fnKeyRe = /^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/; const keyName = { /* xterm/gnome ESC O letter */ 'OP': 'f1', 'OQ': 'f2', 'OR': 'f3', 'OS': 'f4', /* xterm/rxvt ESC [ number ~ */ '[11~': 'f1', '[12~': 'f2', '[13~': 'f3', '[14~': 'f4', /* from Cygwin and used in libuv */ '[[A': 'f1', '[[B': 'f2', '[[C': 'f3', '[[D': 'f4', '[[E': 'f5', /* common */ '[15~': 'f5', '[17~': 'f6', '[18~': 'f7', '[19~': 'f8', '[20~': 'f9', '[21~': 'f10', '[23~': 'f11', '[24~': 'f12', /* xterm ESC [ letter */ '[A': 'up', '[B': 'down', '[C': 'right', '[D': 'left', '[E': 'clear', '[F': 'end', '[H': 'home', /* xterm/gnome ESC O letter */ 'OA': 'up', 'OB': 'down', 'OC': 'right', 'OD': 'left', 'OE': 'clear', 'OF': 'end', 'OH': 'home', /* xterm/rxvt ESC [ number ~ */ '[1~': 'home', '[2~': 'insert', '[3~': 'delete', '[4~': 'end', '[5~': 'pageup', '[6~': 'pagedown', /* putty */ '[[5~': 'pageup', '[[6~': 'pagedown', /* rxvt */ '[7~': 'home', '[8~': 'end', /* rxvt keys with modifiers */ '[a': 'up', '[b': 'down', '[c': 'right', '[d': 'left', '[e': 'clear', '[2$': 'insert', '[3$': 'delete', '[5$': 'pageup', '[6$': 'pagedown', '[7$': 'home', '[8$': 'end', 'Oa': 'up', 'Ob': 'down', 'Oc': 'right', 'Od': 'left', 'Oe': 'clear', '[2^': 'insert', '[3^': 'delete', '[5^': 'pageup', '[6^': 'pagedown', '[7^': 'home', '[8^': 'end', /* misc. */ '[Z': 'tab', } function isShiftKey(code) { return ['[a', '[b', '[c', '[d', '[e', '[2$', '[3$', '[5$', '[6$', '[7$', '[8$', '[Z'].includes(code) } function isCtrlKey(code) { return [ 'Oa', 'Ob', 'Oc', 'Od', 'Oe', '[2^', '[3^', '[5^', '[6^', '[7^', '[8^'].includes(code) } const keypress = (s = '', event = {}) => { let parts; let key = { name: event.name, ctrl: false, meta: false, shift: false, option: false, sequence: s, raw: s, ...event }; if (Buffer.isBuffer(s)) { if (s[0] > 127 && s[1] === void 0) { s[0] -= 128; s = '\x1b' + String(s); } else { s = String(s); } } else if (s !== void 0 && typeof s !== 'string') { s = String(s); } else if (!s) { s = key.sequence || ''; } key.sequence = key.sequence || s || key.name; if (s === '\r') { // carriage return key.raw = void 0; key.name = 'return'; } else if (s === '\n') { // enter, should have been called linefeed key.name = 'enter'; } else if (s === '\t') { // tab key.name = 'tab'; } else if (s === '\b' || s === '\x7f' || s === '\x1b\x7f' || s === '\x1b\b') { // backspace or ctrl+h key.name = 'backspace'; key.meta = s.charAt(0) === '\x1b'; } else if (s === '\x1b' || s === '\x1b\x1b') { // escape key key.name = 'escape'; key.meta = s.length === 2; } else if (s === ' ' || s === '\x1b ') { key.name = 'space'; key.meta = s.length === 2; } else if (s <= '\x1a') { // ctrl+letter key.name = String.fromCharCode(s.charCodeAt(0) + 'a'.charCodeAt(0) - 1); key.ctrl = true; } else if (s.length === 1 && s >= '0' && s <= '9') { // number key.name = 'number'; } else if (s.length === 1 && s >= 'a' && s <= 'z') { // lowercase letter key.name = s; } else if (s.length === 1 && s >= 'A' && s <= 'Z') { // shift+letter key.name = s.toLowerCase(); key.shift = true; } else if ((parts = metaKeyCodeRe.exec(s))) { // meta+character key key.meta = true; key.shift = /^[A-Z]$/.test(parts[1]); } else if ((parts = fnKeyRe.exec(s))) { let segs = [...s]; if (segs[0] === '\u001b' && segs[1] === '\u001b') { key.option = true; } // ansi escape sequence // reassemble the key code leaving out leading \x1b's, // the modifier key bitflag and any meaningless "1;" sequence let code = [parts[1], parts[2], parts[4], parts[6]].filter(Boolean).join(''); let modifier = (parts[3] || parts[5] || 1) - 1; // Parse the key modifier key.ctrl = !!(modifier & 4); key.meta = !!(modifier & 10); key.shift = !!(modifier & 1); key.code = code; key.name = keyName[code]; key.shift = isShiftKey(code) || key.shift; key.ctrl = isCtrlKey(code) || key.ctrl; } return key; }; keypress.listen = (options = {}, onKeypress) => { let { stdin } = options; if (!stdin || (stdin !== process.stdin && !stdin.isTTY)) { throw new Error('Invalid stream passed'); } let rl = readline.createInterface({ terminal: true, input: stdin }); readline.emitKeypressEvents(stdin, rl); let on = (buf, key) => onKeypress(buf, keypress(buf, key), rl); let isRaw = stdin.isRaw; if (stdin.isTTY) stdin.setRawMode(true); stdin.on('keypress', on); rl.resume(); let off = () => { if (stdin.isTTY) stdin.setRawMode(isRaw); stdin.removeListener('keypress', on); rl.pause(); rl.close(); }; return off; }; keypress.action = (buf, key, customActions) => { let obj = { ...combos, ...customActions }; if (key.ctrl) { key.action = obj.ctrl[key.name]; return key; } if (key.option && obj.option) { key.action = obj.option[key.name]; return key; } if (key.shift) { key.action = obj.shift[key.name]; return key; } key.action = obj.keys[key.name]; return key; }; module.exports = keypress; /***/ }), /***/ 12786: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; const utils = __webpack_require__(83546); /** * Render a placeholder value with cursor and styling based on the * position of the cursor. * * @param {Object} `prompt` Prompt instance. * @param {String} `input` Input string. * @param {String} `initial` The initial user-provided value. * @param {Number} `pos` Current cursor position. * @param {Boolean} `showCursor` Render a simulated cursor using the inverse primary style. * @return {String} Returns the styled placeholder string. * @api public */ module.exports = (prompt, options = {}) => { prompt.cursorHide(); let { input = '', initial = '', pos, showCursor = true, color } = options; let style = color || prompt.styles.placeholder; let inverse = utils.inverse(prompt.styles.primary); let blinker = str => inverse(prompt.styles.black(str)); let output = input; let char = ' '; let reverse = blinker(char); if (prompt.blink && prompt.blink.off === true) { blinker = str => str; reverse = ''; } if (showCursor && pos === 0 && initial === '' && input === '') { return blinker(char); } if (showCursor && pos === 0 && (input === initial || input === '')) { return blinker(initial[0]) + style(initial.slice(1)); } initial = utils.isPrimitive(initial) ? `${initial}` : ''; input = utils.isPrimitive(input) ? `${input}` : ''; let placeholder = initial && initial.startsWith(input) && initial !== input; let cursor = placeholder ? blinker(initial[input.length]) : reverse; if (pos !== input.length && showCursor === true) { output = input.slice(0, pos) + blinker(input[pos]) + input.slice(pos + 1); cursor = ''; } if (showCursor === false) { cursor = ''; } if (placeholder) { let raw = prompt.styles.unstyle(output + cursor); return output + cursor + style(initial.slice(raw.length)); } return output + cursor; }; /***/ }), /***/ 232: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; const Events = __webpack_require__(28614); const colors = __webpack_require__(53692); const keypress = __webpack_require__(28914); const timer = __webpack_require__(33940); const State = __webpack_require__(36873); const theme = __webpack_require__(39227); const utils = __webpack_require__(83546); const ansi = __webpack_require__(94907); /** * Base class for creating a new Prompt. * @param {Object} `options` Question object. */ class Prompt extends Events { constructor(options = {}) { super(); this.name = options.name; this.type = options.type; this.options = options; theme(this); timer(this); this.state = new State(this); this.initial = [options.initial, options.default].find(v => v != null); this.stdout = options.stdout || process.stdout; this.stdin = options.stdin || process.stdin; this.scale = options.scale || 1; this.term = this.options.term || process.env.TERM_PROGRAM; this.margin = margin(this.options.margin); this.setMaxListeners(0); setOptions(this); } async keypress(input, event = {}) { this.keypressed = true; let key = keypress.action(input, keypress(input, event), this.options.actions); this.state.keypress = key; this.emit('keypress', input, key); this.emit('state', this.state.clone()); let fn = this.options[key.action] || this[key.action] || this.dispatch; if (typeof fn === 'function') { return await fn.call(this, input, key); } this.alert(); } alert() { delete this.state.alert; if (this.options.show === false) { this.emit('alert'); } else { this.stdout.write(ansi.code.beep); } } cursorHide() { this.stdout.write(ansi.cursor.hide()); utils.onExit(() => this.cursorShow()); } cursorShow() { this.stdout.write(ansi.cursor.show()); } write(str) { if (!str) return; if (this.stdout && this.state.show !== false) { this.stdout.write(str); } this.state.buffer += str; } clear(lines = 0) { let buffer = this.state.buffer; this.state.buffer = ''; if ((!buffer && !lines) || this.options.show === false) return; this.stdout.write(ansi.cursor.down(lines) + ansi.clear(buffer, this.width)); } restore() { if (this.state.closed || this.options.show === false) return; let { prompt, after, rest } = this.sections(); let { cursor, initial = '', input = '', value = '' } = this; let size = this.state.size = rest.length; let state = { after, cursor, initial, input, prompt, size, value }; let codes = ansi.cursor.restore(state); if (codes) { this.stdout.write(codes); } } sections() { let { buffer, input, prompt } = this.state; prompt = colors.unstyle(prompt); let buf = colors.unstyle(buffer); let idx = buf.indexOf(prompt); let header = buf.slice(0, idx); let rest = buf.slice(idx); let lines = rest.split('\n'); let first = lines[0]; let last = lines[lines.length - 1]; let promptLine = prompt + (input ? ' ' + input : ''); let len = promptLine.length; let after = len < first.length ? first.slice(len + 1) : ''; return { header, prompt: first, after, rest: lines.slice(1), last }; } async submit() { this.state.submitted = true; this.state.validating = true; // this will only be called when the prompt is directly submitted // without initializing, i.e. when the prompt is skipped, etc. Otherwize, // "options.onSubmit" is will be handled by the "initialize()" method. if (this.options.onSubmit) { await this.options.onSubmit.call(this, this.name, this.value, this); } let result = this.state.error || await this.validate(this.value, this.state); if (result !== true) { let error = '\n' + this.symbols.pointer + ' '; if (typeof result === 'string') { error += result.trim(); } else { error += 'Invalid input'; } this.state.error = '\n' + this.styles.danger(error); this.state.submitted = false; await this.render(); await this.alert(); this.state.validating = false; this.state.error = void 0; return; } this.state.validating = false; await this.render(); await this.close(); this.value = await this.result(this.value); this.emit('submit', this.value); } async cancel(err) { this.state.cancelled = this.state.submitted = true; await this.render(); await this.close(); if (typeof this.options.onCancel === 'function') { await this.options.onCancel.call(this, this.name, this.value, this); } this.emit('cancel', await this.error(err)); } async close() { this.state.closed = true; try { let sections = this.sections(); let lines = Math.ceil(sections.prompt.length / this.width); if (sections.rest) { this.write(ansi.cursor.down(sections.rest.length)); } this.write('\n'.repeat(lines)); } catch (err) { /* do nothing */ } this.emit('close'); } start() { if (!this.stop && this.options.show !== false) { this.stop = keypress.listen(this, this.keypress.bind(this)); this.once('close', this.stop); } } async skip() { this.skipped = this.options.skip === true; if (typeof this.options.skip === 'function') { this.skipped = await this.options.skip.call(this, this.name, this.value); } return this.skipped; } async initialize() { let { format, options, result } = this; this.format = () => format.call(this, this.value); this.result = () => result.call(this, this.value); if (typeof options.initial === 'function') { this.initial = await options.initial.call(this, this); } if (typeof options.onRun === 'function') { await options.onRun.call(this, this); } // if "options.onSubmit" is defined, we wrap the "submit" method to guarantee // that "onSubmit" will always called first thing inside the submit // method, regardless of how it's handled in inheriting prompts. if (typeof options.onSubmit === 'function') { let onSubmit = options.onSubmit.bind(this); let submit = this.submit.bind(this); delete this.options.onSubmit; this.submit = async() => { await onSubmit(this.name, this.value, this); return submit(); }; } await this.start(); await this.render(); } render() { throw new Error('expected prompt to have a custom render method'); } run() { return new Promise(async(resolve, reject) => { this.once('submit', resolve); this.once('cancel', reject); if (await this.skip()) { this.render = () => {}; return this.submit(); } await this.initialize(); this.emit('run'); }); } async element(name, choice, i) { let { options, state, symbols, timers } = this; let timer = timers && timers[name]; state.timer = timer; let value = options[name] || state[name] || symbols[name]; let val = choice && choice[name] != null ? choice[name] : await value; if (val === '') return val; let res = await this.resolve(val, state, choice, i); if (!res && choice && choice[name]) { return this.resolve(value, state, choice, i); } return res; } async prefix() { let element = await this.element('prefix') || this.symbols; let timer = this.timers && this.timers.prefix; let state = this.state; state.timer = timer; if (utils.isObject(element)) element = element[state.status] || element.pending; if (!utils.hasColor(element)) { let style = this.styles[state.status] || this.styles.pending; return style(element); } return element; } async message() { let message = await this.element('message'); if (!utils.hasColor(message)) { return this.styles.strong(message); } return message; } async separator() { let element = await this.element('separator') || this.symbols; let timer = this.timers && this.timers.separator; let state = this.state; state.timer = timer; let value = element[state.status] || element.pending || state.separator; let ele = await this.resolve(value, state); if (utils.isObject(ele)) ele = ele[state.status] || ele.pending; if (!utils.hasColor(ele)) { return this.styles.muted(ele); } return ele; } async pointer(choice, i) { let val = await this.element('pointer', choice, i); if (typeof val === 'string' && utils.hasColor(val)) { return val; } if (val) { let styles = this.styles; let focused = this.index === i; let style = focused ? styles.primary : val => val; let ele = await this.resolve(val[focused ? 'on' : 'off'] || val, this.state); let styled = !utils.hasColor(ele) ? style(ele) : ele; return focused ? styled : ' '.repeat(ele.length); } } async indicator(choice, i) { let val = await this.element('indicator', choice, i); if (typeof val === 'string' && utils.hasColor(val)) { return val; } if (val) { let styles = this.styles; let enabled = choice.enabled === true; let style = enabled ? styles.success : styles.dark; let ele = val[enabled ? 'on' : 'off'] || val; return !utils.hasColor(ele) ? style(ele) : ele; } return ''; } body() { return null; } footer() { if (this.state.status === 'pending') { return this.element('footer'); } } header() { if (this.state.status === 'pending') { return this.element('header'); } } async hint() { if (this.state.status === 'pending' && !this.isValue(this.state.input)) { let hint = await this.element('hint'); if (!utils.hasColor(hint)) { return this.styles.muted(hint); } return hint; } } error(err) { return !this.state.submitted ? (err || this.state.error) : ''; } format(value) { return value; } result(value) { return value; } validate(value) { if (this.options.required === true) { return this.isValue(value); } return true; } isValue(value) { return value != null && value !== ''; } resolve(value, ...args) { return utils.resolve(this, value, ...args); } get base() { return Prompt.prototype; } get style() { return this.styles[this.state.status]; } get height() { return this.options.rows || utils.height(this.stdout, 25); } get width() { return this.options.columns || utils.width(this.stdout, 80); } get size() { return { width: this.width, height: this.height }; } set cursor(value) { this.state.cursor = value; } get cursor() { return this.state.cursor; } set input(value) { this.state.input = value; } get input() { return this.state.input; } set value(value) { this.state.value = value; } get value() { let { input, value } = this.state; let result = [value, input].find(this.isValue.bind(this)); return this.isValue(result) ? result : this.initial; } static get prompt() { return options => new this(options).run(); } } function setOptions(prompt) { let isValidKey = key => { return prompt[key] === void 0 || typeof prompt[key] === 'function'; }; let ignore = [ 'actions', 'choices', 'initial', 'margin', 'roles', 'styles', 'symbols', 'theme', 'timers', 'value' ]; let ignoreFn = [ 'body', 'footer', 'error', 'header', 'hint', 'indicator', 'message', 'prefix', 'separator', 'skip' ]; for (let key of Object.keys(prompt.options)) { if (ignore.includes(key)) continue; if (/^on[A-Z]/.test(key)) continue; let option = prompt.options[key]; if (typeof option === 'function' && isValidKey(key)) { if (!ignoreFn.includes(key)) { prompt[key] = option.bind(prompt); } } else if (typeof prompt[key] !== 'function') { prompt[key] = option; } } } function margin(value) { if (typeof value === 'number') { value = [value, value, value, value]; } let arr = [].concat(value || []); let pad = i => i % 2 === 0 ? '\n' : ' '; let res = []; for (let i = 0; i < 4; i++) { let char = pad(i); if (arr[i]) { res.push(char.repeat(arr[i])); } else { res.push(''); } } return res; } module.exports = Prompt; /***/ }), /***/ 89317: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; const Select = __webpack_require__(13466); const highlight = (input, color) => { let val = input.toLowerCase(); return str => { let s = str.toLowerCase(); let i = s.indexOf(val); let colored = color(str.slice(i, i + val.length)); return i >= 0 ? str.slice(0, i) + colored + str.slice(i + val.length) : str; }; }; class AutoComplete extends Select { constructor(options) { super(options); this.cursorShow(); } moveCursor(n) { this.state.cursor += n; } dispatch(ch) { return this.append(ch); } space(ch) { return this.options.multiple ? super.space(ch) : this.append(ch); } append(ch) { let { cursor, input } = this.state; this.input = input.slice(0, cursor) + ch + input.slice(cursor); this.moveCursor(1); return this.complete(); } delete() { let { cursor, input } = this.state; if (!input) return this.alert(); this.input = input.slice(0, cursor - 1) + input.slice(cursor); this.moveCursor(-1); return this.complete(); } deleteForward() { let { cursor, input } = this.state; if (input[cursor] === void 0) return this.alert(); this.input = `${input}`.slice(0, cursor) + `${input}`.slice(cursor + 1); return this.complete(); } number(ch) { return this.append(ch); } async complete() { this.completing = true; this.choices = await this.suggest(this.input, this.state._choices); this.state.limit = void 0; // allow getter/setter to reset limit this.index = Math.min(Math.max(this.visible.length - 1, 0), this.index); await this.render(); this.completing = false; } suggest(input = this.input, choices = this.state._choices) { if (typeof this.options.suggest === 'function') { return this.options.suggest.call(this, input, choices); } let str = input.toLowerCase(); return choices.filter(ch => ch.message.toLowerCase().includes(str)); } pointer() { return ''; } format() { if (!this.focused) return this.input; if (this.options.multiple && this.state.submitted) { return this.selected.map(ch => this.styles.primary(ch.message)).join(', '); } if (this.state.submitted) { let value = this.value = this.input = this.focused.value; return this.styles.primary(value); } return this.input; } async render() { if (this.state.status !== 'pending') return super.render(); let style = this.options.highlight ? this.options.highlight.bind(this) : this.styles.placeholder; let color = highlight(this.input, style); let choices = this.choices; this.choices = choices.map(ch => ({ ...ch, message: color(ch.message) })); await super.render(); this.choices = choices; } submit() { if (this.options.multiple) { this.value = this.selected.map(ch => ch.name);