@theholocron/datapad 5.0.0-alpha.246 → 5.0.0-alpha.248
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 +10 -38
- package/dist/index.mjs +12 -24
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { deepMerge as mergeConfig } from "@theholocron/object-utils";
|
|
2
|
-
//#region src/default-extensions/default-extensions.d.ts
|
|
3
2
|
/** Default extension probe order, highest priority first. */
|
|
4
|
-
declare const DEFAULT_EXTENSIONS: readonly ["ts", "js", "mjs", "cjs", "json"];
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region src/define/define.d.ts
|
|
3
|
+
export declare const DEFAULT_EXTENSIONS: readonly ["ts", "js", "mjs", "cjs", "json"];
|
|
7
4
|
/**
|
|
8
5
|
* Build a typed identity `defineConfig` for a specific config shape.
|
|
9
6
|
*
|
|
@@ -16,16 +13,14 @@ declare const DEFAULT_EXTENSIONS: readonly ["ts", "js", "mjs", "cjs", "json"];
|
|
|
16
13
|
* export const defineConfig = createDefineConfig<TasksConfig>();
|
|
17
14
|
* ```
|
|
18
15
|
*/
|
|
19
|
-
declare function createDefineConfig<T>(): <C extends T>(config: C) => C;
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/errors/errors.d.ts
|
|
16
|
+
export declare function createDefineConfig<T>(): <C extends T>(config: C) => C;
|
|
22
17
|
/**
|
|
23
18
|
* Thrown when a config file is found but cannot be loaded — malformed
|
|
24
19
|
* JSON, a syntax error in a `.ts` / `.js` module, or no usable default
|
|
25
20
|
* export. "Not found" is never an error: {@link loadConfigFile} returns
|
|
26
21
|
* `null` for that.
|
|
27
22
|
*/
|
|
28
|
-
declare class ConfigFileError extends Error {
|
|
23
|
+
export declare class ConfigFileError extends Error {
|
|
29
24
|
/** Absolute path of the offending file, when known. */
|
|
30
25
|
readonly filepath?: string | undefined;
|
|
31
26
|
name: string;
|
|
@@ -33,8 +28,6 @@ declare class ConfigFileError extends Error {
|
|
|
33
28
|
/** Absolute path of the offending file, when known. */
|
|
34
29
|
filepath?: string | undefined);
|
|
35
30
|
}
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/load-config-file/load-config-file.type.d.ts
|
|
38
31
|
interface LoadConfigFileOptions {
|
|
39
32
|
/** Directory to start looking in. */
|
|
40
33
|
cwd: string;
|
|
@@ -56,8 +49,6 @@ interface Loaded<T> {
|
|
|
56
49
|
/** Absolute path of the file the value came from. */
|
|
57
50
|
filepath: string;
|
|
58
51
|
}
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/load-config-file/load-config-file.d.ts
|
|
61
52
|
/**
|
|
62
53
|
* Load the first `<name>.config.<ext>` found starting at `cwd` — just
|
|
63
54
|
* `cwd` itself by default, or walking up through ancestor directories when
|
|
@@ -65,9 +56,7 @@ interface Loaded<T> {
|
|
|
65
56
|
* Returns `null` when none is present anywhere searched; throws
|
|
66
57
|
* {@link ConfigFileError} when a file exists but cannot be loaded.
|
|
67
58
|
*/
|
|
68
|
-
declare function loadConfigFile<T>(opts: LoadConfigFileOptions): Promise<Loaded<T> | null>;
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/load-config-from-content/load-config-from-content.type.d.ts
|
|
59
|
+
export declare function loadConfigFile<T>(opts: LoadConfigFileOptions): Promise<Loaded<T> | null>;
|
|
71
60
|
interface LoadConfigFromContentOptions {
|
|
72
61
|
/**
|
|
73
62
|
* Directory to write `<name>.config.<extension>` into before loading —
|
|
@@ -85,8 +74,6 @@ interface LoadConfigFromContentOptions {
|
|
|
85
74
|
/** Which of `DEFAULT_EXTENSIONS` `content` is — determines how it's interpreted (ts/js/mjs/cjs parsed as a module, json as `JSON.parse`). */
|
|
86
75
|
extension: string;
|
|
87
76
|
}
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/load-config-from-content/load-config-from-content.d.ts
|
|
90
77
|
/**
|
|
91
78
|
* Load config from content that didn't come from a file already on disk —
|
|
92
79
|
* writes it to `<dir>/<name>.config.<extension>` first, then loads it
|
|
@@ -97,9 +84,7 @@ interface LoadConfigFromContentOptions {
|
|
|
97
84
|
* a `.ts` config still needs real module resolution, `defineConfig` import
|
|
98
85
|
* included, not a re-implemented parser.
|
|
99
86
|
*/
|
|
100
|
-
declare function loadConfigFromContent<T>(opts: LoadConfigFromContentOptions): Promise<Loaded<T>>;
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/load-layered/load-layered.type.d.ts
|
|
87
|
+
export declare function loadConfigFromContent<T>(opts: LoadConfigFromContentOptions): Promise<Loaded<T>>;
|
|
103
88
|
interface LoadLayeredOptions<T = unknown> extends LoadConfigFileOptions {
|
|
104
89
|
/**
|
|
105
90
|
* When no dedicated `<name>.config.*` exists — or in addition to it —
|
|
@@ -131,17 +116,13 @@ interface LayeredResult<T> {
|
|
|
131
116
|
/** Absolute paths actually merged, lowest priority first. */
|
|
132
117
|
sources: string[];
|
|
133
118
|
}
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/load-layered/load-layered.d.ts
|
|
136
119
|
/**
|
|
137
120
|
* `<name>.config.*` layered over the `[fallback.key]` of
|
|
138
121
|
* `<fallback.file>.config.*`. Either, both, or neither may be present;
|
|
139
122
|
* the dedicated file wins on conflict (vitest-over-vite). Returns `null`
|
|
140
123
|
* when neither source resolves.
|
|
141
124
|
*/
|
|
142
|
-
declare function loadLayered<T>(opts: LoadLayeredOptions<T>): Promise<LayeredResult<T> | null>;
|
|
143
|
-
//#endregion
|
|
144
|
-
//#region src/merge-layers/merge-layers.d.ts
|
|
125
|
+
export declare function loadLayered<T>(opts: LoadLayeredOptions<T>): Promise<LayeredResult<T> | null>;
|
|
145
126
|
/**
|
|
146
127
|
* Deep-merges config layers, lowest priority first (a later layer wins on
|
|
147
128
|
* scalars; arrays concatenate; nested objects merge). `undefined` layers are
|
|
@@ -152,9 +133,7 @@ declare function loadLayered<T>(opts: LoadLayeredOptions<T>): Promise<LayeredRes
|
|
|
152
133
|
* some other way (content from an API, say) use, so layering means the same
|
|
153
134
|
* thing everywhere.
|
|
154
135
|
*/
|
|
155
|
-
declare function mergeLayers<T>(layers: readonly (T | undefined)[]): T | undefined;
|
|
156
|
-
//#endregion
|
|
157
|
-
//#region src/read-config-source/read-config-source.type.d.ts
|
|
136
|
+
export declare function mergeLayers<T>(layers: readonly (T | undefined)[]): T | undefined;
|
|
158
137
|
/** A config file's content fetched from somewhere other than the local disk. */
|
|
159
138
|
interface ConfigSource {
|
|
160
139
|
/** The file name probed, e.g. `holocron.config.ts` — relative, as `fetch` was asked for it. */
|
|
@@ -176,8 +155,6 @@ interface ReadConfigSourceOptions {
|
|
|
176
155
|
/** Override the extension probe order. */
|
|
177
156
|
extensions?: readonly string[];
|
|
178
157
|
}
|
|
179
|
-
//#endregion
|
|
180
|
-
//#region src/read-config-source/read-config-source.d.ts
|
|
181
158
|
/**
|
|
182
159
|
* {@link probeExtensions} for a config that lives somewhere other than the
|
|
183
160
|
* local disk (a GitHub API, a git blob): probes `<name>.config.<ext>` in
|
|
@@ -185,9 +162,7 @@ interface ReadConfigSourceOptions {
|
|
|
185
162
|
* that exists, or `undefined` when none does. Pass the result to
|
|
186
163
|
* `loadConfigFromContent` to execute it exactly as a local file would be.
|
|
187
164
|
*/
|
|
188
|
-
declare function readConfigSource(options: ReadConfigSourceOptions): Promise<ConfigSource | undefined>;
|
|
189
|
-
//#endregion
|
|
190
|
-
//#region src/with-config-sandbox/with-config-sandbox.type.d.ts
|
|
165
|
+
export declare function readConfigSource(options: ReadConfigSourceOptions): Promise<ConfigSource | undefined>;
|
|
191
166
|
interface ConfigSandboxOptions {
|
|
192
167
|
/**
|
|
193
168
|
* A real `node_modules` directory to make visible from the sandbox. A config
|
|
@@ -202,8 +177,6 @@ interface ConfigSandboxOptions {
|
|
|
202
177
|
/** Prefix for the sandbox directory's name. */
|
|
203
178
|
prefix?: string;
|
|
204
179
|
}
|
|
205
|
-
//#endregion
|
|
206
|
-
//#region src/with-config-sandbox/with-config-sandbox.d.ts
|
|
207
180
|
/**
|
|
208
181
|
* Runs `run` with a throwaway directory prepared for
|
|
209
182
|
* {@link loadConfigFromContent}'s `dir`, and removes it afterwards (also when
|
|
@@ -224,6 +197,5 @@ interface ConfigSandboxOptions {
|
|
|
224
197
|
* package: read-only deployments (Vercel's Node.js Functions ship the bundle
|
|
225
198
|
* read-only under `/var/task`) can't create a directory there.
|
|
226
199
|
*/
|
|
227
|
-
declare function withConfigSandbox<R>(options: ConfigSandboxOptions, run: (dir: string) => Promise<R>): Promise<R>;
|
|
228
|
-
|
|
229
|
-
export { ConfigFileError, type ConfigSandboxOptions, type ConfigSource, DEFAULT_EXTENSIONS, type LayeredResult, type LoadConfigFileOptions, type LoadConfigFromContentOptions, type LoadLayeredOptions, type Loaded, type ReadConfigSourceOptions, createDefineConfig, loadConfigFile, loadConfigFromContent, loadLayered, mergeConfig, mergeLayers, readConfigSource, withConfigSandbox };
|
|
200
|
+
export declare function withConfigSandbox<R>(options: ConfigSandboxOptions, run: (dir: string) => Promise<R>): Promise<R>;
|
|
201
|
+
export { type ConfigSandboxOptions, type ConfigSource, type LayeredResult, type LoadConfigFileOptions, type LoadConfigFromContentOptions, type LoadLayeredOptions, type Loaded, type ReadConfigSourceOptions, mergeConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { pathToFileURL } from "node:url";
|
|
|
5
5
|
import { errorMessage } from "@theholocron/misc-utils";
|
|
6
6
|
import { deepMerge, deepMerge as mergeConfig } from "@theholocron/object-utils";
|
|
7
7
|
import { tmpdir } from "node:os";
|
|
8
|
-
|
|
8
|
+
// src/default-extensions/default-extensions.ts
|
|
9
9
|
/** Default extension probe order, highest priority first. */
|
|
10
10
|
const DEFAULT_EXTENSIONS = [
|
|
11
11
|
"ts",
|
|
@@ -14,8 +14,7 @@ const DEFAULT_EXTENSIONS = [
|
|
|
14
14
|
"cjs",
|
|
15
15
|
"json"
|
|
16
16
|
];
|
|
17
|
-
|
|
18
|
-
//#region src/define/define.ts
|
|
17
|
+
// src/define/define.ts
|
|
19
18
|
/**
|
|
20
19
|
* Build a typed identity `defineConfig` for a specific config shape.
|
|
21
20
|
*
|
|
@@ -31,8 +30,7 @@ const DEFAULT_EXTENSIONS = [
|
|
|
31
30
|
function createDefineConfig() {
|
|
32
31
|
return (config) => config;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
//#region src/errors/errors.ts
|
|
33
|
+
// src/errors/errors.ts
|
|
36
34
|
/**
|
|
37
35
|
* Thrown when a config file is found but cannot be loaded — malformed
|
|
38
36
|
* JSON, a syntax error in a `.ts` / `.js` module, or no usable default
|
|
@@ -47,8 +45,7 @@ var ConfigFileError = class extends Error {
|
|
|
47
45
|
this.filepath = filepath;
|
|
48
46
|
}
|
|
49
47
|
};
|
|
50
|
-
|
|
51
|
-
//#region src/is-file/is-file.ts
|
|
48
|
+
// src/is-file/is-file.ts
|
|
52
49
|
async function isFile(path) {
|
|
53
50
|
try {
|
|
54
51
|
return (await stat(path)).isFile();
|
|
@@ -56,8 +53,7 @@ async function isFile(path) {
|
|
|
56
53
|
return false;
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
|
|
60
|
-
//#region src/load-file/load-file.ts
|
|
56
|
+
// src/load-file/load-file.ts
|
|
61
57
|
/**
|
|
62
58
|
* The actual file-loading mechanics `load.ts`'s exported functions share:
|
|
63
59
|
* JSON parsing, dynamic `import()` (TS via `tsx`'s persistent ESM loader,
|
|
@@ -114,8 +110,7 @@ function extractDefault(filepath, mod) {
|
|
|
114
110
|
if (raw === void 0 || raw === null) throw new ConfigFileError(`${filepath} must have a default export (use \`export default defineConfig({…})\`)`, filepath);
|
|
115
111
|
return raw;
|
|
116
112
|
}
|
|
117
|
-
|
|
118
|
-
//#region src/probe-extensions/probe-extensions.ts
|
|
113
|
+
// src/probe-extensions/probe-extensions.ts
|
|
119
114
|
/**
|
|
120
115
|
* Probe `dir` for `<name>.config.<ext>` in extension-priority order,
|
|
121
116
|
* loading and returning the first match. The one piece of per-directory
|
|
@@ -133,8 +128,7 @@ async function probeExtensions(dir, name, extensions) {
|
|
|
133
128
|
};
|
|
134
129
|
}
|
|
135
130
|
}
|
|
136
|
-
|
|
137
|
-
//#region src/load-config-file/load-config-file.ts
|
|
131
|
+
// src/load-config-file/load-config-file.ts
|
|
138
132
|
/**
|
|
139
133
|
* Discover and load `<name>.config.*` files, or load one from content that
|
|
140
134
|
* didn't come from a file at all ({@link loadConfigFromContent}).
|
|
@@ -169,8 +163,7 @@ async function loadConfigFile(opts) {
|
|
|
169
163
|
if (!opts.walkUp) return await checkDir(opts.cwd) ?? null;
|
|
170
164
|
return await findUpward(opts.cwd, checkDir, hasGitEntry) ?? null;
|
|
171
165
|
}
|
|
172
|
-
|
|
173
|
-
//#region src/load-config-from-content/load-config-from-content.ts
|
|
166
|
+
// src/load-config-from-content/load-config-from-content.ts
|
|
174
167
|
/**
|
|
175
168
|
* Load config from content that didn't come from a file already on disk —
|
|
176
169
|
* writes it to `<dir>/<name>.config.<extension>` first, then loads it
|
|
@@ -189,8 +182,7 @@ async function loadConfigFromContent(opts) {
|
|
|
189
182
|
filepath
|
|
190
183
|
};
|
|
191
184
|
}
|
|
192
|
-
|
|
193
|
-
//#region src/merge-layers/merge-layers.ts
|
|
185
|
+
// src/merge-layers/merge-layers.ts
|
|
194
186
|
/**
|
|
195
187
|
* Deep-merges config layers, lowest priority first (a later layer wins on
|
|
196
188
|
* scalars; arrays concatenate; nested objects merge). `undefined` layers are
|
|
@@ -206,8 +198,7 @@ function mergeLayers(layers) {
|
|
|
206
198
|
if (present.length === 0) return void 0;
|
|
207
199
|
return present.reduce((acc, layer) => deepMerge(acc, layer), {});
|
|
208
200
|
}
|
|
209
|
-
|
|
210
|
-
//#region src/load-layered/load-layered.ts
|
|
201
|
+
// src/load-layered/load-layered.ts
|
|
211
202
|
/**
|
|
212
203
|
* `<name>.config.*` layered over the `[fallback.key]` of
|
|
213
204
|
* `<fallback.file>.config.*`. Either, both, or neither may be present;
|
|
@@ -247,8 +238,7 @@ async function loadLayered(opts) {
|
|
|
247
238
|
sources
|
|
248
239
|
};
|
|
249
240
|
}
|
|
250
|
-
|
|
251
|
-
//#region src/read-config-source/read-config-source.ts
|
|
241
|
+
// src/read-config-source/read-config-source.ts
|
|
252
242
|
/**
|
|
253
243
|
* {@link probeExtensions} for a config that lives somewhere other than the
|
|
254
244
|
* local disk (a GitHub API, a git blob): probes `<name>.config.<ext>` in
|
|
@@ -267,8 +257,7 @@ async function readConfigSource(options) {
|
|
|
267
257
|
};
|
|
268
258
|
}
|
|
269
259
|
}
|
|
270
|
-
|
|
271
|
-
//#region src/with-config-sandbox/with-config-sandbox.ts
|
|
260
|
+
// src/with-config-sandbox/with-config-sandbox.ts
|
|
272
261
|
/**
|
|
273
262
|
* Runs `run` with a throwaway directory prepared for
|
|
274
263
|
* {@link loadConfigFromContent}'s `dir`, and removes it afterwards (also when
|
|
@@ -304,5 +293,4 @@ async function withConfigSandbox(options, run) {
|
|
|
304
293
|
});
|
|
305
294
|
}
|
|
306
295
|
}
|
|
307
|
-
//#endregion
|
|
308
296
|
export { ConfigFileError, DEFAULT_EXTENSIONS, createDefineConfig, loadConfigFile, loadConfigFromContent, loadLayered, mergeConfig, mergeLayers, readConfigSource, withConfigSandbox };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/datapad",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.248",
|
|
4
4
|
"description": "Generic config-file loading for Holocron — discover, load (JSON/JS/TS/ESM/CJS), and merge <name>.config.* files with a typed defineConfig.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"@theholocron/tsdown-config": "^8.8.2",
|
|
44
44
|
"@theholocron/vitest-config": "^8.8.2",
|
|
45
45
|
"@types/node": "^26",
|
|
46
|
-
"@vitest/coverage-v8": "^
|
|
46
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
47
47
|
"@vitest/eslint-plugin": "^1.6.27",
|
|
48
48
|
"eslint": "^10.8.1",
|
|
49
49
|
"eslint-plugin-n": "^18.3.0",
|
|
50
50
|
"globals": "^17.11.0",
|
|
51
|
-
"tsdown": "^0.
|
|
51
|
+
"tsdown": "^0.23.3",
|
|
52
52
|
"typescript": "^5.9.3",
|
|
53
|
-
"vitest": "^
|
|
53
|
+
"vitest": "^5.0.5"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=22"
|