@unocss/config 0.13.0 → 0.14.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/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { UserConfig } from '@unocss/core';
2
- import { LoadConfigResult } from 'unconfig';
3
- export { LoadConfigResult } from 'unconfig';
2
+ import { LoadConfigSource, LoadConfigResult } from 'unconfig';
3
+ export { LoadConfigResult, LoadConfigSource } from 'unconfig';
4
4
 
5
- declare function createConfigLoader<U extends UserConfig>(dirOrPath?: string | U): () => Promise<LoadConfigResult<U>>;
5
+ declare function createConfigLoader<U extends UserConfig>(configOrPath?: string | U, extraConfigSources?: LoadConfigSource[]): () => Promise<LoadConfigResult<U>>;
6
6
  declare function loadConfig<U extends UserConfig>(dirOrPath: string | U): Promise<LoadConfigResult<U>>;
7
7
 
8
8
  export { createConfigLoader, loadConfig };
package/dist/index.js CHANGED
@@ -25,40 +25,62 @@ var __toModule = (module2) => {
25
25
  // src/index.ts
26
26
  __export(exports, {
27
27
  LoadConfigResult: () => import_unconfig.LoadConfigResult,
28
+ LoadConfigSource: () => import_unconfig.LoadConfigSource,
28
29
  createConfigLoader: () => createConfigLoader,
29
30
  loadConfig: () => loadConfig
30
31
  });
31
32
  var import_path = __toModule(require("path"));
33
+ var import_fs = __toModule(require("fs"));
32
34
  var import_unconfig = __toModule(require("unconfig"));
33
- var import_presets = __toModule(require("unconfig/presets"));
34
- function createConfigLoader(dirOrPath = process.cwd()) {
35
- if (typeof dirOrPath !== "string") {
36
- return async () => ({
37
- config: dirOrPath,
38
- sources: []
39
- });
35
+ function createConfigLoader(configOrPath = process.cwd(), extraConfigSources = []) {
36
+ let inlineConfig = {};
37
+ if (typeof configOrPath !== "string") {
38
+ inlineConfig = configOrPath;
39
+ if (inlineConfig.configFile === false) {
40
+ return async () => ({
41
+ config: inlineConfig,
42
+ sources: []
43
+ });
44
+ } else {
45
+ configOrPath = inlineConfig.configFile || process.cwd();
46
+ }
47
+ }
48
+ const resolved = (0, import_path.resolve)(configOrPath);
49
+ let cwd = resolved;
50
+ let isFile = false;
51
+ if (import_fs.default.existsSync(resolved) && import_fs.default.statSync(resolved).isFile()) {
52
+ isFile = true;
53
+ cwd = (0, import_path.dirname)(resolved);
40
54
  }
41
- dirOrPath = (0, import_path.resolve)(dirOrPath);
42
55
  const loader = (0, import_unconfig.createConfigLoader)({
43
- sources: [
56
+ sources: isFile ? [
57
+ {
58
+ files: resolved,
59
+ extensions: []
60
+ }
61
+ ] : [
44
62
  {
45
63
  files: [
46
64
  "unocss.config",
47
65
  "uno.config"
48
66
  ]
49
67
  },
50
- (0, import_presets.sourcePluginFactory)({
51
- files: "vite.config",
52
- targetModule: "unocss/vite"
53
- }),
54
- (0, import_presets.sourceObjectFields)({
55
- files: "nuxt.config",
56
- fields: "unocss"
57
- })
68
+ ...extraConfigSources
58
69
  ],
59
- cwd: dirOrPath
70
+ cwd,
71
+ defaults: inlineConfig
60
72
  });
61
- return loader.load;
73
+ return async () => {
74
+ const result = await loader.load();
75
+ result.config = result.config || inlineConfig;
76
+ if (result.config.configDeps) {
77
+ result.sources = [
78
+ ...result.sources,
79
+ ...result.config.configDeps.map((i) => (0, import_path.resolve)(cwd, i))
80
+ ];
81
+ }
82
+ return result;
83
+ };
62
84
  }
63
85
  function loadConfig(dirOrPath) {
64
86
  return createConfigLoader(dirOrPath)();
@@ -66,6 +88,7 @@ function loadConfig(dirOrPath) {
66
88
  // Annotate the CommonJS export names for ESM import in node:
67
89
  0 && (module.exports = {
68
90
  LoadConfigResult,
91
+ LoadConfigSource,
69
92
  createConfigLoader,
70
93
  loadConfig
71
94
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/config",
3
- "version": "0.13.0",
3
+ "version": "0.14.2",
4
4
  "description": "Config loader for UnoCSS",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/antfu/unocss/tree/main/packages/config#readme",
@@ -28,8 +28,8 @@
28
28
  "node": ">=14"
29
29
  },
30
30
  "dependencies": {
31
- "@unocss/core": "0.13.0",
32
- "unconfig": "^0.2.1"
31
+ "@unocss/core": "0.14.2",
32
+ "unconfig": "^0.2.2"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsup",