c12 3.3.0 → 3.3.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/README.md CHANGED
@@ -96,7 +96,7 @@ RC Config file name. Default is generated from `name` (name=foo => `.foorc`).
96
96
 
97
97
  Set to `false` to disable loading RC config.
98
98
 
99
- ### `globalRC`
99
+ ### `globalRc`
100
100
 
101
101
  Load RC config from the workspace directory and the user's home directory. Only enabled when `rcFile` is provided. Set to `false` to disable this functionality.
102
102
 
package/dist/index.d.mts CHANGED
@@ -1,36 +1,37 @@
1
- import { Jiti, JitiOptions } from 'jiti';
2
- import { DownloadTemplateOptions } from 'giget';
3
- import { ChokidarOptions } from 'chokidar';
4
- import { diff } from 'ohash/utils';
1
+ import { Jiti, JitiOptions } from "jiti";
2
+ import { ChokidarOptions } from "chokidar";
3
+ import { DownloadTemplateOptions } from "giget";
4
+ import { diff } from "ohash/utils";
5
5
 
6
+ //#region src/dotenv.d.ts
6
7
  interface DotenvOptions {
7
- /**
8
- * The project root directory (either absolute or relative to the current working directory).
9
- *
10
- * Defaults to `options.cwd` in `loadConfig` context, or `process.cwd()` when used as standalone.
11
- */
12
- cwd?: string;
13
- /**
14
- * What file or files to look in for environment variables (either absolute or relative
15
- * to the current working directory). For example, `.env`.
16
- * With the array type, the order enforce the env loading priority (last one overrides).
17
- */
18
- fileName?: string | string[];
19
- /**
20
- * Whether to interpolate variables within .env.
21
- *
22
- * @example
23
- * ```env
24
- * BASE_DIR="/test"
25
- * # resolves to "/test/further"
26
- * ANOTHER_DIR="${BASE_DIR}/further"
27
- * ```
28
- */
29
- interpolate?: boolean;
30
- /**
31
- * An object describing environment variables (key, value pairs).
32
- */
33
- env?: NodeJS.ProcessEnv;
8
+ /**
9
+ * The project root directory (either absolute or relative to the current working directory).
10
+ *
11
+ * Defaults to `options.cwd` in `loadConfig` context, or `process.cwd()` when used as standalone.
12
+ */
13
+ cwd?: string;
14
+ /**
15
+ * What file or files to look in for environment variables (either absolute or relative
16
+ * to the current working directory). For example, `.env`.
17
+ * With the array type, the order enforce the env loading priority (last one overrides).
18
+ */
19
+ fileName?: string | string[];
20
+ /**
21
+ * Whether to interpolate variables within .env.
22
+ *
23
+ * @example
24
+ * ```env
25
+ * BASE_DIR="/test"
26
+ * # resolves to "/test/further"
27
+ * ANOTHER_DIR="${BASE_DIR}/further"
28
+ * ```
29
+ */
30
+ interpolate?: boolean;
31
+ /**
32
+ * An object describing environment variables (key, value pairs).
33
+ */
34
+ env?: NodeJS.ProcessEnv;
34
35
  }
35
36
  type Env = typeof process.env;
36
37
  /**
@@ -42,126 +43,128 @@ declare function setupDotenv(options: DotenvOptions): Promise<Env>;
42
43
  /** Load environment variables into an object. */
43
44
  declare function loadDotenv(options: DotenvOptions): Promise<Env>;
44
45
  declare global {
45
- var __c12_dotenv_vars__: Map<Record<string, any>, Set<string>>;
46
+ var __c12_dotenv_vars__: Map<Record<string, any>, Set<string>>;
46
47
  }
47
-
48
+ //#endregion
49
+ //#region src/types.d.ts
48
50
  interface ConfigLayerMeta {
49
- name?: string;
50
- [key: string]: any;
51
+ name?: string;
52
+ [key: string]: any;
51
53
  }
52
54
  type UserInputConfig = Record<string, any>;
53
55
  interface C12InputConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
54
- $test?: T;
55
- $development?: T;
56
- $production?: T;
57
- $env?: Record<string, T>;
58
- $meta?: MT;
56
+ $test?: T;
57
+ $development?: T;
58
+ $production?: T;
59
+ $env?: Record<string, T>;
60
+ $meta?: MT;
59
61
  }
60
62
  type InputConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = C12InputConfig<T, MT> & T;
61
63
  interface SourceOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
62
- /** Custom meta for layer */
63
- meta?: MT;
64
- /** Layer config overrides */
65
- overrides?: T;
66
- [key: string]: any;
67
- /**
68
- * Options for cloning remote sources
69
- *
70
- * @see https://giget.unjs.io
71
- */
72
- giget?: DownloadTemplateOptions;
73
- /**
74
- * Install dependencies after cloning
75
- *
76
- * @see https://nypm.unjs.io
77
- */
78
- install?: boolean;
79
- /**
80
- * Token for cloning private sources
81
- *
82
- * @see https://giget.unjs.io#providing-token-for-private-repositories
83
- */
84
- auth?: string;
64
+ /** Custom meta for layer */
65
+ meta?: MT;
66
+ /** Layer config overrides */
67
+ overrides?: T;
68
+ [key: string]: any;
69
+ /**
70
+ * Options for cloning remote sources
71
+ *
72
+ * @see https://giget.unjs.io
73
+ */
74
+ giget?: DownloadTemplateOptions;
75
+ /**
76
+ * Install dependencies after cloning
77
+ *
78
+ * @see https://nypm.unjs.io
79
+ */
80
+ install?: boolean;
81
+ /**
82
+ * Token for cloning private sources
83
+ *
84
+ * @see https://giget.unjs.io#providing-token-for-private-repositories
85
+ */
86
+ auth?: string;
85
87
  }
86
88
  interface ConfigLayer<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
87
- config: T | null;
88
- source?: string;
89
- sourceOptions?: SourceOptions<T, MT>;
90
- meta?: MT;
91
- cwd?: string;
92
- configFile?: string;
89
+ config: T | null;
90
+ source?: string;
91
+ sourceOptions?: SourceOptions<T, MT>;
92
+ meta?: MT;
93
+ cwd?: string;
94
+ configFile?: string;
93
95
  }
94
96
  interface ResolvedConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> extends ConfigLayer<T, MT> {
95
- config: T;
96
- layers?: ConfigLayer<T, MT>[];
97
- cwd?: string;
98
- _configFile?: string;
97
+ config: T;
98
+ layers?: ConfigLayer<T, MT>[];
99
+ cwd?: string;
100
+ _configFile?: string;
99
101
  }
100
102
  type ConfigSource = "overrides" | "main" | "rc" | "packageJson" | "defaultConfig";
101
103
  interface ConfigFunctionContext {
102
- [key: string]: any;
104
+ [key: string]: any;
103
105
  }
104
106
  interface ResolvableConfigContext<T extends UserInputConfig = UserInputConfig> {
105
- configs: Record<ConfigSource, T | null | undefined>;
106
- rawConfigs: Record<ConfigSource, ResolvableConfig<T> | null | undefined>;
107
+ configs: Record<ConfigSource, T | null | undefined>;
108
+ rawConfigs: Record<ConfigSource, ResolvableConfig<T> | null | undefined>;
107
109
  }
108
110
  type MaybePromise<T> = T | Promise<T>;
109
111
  type ResolvableConfig<T extends UserInputConfig = UserInputConfig> = MaybePromise<T | null | undefined> | ((ctx: ResolvableConfigContext<T>) => MaybePromise<T | null | undefined>);
110
112
  interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
111
- name?: string;
112
- cwd?: string;
113
- configFile?: string;
114
- rcFile?: false | string;
115
- globalRc?: boolean;
116
- dotenv?: boolean | DotenvOptions;
117
- envName?: string | false;
118
- packageJson?: boolean | string | string[];
119
- defaults?: T;
120
- defaultConfig?: ResolvableConfig<T>;
121
- overrides?: ResolvableConfig<T>;
122
- omit$Keys?: boolean;
123
- /** Context passed to config functions */
124
- context?: ConfigFunctionContext;
125
- resolve?: (id: string, options: LoadConfigOptions<T, MT>) => null | undefined | ResolvedConfig<T, MT> | Promise<ResolvedConfig<T, MT> | undefined | null>;
126
- jiti?: Jiti;
127
- jitiOptions?: JitiOptions;
128
- giget?: false | DownloadTemplateOptions;
129
- merger?: (...sources: Array<T | null | undefined>) => T;
130
- extend?: false | {
131
- extendKey?: string | string[];
132
- };
133
- configFileRequired?: boolean;
113
+ name?: string;
114
+ cwd?: string;
115
+ configFile?: string;
116
+ rcFile?: false | string;
117
+ globalRc?: boolean;
118
+ dotenv?: boolean | DotenvOptions;
119
+ envName?: string | false;
120
+ packageJson?: boolean | string | string[];
121
+ defaults?: T;
122
+ defaultConfig?: ResolvableConfig<T>;
123
+ overrides?: ResolvableConfig<T>;
124
+ omit$Keys?: boolean;
125
+ /** Context passed to config functions */
126
+ context?: ConfigFunctionContext;
127
+ resolve?: (id: string, options: LoadConfigOptions<T, MT>) => null | undefined | ResolvedConfig<T, MT> | Promise<ResolvedConfig<T, MT> | undefined | null>;
128
+ jiti?: Jiti;
129
+ jitiOptions?: JitiOptions;
130
+ giget?: false | DownloadTemplateOptions;
131
+ merger?: (...sources: Array<T | null | undefined>) => T;
132
+ extend?: false | {
133
+ extendKey?: string | string[];
134
+ };
135
+ configFileRequired?: boolean;
134
136
  }
135
137
  type DefineConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = (input: InputConfig<T, MT>) => InputConfig<T, MT>;
136
138
  declare function createDefineConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(): DefineConfig<T, MT>;
137
-
139
+ //#endregion
140
+ //#region src/loader.d.ts
138
141
  declare const SUPPORTED_EXTENSIONS: string[];
139
142
  declare function loadConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: LoadConfigOptions<T, MT>): Promise<ResolvedConfig<T, MT>>;
140
-
143
+ //#endregion
144
+ //#region src/watch.d.ts
141
145
  type DiffEntries = ReturnType<typeof diff>;
142
146
  type ConfigWatcher<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = ResolvedConfig<T, MT> & {
143
- watchingFiles: string[];
144
- unwatch: () => Promise<void>;
147
+ watchingFiles: string[];
148
+ unwatch: () => Promise<void>;
145
149
  };
146
150
  interface WatchConfigOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> extends LoadConfigOptions<T, MT> {
147
- chokidarOptions?: ChokidarOptions;
148
- debounce?: false | number;
149
- onWatch?: (event: {
150
- type: "created" | "updated" | "removed";
151
- path: string;
152
- }) => void | Promise<void>;
153
- acceptHMR?: (context: {
154
- getDiff: () => DiffEntries;
155
- newConfig: ResolvedConfig<T, MT>;
156
- oldConfig: ResolvedConfig<T, MT>;
157
- }) => void | boolean | Promise<void | boolean>;
158
- onUpdate?: (context: {
159
- getDiff: () => ReturnType<typeof diff>;
160
- newConfig: ResolvedConfig<T, MT>;
161
- oldConfig: ResolvedConfig<T, MT>;
162
- }) => void | Promise<void>;
151
+ chokidarOptions?: ChokidarOptions;
152
+ debounce?: false | number;
153
+ onWatch?: (event: {
154
+ type: "created" | "updated" | "removed";
155
+ path: string;
156
+ }) => void | Promise<void>;
157
+ acceptHMR?: (context: {
158
+ getDiff: () => DiffEntries;
159
+ newConfig: ResolvedConfig<T, MT>;
160
+ oldConfig: ResolvedConfig<T, MT>;
161
+ }) => void | boolean | Promise<void | boolean>;
162
+ onUpdate?: (context: {
163
+ getDiff: () => ReturnType<typeof diff>;
164
+ newConfig: ResolvedConfig<T, MT>;
165
+ oldConfig: ResolvedConfig<T, MT>;
166
+ }) => void | Promise<void>;
163
167
  }
164
168
  declare function watchConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: WatchConfigOptions<T, MT>): Promise<ConfigWatcher<T, MT>>;
165
-
166
- export { SUPPORTED_EXTENSIONS, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };
167
- export type { C12InputConfig, ConfigFunctionContext, ConfigLayer, ConfigLayerMeta, ConfigSource, ConfigWatcher, DefineConfig, DotenvOptions, Env, InputConfig, LoadConfigOptions, ResolvableConfig, ResolvableConfigContext, ResolvedConfig, SourceOptions, UserInputConfig, WatchConfigOptions };
169
+ //#endregion
170
+ export { C12InputConfig, ConfigFunctionContext, ConfigLayer, ConfigLayerMeta, ConfigSource, ConfigWatcher, DefineConfig, DotenvOptions, Env, InputConfig, LoadConfigOptions, ResolvableConfig, ResolvableConfigContext, ResolvedConfig, SUPPORTED_EXTENSIONS, SourceOptions, UserInputConfig, WatchConfigOptions, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };