Skip to content

Commit e4dc78e

Browse files
authored
fix: redirect bundling problems to stderr instead on stdout (#2541)
1 parent aebca51 commit e4dc78e

File tree

11 files changed

+31
-12
lines changed

11 files changed

+31
-12
lines changed

.changeset/major-icons-talk.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@redocly/respect-core": patch
3+
"@redocly/openapi-core": patch
4+
"@redocly/cli": patch
5+
---
6+
7+
Redirected bundling problems (such as lint errors and warnings) to stderr instead of stdout to avoid interfering with the bundled output.

packages/cli/src/__tests__/commands/lint.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ describe('handleLint', () => {
160160
maxProblems: 2,
161161
totals: { errors: 0 },
162162
version: '2.0.0',
163+
command: 'lint',
163164
});
164165
expect(getExecutionTime).toHaveBeenCalledWith(42);
165166
});

packages/cli/src/commands/bundle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export async function handleBundle({
111111
format: 'codeframe',
112112
totals: fileTotals,
113113
version,
114+
command: 'bundle',
114115
});
115116

116117
if (argv.metafile) {
@@ -131,7 +132,7 @@ export async function handleBundle({
131132
)} with errors ${green(elapsed)}.\n${yellow('Errors ignored because of --force')}.\n`
132133
);
133134
} else {
134-
logger.info(
135+
logger.error(
135136
`❌ Errors encountered while bundling ${blue(
136137
formatPath(path)
137138
)}: bundle not created (use --force to ignore errors).\n`

packages/cli/src/commands/join.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export async function handleJoin({
147147
formatProblems(problems, {
148148
totals: fileTotals,
149149
version: packageVersion,
150+
command: 'join',
150151
});
151152
exitWithError(
152153
`❌ Errors encountered while bundling ${blue(

packages/cli/src/commands/lint.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export async function handleLint({
103103
maxProblems: argv['max-problems'],
104104
totals: fileTotals,
105105
version,
106+
command: 'lint',
106107
});
107108
}
108109

@@ -153,6 +154,7 @@ export async function handleLintConfig(argv: Exact<CommandArgv>, version: string
153154
maxProblems: argv['max-problems'],
154155
totals: fileTotals,
155156
version,
157+
command: 'check-config',
156158
});
157159

158160
printConfigLintTotals(fileTotals, command);

packages/core/src/format/format.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export function formatProblems(
8787
color?: boolean;
8888
totals: Totals;
8989
version?: string;
90+
command?: 'bundle' | 'lint' | 'join' | 'check-config';
9091
}
9192
) {
9293
const {
@@ -96,6 +97,7 @@ export function formatProblems(
9697
color = colorOptions.enabled,
9798
totals = getTotals(problems),
9899
version = '2.0',
100+
command,
99101
} = opts;
100102

101103
colorOptions.enabled = color; // force colors if specified
@@ -117,7 +119,11 @@ export function formatProblems(
117119
case 'codeframe':
118120
for (let i = 0; i < problems.length; i++) {
119121
const problem = problems[i];
120-
logger.output(`${formatCodeframe(problem, i)}\n`);
122+
if (command === 'bundle') {
123+
logger.info(`${formatCodeframe(problem, i)}\n`);
124+
} else {
125+
logger.output(`${formatCodeframe(problem, i)}\n`);
126+
}
121127
}
122128
break;
123129
case 'stylish': {

packages/respect-core/src/modules/flow-runner/get-test-description-from-file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export async function bundleArazzo(options: BundleArazzoOptions) {
6666
formatProblems(lintProblems, {
6767
totals: fileTotals,
6868
version,
69+
command: 'bundle',
6970
});
7071

7172
printConfigLintTotals(fileTotals, options.logger);

tests/e2e/bundle/bundle-external-value/snapshot.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ paths:
3232
type: object
3333
externalValue: ./external-value.json
3434
components: {}
35+
36+
bundling test-success.yaml using configuration for api 'first'...
37+
📦 Created a bundle for test-success.yaml at stdout <test>ms.
38+
bundling test-wrong-examples.yaml using configuration for api 'second'...
3539
[1] test-wrong-examples.yaml:27:17 at #/paths/~1/post/requestBody/content/application~1xml/examples/test-wrong-ref
3640

3741
Can't resolve $ref: ENOENT: no such file or directory './tests/e2e/bundle/bundle-external-value/external-value-bad-path.json'
@@ -47,8 +51,4 @@ Can't resolve $ref: ENOENT: no such file or directory './tests/e2e/bundle/bundle
4751
Error was generated by the bundler rule.
4852

4953

50-
51-
bundling test-success.yaml using configuration for api 'first'...
52-
📦 Created a bundle for test-success.yaml at stdout <test>ms.
53-
bundling test-wrong-examples.yaml using configuration for api 'second'...
5454
❌ Errors encountered while bundling test-wrong-examples.yaml: bundle not created (use --force to ignore errors).

tests/e2e/bundle/info-description-override-error/snapshot.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
bundling main.yaml using configuration for api 'main'...
13
[1] main.yaml:8:16 at #/info/description
24

35
Failed to read markdown override file for "info.description".
@@ -13,6 +15,4 @@ ENOENT: no such file or directory, open './tests/e2e/bundle/info-description-ove
1315
Error was generated by the info-description-override rule.
1416

1517

16-
17-
bundling main.yaml using configuration for api 'main'...
1818
❌ Errors encountered while bundling main.yaml: bundle not created (use --force to ignore errors).

tests/e2e/bundle/operation-description-override-error/snapshot.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
bundling openapi.yaml using configuration for api 'main'...
13
[1] openapi.yaml:23:7 at #/paths/~1pet/put/operationId
24

35
Failed to read markdown override file for operation "updatePet".
@@ -13,6 +15,4 @@ ENOENT: no such file or directory, open './tests/e2e/bundle/operation-descriptio
1315
Error was generated by the operation-description-override rule.
1416

1517

16-
17-
bundling openapi.yaml using configuration for api 'main'...
1818
❌ Errors encountered while bundling openapi.yaml: bundle not created (use --force to ignore errors).

0 commit comments

Comments
 (0)