@theholocron/datapad 5.0.0-alpha.353 → 5.0.0-alpha.355
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 +15 -0
- package/dist/index.mjs +42 -14
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -41,6 +41,11 @@ interface ConfigDirArea<T = unknown> {
|
|
|
41
41
|
filepath: string;
|
|
42
42
|
/** The file's default export (`.ts`, `.js`, `.mjs`, `.cjs`) or its parsed content (`.json`). */
|
|
43
43
|
value: T;
|
|
44
|
+
/**
|
|
45
|
+
* The same area read from the repository root's directory, when this one is the config's own and the root has a
|
|
46
|
+
* file for it too. Only areas named in `shared` are looked up there. Absent when the root has no such file.
|
|
47
|
+
*/
|
|
48
|
+
root?: ConfigDirArea<T>;
|
|
44
49
|
}
|
|
45
50
|
/** Options for loading the area files of a config directory from disk. */
|
|
46
51
|
interface LoadConfigDirOptions {
|
|
@@ -50,6 +55,13 @@ interface LoadConfigDirOptions {
|
|
|
50
55
|
dir: string;
|
|
51
56
|
/** The closed list of area names to look for. Files not named here are never read. */
|
|
52
57
|
areas: readonly string[];
|
|
58
|
+
/**
|
|
59
|
+
* Area names that are also read from the repository root's `dir` (the nearest ancestor of `cwd` with a `.git`
|
|
60
|
+
* entry, `cwd` itself first). A shared area with a file in both places comes back as the one in `cwd` with the
|
|
61
|
+
* root's as `root`; one that only the root has comes back as the root's file, its `path` relative to `cwd`. The
|
|
62
|
+
* caller decides how the two combine. When `cwd` is the root there is nothing to inherit.
|
|
63
|
+
*/
|
|
64
|
+
shared?: readonly string[];
|
|
53
65
|
/** Override the extension probe order. */
|
|
54
66
|
extensions?: readonly string[];
|
|
55
67
|
}
|
|
@@ -59,6 +71,9 @@ interface LoadConfigDirOptions {
|
|
|
59
71
|
* with no file are left out, so a missing directory returns `[]`. When one area has files in two formats, the
|
|
60
72
|
* extension priority picks one (`.ts` over `.json`). Throws {@link ConfigFileError} when a file exists but cannot be
|
|
61
73
|
* loaded. Holocron-agnostic: the directory and the area names are parameters, and what an area means is the caller's.
|
|
74
|
+
*
|
|
75
|
+
* Areas named in `options.shared` are also looked up in the repository root's directory (see
|
|
76
|
+
* {@link LoadConfigDirOptions.shared}), so a config in a subdirectory can inherit what the repo declares once.
|
|
62
77
|
*/
|
|
63
78
|
export declare function loadConfigDir<T = unknown>(options: LoadConfigDirOptions): Promise<ConfigDirArea<T>[]>;
|
|
64
79
|
/** Options for finding and loading a config file from disk. */
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { findRoot, findUpward, hasGitEntry } from "@theholocron/fs-utils";
|
|
2
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
2
3
|
import { mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
3
4
|
import { pathToFileURL } from "node:url";
|
|
4
5
|
import { errorMessage } from "@theholocron/misc-utils";
|
|
5
|
-
import { findUpward, hasGitEntry } from "@theholocron/fs-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
|
|
@@ -111,6 +111,32 @@ function extractDefault(filepath, mod) {
|
|
|
111
111
|
if (raw === void 0 || raw === null) throw new ConfigFileError(`${filepath} must have a default export (use \`export default defineConfig({…})\`)`, filepath);
|
|
112
112
|
return raw;
|
|
113
113
|
}
|
|
114
|
+
// src/load-config-dir-area/load-config-dir-area.ts
|
|
115
|
+
/**
|
|
116
|
+
* Load one area of a config directory: the first of `<root>/<dir>/<area>.{ts,js,mjs,cjs,json}` that exists, or
|
|
117
|
+
* `undefined` when there is none. `path` on the result is relative to `base` (the directory the caller treats as
|
|
118
|
+
* its own), with `/` separators, so an area read from an ancestor directory comes back as `../../.holocron/org.ts`.
|
|
119
|
+
* Throws {@link ConfigFileError} when the file exists but cannot be loaded.
|
|
120
|
+
*
|
|
121
|
+
* @param root - The directory holding `dir`.
|
|
122
|
+
* @param base - The directory `path` is relative to; the same as `root` for the caller's own directory.
|
|
123
|
+
* @param dir - The directory the area lives in, relative to `root`: `".holocron"`.
|
|
124
|
+
* @param area - The area's name.
|
|
125
|
+
* @param extensions - The extension probe order. Default {@link DEFAULT_EXTENSIONS}.
|
|
126
|
+
*/
|
|
127
|
+
async function loadConfigDirArea(root, base, dir, area, extensions = DEFAULT_EXTENSIONS) {
|
|
128
|
+
for (const extension of extensions) {
|
|
129
|
+
const filepath = join(root, dir, `${area}.${extension}`);
|
|
130
|
+
if (!await isFile(filepath)) continue;
|
|
131
|
+
return {
|
|
132
|
+
area,
|
|
133
|
+
path: relative(base, filepath).split(sep).join("/"),
|
|
134
|
+
extension,
|
|
135
|
+
filepath,
|
|
136
|
+
value: await loadFile(filepath, extension)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
114
140
|
// src/load-config-dir/load-config-dir.ts
|
|
115
141
|
/**
|
|
116
142
|
* Load the area files of a config directory: for each name in `options.areas`, the first of
|
|
@@ -118,21 +144,23 @@ function extractDefault(filepath, mod) {
|
|
|
118
144
|
* with no file are left out, so a missing directory returns `[]`. When one area has files in two formats, the
|
|
119
145
|
* extension priority picks one (`.ts` over `.json`). Throws {@link ConfigFileError} when a file exists but cannot be
|
|
120
146
|
* loaded. Holocron-agnostic: the directory and the area names are parameters, and what an area means is the caller's.
|
|
147
|
+
*
|
|
148
|
+
* Areas named in `options.shared` are also looked up in the repository root's directory (see
|
|
149
|
+
* {@link LoadConfigDirOptions.shared}), so a config in a subdirectory can inherit what the repo declares once.
|
|
121
150
|
*/
|
|
122
151
|
async function loadConfigDir(options) {
|
|
152
|
+
const shared = options.shared ?? [];
|
|
153
|
+
const root = shared.length > 0 ? await findRoot(options.cwd, ".git") : void 0;
|
|
154
|
+
const inheritFrom = root !== void 0 && root !== options.cwd ? root : void 0;
|
|
123
155
|
const areas = [];
|
|
124
|
-
for (const area of options.areas)
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
filepath,
|
|
133
|
-
value: await loadFile(filepath, extension)
|
|
134
|
-
});
|
|
135
|
-
break;
|
|
156
|
+
for (const area of options.areas) {
|
|
157
|
+
const own = await loadConfigDirArea(options.cwd, options.cwd, options.dir, area, options.extensions);
|
|
158
|
+
const inherited = inheritFrom !== void 0 && shared.includes(area) ? await loadConfigDirArea(inheritFrom, options.cwd, options.dir, area, options.extensions) : void 0;
|
|
159
|
+
const found = own && inherited ? {
|
|
160
|
+
...own,
|
|
161
|
+
root: inherited
|
|
162
|
+
} : own ?? inherited;
|
|
163
|
+
if (found) areas.push(found);
|
|
136
164
|
}
|
|
137
165
|
return areas;
|
|
138
166
|
}
|
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.355",
|
|
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",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"tsx": "4.23.15",
|
|
36
36
|
"@theholocron/fs-utils": "^1.17.0-alpha.1",
|
|
37
|
-
"@theholocron/
|
|
38
|
-
"@theholocron/
|
|
37
|
+
"@theholocron/object-utils": "^1.17.0-alpha.1",
|
|
38
|
+
"@theholocron/misc-utils": "^1.17.0-alpha.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^26",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"tsdown": "^0.23.4",
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"vitest": "^5.0.5",
|
|
50
|
-
"@theholocron/tsconfig": "^8.9.0-alpha.8",
|
|
51
|
-
"@theholocron/tsdown-config": "^8.9.0-alpha.8",
|
|
52
50
|
"@theholocron/eslint-config": "^8.9.0-alpha.8",
|
|
53
|
-
"@theholocron/
|
|
51
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.8",
|
|
52
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.8",
|
|
53
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.8"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=22"
|