|
1 | 1 | import type { CompilerSystem, Diagnostic } from '../declarations'; |
2 | 2 | import { isString, normalizePath, buildError } from '@utils'; |
3 | 3 |
|
4 | | -export const findConfig = async (opts: { sys: CompilerSystem; configPath: string }) => { |
| 4 | +/** |
| 5 | + * An object containing the {@link CompilerSystem} used to find the configuration file, as well as the location on disk |
| 6 | + * to search for a Stencil configuration |
| 7 | + */ |
| 8 | +export type FindConfigOptions = { |
| 9 | + sys: CompilerSystem; |
| 10 | + configPath: string; |
| 11 | +}; |
| 12 | + |
| 13 | +/** |
| 14 | + * The results of attempting to find a Stencil configuration file on disk |
| 15 | + */ |
| 16 | +export type FindConfigResults = { |
| 17 | + configPath: string; |
| 18 | + rootDir: string; |
| 19 | + diagnostics: Diagnostic[]; |
| 20 | +}; |
| 21 | + |
| 22 | +/** |
| 23 | + * Attempt to find a Stencil configuration file on the file system |
| 24 | + * @param opts the options needed to find the configuration file |
| 25 | + * @returns the results of attempting to find a configuration file on disk |
| 26 | + */ |
| 27 | +export const findConfig = async (opts: FindConfigOptions): Promise<FindConfigResults> => { |
5 | 28 | const sys = opts.sys; |
6 | 29 | const cwd = sys.getCurrentDirectory(); |
7 | | - const results = { |
| 30 | + const results: FindConfigResults = { |
8 | 31 | configPath: null as string, |
9 | 32 | rootDir: normalizePath(cwd), |
10 | | - diagnostics: [] as Diagnostic[], |
| 33 | + diagnostics: [], |
11 | 34 | }; |
12 | 35 | let configPath = opts.configPath; |
13 | 36 |
|
14 | 37 | if (isString(configPath)) { |
15 | 38 | if (!sys.platformPath.isAbsolute(configPath)) { |
16 | | - // passed in a custom stencil config location |
| 39 | + // passed in a custom stencil config location, |
17 | 40 | // but it's relative, so prefix the cwd |
18 | 41 | configPath = normalizePath(sys.platformPath.join(cwd, configPath)); |
19 | 42 | } else { |
|
0 commit comments