Skip to content

Commit

Permalink
chore: remove useless deps (#63)
Browse files Browse the repository at this point in the history
* refactor: remove strip-ansi

* chore: remove is-ci

* chore: remove is-unicode-supported
  • Loading branch information
fraxken authored Nov 28, 2023
1 parent 166d2bf commit 31ac33d
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 15 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
},
"dependencies": {
"@topcli/wcwidth": "^1.0.1",
"is-ci": "^3.0.1",
"is-unicode-supported": "^2.0.0",
"kleur": "^4.1.5",
"strip-ansi": "^7.1.0"
"kleur": "^4.1.5"
},
"engines": {
"node": ">=14"
Expand Down
4 changes: 3 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Import Third-party Dependencies
import kleur from "kleur";
import isUnicodeSupported from "is-unicode-supported";

// Import Internal Dependencies
import { isUnicodeSupported } from "./utils.js";

const kMainSymbols = {
tick: "✔",
Expand Down
4 changes: 1 addition & 3 deletions src/prompts/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { EOL } from "node:os";
import { createInterface } from "node:readline";
import { Writable } from "node:stream";

// Import Third-party Dependencies
import stripAnsi from "strip-ansi";

// Import Internal Dependencies
import { stripAnsi } from "../utils.js";
import { PromptAgent } from "../prompt-agent.js";

export class AbstractPrompt {
Expand Down
2 changes: 1 addition & 1 deletion src/prompts/confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { EOL } from "node:os";

// Import Third-party Dependencies
import kleur from "kleur";
import stripAnsi from "strip-ansi";
import wcwidth from "@topcli/wcwidth";

// Import Internal Dependencies
import { AbstractPrompt } from "./abstract.js";
import { stripAnsi } from "../utils.js";
import { SYMBOLS } from "../constants.js";

// CONSTANTS
Expand Down
2 changes: 1 addition & 1 deletion src/prompts/multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { EOL } from "node:os";

// Import Third-party Dependencies
import kleur from "kleur";
import stripAnsi from "strip-ansi";
import wcwidth from "@topcli/wcwidth";

// Import Internal Dependencies
import { AbstractPrompt } from "./abstract.js";
import { stripAnsi } from "../utils.js";
import { SYMBOLS } from "../constants.js";

export class MultiselectPrompt extends AbstractPrompt {
Expand Down
2 changes: 1 addition & 1 deletion src/prompts/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { EOL } from "node:os";

// Import Third-party Dependencies
import kleur from "kleur";
import stripAnsi from "strip-ansi";
import wcwidth from "@topcli/wcwidth";

// Import Internal Dependencies
import { AbstractPrompt } from "./abstract.js";
import { stripAnsi } from "../utils.js";
import { SYMBOLS } from "../constants.js";

export class QuestionPrompt extends AbstractPrompt {
Expand Down
2 changes: 1 addition & 1 deletion src/prompts/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { EOL } from "node:os";

// Import Third-party Dependencies
import kleur from "kleur";
import stripAnsi from "strip-ansi";
import wcwidth from "@topcli/wcwidth";

// Import Internal Dependencies
import { AbstractPrompt } from "./abstract.js";
import { stripAnsi } from "../utils.js";
import { SYMBOLS } from "../constants.js";

export class SelectPrompt extends AbstractPrompt {
Expand Down
43 changes: 43 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import process from "node:process";

// CONSTANTS
const kAnsiRegex = ansiRegex();

/**
* @see https://github.com/chalk/ansi-regex
*/
export function ansiRegex({onlyFirst = false} = {}) {
const pattern = [
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
].join('|');

return new RegExp(pattern, onlyFirst ? undefined : 'g');
}

/**
* @param {!string} string
* @returns {string}
*/
export function stripAnsi(string) {
return string.replace(kAnsiRegex, "");
}

/**
* @see https://github.com/sindresorhus/is-unicode-supported
* @returns {boolean}
*/
export function isUnicodeSupported() {
if (process.platform !== 'win32') {
return process.env.TERM !== 'linux'; // Linux console (kernel)
}

return Boolean(process.env.WT_SESSION) // Windows Terminal
|| Boolean(process.env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
|| process.env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
|| process.env.TERM_PROGRAM === 'Terminus-Sublime'
|| process.env.TERM_PROGRAM === 'vscode'
|| process.env.TERM === 'xterm-256color'
|| process.env.TERM === 'alacritty'
|| process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
}
4 changes: 2 additions & 2 deletions test/helpers/mock-process.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Import Node.js Dependencies
import { EOL } from "node:os";

// Import Third-party Dependencies
import stripAnsi from "strip-ansi";
// Import Internal Dependencies
import { stripAnsi } from "../../src/utils.js";

export function mockProcess(inputs, writeCb) {
const stdout = {
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/testing-prompt.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Import Third-party Dependencies
import stripAnsi from "strip-ansi";
import esmock from "esmock";

// Import Internal Dependencies
import { stripAnsi } from "../../src/utils.js";
import { mockProcess } from "./mock-process.js";

export class TestingPrompt {
Expand Down

0 comments on commit 31ac33d

Please sign in to comment.