feat(logger): new "url" format, add double quotes around paths (#7019)

* refactor(logger): add double quotes around paths

* Introduce url formatter

* Fix
This commit is contained in:
Alexey Pyltsyn 2022-03-27 09:59:20 +03:00 committed by GitHub
parent 2bcac29cd4
commit a307da0b9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 11 deletions

View file

@ -11,7 +11,12 @@ import logger from '../index';
describe('formatters', () => {
it('path', () => {
// cSpell:ignore mhey
expect(logger.path('hey')).toMatchInlineSnapshot(`"hey"`);
expect(logger.path('hey')).toMatchInlineSnapshot(`"\\"hey\\""`);
});
it('url', () => {
expect(logger.url('https://docusaurus.io/')).toMatchInlineSnapshot(
`"https://docusaurus.io/"`,
);
});
it('id', () => {
expect(logger.name('hey')).toMatchInlineSnapshot(`"hey"`);
@ -40,8 +45,7 @@ describe('interpolate', () => {
expect(
logger.interpolate`The package at path=${'packages/docusaurus'} has number=${10} files. name=${'Babel'} is exported here subdue=${'(as a preset)'} that you can with code=${"require.resolve('@docusaurus/core/lib/babel/preset')"}`,
).toMatchInlineSnapshot(
// cSpell:ignore mpackages
`"The package at packages/docusaurus has 10 files. Babel is exported here (as a preset) that you can with \`require.resolve('@docusaurus/core/lib/babel/preset')\`"`,
`"The package at \\"packages/docusaurus\\" has 10 files. Babel is exported here (as a preset) that you can with \`require.resolve('@docusaurus/core/lib/babel/preset')\`"`,
);
});
it('interpolates arrays with flags', () => {

View file

@ -9,7 +9,8 @@ import chalk, {type Chalk} from 'chalk';
type InterpolatableValue = string | number | (string | number)[];
const path = (msg: unknown): string => chalk.cyan(chalk.underline(msg));
const path = (msg: unknown): string => chalk.cyan(chalk.underline(`"${msg}"`));
const url = (msg: unknown): string => chalk.cyan(chalk.underline(msg));
const name = (msg: unknown): string => chalk.blue(chalk.bold(msg));
const code = (msg: unknown): string => chalk.cyan(`\`${msg}\``);
const subdue: Chalk = chalk.gray;
@ -30,6 +31,8 @@ function interpolate(
switch (flag[0]) {
case 'path=':
return path;
case 'url=':
return url;
case 'number=':
return num;
case 'name=':
@ -131,6 +134,7 @@ const logger = {
bold: chalk.bold,
dim: chalk.dim,
path,
url,
name,
code,
subdue,