-
Notifications
You must be signed in to change notification settings - Fork 21
/
getViteConfigPath.ts
51 lines (44 loc) · 1.44 KB
/
getViteConfigPath.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import * as core from "@actions/core";
import path from "node:path";
import { constants, promises as fs } from "fs";
import { stripIndent } from "common-tags";
const testFilePath = async (workingDirectory: string, filePath: string) => {
const resolvedPath = path.resolve(workingDirectory, filePath);
await fs.access(resolvedPath, constants.R_OK);
return resolvedPath;
};
const defaultPaths = [
"vitest.config.ts",
"vitest.config.mts",
"vitest.config.cts",
"vitest.config.js",
"vitest.config.mjs",
"vitest.config.cjs",
"vite.config.ts",
"vite.config.mts",
"vite.config.cts",
"vite.config.js",
"vite.config.mjs",
"vite.config.cjs",
];
const getViteConfigPath = async (workingDirectory: string, input: string) => {
try {
if (input === "") {
return await Promise.any(
defaultPaths.map((filePath) => testFilePath(workingDirectory, filePath))
);
}
return await testFilePath(workingDirectory, input);
} catch (error) {
const searchPath = input ?
`"${workingDirectory}/${input}"` :
`any default location in "${workingDirectory}"`;
core.warning(stripIndent`
Failed to read vite config file at ${searchPath}.
Make sure you provide the vite-config-path option if you're using a non-default location or name of your config file.
Will not include thresholds in the final report.
`);
return null;
}
};
export { getViteConfigPath };