MCPcopy Index your code
hub / github.com/code-pushup/cli / getConfig

Function getConfig

packages/plugin-lighthouse/src/lib/runner/utils.ts:128–177  ·  view source on GitHub ↗
(
  options: ConfigOptions = {},
)

Source from the content-addressed store, hash-verified

126>;
127
128export async function getConfig(
129 options: ConfigOptions = {},
130): Promise<Config | undefined> {
131 const { configPath, preset } = options;
132
133 if (configPath != null) {
134 // Resolve the config file path relative to where cli was called.
135 return logger.task(
136 `Loading lighthouse config from ${configPath}`,
137 async () => {
138 const message = `Loaded lighthouse config from ${configPath}`;
139 if (configPath.endsWith('.json')) {
140 return { message, result: await readJsonFile<Config>(configPath) };
141 }
142 if (/\.(ts|js|mjs)$/.test(configPath)) {
143 return {
144 message,
145 result: await importModule<Config>({
146 filepath: configPath,
147 }),
148 };
149 }
150 throw new Error(
151 `Unknown Lighthouse config file extension in ${configPath}`,
152 );
153 },
154 );
155 }
156
157 if (preset != null) {
158 const supportedPresets: Record<
159 NonNullable<LighthouseCliFlags['preset']>,
160 Config
161 > = {
162 desktop: desktopConfig,
163 perf: perfConfig,
164 experimental: experimentalConfig,
165 };
166 // in reality, the preset could be a string not included in the type definition
167 const config: Config | undefined = supportedPresets[preset];
168 if (config) {
169 logger.info(`Loaded config from ${ansis.bold(preset)} preset`);
170 return config;
171 } else {
172 logger.warn(`Preset "${preset}" is not supported`);
173 }
174 }
175
176 return undefined;
177}
178
179export function enrichFlags(
180 flags: LighthouseCliFlags,

Callers 2

createRunnerFunctionFunction · 0.85
utils.unit.test.tsFile · 0.85

Calls 3

taskMethod · 0.80
infoMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected