Skip to content

Commit

Permalink
fix: use ansis instead of chalk
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed May 23, 2024
1 parent 4d3852e commit 61aad8b
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/oclif/plugin-plugins/issues",
"dependencies": {
"@oclif/core": "4.0.0-beta.10",
"chalk": "^5.3.0",
"ansis": "^3.2.0",
"debug": "^4.3.4",
"npm": "^10.8.0",
"npm-package-arg": "^11.0.2",
Expand Down
12 changes: 6 additions & 6 deletions src/commands/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Command, Flags, Interfaces, Plugin} from '@oclif/core'
import chalk from 'chalk'
import {dim} from 'ansis'
// @ts-expect-error because object-treeify does not have types: https://github.com/blackflux/object-treeify/issues/1077
import treeify from 'object-treeify'

Expand Down Expand Up @@ -79,17 +79,17 @@ export default class PluginsIndex extends Command {

private displayJitPlugins(jitPlugins: JitPlugin[]) {
if (jitPlugins.length === 0) return
this.log(chalk.dim('\nUninstalled JIT Plugins:'))
this.log(dim('\nUninstalled JIT Plugins:'))
for (const {name, version} of jitPlugins) {
this.log(`${this.plugins.friendlyName(name)} ${chalk.dim(version)}`)
this.log(`${this.plugins.friendlyName(name)} ${dim(version)}`)
}
}

private formatPlugin(plugin: Plugin): string {
let output = `${this.plugins.friendlyName(plugin.name)} ${chalk.dim(plugin.version)}`
if (plugin.type !== 'user') output += chalk.dim(` (${plugin.type})`)
let output = `${this.plugins.friendlyName(plugin.name)} ${dim(plugin.version)}`
if (plugin.type !== 'user') output += dim(` (${plugin.type})`)
if (plugin.type === 'link') output += ` ${plugin.root}`
else if (plugin.tag && plugin.tag !== 'latest') output += chalk.dim(` (${String(plugin.tag)})`)
else if (plugin.tag && plugin.tag !== 'latest') output += dim(` (${String(plugin.tag)})`)
return output
}
}
8 changes: 4 additions & 4 deletions src/commands/plugins/inspect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Args, Command, Flags, Plugin} from '@oclif/core'
import chalk from 'chalk'
import {bold, dim} from 'ansis'
import {readFile} from 'node:fs/promises'
import {dirname, join, sep} from 'node:path'
// @ts-expect-error because object-treeify does not have types: https://github.com/blackflux/object-treeify/issues/1077
Expand Down Expand Up @@ -113,15 +113,15 @@ export default class PluginsInspect extends Command {
if (!version) continue

const from = plugin.pjson.dependencies?.[dep]
const versionMsg = chalk.dim(from ? `${from} => ${version}` : version)
const versionMsg = dim(from ? `${from} => ${version}` : version)
const msg = verbose ? `${dep} ${versionMsg} ${pkgPath}` : `${dep} ${versionMsg}`

dependencies[msg] = null
depsJson[dep] = {from, version}
}

const tree = {
[chalk.bold.cyan(plugin.name)]: {
[bold.cyan(plugin.name)]: {
[`version ${plugin.version}`]: null,
...(plugin.tag ? {[`tag ${plugin.tag}`]: null} : {}),
...(plugin.pjson.homepage ? {[`homepage ${plugin.pjson.homepage}`]: null} : {}),
Expand Down Expand Up @@ -158,7 +158,7 @@ export default class PluginsInspect extends Command {
try {
plugins.push(await this.inspect(pluginName, flags.verbose))
} catch (error) {
this.log(chalk.bold.red('failed'))
this.log(bold.red('failed'))
throw error
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/commands/plugins/install.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-await-in-loop */
import {Args, Command, Errors, Flags, Interfaces, ux} from '@oclif/core'
import chalk from 'chalk'
import {bold, cyan} from 'ansis'
import validate from 'validate-npm-package-name'

import {determineLogLevel} from '../../log-level.js'
Expand Down Expand Up @@ -160,19 +160,17 @@ Use the <%= config.scopedEnvVarKey('NPM_REGISTRY') %> environment variable to se
})
try {
if (p.type === 'npm') {
ux.action.start(
`${this.config.name}: Installing plugin ${chalk.cyan(plugins.friendlyName(p.name) + '@' + p.tag)}`,
)
ux.action.start(`${this.config.name}: Installing plugin ${cyan(plugins.friendlyName(p.name) + '@' + p.tag)}`)
plugin = await plugins.install(p.name, {
force: flags.force,
tag: p.tag,
})
} else {
ux.action.start(`${this.config.name}: Installing plugin ${chalk.cyan(p.url)}`)
ux.action.start(`${this.config.name}: Installing plugin ${cyan(p.url)}`)
plugin = await plugins.install(p.url, {force: flags.force})
}
} catch (error) {
ux.action.stop(chalk.bold.red('failed'))
ux.action.stop(bold.red('failed'))
throw error
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/plugins/link.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Args, Command, Flags, ux} from '@oclif/core'
import chalk from 'chalk'
import {cyan} from 'ansis'

import {determineLogLevel} from '../../log-level.js'
import Plugins from '../../plugins.js'
Expand Down Expand Up @@ -35,7 +35,7 @@ e.g. If you have a user-installed or core plugin that has a 'hello' command, ins
logLevel: determineLogLevel(this.config, flags, 'silent'),
})

ux.action.start(`${this.config.name}: Linking plugin ${chalk.cyan(args.path)}`)
ux.action.start(`${this.config.name}: Linking plugin ${cyan(args.path)}`)
await plugins.link(args.path, {install: flags.install})
ux.action.stop()
}
Expand Down
8 changes: 4 additions & 4 deletions src/commands/plugins/reset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-await-in-loop */
import {Command, Flags} from '@oclif/core'
import chalk from 'chalk'
import {dim} from 'ansis'
import {rm} from 'node:fs/promises'
import {join} from 'node:path'

Expand Down Expand Up @@ -28,7 +28,7 @@ export default class Reset extends Command {
this.log(`Found ${userPlugins.length} plugin${userPlugins.length === 0 ? '' : 's'}:`)
for (const plugin of userPlugins) {
this.log(
`- ${plugin.name} ${chalk.dim(this.config.plugins.get(plugin.name)?.version)} ${chalk.dim(`(${plugin.type})`)}`,
`- ${plugin.name} ${dim(this.config.plugins.get(plugin.name)?.version ?? '')} ${dim(`(${plugin.type})`)}`,
)
}

Expand Down Expand Up @@ -68,7 +68,7 @@ export default class Reset extends Command {
if (plugin.type === 'link') {
try {
const newPlugin = await plugins.link(plugin.root, {install: false})
const newVersion = chalk.dim(`-> ${newPlugin.version}`)
const newVersion = dim(`-> ${newPlugin.version}`)
this.log(`✅ Relinked ${plugin.name} ${newVersion}`)
} catch {
this.warn(`Failed to relink ${plugin.name}`)
Expand All @@ -80,7 +80,7 @@ export default class Reset extends Command {
const newPlugin = plugin.url
? await plugins.install(plugin.url)
: await plugins.install(plugin.name, {tag: plugin.tag})
const newVersion = chalk.dim(`-> ${newPlugin.version}`)
const newVersion = dim(`-> ${newPlugin.version}`)
const tag = plugin.tag ? `@${plugin.tag}` : plugin.url ? ` (${plugin.url})` : ''
this.log(`✅ Reinstalled ${plugin.name}${tag} ${newVersion}`)
} catch {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/plugins/uninstall.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-await-in-loop */
import {Args, Command, Flags, ux} from '@oclif/core'
import chalk from 'chalk'
import {bold} from 'ansis'

import {determineLogLevel} from '../../log-level.js'
import Plugins from '../../plugins.js'
Expand Down Expand Up @@ -68,7 +68,7 @@ export default class PluginsUninstall extends Command {
ux.action.start(`${this.config.name}: Uninstalling ${displayName}`)
await plugins.uninstall(name)
} catch (error) {
ux.action.stop(chalk.bold.red('failed'))
ux.action.stop(bold.red('failed'))
throw error
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Config, Errors, Interfaces, ux} from '@oclif/core'
import chalk from 'chalk'
import {bold} from 'ansis'
import makeDebug from 'debug'
import {spawn} from 'node:child_process'
import {access, mkdir, readFile, rename, rm, writeFile} from 'node:fs/promises'
Expand Down Expand Up @@ -68,7 +68,7 @@ function extractIssuesLocation(
function notifyUser(plugin: Config, output: Output): void {
const containsWarnings = [...output.stdout, ...output.stderr].some((l) => l.includes('npm WARN'))
if (containsWarnings) {
ux.stderr(chalk.bold.yellow(`\nThese warnings can only be addressed by the owner(s) of ${plugin.name}.`))
ux.stderr(bold.yellow(`\nThese warnings can only be addressed by the owner(s) of ${plugin.name}.`))

if (plugin.pjson.bugs || plugin.pjson.repository) {
ux.stderr(
Expand Down
8 changes: 4 additions & 4 deletions test/integration/install.integration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Errors, ux} from '@oclif/core'
import {dim} from 'ansis'
import {expect} from 'chai'
import chalk from 'chalk'
import {rm} from 'node:fs/promises'
import {join, resolve} from 'node:path'
import {SinonSandbox, SinonStub, createSandbox, match} from 'sinon'
Expand All @@ -18,9 +18,9 @@ describe('install/uninstall integration tests', () => {
const configDir = join(tmp, 'plugin-plugins-tests', 'config')
const dataDir = join(tmp, 'plugin-plugins-tests', 'data')

console.log('process.env.MYCLI_DATA_DIR:', chalk.dim(dataDir))
console.log('process.env.MYCLI_CACHE_DIR:', chalk.dim(cacheDir))
console.log('process.env.MYCLI_CONFIG_DIR:', chalk.dim(configDir))
console.log('process.env.MYCLI_DATA_DIR:', dim(dataDir))
console.log('process.env.MYCLI_CACHE_DIR:', dim(cacheDir))
console.log('process.env.MYCLI_CONFIG_DIR:', dim(configDir))

const cwd = process.cwd()

Expand Down
10 changes: 5 additions & 5 deletions test/integration/sf.integration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {dim} from 'ansis'
import {expect} from 'chai'
import chalk from 'chalk'
import {exec as cpExec} from 'node:child_process'
import {mkdir, rm, writeFile} from 'node:fs/promises'
import {join, resolve} from 'node:path'
Expand All @@ -19,7 +19,7 @@ async function exec(command: string): Promise<{code: number; stderr: string; std
async function ensureSfExists(): Promise<boolean> {
try {
const {stdout} = await exec('sf --version')
console.log('sf version:', chalk.dim(stdout.trim()))
console.log('sf version:', dim(stdout.trim()))
return true
} catch {
return false
Expand All @@ -35,9 +35,9 @@ describe('sf Integration', () => {
process.env.SF_CACHE_DIR = join(tmp, 'cache')
process.env.SF_CONFIG_DIR = join(tmp, 'config')

console.log('process.env.SF_DATA_DIR:', chalk.dim(process.env.SF_DATA_DIR))
console.log('process.env.SF_CACHE_DIR:', chalk.dim(process.env.SF_CACHE_DIR))
console.log('process.env.SF_CONFIG_DIR:', chalk.dim(process.env.SF_CONFIG_DIR))
console.log('process.env.SF_DATA_DIR:', dim(process.env.SF_DATA_DIR))
console.log('process.env.SF_CACHE_DIR:', dim(process.env.SF_CACHE_DIR))
console.log('process.env.SF_CONFIG_DIR:', dim(process.env.SF_CONFIG_DIR))

try {
// no need to clear out directories in CI since they'll always be empty
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3016,7 +3016,7 @@ ansicolors@~0.3.2:
resolved "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz"
integrity sha512-QXu7BPrP29VllRxH8GwB7x5iX5qWKAAMLqKQGWTeLWVlNHNOpVMJ91dsxQAIWXpjuW5wqvxu3Jd/nRjrJ+0pqg==

ansis@^3.0.1:
ansis@^3.0.1, ansis@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/ansis/-/ansis-3.2.0.tgz#0e050c5be94784f32ffdac4b84fccba064aeae4b"
integrity sha512-Yk3BkHH9U7oPyCN3gL5Tc7CpahG/+UFv/6UG03C311Vy9lzRmA5uoxDTpU9CO3rGHL6KzJz/pdDeXZCZ5Mu/Sg==
Expand Down

0 comments on commit 61aad8b

Please sign in to comment.