From a7bd6fef9a61637458ddf790425efb237473def6 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 5 Sep 2023 13:18:59 +0200 Subject: [PATCH] fix: Remove `picocolor` usage --- lib/Steps/ChooseIntegration.ts | 2 +- package.json | 4 +- src/utils/clack-utils.ts | 5 +- src/utils/vendor/clack-custom-select.ts | 160 ------------------------ yarn.lock | 23 ++-- 5 files changed, 19 insertions(+), 175 deletions(-) delete mode 100644 src/utils/vendor/clack-custom-select.ts diff --git a/lib/Steps/ChooseIntegration.ts b/lib/Steps/ChooseIntegration.ts index 787df042..1a5651f7 100755 --- a/lib/Steps/ChooseIntegration.ts +++ b/lib/Steps/ChooseIntegration.ts @@ -1,6 +1,5 @@ import type { Answers } from 'inquirer'; import { prompt } from 'inquirer'; -import { dim } from 'picocolors'; import { Args, @@ -19,6 +18,7 @@ import { SvelteKitShim } from './Integrations/SvelteKitShim'; import { hasPackageInstalled } from '../../src/utils/package-json'; import { Remix } from './Integrations/Remix'; import { Android } from './Integrations/Android'; +import { dim } from '../Helper/Logging'; let projectPackage: any = {}; diff --git a/package.json b/package.json index 896f8d89..982b4361 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "definition": "dist/index.d.ts" }, "dependencies": { - "@clack/core": "0.3.2", - "@clack/prompts": "0.6.3", + "@clack/core": "0.3.3", + "@clack/prompts": "0.7.0", "@sentry/cli": "^1.72.0", "@sentry/node": "^7.57.0", "axios": "1.3.5", diff --git a/src/utils/clack-utils.ts b/src/utils/clack-utils.ts index e72d739e..09b129cc 100644 --- a/src/utils/clack-utils.ts +++ b/src/utils/clack-utils.ts @@ -8,7 +8,6 @@ import * as path from 'path'; import { setInterval } from 'timers'; import { URL } from 'url'; import * as Sentry from '@sentry/node'; -import { windowedSelect } from './vendor/clack-custom-select'; import { hasPackageInstalled, PackageDotJson } from './package-json'; import { SentryProjectData, WizardOptions } from './types'; import { traceStep } from '../telemetry'; @@ -145,7 +144,7 @@ export async function askForItemSelection( ): Promise<{ value: string; index: number }> { const selection: { value: string; index: number } | symbol = await abortIfCancelled( - windowedSelect({ + clack.select({ maxItems: 12, message: message, options: items.map((item, index) => { @@ -743,7 +742,7 @@ async function askForProjectSelection( projects: SentryProjectData[], ): Promise { const selection: SentryProjectData | symbol = await abortIfCancelled( - windowedSelect({ + clack.select({ maxItems: 12, message: 'Select your Sentry project.', options: projects.map((project) => { diff --git a/src/utils/vendor/clack-custom-select.ts b/src/utils/vendor/clack-custom-select.ts deleted file mode 100644 index ac481ddf..00000000 --- a/src/utils/vendor/clack-custom-select.ts +++ /dev/null @@ -1,160 +0,0 @@ -// Vendored and adjusted from: https://github.com/natemoo-re/clack/blob/593f93d06c1a53c8424e9aaf0c1c63fbf6975527/packages/prompts/src/index.ts -// Upstream PR: https://github.com/natemoo-re/clack/pull/129 - -// MIT License - -// Copyright (c) Nate Moore - -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -// --- - -// `ansi-regex` is adapted from https://github.com/chalk/ansi-regex - -// MIT License - -// Copyright (c) Sindre Sorhus (https://sindresorhus.com) - -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -// --- - -// @ts-ignore -import * as clackCore from '@clack/core'; -import color from 'picocolors'; -import { isUnicodeSupported } from './is-unicorn-supported'; - -const unicode = isUnicodeSupported(); -const s = (c: string, fallback: string) => (unicode ? c : fallback); - -const S_RADIO_ACTIVE = s('●', '>'); -const S_RADIO_INACTIVE = s('○', ' '); -const S_BAR = s('│', '|'); - -const S_STEP_ACTIVE = s('◆', '*'); -const S_STEP_CANCEL = s('■', 'x'); -const S_STEP_ERROR = s('▲', 'x'); -const S_STEP_SUBMIT = s('◇', 'o'); -const S_BAR_END = s('└', '—'); - -const symbol = (state: string) => { - switch (state) { - case 'initial': - case 'active': - return color.cyan(S_STEP_ACTIVE); - case 'cancel': - return color.red(S_STEP_CANCEL); - case 'error': - return color.yellow(S_STEP_ERROR); - case 'submit': - return color.green(S_STEP_SUBMIT); - } -}; - -type Primitive = Readonly; -type Option = Value extends Primitive - ? { value: Value; label?: string; hint?: string } - : { value: Value; label: string; hint?: string }; -export interface SelectOptions[], Value> { - message: string; - options: Options; - initialValue?: Value; - maxItems?: number; -} - -/** - * Like the normal clack select prompt but with a `maxItems` option. - */ -export const windowedSelect = [], Value>( - opts: SelectOptions, -) => { - const opt = ( - option: Option, - state: 'inactive' | 'active' | 'selected' | 'cancelled', - ) => { - const label = option.label ?? String(option.value); - if (state === 'active') { - return `${color.green(S_RADIO_ACTIVE)} ${label} ${ - option.hint ? color.dim(`(${option.hint})`) : '' - }`; - } else if (state === 'selected') { - return `${color.dim(label)}`; - } else if (state === 'cancelled') { - return `${color.strikethrough(color.dim(label))}`; - } - return `${color.dim(S_RADIO_INACTIVE)} ${color.dim(label)}`; - }; - - let slidingWindowLocation = 0; - - return new clackCore.SelectPrompt({ - options: opts.options, - initialValue: opts.initialValue, - render() { - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - const title = `${color.gray(S_BAR)}\n${symbol(this.state)} ${ - opts.message - }\n`; - switch (this.state) { - case 'submit': - return `${title}${color.gray(S_BAR)} ${opt( - this.options[this.cursor], - 'selected', - )}`; - case 'cancel': - return `${title}${color.gray(S_BAR)} ${opt( - this.options[this.cursor], - 'cancelled', - )}\n${color.gray(S_BAR)}`; - default: { - // We clamp to minimum 5 because anything less doesn't make sense UX wise - const maxItems = - opts.maxItems === undefined ? Infinity : Math.max(opts.maxItems, 5); - if (this.cursor >= slidingWindowLocation + maxItems - 3) { - slidingWindowLocation = Math.max( - Math.min( - this.cursor - maxItems + 3, - this.options.length - maxItems, - ), - 0, - ); - } else if (this.cursor < slidingWindowLocation + 2) { - slidingWindowLocation = Math.max(this.cursor - 2, 0); - } - - const shouldRenderTopEllipsis = - maxItems < this.options.length && slidingWindowLocation > 0; - const shouldRenderBottomEllipsis = - maxItems < this.options.length && - slidingWindowLocation + maxItems < this.options.length; - - return `${title}${color.cyan(S_BAR)} ${this.options - .slice(slidingWindowLocation, slidingWindowLocation + maxItems) - .map((option, i, arr) => { - if (i === 0 && shouldRenderTopEllipsis) { - return color.dim('...'); - } else if (i === arr.length - 1 && shouldRenderBottomEllipsis) { - return color.dim('...'); - } else { - return opt( - option, - i + slidingWindowLocation === this.cursor - ? 'active' - : 'inactive', - ); - } - }) - .join(`\n${color.cyan(S_BAR)} `)}\n${color.cyan(S_BAR_END)}\n`; - } - } - }, - }).prompt() as Promise; -}; diff --git a/yarn.lock b/yarn.lock index 3939afaa..d1ae6872 100644 --- a/yarn.lock +++ b/yarn.lock @@ -371,20 +371,20 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@clack/core@0.3.2", "@clack/core@^0.3.2": - version "0.3.2" - resolved "https://registry.yarnpkg.com/@clack/core/-/core-0.3.2.tgz#23c6e440ed263c2f012b1cc0806386481e78420b" - integrity sha512-FZnsNynwGDIDktx6PEZK1EuCkFpY4ldEX6VYvfl0dqeoLPb9Jpw1xoUXaVcGR8ExmYNm1w2vdGdJkEUYD/2pqg== +"@clack/core@0.3.3", "@clack/core@^0.3.3": + version "0.3.3" + resolved "https://registry.yarnpkg.com/@clack/core/-/core-0.3.3.tgz#233ccebf779aa5a66fc68ee48df5e58cd226fd94" + integrity sha512-5ZGyb75BUBjlll6eOa1m/IZBxwk91dooBWhPSL67sWcLS0zt9SnswRL0l26TVdBhb0wnWORRxUn//uH6n4z7+A== dependencies: picocolors "^1.0.0" sisteransi "^1.0.5" -"@clack/prompts@0.6.3": - version "0.6.3" - resolved "https://registry.yarnpkg.com/@clack/prompts/-/prompts-0.6.3.tgz#c6184bb3f8685dfc72207d2ff051f7a6a733fcb3" - integrity sha512-AM+kFmAHawpUQv2q9+mcB6jLKxXGjgu/r2EQjEwujgpCdzrST6BJqYw00GRn56/L/Izw5U7ImoLmy00X/r80Pw== +"@clack/prompts@0.7.0": + version "0.7.0" + resolved "https://registry.yarnpkg.com/@clack/prompts/-/prompts-0.7.0.tgz#6aaef48ea803d91cce12bc80811cfcb8de2e75ea" + integrity sha512-0MhX9/B4iL6Re04jPrttDm+BsP8y6mS7byuv0BvXgdXhbV5PdlsHt55dvNsuBCPZ7xq1oTAOOuotR9NFbQyMSA== dependencies: - "@clack/core" "^0.3.2" + "@clack/core" "^0.3.3" picocolors "^1.0.0" sisteransi "^1.0.5" @@ -2746,6 +2746,11 @@ is-typedarray@^1.0.0: resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo= +is-unicode-supported@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz#d824984b616c292a2e198207d4a609983842f714" + integrity sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ== + is-wsl@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d"