Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deps and restore "supports-color" #1264

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/lint-staged.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { isColorSupported } from 'colorette'
import { Option, program } from 'commander'
import debug from 'debug'
import supportsColor from 'supports-color'

import lintStaged from '../lib/index.js'
import { CONFIG_STDIN_ERROR } from '../lib/messages.js'

// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
if (isColorSupported) {
process.env.FORCE_COLOR = '1'
if (supportsColor.stdout) {
process.env.FORCE_COLOR = supportsColor.stdout.level.toString()
}

// Do not terminate main Listr process on SIGINT
Expand Down
8 changes: 4 additions & 4 deletions lib/figures.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { blue, redBright, yellow } from 'colorette'
import chalk from 'chalk'
import { figures } from 'listr2'

export const info = blue(figures.arrowRight)
export const info = chalk.blue(figures.arrowRight)

export const error = redBright(figures.cross)
export const error = chalk.redBright(figures.cross)

export const warning = yellow(figures.warning)
export const warning = chalk.yellow(figures.warning)
26 changes: 14 additions & 12 deletions lib/messages.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { redBright, bold, yellow } from 'colorette'
import chalk from 'chalk'
import inspect from 'object-inspect'

import { error, info, warning } from './figures.js'

export const configurationError = (opt, helpMsg, value) =>
`${redBright(`${error} Validation Error:`)}
`${chalk.redBright(`${error} Validation Error:`)}

Invalid value for '${bold(opt)}': ${bold(
Invalid value for '${chalk.bold(opt)}': ${chalk.bold(
inspect(value, { inlineCharacterLimit: Number.POSITIVE_INFINITY })
)}

${helpMsg}`

export const NOT_GIT_REPO = redBright(`${error} Current directory is not a git directory!`)
export const NOT_GIT_REPO = chalk.redBright(`${error} Current directory is not a git directory!`)

export const FAILED_GET_STAGED_FILES = redBright(`${error} Failed to get staged files!`)
export const FAILED_GET_STAGED_FILES = chalk.redBright(`${error} Failed to get staged files!`)

export const incorrectBraces = (before, after) =>
yellow(
chalk.yellow(
`${warning} Detected incorrect braces with only single value: \`${before}\`. Reformatted as: \`${after}\`
`
)
Expand All @@ -36,10 +36,10 @@ export const skippingBackup = (hasInitialCommit, diff) => {
? '`--no-stash` was used'
: 'there’s no initial commit yet'

return yellow(`${warning} Skipping backup because ${reason}.\n`)
return chalk.yellow(`${warning} Skipping backup because ${reason}.\n`)
}

export const DEPRECATED_GIT_ADD = yellow(
export const DEPRECATED_GIT_ADD = chalk.yellow(
`${warning} Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.
`
)
Expand All @@ -48,18 +48,20 @@ export const TASK_ERROR = 'Skipped because of errors from tasks.'

export const SKIPPED_GIT_ERROR = 'Skipped because of previous git error.'

export const GIT_ERROR = `\n ${redBright(`${error} lint-staged failed due to a git error.`)}`
export const GIT_ERROR = `\n ${chalk.redBright(`${error} lint-staged failed due to a git error.`)}`

export const invalidOption = (name, value, message) => `${redBright(`${error} Validation Error:`)}
export const invalidOption = (name, value, message) => `${chalk.redBright(
`${error} Validation Error:`
)}

Invalid value for option '${bold(name)}': ${bold(value)}
Invalid value for option '${chalk.bold(name)}': ${chalk.bold(value)}

${message}

See https://github.com/okonet/lint-staged#command-line-flags`

export const PREVENTED_EMPTY_COMMIT = `
${yellow(`${warning} lint-staged prevented an empty git commit.
${chalk.yellow(`${warning} lint-staged prevented an empty git commit.
Use the --allow-empty option to continue, or check your task configuration`)}
`

Expand Down
8 changes: 4 additions & 4 deletions lib/resolveTaskFn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { redBright, dim } from 'colorette'
import chalk from 'chalk'
import { execa, execaCommand } from 'execa'
import debug from 'debug'
import { parseArgsStringToArgv } from 'string-argv'
Expand Down Expand Up @@ -32,7 +32,7 @@ const handleOutput = (command, result, ctx, isError = false) => {
const hasOutput = !!stderr || !!stdout

if (hasOutput) {
const outputTitle = isError ? redBright(`${error} ${command}:`) : `${info} ${command}:`
const outputTitle = isError ? chalk.redBright(`${error} ${command}:`) : `${info} ${command}:`
const output = []
.concat(ctx.quiet ? [] : ['', outputTitle])
.concat(stderr ? stderr : [])
Expand All @@ -41,7 +41,7 @@ const handleOutput = (command, result, ctx, isError = false) => {
} else if (isError) {
// Show generic error when task had no output
const tag = getTag(result)
const message = redBright(`\n${error} ${command} failed without output (${tag}).`)
const message = chalk.redBright(`\n${error} ${command} failed without output (${tag}).`)
if (!ctx.quiet) ctx.output.push(message)
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ const makeErr = (command, result, ctx) => {

handleOutput(command, result, ctx, true)
const tag = getTag(result)
return new Error(`${redBright(command)} ${dim(`[${tag}]`)}`)
return new Error(`${chalk.redBright(command)} ${chalk.dim(`[${tag}]`)}`)
}

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/runAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import path from 'node:path'

import { dim } from 'colorette'
import chalk from 'chalk'
import debug from 'debug'
import { Listr } from 'listr2'
import normalize from 'normalize-path'
Expand Down Expand Up @@ -204,7 +204,7 @@ export const runAll = async (
const fileCount = task.fileList.length

return {
title: `${task.pattern}${dim(
title: `${task.pattern}${chalk.dim(
` — ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`
)}`,
task: async (ctx, task) =>
Expand All @@ -216,7 +216,7 @@ export const runAll = async (
skip: () => {
// Skip task when no files matched
if (fileCount === 0) {
return `${task.pattern}${dim(' — no files')}`
return `${task.pattern}${chalk.dim(' — no files')}`
}
return false
},
Expand All @@ -227,15 +227,15 @@ export const runAll = async (

listrTasks.push({
title:
`${configName}${dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
(chunkCount > 1 ? dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
`${configName}${chalk.dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
(chunkCount > 1 ? chalk.dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
task: (ctx, task) => task.newListr(chunkListrTasks, { concurrent, exitOnError: true }),
skip: () => {
// Skip if the first step (backup) failed
if (ctx.errors.has(GitError)) return SKIPPED_GIT_ERROR
// Skip chunk when no every task is skipped (due to no matches)
if (chunkListrTasks.every((task) => task.skip())) {
return `${configName}${dim(' — no tasks to run')}`
return `${configName}${chalk.dim(' — no tasks to run')}`
}
return false
},
Expand Down
Loading