Skip to content

Commit 9132a76

Browse files
authored
chore(cli): add types to finding config (stenciljs#3527)
this commit adds additional types for the function that finds a user's configuration file on disk in the hope of adding clarity and removing a type assertion in the function
1 parent 7f8e5c6 commit 9132a76

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

src/cli/find-config.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11
import type { CompilerSystem, Diagnostic } from '../declarations';
22
import { isString, normalizePath, buildError } from '@utils';
33

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> => {
528
const sys = opts.sys;
629
const cwd = sys.getCurrentDirectory();
7-
const results = {
30+
const results: FindConfigResults = {
831
configPath: null as string,
932
rootDir: normalizePath(cwd),
10-
diagnostics: [] as Diagnostic[],
33+
diagnostics: [],
1134
};
1235
let configPath = opts.configPath;
1336

1437
if (isString(configPath)) {
1538
if (!sys.platformPath.isAbsolute(configPath)) {
16-
// passed in a custom stencil config location
39+
// passed in a custom stencil config location,
1740
// but it's relative, so prefix the cwd
1841
configPath = normalizePath(sys.platformPath.join(cwd, configPath));
1942
} else {

0 commit comments

Comments
 (0)