Repository navigation
Conversation
ebb3b5b to
26aa3a2
Compare
| // @ts-expect-error TS(7006) FIXME: Parameter 'optionA' implicitly has an 'any' type. | ||
| export const sortOptions = (optionA, optionB) => { | ||
| export const compareOptions = (optionA: Option, optionB: Option): number => { | ||
| const longOptionA = optionA.long ?? '' |
There was a problem hiding this comment.
Though we always define one, an option is allowed to have no long variant
| // FIXME(serhalp) This logic can't be right? Look at it... This must only happen to work. | ||
| if (BASE_FLAGS.has(longOptionA) || BASE_FLAGS.has(longOptionB)) { | ||
| return -1 | ||
| } |
There was a problem hiding this comment.
Reviewer, am I tripping? This should be something like this, right?
| // FIXME(serhalp) This logic can't be right? Look at it... This must only happen to work. | |
| if (BASE_FLAGS.has(longOptionA) || BASE_FLAGS.has(longOptionB)) { | |
| return -1 | |
| } | |
| if (BASE_FLAGS.has(longOptionA)) { | |
| return 1 // A is a base flag, it should come last | |
| } else if (BASE_FLAGS.has(longOptionB)) { | |
| return -1 // B is a base flag, it should come last | |
| } |
There was a problem hiding this comment.
Your suggestion looks to be correct. A negative value indicates that a should come before b, and a positive value indicates that a should come after b.
26aa3a2 to
4b74afe
Compare
chalk with smaller ansis
d3883ca to
664df79
Compare
chalk with smaller ansischalk with smaller and faster ansis
664df79 to
13eeded
Compare
| // This is not possible, but since the fixed set of choices contains one dynamically interpolated string, | ||
| // we can't tell TS that these are exhaustive values | ||
| return logAndThrowError(new Error('Invalid link type selected')) |
| nodeOptions: [], | ||
| env: { | ||
| // TODO(serhalp) Why not exercise colorization in integration tests? Remove and update snapshots? | ||
| NO_COLOR: '1', |
There was a problem hiding this comment.
chalk was doing this magically in our tests, so this is just preserving that behaviour for now
There was a problem hiding this comment.
some tests failed because expected /^VERSION/ but received the string \u001b[1mVERSION\u001b[22m\n containing ANSI codes.
Ansis automatically detects CI environments as supported color.
To force disable color should be created separate file with the NO_COLOR variable, e.g. no-color.js:
// set env variable to force disable color
process.env.NO_COLOR = '1';This file must be imported in the test file before other files used ansis:
import { expect, describe, test } from 'vitest';
// import env variables to force disable color
import './no-color.js';
// ... import othersAlternatively, you can use the ansis.strip() function to clean a string from ANSI codes:
import { expect, describe, test } from 'vitest';
import ansis from 'ansis';
// ...
expect(ansis.strip(stdout.trim()), `Help command does not start with 'VERSION':\n\n${ansis.strip(stdout)}`).toMatch(/^VERSION/)See please the no-color.test.js
98e3f92 to
3513229
Compare
3513229 to
f39e193
Compare
Oops and I got carried away and fixed a lot of types along the way.
f39e193 to
46ca5d8
Compare
|
|
||
| try { | ||
| log(`${NETLIFYDEVLOG} updating site settings with ${chalk.magenta.inverse(functionsDir)}`) | ||
| log(`${NETLIFYDEVLOG} updating site settings with ${ansis.inverse(ansis.magenta(functionsDir))}`) |
There was a problem hiding this comment.
Hello @serhalp, I'm curious why nested calls are often used in some cases, while chained syntax is preferred in others.
Ansis supports both, but chaining is shorter, more readable, and performs better:
- log(`${NETLIFYDEVLOG} updating site settings with ${chalk.magenta.inverse(functionsDir)}`)
+ log(`${NETLIFYDEVLOG} updating site settings with ${ansis.magenta.inverse(functionsDir)}`)| "@pnpm/tabtab": "0.5.4", | ||
| "ansi-escapes": "7.0.0", | ||
| "ansi-to-html": "0.7.2", | ||
| "ansis": "^3.17.0", |
There was a problem hiding this comment.
@serhalp,
meanwhile I have released a new version - 4.0.0.
This release brings a stable and more compact ANSI library.
v4 is ~15.7% smaller than v3.17.
Co-authored-by: serhalp <[email protected]>
|
PR is stale and full of conflicts, value is minimal, closing. keeping type fixes in #7383. |
Co-authored-by: serhalp <[email protected]>
Summary
Replace
chalkwithansis: https://github.com/webdiscus/ansis?tab=readme-ov-file#how-to-switch-to-ansis-1.Honestly, I did this before realizing the savings are absolutely tiny (44 KB → 6 KB), but I fixed a few types along the way so we might as well ship it.