Upakovka v Electron.JS no po staroy sborke cherez .cjs

This commit is contained in:
Neyra
2026-02-10 19:19:41 +08:00
parent 8e9b7201ed
commit a1bba1d3d1
442 changed files with 19825 additions and 47462 deletions

447
node_modules/ora/index.js generated vendored
View File

@@ -1,95 +1,139 @@
import process from 'node:process';
import chalk from 'chalk';
import cliCursor from 'cli-cursor';
import cliSpinners from 'cli-spinners';
import logSymbols from 'log-symbols';
import stripAnsi from 'strip-ansi';
import stringWidth from 'string-width';
import isInteractive from 'is-interactive';
import isUnicodeSupported from 'is-unicode-supported';
import stdinDiscarder from 'stdin-discarder';
'use strict';
const readline = require('readline');
const chalk = require('chalk');
const cliCursor = require('cli-cursor');
const cliSpinners = require('cli-spinners');
const logSymbols = require('log-symbols');
const stripAnsi = require('strip-ansi');
const wcwidth = require('wcwidth');
const isInteractive = require('is-interactive');
const isUnicodeSupported = require('is-unicode-supported');
const {BufferListStream} = require('bl');
class Ora {
#linesToClear = 0;
#isDiscardingStdin = false;
#lineCount = 0;
#frameIndex = -1;
#lastSpinnerFrameTime = 0;
#options;
#spinner;
#stream;
#id;
#initialInterval;
#isEnabled;
#isSilent;
#indent;
#text;
#prefixText;
#suffixText;
color;
const TEXT = Symbol('text');
const PREFIX_TEXT = Symbol('prefixText');
const ASCII_ETX_CODE = 0x03; // Ctrl+C emits this code
constructor(options) {
if (typeof options === 'string') {
options = {
text: options,
};
}
class StdinDiscarder {
constructor() {
this.requests = 0;
this.#options = {
color: 'cyan',
stream: process.stderr,
discardStdin: true,
hideCursor: true,
...options,
this.mutedStream = new BufferListStream();
this.mutedStream.pipe(process.stdout);
const self = this; // eslint-disable-line unicorn/no-this-assignment
this.ourEmit = function (event, data, ...args) {
const {stdin} = process;
if (self.requests > 0 || stdin.emit === self.ourEmit) {
if (event === 'keypress') { // Fixes readline behavior
return;
}
if (event === 'data' && data.includes(ASCII_ETX_CODE)) {
process.emit('SIGINT');
}
Reflect.apply(self.oldEmit, this, [event, data, ...args]);
} else {
Reflect.apply(process.stdin.emit, this, [event, data, ...args]);
}
};
}
// Public
this.color = this.#options.color;
start() {
this.requests++;
// It's important that these use the public setters.
this.spinner = this.#options.spinner;
this.#initialInterval = this.#options.interval;
this.#stream = this.#options.stream;
this.#isEnabled = typeof this.#options.isEnabled === 'boolean' ? this.#options.isEnabled : isInteractive({stream: this.#stream});
this.#isSilent = typeof this.#options.isSilent === 'boolean' ? this.#options.isSilent : false;
// Set *after* `this.#stream`.
// It's important that these use the public setters.
this.text = this.#options.text;
this.prefixText = this.#options.prefixText;
this.suffixText = this.#options.suffixText;
this.indent = this.#options.indent;
if (process.env.NODE_ENV === 'test') {
this._stream = this.#stream;
this._isEnabled = this.#isEnabled;
Object.defineProperty(this, '_linesToClear', {
get() {
return this.#linesToClear;
},
set(newValue) {
this.#linesToClear = newValue;
},
});
Object.defineProperty(this, '_frameIndex', {
get() {
return this.#frameIndex;
},
});
Object.defineProperty(this, '_lineCount', {
get() {
return this.#lineCount;
},
});
if (this.requests === 1) {
this.realStart();
}
}
stop() {
if (this.requests <= 0) {
throw new Error('`stop` called more times than `start`');
}
this.requests--;
if (this.requests === 0) {
this.realStop();
}
}
realStart() {
// No known way to make it work reliably on Windows
if (process.platform === 'win32') {
return;
}
this.rl = readline.createInterface({
input: process.stdin,
output: this.mutedStream
});
this.rl.on('SIGINT', () => {
if (process.listenerCount('SIGINT') === 0) {
process.emit('SIGINT');
} else {
this.rl.close();
process.kill(process.pid, 'SIGINT');
}
});
}
realStop() {
if (process.platform === 'win32') {
return;
}
this.rl.close();
this.rl = undefined;
}
}
let stdinDiscarder;
class Ora {
constructor(options) {
if (!stdinDiscarder) {
stdinDiscarder = new StdinDiscarder();
}
if (typeof options === 'string') {
options = {
text: options
};
}
this.options = {
text: '',
color: 'cyan',
stream: process.stderr,
discardStdin: true,
...options
};
this.spinner = this.options.spinner;
this.color = this.options.color;
this.hideCursor = this.options.hideCursor !== false;
this.interval = this.options.interval || this.spinner.interval || 100;
this.stream = this.options.stream;
this.id = undefined;
this.isEnabled = typeof this.options.isEnabled === 'boolean' ? this.options.isEnabled : isInteractive({stream: this.stream});
this.isSilent = typeof this.options.isSilent === 'boolean' ? this.options.isSilent : false;
// Set *after* `this.stream`
this.text = this.options.text;
this.prefixText = this.options.prefixText;
this.linesToClear = 0;
this.indent = this.options.indent;
this.discardStdin = this.options.discardStdin;
this.isDiscardingStdin = false;
}
get indent() {
return this.#indent;
return this._indent;
}
set indent(indent = 0) {
@@ -97,73 +141,66 @@ class Ora {
throw new Error('The `indent` option must be an integer from 0 and up');
}
this.#indent = indent;
this.#updateLineCount();
this._indent = indent;
}
get interval() {
return this.#initialInterval ?? this.#spinner.interval ?? 100;
_updateInterval(interval) {
if (interval !== undefined) {
this.interval = interval;
}
}
get spinner() {
return this.#spinner;
return this._spinner;
}
set spinner(spinner) {
this.#frameIndex = -1;
this.#initialInterval = undefined;
this.frameIndex = 0;
if (typeof spinner === 'object') {
if (spinner.frames === undefined) {
throw new Error('The given spinner must have a `frames` property');
}
this.#spinner = spinner;
this._spinner = spinner;
} else if (!isUnicodeSupported()) {
this.#spinner = cliSpinners.line;
this._spinner = cliSpinners.line;
} else if (spinner === undefined) {
// Set default spinner
this.#spinner = cliSpinners.dots;
this._spinner = cliSpinners.dots;
} else if (spinner !== 'default' && cliSpinners[spinner]) {
this.#spinner = cliSpinners[spinner];
this._spinner = cliSpinners[spinner];
} else {
throw new Error(`There is no built-in spinner named '${spinner}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`);
}
this._updateInterval(this._spinner.interval);
}
get text() {
return this.#text;
return this[TEXT];
}
set text(value = '') {
this.#text = value;
this.#updateLineCount();
set text(value) {
this[TEXT] = value;
this.updateLineCount();
}
get prefixText() {
return this.#prefixText;
return this[PREFIX_TEXT];
}
set prefixText(value = '') {
this.#prefixText = value;
this.#updateLineCount();
}
get suffixText() {
return this.#suffixText;
}
set suffixText(value = '') {
this.#suffixText = value;
this.#updateLineCount();
set prefixText(value) {
this[PREFIX_TEXT] = value;
this.updateLineCount();
}
get isSpinning() {
return this.#id !== undefined;
return this.id !== undefined;
}
#getFullPrefixText(prefixText = this.#prefixText, postfix = ' ') {
if (typeof prefixText === 'string' && prefixText !== '') {
getFullPrefixText(prefixText = this[PREFIX_TEXT], postfix = ' ') {
if (typeof prefixText === 'string') {
return prefixText + postfix;
}
@@ -174,32 +211,17 @@ class Ora {
return '';
}
#getFullSuffixText(suffixText = this.#suffixText, prefix = ' ') {
if (typeof suffixText === 'string' && suffixText !== '') {
return prefix + suffixText;
}
if (typeof suffixText === 'function') {
return prefix + suffixText();
}
return '';
}
#updateLineCount() {
const columns = this.#stream.columns ?? 80;
const fullPrefixText = this.#getFullPrefixText(this.#prefixText, '-');
const fullSuffixText = this.#getFullSuffixText(this.#suffixText, '-');
const fullText = ' '.repeat(this.#indent) + fullPrefixText + '--' + this.#text + '--' + fullSuffixText;
this.#lineCount = 0;
for (const line of stripAnsi(fullText).split('\n')) {
this.#lineCount += Math.max(1, Math.ceil(stringWidth(line, {countAnsiEscapeCodes: true}) / columns));
updateLineCount() {
const columns = this.stream.columns || 80;
const fullPrefixText = this.getFullPrefixText(this.prefixText, '-');
this.lineCount = 0;
for (const line of stripAnsi(fullPrefixText + '--' + this[TEXT]).split('\n')) {
this.lineCount += Math.max(1, Math.ceil(wcwidth(line) / columns));
}
}
get isEnabled() {
return this.#isEnabled && !this.#isSilent;
return this._isEnabled && !this.isSilent;
}
set isEnabled(value) {
@@ -207,11 +229,11 @@ class Ora {
throw new TypeError('The `isEnabled` option must be a boolean');
}
this.#isEnabled = value;
this._isEnabled = value;
}
get isSilent() {
return this.#isSilent;
return this._isSilent;
}
set isSilent(value) {
@@ -219,65 +241,51 @@ class Ora {
throw new TypeError('The `isSilent` option must be a boolean');
}
this.#isSilent = value;
this._isSilent = value;
}
frame() {
// Ensure we only update the spinner frame at the wanted interval,
// even if the render method is called more often.
const now = Date.now();
if (this.#frameIndex === -1 || now - this.#lastSpinnerFrameTime >= this.interval) {
this.#frameIndex = ++this.#frameIndex % this.#spinner.frames.length;
this.#lastSpinnerFrameTime = now;
}
const {frames} = this.#spinner;
let frame = frames[this.#frameIndex];
const {frames} = this.spinner;
let frame = frames[this.frameIndex];
if (this.color) {
frame = chalk[this.color](frame);
}
const fullPrefixText = (typeof this.#prefixText === 'string' && this.#prefixText !== '') ? this.#prefixText + ' ' : '';
this.frameIndex = ++this.frameIndex % frames.length;
const fullPrefixText = (typeof this.prefixText === 'string' && this.prefixText !== '') ? this.prefixText + ' ' : '';
const fullText = typeof this.text === 'string' ? ' ' + this.text : '';
const fullSuffixText = (typeof this.#suffixText === 'string' && this.#suffixText !== '') ? ' ' + this.#suffixText : '';
return fullPrefixText + frame + fullText + fullSuffixText;
return fullPrefixText + frame + fullText;
}
clear() {
if (!this.#isEnabled || !this.#stream.isTTY) {
if (!this.isEnabled || !this.stream.isTTY) {
return this;
}
this.#stream.cursorTo(0);
for (let index = 0; index < this.#linesToClear; index++) {
if (index > 0) {
this.#stream.moveCursor(0, -1);
for (let i = 0; i < this.linesToClear; i++) {
if (i > 0) {
this.stream.moveCursor(0, -1);
}
this.#stream.clearLine(1);
this.stream.clearLine();
this.stream.cursorTo(this.indent);
}
if (this.#indent || this.lastIndent !== this.#indent) {
this.#stream.cursorTo(this.#indent);
}
this.lastIndent = this.#indent;
this.#linesToClear = 0;
this.linesToClear = 0;
return this;
}
render() {
if (this.#isSilent) {
if (this.isSilent) {
return this;
}
this.clear();
this.#stream.write(this.frame());
this.#linesToClear = this.#lineCount;
this.stream.write(this.frame());
this.linesToClear = this.lineCount;
return this;
}
@@ -287,13 +295,13 @@ class Ora {
this.text = text;
}
if (this.#isSilent) {
if (this.isSilent) {
return this;
}
if (!this.#isEnabled) {
if (!this.isEnabled) {
if (this.text) {
this.#stream.write(`- ${this.text}\n`);
this.stream.write(`- ${this.text}\n`);
}
return this;
@@ -303,37 +311,37 @@ class Ora {
return this;
}
if (this.#options.hideCursor) {
cliCursor.hide(this.#stream);
if (this.hideCursor) {
cliCursor.hide(this.stream);
}
if (this.#options.discardStdin && process.stdin.isTTY) {
this.#isDiscardingStdin = true;
if (this.discardStdin && process.stdin.isTTY) {
this.isDiscardingStdin = true;
stdinDiscarder.start();
}
this.render();
this.#id = setInterval(this.render.bind(this), this.interval);
this.id = setInterval(this.render.bind(this), this.interval);
return this;
}
stop() {
if (!this.#isEnabled) {
if (!this.isEnabled) {
return this;
}
clearInterval(this.#id);
this.#id = undefined;
this.#frameIndex = 0;
clearInterval(this.id);
this.id = undefined;
this.frameIndex = 0;
this.clear();
if (this.#options.hideCursor) {
cliCursor.show(this.#stream);
if (this.hideCursor) {
cliCursor.show(this.stream);
}
if (this.#options.discardStdin && process.stdin.isTTY && this.#isDiscardingStdin) {
if (this.discardStdin && process.stdin.isTTY && this.isDiscardingStdin) {
stdinDiscarder.stop();
this.#isDiscardingStdin = false;
this.isDiscardingStdin = false;
}
return this;
@@ -356,69 +364,44 @@ class Ora {
}
stopAndPersist(options = {}) {
if (this.#isSilent) {
if (this.isSilent) {
return this;
}
const prefixText = options.prefixText ?? this.#prefixText;
const fullPrefixText = this.#getFullPrefixText(prefixText, ' ');
const symbolText = options.symbol ?? ' ';
const text = options.text ?? this.text;
const separatorText = symbolText ? ' ' : '';
const fullText = (typeof text === 'string') ? separatorText + text : '';
const suffixText = options.suffixText ?? this.#suffixText;
const fullSuffixText = this.#getFullSuffixText(suffixText, ' ');
const textToWrite = fullPrefixText + symbolText + fullText + fullSuffixText + '\n';
const prefixText = options.prefixText || this.prefixText;
const text = options.text || this.text;
const fullText = (typeof text === 'string') ? ' ' + text : '';
this.stop();
this.#stream.write(textToWrite);
this.stream.write(`${this.getFullPrefixText(prefixText, ' ')}${options.symbol || ' '}${fullText}\n`);
return this;
}
}
export default function ora(options) {
const oraFactory = function (options) {
return new Ora(options);
}
};
export async function oraPromise(action, options) {
const actionIsFunction = typeof action === 'function';
const actionIsPromise = typeof action.then === 'function';
module.exports = oraFactory;
if (!actionIsFunction && !actionIsPromise) {
throw new TypeError('Parameter `action` must be a Function or a Promise');
module.exports.promise = (action, options) => {
// eslint-disable-next-line promise/prefer-await-to-then
if (typeof action.then !== 'function') {
throw new TypeError('Parameter `action` must be a Promise');
}
const {successText, failText} = typeof options === 'object'
? options
: {successText: undefined, failText: undefined};
const spinner = new Ora(options);
spinner.start();
const spinner = ora(options).start();
(async () => {
try {
await action;
spinner.succeed();
} catch {
spinner.fail();
}
})();
try {
const promise = actionIsFunction ? action(spinner) : action;
const result = await promise;
spinner.succeed(
successText === undefined
? undefined
: (typeof successText === 'string' ? successText : successText(result)),
);
return result;
} catch (error) {
spinner.fail(
failText === undefined
? undefined
: (typeof failText === 'string' ? failText : failText(error)),
);
throw error;
}
}
export {default as spinners} from 'cli-spinners';
return spinner;
};