Skip to content

Commit ed35b65

Browse files
committed
fix: adjust middleware
1 parent 246c780 commit ed35b65

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

packages/cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Each example is fully tested to demonstrate best practices for plugin testing as
212212
| **`--persist.outputDir`** | `string` | n/a | Directory for the produced reports. |
213213
| **`--persist.filename`** | `string` | `report` | Filename for the produced reports without extension. |
214214
| **`--persist.format`** | `('json' \| 'md')[]` | `json` | Format(s) of the report file. |
215-
| **`--persist.skipReports`** | `boolean` | `false` | Skip generating report files. (useful in combination with caching) |
215+
| **`--persist.skipReports`** | `boolean` | `false` | Skip generating report files. (useful in combination with caching) |
216216
| **`--upload.organization`** | `string` | n/a | Organization slug from portal. |
217217
| **`--upload.project`** | `string` | n/a | Project slug from portal. |
218218
| **`--upload.server`** | `string` | n/a | URL to your portal server. |

packages/cli/src/lib/implementation/core-config.middleware.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ export type CoreConfigMiddlewareOptions = GeneralCliOptions &
1515
CoreConfigCliOptions &
1616
FilterOptions;
1717

18+
function buildPersistConfig(
19+
cliPersist: CoreConfigCliOptions['persist'],
20+
rcPersist: CoreConfig['persist'],
21+
): Required<CoreConfig['persist']> {
22+
return {
23+
outputDir:
24+
cliPersist?.outputDir ??
25+
rcPersist?.outputDir ??
26+
DEFAULT_PERSIST_OUTPUT_DIR,
27+
filename:
28+
cliPersist?.filename ?? rcPersist?.filename ?? DEFAULT_PERSIST_FILENAME,
29+
format: normalizeFormats(
30+
cliPersist?.format ?? rcPersist?.format ?? DEFAULT_PERSIST_FORMAT,
31+
),
32+
skipReports: cliPersist?.skipReports ?? rcPersist?.skipReports ?? false,
33+
};
34+
}
35+
1836
export async function coreConfigMiddleware<
1937
T extends CoreConfigMiddlewareOptions,
2038
>(processArgs: T): Promise<GeneralCliOptions & CoreConfig & FilterOptions> {
@@ -43,18 +61,7 @@ export async function coreConfigMiddleware<
4361
});
4462
return {
4563
...(config != null && { config }),
46-
persist: {
47-
outputDir:
48-
cliPersist?.outputDir ??
49-
rcPersist?.outputDir ??
50-
DEFAULT_PERSIST_OUTPUT_DIR,
51-
filename:
52-
cliPersist?.filename ?? rcPersist?.filename ?? DEFAULT_PERSIST_FILENAME,
53-
format: normalizeFormats(
54-
cliPersist?.format ?? rcPersist?.format ?? DEFAULT_PERSIST_FORMAT,
55-
),
56-
skipReports: cliPersist?.skipReports ?? rcPersist?.skipReports ?? false,
57-
},
64+
persist: buildPersistConfig(cliPersist, rcPersist),
5865
...(upload != null && { upload }),
5966
...remainingRcConfig,
6067
...remainingCliOptions,

packages/core/src/lib/collect-and-persist.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export async function collectAndPersistReports(
3535
const { persist } = options;
3636
const { skipReports = false, ...persistOptions } = persist ?? {};
3737

38-
if (skipReports !== true) {
38+
if (skipReports === true) {
39+
logger.info('Skipping saving reports as `persist.skipReports` is true');
40+
} else {
3941
const persistResults = await persistReport(
4042
reportResult,
4143
sortedScoredReport,
@@ -45,8 +47,6 @@ export async function collectAndPersistReports(
4547
if (isVerbose()) {
4648
logPersistedResults(persistResults);
4749
}
48-
} else {
49-
logger.info('Skipping saving reports as `persist.skipReports` is true');
5050
}
5151

5252
// terminal output

0 commit comments

Comments
 (0)