@rpcbase/test 0.235.0 → 0.237.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/vitest.config.mjs +29 -60
package/package.json
CHANGED
package/src/vitest.config.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fs from "node:fs"
|
|
2
1
|
import path from "node:path"
|
|
3
2
|
import { createRequire } from "node:module"
|
|
4
3
|
|
|
@@ -7,73 +6,43 @@ import { defineConfig } from "vitest/config"
|
|
|
7
6
|
|
|
8
7
|
const require = createRequire(import.meta.url)
|
|
9
8
|
|
|
10
|
-
function
|
|
9
|
+
function loadTsconfig() {
|
|
10
|
+
let ts
|
|
11
11
|
try {
|
|
12
|
-
|
|
13
|
-
const cwd = process.cwd()
|
|
14
|
-
const configPath =
|
|
15
|
-
ts.findConfigFile(cwd, ts.sys.fileExists, "tsconfig.json") ||
|
|
16
|
-
ts.findConfigFile(cwd, ts.sys.fileExists, "tsconfig.base.json")
|
|
17
|
-
|
|
18
|
-
if (!configPath) return null
|
|
19
|
-
|
|
20
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile)
|
|
21
|
-
if (configFile.error) return null
|
|
22
|
-
|
|
23
|
-
const parsed = ts.parseJsonConfigFileContent(
|
|
24
|
-
configFile.config,
|
|
25
|
-
ts.sys,
|
|
26
|
-
path.dirname(configPath),
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
path: configPath,
|
|
31
|
-
config: configFile.config,
|
|
32
|
-
baseUrl: parsed.options?.baseUrl
|
|
33
|
-
? path.resolve(path.dirname(configPath), parsed.options.baseUrl)
|
|
34
|
-
: path.dirname(configPath),
|
|
35
|
-
paths: parsed.options?.paths,
|
|
36
|
-
}
|
|
12
|
+
ts = require("typescript")
|
|
37
13
|
} catch (_err) {
|
|
38
|
-
|
|
14
|
+
throw new Error(
|
|
15
|
+
"@rpcbase/test: TypeScript is required to resolve path aliases. Please add it as a devDependency.",
|
|
16
|
+
)
|
|
39
17
|
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function loadTsconfigManually() {
|
|
43
|
-
const stripComments = (jsonWithComments) =>
|
|
44
|
-
jsonWithComments
|
|
45
|
-
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
46
|
-
.replace(/(^|\s+)\/\/.*$/gm, "")
|
|
47
18
|
|
|
48
19
|
const cwd = process.cwd()
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
const raw = fs.readFileSync(fullPath, "utf8")
|
|
57
|
-
const parsed = JSON.parse(stripComments(raw))
|
|
58
|
-
const baseUrl = parsed.compilerOptions?.baseUrl
|
|
59
|
-
? path.resolve(path.dirname(fullPath), parsed.compilerOptions.baseUrl)
|
|
60
|
-
: path.dirname(fullPath)
|
|
61
|
-
return {
|
|
62
|
-
path: fullPath,
|
|
63
|
-
config: parsed,
|
|
64
|
-
baseUrl,
|
|
65
|
-
paths: parsed.compilerOptions?.paths,
|
|
66
|
-
}
|
|
67
|
-
} catch (_err) {
|
|
68
|
-
// ignore parsing errors; fall through to next candidate
|
|
69
|
-
}
|
|
20
|
+
const configPath =
|
|
21
|
+
ts.findConfigFile(cwd, ts.sys.fileExists, "tsconfig.json") ||
|
|
22
|
+
ts.findConfigFile(cwd, ts.sys.fileExists, "tsconfig.base.json")
|
|
23
|
+
|
|
24
|
+
if (!configPath) {
|
|
25
|
+
throw new Error("@rpcbase/test: no tsconfig found for alias resolution")
|
|
70
26
|
}
|
|
71
27
|
|
|
72
|
-
|
|
73
|
-
|
|
28
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile)
|
|
29
|
+
if (configFile.error) {
|
|
30
|
+
throw new Error(`@rpcbase/test: unable to read tsconfig at ${configPath}`)
|
|
31
|
+
}
|
|
74
32
|
|
|
75
|
-
|
|
76
|
-
|
|
33
|
+
const parsed = ts.parseJsonConfigFileContent(
|
|
34
|
+
configFile.config,
|
|
35
|
+
ts.sys,
|
|
36
|
+
path.dirname(configPath),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
path: configPath,
|
|
41
|
+
baseUrl: parsed.options?.baseUrl
|
|
42
|
+
? path.resolve(path.dirname(configPath), parsed.options.baseUrl)
|
|
43
|
+
: path.dirname(configPath),
|
|
44
|
+
paths: parsed.options?.paths,
|
|
45
|
+
}
|
|
77
46
|
}
|
|
78
47
|
|
|
79
48
|
function pathsToAlias(tsconfig) {
|