Skip to content

Commit 67abfb7

Browse files
committed
feat(cli): add --tsconfig option
1 parent 474625c commit 67abfb7

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ export async function coreConfigMiddleware<
1313
const args = processArgs;
1414
const {
1515
config,
16+
tsconfig,
1617
persist: cliPersist,
1718
upload: cliUpload,
1819
...remainingCliOptions
1920
} = args as GeneralCliOptions & Required<CoreConfig>;
2021
// if config path is given use it otherwise auto-load
21-
const importedRc = config ? await readRcByPath(config) : await autoloadRc();
22+
const importedRc = config
23+
? await readRcByPath(config, tsconfig)
24+
: await autoloadRc(tsconfig);
2225
const {
2326
persist: rcPersist,
2427
upload: rcUpload,

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export type UploadConfigCliOptions = {
1515
};
1616
/* eslint-enable @typescript-eslint/naming-convention */
1717

18-
export type ConfigCliOptions = { config: string };
18+
export type ConfigCliOptions = {
19+
config: string;
20+
tsconfig?: string;
21+
};
1922

2023
export type CoreConfigCliOptions = ConfigCliOptions &
2124
PersistConfigCliOptions &

packages/cli/src/lib/implementation/global.options.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ export function yargsGlobalOptionsDefinition(): Record<
1919
},
2020
config: {
2121
describe:
22-
'Path the the config file, e.g. code-pushup.config.ts. By default it loads code-pushup.config.(ts|mjs|js).',
22+
'Path to config file, e.g. code-pushup.config.ts. By default it loads code-pushup.config.(ts|mjs|js).',
23+
type: 'string',
24+
},
25+
tsconfig: {
26+
describe:
27+
'Path to a TypeScript config, to be used when loading config file.',
2328
type: 'string',
2429
},
2530
};

packages/core/src/lib/implementation/read-rc-file.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export class ConfigPathError extends Error {
1313
}
1414
}
1515

16-
export async function readRcByPath(filepath: string): Promise<CoreConfig> {
16+
export async function readRcByPath(
17+
filepath: string,
18+
tsconfig?: string,
19+
): Promise<CoreConfig> {
1720
if (filepath.length === 0) {
1821
throw new Error('The path to the configuration file is empty.');
1922
}
@@ -22,12 +25,12 @@ export async function readRcByPath(filepath: string): Promise<CoreConfig> {
2225
throw new ConfigPathError(filepath);
2326
}
2427

25-
const cfg = await importEsmModule({ filepath });
28+
const cfg = await importEsmModule({ filepath, tsconfig });
2629

2730
return coreConfigSchema.parse(cfg);
2831
}
2932

30-
export async function autoloadRc(): Promise<CoreConfig> {
33+
export async function autoloadRc(tsconfig?: string): Promise<CoreConfig> {
3134
// eslint-disable-next-line functional/no-let
3235
let ext = '';
3336
// eslint-disable-next-line functional/no-loop-statements
@@ -49,5 +52,8 @@ export async function autoloadRc(): Promise<CoreConfig> {
4952
);
5053
}
5154

52-
return readRcByPath(join(process.cwd(), `${CONFIG_FILE_NAME}.${ext}`));
55+
return readRcByPath(
56+
join(process.cwd(), `${CONFIG_FILE_NAME}.${ext}`),
57+
tsconfig,
58+
);
5359
}

packages/core/src/lib/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type GlobalOptions = {
2-
// 'Show progress bar in stdout'
2+
// Show progress bar in stdout
33
progress: boolean;
4-
// Outputs additional information for a run'
4+
// Outputs additional information for a run
55
verbose: boolean;
66
};

0 commit comments

Comments
 (0)