@wtf/project-config 1.1.0 → 2.0.0

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
@@ -6,35 +6,44 @@ One file for the settings of a project's tools: a `wtf` object with a section fo
6
6
  environment's variables over it, checks it by the tool's schema, and writes values back. A repo
7
7
  loads its config itself and hands each section to the tool it is for, as a preset's options.
8
8
 
9
- | Subpath | What you get |
10
- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11
- | `.` | The types: `NamespaceConfig`, `SectionsOf`, `ResolvedConfig`, `SectionSchema`, `ConfigPlatform`, `ConfigSyncPlatform`, … |
12
- | `./node` | `loadConfig(folder?)` and `loadConfigSync(folder?)`, of Node's disk and `process.env`; `nodeConfigPlatform()`, `nodeSyncPlatform()`; `nodeLoadModule(root?, beside?)` |
13
- | `./load` | `loadConfig(folder, { platform })`, of code or JSON; `loadConfigSync(folder, { platform })`, of JSON alone; `ignoredWarning` |
14
- | `./section` | `sectionOf(resolved, name, schema?)` and `sectionOfSync`: a tool's section, the environment over it, checked; `issuesOf`, `mergeSection` |
15
- | `./locate` | `locateConfig`, `projectRootOf` and their sync twins; `configFilesOf`, `configNamesOf`, `jsonFilesOf`, `DEFAULT_NAMESPACE` |
16
- | `./env` | `withEnvironment`, `variablesOf`, `envNameOf`, `envPrefixOf`: variables such as `WTF_VITE_COMPRESS` over a value |
17
- | `./placeholder` | `expandPlaceholders` and `expandString`: each `${env:NAME}` replaced by its variable |
18
- | `./path` | `configPathOf('vite.compress')`, `textOfConfigPath`, `valueAt` |
19
- | `./write` | `setConfigValue` and `unsetConfigValue`, in the JSON file or in package.json's key |
20
- | `./schema` | `namespaceSchema('wtf', sections)`: one JSON Schema for the whole file, of each tool's schema |
21
- | `./define` | `defineConfig<S>(config)`: a code config, typed by the sections of the tools |
22
- | `./named` | `resolveNamed`, `resolveNamedSet`, `factoryOf`, `namedSchema`, `namedSetSchema`: a value or a function named in JSON |
23
- | `./errors` | `ConfigError` and every other error, each with a stable `code` |
9
+ | Subpath | What you get |
10
+ | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
11
+ | `.` | The types: `NamespaceConfig`, `SectionsOf`, `ResolvedConfig`, `SectionSchema`, `ConfigPlatform`, `ConfigSyncPlatform`, … |
12
+ | `./load` | `loadConfig({ platform })`, of code or JSON; `loadConfigSync({ platform })`, of JSON alone; `ignoredWarning` |
13
+ | `./node` | `nodeSyncPlatform(platform)`, a platform's files read synchronously by `node:fs`; `nodeLoadModule(root, beside?)` |
14
+ | `./section` | `sectionOf(resolved, name, schema?)` and `sectionOfSync`: a tool's section, the environment over it, checked; `issuesOf`, `mergeSection` |
15
+ | `./locate` | `locateConfig`, `projectRootOf` and their sync twins; `configFilesOf`, `configNamesOf`, `jsonFilesOf`, `DEFAULT_NAMESPACE` |
16
+ | `./env` | `withEnvironment`, `variablesOf`, `envNameOf`, `envPrefixOf`: variables such as `WTF_VITE_COMPRESS` over a value |
17
+ | `./placeholder` | `expandPlaceholders` and `expandString`: each `${env:NAME}` replaced by its variable |
18
+ | `./path` | `configPathOf('vite.compress')`, `textOfConfigPath`, `valueAt` |
19
+ | `./write` | `setConfigValue` and `unsetConfigValue`, in the JSON file or in package.json's key |
20
+ | `./schema` | `namespaceSchema('wtf', sections)`: one JSON Schema for the whole file, of each tool's schema |
21
+ | `./define` | `defineConfig<S>(config)`: a code config, typed by the sections of the tools |
22
+ | `./named` | `resolveNamed`, `resolveNamedSet`, `factoryOf`, `namedSchema`, `namedSetSchema`: a value or a function named in JSON |
23
+ | `./errors` | `ConfigError` and every other error, each with a stable `code` |
24
24
 
25
25
  ```ts
26
26
  // vite.config.ts
27
- import { loadConfig } from '@wtf/project-config/node'
27
+ import { nodeStorage } from '@wtf/platform-fs-node/storage'
28
+ import { nodePlatform } from '@wtf/platform-node/platform'
29
+ import { loadConfig } from '@wtf/project-config/load'
28
30
  import { sectionOf } from '@wtf/project-config/section'
29
- import { baseConfig, type BaseOptions } from '@wtf/project-vite/config'
31
+ import { baseConfig } from '@wtf/project-vite/config'
32
+ import { viteSchema } from '@wtf/project-vite/schema'
30
33
 
31
- const config = await loadConfig()
32
- export default baseConfig({ ...(await sectionOf<BaseOptions>(config, 'vite')) })
34
+ const platform = nodePlatform({ fetch, storage: nodeStorage() })
35
+ const config = await loadConfig({ platform })
36
+ export default baseConfig({ platform, ...(await sectionOf(config, 'vite', viteSchema)) })
33
37
  ```
34
38
 
39
+ The config file is the entry point: it builds the platform, and the loads read through it alone,
40
+ its files, its working folder, where the project is looked for from, and its environment. Nothing
41
+ here reads the process.
42
+
35
43
  ## Where it looks
36
44
 
37
- It looks at the root of the workspace the folder is in (the nearest folder up with a
45
+ It looks at the root of the workspace the folder is in, the working folder of the platform by
46
+ default (the nearest folder up with a
38
47
  pnpm-workspace.yaml, or a package.json of `workspaces`), else the nearest package.json's folder.
39
48
  There it uses the first of `wtf.config.mjs`, `wtf.config.js`, `wtf.config.ts`, `wtf.config.json`
40
49
  and the `wtf` key of package.json, and ignores the others: `ignoredWarning` says which. A tool can
@@ -47,13 +56,14 @@ imports it, `wtf.config.ts` too, as it strips the types itself.
47
56
  ## Asynchronous and synchronous
48
57
 
49
58
  `loadConfig` reads every kind of file, as importing code is asynchronous. `loadConfigSync` is for a
50
- tool that loads its own config synchronously: it reads `wtf.config.json` and package.json's key,
59
+ tool that loads its own config synchronously: it reads `wtf.config.json` and package.json's key, of
60
+ a platform whose files are read synchronously, as `nodeSyncPlatform(platform)` of `./node` gives,
51
61
  and throws a `SyncConfigInCodeError` when the config in use is code. `sectionOfSync` checks a
52
62
  section synchronously, and throws a `SyncSchemaError` of a schema that answers with a promise.
53
63
 
54
64
  ## The environment over it
55
65
 
56
- The loads of `./node` keep `process.env`. A variable `WTF_<SECTION>_<KEY>` sets a value of a
66
+ The loads keep the environment of the platform, its `env`. A variable `WTF_<SECTION>_<KEY>` sets a value of a
57
67
  section as it is read, a JSON value or else the text: `WTF_VITE_COMPRESS=false` sets
58
68
  `wtf.vite.compress`. A key of camelCase is its words in capitals, so `testTimeout` is
59
69
  `TEST_TIMEOUT`. A variable sets a key the section has, or its schema names, and no other. A string in a section can point at a variable with
@@ -97,9 +107,11 @@ import {
97
107
  type Format = { readonly width: number; readonly ellipsis: string }
98
108
  declare const configured: { formatters?: NamedSet<Format>[]; format: NamedReference }
99
109
 
110
+ declare const root: string
111
+
100
112
  const builtin = { short: { width: 40, ellipsis: '…' } }
101
113
  const formatters = await resolveNamedSet<Format>([builtin, ...(configured.formatters ?? [])], {
102
- load: nodeLoadModule(process.cwd(), import.meta.url)
114
+ load: nodeLoadModule(root, import.meta.url)
103
115
  })
104
116
  const format = await resolveNamed<Format>(configured.format, {
105
117
  key: 'format',
@@ -110,8 +122,12 @@ const format = await resolveNamed<Format>(configured.format, {
110
122
 
111
123
  A name of no entry throws a `NamedError` of `UNKNOWN_NAME`, which lists the names there are; a
112
124
  module that fails to load, `UNLOADABLE_MODULE`; an export it has not, `MISSING_EXPORT`; and a value
113
- of the wrong shape, or one the `check` you pass refuses, `INVALID_NAMED_VALUE`. `nodeLoadModule`
114
- loads a path from the root, and a package the root installs, else one installed beside your tool.
125
+ of the wrong shape, or one the `check` you pass refuses, `INVALID_NAMED_VALUE`. Each names where
126
+ it failed: its `at` path, from the `at` you pass, the index of the `set` and the name of the
127
+ `entry`, and the `module` and `export` a value came from. With `checkResults: true`, `check` also
128
+ checks what each function entry gives. `nodeLoadModule`
129
+ loads a path from the root you give it, and a package the root installs, else one installed beside
130
+ your tool.
115
131
  `namedSchema('format', { names, options })` and `namedSetSchema({ entry })` give the schema of a
116
132
  reference and of the sets, so an editor completes the names.
117
133
 
@@ -119,7 +135,8 @@ reference and of the sets, so an editor completes the names.
119
135
 
120
136
  `./load`, `./locate` and `./write` read through the platform you pass: a `Platform` of
121
137
  [`@wtf/platform`](https://www.npmjs.com/package/@wtf/platform), whose `navigator.storage` gives
122
- the root of a WHATWG File System, as a browser's or `@wtf/platform-fs-memory`'s. The sync loads take
123
- a `ConfigSyncPlatform`, whose files are read synchronously. `./node` gives Node's of each.
138
+ the root of a WHATWG File System, as a browser's or `@wtf/platform-fs-memory`'s, or
139
+ `nodeStorage()` of `@wtf/platform-fs-node` for Node's disk. The sync load takes a platform whose
140
+ files are read synchronously, which `nodeSyncPlatform` of `./node` makes of Node's.
124
141
 
125
142
  See the [configuration guide](../project-docs/guides/config.md).
package/dist/env.js CHANGED
@@ -48,16 +48,52 @@ function schemasOf(node, root, seen = new Set()) {
48
48
  const propertyOf = (node, root, key) => schemasOf(node, root).flatMap((schema) => isNode(schema.properties) && Object.hasOwn(schema.properties, key)
49
49
  ? [schema.properties[key]]
50
50
  : []);
51
- /** Whether a value of the schemas `nodes` is only ever a string: of a `type` `string`, a `const`
52
- * or an `enum` of strings, each branch of it so. */
53
- function onlyString(nodes, root) {
51
+ /** Whether the schemas `nodes`, of the document `root`, take a string: one of them, or a branch of
52
+ * one, of a `type` `string`, a `const` or an `enum` of strings, or a union of such branches. */
53
+ function takesString(nodes, root) {
54
54
  const schemas = nodes.flatMap((node) => schemasOf(node, root));
55
55
  return schemas.some((schema) => schema.type === 'string' ||
56
56
  typeof schema.const === 'string' ||
57
57
  (Array.isArray(schema.enum) && schema.enum.every((value) => typeof value === 'string')) ||
58
58
  ['anyOf', 'oneOf'].some((key) => Array.isArray(schema[key]) &&
59
- schema[key].every((branch) => onlyString([branch], root))));
59
+ schema[key].every((branch) => takesString([branch], root))));
60
60
  }
61
+ /** The types of JSON `value` is of: `integer` beside `number` of a whole number. */
62
+ const typesOf = (value) => value === null
63
+ ? ['null']
64
+ : Array.isArray(value)
65
+ ? ['array']
66
+ : typeof value === 'number'
67
+ ? Number.isInteger(value)
68
+ ? ['number', 'integer']
69
+ : ['number']
70
+ : [typeof value];
71
+ /**
72
+ * Whether the schema `node`, of the document `root`, takes a value of the type of `value`: of its
73
+ * `type`, `const` and `enum`, each of its `allOf`, and some branch of its `anyOf` and `oneOf`, each
74
+ * by its `$ref`; a schema that says none of those takes any value.
75
+ */
76
+ function takes(node, value, root, seen = new Set()) {
77
+ const schema = derefOf(node, root);
78
+ if (typeof schema === 'boolean')
79
+ return schema;
80
+ if (!isNode(schema) || seen.has(schema))
81
+ return true;
82
+ const within = new Set(seen).add(schema);
83
+ const { type } = schema;
84
+ const types = typeof type === 'string' ? [type] : Array.isArray(type) ? type : undefined;
85
+ const text = JSON.stringify(value);
86
+ const branches = (key) => Array.isArray(schema[key]) ? schema[key] : [];
87
+ return ((types === undefined || typesOf(value).some((each) => types.includes(each))) &&
88
+ (!('const' in schema) || JSON.stringify(schema.const) === text) &&
89
+ (!Array.isArray(schema.enum) || schema.enum.some((each) => JSON.stringify(each) === text)) &&
90
+ branches('allOf').every((branch) => takes(branch, value, root, within)) &&
91
+ ['anyOf', 'oneOf'].every((key) => branches(key).length === 0 ||
92
+ branches(key).some((branch) => takes(branch, value, root, within))));
93
+ }
94
+ /** Whether each of the schemas `nodes`, of the document `root`, takes a value of the type of
95
+ * `value` ({@link takes}). */
96
+ const takenBy = (nodes, value, root) => nodes.every((node) => takes(node, value, root));
61
97
  /** The keys a value can have, as the value `value` and the schemas `nodes` name them, the
62
98
  * longest of them as a variable names it first, so `API_KEY` is `apiKey` before it is `api.key`. */
63
99
  function keysOf(value, nodes, root) {
@@ -86,17 +122,23 @@ function pathOf(rest, value, nodes, root) {
86
122
  }
87
123
  return undefined;
88
124
  }
89
- /** The value of a variable's text: the text of a value that is only ever a string, else its JSON,
90
- * else the text. */
125
+ /**
126
+ * The value of a variable's text, of the schemas `nodes`: its JSON, of a value of a type they take
127
+ * other than a string, so `2` is a number and `[2, "newest"]` a list where a value may be a name,
128
+ * a number or a list; else the text where they take a string, so a name stays a name, and JSON
129
+ * that is no value they take is the text; else its JSON, else the text.
130
+ */
91
131
  function parsedOf(text, nodes, root) {
92
- if (onlyString(nodes, root))
93
- return text;
132
+ let parsed;
94
133
  try {
95
- return JSON.parse(text);
134
+ parsed = JSON.parse(text);
96
135
  }
97
136
  catch {
98
137
  return text;
99
138
  }
139
+ if (typeof parsed !== 'string' && takenBy(nodes, parsed, root))
140
+ return parsed;
141
+ return takesString(nodes, root) ? text : parsed;
100
142
  }
101
143
  /** `value` with `over` at `path`, merged over what is there ({@link mergeSection}). */
102
144
  function withValueAt(value, path, over) {
package/dist/env.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAkBzC;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAU,EAAE,CAChD,IAAI;KACD,UAAU,CAAC,mBAAmB,EAAE,OAAO,CAAC;KACxC,UAAU,CAAC,eAAe,EAAE,GAAG,CAAC;KAChC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC;KACxB,WAAW,EAAE,CAAA;AAElB;mFACmF;AACnF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAA;AAE1E;4BAC4B;AAC5B,MAAM,UAAU,WAAW,CAAC,WAAwB,EAAE,MAAc;IAClE,MAAM,SAAS,GAA2B,EAAE,CAAA;IAC5C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;QACrD,IACE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;YAC3B,KAAK,KAAK,SAAS;YACnB,KAAK,KAAK,EAAE;YAEZ,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;IAC3B,OAAO,SAAS,CAAA;AAClB,CAAC;AAID,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE,CAC/C,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAA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AAK,EAAE;YACrB,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC;gBAC3B,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;gBAC7D,CAAC,CAAC,SAAS,CAAA;QACjB,OAAO,EAAE,KAAK,SAAS;YACrB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,CAAA;IAC5E,CAAC,CAAC,CAAA;IACF,IAAI,MAAM,GAAG,KAAK,CAAA;IAClB,MAAM,GAAG,GAAuB,EAAE,CAAA;IAClC,KAAK,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,KAAK,CAAC,QAAQ,CAC1D,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAChF,EAAE,CAAC;QACF,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QACxC,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAC9B,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAA;AAC/B,CAAC","sourcesContent":["/**\n * The configuration of a project, as the environment overrides it: a variable of the prefix of its\n * names, of the key of package.json by default, as `WTF_` of the key `wtf` ({@link envPrefixOf}),\n * followed by the path of a value, each key as a variable names it ({@link envNameOf}):\n * `WTF_VITE_COMPRESS` sets `wtf.vite.compress`. A key is one a value under it already has, or one\n * the schema of its section names, so `apiKey` is `API_KEY` and no `_` is ever taken for a key it\n * is not. A value is JSON, else the text as it is, and the text always of a value the schema takes\n * only as a string. {@link variablesOf} gives the variables of a prefix, and\n * {@link withEnvironment} a value with them over it, as `sectionOf` of ./section reads a section.\n * The variables are what a caller gives, as `loadConfig` of ./load takes them: nothing here reads\n * the environment of a process.\n *\n * ```ts\n * withEnvironment({ compress: { threshold: 1024 } }, { WTF_VITE_COMPRESS_THRESHOLD: '512' }, 'WTF_VITE_')\n * // { value: { compress: { threshold: 512 } }, set: [{ variable: 'WTF_VITE_COMPRESS_THRESHOLD', path: ['compress', 'threshold'] }] }\n * ```\n *\n * @packageDocumentation\n */\nimport type { StandardJSONSchemaV1 } from '@standard-schema/spec'\n\nimport type { ConfigPath, JsonSchema } from './index.ts'\nimport { mergeSection } from './merge.ts'\n\n/** The variables of an environment, by their names, as a process's environment holds them. */\nexport type Environment = Readonly<Record<string, string | undefined>>\n\n/** A variable of the environment that set a value of the configuration: its name, and the path\n * of the value. */\nexport type EnvironmentValue = {\n readonly variable: string\n readonly path: ConfigPath\n}\n\n/** A value with the environment over it: the value, and each variable that set some of it. */\nexport type WithEnvironment = {\n readonly value: unknown\n readonly set: readonly EnvironmentValue[]\n}\n\n/**\n * A name as a variable of the environment writes it: its words in capitals, joined by `_`, a word\n * of camelCase its own, as `apiKey` is `API_KEY`, and any other character a `_`.\n */\nexport const envNameOf = (name: string): string =>\n name\n .replaceAll(/([a-z\\d])([A-Z])/g, '$1_$2')\n .replaceAll(/[^A-Za-z\\d]+/g, '_')\n .replaceAll(/^_|_$/g, '')\n .toUpperCase()\n\n/** The prefix of the variables of the environment of `name`, the key of package.json by default:\n * {@link envNameOf} it, and `_`, as `wtf` is `WTF_` and `wtf-vite` `WTF_VITE_`. */\nexport const envPrefixOf = (name: string): string => `${envNameOf(name)}_`\n\n/** The variables of `environment` of `prefix`, as {@link envPrefixOf} gives it, each set and not\n * empty, by their names. */\nexport function variablesOf(environment: Environment, prefix: string): Record<string, string> {\n const variables: Record<string, string> = {}\n for (const [name, value] of Object.entries(environment))\n if (\n name.startsWith(prefix) &&\n name.length > prefix.length &&\n value !== undefined &&\n value !== ''\n )\n variables[name] = value\n return variables\n}\n\ntype Node = Readonly<Record<string, unknown>>\n\nconst isNode = (value: unknown): value is Node =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/** The node a `$ref` of the document `root` names, as `#/$defs/api`; the node itself of none. */\nfunction derefOf(node: unknown, root: unknown): unknown {\n if (!isNode(node) || typeof node.$ref !== 'string' || !node.$ref.startsWith('#')) return node\n let at: unknown = root\n for (const part of node.$ref.slice(1).split('/').filter(Boolean))\n at = isNode(at) ? at[part.replaceAll('~1', '/').replaceAll('~0', '~')] : undefined\n return at\n}\n\n/** The schemas `node` is, of the document `root`: itself, and each of its `allOf`, `anyOf` and\n * `oneOf`, each by its `$ref`. */\nfunction schemasOf(node: unknown, root: unknown, seen = new Set<unknown>()): Node[] {\n const schema = derefOf(node, root)\n if (!isNode(schema) || seen.has(schema)) return []\n seen.add(schema)\n const branches = ['allOf', 'anyOf', 'oneOf'].flatMap((key) =>\n Array.isArray(schema[key]) ? (schema[key] as unknown[]) : []\n )\n return [schema, ...branches.flatMap((branch) => schemasOf(branch, root, seen))]\n}\n\n/** The schema of the key `key` of a value of the schema `node`: of each of its `properties` that\n * names it. */\nconst propertyOf = (node: unknown, root: unknown, key: string): unknown[] =>\n schemasOf(node, root).flatMap((schema) =>\n isNode(schema.properties) && Object.hasOwn(schema.properties, key)\n ? [schema.properties[key]]\n : []\n )\n\n/** Whether a value of the schemas `nodes` is only ever a string: of a `type` `string`, a `const`\n * or an `enum` of strings, each branch of it so. */\nfunction onlyString(nodes: readonly unknown[], root: unknown): boolean {\n const schemas = nodes.flatMap((node) => schemasOf(node, root))\n return schemas.some(\n (schema) =>\n schema.type === 'string' ||\n typeof schema.const === 'string' ||\n (Array.isArray(schema.enum) && schema.enum.every((value) => typeof value === 'string')) ||\n (['anyOf', 'oneOf'] as const).some(\n (key) =>\n Array.isArray(schema[key]) &&\n (schema[key] as unknown[]).every((branch) => onlyString([branch], root))\n )\n )\n}\n\n/** The keys a value can have, as the value `value` and the schemas `nodes` name them, the\n * longest of them as a variable names it first, so `API_KEY` is `apiKey` before it is `api.key`. */\nfunction keysOf(value: unknown, nodes: readonly unknown[], root: unknown): string[] {\n const keys = new Set(isNode(value) ? Object.keys(value) : [])\n for (const schema of nodes.flatMap((node) => schemasOf(node, root)))\n if (isNode(schema.properties)) for (const key of Object.keys(schema.properties)) keys.add(key)\n return [...keys].toSorted((a, b) => envNameOf(b).length - envNameOf(a).length)\n}\n\n/** The path the rest of a variable's name, `rest`, names in `value`, of the schemas `nodes`, and\n * the schemas of the value there; `undefined` when it names no key there is. */\nfunction pathOf(\n rest: string,\n value: unknown,\n nodes: readonly unknown[],\n root: unknown\n): { readonly path: string[]; readonly nodes: readonly unknown[] } | undefined {\n for (const key of keysOf(value, nodes, root)) {\n const name = envNameOf(key)\n if (name === '') continue\n const under = nodes.flatMap((node) => propertyOf(node, root, key))\n if (rest === name) return { path: [key], nodes: under }\n if (rest.startsWith(`${name}_`)) {\n const found = pathOf(\n rest.slice(name.length + 1),\n isNode(value) ? value[key] : undefined,\n under,\n root\n )\n if (found !== undefined) return { path: [key, ...found.path], nodes: found.nodes }\n }\n }\n return undefined\n}\n\n/** The value of a variable's text: the text of a value that is only ever a string, else its JSON,\n * else the text. */\nfunction parsedOf(text: string, nodes: readonly unknown[], root: unknown): unknown {\n if (onlyString(nodes, root)) return text\n try {\n return JSON.parse(text) as unknown\n } catch {\n return text\n }\n}\n\n/** `value` with `over` at `path`, merged over what is there ({@link mergeSection}). */\nfunction withValueAt(value: unknown, path: ConfigPath, over: unknown): unknown {\n const [key, ...rest] = path\n if (key === undefined) return mergeSection(value, over)\n const object = isNode(value) ? value : {}\n return { ...object, [key]: withValueAt(object[key], rest, over) }\n}\n\n/**\n * The JSON Schema of `schema`, as a tool checks its section by it: the schema itself, of a JSON\n * Schema; of a Standard Schema that gives one, as zod's does, the JSON Schema of its input; else\n * none, of a function, or a schema that gives none.\n */\nexport function jsonSchemaOf(schema: unknown): JsonSchema | undefined {\n if (typeof schema === 'boolean') return schema\n if (!isNode(schema)) return undefined\n if (!('~standard' in schema)) return schema\n const converter = (schema as Partial<StandardJSONSchemaV1>)['~standard']?.jsonSchema\n if (converter === undefined) return undefined\n try {\n return converter.input({ target: 'draft-2020-12' })\n } catch {\n return undefined\n }\n}\n\n/**\n * `value` with the variables `variables` of `prefix` over it: each variable that names a path of\n * a key there is, in `value` or in `schema`, a JSON Schema of it, sets the value at that path,\n * merged over what is there ({@link mergeSection}), and the variable of the prefix itself, without\n * its last `_`, the whole value, a variable of a shorter path first, so `WTF_VITE_COMPRESS_THRESHOLD`\n * is over what `WTF_VITE` sets, of the prefix `WTF_VITE_`. A variable that names no key there\n * is is passed over.\n */\nexport function withEnvironment(\n value: unknown,\n variables: Readonly<Record<string, string>>,\n prefix: string,\n schema?: JsonSchema\n): WithEnvironment {\n const nodes = schema === undefined ? [] : [schema]\n const whole = prefix.slice(0, -1)\n const found = Object.entries(variables).flatMap(([variable, text]) => {\n const at =\n variable === whole\n ? { path: [], nodes }\n : variable.startsWith(prefix)\n ? pathOf(variable.slice(prefix.length), value, nodes, schema)\n : undefined\n return at === undefined\n ? []\n : [{ variable, path: at.path, value: parsedOf(text, at.nodes, schema) }]\n })\n let result = value\n const set: EnvironmentValue[] = []\n for (const { variable, path, value: over } of found.toSorted(\n (a, b) => a.path.length - b.path.length || a.variable.localeCompare(b.variable)\n )) {\n result = withValueAt(result, path, over)\n set.push({ variable, path })\n }\n return { value: result, set }\n}\n"]}
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAkBzC;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,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K,EAAE,KAAK,EAAE,MAAM,CAAC;gBAC7D,CAAC,CAAC,SAAS,CAAA;QACjB,OAAO,EAAE,KAAK,SAAS;YACrB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,CAAA;IAC5E,CAAC,CAAC,CAAA;IACF,IAAI,MAAM,GAAG,KAAK,CAAA;IAClB,MAAM,GAAG,GAAuB,EAAE,CAAA;IAClC,KAAK,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,KAAK,CAAC,QAAQ,CAC1D,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAChF,EAAE,CAAC;QACF,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QACxC,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAC9B,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAA;AAC/B,CAAC","sourcesContent":["/**\n * The configuration of a project, as the environment overrides it: a variable of the prefix of its\n * names, of the key of package.json by default, as `WTF_` of the key `wtf` ({@link envPrefixOf}),\n * followed by the path of a value, each key as a variable names it ({@link envNameOf}):\n * `WTF_VITE_COMPRESS` sets `wtf.vite.compress`. A key is one a value under it already has, or one\n * the schema of its section names, so `apiKey` is `API_KEY` and no `_` is ever taken for a key it\n * is not. A value is JSON of a type the schema takes other than a string, else the text as it is\n * where the schema takes a string, so `2` is a number and a name stays a name where a value is\n * either; of no schema, JSON, else the text. {@link variablesOf} gives the variables of a prefix, and\n * {@link withEnvironment} a value with them over it, as `sectionOf` of ./section reads a section.\n * The variables are what a caller gives, as `loadConfig` of ./load takes them of the environment of\n * the platform it is given: nothing here reads the environment of a process.\n *\n * ```ts\n * withEnvironment({ compress: { threshold: 1024 } }, { WTF_VITE_COMPRESS_THRESHOLD: '512' }, 'WTF_VITE_')\n * // { value: { compress: { threshold: 512 } }, set: [{ variable: 'WTF_VITE_COMPRESS_THRESHOLD', path: ['compress', 'threshold'] }] }\n * ```\n *\n * @packageDocumentation\n */\nimport type { StandardJSONSchemaV1 } from '@standard-schema/spec'\n\nimport type { ConfigPath, JsonSchema } from './index.ts'\nimport { mergeSection } from './merge.ts'\n\n/** The variables of an environment, by their names, as a process's environment holds them. */\nexport type Environment = Readonly<Record<string, string | undefined>>\n\n/** A variable of the environment that set a value of the configuration: its name, and the path\n * of the value. */\nexport type EnvironmentValue = {\n readonly variable: string\n readonly path: ConfigPath\n}\n\n/** A value with the environment over it: the value, and each variable that set some of it. */\nexport type WithEnvironment = {\n readonly value: unknown\n readonly set: readonly EnvironmentValue[]\n}\n\n/**\n * A name as a variable of the environment writes it: its words in capitals, joined by `_`, a word\n * of camelCase its own, as `apiKey` is `API_KEY`, and any other character a `_`.\n */\nexport const envNameOf = (name: string): string =>\n name\n .replaceAll(/([a-z\\d])([A-Z])/g, '$1_$2')\n .replaceAll(/[^A-Za-z\\d]+/g, '_')\n .replaceAll(/^_|_$/g, '')\n .toUpperCase()\n\n/** The prefix of the variables of the environment of `name`, the key of package.json by default:\n * {@link envNameOf} it, and `_`, as `wtf` is `WTF_` and `wtf-vite` `WTF_VITE_`. */\nexport const envPrefixOf = (name: string): string => `${envNameOf(name)}_`\n\n/** The variables of `environment` of `prefix`, as {@link envPrefixOf} gives it, each set and not\n * empty, by their names. */\nexport function variablesOf(environment: Environment, prefix: string): Record<string, string> {\n const variables: Record<string, string> = {}\n for (const [name, value] of Object.entries(environment))\n if (\n name.startsWith(prefix) &&\n name.length > prefix.length &&\n value !== undefined &&\n value !== ''\n )\n variables[name] = value\n return variables\n}\n\ntype Node = Readonly<Record<string, unknown>>\n\nconst isNode = (value: unknown): value is Node =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/** The node a `$ref` of the document `root` names, as `#/$defs/api`; the node itself of none. */\nfunction derefOf(node: unknown, root: unknown): unknown {\n if (!isNode(node) || typeof node.$ref !== 'string' || !node.$ref.startsWith('#')) return node\n let at: unknown = root\n for (const part of node.$ref.slice(1).split('/').filter(Boolean))\n at = isNode(at) ? at[part.replaceAll('~1', '/').replaceAll('~0', '~')] : undefined\n return at\n}\n\n/** The schemas `node` is, of the document `root`: itself, and each of its `allOf`, `anyOf` and\n * `oneOf`, each by its `$ref`. */\nfunction schemasOf(node: unknown, root: unknown, seen = new Set<unknown>()): Node[] {\n const schema = derefOf(node, root)\n if (!isNode(schema) || seen.has(schema)) return []\n seen.add(schema)\n const branches = ['allOf', 'anyOf', 'oneOf'].flatMap((key) =>\n Array.isArray(schema[key]) ? (schema[key] as unknown[]) : []\n )\n return [schema, ...branches.flatMap((branch) => schemasOf(branch, root, seen))]\n}\n\n/** The schema of the key `key` of a value of the schema `node`: of each of its `properties` that\n * names it. */\nconst propertyOf = (node: unknown, root: unknown, key: string): unknown[] =>\n schemasOf(node, root).flatMap((schema) =>\n isNode(schema.properties) && Object.hasOwn(schema.properties, key)\n ? [schema.properties[key]]\n : []\n )\n\n/** Whether the schemas `nodes`, of the document `root`, take a string: one of them, or a branch of\n * one, of a `type` `string`, a `const` or an `enum` of strings, or a union of such branches. */\nfunction takesString(nodes: readonly unknown[], root: unknown): boolean {\n const schemas = nodes.flatMap((node) => schemasOf(node, root))\n return schemas.some(\n (schema) =>\n schema.type === 'string' ||\n typeof schema.const === 'string' ||\n (Array.isArray(schema.enum) && schema.enum.every((value) => typeof value === 'string')) ||\n (['anyOf', 'oneOf'] as const).some(\n (key) =>\n Array.isArray(schema[key]) &&\n (schema[key] as unknown[]).every((branch) => takesString([branch], root))\n )\n )\n}\n\n/** The types of JSON `value` is of: `integer` beside `number` of a whole number. */\nconst typesOf = (value: unknown): readonly string[] =>\n value === null\n ? ['null']\n : Array.isArray(value)\n ? ['array']\n : typeof value === 'number'\n ? Number.isInteger(value)\n ? ['number', 'integer']\n : ['number']\n : [typeof value]\n\n/**\n * Whether the schema `node`, of the document `root`, takes a value of the type of `value`: of its\n * `type`, `const` and `enum`, each of its `allOf`, and some branch of its `anyOf` and `oneOf`, each\n * by its `$ref`; a schema that says none of those takes any value.\n */\nfunction takes(node: unknown, value: unknown, root: unknown, seen = new Set<unknown>()): boolean {\n const schema = derefOf(node, root)\n if (typeof schema === 'boolean') return schema\n if (!isNode(schema) || seen.has(schema)) return true\n const within = new Set(seen).add(schema)\n const { type } = schema\n const types = typeof type === 'string' ? [type] : Array.isArray(type) ? type : undefined\n const text = JSON.stringify(value)\n const branches = (key: string): unknown[] =>\n Array.isArray(schema[key]) ? (schema[key] as unknown[]) : []\n return (\n (types === undefined || typesOf(value).some((each) => types.includes(each))) &&\n (!('const' in schema) || JSON.stringify(schema.const) === text) &&\n (!Array.isArray(schema.enum) || schema.enum.some((each) => JSON.stringify(each) === text)) &&\n branches('allOf').every((branch) => takes(branch, value, root, within)) &&\n (['anyOf', 'oneOf'] as const).every(\n (key) =>\n branches(key).length === 0 ||\n branches(key).some((branch) => takes(branch, value, root, within))\n )\n )\n}\n\n/** Whether each of the schemas `nodes`, of the document `root`, takes a value of the type of\n * `value` ({@link takes}). */\nconst takenBy = (nodes: readonly unknown[], value: unknown, root: unknown): boolean =>\n nodes.every((node) => takes(node, value, root))\n\n/** The keys a value can have, as the value `value` and the schemas `nodes` name them, the\n * longest of them as a variable names it first, so `API_KEY` is `apiKey` before it is `api.key`. */\nfunction keysOf(value: unknown, nodes: readonly unknown[], root: unknown): string[] {\n const keys = new Set(isNode(value) ? Object.keys(value) : [])\n for (const schema of nodes.flatMap((node) => schemasOf(node, root)))\n if (isNode(schema.properties)) for (const key of Object.keys(schema.properties)) keys.add(key)\n return [...keys].toSorted((a, b) => envNameOf(b).length - envNameOf(a).length)\n}\n\n/** The path the rest of a variable's name, `rest`, names in `value`, of the schemas `nodes`, and\n * the schemas of the value there; `undefined` when it names no key there is. */\nfunction pathOf(\n rest: string,\n value: unknown,\n nodes: readonly unknown[],\n root: unknown\n): { readonly path: string[]; readonly nodes: readonly unknown[] } | undefined {\n for (const key of keysOf(value, nodes, root)) {\n const name = envNameOf(key)\n if (name === '') continue\n const under = nodes.flatMap((node) => propertyOf(node, root, key))\n if (rest === name) return { path: [key], nodes: under }\n if (rest.startsWith(`${name}_`)) {\n const found = pathOf(\n rest.slice(name.length + 1),\n isNode(value) ? value[key] : undefined,\n under,\n root\n )\n if (found !== undefined) return { path: [key, ...found.path], nodes: found.nodes }\n }\n }\n return undefined\n}\n\n/**\n * The value of a variable's text, of the schemas `nodes`: its JSON, of a value of a type they take\n * other than a string, so `2` is a number and `[2, \"newest\"]` a list where a value may be a name,\n * a number or a list; else the text where they take a string, so a name stays a name, and JSON\n * that is no value they take is the text; else its JSON, else the text.\n */\nfunction parsedOf(text: string, nodes: readonly unknown[], root: unknown): unknown {\n let parsed: unknown\n try {\n parsed = JSON.parse(text) as unknown\n } catch {\n return text\n }\n if (typeof parsed !== 'string' && takenBy(nodes, parsed, root)) return parsed\n return takesString(nodes, root) ? text : parsed\n}\n\n/** `value` with `over` at `path`, merged over what is there ({@link mergeSection}). */\nfunction withValueAt(value: unknown, path: ConfigPath, over: unknown): unknown {\n const [key, ...rest] = path\n if (key === undefined) return mergeSection(value, over)\n const object = isNode(value) ? value : {}\n return { ...object, [key]: withValueAt(object[key], rest, over) }\n}\n\n/**\n * The JSON Schema of `schema`, as a tool checks its section by it: the schema itself, of a JSON\n * Schema; of a Standard Schema that gives one, as zod's does, the JSON Schema of its input; else\n * none, of a function, or a schema that gives none.\n */\nexport function jsonSchemaOf(schema: unknown): JsonSchema | undefined {\n if (typeof schema === 'boolean') return schema\n if (!isNode(schema)) return undefined\n if (!('~standard' in schema)) return schema\n const converter = (schema as Partial<StandardJSONSchemaV1>)['~standard']?.jsonSchema\n if (converter === undefined) return undefined\n try {\n return converter.input({ target: 'draft-2020-12' })\n } catch {\n return undefined\n }\n}\n\n/**\n * `value` with the variables `variables` of `prefix` over it: each variable that names a path of\n * a key there is, in `value` or in `schema`, a JSON Schema of it, sets the value at that path,\n * merged over what is there ({@link mergeSection}), and the variable of the prefix itself, without\n * its last `_`, the whole value, a variable of a shorter path first, so `WTF_VITE_COMPRESS_THRESHOLD`\n * is over what `WTF_VITE` sets, of the prefix `WTF_VITE_`. A variable that names no key there\n * is is passed over.\n */\nexport function withEnvironment(\n value: unknown,\n variables: Readonly<Record<string, string>>,\n prefix: string,\n schema?: JsonSchema\n): WithEnvironment {\n const nodes = schema === undefined ? [] : [schema]\n const whole = prefix.slice(0, -1)\n const found = Object.entries(variables).flatMap(([variable, text]) => {\n const at =\n variable === whole\n ? { path: [], nodes }\n : variable.startsWith(prefix)\n ? pathOf(variable.slice(prefix.length), value, nodes, schema)\n : undefined\n return at === undefined\n ? []\n : [{ variable, path: at.path, value: parsedOf(text, at.nodes, schema) }]\n })\n let result = value\n const set: EnvironmentValue[] = []\n for (const { variable, path, value: over } of found.toSorted(\n (a, b) => a.path.length - b.path.length || a.variable.localeCompare(b.variable)\n )) {\n result = withValueAt(result, path, over)\n set.push({ variable, path })\n }\n return { value: result, set }\n}\n"]}
package/dist/errors.d.ts CHANGED
@@ -157,16 +157,22 @@ export declare class SyncSchemaError extends ConfigError {
157
157
  * of its shape, or that its check refuses.
158
158
  */
159
159
  export type NamedErrorCode = 'UNKNOWN_NAME' | 'UNLOADABLE_MODULE' | 'MISSING_EXPORT' | 'INVALID_NAMED_VALUE';
160
- /** What a {@link NamedError} names, of its code: the name and those there are, the module and its
161
- * export, or the issues of a check. */
160
+ /** What a {@link NamedError} names, of its code: where it failed, the name and those there are,
161
+ * the module and its export, or the issues of a check. */
162
162
  export type NamedErrorDetails = {
163
+ /** Where the value that failed is, by its path from what the caller gave, of any code. */
164
+ readonly at?: ConfigPath;
165
+ /** The index of the set that failed in the array of sets, of any code. */
166
+ readonly set?: number;
167
+ /** The name of the entry that failed, of a set or of a reference, of any code. */
168
+ readonly entry?: string;
163
169
  /** The name of no entry, of `UNKNOWN_NAME`. */
164
170
  readonly name?: string;
165
171
  /** The names of the entries there are, of `UNKNOWN_NAME`. */
166
172
  readonly names?: readonly string[];
167
- /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
173
+ /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`, and of a value it exports. */
168
174
  readonly module?: string;
169
- /** The name of its export, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
175
+ /** The name of its export, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`, and of a value it exports. */
170
176
  readonly export?: string;
171
177
  /** What the check found wrong, of `INVALID_NAMED_VALUE`. */
172
178
  readonly issues?: readonly ConfigIssue[];
@@ -174,18 +180,30 @@ export type NamedErrorDetails = {
174
180
  /**
175
181
  * A reference of ./named that cannot be resolved, of a stable code of {@link NamedErrorCode}: a
176
182
  * name of no entry, whose message lists the names there are; a module that fails to load; an
177
- * export it has not; or a reference, a set or a value of no shape it takes. A tool maps each code
178
- * to its own, as it chooses.
183
+ * export it has not; or a reference, a set or a value of no shape it takes. Of any code, it names
184
+ * where it failed: its path, `at`, the index of its `set` and the name of its `entry`, and the
185
+ * `module` and `export` a value came from. A tool maps each code to its own, as it chooses.
179
186
  */
180
187
  export declare class NamedError extends ConfigError {
181
188
  readonly code: NamedErrorCode;
189
+ /**
190
+ * Where the value that failed is, by its path from what the caller gave: the path the caller
191
+ * gives as `at`, the index of the set in an array of sets, and the name of the entry, as
192
+ * `['formatters', '1', 'wide']`; empty when nothing narrows it.
193
+ */
194
+ readonly at: ConfigPath;
195
+ /** The index of the set that failed in the array of sets: none of one set alone, or of a reference. */
196
+ readonly set: number | undefined;
197
+ /** The name of the entry that failed, of a set or of the one a reference names: none of others. */
198
+ readonly entry: string | undefined;
182
199
  /** The name of no entry, of `UNKNOWN_NAME`. */
183
200
  readonly unknown: string | undefined;
184
201
  /** The names of the entries there are, of `UNKNOWN_NAME`; none of any other code. */
185
202
  readonly names: readonly string[];
186
- /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
203
+ /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`, and of a value it exports. */
187
204
  readonly module: string | undefined;
188
- /** The name of the export of the module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
205
+ /** The name of the export of the module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`, and of a
206
+ * value it exports. */
189
207
  readonly export: string | undefined;
190
208
  /** What the check found wrong, of `INVALID_NAMED_VALUE` of a value it refuses; none of others. */
191
209
  readonly issues: readonly ConfigIssue[];
package/dist/errors.js CHANGED
@@ -175,22 +175,37 @@ export class SyncSchemaError extends ConfigError {
175
175
  /**
176
176
  * A reference of ./named that cannot be resolved, of a stable code of {@link NamedErrorCode}: a
177
177
  * name of no entry, whose message lists the names there are; a module that fails to load; an
178
- * export it has not; or a reference, a set or a value of no shape it takes. A tool maps each code
179
- * to its own, as it chooses.
178
+ * export it has not; or a reference, a set or a value of no shape it takes. Of any code, it names
179
+ * where it failed: its path, `at`, the index of its `set` and the name of its `entry`, and the
180
+ * `module` and `export` a value came from. A tool maps each code to its own, as it chooses.
180
181
  */
181
182
  export class NamedError extends ConfigError {
183
+ /**
184
+ * Where the value that failed is, by its path from what the caller gave: the path the caller
185
+ * gives as `at`, the index of the set in an array of sets, and the name of the entry, as
186
+ * `['formatters', '1', 'wide']`; empty when nothing narrows it.
187
+ */
188
+ at;
189
+ /** The index of the set that failed in the array of sets: none of one set alone, or of a reference. */
190
+ set;
191
+ /** The name of the entry that failed, of a set or of the one a reference names: none of others. */
192
+ entry;
182
193
  /** The name of no entry, of `UNKNOWN_NAME`. */
183
194
  unknown;
184
195
  /** The names of the entries there are, of `UNKNOWN_NAME`; none of any other code. */
185
196
  names;
186
- /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
197
+ /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`, and of a value it exports. */
187
198
  module;
188
- /** The name of the export of the module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
199
+ /** The name of the export of the module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`, and of a
200
+ * value it exports. */
189
201
  export;
190
202
  /** What the check found wrong, of `INVALID_NAMED_VALUE` of a value it refuses; none of others. */
191
203
  issues;
192
204
  constructor(code, message, details = {}, options) {
193
205
  super(code, message, options);
206
+ this.at = details.at ?? [];
207
+ this.set = details.set;
208
+ this.entry = details.entry;
194
209
  this.unknown = details.name;
195
210
  this.names = details.names ?? [];
196
211
  this.module = details.module;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC;wDACwD;AACxD,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAQ;IACrB,kDAAkD;IACzC,QAAQ,GAAW,CAAC,CAAA;IAE7B,YAAY,IAAY,EAAE,OAAe,EAAE,OAAsB;QAC/D,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAA;IAC7B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IACrD,sCAAsC;IAC7B,IAAI,CAAQ;IAErB,YAAY,IAAY,EAAE,MAAc,EAAE,OAAsB;QAC9D,KAAK,CAAC,qBAAqB,EAAE,GAAG,IAAI,KAAK,MAAM,EAAE,EAAE,OAAO,CAAC,CAAA;QAC3D,IAAI,CAAC,I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AK,CACH,qBAAqB,EACrB,iCAAiC,IAAI,yDAAyD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,+BAA+B,CAChJ,CAAA;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC9C,gCAAgC;IACvB,OAAO,CAAQ;IAExB,YAAY,OAAe;QACzB,KAAK,CACH,iBAAiB,EACjB,qBAAqB,OAAO,4DAA4D,CACzF,CAAA;QACD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AA6BD;;;;;GAKG;AACH,MAAM,OAAO,UAAW,SAAQ,WAAW;IAEzC,+CAA+C;IACtC,OAAO,CAAoB;IACpC,qFAAqF;IAC5E,KAAK,CAAmB;IACjC,+DAA+D;IACtD,MAAM,CAAoB;IACnC,yFAAyF;IAChF,MAAM,CAAoB;IACnC,kGAAkG;IACzF,MAAM,CAAwB;IAEvC,YACE,IAAoB,EACpB,OAAe,EACf,UAA6B,EAAE,EAC/B,OAAsB;QAEtB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA;IACpC,CAAC;CACF","sourcesContent":["/**\n * What `@wtf/project-config` throws, each a {@link ConfigError} of a stable `code`:\n * {@link InvalidConfigFileError}, a file of the configuration that holds no object;\n * {@link InvalidSectionError}, a section its tool's schema refuses; {@link ConfigPathError}, a path\n * that names no value; {@link ConfigInCodeError}, a write to a configuration of code;\n * {@link NoConfigFileError}, a write with no package.json to hold it;\n * {@link ConfigFileMismatchError}, a write to a file that is not the one in use;\n * {@link UnwritableConfigFileError}, a write to a file that is never written;\n * {@link NoConfigValueError}, a value asked for that is not set; and\n * {@link EnvPlaceholderUnsetError}, a value that points at a variable of the environment that is\n * not set; {@link SyncConfigInCodeError}, a configuration of code loaded synchronously; and\n * {@link SyncSchemaError}, a section checked synchronously by a schema that checks asynchronously;\n * and {@link NamedError}, a reference of ./named that names no entry, or a module, an export or a\n * value that is not what it says. One that the arguments of a person cause exits 2.\n *\n * @packageDocumentation\n */\nimport type { ConfigIssue, ConfigPath } from './index.ts'\nimport { textOfPath } from './text.ts'\n\n/** What this package throws: an Error with a stable SCREAMING_SNAKE `code`, and the `exitCode` a\n * command that fails by it exits with, 1 by default. */\nexport class ConfigError extends Error {\n readonly code: string\n /** What a command that fails by it exits with. */\n readonly exitCode: number = 1\n\n constructor(code: string, message: string, options?: ErrorOptions) {\n super(message, options)\n this.code = code\n this.name = new.target.name\n }\n}\n\n/**\n * A file of the configuration that holds no configuration: no JSON, no object, or a module that\n * fails to load, or exports no object.\n */\nexport class InvalidConfigFileError extends ConfigError {\n /** The file, by its absolute path. */\n readonly file: string\n\n constructor(file: string, reason: string, options?: ErrorOptions) {\n super('INVALID_CONFIG_FILE', `${file}: ${reason}`, options)\n this.file = file\n }\n}\n\n/**\n * A section of the configuration that the schema of its tool refuses: each issue, by the file and\n * the path of the value, from the key that names the configuration, the namespace by default.\n */\nexport class InvalidSectionError extends ConfigError {\n /** The file of the configuration, by its absolute path. */\n readonly file: string\n /** The section, by its name. */\n readonly section: string\n /** What is wrong, each by its path in the section. */\n readonly issues: readonly ConfigIssue[]\n\n constructor(\n file: string,\n namespace: string,\n section: string,\n issues: readonly ConfigIssue[],\n key: string = namespace\n ) {\n super(\n 'INVALID_CONFIG_SECTION',\n [\n `${file}: the ${section} section of the ${namespace} configuration is not valid:`,\n ...issues.map(({ path, message }) => ` ${textOfPath([key, section, ...path])}: ${message}`)\n ].join('\\n')\n )\n this.file = file\n this.section = section\n this.issues = issues\n }\n}\n\n/**\n * A path of the configuration that names no value to read or write: an empty one, or one that\n * goes into a value that is no object or list. A usage failure: it exits 2.\n */\nexport class ConfigPathError extends ConfigError {\n /** The path, as it was given. */\n readonly path: string\n override readonly exitCode: number = 2\n\n constructor(path: string, reason: string) {\n super('INVALID_CONFIG_PATH', `${path === '' ? 'The path' : path} ${reason}`)\n this.path = path\n }\n}\n\n/**\n * A write to a configuration of code, as `wtf.config.mjs`, `wtf.config.js` or `wtf.config.ts`: code\n * is changed by a person, and not by a tool. Its message names what is written: the JSON files, and\n * the key of package.json.\n */\nexport class ConfigInCodeError extends ConfigError {\n /** The file of code, by its absolute path. */\n readonly file: string\n\n constructor(file: string, written: { readonly files: readonly string[]; readonly key: string }) {\n const names = [...written.files, `the \"${written.key}\" key of package.json`]\n super(\n 'CONFIG_IN_CODE',\n `The configuration is code, in ${file}: change it there. Only ${names.join(' and ')} ${names.length === 1 ? 'is' : 'are'} written.`\n )\n this.file = file\n }\n}\n\n/**\n * A write to the configuration of a project that has none, in the key of package.json, the\n * default, where the root has no package.json. Its message names the key, and the JSON file to make\n * it in instead, if there is one. A usage failure: it exits 2.\n */\nexport class NoConfigFileError extends ConfigError {\n /** The root of the project. */\n readonly root: string\n override readonly exitCode: number = 2\n\n constructor(\n root: string,\n {\n namespace,\n key = namespace,\n json\n }: { readonly namespace: string; readonly key?: string; readonly json?: string | undefined }\n ) {\n super(\n 'NO_CONFIG_FILE',\n `No package.json is in ${root} to hold the ${namespace} configuration in its \"${key}\" key: make one there${json === undefined ? '' : `, or name ${json} to make the configuration in`}.`\n )\n this.root = root\n }\n}\n\n/**\n * A write to a file of the configuration that is not the one in use, as its JSON file named where\n * package.json holds it. A usage failure: it exits 2.\n */\nexport class ConfigFileMismatchError extends ConfigError {\n /** The file that holds the configuration, by its absolute path. */\n readonly file: string\n /** The file named. */\n readonly named: string\n override readonly exitCode: number = 2\n\n constructor(file: string, named: string) {\n super(\n 'CONFIG_FILE_MISMATCH',\n `The configuration is in ${file}, and not in ${named}: write it there, or move it.`\n )\n this.file = file\n this.named = named\n }\n}\n\n/**\n * A write to a file that is no JSON file of the names of the configuration, nor package.json: one\n * of code, or one its names do not hold. Its message names those that are written. A usage\n * failure: it exits 2.\n */\nexport class UnwritableConfigFileError extends ConfigError {\n /** The file named. */\n readonly named: string\n override readonly exitCode: number = 2\n\n constructor(named: string, written: readonly string[]) {\n super(\n 'UNWRITABLE_CONFIG_FILE',\n `${named} is no file the configuration is written to: name ${[...written, 'package.json'].join(' or ')}.`\n )\n this.named = named\n }\n}\n\n/** A value of the configuration that is not set, which was asked for. */\nexport class NoConfigValueError extends ConfigError {\n /** The path, as it was given. */\n readonly path: string\n /** The file of the configuration, by its absolute path, or `undefined` when there is none. */\n readonly file: string | undefined\n\n constructor(path: string, file: string | undefined) {\n super(\n 'NO_CONFIG_VALUE',\n file === undefined\n ? `${path} is not set: the project has no configuration.`\n : `${path} is not set in ${file}.`\n )\n this.path = path\n this.file = file\n }\n}\n\n/**\n * A value of the configuration that points at a variable of the environment, by a placeholder\n * `${env:NAME}`, which is not set, or is empty. Its message names the path of the value, from the\n * key that names the configuration, and the variable, and holds no value.\n */\nexport class EnvPlaceholderUnsetError extends ConfigError {\n /** The path of the value that holds the placeholder. */\n readonly path: ConfigPath\n /** The name of the variable of the environment. */\n readonly variable: string\n\n constructor(path: ConfigPath, variable: string) {\n super(\n 'CONFIG_ENV_PLACEHOLDER_UNSET',\n `${textOfPath(path)}: points at the variable ${variable} of the environment by \\${env:${variable}}, which is not set, or is empty.`\n )\n this.path = path\n this.variable = variable\n }\n}\n\n/**\n * A configuration of code, as `wtf.config.ts`, loaded synchronously, as `loadConfigSync` of ./load\n * loads it for a tool that reads its config synchronously: code is imported, which is\n * asynchronous. Its message names the files a synchronous load reads, JSON and package.json's key.\n */\nexport class SyncConfigInCodeError extends ConfigError {\n /** The file of code, by its absolute path. */\n readonly file: string\n\n constructor(file: string, read: { readonly files: readonly string[]; readonly key: string }) {\n const names = [...read.files, `the \"${read.key}\" key of package.json`]\n super(\n 'CONFIG_IN_CODE_SYNC',\n `The configuration is code, in ${file}, which a synchronous load cannot import: write it in ${names.join(' or ')}, or load it with loadConfig.`\n )\n this.file = file\n }\n}\n\n/**\n * A section checked synchronously, as `sectionOfSync` of ./section checks it, by a schema that\n * checks asynchronously: a Standard Schema whose `validate` gives a promise, or a function that\n * does.\n */\nexport class SyncSchemaError extends ConfigError {\n /** The section, by its name. */\n readonly section: string\n\n constructor(section: string) {\n super(\n 'SCHEMA_NOT_SYNC',\n `The schema of the ${section} section checks it asynchronously: read it with sectionOf.`\n )\n this.section = section\n }\n}\n\n/**\n * The codes of a {@link NamedError}: `UNKNOWN_NAME`, a reference of a name of no entry;\n * `UNLOADABLE_MODULE`, a module that fails to load, or of no loader given; `MISSING_EXPORT`, an\n * export the module has not; and `INVALID_NAMED_VALUE`, a reference, a set or a value that is not\n * of its shape, or that its check refuses.\n */\nexport type NamedErrorCode =\n | 'UNKNOWN_NAME'\n | 'UNLOADABLE_MODULE'\n | 'MISSING_EXPORT'\n | 'INVALID_NAMED_VALUE'\n\n/** What a {@link NamedError} names, of its code: the name and those there are, the module and its\n * export, or the issues of a check. */\nexport type NamedErrorDetails = {\n /** The name of no entry, of `UNKNOWN_NAME`. */\n readonly name?: string\n /** The names of the entries there are, of `UNKNOWN_NAME`. */\n readonly names?: readonly string[]\n /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */\n readonly module?: string\n /** The name of its export, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */\n readonly export?: string\n /** What the check found wrong, of `INVALID_NAMED_VALUE`. */\n readonly issues?: readonly ConfigIssue[]\n}\n\n/**\n * A reference of ./named that cannot be resolved, of a stable code of {@link NamedErrorCode}: a\n * name of no entry, whose message lists the names there are; a module that fails to load; an\n * export it has not; or a reference, a set or a value of no shape it takes. A tool maps each code\n * to its own, as it chooses.\n */\nexport class NamedError extends ConfigError {\n declare readonly code: NamedErrorCode\n /** The name of no entry, of `UNKNOWN_NAME`. */\n readonly unknown: string | undefined\n /** The names of the entries there are, of `UNKNOWN_NAME`; none of any other code. */\n readonly names: readonly string[]\n /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */\n readonly module: string | undefined\n /** The name of the export of the module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */\n readonly export: string | undefined\n /** What the check found wrong, of `INVALID_NAMED_VALUE` of a value it refuses; none of others. */\n readonly issues: readonly ConfigIssue[]\n\n constructor(\n code: NamedErrorCode,\n message: string,\n details: NamedErrorDetails = {},\n options?: ErrorOptions\n ) {\n super(code, message, options)\n this.unknown = details.name\n this.names = details.names ?? []\n this.module = details.module\n this.export = details.export\n this.issues = details.issues ?? []\n }\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC;wDACwD;AACxD,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAQ;IACrB,kDAAkD;IACzC,QAAQ,GAAW,CAAC,CAAA;IAE7B,YAAY,IAAY,EAAE,OAAe,EAAE,OAAsB;QAC/D,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAA;IAC7B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IACrD,sCAAsC;IAC7B,IAAI,CAAQ;IAErB,YAAY,IAAY,EAAE,MAAc,EAAE,OAAsB;QAC9D,KAAK,CAAC,qBAAqB,EAAE,GAAG,IAAI,KAAK,MAAM,EAAE,EAAE,OAAO,CAAC,CAAA;QAC3D,IAAI,CAAC,IAAI,GAAG,IAAI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A;QAC5B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA;IACpC,CAAC;CACF","sourcesContent":["/**\n * What `@wtf/project-config` throws, each a {@link ConfigError} of a stable `code`:\n * {@link InvalidConfigFileError}, a file of the configuration that holds no object;\n * {@link InvalidSectionError}, a section its tool's schema refuses; {@link ConfigPathError}, a path\n * that names no value; {@link ConfigInCodeError}, a write to a configuration of code;\n * {@link NoConfigFileError}, a write with no package.json to hold it;\n * {@link ConfigFileMismatchError}, a write to a file that is not the one in use;\n * {@link UnwritableConfigFileError}, a write to a file that is never written;\n * {@link NoConfigValueError}, a value asked for that is not set; and\n * {@link EnvPlaceholderUnsetError}, a value that points at a variable of the environment that is\n * not set; {@link SyncConfigInCodeError}, a configuration of code loaded synchronously; and\n * {@link SyncSchemaError}, a section checked synchronously by a schema that checks asynchronously;\n * and {@link NamedError}, a reference of ./named that names no entry, or a module, an export or a\n * value that is not what it says. One that the arguments of a person cause exits 2.\n *\n * @packageDocumentation\n */\nimport type { ConfigIssue, ConfigPath } from './index.ts'\nimport { textOfPath } from './text.ts'\n\n/** What this package throws: an Error with a stable SCREAMING_SNAKE `code`, and the `exitCode` a\n * command that fails by it exits with, 1 by default. */\nexport class ConfigError extends Error {\n readonly code: string\n /** What a command that fails by it exits with. */\n readonly exitCode: number = 1\n\n constructor(code: string, message: string, options?: ErrorOptions) {\n super(message, options)\n this.code = code\n this.name = new.target.name\n }\n}\n\n/**\n * A file of the configuration that holds no configuration: no JSON, no object, or a module that\n * fails to load, or exports no object.\n */\nexport class InvalidConfigFileError extends ConfigError {\n /** The file, by its absolute path. */\n readonly file: string\n\n constructor(file: string, reason: string, options?: ErrorOptions) {\n super('INVALID_CONFIG_FILE', `${file}: ${reason}`, options)\n this.file = file\n }\n}\n\n/**\n * A section of the configuration that the schema of its tool refuses: each issue, by the file and\n * the path of the value, from the key that names the configuration, the namespace by default.\n */\nexport class InvalidSectionError extends ConfigError {\n /** The file of the configuration, by its absolute path. */\n readonly file: string\n /** The section, by its name. */\n readonly section: string\n /** What is wrong, each by its path in the section. */\n readonly issues: readonly ConfigIssue[]\n\n constructor(\n file: string,\n namespace: string,\n section: string,\n issues: readonly ConfigIssue[],\n key: string = namespace\n ) {\n super(\n 'INVALID_CONFIG_SECTION',\n [\n `${file}: the ${section} section of the ${namespace} configuration is not valid:`,\n ...issues.map(({ path, message }) => ` ${textOfPath([key, section, ...path])}: ${message}`)\n ].join('\\n')\n )\n this.file = file\n this.section = section\n this.issues = issues\n }\n}\n\n/**\n * A path of the configuration that names no value to read or write: an empty one, or one that\n * goes into a value that is no object or list. A usage failure: it exits 2.\n */\nexport class ConfigPathError extends ConfigError {\n /** The path, as it was given. */\n readonly path: string\n override readonly exitCode: number = 2\n\n constructor(path: string, reason: string) {\n super('INVALID_CONFIG_PATH', `${path === '' ? 'The path' : path} ${reason}`)\n this.path = path\n }\n}\n\n/**\n * A write to a configuration of code, as `wtf.config.mjs`, `wtf.config.js` or `wtf.config.ts`: code\n * is changed by a person, and not by a tool. Its message names what is written: the JSON files, and\n * the key of package.json.\n */\nexport class ConfigInCodeError extends ConfigError {\n /** The file of code, by its absolute path. */\n readonly file: string\n\n constructor(file: string, written: { readonly files: readonly string[]; readonly key: string }) {\n const names = [...written.files, `the \"${written.key}\" key of package.json`]\n super(\n 'CONFIG_IN_CODE',\n `The configuration is code, in ${file}: change it there. Only ${names.join(' and ')} ${names.length === 1 ? 'is' : 'are'} written.`\n )\n this.file = file\n }\n}\n\n/**\n * A write to the configuration of a project that has none, in the key of package.json, the\n * default, where the root has no package.json. Its message names the key, and the JSON file to make\n * it in instead, if there is one. A usage failure: it exits 2.\n */\nexport class NoConfigFileError extends ConfigError {\n /** The root of the project. */\n readonly root: string\n override readonly exitCode: number = 2\n\n constructor(\n root: string,\n {\n namespace,\n key = namespace,\n json\n }: { readonly namespace: string; readonly key?: string; readonly json?: string | undefined }\n ) {\n super(\n 'NO_CONFIG_FILE',\n `No package.json is in ${root} to hold the ${namespace} configuration in its \"${key}\" key: make one there${json === undefined ? '' : `, or name ${json} to make the configuration in`}.`\n )\n this.root = root\n }\n}\n\n/**\n * A write to a file of the configuration that is not the one in use, as its JSON file named where\n * package.json holds it. A usage failure: it exits 2.\n */\nexport class ConfigFileMismatchError extends ConfigError {\n /** The file that holds the configuration, by its absolute path. */\n readonly file: string\n /** The file named. */\n readonly named: string\n override readonly exitCode: number = 2\n\n constructor(file: string, named: string) {\n super(\n 'CONFIG_FILE_MISMATCH',\n `The configuration is in ${file}, and not in ${named}: write it there, or move it.`\n )\n this.file = file\n this.named = named\n }\n}\n\n/**\n * A write to a file that is no JSON file of the names of the configuration, nor package.json: one\n * of code, or one its names do not hold. Its message names those that are written. A usage\n * failure: it exits 2.\n */\nexport class UnwritableConfigFileError extends ConfigError {\n /** The file named. */\n readonly named: string\n override readonly exitCode: number = 2\n\n constructor(named: string, written: readonly string[]) {\n super(\n 'UNWRITABLE_CONFIG_FILE',\n `${named} is no file the configuration is written to: name ${[...written, 'package.json'].join(' or ')}.`\n )\n this.named = named\n }\n}\n\n/** A value of the configuration that is not set, which was asked for. */\nexport class NoConfigValueError extends ConfigError {\n /** The path, as it was given. */\n readonly path: string\n /** The file of the configuration, by its absolute path, or `undefined` when there is none. */\n readonly file: string | undefined\n\n constructor(path: string, file: string | undefined) {\n super(\n 'NO_CONFIG_VALUE',\n file === undefined\n ? `${path} is not set: the project has no configuration.`\n : `${path} is not set in ${file}.`\n )\n this.path = path\n this.file = file\n }\n}\n\n/**\n * A value of the configuration that points at a variable of the environment, by a placeholder\n * `${env:NAME}`, which is not set, or is empty. Its message names the path of the value, from the\n * key that names the configuration, and the variable, and holds no value.\n */\nexport class EnvPlaceholderUnsetError extends ConfigError {\n /** The path of the value that holds the placeholder. */\n readonly path: ConfigPath\n /** The name of the variable of the environment. */\n readonly variable: string\n\n constructor(path: ConfigPath, variable: string) {\n super(\n 'CONFIG_ENV_PLACEHOLDER_UNSET',\n `${textOfPath(path)}: points at the variable ${variable} of the environment by \\${env:${variable}}, which is not set, or is empty.`\n )\n this.path = path\n this.variable = variable\n }\n}\n\n/**\n * A configuration of code, as `wtf.config.ts`, loaded synchronously, as `loadConfigSync` of ./load\n * loads it for a tool that reads its config synchronously: code is imported, which is\n * asynchronous. Its message names the files a synchronous load reads, JSON and package.json's key.\n */\nexport class SyncConfigInCodeError extends ConfigError {\n /** The file of code, by its absolute path. */\n readonly file: string\n\n constructor(file: string, read: { readonly files: readonly string[]; readonly key: string }) {\n const names = [...read.files, `the \"${read.key}\" key of package.json`]\n super(\n 'CONFIG_IN_CODE_SYNC',\n `The configuration is code, in ${file}, which a synchronous load cannot import: write it in ${names.join(' or ')}, or load it with loadConfig.`\n )\n this.file = file\n }\n}\n\n/**\n * A section checked synchronously, as `sectionOfSync` of ./section checks it, by a schema that\n * checks asynchronously: a Standard Schema whose `validate` gives a promise, or a function that\n * does.\n */\nexport class SyncSchemaError extends ConfigError {\n /** The section, by its name. */\n readonly section: string\n\n constructor(section: string) {\n super(\n 'SCHEMA_NOT_SYNC',\n `The schema of the ${section} section checks it asynchronously: read it with sectionOf.`\n )\n this.section = section\n }\n}\n\n/**\n * The codes of a {@link NamedError}: `UNKNOWN_NAME`, a reference of a name of no entry;\n * `UNLOADABLE_MODULE`, a module that fails to load, or of no loader given; `MISSING_EXPORT`, an\n * export the module has not; and `INVALID_NAMED_VALUE`, a reference, a set or a value that is not\n * of its shape, or that its check refuses.\n */\nexport type NamedErrorCode =\n | 'UNKNOWN_NAME'\n | 'UNLOADABLE_MODULE'\n | 'MISSING_EXPORT'\n | 'INVALID_NAMED_VALUE'\n\n/** What a {@link NamedError} names, of its code: where it failed, the name and those there are,\n * the module and its export, or the issues of a check. */\nexport type NamedErrorDetails = {\n /** Where the value that failed is, by its path from what the caller gave, of any code. */\n readonly at?: ConfigPath\n /** The index of the set that failed in the array of sets, of any code. */\n readonly set?: number\n /** The name of the entry that failed, of a set or of a reference, of any code. */\n readonly entry?: string\n /** The name of no entry, of `UNKNOWN_NAME`. */\n readonly name?: string\n /** The names of the entries there are, of `UNKNOWN_NAME`. */\n readonly names?: readonly string[]\n /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`, and of a value it exports. */\n readonly module?: string\n /** The name of its export, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`, and of a value it exports. */\n readonly export?: string\n /** What the check found wrong, of `INVALID_NAMED_VALUE`. */\n readonly issues?: readonly ConfigIssue[]\n}\n\n/**\n * A reference of ./named that cannot be resolved, of a stable code of {@link NamedErrorCode}: a\n * name of no entry, whose message lists the names there are; a module that fails to load; an\n * export it has not; or a reference, a set or a value of no shape it takes. Of any code, it names\n * where it failed: its path, `at`, the index of its `set` and the name of its `entry`, and the\n * `module` and `export` a value came from. A tool maps each code to its own, as it chooses.\n */\nexport class NamedError extends ConfigError {\n declare readonly code: NamedErrorCode\n /**\n * Where the value that failed is, by its path from what the caller gave: the path the caller\n * gives as `at`, the index of the set in an array of sets, and the name of the entry, as\n * `['formatters', '1', 'wide']`; empty when nothing narrows it.\n */\n readonly at: ConfigPath\n /** The index of the set that failed in the array of sets: none of one set alone, or of a reference. */\n readonly set: number | undefined\n /** The name of the entry that failed, of a set or of the one a reference names: none of others. */\n readonly entry: string | undefined\n /** The name of no entry, of `UNKNOWN_NAME`. */\n readonly unknown: string | undefined\n /** The names of the entries there are, of `UNKNOWN_NAME`; none of any other code. */\n readonly names: readonly string[]\n /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`, and of a value it exports. */\n readonly module: string | undefined\n /** The name of the export of the module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`, and of a\n * value it exports. */\n readonly export: string | undefined\n /** What the check found wrong, of `INVALID_NAMED_VALUE` of a value it refuses; none of others. */\n readonly issues: readonly ConfigIssue[]\n\n constructor(\n code: NamedErrorCode,\n message: string,\n details: NamedErrorDetails = {},\n options?: ErrorOptions\n ) {\n super(code, message, options)\n this.at = details.at ?? []\n this.set = details.set\n this.entry = details.entry\n this.unknown = details.name\n this.names = details.names ?? []\n this.module = details.module\n this.export = details.export\n this.issues = details.issues ?? []\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -174,8 +174,8 @@ export type ImportModule = (path: string) => Promise<unknown>;
174
174
  /**
175
175
  * What the configuration is read and written by, asynchronously: the platform's storage, whose
176
176
  * `getDirectory()` is the root of its file system, its paths, and its working folder, as
177
- * `@wtf/platform-fs/files` reads a platform's files. A `Platform` of `@wtf/platform` is one, and
178
- * `nodeConfigPlatform()` of ./node gives Node's.
177
+ * `@wtf/platform-fs/files` reads a platform's files. A `Platform` of `@wtf/platform` is one, as
178
+ * `nodePlatform()` of `@wtf/platform-node/platform` makes Node's.
179
179
  */
180
180
  export type ConfigPlatform = FilesPlatform;
181
181
  /** What reads a project's files synchronously, by their absolute paths. */
@@ -187,8 +187,8 @@ export type SyncFiles = {
187
187
  };
188
188
  /**
189
189
  * What the configuration is read by synchronously: the platform's paths, and its files, read
190
- * synchronously, as no handle of the File System Standard is. `nodeSyncPlatform()` of ./node gives
191
- * Node's.
190
+ * synchronously, as no handle of the File System Standard is. `nodeSyncPlatform()` of ./node adds
191
+ * Node's files to a platform.
192
192
  */
193
193
  export type ConfigSyncPlatform = {
194
194
  readonly path: Pick<Path, 'resolve' | 'join' | 'dirname'>;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The types of a project's configuration under a namespace, `wtf` by default: the object\n * ({@link NamespaceConfig}), made of a section for each tool ({@link ConfigSection}), or of the\n * sections the schemas of the tools type ({@link SectionsOf}); the names it is looked for by\n * ({@link ConfigNames}); the file it is in ({@link ConfigSource}); where it is\n * ({@link LocatedConfig}); what a tool reads ({@link ResolvedConfig}); the defaults a tool's\n * package gives ({@link ConfigDefaults}); a path in it ({@link ConfigPath}); what checks a section\n * ({@link SectionSchema}) and what it finds wrong ({@link ConfigIssue}); what a write did\n * ({@link ConfigWrite}); and what it is read by ({@link ConfigPlatform}, {@link ConfigSyncPlatform}).\n * Types only, with no code.\n *\n * @packageDocumentation\n * @module index\n */\nimport type { StandardJSONSchemaV1, StandardSchemaV1, StandardTypedV1 } from '@standard-schema/spec'\nimport type { FilesPlatform } from '@wtf/platform-fs/files'\nimport type { Path } from '@wtf/platform/path'\n\n/**\n * The section of one tool, by its key `K` and its value `V`, as `ConfigSection<'vite', ViteOptions>`.\n * A section is optional: a project configures the tools it chooses.\n */\nexport type ConfigSection<K extends string, V> = { readonly [P in K]?: V }\n\n/**\n * The sections of the schemas `S`, each by its name: the input type of each schema, as\n * `SectionsOf<{ vite: typeof viteSchema }>` is `{ vite?: ViteOptions }`. A code config is typed by\n * it with `defineConfig` of ./define.\n */\nexport type SectionsOf<S extends Readonly<Record<string, StandardTypedV1>>> = {\n readonly [K in keyof S]?: StandardTypedV1.InferInput<S[K]>\n}\n\n/**\n * The configuration of a project under a namespace: the sections `S`, each checked by its type;\n * the `$schema` a JSON file names its schema by; and any other section, of a tool not named, as it\n * is. A tool reads its own section, and no other.\n *\n * ```ts\n * const config: NamespaceConfig<{ vite?: { compress?: false } }> = { vite: { compress: false } }\n * ```\n */\nexport type NamespaceConfig<S extends object = Record<never, never>> = S & {\n /** The JSON Schema of a JSON file of the configuration, as an editor reads it. */\n readonly $schema?: string\n readonly [section: string]: unknown\n}\n\n/**\n * The names the configuration of a namespace is looked for by, each a tool's to give: the files at\n * the root of the project, the key of its package.json, and the prefix of the environment's\n * variables over it. Of the namespace `wtf`, by default, `wtf.config.mjs`, `wtf.config.js`,\n * `wtf.config.ts` and `wtf.config.json`, the `wtf` key, and the variables `WTF_*`.\n */\nexport type ConfigNames = {\n /**\n * The files it can be in, in the order the first found is used, each of code (`.mjs`, `.js`,\n * `.ts`, `.cjs`, `.mts` or `.cts`) or of JSON (`.json`). The key of package.json comes last.\n */\n readonly files?: readonly string[]\n /** The key of package.json that holds it when no file does: the namespace by default. */\n readonly key?: string\n /**\n * The name the environment's variables over it start with: the key by default, so `wtf` is\n * `WTF_`, and `WTF_VITE_COMPRESS` sets `wtf.vite.compress`.\n */\n readonly env?: string\n}\n\n/** A file of the configuration found at the root of a project: one of its files, or package.json. */\nexport type ConfigSource = {\n /** Its name, as the names give it, or `package.json`. */\n readonly file: string\n /** Its absolute path. */\n readonly path: string\n}\n\n/**\n * Where a project's configuration is: the root of the project, the key of package.json, and each\n * file of it found there, in the order of its files, then package.json. The first is used; the\n * others are ignored.\n */\nexport type LocatedConfig = {\n readonly root: string\n /** The key of package.json, which a path of the configuration starts from: `wtf.vite.compress`. */\n readonly key: string\n readonly sources: readonly ConfigSource[]\n}\n\n/**\n * The configuration a tool's package gives under the project's, as its own defaults: each section\n * the project gives is merged over it, value by value, as `sectionOf` of ./section reads it.\n */\nexport type ConfigDefaults = {\n /** The object, of the sections of the namespace. */\n readonly config: NamespaceConfig\n /** The file it is in, by its absolute path, which an error of a section of it names. */\n readonly path: string\n}\n\n/**\n * The environment a tool reads the configuration with: the prefix of the variables over it, as\n * `WTF_`; each of those that is set and not empty, by its name; and the whole environment, in\n * `values`, which the placeholders `${env:NAME}` of a section are taken from. Only `sectionOf` of\n * ./section reads `values`: nothing shows or writes it.\n */\nexport type ConfigEnvironment = {\n readonly prefix: string\n readonly variables: Readonly<Record<string, string>>\n readonly values: Readonly<Record<string, string | undefined>>\n}\n\n/** A project's configuration, as a tool reads it. */\nexport type ResolvedConfig = {\n /** Its namespace. */\n readonly namespace: string\n /** The root of the project, where it was looked for. */\n readonly root: string\n /** The key of package.json it was looked for in, which a path of it starts from. */\n readonly key: string\n /** The object, `{}` when no file holds one. */\n readonly config: NamespaceConfig\n /** The file it came from, or `undefined` when no file holds one. */\n readonly source: ConfigSource | undefined\n /** The other files found, which are ignored, as only the first is used. */\n readonly ignored: readonly ConfigSource[]\n /** The configuration of the tool's package under the project's, when the tool gives one. */\n readonly defaults?: ConfigDefaults | undefined\n /**\n * The environment the tool gave, which a section is read with: its variables over the project's\n * configuration, and the values its placeholders are taken from. None when no environment was\n * given: then a placeholder names a variable that is not set.\n */\n readonly environment?: ConfigEnvironment | undefined\n}\n\n/** A path in the configuration, by its keys from the top: `['vite', 'compress']`. A key of digits\n * is an index of a list. */\nexport type ConfigPath = readonly string[]\n\n/** What is wrong with a value of a section: where it is, by its path in the section, and why. */\nexport type ConfigIssue = {\n readonly path: ConfigPath\n readonly message: string\n}\n\n/** A JSON Schema, as the object of its keywords, or `true` or `false`. */\nexport type JsonSchema = { readonly [keyword: string]: unknown } | boolean\n\n/** A function that checks a section: what is wrong with it, none when it is valid. */\nexport type ValidateSection = (\n value: unknown\n) => readonly ConfigIssue[] | Promise<readonly ConfigIssue[]>\n\n/**\n * What a tool checks its section by: a Standard Schema, as a preset's `./schema` exports one, or\n * zod's, whose output is what the section reads as; a JSON Schema of draft 2020-12, or a Standard\n * JSON Schema, which ajv checks; or a function of its own.\n */\nexport type SectionSchema<T = unknown> =\n | StandardSchemaV1<unknown, T>\n | StandardJSONSchemaV1<unknown, T>\n | JsonSchema\n | ValidateSection\n\n/**\n * What a write did: where, at which path, the value there before and after it, and whether it\n * changed the file, or made it.\n */\nexport type ConfigWrite = {\n readonly root: string\n /** The key of package.json, which a path of the configuration starts from. */\n readonly key: string\n /** The file written, or `undefined` when nothing was there to unset. */\n readonly source: ConfigSource | undefined\n /** The other files of the configuration found, which a reader ignores. */\n readonly ignored: readonly ConfigSource[]\n readonly path: ConfigPath\n /** The value at the path before the write, `undefined` when there was none. */\n readonly previous: unknown\n /** The value at the path after the write, `undefined` when it was unset. */\n readonly value: unknown\n /** Whether the file was written: false when the value was already so. */\n readonly changed: boolean\n /** Whether the file, or the key of package.json, was made by the write. */\n readonly created: boolean\n}\n\n/** What imports a file of code, as `wtf.config.ts`, by its absolute path: its module, whose\n * `default` is the configuration. */\nexport type ImportModule = (path: string) => Promise<unknown>\n\n/**\n * What the configuration is read and written by, asynchronously: the platform's storage, whose\n * `getDirectory()` is the root of its file system, its paths, and its working folder, as\n * `@wtf/platform-fs/files` reads a platform's files. A `Platform` of `@wtf/platform` is one, and\n * `nodeConfigPlatform()` of ./node gives Node's.\n */\nexport type ConfigPlatform = FilesPlatform\n\n/** What reads a project's files synchronously, by their absolute paths. */\nexport type SyncFiles = {\n /** The text of the file at `path`, or `undefined` when no file is there. */\n readonly text: (path: string) => string | undefined\n /** The names of the files in `folder`, none when it is no folder. */\n readonly files: (folder: string) => ReadonlySet<string>\n}\n\n/**\n * What the configuration is read by synchronously: the platform's paths, and its files, read\n * synchronously, as no handle of the File System Standard is. `nodeSyncPlatform()` of ./node gives\n * Node's.\n */\nexport type ConfigSyncPlatform = {\n readonly path: Pick<Path, 'resolve' | 'join' | 'dirname'>\n readonly files: SyncFiles\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The types of a project's configuration under a namespace, `wtf` by default: the object\n * ({@link NamespaceConfig}), made of a section for each tool ({@link ConfigSection}), or of the\n * sections the schemas of the tools type ({@link SectionsOf}); the names it is looked for by\n * ({@link ConfigNames}); the file it is in ({@link ConfigSource}); where it is\n * ({@link LocatedConfig}); what a tool reads ({@link ResolvedConfig}); the defaults a tool's\n * package gives ({@link ConfigDefaults}); a path in it ({@link ConfigPath}); what checks a section\n * ({@link SectionSchema}) and what it finds wrong ({@link ConfigIssue}); what a write did\n * ({@link ConfigWrite}); and what it is read by ({@link ConfigPlatform}, {@link ConfigSyncPlatform}).\n * Types only, with no code.\n *\n * @packageDocumentation\n * @module index\n */\nimport type { StandardJSONSchemaV1, StandardSchemaV1, StandardTypedV1 } from '@standard-schema/spec'\nimport type { FilesPlatform } from '@wtf/platform-fs/files'\nimport type { Path } from '@wtf/platform/path'\n\n/**\n * The section of one tool, by its key `K` and its value `V`, as `ConfigSection<'vite', ViteOptions>`.\n * A section is optional: a project configures the tools it chooses.\n */\nexport type ConfigSection<K extends string, V> = { readonly [P in K]?: V }\n\n/**\n * The sections of the schemas `S`, each by its name: the input type of each schema, as\n * `SectionsOf<{ vite: typeof viteSchema }>` is `{ vite?: ViteOptions }`. A code config is typed by\n * it with `defineConfig` of ./define.\n */\nexport type SectionsOf<S extends Readonly<Record<string, StandardTypedV1>>> = {\n readonly [K in keyof S]?: StandardTypedV1.InferInput<S[K]>\n}\n\n/**\n * The configuration of a project under a namespace: the sections `S`, each checked by its type;\n * the `$schema` a JSON file names its schema by; and any other section, of a tool not named, as it\n * is. A tool reads its own section, and no other.\n *\n * ```ts\n * const config: NamespaceConfig<{ vite?: { compress?: false } }> = { vite: { compress: false } }\n * ```\n */\nexport type NamespaceConfig<S extends object = Record<never, never>> = S & {\n /** The JSON Schema of a JSON file of the configuration, as an editor reads it. */\n readonly $schema?: string\n readonly [section: string]: unknown\n}\n\n/**\n * The names the configuration of a namespace is looked for by, each a tool's to give: the files at\n * the root of the project, the key of its package.json, and the prefix of the environment's\n * variables over it. Of the namespace `wtf`, by default, `wtf.config.mjs`, `wtf.config.js`,\n * `wtf.config.ts` and `wtf.config.json`, the `wtf` key, and the variables `WTF_*`.\n */\nexport type ConfigNames = {\n /**\n * The files it can be in, in the order the first found is used, each of code (`.mjs`, `.js`,\n * `.ts`, `.cjs`, `.mts` or `.cts`) or of JSON (`.json`). The key of package.json comes last.\n */\n readonly files?: readonly string[]\n /** The key of package.json that holds it when no file does: the namespace by default. */\n readonly key?: string\n /**\n * The name the environment's variables over it start with: the key by default, so `wtf` is\n * `WTF_`, and `WTF_VITE_COMPRESS` sets `wtf.vite.compress`.\n */\n readonly env?: string\n}\n\n/** A file of the configuration found at the root of a project: one of its files, or package.json. */\nexport type ConfigSource = {\n /** Its name, as the names give it, or `package.json`. */\n readonly file: string\n /** Its absolute path. */\n readonly path: string\n}\n\n/**\n * Where a project's configuration is: the root of the project, the key of package.json, and each\n * file of it found there, in the order of its files, then package.json. The first is used; the\n * others are ignored.\n */\nexport type LocatedConfig = {\n readonly root: string\n /** The key of package.json, which a path of the configuration starts from: `wtf.vite.compress`. */\n readonly key: string\n readonly sources: readonly ConfigSource[]\n}\n\n/**\n * The configuration a tool's package gives under the project's, as its own defaults: each section\n * the project gives is merged over it, value by value, as `sectionOf` of ./section reads it.\n */\nexport type ConfigDefaults = {\n /** The object, of the sections of the namespace. */\n readonly config: NamespaceConfig\n /** The file it is in, by its absolute path, which an error of a section of it names. */\n readonly path: string\n}\n\n/**\n * The environment a tool reads the configuration with: the prefix of the variables over it, as\n * `WTF_`; each of those that is set and not empty, by its name; and the whole environment, in\n * `values`, which the placeholders `${env:NAME}` of a section are taken from. Only `sectionOf` of\n * ./section reads `values`: nothing shows or writes it.\n */\nexport type ConfigEnvironment = {\n readonly prefix: string\n readonly variables: Readonly<Record<string, string>>\n readonly values: Readonly<Record<string, string | undefined>>\n}\n\n/** A project's configuration, as a tool reads it. */\nexport type ResolvedConfig = {\n /** Its namespace. */\n readonly namespace: string\n /** The root of the project, where it was looked for. */\n readonly root: string\n /** The key of package.json it was looked for in, which a path of it starts from. */\n readonly key: string\n /** The object, `{}` when no file holds one. */\n readonly config: NamespaceConfig\n /** The file it came from, or `undefined` when no file holds one. */\n readonly source: ConfigSource | undefined\n /** The other files found, which are ignored, as only the first is used. */\n readonly ignored: readonly ConfigSource[]\n /** The configuration of the tool's package under the project's, when the tool gives one. */\n readonly defaults?: ConfigDefaults | undefined\n /**\n * The environment the tool gave, which a section is read with: its variables over the project's\n * configuration, and the values its placeholders are taken from. None when no environment was\n * given: then a placeholder names a variable that is not set.\n */\n readonly environment?: ConfigEnvironment | undefined\n}\n\n/** A path in the configuration, by its keys from the top: `['vite', 'compress']`. A key of digits\n * is an index of a list. */\nexport type ConfigPath = readonly string[]\n\n/** What is wrong with a value of a section: where it is, by its path in the section, and why. */\nexport type ConfigIssue = {\n readonly path: ConfigPath\n readonly message: string\n}\n\n/** A JSON Schema, as the object of its keywords, or `true` or `false`. */\nexport type JsonSchema = { readonly [keyword: string]: unknown } | boolean\n\n/** A function that checks a section: what is wrong with it, none when it is valid. */\nexport type ValidateSection = (\n value: unknown\n) => readonly ConfigIssue[] | Promise<readonly ConfigIssue[]>\n\n/**\n * What a tool checks its section by: a Standard Schema, as a preset's `./schema` exports one, or\n * zod's, whose output is what the section reads as; a JSON Schema of draft 2020-12, or a Standard\n * JSON Schema, which ajv checks; or a function of its own.\n */\nexport type SectionSchema<T = unknown> =\n | StandardSchemaV1<unknown, T>\n | StandardJSONSchemaV1<unknown, T>\n | JsonSchema\n | ValidateSection\n\n/**\n * What a write did: where, at which path, the value there before and after it, and whether it\n * changed the file, or made it.\n */\nexport type ConfigWrite = {\n readonly root: string\n /** The key of package.json, which a path of the configuration starts from. */\n readonly key: string\n /** The file written, or `undefined` when nothing was there to unset. */\n readonly source: ConfigSource | undefined\n /** The other files of the configuration found, which a reader ignores. */\n readonly ignored: readonly ConfigSource[]\n readonly path: ConfigPath\n /** The value at the path before the write, `undefined` when there was none. */\n readonly previous: unknown\n /** The value at the path after the write, `undefined` when it was unset. */\n readonly value: unknown\n /** Whether the file was written: false when the value was already so. */\n readonly changed: boolean\n /** Whether the file, or the key of package.json, was made by the write. */\n readonly created: boolean\n}\n\n/** What imports a file of code, as `wtf.config.ts`, by its absolute path: its module, whose\n * `default` is the configuration. */\nexport type ImportModule = (path: string) => Promise<unknown>\n\n/**\n * What the configuration is read and written by, asynchronously: the platform's storage, whose\n * `getDirectory()` is the root of its file system, its paths, and its working folder, as\n * `@wtf/platform-fs/files` reads a platform's files. A `Platform` of `@wtf/platform` is one, as\n * `nodePlatform()` of `@wtf/platform-node/platform` makes Node's.\n */\nexport type ConfigPlatform = FilesPlatform\n\n/** What reads a project's files synchronously, by their absolute paths. */\nexport type SyncFiles = {\n /** The text of the file at `path`, or `undefined` when no file is there. */\n readonly text: (path: string) => string | undefined\n /** The names of the files in `folder`, none when it is no folder. */\n readonly files: (folder: string) => ReadonlySet<string>\n}\n\n/**\n * What the configuration is read by synchronously: the platform's paths, and its files, read\n * synchronously, as no handle of the File System Standard is. `nodeSyncPlatform()` of ./node adds\n * Node's files to a platform.\n */\nexport type ConfigSyncPlatform = {\n readonly path: Pick<Path, 'resolve' | 'join' | 'dirname'>\n readonly files: SyncFiles\n}\n"]}