@unocss/config 0.61.3 → 0.61.4

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.mts CHANGED
@@ -3,5 +3,13 @@ import { LoadConfigSource, LoadConfigResult } from 'unconfig';
3
3
  export { LoadConfigResult, LoadConfigSource } from 'unconfig';
4
4
 
5
5
  declare function loadConfig<U extends UserConfig>(cwd?: string, configOrPath?: string | U, extraConfigSources?: LoadConfigSource[], defaults?: UserConfigDefaults): Promise<LoadConfigResult<U>>;
6
+ /**
7
+ * Create a factory function that returns a config loader that recovers from errors.
8
+ *
9
+ * When it fails to load the config, it will return the last successfully loaded config.
10
+ *
11
+ * Mainly used for dev-time where users might have a broken config in between changes.
12
+ */
13
+ declare function createRecoveryConfigLoader<U extends UserConfig>(): (cwd?: string, configOrPath?: string | U, extraConfigSources?: LoadConfigSource[], defaults?: UserConfigDefaults) => Promise<LoadConfigResult<U>>;
6
14
 
7
- export { loadConfig };
15
+ export { createRecoveryConfigLoader, loadConfig };
package/dist/index.d.ts CHANGED
@@ -3,5 +3,13 @@ import { LoadConfigSource, LoadConfigResult } from 'unconfig';
3
3
  export { LoadConfigResult, LoadConfigSource } from 'unconfig';
4
4
 
5
5
  declare function loadConfig<U extends UserConfig>(cwd?: string, configOrPath?: string | U, extraConfigSources?: LoadConfigSource[], defaults?: UserConfigDefaults): Promise<LoadConfigResult<U>>;
6
+ /**
7
+ * Create a factory function that returns a config loader that recovers from errors.
8
+ *
9
+ * When it fails to load the config, it will return the last successfully loaded config.
10
+ *
11
+ * Mainly used for dev-time where users might have a broken config in between changes.
12
+ */
13
+ declare function createRecoveryConfigLoader<U extends UserConfig>(): (cwd?: string, configOrPath?: string | U, extraConfigSources?: LoadConfigSource[], defaults?: UserConfigDefaults) => Promise<LoadConfigResult<U>>;
6
14
 
7
- export { loadConfig };
15
+ export { createRecoveryConfigLoader, loadConfig };
package/dist/index.mjs CHANGED
@@ -50,5 +50,21 @@ async function loadConfig(cwd = process.cwd(), configOrPath = cwd, extraConfigSo
50
50
  }
51
51
  return result;
52
52
  }
53
+ function createRecoveryConfigLoader() {
54
+ let lastResolved;
55
+ return async (cwd = process.cwd(), configOrPath = cwd, extraConfigSources = [], defaults = {}) => {
56
+ try {
57
+ const config = await loadConfig(cwd, configOrPath, extraConfigSources, defaults);
58
+ lastResolved = config;
59
+ return config;
60
+ } catch (e) {
61
+ if (lastResolved) {
62
+ console.error(e);
63
+ return lastResolved;
64
+ }
65
+ throw e;
66
+ }
67
+ };
68
+ }
53
69
 
54
- export { loadConfig };
70
+ export { createRecoveryConfigLoader, loadConfig };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/config",
3
3
  "type": "module",
4
- "version": "0.61.3",
4
+ "version": "0.61.4",
5
5
  "description": "Config loader for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "unconfig": "^0.3.13",
37
- "@unocss/core": "0.61.3"
37
+ "@unocss/core": "0.61.4"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "unbuild",