Skip to content

Commit

Permalink
Implements enableMessageNames (#2513)
Browse files Browse the repository at this point in the history
* Allows disabling the message names

* Versions
  • Loading branch information
arcanis committed Feb 24, 2021
1 parent f6436fd commit 2da8101
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
30 changes: 30 additions & 0 deletions .yarn/versions/c958a387.yml
@@ -0,0 +1,30 @@
releases:
"@yarnpkg/cli": minor
"@yarnpkg/core": minor

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-node-modules"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/pnpify"
5 changes: 5 additions & 0 deletions packages/yarnpkg-core/sources/Configuration.ts
Expand Up @@ -236,6 +236,11 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} =
default: isCI,
defaultText: `<dynamic>`,
},
enableMessageNames: {
description: `If true, the CLI will prefix most messages with codes suitable for search engines`,
type: SettingsType.BOOLEAN,
default: true,
},
enableProgressBars: {
description: `If true, the CLI is allowed to show a progress bar for long-running events`,
type: SettingsType.BOOLEAN,
Expand Down
25 changes: 21 additions & 4 deletions packages/yarnpkg-core/sources/StreamReport.ts
Expand Up @@ -78,6 +78,9 @@ const defaultStyle = (supportsEmojis && Object.keys(PROGRESS_STYLES).find(name =
})) || `default`;

export function formatName(name: MessageName | null, {configuration, json}: {configuration: Configuration, json: boolean}) {
if (!configuration.get(`enableMessageNames`))
return ``;

const num = name === null ? 0 : name;
const label = stringifyMessageName(num);

Expand All @@ -90,6 +93,8 @@ export function formatName(name: MessageName | null, {configuration, json}: {con

export function formatNameWithHyperlink(name: MessageName | null, {configuration, json}: {configuration: Configuration, json: boolean}) {
const code = formatName(name, {configuration, json});
if (!code)
return code;

// Only print hyperlinks if allowed per configuration
if (!configuration.get(`enableHyperlinks`))
Expand Down Expand Up @@ -360,7 +365,10 @@ export class StreamReport extends Report {

this.commit();

const message = `${formatUtils.pretty(this.configuration, `➤`, `blueBright`)} ${this.formatNameWithHyperlink(name)}: ${this.formatIndent()}${text}`;
const formattedName = this.formatNameWithHyperlink(name);
const prefix = formattedName ? `${formattedName}: ` : ``;

const message = `${formatUtils.pretty(this.configuration, `➤`, `blueBright`)} ${prefix}${this.formatIndent()}${text}`;

if (!this.json) {
if (this.forgettableNames.has(name)) {
Expand Down Expand Up @@ -389,8 +397,11 @@ export class StreamReport extends Report {

this.commit();

const formattedName = this.formatNameWithHyperlink(name);
const prefix = formattedName ? `${formattedName}: ` : ``;

if (!this.json) {
this.writeLineWithForgettableReset(`${formatUtils.pretty(this.configuration, `➤`, `yellowBright`)} ${this.formatNameWithHyperlink(name)}: ${this.formatIndent()}${text}`);
this.writeLineWithForgettableReset(`${formatUtils.pretty(this.configuration, `➤`, `yellowBright`)} ${prefix}${this.formatIndent()}${text}`);
} else {
this.reportJson({type: `warning`, name, displayName: this.formatName(name), indent: this.formatIndent(), data: text});
}
Expand All @@ -401,8 +412,11 @@ export class StreamReport extends Report {

this.commit();

const formattedName = this.formatNameWithHyperlink(name);
const prefix = formattedName ? `${formattedName}: ` : ``;

if (!this.json) {
this.writeLineWithForgettableReset(`${formatUtils.pretty(this.configuration, `➤`, `redBright`)} ${this.formatNameWithHyperlink(name)}: ${this.formatIndent()}${text}`, {truncate: false});
this.writeLineWithForgettableReset(`${formatUtils.pretty(this.configuration, `➤`, `redBright`)} ${prefix}${this.formatIndent()}${text}`, {truncate: false});
} else {
this.reportJson({type: `error`, name, displayName: this.formatName(name), indent: this.formatIndent(), data: text});
}
Expand Down Expand Up @@ -584,7 +598,10 @@ export class StreamReport extends Report {
const ok = this.progressStyle.chars[0].repeat(progress.lastScaledSize);
const ko = this.progressStyle.chars[1].repeat(this.progressMaxScaledSize - progress.lastScaledSize);

this.stdout.write(`${formatUtils.pretty(this.configuration, `➤`, `blueBright`)} ${this.formatName(null)}: ${spinner} ${ok}${ko}\n`);
const formattedName = this.formatName(null);
const prefix = formattedName ? `${formattedName}: ` : ``;

this.stdout.write(`${formatUtils.pretty(this.configuration, `➤`, `blueBright`)} ${prefix}${spinner} ${ok}${ko}\n`);
}

this.progressTimeout = setTimeout(() => {
Expand Down

0 comments on commit 2da8101

Please sign in to comment.