@infcss/config 0.0.1 → 0.0.2
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 +5 -5
- package/src/index.ts +0 -53
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infcss/config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"description": "Infcss config",
|
|
6
|
-
"main": "
|
|
7
|
-
"module": "
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"import": "./
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
11
|
"require": "./src/index.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"jiti": "^2.7.0",
|
|
20
|
-
"@infcss/shared": "0.0.
|
|
20
|
+
"@infcss/shared": "0.0.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"unbuild": "^3.6.1"
|
package/src/index.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import jiti from 'jiti'
|
|
2
|
-
import { existsSync } from 'node:fs'
|
|
3
|
-
import { join, dirname } from 'node:path'
|
|
4
|
-
|
|
5
|
-
const CONFIG_FILES = [
|
|
6
|
-
'infcss.config.ts',
|
|
7
|
-
'infcss.config.js',
|
|
8
|
-
'infcss.config.mjs',
|
|
9
|
-
'infcss.config.cjs',
|
|
10
|
-
]
|
|
11
|
-
|
|
12
|
-
/** 向上递归查找配置文件 */
|
|
13
|
-
export function findConfigFile(cwd = process.cwd()) {
|
|
14
|
-
let dir = cwd
|
|
15
|
-
|
|
16
|
-
while (true) {
|
|
17
|
-
for (const name of CONFIG_FILES) {
|
|
18
|
-
const filePath = join(dir, name)
|
|
19
|
-
if (existsSync(filePath)) return filePath
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const parent = dirname(dir)
|
|
23
|
-
if (parent === dir) break
|
|
24
|
-
dir = parent
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return null
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** 加载配置文件,找不到则返回空对象 */
|
|
31
|
-
export function loadConfig(cwd = process.cwd()) {
|
|
32
|
-
const configPath = findConfigFile(cwd)
|
|
33
|
-
|
|
34
|
-
if (!configPath) {
|
|
35
|
-
console.warn('[infcss] 未找到配置文件,使用默认配置')
|
|
36
|
-
return {}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const load = jiti(dirname(configPath), {
|
|
40
|
-
interopDefault: true,
|
|
41
|
-
cache: false,
|
|
42
|
-
requireCache: false,
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
const config = load(configPath)
|
|
47
|
-
console.log(`[infcss] 已加载配置: ${configPath}`)
|
|
48
|
-
return config.default ?? config
|
|
49
|
-
} catch (err) {
|
|
50
|
-
console.error(`[infcss] 配置文件加载失败: ${configPath}`)
|
|
51
|
-
throw err
|
|
52
|
-
}
|
|
53
|
-
}
|