Skip to content

Commit 26aa3a2

Browse files
committed
fix(deps): replace chalk with lightweight picocolors
Oops and I got carried away and fixed a lot of types along the way.
1 parent 0b9d4f5 commit 26aa3a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+498
-517
lines changed

Diff for: package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
"ascii-table": "0.0.9",
9191
"backoff": "2.5.0",
9292
"boxen": "8.0.1",
93-
"chalk": "5.4.1",
9493
"chokidar": "3.6.0",
9594
"ci-info": "4.1.0",
9695
"clean-deep": "3.4.0",
@@ -153,6 +152,7 @@
153152
"parallel-transform": "1.2.0",
154153
"parse-github-url": "1.0.3",
155154
"parse-gitignore": "2.0.0",
155+
"picocolors": "^1.1.1",
156156
"prettyjson": "1.2.5",
157157
"pump": "3.0.2",
158158
"raw-body": "3.0.0",

Diff for: scripts/postinstall.js

+8-34
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
11
import process from 'process'
22

3-
import chalk from 'chalk'
3+
import pc from 'picocolors'
44

55
import { createMainCommand } from '../dist/commands/index.js'
66
import { generateAutocompletion } from '../dist/lib/completion/index.js'
77

8-
const id = (message) => message
9-
10-
/**
11-
*
12-
* @param {string} message
13-
* @param {Array<chalk['Color'] | chalk['Modifiers']>} styles
14-
* @returns
15-
*/
16-
const format = (message, styles) => {
17-
let func = id
18-
try {
19-
func = chalk
20-
styles.forEach((style) => {
21-
func = func[style]
22-
})
23-
} catch {}
24-
return func(message)
25-
}
26-
27-
const postInstall = async () => {
8+
const postInstall = () => {
289
// yarn plug and play seems to have an issue with reading an esm file by building up the cache.
2910
// as yarn pnp analyzes everything inside the postinstall
3011
// yarn pnp executes it out of a .yarn folder .yarn/unplugged/netlify-cli-file-fb026a3a6d/node_modules/netlify-cli/scripts/postinstall.js
@@ -35,25 +16,18 @@ const postInstall = async () => {
3516
}
3617

3718
console.log('')
38-
console.log(await format('Success! Netlify CLI has been installed!', ['greenBright', 'bold', 'underline']))
19+
console.log(pc.greenBright(pc.bold(pc.underline('Success! Netlify CLI has been installed!'))))
3920
console.log('')
4021
console.log('Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.')
4122
console.log('')
4223
console.log('Next steps:')
4324
console.log('')
44-
console.log(
45-
` ${await format('netlify init', [
46-
'cyanBright',
47-
'bold',
48-
])} Connect or create a Netlify site from current directory`,
49-
)
50-
console.log(
51-
` ${await format('netlify deploy', ['cyanBright', 'bold'])} Deploy the latest changes to your Netlify site`,
52-
)
25+
console.log(` ${pc.cyanBright(pc.bold('netlify init'))} Connect or create a Netlify site from current directory`)
26+
console.log(` ${pc.cyanBright(pc.bold('netlify deploy'))} Deploy the latest changes to your Netlify site`)
5327
console.log('')
54-
console.log(`For more information on the CLI run ${await format('netlify help', ['cyanBright', 'bold'])}`)
55-
console.log(`Or visit the docs at ${await format('https://cli.netlify.com', ['cyanBright', 'bold'])}`)
28+
console.log(`For more information on the CLI run ${pc.cyanBright(pc.bold('netlify help'))}`)
29+
console.log(`Or visit the docs at ${pc.cyanBright(pc.bold('https://cli.netlify.com'))}`)
5630
console.log('')
5731
}
5832

59-
await postInstall()
33+
postInstall()

Diff for: site/scripts/util/generate-command-data.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createMainCommand } from '../../../dist/commands/index.js'
2-
import { sortOptions } from '../../../dist/utils/command-helpers.js'
2+
import { compareOptions } from '../../../dist/utils/command-helpers.js'
33

44
const program = createMainCommand()
55

@@ -19,7 +19,7 @@ const parseCommand = function (command) {
1919

2020
const flags = command.options
2121
.filter((option) => !option.hidden)
22-
.sort(sortOptions)
22+
.sort(compareOptions)
2323
.reduce((prev, cur) => {
2424
const name = cur.long.replace('--', '')
2525
const contentType = cur.argChoices ? cur.argChoices.join(' | ') : 'string'

Diff for: src/commands/api/api.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import AsciiTable from 'ascii-table'
22
import { OptionValues } from 'commander'
33
import { methods } from 'netlify'
44

5-
import { chalk, error, exit, log, logJson } from '../../utils/command-helpers.js'
5+
import { picocolors, error, exit, log, logJson } from '../../utils/command-helpers.js'
66
import BaseCommand from '../base-command.js'
77

88
export const apiCommand = async (apiMethod: string, options: OptionValues, command: BaseCommand) => {
@@ -18,7 +18,7 @@ export const apiCommand = async (apiMethod: string, options: OptionValues, comma
1818
log(table.toString())
1919
log()
2020
log('Above is a list of available API methods')
21-
log(`To run a method use "${chalk.cyanBright('netlify api methodName')}"`)
21+
log(`To run a method use "${picocolors.cyanBright('netlify api methodName')}"`)
2222
exit()
2323
}
2424

Diff for: src/commands/api/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { chalk } from '../../utils/command-helpers.js'
1+
import { picocolors } from '../../utils/command-helpers.js'
22
import BaseCommand from '../base-command.js'
33

44
export const createApiCommand = (program: BaseCommand) =>
@@ -7,7 +7,7 @@ export const createApiCommand = (program: BaseCommand) =>
77
.argument('[apiMethod]', 'Open API method to run')
88
.description(
99
`Run any Netlify API method
10-
For more information on available methods checkout https://open-api.netlify.com/ or run '${chalk.grey(
10+
For more information on available methods checkout https://open-api.netlify.com/ or run '${picocolors.gray(
1111
'netlify api --list',
1212
)}'`,
1313
)

Diff for: src/commands/base-command.ts

+17-18
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { getAgent } from '../lib/http-agent.js'
1919
import {
2020
NETLIFY_CYAN,
2121
USER_AGENT,
22-
chalk,
22+
picocolors,
2323
error,
2424
exit,
2525
getToken,
@@ -28,7 +28,7 @@ import {
2828
normalizeConfig,
2929
padLeft,
3030
pollForToken,
31-
sortOptions,
31+
compareOptions,
3232
warn,
3333
} from '../utils/command-helpers.js'
3434
import { FeatureFlags } from '../utils/feature-flags.js'
@@ -106,7 +106,7 @@ async function selectWorkspace(project: Project, filter?: string): Promise<strin
106106

107107
if (!selected) {
108108
log()
109-
log(chalk.cyan(`We've detected multiple sites inside your repository`))
109+
log(picocolors.cyan(`We've detected multiple sites inside your repository`))
110110

111111
if (isCI) {
112112
throw new Error(
@@ -128,7 +128,7 @@ async function selectWorkspace(project: Project, filter?: string): Promise<strin
128128
(project.workspace?.packages || [])
129129
.filter((pkg) => pkg.path.includes(input))
130130
.map((pkg) => ({
131-
name: `${pkg.name ? `${chalk.bold(pkg.name)} ` : ''}${pkg.path} ${chalk.dim(
131+
name: `${pkg.name ? `${picocolors.bold(pkg.name)} ` : ''}${pkg.path} ${picocolors.dim(
132132
`--filter ${pkg.name || pkg.path}`,
133133
)}`,
134134
value: pkg.path,
@@ -287,7 +287,7 @@ export default class BaseCommand extends Command {
287287

288288
if (description) {
289289
const pad = termWidth + HELP_SEPARATOR_WIDTH
290-
const fullText = `${bang}${term.padEnd(pad - (isCommand ? 2 : 0))}${chalk.grey(description)}`
290+
const fullText = `${bang}${term.padEnd(pad - (isCommand ? 2 : 0))}${picocolors.gray(description)}`
291291
return helper.wrap(fullText, helpWidth - HELP_INDENT_WIDTH, pad)
292292
}
293293

@@ -304,34 +304,34 @@ export default class BaseCommand extends Command {
304304

305305
// on the parent help command the version should be displayed
306306
if (this.name() === 'netlify') {
307-
output = [...output, chalk.bold('VERSION'), formatHelpList([formatItem(USER_AGENT)]), '']
307+
output = [...output, picocolors.bold('VERSION'), formatHelpList([formatItem(USER_AGENT)]), '']
308308
}
309309

310310
// Usage
311-
output = [...output, chalk.bold('USAGE'), helper.commandUsage(command), '']
311+
output = [...output, picocolors.bold('USAGE'), helper.commandUsage(command), '']
312312

313313
// Arguments
314314
const argumentList = helper
315315
.visibleArguments(command)
316316
.map((argument) => formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument)))
317317
if (argumentList.length !== 0) {
318-
output = [...output, chalk.bold('ARGUMENTS'), formatHelpList(argumentList), '']
318+
output = [...output, picocolors.bold('ARGUMENTS'), formatHelpList(argumentList), '']
319319
}
320320

321321
if (command.#noBaseOptions === false) {
322322
// Options
323323
const optionList = helper
324324
.visibleOptions(command)
325-
.sort(sortOptions)
325+
.sort(compareOptions)
326326
.map((option) => formatItem(helper.optionTerm(option), helper.optionDescription(option)))
327327
if (optionList.length !== 0) {
328-
output = [...output, chalk.bold('OPTIONS'), formatHelpList(optionList), '']
328+
output = [...output, picocolors.bold('OPTIONS'), formatHelpList(optionList), '']
329329
}
330330
}
331331

332332
// Description
333333
if (commandDescription.length !== 0) {
334-
output = [...output, chalk.bold('DESCRIPTION'), formatHelpList(commandDescription), '']
334+
output = [...output, picocolors.bold('DESCRIPTION'), formatHelpList(commandDescription), '']
335335
}
336336

337337
// Aliases
@@ -340,13 +340,13 @@ export default class BaseCommand extends Command {
340340
if (command._aliases.length !== 0) {
341341
// @ts-expect-error TS(2551) FIXME: Property '_aliases' does not exist on type 'Comman... Remove this comment to see the full error message
342342
const aliases = command._aliases.map((alias) => formatItem(`${parentCommand.name()} ${alias}`, null, true))
343-
output = [...output, chalk.bold('ALIASES'), formatHelpList(aliases), '']
343+
output = [...output, picocolors.bold('ALIASES'), formatHelpList(aliases), '']
344344
}
345345

346346
if (command.examples.length !== 0) {
347347
output = [
348348
...output,
349-
chalk.bold('EXAMPLES'),
349+
picocolors.bold('EXAMPLES'),
350350
formatHelpList(command.examples.map((example) => `${HELP_$} ${example}`)),
351351
'',
352352
]
@@ -356,7 +356,7 @@ export default class BaseCommand extends Command {
356356
formatItem(cmd.name(), helper.subcommandDescription(cmd).split('\n')[0], true),
357357
)
358358
if (commandList.length !== 0) {
359-
output = [...output, chalk.bold('COMMANDS'), formatHelpList(commandList), '']
359+
output = [...output, picocolors.bold('COMMANDS'), formatHelpList(commandList), '']
360360
}
361361

362362
return [...output, ''].join('\n')
@@ -410,7 +410,6 @@ export default class BaseCommand extends Command {
410410
const authLink = `${webUI}/authorize?response_type=ticket&ticket=${ticket.id}`
411411

412412
log(`Opening ${authLink}`)
413-
// @ts-expect-error TS(2345) FIXME: Argument of type '{ url: string; }' is not assigna... Remove this comment to see the full error message
414413
await openBrowser({ url: authLink })
415414

416415
const accessToken = await pollForToken({
@@ -448,11 +447,11 @@ export default class BaseCommand extends Command {
448447

449448
// Log success
450449
log()
451-
log(`${chalk.greenBright('You are now logged into your Netlify account!')}`)
450+
log(`${picocolors.greenBright('You are now logged into your Netlify account!')}`)
452451
log()
453-
log(`Run ${chalk.cyanBright('netlify status')} for account details`)
452+
log(`Run ${picocolors.cyanBright('netlify status')} for account details`)
454453
log()
455-
log(`To see all available commands run: ${chalk.cyanBright('netlify help')}`)
454+
log(`To see all available commands run: ${picocolors.cyanBright('netlify help')}`)
456455
log()
457456
return accessToken
458457
}

Diff for: src/commands/blobs/blobs-delete.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getStore } from '@netlify/blobs'
22

3-
import { chalk, error as printError, log } from '../../utils/command-helpers.js'
3+
import { picocolors, error as printError, log } from '../../utils/command-helpers.js'
44
import { promptBlobDelete } from '../../utils/prompts/blob-delete-prompts.js'
55

66
/**
@@ -24,8 +24,12 @@ export const blobsDelete = async (storeName: string, key: string, _options: Reco
2424
try {
2525
await store.delete(key)
2626

27-
log(`${chalk.greenBright('Success')}: Blob ${chalk.yellow(key)} deleted from store ${chalk.yellow(storeName)}`)
27+
log(
28+
`${picocolors.greenBright('Success')}: Blob ${picocolors.yellow(key)} deleted from store ${picocolors.yellow(
29+
storeName,
30+
)}`,
31+
)
2832
} catch {
29-
return printError(`Could not delete blob ${chalk.yellow(key)} from store ${chalk.yellow(storeName)}`)
33+
return printError(`Could not delete blob ${picocolors.yellow(key)} from store ${picocolors.yellow(storeName)}`)
3034
}
3135
}

Diff for: src/commands/blobs/blobs-get.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { resolve } from 'path'
44
import { getStore } from '@netlify/blobs'
55
import { OptionValues } from 'commander'
66

7-
import { chalk, error as printError } from '../../utils/command-helpers.js'
7+
import { picocolors, error as printError } from '../../utils/command-helpers.js'
88
import BaseCommand from '../base-command.js'
99

1010
interface Options extends OptionValues {
@@ -26,11 +26,11 @@ export const blobsGet = async (storeName: string, key: string, options: Options,
2626
try {
2727
blob = await store.get(key)
2828
} catch {
29-
return printError(`Could not retrieve blob ${chalk.yellow(key)} from store ${chalk.yellow(storeName)}`)
29+
return printError(`Could not retrieve blob ${picocolors.yellow(key)} from store ${picocolors.yellow(storeName)}`)
3030
}
3131

3232
if (blob === null) {
33-
return printError(`Blob ${chalk.yellow(key)} does not exist in store ${chalk.yellow(storeName)}`)
33+
return printError(`Blob ${picocolors.yellow(key)} does not exist in store ${picocolors.yellow(storeName)}`)
3434
}
3535

3636
if (output) {

Diff for: src/commands/blobs/blobs-list.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getStore } from '@netlify/blobs'
22
import AsciiTable from 'ascii-table'
33
import { OptionValues } from 'commander'
44

5-
import { chalk, error as printError, log, logJson } from '../../utils/command-helpers.js'
5+
import { picocolors, error as printError, log, logJson } from '../../utils/command-helpers.js'
66
import BaseCommand from '../base-command.js'
77

88
interface Options extends OptionValues {
@@ -31,7 +31,7 @@ export const blobsList = async (storeName: string, options: Options, command: Ba
3131
}
3232

3333
if (blobs.length === 0 && directories.length === 0) {
34-
return log(`Netlify Blobs store ${chalk.yellow(storeName)} is empty`)
34+
return log(`Netlify Blobs store ${picocolors.yellow(storeName)} is empty`)
3535
}
3636

3737
const table = new AsciiTable(`Netlify Blobs (${storeName})`)
@@ -48,6 +48,6 @@ export const blobsList = async (storeName: string, options: Options, command: Ba
4848

4949
log(table.toString())
5050
} catch {
51-
return printError(`Could not list blobs from store ${chalk.yellow(storeName)}`)
51+
return printError(`Could not list blobs from store ${picocolors.yellow(storeName)}`)
5252
}
5353
}

0 commit comments

Comments
 (0)