Skip to content

Commit aec9136

Browse files
committed
chore: fix output formatting
1 parent 704ee33 commit aec9136

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

__tests__/miscellaneous/apply-per-api-decorators/snapshot.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ components:
3737
3838
bundling nested/openapi/main.yaml...
3939
📦 Created a bundle for nested/openapi/main.yaml at stdout <test>ms.
40-
bundling https:/raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml...
41-
📦 Created a bundle for https:/raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml at stdout <test>ms.
40+
bundling https://raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml...
41+
📦 Created a bundle for https://raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml at stdout <test>ms.
4242
4343
`;
4444

4545
exports[`E2E miscellaneous lint a specific api (when the api is specified as an alias and it points to an external URL) 1`] = `
4646
47-
validating https:/raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml...
47+
validating https://raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml...
4848
[1] https://raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml:2:1 at #/info/contact
4949
5050
Info object should contain \`contact\` field.
@@ -58,7 +58,7 @@ Info object should contain \`contact\` field.
5858
Error was generated by the info-contact rule.
5959
6060
61-
https:/raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml: validated in <test>ms
61+
https://raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml: validated in <test>ms
6262
6363
❌ Validation failed with 1 error.
6464
run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.

packages/cli/src/commands/bundle.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
saveBundle,
1414
sortTopLevelKeysForOas,
1515
checkForDeprecatedOptions,
16+
formatPath,
1617
} from '../utils/miscellaneous';
1718

1819
import type { OutputExtensions, Skips, Totals, VerifyConfigOptions } from '../types';
@@ -55,7 +56,7 @@ export async function handleBundle({
5556
styleguide.skipPreprocessors(argv['skip-preprocessor']);
5657
styleguide.skipDecorators(argv['skip-decorator']);
5758

58-
process.stderr.write(gray(`bundling ${relative(process.cwd(), path)}...\n`));
59+
process.stderr.write(gray(`bundling ${formatPath(path)}...\n`));
5960

6061
const {
6162
bundle: result,
@@ -118,20 +119,20 @@ export async function handleBundle({
118119
if (fileTotals.errors > 0) {
119120
if (argv.force) {
120121
process.stderr.write(
121-
`❓ Created a bundle for ${blue(relative(process.cwd(), path))} at ${blue(
122+
`❓ Created a bundle for ${blue(formatPath(path))} at ${blue(
122123
outputFile || 'stdout'
123124
)} with errors ${green(elapsed)}.\n${yellow('Errors ignored because of --force')}.\n`
124125
);
125126
} else {
126127
process.stderr.write(
127128
`❌ Errors encountered while bundling ${blue(
128-
relative(process.cwd(), path)
129+
formatPath(path)
129130
)}: bundle not created (use --force to ignore errors).\n`
130131
);
131132
}
132133
} else {
133134
process.stderr.write(
134-
`📦 Created a bundle for ${blue(relative(process.cwd(), path))} at ${blue(
135+
`📦 Created a bundle for ${blue(formatPath(path))} at ${blue(
135136
outputFile || 'stdout'
136137
)} ${green(elapsed)}.\n`
137138
);

packages/cli/src/commands/lint.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { pluralize } from '@redocly/openapi-core/lib/utils';
1313
import {
1414
checkIfRulesetExist,
1515
exitWithError,
16+
formatPath,
1617
getExecutionTime,
1718
getFallbackApisOrExit,
1819
handleError,
@@ -75,7 +76,7 @@ export async function handleLint({
7576
)} configuration by default.\n\n`
7677
);
7778
}
78-
process.stderr.write(gray(`validating ${relative(process.cwd(), path)}...\n`));
79+
process.stderr.write(gray(`validating ${formatPath(path)}...\n`));
7980
const results = await lint({
8081
ref: path,
8182
config: resolvedConfig,
@@ -102,7 +103,7 @@ export async function handleLint({
102103
}
103104

104105
const elapsed = getExecutionTime(startedAt);
105-
process.stderr.write(gray(`${relative(process.cwd(), path)}: validated in ${elapsed}\n\n`));
106+
process.stderr.write(gray(`${formatPath(path)}: validated in ${elapsed}\n\n`));
106107
} catch (e) {
107108
handleError(e, path);
108109
}

packages/cli/src/utils/miscellaneous.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function getFallbackApisOrExit(
5757
if (isNotEmptyArray(filteredInvalidEntrypoints)) {
5858
for (const { path } of filteredInvalidEntrypoints) {
5959
process.stderr.write(
60-
yellow(`\n${relative(process.cwd(), path)} ${red(`does not exist or is invalid.\n\n`)}`)
60+
yellow(`\n${formatPath(path)} ${red(`does not exist or is invalid.\n\n`)}`)
6161
);
6262
}
6363
exitWithError('Please provide a valid path.');
@@ -702,3 +702,10 @@ export function notifyAboutIncompatibleConfigOptions(
702702
}
703703
}
704704
}
705+
706+
export function formatPath(path: string) {
707+
if (isAbsoluteUrl(path)) {
708+
return path;
709+
}
710+
return relative(process.cwd(), path);
711+
}

0 commit comments

Comments
 (0)