@wtf/project-config 1.0.0 → 1.1.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,20 +6,21 @@ 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()` |
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
- | `./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
+ | `./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` |
23
24
 
24
25
  ```ts
25
26
  // vite.config.ts
@@ -65,7 +66,54 @@ not set throws an `EnvPlaceholderUnsetError`, which never shows a value.
65
66
  `./schema` exports, or zod's), a JSON Schema or a Standard JSON Schema (checked by ajv), or a
66
67
  function. What is wrong is an `InvalidSectionError` that names the file, or the variable, and the
67
68
  path of each value. `namespaceSchema('wtf', { vite: viteSchema, … })` gives the JSON Schema of the
68
- whole file, for `$schema` in `wtf.config.json`.
69
+ whole file, for `$schema` in `wtf.config.json`. A key that starts with `//` is a comment: the
70
+ JSON Schema of the whole takes one beside the sections, and each preset's schema in its section,
71
+ which it leaves out of the options it gives.
72
+
73
+ ## Values and functions by name
74
+
75
+ JSON cannot hold a function, nor share a value a package gives. `./named` lets a config name one
76
+ instead. Your tool keeps a set of entries by name, a project adds its own, and an option names one
77
+ of them in one of three forms:
78
+
79
+ - `"short"`: the entry of that name.
80
+ - `{ "format": "short", "width": 60 }`: the entry, with options. Your tool chooses the key.
81
+ - `{ "module": "./formatters.mjs", "export": "wide" }`: the export of a module, `default` by
82
+ default.
83
+
84
+ An entry is a factory, `(options) => value`. A plain value is one too: the options are merged
85
+ over it. Sets merge in order, a later one over an earlier one by name, and a set can be a map, the
86
+ export of a module that is one, or an array of those:
87
+
88
+ ```ts
89
+ import { nodeLoadModule } from '@wtf/project-config/node'
90
+ import {
91
+ type NamedReference,
92
+ type NamedSet,
93
+ resolveNamed,
94
+ resolveNamedSet
95
+ } from '@wtf/project-config/named'
96
+
97
+ type Format = { readonly width: number; readonly ellipsis: string }
98
+ declare const configured: { formatters?: NamedSet<Format>[]; format: NamedReference }
99
+
100
+ const builtin = { short: { width: 40, ellipsis: '…' } }
101
+ const formatters = await resolveNamedSet<Format>([builtin, ...(configured.formatters ?? [])], {
102
+ load: nodeLoadModule(process.cwd(), import.meta.url)
103
+ })
104
+ const format = await resolveNamed<Format>(configured.format, {
105
+ key: 'format',
106
+ names: formatters,
107
+ kind: 'formatter'
108
+ })
109
+ ```
110
+
111
+ A name of no entry throws a `NamedError` of `UNKNOWN_NAME`, which lists the names there are; a
112
+ 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.
115
+ `namedSchema('format', { names, options })` and `namedSetSchema({ entry })` give the schema of a
116
+ reference and of the sets, so an editor completes the names.
69
117
 
70
118
  ## Any platform
71
119
 
package/dist/errors.d.ts CHANGED
@@ -9,8 +9,9 @@
9
9
  * {@link NoConfigValueError}, a value asked for that is not set; and
10
10
  * {@link EnvPlaceholderUnsetError}, a value that points at a variable of the environment that is
11
11
  * not set; {@link SyncConfigInCodeError}, a configuration of code loaded synchronously; and
12
- * {@link SyncSchemaError}, a section checked synchronously by a schema that checks asynchronously.
13
- * One that the arguments of a person cause exits 2.
12
+ * {@link SyncSchemaError}, a section checked synchronously by a schema that checks asynchronously;
13
+ * and {@link NamedError}, a reference of ./named that names no entry, or a module, an export or a
14
+ * value that is not what it says. One that the arguments of a person cause exits 2.
14
15
  *
15
16
  * @packageDocumentation
16
17
  */
@@ -149,3 +150,44 @@ export declare class SyncSchemaError extends ConfigError {
149
150
  readonly section: string;
150
151
  constructor(section: string);
151
152
  }
153
+ /**
154
+ * The codes of a {@link NamedError}: `UNKNOWN_NAME`, a reference of a name of no entry;
155
+ * `UNLOADABLE_MODULE`, a module that fails to load, or of no loader given; `MISSING_EXPORT`, an
156
+ * export the module has not; and `INVALID_NAMED_VALUE`, a reference, a set or a value that is not
157
+ * of its shape, or that its check refuses.
158
+ */
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. */
162
+ export type NamedErrorDetails = {
163
+ /** The name of no entry, of `UNKNOWN_NAME`. */
164
+ readonly name?: string;
165
+ /** The names of the entries there are, of `UNKNOWN_NAME`. */
166
+ readonly names?: readonly string[];
167
+ /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
168
+ readonly module?: string;
169
+ /** The name of its export, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
170
+ readonly export?: string;
171
+ /** What the check found wrong, of `INVALID_NAMED_VALUE`. */
172
+ readonly issues?: readonly ConfigIssue[];
173
+ };
174
+ /**
175
+ * A reference of ./named that cannot be resolved, of a stable code of {@link NamedErrorCode}: a
176
+ * 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.
179
+ */
180
+ export declare class NamedError extends ConfigError {
181
+ readonly code: NamedErrorCode;
182
+ /** The name of no entry, of `UNKNOWN_NAME`. */
183
+ readonly unknown: string | undefined;
184
+ /** The names of the entries there are, of `UNKNOWN_NAME`; none of any other code. */
185
+ readonly names: readonly string[];
186
+ /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
187
+ readonly module: string | undefined;
188
+ /** The name of the export of the module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
189
+ readonly export: string | undefined;
190
+ /** What the check found wrong, of `INVALID_NAMED_VALUE` of a value it refuses; none of others. */
191
+ readonly issues: readonly ConfigIssue[];
192
+ constructor(code: NamedErrorCode, message: string, details?: NamedErrorDetails, options?: ErrorOptions);
193
+ }
package/dist/errors.js CHANGED
@@ -172,4 +172,30 @@ export class SyncSchemaError extends ConfigError {
172
172
  this.section = section;
173
173
  }
174
174
  }
175
+ /**
176
+ * A reference of ./named that cannot be resolved, of a stable code of {@link NamedErrorCode}: a
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.
180
+ */
181
+ export class NamedError extends ConfigError {
182
+ /** The name of no entry, of `UNKNOWN_NAME`. */
183
+ unknown;
184
+ /** The names of the entries there are, of `UNKNOWN_NAME`; none of any other code. */
185
+ names;
186
+ /** The module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
187
+ module;
188
+ /** The name of the export of the module, of `UNLOADABLE_MODULE` and `MISSING_EXPORT`. */
189
+ export;
190
+ /** What the check found wrong, of `INVALID_NAMED_VALUE` of a value it refuses; none of others. */
191
+ issues;
192
+ constructor(code, message, details = {}, options) {
193
+ super(code, message, options);
194
+ this.unknown = details.name;
195
+ this.names = details.names ?? [];
196
+ this.module = details.module;
197
+ this.export = details.export;
198
+ this.issues = details.issues ?? [];
199
+ }
200
+ }
175
201
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAiBA,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,CAAA;IAClB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,2DAA2D;IAClD,IAAI,CAAQ;IACrB,gCAAgC;IACvB,OAAO,CAAQ;IACxB,sDAAsD;IAC7C,MAAM,CAAwB;IAEvC,YACE,IAAY,EACZ,SAAiB,EACjB,OAAe,EACf,MAA8B,EAC9B,MAAc,SAAS;QAEvB,KAAK,CACH,wBAAwB,EACxB;YACE,GAAG,IAAI,SAAS,OAAO,mBAAmB,SAAS,8BAA8B;YACjF,GAAG,MAAM,CAAC,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B,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 * 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"]}
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,M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,QAAQ,IAAI,CAAC,GAAG,uBAAuB,CAAC,CAAA;QACtE,KAAK,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"]}
@@ -0,0 +1,170 @@
1
+ /**
2
+ * A value or a function a configuration of JSON names, where JSON cannot hold it, and the code
3
+ * that finds it: a set of named entries, as a tool gives some and a project adds its own, and a
4
+ * reference to one of them, or to the export of a module. {@link resolveNamed} gives the value a
5
+ * reference is; {@link resolveNamedSet} the entries of one set or of sets merged in order;
6
+ * {@link factoryOf} the entry of a plain value, the options of a reference merged over it; and
7
+ * {@link namedSchema} and {@link namedSetSchema} the schema of a reference and of a set, a
8
+ * Standard Schema that checks it and gives its JSON Schema, so an editor completes the names.
9
+ *
10
+ * A reference is one of three forms:
11
+ *
12
+ * - `"short"`: the entry of that name;
13
+ * - `{ "format": "short", "width": 60 }`: the entry of that name, by a key the caller chooses,
14
+ * with the options beside it, which the entry is given;
15
+ * - `{ "module": "./formatters.mjs", "export": "wide" }`: the export of a module, `default` by
16
+ * default, as it is.
17
+ *
18
+ * Each entry is a factory of the value, `(options) => value`: a function, which takes the options
19
+ * as it chooses, or a plain value, whose options are merged over it ({@link factoryOf}). A set is
20
+ * a map of entries by name, the export of a module that is one, or an array of those, a later set
21
+ * over an earlier one by name. A module is loaded by what the caller gives, `nodeLoadModule` of
22
+ * ./node of Node's, so this module runs on any platform. What fails is a `NamedError` of ./errors.
23
+ *
24
+ * ```ts
25
+ * import { factoryOf, resolveNamed, resolveNamedSet } from '@wtf/project-config/named'
26
+ *
27
+ * type Format = { readonly width: number; readonly ellipsis: string }
28
+ *
29
+ * const formatters = await resolveNamedSet<Format>([
30
+ * { short: factoryOf({ width: 40, ellipsis: '…' }) },
31
+ * { wide: { width: 120, ellipsis: '' } }
32
+ * ])
33
+ * const format = await resolveNamed<Format>(
34
+ * { format: 'short', width: 60 },
35
+ * { key: 'format', names: formatters, kind: 'formatter' }
36
+ * )
37
+ * // { width: 60, ellipsis: '…' }
38
+ * ```
39
+ *
40
+ * @packageDocumentation
41
+ */
42
+ import type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';
43
+ import type { SectionSchema } from './index.ts';
44
+ /**
45
+ * The export of a module, as a configuration of JSON names it: the module, by what the loader
46
+ * resolves, as a path from the root of the project or the name of a package, and the name of its
47
+ * export, `default` by default.
48
+ */
49
+ export type ModuleReference = {
50
+ /** The module, as the loader resolves it: `./formatters.mjs`, or a package. */
51
+ readonly module: string;
52
+ /** The name of its export: `default` by default. */
53
+ readonly export?: string | undefined;
54
+ };
55
+ /**
56
+ * A reference to an entry by its name under the key `K`, with the options beside it, which the
57
+ * entry is given: `{ "format": "short", "width": 60 }` of the key `format`. Of a key not known, as
58
+ * `string`, any object of options.
59
+ */
60
+ export type NamedUse<K extends string = string> = string extends K ? NamedOptions : {
61
+ readonly [P in K]: string;
62
+ } & NamedOptions;
63
+ /**
64
+ * A reference, as a configuration of JSON gives it: the name of an entry; the name under the key
65
+ * `K`, with options; or the export of a module.
66
+ */
67
+ export type NamedReference<K extends string = string> = string | NamedUse<K> | ModuleReference;
68
+ /** The options a reference gives an entry: each beside its name, but the key and any `undefined`. */
69
+ export type NamedOptions = Readonly<Record<string, unknown>>;
70
+ /** An entry of a set: what makes the value of the options a reference gives, none of a name alone. */
71
+ export type NamedFactory<T> = (options: NamedOptions) => T | Promise<T>;
72
+ /** The entries of a set, each a factory, by their names, as {@link resolveNamedSet} gives them. */
73
+ export type NamedEntries<T> = Readonly<Record<string, NamedFactory<T>>>;
74
+ /**
75
+ * A set of entries, as a configuration gives it: a map of each by its name, a factory, a plain
76
+ * value or the export of a module that is one of those; or the export of a module that is such a
77
+ * map.
78
+ */
79
+ export type NamedSet<T> = ModuleReference | Readonly<Record<string, NamedFactory<T> | ModuleReference | T>>;
80
+ /** The sets of a configuration: one, or an array of them, merged in order, each over those before. */
81
+ export type NamedSets<T> = NamedSet<T> | readonly NamedSet<T>[];
82
+ /**
83
+ * What loads a module of a {@link ModuleReference}: the module of the text it names, as an object
84
+ * of its exports, or a failure, which a `NamedError` of `UNLOADABLE_MODULE` holds as its cause.
85
+ */
86
+ export type LoadModule = (module: string) => Promise<unknown>;
87
+ /** How a set is resolved: the loader of its modules, the check of its values, and their kind. */
88
+ export type NamedSetOptions<T> = {
89
+ /** What loads each module a set names: none by default, of which a module is unloadable. */
90
+ readonly load?: LoadModule | undefined;
91
+ /**
92
+ * What checks each value an entry is, of a map or of a module, but a function: a Standard
93
+ * Schema, a JSON Schema or a function, as `issuesOf` of ./section takes it.
94
+ */
95
+ readonly check?: SectionSchema<T> | undefined;
96
+ /** What the entries are, which an error names: `entry` by default, as `formatter`. */
97
+ readonly kind?: string | undefined;
98
+ };
99
+ /** How a reference is resolved: the key of its names, its entries, and those of a set. */
100
+ export type NamedResolveOptions<T> = NamedSetOptions<T> & {
101
+ /** The key a reference of options names its entry by, as `format`: none takes a name alone. */
102
+ readonly key?: string | undefined;
103
+ /** The entries a reference names, by their names: none by default. */
104
+ readonly names?: NamedEntries<T> | undefined;
105
+ };
106
+ /** The schema of a reference or a set: a Standard Schema that checks it, and gives its JSON Schema. */
107
+ export type NamedSchema<T> = StandardSchemaV1<unknown, T> & StandardJSONSchemaV1<unknown, T>;
108
+ /**
109
+ * The entry of `value`: of a plain object, `value` with the options a reference gives beside the
110
+ * name merged over it, key by key, and those of `undefined` left out, so
111
+ * `{ format: 'short', width: 60 }` gives `{ width: 60, ellipsis: '…' }` of
112
+ * `{ width: 40, ellipsis: '…' }`; of any other value, the value, which takes no options, so options
113
+ * given are a `NamedError` of `INVALID_NAMED_VALUE`. {@link resolveNamedSet} makes each value of a
114
+ * set that is no function an entry so.
115
+ */
116
+ export declare function factoryOf<T>(value: T): NamedFactory<T>;
117
+ /**
118
+ * The entries of `sets`, each a factory, by their names: of each set in order, a map of entries by
119
+ * name or the export of a module that is one, a later set over an earlier one by name, so a
120
+ * project's own are over those of a package; none of `undefined`. Each entry is a function, a
121
+ * factory as it is, or a plain value, checked by `check`, of {@link factoryOf}; or the export of
122
+ * a module that is one of those, loaded by `load`. Each module is loaded at once, so a set that
123
+ * fails does before any entry is used. Fails with a `NamedError` of `UNLOADABLE_MODULE` or
124
+ * `MISSING_EXPORT` of a module, and of `INVALID_NAMED_VALUE` of a set that is no map, or a value
125
+ * `check` refuses.
126
+ */
127
+ export declare function resolveNamedSet<T>(sets: NamedSets<T> | undefined, options?: NamedSetOptions<T>): Promise<NamedEntries<T>>;
128
+ /**
129
+ * The value `reference` is: of a name, the entry of that name of `names`, given no options; of an
130
+ * object of the `key`, the entry of the name under it, given the options beside it but those of
131
+ * `undefined`; of the export of a module, `{ module, export }`, the export as it is, loaded by
132
+ * `load`. With a `check`, the value is checked by it. Fails with a `NamedError`: `UNKNOWN_NAME` of
133
+ * a name of no entry, whose message lists the names there are; `UNLOADABLE_MODULE` and
134
+ * `MISSING_EXPORT` of a module; and `INVALID_NAMED_VALUE` of a reference of none of the forms, or
135
+ * a value `check` refuses.
136
+ */
137
+ export declare function resolveNamed<T>(reference: NamedReference, { key, names, load, check, kind }?: NamedResolveOptions<T>): Promise<T>;
138
+ /** What the schema of a reference says of it. */
139
+ export type NamedSchemaOptions = {
140
+ /** The names an editor completes: those of the entries there are. */
141
+ readonly names?: readonly string[] | undefined;
142
+ /**
143
+ * The schema of the options beside a name, as each entry takes them: a JSON Schema, or a
144
+ * Standard Schema that gives one, of an object, whose `properties` are each an option. Any by
145
+ * default.
146
+ */
147
+ readonly options?: SectionSchema | undefined;
148
+ /** What the entries are, which the descriptions name: `entry` by default. */
149
+ readonly kind?: string | undefined;
150
+ };
151
+ /**
152
+ * The schema of a reference of the key `key`: a name, of `names`, which an editor completes;
153
+ * `{ [key]: name, … }`, with the options of `options` beside it, each optional, as they are over
154
+ * the entry's own; or `{ module, export }`. Its JSON Schema, which `input()` of its
155
+ * `~standard.jsonSchema` gives, holds no `$schema`, so it goes in a tool's own as it is.
156
+ */
157
+ export declare function namedSchema<K extends string>(key: K, { names, options, kind }?: NamedSchemaOptions): NamedSchema<NamedReference<K>>;
158
+ /** What the schema of a set says of it. */
159
+ export type NamedSetSchemaOptions = {
160
+ /** The schema of the value of an entry: a JSON Schema, or a Standard Schema that gives one. Any by default. */
161
+ readonly entry?: SectionSchema | undefined;
162
+ /** What the entries are, which the descriptions name: `entry` by default. */
163
+ readonly kind?: string | undefined;
164
+ };
165
+ /**
166
+ * The schema of the sets of entries: a set, or an array of sets, merged in order; each set the
167
+ * export of a module, or a map of each entry by its name, of `entry`, or the export of a module.
168
+ * Its JSON Schema holds no `$schema`, as {@link namedSchema}'s.
169
+ */
170
+ export declare function namedSetSchema({ entry, kind }?: NamedSetSchemaOptions): NamedSchema<NamedSets<unknown>>;
package/dist/named.js ADDED
@@ -0,0 +1,247 @@
1
+ import { jsonSchemaOf } from "./env.js";
2
+ import { NamedError } from "./errors.js";
3
+ import { issuesOf, issuesOfSync } from "./section.js";
4
+ /** Whether `value` is an object of keys, as JSON's: no list, and no instance of a class. */
5
+ const isPlain = (value) => {
6
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
7
+ return false;
8
+ const prototype = Object.getPrototypeOf(value);
9
+ return prototype === Object.prototype || prototype === null;
10
+ };
11
+ /** Whether `value` is the export of a module: an object whose `module` is a text. */
12
+ const isModule = (value) => isPlain(value) && typeof value['module'] === 'string';
13
+ /** `word` after its article, `a` or `an`, as `an entry`. */
14
+ const article = (word) => `${/^[aeiou]/i.test(word) ? 'an' : 'a'} ${word}`;
15
+ /** `text` of a capital first. */
16
+ const capital = (text) => `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
17
+ /** `value` as an error names it. */
18
+ const textOf = (value) => typeof value === 'function' ? 'a function' : (JSON.stringify(value) ?? String(value));
19
+ /** The options of `options` that are given: each but those of `undefined`. */
20
+ const givenOf = (options) => Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined));
21
+ /**
22
+ * The entry of `value`: of a plain object, `value` with the options a reference gives beside the
23
+ * name merged over it, key by key, and those of `undefined` left out, so
24
+ * `{ format: 'short', width: 60 }` gives `{ width: 60, ellipsis: '…' }` of
25
+ * `{ width: 40, ellipsis: '…' }`; of any other value, the value, which takes no options, so options
26
+ * given are a `NamedError` of `INVALID_NAMED_VALUE`. {@link resolveNamedSet} makes each value of a
27
+ * set that is no function an entry so.
28
+ */
29
+ export function factoryOf(value) {
30
+ return (options) => {
31
+ const given = givenOf(options);
32
+ if (isPlain(value))
33
+ return { ...value, ...given };
34
+ if (Object.keys(given).length === 0)
35
+ return value;
36
+ throw new NamedError('INVALID_NAMED_VALUE', `${textOf(value)} takes no options, and is given ${Object.keys(given).join(', ')}.`);
37
+ };
38
+ }
39
+ /** The text of the issues a check found. */
40
+ const issuesText = (issues) => issues
41
+ .map(({ path, message }) => (path.length === 0 ? message : `${path.join('.')}: ${message}`))
42
+ .join('; ');
43
+ /** `value`, checked by `check`, else a `NamedError` of `INVALID_NAMED_VALUE` of what `what` is. */
44
+ async function checked(value, check, what) {
45
+ if (check === undefined)
46
+ return value;
47
+ const { issues, value: read } = await issuesOf(value, check);
48
+ if (issues.length === 0)
49
+ return read;
50
+ throw new NamedError('INVALID_NAMED_VALUE', `${what} is not valid: ${issuesText(issues)}.`, {
51
+ issues
52
+ });
53
+ }
54
+ /**
55
+ * The export `reference.export`, `default` by default, of the module `reference.module`, loaded by
56
+ * `load`: a `NamedError` of `UNLOADABLE_MODULE` of a module that fails to load, or of no loader,
57
+ * and of `MISSING_EXPORT` of an export it has not.
58
+ */
59
+ async function exportOf(reference, load) {
60
+ const { module } = reference;
61
+ const name = reference.export ?? 'default';
62
+ const details = { module, export: name };
63
+ if (load === undefined)
64
+ throw new NamedError('UNLOADABLE_MODULE', `The module ${module} cannot be loaded, for its export ${name}: no loader of modules is given.`, details);
65
+ let loaded;
66
+ try {
67
+ loaded = await load(module);
68
+ }
69
+ catch (error) {
70
+ throw new NamedError('UNLOADABLE_MODULE', `The module ${module} cannot be loaded, for its export ${name}: ${error instanceof Error ? error.message : String(error)}`, details, { cause: error });
71
+ }
72
+ const exports = loaded;
73
+ const found = typeof exports === 'object' && exports !== null ? exports[name] : undefined;
74
+ if (found === undefined)
75
+ throw new NamedError('MISSING_EXPORT', `The module ${module} has no export ${name}.`, details);
76
+ return found;
77
+ }
78
+ /** What a module's export is, as an error names it. */
79
+ const exportText = ({ module, export: name = 'default' }) => `The export ${name} of ${module}`;
80
+ /** The entry of `value` of the name `name`: a function as it is, else checked, of {@link factoryOf}. */
81
+ async function entryOf(value, name, { load, check, kind = 'entry' }) {
82
+ const at = isModule(value) ? await exportOf(value, load) : value;
83
+ if (typeof at === 'function')
84
+ return at;
85
+ const what = isModule(value)
86
+ ? `${exportText(value)}, the ${kind} ${name},`
87
+ : `The ${kind} ${name}`;
88
+ return factoryOf(await checked(at, check, what));
89
+ }
90
+ /**
91
+ * The entries of `sets`, each a factory, by their names: of each set in order, a map of entries by
92
+ * name or the export of a module that is one, a later set over an earlier one by name, so a
93
+ * project's own are over those of a package; none of `undefined`. Each entry is a function, a
94
+ * factory as it is, or a plain value, checked by `check`, of {@link factoryOf}; or the export of
95
+ * a module that is one of those, loaded by `load`. Each module is loaded at once, so a set that
96
+ * fails does before any entry is used. Fails with a `NamedError` of `UNLOADABLE_MODULE` or
97
+ * `MISSING_EXPORT` of a module, and of `INVALID_NAMED_VALUE` of a set that is no map, or a value
98
+ * `check` refuses.
99
+ */
100
+ export async function resolveNamedSet(sets, options = {}) {
101
+ const list = sets === undefined ? [] : Array.isArray(sets) ? sets : [sets];
102
+ const resolved = await Promise.all(list.map(async (set) => {
103
+ const map = isModule(set) ? await exportOf(set, options.load) : set;
104
+ if (!isPlain(map))
105
+ throw new NamedError('INVALID_NAMED_VALUE', `${isModule(set) ? exportText(set) : textOf(set)} is no set: give an object of each ${options.kind ?? 'entry'} by its name.`);
106
+ const entries = await Promise.all(Object.entries(map).map(async ([name, value]) => [
107
+ name,
108
+ await entryOf(value, name, options)
109
+ ]));
110
+ return Object.fromEntries(entries);
111
+ }));
112
+ return Object.assign({}, ...resolved);
113
+ }
114
+ /**
115
+ * The value `reference` is: of a name, the entry of that name of `names`, given no options; of an
116
+ * object of the `key`, the entry of the name under it, given the options beside it but those of
117
+ * `undefined`; of the export of a module, `{ module, export }`, the export as it is, loaded by
118
+ * `load`. With a `check`, the value is checked by it. Fails with a `NamedError`: `UNKNOWN_NAME` of
119
+ * a name of no entry, whose message lists the names there are; `UNLOADABLE_MODULE` and
120
+ * `MISSING_EXPORT` of a module; and `INVALID_NAMED_VALUE` of a reference of none of the forms, or
121
+ * a value `check` refuses.
122
+ */
123
+ export async function resolveNamed(reference, { key, names = {}, load, check, kind = 'entry' } = {}) {
124
+ const use = reference;
125
+ if (isModule(use) && (key === undefined || !(key in use)))
126
+ return checked(await exportOf(use, load), check, exportText(use));
127
+ const named = typeof use === 'string'
128
+ ? { name: use, options: {} }
129
+ : isPlain(use) && key !== undefined && typeof use[key] === 'string'
130
+ ? (() => {
131
+ const { [key]: name, ...options } = use;
132
+ return { name: name, options: givenOf(options) };
133
+ })()
134
+ : undefined;
135
+ if (named === undefined)
136
+ throw new NamedError('INVALID_NAMED_VALUE', `${textOf(use)} is no reference of ${article(kind)}: give its name${key === undefined ? '' : `, { "${key}": name, … }`} or { "module": …, "export": … }.`);
137
+ const { name, options } = named;
138
+ if (!Object.hasOwn(names, name)) {
139
+ const known = Object.keys(names);
140
+ throw new NamedError('UNKNOWN_NAME', `No ${kind} is named ${JSON.stringify(name)}: the names are ${known.length === 0 ? 'none' : known.join(', ')}.`, { name, names: known });
141
+ }
142
+ const entry = names[name];
143
+ return checked(await entry(options), check, `The ${kind} ${name}`);
144
+ }
145
+ /** The JSON Schema of the export of a module. */
146
+ const MODULE_SCHEMA = {
147
+ description: 'The export of a module: `default` by default.',
148
+ type: 'object',
149
+ properties: {
150
+ module: {
151
+ description: 'The module: a path from the root, or a package.',
152
+ type: 'string',
153
+ minLength: 1
154
+ },
155
+ export: {
156
+ description: 'The name of its export: `default` by default.',
157
+ type: 'string',
158
+ minLength: 1
159
+ }
160
+ },
161
+ required: ['module'],
162
+ additionalProperties: false
163
+ };
164
+ /** The JSON Schema of a name: a text, of the `names` an editor completes. */
165
+ const nameSchema = (kind, names) => ({
166
+ description: `The name of ${article(kind)}.`,
167
+ type: 'string',
168
+ minLength: 1,
169
+ ...(names === undefined || names.length === 0 ? {} : { examples: [...names] })
170
+ });
171
+ /** The JSON Schema of `schema`, as an object of its keywords: `{}`, any value, of none. */
172
+ const objectSchemaOf = (schema) => {
173
+ const json = schema === undefined ? undefined : jsonSchemaOf(schema);
174
+ if (json === undefined || json === true)
175
+ return {};
176
+ if (json === false)
177
+ return { not: {} };
178
+ const { $schema: _draft, $id: _id, ...rest } = json;
179
+ return rest;
180
+ };
181
+ /**
182
+ * The schema of `json`, of the type `T`: it checks a value by ajv, as `issuesOfSync` of ./section
183
+ * checks a JSON Schema, and gives `json`, of draft 2020-12, as the JSON Schema of its input and
184
+ * output alike.
185
+ */
186
+ function schemaOf(json) {
187
+ const jsonSchema = () => ({ ...json });
188
+ return {
189
+ '~standard': {
190
+ version: 1,
191
+ vendor: '@wtf/project-config',
192
+ validate: (value) => {
193
+ const { issues } = issuesOfSync(value, json);
194
+ return issues.length === 0
195
+ ? { value: value }
196
+ : { issues: issues.map(({ path, message }) => ({ path, message })) };
197
+ },
198
+ jsonSchema: { input: jsonSchema, output: jsonSchema }
199
+ }
200
+ };
201
+ }
202
+ /**
203
+ * The schema of a reference of the key `key`: a name, of `names`, which an editor completes;
204
+ * `{ [key]: name, … }`, with the options of `options` beside it, each optional, as they are over
205
+ * the entry's own; or `{ module, export }`. Its JSON Schema, which `input()` of its
206
+ * `~standard.jsonSchema` gives, holds no `$schema`, so it goes in a tool's own as it is.
207
+ */
208
+ export function namedSchema(key, { names, options, kind = 'entry' } = {}) {
209
+ const name = nameSchema(kind, names);
210
+ const { properties, required: _required, type: _type, ...rest } = objectSchemaOf(options);
211
+ return schemaOf({
212
+ description: `${capital(article(kind))}: its name, { "${key}": name, … } with options over its own, or the export of a module.`,
213
+ anyOf: [
214
+ name,
215
+ {
216
+ ...rest,
217
+ description: `${capital(article(kind))} by its name, with options over its own.`,
218
+ type: 'object',
219
+ properties: { ...(isPlain(properties) ? properties : {}), [key]: name },
220
+ required: [key]
221
+ },
222
+ MODULE_SCHEMA
223
+ ]
224
+ });
225
+ }
226
+ /**
227
+ * The schema of the sets of entries: a set, or an array of sets, merged in order; each set the
228
+ * export of a module, or a map of each entry by its name, of `entry`, or the export of a module.
229
+ * Its JSON Schema holds no `$schema`, as {@link namedSchema}'s.
230
+ */
231
+ export function namedSetSchema({ entry, kind = 'entry' } = {}) {
232
+ const set = {
233
+ description: `A set of ${kind}s: a map of each by its name, or the export of a module that is one.`,
234
+ anyOf: [
235
+ MODULE_SCHEMA,
236
+ {
237
+ type: 'object',
238
+ additionalProperties: { anyOf: [MODULE_SCHEMA, objectSchemaOf(entry)] }
239
+ }
240
+ ]
241
+ };
242
+ return schemaOf({
243
+ description: `The sets of ${kind}s: a set, or an array of sets merged in order, each over those before.`,
244
+ anyOf: [set, { type: 'array', items: set }]
245
+ });
246
+ }
247
+ //# sourceMappingURL=named.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"named.js","sourceRoot":"","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K,EAAE,GAAG,EAAE,CAAC;KAC5C,CAAC,CAAA;AACJ,CAAC","sourcesContent":["/**\n * A value or a function a configuration of JSON names, where JSON cannot hold it, and the code\n * that finds it: a set of named entries, as a tool gives some and a project adds its own, and a\n * reference to one of them, or to the export of a module. {@link resolveNamed} gives the value a\n * reference is; {@link resolveNamedSet} the entries of one set or of sets merged in order;\n * {@link factoryOf} the entry of a plain value, the options of a reference merged over it; and\n * {@link namedSchema} and {@link namedSetSchema} the schema of a reference and of a set, a\n * Standard Schema that checks it and gives its JSON Schema, so an editor completes the names.\n *\n * A reference is one of three forms:\n *\n * - `\"short\"`: the entry of that name;\n * - `{ \"format\": \"short\", \"width\": 60 }`: the entry of that name, by a key the caller chooses,\n * with the options beside it, which the entry is given;\n * - `{ \"module\": \"./formatters.mjs\", \"export\": \"wide\" }`: the export of a module, `default` by\n * default, as it is.\n *\n * Each entry is a factory of the value, `(options) => value`: a function, which takes the options\n * as it chooses, or a plain value, whose options are merged over it ({@link factoryOf}). A set is\n * a map of entries by name, the export of a module that is one, or an array of those, a later set\n * over an earlier one by name. A module is loaded by what the caller gives, `nodeLoadModule` of\n * ./node of Node's, so this module runs on any platform. What fails is a `NamedError` of ./errors.\n *\n * ```ts\n * import { factoryOf, resolveNamed, resolveNamedSet } from '@wtf/project-config/named'\n *\n * type Format = { readonly width: number; readonly ellipsis: string }\n *\n * const formatters = await resolveNamedSet<Format>([\n * { short: factoryOf({ width: 40, ellipsis: '…' }) },\n * { wide: { width: 120, ellipsis: '' } }\n * ])\n * const format = await resolveNamed<Format>(\n * { format: 'short', width: 60 },\n * { key: 'format', names: formatters, kind: 'formatter' }\n * )\n * // { width: 60, ellipsis: '…' }\n * ```\n *\n * @packageDocumentation\n */\nimport type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { jsonSchemaOf } from './env.ts'\nimport { NamedError } from './errors.ts'\nimport type { ConfigIssue, JsonSchema, SectionSchema } from './index.ts'\nimport { issuesOf, issuesOfSync } from './section.ts'\n\n/**\n * The export of a module, as a configuration of JSON names it: the module, by what the loader\n * resolves, as a path from the root of the project or the name of a package, and the name of its\n * export, `default` by default.\n */\nexport type ModuleReference = {\n /** The module, as the loader resolves it: `./formatters.mjs`, or a package. */\n readonly module: string\n /** The name of its export: `default` by default. */\n readonly export?: string | undefined\n}\n\n/**\n * A reference to an entry by its name under the key `K`, with the options beside it, which the\n * entry is given: `{ \"format\": \"short\", \"width\": 60 }` of the key `format`. Of a key not known, as\n * `string`, any object of options.\n */\nexport type NamedUse<K extends string = string> = string extends K\n ? NamedOptions\n : { readonly [P in K]: string } & NamedOptions\n\n/**\n * A reference, as a configuration of JSON gives it: the name of an entry; the name under the key\n * `K`, with options; or the export of a module.\n */\nexport type NamedReference<K extends string = string> = string | NamedUse<K> | ModuleReference\n\n/** The options a reference gives an entry: each beside its name, but the key and any `undefined`. */\nexport type NamedOptions = Readonly<Record<string, unknown>>\n\n/** An entry of a set: what makes the value of the options a reference gives, none of a name alone. */\nexport type NamedFactory<T> = (options: NamedOptions) => T | Promise<T>\n\n/** The entries of a set, each a factory, by their names, as {@link resolveNamedSet} gives them. */\nexport type NamedEntries<T> = Readonly<Record<string, NamedFactory<T>>>\n\n/**\n * A set of entries, as a configuration gives it: a map of each by its name, a factory, a plain\n * value or the export of a module that is one of those; or the export of a module that is such a\n * map.\n */\nexport type NamedSet<T> =\n | ModuleReference\n | Readonly<Record<string, NamedFactory<T> | ModuleReference | T>>\n\n/** The sets of a configuration: one, or an array of them, merged in order, each over those before. */\nexport type NamedSets<T> = NamedSet<T> | readonly NamedSet<T>[]\n\n/**\n * What loads a module of a {@link ModuleReference}: the module of the text it names, as an object\n * of its exports, or a failure, which a `NamedError` of `UNLOADABLE_MODULE` holds as its cause.\n */\nexport type LoadModule = (module: string) => Promise<unknown>\n\n/** How a set is resolved: the loader of its modules, the check of its values, and their kind. */\nexport type NamedSetOptions<T> = {\n /** What loads each module a set names: none by default, of which a module is unloadable. */\n readonly load?: LoadModule | undefined\n /**\n * What checks each value an entry is, of a map or of a module, but a function: a Standard\n * Schema, a JSON Schema or a function, as `issuesOf` of ./section takes it.\n */\n readonly check?: SectionSchema<T> | undefined\n /** What the entries are, which an error names: `entry` by default, as `formatter`. */\n readonly kind?: string | undefined\n}\n\n/** How a reference is resolved: the key of its names, its entries, and those of a set. */\nexport type NamedResolveOptions<T> = NamedSetOptions<T> & {\n /** The key a reference of options names its entry by, as `format`: none takes a name alone. */\n readonly key?: string | undefined\n /** The entries a reference names, by their names: none by default. */\n readonly names?: NamedEntries<T> | undefined\n}\n\n/** The schema of a reference or a set: a Standard Schema that checks it, and gives its JSON Schema. */\nexport type NamedSchema<T> = StandardSchemaV1<unknown, T> & StandardJSONSchemaV1<unknown, T>\n\n/** Whether `value` is an object of keys, as JSON's: no list, and no instance of a class. */\nconst isPlain = (value: unknown): value is Readonly<Record<string, unknown>> => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false\n const prototype: unknown = Object.getPrototypeOf(value)\n return prototype === Object.prototype || prototype === null\n}\n\n/** Whether `value` is the export of a module: an object whose `module` is a text. */\nconst isModule = (value: unknown): value is ModuleReference =>\n isPlain(value) && typeof value['module'] === 'string'\n\n/** `word` after its article, `a` or `an`, as `an entry`. */\nconst article = (word: string): string => `${/^[aeiou]/i.test(word) ? 'an' : 'a'} ${word}`\n\n/** `text` of a capital first. */\nconst capital = (text: string): string => `${text.charAt(0).toUpperCase()}${text.slice(1)}`\n\n/** `value` as an error names it. */\nconst textOf = (value: unknown): string =>\n typeof value === 'function' ? 'a function' : (JSON.stringify(value) ?? String(value))\n\n/** The options of `options` that are given: each but those of `undefined`. */\nconst givenOf = (options: NamedOptions): NamedOptions =>\n Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined))\n\n/**\n * The entry of `value`: of a plain object, `value` with the options a reference gives beside the\n * name merged over it, key by key, and those of `undefined` left out, so\n * `{ format: 'short', width: 60 }` gives `{ width: 60, ellipsis: '…' }` of\n * `{ width: 40, ellipsis: '…' }`; of any other value, the value, which takes no options, so options\n * given are a `NamedError` of `INVALID_NAMED_VALUE`. {@link resolveNamedSet} makes each value of a\n * set that is no function an entry so.\n */\nexport function factoryOf<T>(value: T): NamedFactory<T> {\n return (options) => {\n const given = givenOf(options)\n if (isPlain(value)) return { ...value, ...given } as T\n if (Object.keys(given).length === 0) return value\n throw new NamedError(\n 'INVALID_NAMED_VALUE',\n `${textOf(value)} takes no options, and is given ${Object.keys(given).join(', ')}.`\n )\n }\n}\n\n/** The text of the issues a check found. */\nconst issuesText = (issues: readonly ConfigIssue[]): string =>\n issues\n .map(({ path, message }) => (path.length === 0 ? message : `${path.join('.')}: ${message}`))\n .join('; ')\n\n/** `value`, checked by `check`, else a `NamedError` of `INVALID_NAMED_VALUE` of what `what` is. */\nasync function checked<T>(value: unknown, check: SectionSchema<T> | undefined, what: string) {\n if (check === undefined) return value as T\n const { issues, value: read } = await issuesOf(value, check)\n if (issues.length === 0) return read\n throw new NamedError('INVALID_NAMED_VALUE', `${what} is not valid: ${issuesText(issues)}.`, {\n issues\n })\n}\n\n/**\n * The export `reference.export`, `default` by default, of the module `reference.module`, loaded by\n * `load`: a `NamedError` of `UNLOADABLE_MODULE` of a module that fails to load, or of no loader,\n * and of `MISSING_EXPORT` of an export it has not.\n */\nasync function exportOf(reference: ModuleReference, load: LoadModule | undefined) {\n const { module } = reference\n const name = reference.export ?? 'default'\n const details = { module, export: name }\n if (load === undefined)\n throw new NamedError(\n 'UNLOADABLE_MODULE',\n `The module ${module} cannot be loaded, for its export ${name}: no loader of modules is given.`,\n details\n )\n let loaded: unknown\n try {\n loaded = await load(module)\n } catch (error) {\n throw new NamedError(\n 'UNLOADABLE_MODULE',\n `The module ${module} cannot be loaded, for its export ${name}: ${error instanceof Error ? error.message : String(error)}`,\n details,\n { cause: error }\n )\n }\n const exports = loaded as Readonly<Record<string, unknown>> | null | undefined\n const found = typeof exports === 'object' && exports !== null ? exports[name] : undefined\n if (found === undefined)\n throw new NamedError('MISSING_EXPORT', `The module ${module} has no export ${name}.`, details)\n return found\n}\n\n/** What a module's export is, as an error names it. */\nconst exportText = ({ module, export: name = 'default' }: ModuleReference): string =>\n `The export ${name} of ${module}`\n\n/** The entry of `value` of the name `name`: a function as it is, else checked, of {@link factoryOf}. */\nasync function entryOf<T>(\n value: unknown,\n name: string,\n { load, check, kind = 'entry' }: NamedSetOptions<T>\n): Promise<NamedFactory<T>> {\n const at = isModule(value) ? await exportOf(value, load) : value\n if (typeof at === 'function') return at as NamedFactory<T>\n const what = isModule(value)\n ? `${exportText(value)}, the ${kind} ${name},`\n : `The ${kind} ${name}`\n return factoryOf(await checked(at, check, what))\n}\n\n/**\n * The entries of `sets`, each a factory, by their names: of each set in order, a map of entries by\n * name or the export of a module that is one, a later set over an earlier one by name, so a\n * project's own are over those of a package; none of `undefined`. Each entry is a function, a\n * factory as it is, or a plain value, checked by `check`, of {@link factoryOf}; or the export of\n * a module that is one of those, loaded by `load`. Each module is loaded at once, so a set that\n * fails does before any entry is used. Fails with a `NamedError` of `UNLOADABLE_MODULE` or\n * `MISSING_EXPORT` of a module, and of `INVALID_NAMED_VALUE` of a set that is no map, or a value\n * `check` refuses.\n */\nexport async function resolveNamedSet<T>(\n sets: NamedSets<T> | undefined,\n options: NamedSetOptions<T> = {}\n): Promise<NamedEntries<T>> {\n const list: readonly unknown[] = sets === undefined ? [] : Array.isArray(sets) ? sets : [sets]\n const resolved = await Promise.all(\n list.map(async (set) => {\n const map = isModule(set) ? await exportOf(set, options.load) : set\n if (!isPlain(map))\n throw new NamedError(\n 'INVALID_NAMED_VALUE',\n `${isModule(set) ? exportText(set) : textOf(set)} is no set: give an object of each ${options.kind ?? 'entry'} by its name.`\n )\n const entries = await Promise.all(\n Object.entries(map).map(async ([name, value]): Promise<[string, NamedFactory<T>]> => [\n name,\n await entryOf(value, name, options)\n ])\n )\n return Object.fromEntries(entries)\n })\n )\n return Object.assign({}, ...resolved) as NamedEntries<T>\n}\n\n/**\n * The value `reference` is: of a name, the entry of that name of `names`, given no options; of an\n * object of the `key`, the entry of the name under it, given the options beside it but those of\n * `undefined`; of the export of a module, `{ module, export }`, the export as it is, loaded by\n * `load`. With a `check`, the value is checked by it. Fails with a `NamedError`: `UNKNOWN_NAME` of\n * a name of no entry, whose message lists the names there are; `UNLOADABLE_MODULE` and\n * `MISSING_EXPORT` of a module; and `INVALID_NAMED_VALUE` of a reference of none of the forms, or\n * a value `check` refuses.\n */\nexport async function resolveNamed<T>(\n reference: NamedReference,\n { key, names = {}, load, check, kind = 'entry' }: NamedResolveOptions<T> = {}\n): Promise<T> {\n const use: unknown = reference\n if (isModule(use) && (key === undefined || !(key in use)))\n return checked(await exportOf(use, load), check, exportText(use))\n const named =\n typeof use === 'string'\n ? { name: use, options: {} }\n : isPlain(use) && key !== undefined && typeof use[key] === 'string'\n ? (() => {\n const { [key]: name, ...options } = use\n return { name: name as string, options: givenOf(options) }\n })()\n : undefined\n if (named === undefined)\n throw new NamedError(\n 'INVALID_NAMED_VALUE',\n `${textOf(use)} is no reference of ${article(kind)}: give its name${key === undefined ? '' : `, { \"${key}\": name, … }`} or { \"module\": …, \"export\": … }.`\n )\n const { name, options } = named\n if (!Object.hasOwn(names, name)) {\n const known = Object.keys(names)\n throw new NamedError(\n 'UNKNOWN_NAME',\n `No ${kind} is named ${JSON.stringify(name)}: the names are ${known.length === 0 ? 'none' : known.join(', ')}.`,\n { name, names: known }\n )\n }\n const entry = names[name] as NamedFactory<T>\n return checked(await entry(options), check, `The ${kind} ${name}`)\n}\n\n/** The JSON Schema of the export of a module. */\nconst MODULE_SCHEMA = {\n description: 'The export of a module: `default` by default.',\n type: 'object',\n properties: {\n module: {\n description: 'The module: a path from the root, or a package.',\n type: 'string',\n minLength: 1\n },\n export: {\n description: 'The name of its export: `default` by default.',\n type: 'string',\n minLength: 1\n }\n },\n required: ['module'],\n additionalProperties: false\n} as const\n\n/** The JSON Schema of a name: a text, of the `names` an editor completes. */\nconst nameSchema = (kind: string, names: readonly string[] | undefined): JsonSchema => ({\n description: `The name of ${article(kind)}.`,\n type: 'string',\n minLength: 1,\n ...(names === undefined || names.length === 0 ? {} : { examples: [...names] })\n})\n\n/** The JSON Schema of `schema`, as an object of its keywords: `{}`, any value, of none. */\nconst objectSchemaOf = (schema: SectionSchema | undefined): Readonly<Record<string, unknown>> => {\n const json = schema === undefined ? undefined : jsonSchemaOf(schema)\n if (json === undefined || json === true) return {}\n if (json === false) return { not: {} }\n const { $schema: _draft, $id: _id, ...rest } = json\n return rest\n}\n\n/**\n * The schema of `json`, of the type `T`: it checks a value by ajv, as `issuesOfSync` of ./section\n * checks a JSON Schema, and gives `json`, of draft 2020-12, as the JSON Schema of its input and\n * output alike.\n */\nfunction schemaOf<T>(json: Readonly<Record<string, unknown>>): NamedSchema<T> {\n const jsonSchema = (): Record<string, unknown> => ({ ...json })\n return {\n '~standard': {\n version: 1,\n vendor: '@wtf/project-config',\n validate: (value) => {\n const { issues } = issuesOfSync(value, json)\n return issues.length === 0\n ? { value: value as T }\n : { issues: issues.map(({ path, message }) => ({ path, message })) }\n },\n jsonSchema: { input: jsonSchema, output: jsonSchema }\n }\n }\n}\n\n/** What the schema of a reference says of it. */\nexport type NamedSchemaOptions = {\n /** The names an editor completes: those of the entries there are. */\n readonly names?: readonly string[] | undefined\n /**\n * The schema of the options beside a name, as each entry takes them: a JSON Schema, or a\n * Standard Schema that gives one, of an object, whose `properties` are each an option. Any by\n * default.\n */\n readonly options?: SectionSchema | undefined\n /** What the entries are, which the descriptions name: `entry` by default. */\n readonly kind?: string | undefined\n}\n\n/**\n * The schema of a reference of the key `key`: a name, of `names`, which an editor completes;\n * `{ [key]: name, … }`, with the options of `options` beside it, each optional, as they are over\n * the entry's own; or `{ module, export }`. Its JSON Schema, which `input()` of its\n * `~standard.jsonSchema` gives, holds no `$schema`, so it goes in a tool's own as it is.\n */\nexport function namedSchema<K extends string>(\n key: K,\n { names, options, kind = 'entry' }: NamedSchemaOptions = {}\n): NamedSchema<NamedReference<K>> {\n const name = nameSchema(kind, names)\n const { properties, required: _required, type: _type, ...rest } = objectSchemaOf(options)\n return schemaOf({\n description: `${capital(article(kind))}: its name, { \"${key}\": name, … } with options over its own, or the export of a module.`,\n anyOf: [\n name,\n {\n ...rest,\n description: `${capital(article(kind))} by its name, with options over its own.`,\n type: 'object',\n properties: { ...(isPlain(properties) ? properties : {}), [key]: name },\n required: [key]\n },\n MODULE_SCHEMA\n ]\n })\n}\n\n/** What the schema of a set says of it. */\nexport type NamedSetSchemaOptions = {\n /** The schema of the value of an entry: a JSON Schema, or a Standard Schema that gives one. Any by default. */\n readonly entry?: SectionSchema | undefined\n /** What the entries are, which the descriptions name: `entry` by default. */\n readonly kind?: string | undefined\n}\n\n/**\n * The schema of the sets of entries: a set, or an array of sets, merged in order; each set the\n * export of a module, or a map of each entry by its name, of `entry`, or the export of a module.\n * Its JSON Schema holds no `$schema`, as {@link namedSchema}'s.\n */\nexport function namedSetSchema({ entry, kind = 'entry' }: NamedSetSchemaOptions = {}): NamedSchema<\n NamedSets<unknown>\n> {\n const set = {\n description: `A set of ${kind}s: a map of each by its name, or the export of a module that is one.`,\n anyOf: [\n MODULE_SCHEMA,\n {\n type: 'object',\n additionalProperties: { anyOf: [MODULE_SCHEMA, objectSchemaOf(entry)] }\n }\n ]\n }\n return schemaOf({\n description: `The sets of ${kind}s: a set, or an array of sets merged in order, each over those before.`,\n anyOf: [set, { type: 'array', items: set }]\n })\n}\n"]}
package/dist/node.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ConfigPlatform, ConfigSyncPlatform, ResolvedConfig } from './index.ts';
2
2
  import { type LoadOptions, type LoadSyncOptions } from './load.ts';
3
+ import type { LoadModule } from './named.ts';
3
4
  /** Node's platform the configuration is read and written by: the disk from its root, its paths,
4
5
  * and the process's working folder. */
5
6
  export declare const nodeConfigPlatform: () => ConfigPlatform;
@@ -18,3 +19,17 @@ export declare const loadConfig: (folder?: string, options?: Partial<LoadOptions
18
19
  * and the process's environment, unless `options` gives others.
19
20
  */
20
21
  export declare const loadConfigSync: (folder?: string, options?: Partial<LoadSyncOptions>) => ResolvedConfig;
22
+ /**
23
+ * Node's loader of the modules a reference of ./named names, by `import()` of its file: a path, of
24
+ * `root`, the root of the project, the process's working folder by default; a package, the one
25
+ * `root` installs, else the one installed beside `beside`, as a tool gives its own
26
+ * `import.meta.url`, so a package a global install puts beside the tool is found too. What fails
27
+ * to resolve or load fails of the error of `root`'s resolve, or of the import.
28
+ *
29
+ * ```ts
30
+ * import { nodeLoadModule } from '@wtf/project-config/node'
31
+ *
32
+ * const load = nodeLoadModule(process.cwd(), import.meta.url)
33
+ * ```
34
+ */
35
+ export declare const nodeLoadModule: (root?: string, beside?: string | URL) => LoadModule;
package/dist/node.js CHANGED
@@ -1,10 +1,19 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
1
9
  /**
2
10
  * Node's platform and loads of the configuration: {@link nodeConfigPlatform}, the disk as handles
3
11
  * of the File System Standard, by `nodeStorage()` of `@wtf/platform-fs-node/storage`, and the paths
4
12
  * of `nodePath()` of `@wtf/platform-node/path`; {@link nodeSyncPlatform}, the disk read
5
- * synchronously, by `node:fs`; and {@link loadConfig} and {@link loadConfigSync}, those of ./load,
6
- * of the process's working folder, its environment and Node's platform by default. A repo loads its
7
- * config by them, and spreads a section into a preset's options:
13
+ * synchronously, by `node:fs`; {@link loadConfig} and {@link loadConfigSync}, those of ./load,
14
+ * of the process's working folder, its environment and Node's platform by default; and
15
+ * {@link nodeLoadModule}, what loads a module a reference of ./named names. A repo loads its config
16
+ * by them, and spreads a section into a preset's options:
8
17
  *
9
18
  * ```ts
10
19
  * import { loadConfig } from '@wtf/project-config/node'
@@ -19,7 +28,9 @@
19
28
  * @packageDocumentation
20
29
  */
21
30
  import { readdirSync, readFileSync, statSync } from 'node:fs';
22
- import { join } from 'node:path';
31
+ import { createRequire } from 'node:module';
32
+ import { isAbsolute, join } from 'node:path';
33
+ import { pathToFileURL } from 'node:url';
23
34
  import { nodeStorage } from '@wtf/platform-fs-node/storage';
24
35
  import { nodePath } from '@wtf/platform-node/path';
25
36
  import { loadConfig as loadWith, loadConfigSync as loadSyncWith } from "./load.js";
@@ -87,4 +98,42 @@ export const loadConfigSync = (folder = process.cwd(), options = {}) => loadSync
87
98
  ...options,
88
99
  platform: options.platform ?? nodeSyncPlatform()
89
100
  });
101
+ /**
102
+ * The file of the module `module`: of an absolute path, itself; of a path from the root, `./` or
103
+ * `../`, of `root`; of a package, the one `root` installs, as a devDependency of the project, else
104
+ * the one installed beside `beside`, as of a global install of a tool and its plugins.
105
+ */
106
+ function fileOf(module, root, beside) {
107
+ if (isAbsolute(module))
108
+ return module;
109
+ if (/^\.{1,2}\//.test(module))
110
+ return join(root, module);
111
+ try {
112
+ return createRequire(join(root, 'package.json')).resolve(module);
113
+ }
114
+ catch (error) {
115
+ if (beside === undefined)
116
+ throw error;
117
+ try {
118
+ return createRequire(beside).resolve(module);
119
+ }
120
+ catch {
121
+ throw error;
122
+ }
123
+ }
124
+ }
125
+ /**
126
+ * Node's loader of the modules a reference of ./named names, by `import()` of its file: a path, of
127
+ * `root`, the root of the project, the process's working folder by default; a package, the one
128
+ * `root` installs, else the one installed beside `beside`, as a tool gives its own
129
+ * `import.meta.url`, so a package a global install puts beside the tool is found too. What fails
130
+ * to resolve or load fails of the error of `root`'s resolve, or of the import.
131
+ *
132
+ * ```ts
133
+ * import { nodeLoadModule } from '@wtf/project-config/node'
134
+ *
135
+ * const load = nodeLoadModule(process.cwd(), import.meta.url)
136
+ * ```
137
+ */
138
+ export const nodeLoadModule = (root = process.cwd(), beside) => async (module) => import(__rewriteRelativeImportExtension(pathToFileURL(fileOf(module, root, beside)).href));
90
139
  //# sourceMappingURL=node.js.map
package/dist/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAGlD,OAAO,EACL,UAAU,IAAI,QAAQ,EACtB,cAAc,IAAI,YAAY,EAG/B,MAAM,WAAW,CAAA;AAElB;uCACuC;AACvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAmB,EAAE,CAAC,CAAC;IACvD,SAAS,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE;IACrC,IAAI,EAAE,QAAQ,EAAE;IAChB,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE;CAC7B,CAAC,CAAA;AAEF,uFAAuF;AACvF,MAAM,SAAS,GAAG,CAAC,KAAc,EAAW,EAAE,CAC5C,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAE,KAA2C,EAAE,IAAI,IAAI,EAAE,CAAC,CAAA;AAEpG;YACY;AACZ,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAuB,EAAE,CAAC,CAAC;IACzD,IAAI,EAAE,QAAQ,EAAE;IAChB,KAAK,EAAE;QACL,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;YACb,IAAI,CAAC;gBACH,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA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,QAAQ,IAAI,gBAAgB,EAAE;CACjD,CAAC,CAAA","sourcesContent":["/**\n * Node's platform and loads of the configuration: {@link nodeConfigPlatform}, the disk as handles\n * of the File System Standard, by `nodeStorage()` of `@wtf/platform-fs-node/storage`, and the paths\n * of `nodePath()` of `@wtf/platform-node/path`; {@link nodeSyncPlatform}, the disk read\n * synchronously, by `node:fs`; and {@link loadConfig} and {@link loadConfigSync}, those of ./load,\n * of the process's working folder, its environment and Node's platform by default. A repo loads its\n * config by them, and spreads a section into a preset's options:\n *\n * ```ts\n * import { loadConfig } from '@wtf/project-config/node'\n * import { sectionOf } from '@wtf/project-config/section'\n * import { rootConfig } from '@wtf/project-vitest/config'\n * import { vitestSchema } from '@wtf/project-vitest/schema'\n *\n * const config = await loadConfig()\n * export default rootConfig({ ...(await sectionOf(config, 'vitest', vitestSchema)) })\n * ```\n *\n * @packageDocumentation\n */\nimport { readdirSync, readFileSync, statSync } from 'node:fs'\nimport { join } from 'node:path'\n\nimport { nodeStorage } from '@wtf/platform-fs-node/storage'\nimport { nodePath } from '@wtf/platform-node/path'\n\nimport type { ConfigPlatform, ConfigSyncPlatform, ResolvedConfig } from './index.ts'\nimport {\n loadConfig as loadWith,\n loadConfigSync as loadSyncWith,\n type LoadOptions,\n type LoadSyncOptions\n} from './load.ts'\n\n/** Node's platform the configuration is read and written by: the disk from its root, its paths,\n * and the process's working folder. */\nexport const nodeConfigPlatform = (): ConfigPlatform => ({\n navigator: { storage: nodeStorage() },\n path: nodePath(),\n dirs: { cwd: process.cwd() }\n})\n\n/** Whether `error` is Node's of a file or a folder not there, or of the other kind. */\nconst isMissing = (error: unknown): boolean =>\n ['ENOENT', 'ENOTDIR', 'EISDIR'].includes((error as NodeJS.ErrnoException | undefined)?.code ?? '')\n\n/** Node's platform the configuration is read by synchronously: the disk by `node:fs`, and its\n * paths. */\nexport const nodeSyncPlatform = (): ConfigSyncPlatform => ({\n path: nodePath(),\n files: {\n text: (path) => {\n try {\n return readFileSync(path, 'utf8')\n } catch (error) {\n if (isMissing(error)) return undefined\n throw error\n }\n },\n files: (folder) => {\n try {\n // A link is what it links to, as a handle of the disk reads it.\n return new Set(\n readdirSync(folder).filter((name) => {\n try {\n return statSync(join(folder, name)).isFile()\n } catch {\n return false\n }\n })\n )\n } catch (error) {\n if (isMissing(error)) return new Set<string>()\n throw error\n }\n }\n }\n})\n\n/**\n * The configuration of the project in `folder`, the process's working folder by default, as\n * `loadConfig` of ./load reads it: the namespace `wtf` by default, of Node's platform and the\n * process's environment, unless `options` gives others.\n */\nexport const loadConfig = (\n folder: string = process.cwd(),\n options: Partial<LoadOptions> = {}\n): Promise<ResolvedConfig> =>\n loadWith(folder, {\n environment: process.env,\n ...options,\n platform: options.platform ?? nodeConfigPlatform()\n })\n\n/**\n * The configuration of the project in `folder`, the process's working folder by default, as\n * `loadConfigSync` of ./load reads it, of a JSON file or package.json alone: of Node's platform\n * and the process's environment, unless `options` gives others.\n */\nexport const loadConfigSync = (\n folder: string = process.cwd(),\n options: Partial<LoadSyncOptions> = {}\n): ResolvedConfig =>\n loadSyncWith(folder, {\n environment: process.env,\n ...options,\n platform: options.platform ?? nodeSyncPlatform()\n })\n"]}
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAGlD,OAAO,EACL,UAAU,IAAI,QAAQ,EACtB,cAAc,IAAI,YA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,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,CAAC,OAAe,OAAO,CAAC,GAAG,EAAE,EAAE,MAAqB,EAAc,EAAE,CACpE,KAAK,EAAE,MAAM,EAAE,EAAE,CACf,MAAM,kCAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,EAAC,CAAA","sourcesContent":["/**\n * Node's platform and loads of the configuration: {@link nodeConfigPlatform}, the disk as handles\n * of the File System Standard, by `nodeStorage()` of `@wtf/platform-fs-node/storage`, and the paths\n * of `nodePath()` of `@wtf/platform-node/path`; {@link nodeSyncPlatform}, the disk read\n * synchronously, by `node:fs`; {@link loadConfig} and {@link loadConfigSync}, those of ./load,\n * of the process's working folder, its environment and Node's platform by default; and\n * {@link nodeLoadModule}, what loads a module a reference of ./named names. A repo loads its config\n * by them, and spreads a section into a preset's options:\n *\n * ```ts\n * import { loadConfig } from '@wtf/project-config/node'\n * import { sectionOf } from '@wtf/project-config/section'\n * import { rootConfig } from '@wtf/project-vitest/config'\n * import { vitestSchema } from '@wtf/project-vitest/schema'\n *\n * const config = await loadConfig()\n * export default rootConfig({ ...(await sectionOf(config, 'vitest', vitestSchema)) })\n * ```\n *\n * @packageDocumentation\n */\nimport { readdirSync, readFileSync, statSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { isAbsolute, join } from 'node:path'\nimport { pathToFileURL } from 'node:url'\n\nimport { nodeStorage } from '@wtf/platform-fs-node/storage'\nimport { nodePath } from '@wtf/platform-node/path'\n\nimport type { ConfigPlatform, ConfigSyncPlatform, ResolvedConfig } from './index.ts'\nimport {\n loadConfig as loadWith,\n loadConfigSync as loadSyncWith,\n type LoadOptions,\n type LoadSyncOptions\n} from './load.ts'\nimport type { LoadModule } from './named.ts'\n\n/** Node's platform the configuration is read and written by: the disk from its root, its paths,\n * and the process's working folder. */\nexport const nodeConfigPlatform = (): ConfigPlatform => ({\n navigator: { storage: nodeStorage() },\n path: nodePath(),\n dirs: { cwd: process.cwd() }\n})\n\n/** Whether `error` is Node's of a file or a folder not there, or of the other kind. */\nconst isMissing = (error: unknown): boolean =>\n ['ENOENT', 'ENOTDIR', 'EISDIR'].includes((error as NodeJS.ErrnoException | undefined)?.code ?? '')\n\n/** Node's platform the configuration is read by synchronously: the disk by `node:fs`, and its\n * paths. */\nexport const nodeSyncPlatform = (): ConfigSyncPlatform => ({\n path: nodePath(),\n files: {\n text: (path) => {\n try {\n return readFileSync(path, 'utf8')\n } catch (error) {\n if (isMissing(error)) return undefined\n throw error\n }\n },\n files: (folder) => {\n try {\n // A link is what it links to, as a handle of the disk reads it.\n return new Set(\n readdirSync(folder).filter((name) => {\n try {\n return statSync(join(folder, name)).isFile()\n } catch {\n return false\n }\n })\n )\n } catch (error) {\n if (isMissing(error)) return new Set<string>()\n throw error\n }\n }\n }\n})\n\n/**\n * The configuration of the project in `folder`, the process's working folder by default, as\n * `loadConfig` of ./load reads it: the namespace `wtf` by default, of Node's platform and the\n * process's environment, unless `options` gives others.\n */\nexport const loadConfig = (\n folder: string = process.cwd(),\n options: Partial<LoadOptions> = {}\n): Promise<ResolvedConfig> =>\n loadWith(folder, {\n environment: process.env,\n ...options,\n platform: options.platform ?? nodeConfigPlatform()\n })\n\n/**\n * The configuration of the project in `folder`, the process's working folder by default, as\n * `loadConfigSync` of ./load reads it, of a JSON file or package.json alone: of Node's platform\n * and the process's environment, unless `options` gives others.\n */\nexport const loadConfigSync = (\n folder: string = process.cwd(),\n options: Partial<LoadSyncOptions> = {}\n): ResolvedConfig =>\n loadSyncWith(folder, {\n environment: process.env,\n ...options,\n platform: options.platform ?? nodeSyncPlatform()\n })\n\n/**\n * The file of the module `module`: of an absolute path, itself; of a path from the root, `./` or\n * `../`, of `root`; of a package, the one `root` installs, as a devDependency of the project, else\n * the one installed beside `beside`, as of a global install of a tool and its plugins.\n */\nfunction fileOf(module: string, root: string, beside: string | URL | undefined): string {\n if (isAbsolute(module)) return module\n if (/^\\.{1,2}\\//.test(module)) return join(root, module)\n try {\n return createRequire(join(root, 'package.json')).resolve(module)\n } catch (error) {\n if (beside === undefined) throw error\n try {\n return createRequire(beside).resolve(module)\n } catch {\n throw error\n }\n }\n}\n\n/**\n * Node's loader of the modules a reference of ./named names, by `import()` of its file: a path, of\n * `root`, the root of the project, the process's working folder by default; a package, the one\n * `root` installs, else the one installed beside `beside`, as a tool gives its own\n * `import.meta.url`, so a package a global install puts beside the tool is found too. What fails\n * to resolve or load fails of the error of `root`'s resolve, or of the import.\n *\n * ```ts\n * import { nodeLoadModule } from '@wtf/project-config/node'\n *\n * const load = nodeLoadModule(process.cwd(), import.meta.url)\n * ```\n */\nexport const nodeLoadModule =\n (root: string = process.cwd(), beside?: string | URL): LoadModule =>\n async (module) =>\n import(pathToFileURL(fileOf(module, root, beside)).href)\n"]}
package/dist/schema.d.ts CHANGED
@@ -15,8 +15,9 @@ export type NamespaceSchemaOptions = {
15
15
  * The JSON Schema of the configuration of `namespace`, of draft 2020-12, of `sections`, the schema
16
16
  * of each section by its name: a JSON Schema, or a Standard Schema that gives one, as zod's and
17
17
  * the presets' do, of its input. It is an object with each section at its property, checked by its
18
- * schema; the `$schema` key, by which a file names its schema; and any other key as it is. A
19
- * schema that gives no JSON Schema, as a function, takes any value.
18
+ * schema; the `$schema` key, by which a file names its schema; a key that starts with `//`, a
19
+ * comment, as each preset's options take one; and any other key as it is. A schema that gives no
20
+ * JSON Schema, as a function, takes any value.
20
21
  */
21
22
  export declare function namespaceSchema(namespace: string, sections: Readonly<Record<string, SectionSchema>>, { title, description }?: NamespaceSchemaOptions): {
22
23
  readonly [keyword: string]: unknown;
package/dist/schema.js CHANGED
@@ -35,8 +35,9 @@ function sectionSchema(namespace, name, schema) {
35
35
  * The JSON Schema of the configuration of `namespace`, of draft 2020-12, of `sections`, the schema
36
36
  * of each section by its name: a JSON Schema, or a Standard Schema that gives one, as zod's and
37
37
  * the presets' do, of its input. It is an object with each section at its property, checked by its
38
- * schema; the `$schema` key, by which a file names its schema; and any other key as it is. A
39
- * schema that gives no JSON Schema, as a function, takes any value.
38
+ * schema; the `$schema` key, by which a file names its schema; a key that starts with `//`, a
39
+ * comment, as each preset's options take one; and any other key as it is. A schema that gives no
40
+ * JSON Schema, as a function, takes any value.
40
41
  */
41
42
  export function namespaceSchema(namespace, sections, { title = `The ${namespace} configuration`, description = 'The configuration of the tools of a project: a section of each tool, by its name.' } = {}) {
42
43
  return {
@@ -50,7 +51,8 @@ export function namespaceSchema(namespace, sections, { title = `The ${namespace}
50
51
  name,
51
52
  sectionSchema(namespace, name, schema)
52
53
  ]))
53
- }
54
+ },
55
+ patternProperties: { '^//': { description: 'A comment, which the tools leave out.' } }
54
56
  };
55
57
  }
56
58
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAGvC,8FAA8F;AAC9F,MAAM,CAAC,MAAM,iBAAiB,GAAG,8CAA8C,CAAA;AAE/E;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAiB,EAAE,IAAY,EAAU,EAAE,CAAC,OAAO,SAAS,IAAI,IAAI,EAAE,CAAA;AAQlG;kEACkE;AAClE,SAAS,aAAa,CAAC,SAAiB,EAAE,IAAY,EAAE,MAAqB;IAC3E,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,CAAA;IACjC,IAAI,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,IAAI,IAAI,CAAA;IACxE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAA;IACzC,OAAO,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,CAAA;AAChG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,SAAiB,EACjB,QAAiD,EACjD,EACE,KAAK,GAAG,OAAO,SAAS,gBAAgB,EACxC,WAAW,GAAG,mFAAmF,KACvE,EAAE;IAE9B,OAAO;QACL,OAAO,EAAE,iBAAiB;QAC1B,KAAK;QACL,WAAW;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,OAAO,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,IAAI,EAAE,QAAQ,EAAE;YACzE,GAAG,MAAM,CAAC,WAAW,CACnB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;gBAC/C,IAAI;gBACJ,aAAa,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC;aACvC,CAAC,CACH;SACF;KACF,CAAA;AACH,CAAC","sourcesContent":["/**\n * The JSON Schema of a namespace's configuration, of the schemas of the sections of the tools a\n * project uses: {@link namespaceSchema}. Each tool's package exports the schema of its options, as\n * `viteSchema` of `@wtf/project-vite/schema`, a Standard Schema that gives its JSON Schema; the\n * schema of the whole has each at the property of its section, and takes any other section as it\n * is. An editor completes `wtf.config.json` by it.\n *\n * ```ts\n * import { namespaceSchema } from '@wtf/project-config/schema'\n * import { viteSchema } from '@wtf/project-vite/schema'\n *\n * const schema = namespaceSchema('wtf', { vite: viteSchema })\n * ```\n *\n * @packageDocumentation\n */\nimport { jsonSchemaOf } from './env.ts'\nimport type { JsonSchema, SectionSchema } from './index.ts'\n\n/** The draft of the JSON Schema {@link namespaceSchema} gives, and a section's is read as. */\nexport const JSON_SCHEMA_DRAFT = 'https://json-schema.org/draft/2020-12/schema'\n\n/**\n * The `$id` of a section's schema that has none: a `$ref` in it, as `#/$defs/x`, is then of the\n * section's own schema, and not of the whole.\n */\nexport const sectionIdOf = (namespace: string, name: string): string => `urn:${namespace}:${name}`\n\n/** What the schema of the whole says of itself. */\nexport type NamespaceSchemaOptions = {\n readonly title?: string\n readonly description?: string\n}\n\n/** A section's JSON Schema, with an `$id` of its own when it has none, and with no `$schema`; any\n * value, of a schema that gives no JSON Schema, as a function. */\nfunction sectionSchema(namespace: string, name: string, schema: SectionSchema): JsonSchema {\n const json = jsonSchemaOf(schema)\n if (json === undefined || typeof json === 'boolean') return json ?? true\n const { $schema: _draft, ...rest } = json\n return typeof rest['$id'] === 'string' ? rest : { $id: sectionIdOf(namespace, name), ...rest }\n}\n\n/**\n * The JSON Schema of the configuration of `namespace`, of draft 2020-12, of `sections`, the schema\n * of each section by its name: a JSON Schema, or a Standard Schema that gives one, as zod's and\n * the presets' do, of its input. It is an object with each section at its property, checked by its\n * schema; the `$schema` key, by which a file names its schema; and any other key as it is. A\n * schema that gives no JSON Schema, as a function, takes any value.\n */\nexport function namespaceSchema(\n namespace: string,\n sections: Readonly<Record<string, SectionSchema>>,\n {\n title = `The ${namespace} configuration`,\n description = 'The configuration of the tools of a project: a section of each tool, by its name.'\n }: NamespaceSchemaOptions = {}\n): { readonly [keyword: string]: unknown } {\n return {\n $schema: JSON_SCHEMA_DRAFT,\n title,\n description,\n type: 'object',\n properties: {\n $schema: { description: 'The JSON Schema of this file.', type: 'string' },\n ...Object.fromEntries(\n Object.entries(sections).map(([name, schema]) => [\n name,\n sectionSchema(namespace, name, schema)\n ])\n )\n }\n }\n}\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE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,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC;aACvC,CAAC,CACH;SACF;QACD,iBAAiB,EAAE,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,uCAAuC,EAAE,EAAE;KACvF,CAAA;AACH,CAAC","sourcesContent":["/**\n * The JSON Schema of a namespace's configuration, of the schemas of the sections of the tools a\n * project uses: {@link namespaceSchema}. Each tool's package exports the schema of its options, as\n * `viteSchema` of `@wtf/project-vite/schema`, a Standard Schema that gives its JSON Schema; the\n * schema of the whole has each at the property of its section, and takes any other section as it\n * is. An editor completes `wtf.config.json` by it.\n *\n * ```ts\n * import { namespaceSchema } from '@wtf/project-config/schema'\n * import { viteSchema } from '@wtf/project-vite/schema'\n *\n * const schema = namespaceSchema('wtf', { vite: viteSchema })\n * ```\n *\n * @packageDocumentation\n */\nimport { jsonSchemaOf } from './env.ts'\nimport type { JsonSchema, SectionSchema } from './index.ts'\n\n/** The draft of the JSON Schema {@link namespaceSchema} gives, and a section's is read as. */\nexport const JSON_SCHEMA_DRAFT = 'https://json-schema.org/draft/2020-12/schema'\n\n/**\n * The `$id` of a section's schema that has none: a `$ref` in it, as `#/$defs/x`, is then of the\n * section's own schema, and not of the whole.\n */\nexport const sectionIdOf = (namespace: string, name: string): string => `urn:${namespace}:${name}`\n\n/** What the schema of the whole says of itself. */\nexport type NamespaceSchemaOptions = {\n readonly title?: string\n readonly description?: string\n}\n\n/** A section's JSON Schema, with an `$id` of its own when it has none, and with no `$schema`; any\n * value, of a schema that gives no JSON Schema, as a function. */\nfunction sectionSchema(namespace: string, name: string, schema: SectionSchema): JsonSchema {\n const json = jsonSchemaOf(schema)\n if (json === undefined || typeof json === 'boolean') return json ?? true\n const { $schema: _draft, ...rest } = json\n return typeof rest['$id'] === 'string' ? rest : { $id: sectionIdOf(namespace, name), ...rest }\n}\n\n/**\n * The JSON Schema of the configuration of `namespace`, of draft 2020-12, of `sections`, the schema\n * of each section by its name: a JSON Schema, or a Standard Schema that gives one, as zod's and\n * the presets' do, of its input. It is an object with each section at its property, checked by its\n * schema; the `$schema` key, by which a file names its schema; a key that starts with `//`, a\n * comment, as each preset's options take one; and any other key as it is. A schema that gives no\n * JSON Schema, as a function, takes any value.\n */\nexport function namespaceSchema(\n namespace: string,\n sections: Readonly<Record<string, SectionSchema>>,\n {\n title = `The ${namespace} configuration`,\n description = 'The configuration of the tools of a project: a section of each tool, by its name.'\n }: NamespaceSchemaOptions = {}\n): { readonly [keyword: string]: unknown } {\n return {\n $schema: JSON_SCHEMA_DRAFT,\n title,\n description,\n type: 'object',\n properties: {\n $schema: { description: 'The JSON Schema of this file.', type: 'string' },\n ...Object.fromEntries(\n Object.entries(sections).map(([name, schema]) => [\n name,\n sectionSchema(namespace, name, schema)\n ])\n )\n },\n patternProperties: { '^//': { description: 'A comment, which the tools leave out.' } }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wtf/project-config",
3
- "version": "1.0.0",
4
- "description": "Read and write a project's configuration of its tools: one object under a namespace, wtf by default, with a section for each tool, in wtf.config.{mjs,js,ts,json} or the wtf key of package.json, the first found. Find it (./locate); load it, asynchronously with code, or synchronously of JSON and package.json alone (./load); read a tool's section, checked by its Standard Schema, a JSON Schema or a function, with WTF_<SECTION>_<KEY> variables over it (./section, ./env); replace ${env:NAME} placeholders (./placeholder); get a value by its path (./path); write a value (./write); the JSON Schema of the whole (./schema); a code config, typed (./define); Node's platform and loads (./node); and the errors (./errors).",
3
+ "version": "1.1.0",
4
+ "description": "Read and write a project's configuration of its tools: one object under a namespace, wtf by default, with a section for each tool, in wtf.config.{mjs,js,ts,json} or the wtf key of package.json, the first found. Find it (./locate); load it, asynchronously with code, or synchronously of JSON and package.json alone (./load); read a tool's section, checked by its Standard Schema, a JSON Schema or a function, with WTF_<SECTION>_<KEY> variables over it (./section, ./env); replace ${env:NAME} placeholders (./placeholder); get a value by its path (./path); write a value (./write); the JSON Schema of the whole (./schema); a code config, typed (./define); a value or a function named in JSON, by a name, a name with options or the export of a module, of sets merged in order (./named); Node's platform, loads and loader of modules (./node); and the errors (./errors).",
5
5
  "homepage": "https://gitlab.com/wetryfun/project/project/-/tree/main/packages/project-config",
6
6
  "bugs": {
7
7
  "url": "https://gitlab.com/wetryfun/project/project/-/issues"
@@ -58,6 +58,10 @@
58
58
  "types": "./dist/define.d.ts",
59
59
  "default": "./dist/define.js"
60
60
  },
61
+ "./named": {
62
+ "types": "./dist/named.d.ts",
63
+ "default": "./dist/named.js"
64
+ },
61
65
  "./node": {
62
66
  "types": "./dist/node.d.ts",
63
67
  "default": "./dist/node.js"