-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.ts
More file actions
81 lines (66 loc) · 1.99 KB
/
vitest.config.ts
File metadata and controls
81 lines (66 loc) · 1.99 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { defineConfig } from "vitest/config";
import path from "path";
import fs from "fs";
const isWatch =
process.argv.includes("--watch") || process.argv.includes("watch");
function getLibAliases() {
const aliases: Record<string, string> = {};
const libDir = path.resolve(__dirname, "packages/libs");
if (!fs.existsSync(libDir)) {
return aliases;
}
const packages = fs.readdirSync(libDir);
for (const pkg of packages) {
const pkgPath = path.join(libDir, pkg);
const pkgJsonPath = path.join(pkgPath, "package.json");
if (!fs.statSync(pkgPath).isDirectory() || !fs.existsSync(pkgJsonPath)) {
continue;
}
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
if (!pkgJson.name) {
continue;
}
if (pkgJson.exports?.["."]) {
const exportKeys = Object.keys(pkgJson.exports).sort((a, b) =>
b.localeCompare(a)
);
for (const key of exportKeys) {
const exportValue = pkgJson.exports[key];
const importPath =
typeof exportValue === "string" ? exportValue : exportValue.import;
const entryPoint = path.join(
pkgPath,
importPath.replace(/^\.\/dist\//, "./src/").replace(/\.c?js$/, ".ts")
);
if (fs.existsSync(entryPoint)) {
const aliasKey =
key === "." ? pkgJson.name : `${pkgJson.name}${key.slice(1)}`;
aliases[aliasKey] = entryPoint;
}
}
} else if (pkgJson.main) {
const entryPoint = path.join(
pkgPath,
pkgJson.main.replace(/^\.\/dist\//, "./src/").replace(/\.c?js$/, ".ts")
);
if (fs.existsSync(entryPoint)) {
aliases[pkgJson.name] = entryPoint;
}
}
}
return aliases;
}
export default defineConfig({
test: {
globals: true,
environment: "node",
include: ["**/*.test.ts"],
exclude: ["**/node_modules/**", "**/dist/**"],
passWithNoTests: true,
},
...(isWatch && {
resolve: {
alias: getLibAliases(),
},
}),
});