@theholocron/datapad 5.0.0-alpha.372 → 5.0.0-alpha.373

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
@@ -87,6 +87,13 @@ the file isn't there, and throws for any other failure) and returns the first
87
87
  hit as `{ path, extension, content }`, or `undefined`. Hand the result to
88
88
  `loadConfigFromContent`.
89
89
 
90
+ ### `loadConfigPath<T>(filepath)`
91
+
92
+ Loads the one file at `filepath`, whatever its name (`linear-trial.json`), for a file the caller names rather than one
93
+ found by convention: `.json` is parsed, `.ts` goes through `tsx`, `.js`, `.mjs` and `.cjs` are imported, and the default
94
+ export is the value. Throws `ConfigFileError` for a missing file, an extension that is not one of those, or a file that
95
+ cannot be loaded.
96
+
90
97
  ### `loadConfigDir<T>({ cwd, dir, areas, extensions? })`
91
98
 
92
99
  Loads the area files of a config directory (`.holocron/notifications.ts`,
package/dist/index.d.mts CHANGED
@@ -137,6 +137,17 @@ interface LoadConfigFromContentOptions {
137
137
  * included, not a re-implemented parser.
138
138
  */
139
139
  export declare function loadConfigFromContent<T>(opts: LoadConfigFromContentOptions): Promise<Loaded<T>>;
140
+ /**
141
+ * Load the one file at `filepath`, whatever its name: `.json` is parsed, `.ts` goes through `tsx`, and `.js`, `.mjs`
142
+ * and `.cjs` are imported; the default export is the value. For a file the caller names (a flag's argument) rather
143
+ * than one found by convention.
144
+ *
145
+ * Throws {@link ConfigFileError} when the file is missing, has an extension that is not one of
146
+ * {@link DEFAULT_EXTENSIONS}, or cannot be loaded.
147
+ *
148
+ * @param filepath - Absolute path of the file.
149
+ */
150
+ export declare function loadConfigPath<T = unknown>(filepath: string): Promise<T>;
140
151
  /** Options for loading a dedicated config file layered over a fallback file's key. */
141
152
  interface LoadLayeredOptions<T = unknown> extends LoadConfigFileOptions {
142
153
  /**
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { findRoot, findUpward, hasGitEntry } from "@theholocron/fs-utils";
2
- import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
2
+ import { dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
3
  import { mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
4
4
  import { pathToFileURL } from "node:url";
5
5
  import { errorMessage } from "@theholocron/misc-utils";
@@ -236,6 +236,24 @@ async function loadConfigFromContent(opts) {
236
236
  filepath
237
237
  };
238
238
  }
239
+ // src/load-config-path/load-config-path.ts
240
+ const SUPPORTED = DEFAULT_EXTENSIONS;
241
+ /**
242
+ * Load the one file at `filepath`, whatever its name: `.json` is parsed, `.ts` goes through `tsx`, and `.js`, `.mjs`
243
+ * and `.cjs` are imported; the default export is the value. For a file the caller names (a flag's argument) rather
244
+ * than one found by convention.
245
+ *
246
+ * Throws {@link ConfigFileError} when the file is missing, has an extension that is not one of
247
+ * {@link DEFAULT_EXTENSIONS}, or cannot be loaded.
248
+ *
249
+ * @param filepath - Absolute path of the file.
250
+ */
251
+ async function loadConfigPath(filepath) {
252
+ if (!await isFile(filepath)) throw new ConfigFileError(`${filepath} is not a file`, filepath);
253
+ const extension = extname(filepath).slice(1);
254
+ if (!SUPPORTED.includes(extension)) throw new ConfigFileError(`${filepath} must be a .${SUPPORTED.join(", .")} file`, filepath);
255
+ return loadFile(filepath, extension);
256
+ }
239
257
  // src/merge-layers/merge-layers.ts
240
258
  /**
241
259
  * Deep-merges config layers, lowest priority first (a later layer wins on
@@ -398,4 +416,4 @@ async function writeConfigDir(options) {
398
416
  }
399
417
  return targets.map(({ target }) => target);
400
418
  }
401
- export { ConfigFileError, DEFAULT_EXTENSIONS, createDefineConfig, loadConfigDir, loadConfigFile, loadConfigFromContent, loadLayered, mergeConfig, mergeLayers, readConfigDirSource, readConfigSource, withConfigSandbox, writeConfigDir };
419
+ export { ConfigFileError, DEFAULT_EXTENSIONS, createDefineConfig, loadConfigDir, loadConfigFile, loadConfigFromContent, loadConfigPath, loadLayered, mergeConfig, mergeLayers, readConfigDirSource, readConfigSource, withConfigSandbox, writeConfigDir };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/datapad",
3
- "version": "5.0.0-alpha.372",
3
+ "version": "5.0.0-alpha.373",
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.2",
37
- "@theholocron/misc-utils": "^1.17.0-alpha.2",
38
- "@theholocron/object-utils": "^1.17.0-alpha.2"
37
+ "@theholocron/object-utils": "^1.17.0-alpha.2",
38
+ "@theholocron/misc-utils": "^1.17.0-alpha.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^26",
@@ -48,9 +48,9 @@
48
48
  "typescript": "^5.9.3",
49
49
  "vitest": "^5.1.0",
50
50
  "@theholocron/eslint-config": "^8.9.0-alpha.12",
51
- "@theholocron/vitest-config": "^8.9.0-alpha.12",
51
+ "@theholocron/tsconfig": "^8.9.0-alpha.12",
52
52
  "@theholocron/tsdown-config": "^8.9.0-alpha.12",
53
- "@theholocron/tsconfig": "^8.9.0-alpha.12"
53
+ "@theholocron/vitest-config": "^8.9.0-alpha.12"
54
54
  },
55
55
  "engines": {
56
56
  "node": ">=22"