@wtf/project-config 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/load.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAoB,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC3E,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,UAAU,EACV,SAAS,EAET,QAAQ,EACR,MAAM,EACP,MAAM,YAAY,CAAA;AASnB,OAAO,EACL,aAAa,EACb,WAAW,EACX,YAAY,EACZ,gBAAgB,EAIjB,MAAM,aAAa,CAAA;AAkCpB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,CAAC,IAA+C,EAAgB,EAAE,CAClE,KAAK,EAAE,IAAI,EAAE,EAAE,CACb,MAAM,kCAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAC,CAAA;AAErC,oGAAoG;AACpG,KAAK,UAAU,cAAc,CAC3B,MAAoB,EACpB,YAA0B;IAE1B,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,sBAAsB,CAC9B,MAAM,CAAC,IAAI,EACX,mBAAmB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAC3E,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;IACH,CAAC;IACD,MAAM,QAAQ,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AC,MAAM,CAAC,IAAI,CAAC,KAAK,MAAM;QAChC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,CAAA;IACpF,MAAM,MAAM,GAAG,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;IAClE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,CAAA;AACrE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,SAAS,EACT,GAAG,EACH,MAAM,EACN,OAAO,EAC0D;IACjE,IAAI,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAClE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CACrC,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,GAAG,YAAY,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAClE,CAAA;IACD,OAAO,OAAO,SAAS,+BAA+B,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,gCAAgC,CAAA;AAChK,CAAC","sourcesContent":["/**\n * A project's configuration, as a tool reads it: {@link loadConfig}, the object of the first file\n * of it found at the root of the project, of code or of JSON, the file it came from, and the\n * others found, which are ignored; {@link loadConfigSync}, the same of a JSON file or package.json\n * alone, for a tool that reads its config synchronously; {@link ignoredWarning}, what to say of\n * the files ignored; and {@link importFileModule}, which imports a configuration of code, as\n * `wtf.config.ts`, by its file URL, as Node imports a module.\n *\n * ```ts\n * import { loadConfig } from '@wtf/project-config/load'\n * import { nodeConfigPlatform } from '@wtf/project-config/node'\n *\n * const resolved = await loadConfig(process.cwd(), {\n * platform: nodeConfigPlatform(),\n * environment: process.env\n * })\n * ```\n *\n * @packageDocumentation\n */\nimport { envPrefixOf, variablesOf, type Environment } from './env.ts'\nimport { InvalidConfigFileError, SyncConfigInCodeError } from './errors.ts'\nimport {\n filesOf,\n isObject,\n kindOf,\n manifestOf,\n readAsync,\n type Reads,\n readSync,\n textOf\n} from './files.ts'\nimport type {\n ConfigDefaults,\n ConfigPlatform,\n ConfigSource,\n ImportModule,\n NamespaceConfig,\n ResolvedConfig\n} from './index.ts'\nimport {\n configNamesOf,\n jsonFilesOf,\n locateConfig,\n locateConfigSync,\n type LocateNames,\n type LocateOptions,\n type LocateSyncOptions\n} from './locate.ts'\n\n/** How a configuration is read, apart from the platform: its names, the defaults of the tool's\n * package, and the environment over it. */\nexport type LoadLayers = LocateNames & {\n /**\n * The configuration under the project's, as the tool's package gives it: a section the project\n * gives none of is the one of the defaults, and one it gives is merged over it (`sectionOf` of\n * ./section).\n */\n readonly defaults?: ConfigDefaults\n /**\n * The variables of an environment, as a process's: those of the prefix of the names, as `WTF_`,\n * are kept, and a section is read with them over it, and its placeholders `${env:NAME}` taken\n * from the whole (`sectionOf` of ./section). None by default: nothing here reads the process's\n * own, which `loadConfig` of ./node gives.\n */\n readonly environment?: Environment\n}\n\n/** How a configuration is read asynchronously. */\nexport type LoadOptions = LocateOptions &\n LoadLayers & {\n /**\n * What imports a file of code: by default `import()` of its file URL, as the platform's paths\n * give it ({@link importFileModule}). A caller of a file system of its own, not the one its\n * runtime imports from, gives one too.\n */\n readonly importModule?: ImportModule\n }\n\n/** How a configuration is read synchronously. */\nexport type LoadSyncOptions = LocateSyncOptions & LoadLayers\n\n/**\n * What imports the module of the file at an absolute path, by its file URL, as the paths `path`\n * give it: what imports a configuration of code by default, `wtf.config.ts` among them, whose types\n * Node strips itself. The runtime imports it, of the file system it imports from, and not the one\n * a caller gives.\n */\nexport const importFileModule =\n (path: Pick<ConfigPlatform['path'], 'toFileUrl'>): ImportModule =>\n async (file) =>\n import(path.toFileUrl(file).href)\n\n/** The configuration of a module: its default export, an object, or a function that returns one. */\nasync function configOfModule(\n source: ConfigSource,\n importModule: ImportModule\n): Promise<NamespaceConfig> {\n let module: unknown\n try {\n module = await importModule(source.path)\n } catch (error) {\n throw new InvalidConfigFileError(\n source.path,\n `failed to load: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error }\n )\n }\n const exported: unknown = isObject(module) ? module['default'] : undefined\n const config: unknown = typeof exported === 'function' ? await exported() : exported\n if (!isObject(config))\n throw new InvalidConfigFileError(\n source.path,\n 'exports no object by default: give `export default { … }`, or a function that returns one.'\n )\n return config\n}\n\n/** The configuration of a JSON file: its own object, or the `key` of package.json. */\nfunction* configOfJson(source: ConfigSource, key: string): Reads<NamespaceConfig> {\n const text = (yield* textOf(source.path)) ?? ''\n if (kindOf(source.file) === 'package') {\n const value = manifestOf(source.path, text)[key]\n if (!isObject(value))\n throw new InvalidConfigFileError(source.path, `its \"${key}\" key is no JSON object.`)\n return value\n }\n let value: unknown\n try {\n value = JSON.parse(text)\n } catch (error) {\n throw new InvalidConfigFileError(source.path, 'is no JSON.', { cause: error })\n }\n if (!isObject(value)) throw new InvalidConfigFileError(source.path, 'is no JSON object.')\n return value\n}\n\n/** What a resolved configuration keeps beside the object: the defaults and the environment. */\nfunction layersOf({ defaults, environment, ...names }: LoadLayers) {\n const prefix = envPrefixOf(configNamesOf(names).env)\n return {\n ...(defaults === undefined ? {} : { defaults }),\n ...(environment === undefined\n ? {}\n : {\n environment: { prefix, variables: variablesOf(environment, prefix), values: environment }\n })\n }\n}\n\n/** The options of the names alone, without what reads them. */\nconst locateNamesOf = ({ defaults: _d, environment: _e, ...names }: LoadLayers): LocateNames =>\n names\n\n/**\n * The configuration of the project in `folder`: the object of the first file of it at the root of\n * the project, in the order of the files of its names — by default `wtf.config.mjs`,\n * `wtf.config.js`, `wtf.config.ts` and `wtf.config.json`, then the `wtf` key of package.json — and\n * the file it came from; `{}`, of no file, when none is there. Each other file found is in\n * `ignored`. The `defaults` a tool gives are kept beside it, for `sectionOf` of ./section to merge\n * the project's sections over, and so are the variables of the `environment` it gives of the\n * prefix of the names, `WTF_` by default, with the whole environment, which placeholders are taken\n * from. No placeholder is expanded here. A file of code is imported by `importModule`. A file that\n * holds no object, or a module that fails to load, is an {@link InvalidConfigFileError}.\n */\nexport async function loadConfig(\n folder: string,\n { importModule, platform, ...options }: LoadOptions\n): Promise<ResolvedConfig> {\n const { namespace } = configNamesOf(options)\n const { root, key, sources } = await locateConfig(folder, { platform, ...locateNamesOf(options) })\n const [source, ...ignored] = sources\n const layers = layersOf(options)\n if (source === undefined)\n return { namespace, root, key, config: {}, source: undefined, ignored: [], ...layers }\n const config =\n kindOf(source.file) === 'code'\n ? await configOfModule(source, importModule ?? importFileModule(platform.path))\n : await readAsync(configOfJson(source, key), filesOf(platform))\n return { namespace, root, key, config, source, ignored, ...layers }\n}\n\n/**\n * The configuration of the project in `folder`, as {@link loadConfig} reads it, read synchronously:\n * of a JSON file of the names, `wtf.config.json` by default, or the key of package.json, `wtf` by\n * default, for a tool that loads its own config synchronously. A configuration of code in use, as\n * `wtf.config.ts`, is a {@link SyncConfigInCodeError}, as importing it is asynchronous.\n */\nexport function loadConfigSync(\n folder: string,\n { platform, ...options }: LoadSyncOptions\n): ResolvedConfig {\n const { namespace } = configNamesOf(options)\n const { root, key, sources } = locateConfigSync(folder, { platform, ...locateNamesOf(options) })\n const [source, ...ignored] = sources\n const layers = layersOf(options)\n if (source === undefined)\n return { namespace, root, key, config: {}, source: undefined, ignored: [], ...layers }\n if (kindOf(source.file) === 'code')\n throw new SyncConfigInCodeError(source.path, { files: jsonFilesOf(options), key })\n const config = readSync(configOfJson(source, key), platform.files)\n return { namespace, root, key, config, source, ignored, ...layers }\n}\n\n/**\n * What to say of the files of the configuration that are ignored, as a tool warns: `undefined`\n * when none is.\n */\nexport function ignoredWarning({\n namespace,\n key,\n source,\n ignored\n}: Pick<ResolvedConfig, 'namespace' | 'key' | 'source' | 'ignored'>): string | undefined {\n if (source === undefined || ignored.length === 0) return undefined\n const names = ignored.map(({ file }) =>\n kindOf(file) === 'package' ? `the \"${key}\" key of ${file}` : file\n )\n return `The ${namespace} configuration is read from ${source.file}; ${names.join(' and ')} ${names.length === 1 ? 'is' : 'are'} ignored. Keep it in one file.`\n}\n"]}
1
+ {"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":";;;;;;;;AA4BA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAoB,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC3E,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,UAAU,EACV,SAAS,EAET,QAAQ,EACR,MAAM,EACP,MAAM,YAAY,CAAA;AAUnB,OAAO,EACL,aAAa,EACb,WAAW,EACX,YAAY,EACZ,gBAAgB,EAEjB,MAAM,aAAa,CAAA;AAqDpB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,CAAC,IAA+C,EAAgB,EAAE,CAClE,KAAK,EAAE,IAAI,EAAE,EAAE,CACb,MAAM,kCAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAC,CAAA;AAErC,oGAAoG;AACpG,KAAK,UAAU,cAAc,CAC3B,MAAoB,EACpB,YAA0B;IAE1B,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,sBAAsB,CAC9B,MAAM,CAAC,IAAI,EACX,mBAAmB,KAAK,YAAY,KAAK,CAAC,CAA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project's configuration, as a tool reads it: {@link loadConfig}, the object of the first file\n * of it found at the root of the project, of code or of JSON, the file it came from, and the\n * others found, which are ignored; {@link loadConfigSync}, the same of a JSON file or package.json\n * alone, for a tool that reads its config synchronously; {@link ignoredWarning}, what to say of\n * the files ignored; and {@link importFileModule}, which imports a configuration of code, as\n * `wtf.config.ts`, by its file URL, as Node imports a module.\n *\n * Each reads by the platform it is given, and nothing of the process: its files, its paths, the\n * folder it works in, which the project is looked for from, and its environment, whose variables\n * are over the configuration. The entry point builds it, as `nodePlatform()` of\n * `@wtf/platform-node/platform` makes Node's:\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { loadConfig } from '@wtf/project-config/load'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const resolved = await loadConfig({ platform })\n * ```\n *\n * @packageDocumentation\n */\nimport type { Platform } from '@wtf/platform'\nimport type { Dirs } from '@wtf/platform/dirs'\n\nimport { envPrefixOf, variablesOf, type Environment } from './env.ts'\nimport { InvalidConfigFileError, SyncConfigInCodeError } from './errors.ts'\nimport {\n filesOf,\n isObject,\n kindOf,\n manifestOf,\n readAsync,\n type Reads,\n readSync,\n textOf\n} from './files.ts'\nimport type {\n ConfigDefaults,\n ConfigPlatform,\n ConfigSource,\n ConfigSyncPlatform,\n ImportModule,\n NamespaceConfig,\n ResolvedConfig\n} from './index.ts'\nimport {\n configNamesOf,\n jsonFilesOf,\n locateConfig,\n locateConfigSync,\n type LocateNames\n} from './locate.ts'\n\n/** How a configuration is read, apart from the platform: the folder of the project, its names, and\n * the defaults of the tool's package. */\nexport type LoadLayers = LocateNames & {\n /**\n * The folder of the project, which its root is looked for from: the working folder of the\n * platform, `dirs.cwd`, by default.\n */\n readonly folder?: string\n /**\n * The configuration under the project's, as the tool's package gives it: a section the project\n * gives none of is the one of the defaults, and one it gives is merged over it (`sectionOf` of\n * ./section).\n */\n readonly defaults?: ConfigDefaults\n}\n\n/**\n * What a configuration is read by asynchronously: the platform's files, its paths and its working\n * folder ({@link ConfigPlatform}), and its environment, `env`, of which the variables of the prefix\n * of the names, as `WTF_`, are kept, and a section is read with them over it, and its placeholders\n * `${env:NAME}` taken from the whole (`sectionOf` of ./section). A `Platform` of `@wtf/platform` is\n * one.\n */\nexport type LoadPlatform = ConfigPlatform & Pick<Platform, 'env'>\n\n/**\n * What a configuration is read by synchronously: the platform's paths and its files, read\n * synchronously ({@link ConfigSyncPlatform}), its working folder, and its environment, as\n * {@link LoadPlatform} has them. `nodeSyncPlatform()` of ./node adds Node's files to a platform.\n */\nexport type LoadSyncPlatform = ConfigSyncPlatform &\n Pick<Platform, 'env'> & { readonly dirs: Pick<Dirs, 'cwd'> }\n\n/** How a configuration is read asynchronously. */\nexport type LoadOptions = LoadLayers & {\n /** The platform it is read by ({@link LoadPlatform}). */\n readonly platform: LoadPlatform\n /**\n * What imports a file of code: by default `import()` of its file URL, as the platform's paths\n * give it ({@link importFileModule}). A caller of a file system of its own, not the one its\n * runtime imports from, gives one too.\n */\n readonly importModule?: ImportModule\n}\n\n/** How a configuration is read synchronously. */\nexport type LoadSyncOptions = LoadLayers & {\n /** The platform it is read by synchronously ({@link LoadSyncPlatform}). */\n readonly platform: LoadSyncPlatform\n}\n\n/**\n * What imports the module of the file at an absolute path, by its file URL, as the paths `path`\n * give it: what imports a configuration of code by default, `wtf.config.ts` among them, whose types\n * Node strips itself. The runtime imports it, of the file system it imports from, and not the one\n * a caller gives.\n */\nexport const importFileModule =\n (path: Pick<ConfigPlatform['path'], 'toFileUrl'>): ImportModule =>\n async (file) =>\n import(path.toFileUrl(file).href)\n\n/** The configuration of a module: its default export, an object, or a function that returns one. */\nasync function configOfModule(\n source: ConfigSource,\n importModule: ImportModule\n): Promise<NamespaceConfig> {\n let module: unknown\n try {\n module = await importModule(source.path)\n } catch (error) {\n throw new InvalidConfigFileError(\n source.path,\n `failed to load: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error }\n )\n }\n const exported: unknown = isObject(module) ? module['default'] : undefined\n const config: unknown = typeof exported === 'function' ? await exported() : exported\n if (!isObject(config))\n throw new InvalidConfigFileError(\n source.path,\n 'exports no object by default: give `export default { … }`, or a function that returns one.'\n )\n return config\n}\n\n/** The configuration of a JSON file: its own object, or the `key` of package.json. */\nfunction* configOfJson(source: ConfigSource, key: string): Reads<NamespaceConfig> {\n const text = (yield* textOf(source.path)) ?? ''\n if (kindOf(source.file) === 'package') {\n const value = manifestOf(source.path, text)[key]\n if (!isObject(value))\n throw new InvalidConfigFileError(source.path, `its \"${key}\" key is no JSON object.`)\n return value\n }\n let value: unknown\n try {\n value = JSON.parse(text)\n } catch (error) {\n throw new InvalidConfigFileError(source.path, 'is no JSON.', { cause: error })\n }\n if (!isObject(value)) throw new InvalidConfigFileError(source.path, 'is no JSON object.')\n return value\n}\n\n/** What a resolved configuration keeps beside the object: the defaults and the environment. */\nfunction layersOf({ defaults, folder: _folder, ...names }: LoadLayers, environment: Environment) {\n const prefix = envPrefixOf(configNamesOf(names).env)\n return {\n ...(defaults === undefined ? {} : { defaults }),\n environment: { prefix, variables: variablesOf(environment, prefix), values: environment }\n }\n}\n\n/** The options of the names alone, without what reads them. */\nconst locateNamesOf = ({ defaults: _d, folder: _f, ...names }: LoadLayers): LocateNames => names\n\n/**\n * The configuration of the project in `folder`, the working folder of the platform by default: the\n * object of the first file of it at the root of the project, in the order of the files of its\n * names — by default `wtf.config.mjs`, `wtf.config.js`, `wtf.config.ts` and `wtf.config.json`,\n * then the `wtf` key of package.json — and the file it came from; `{}`, of no file, when none is\n * there. Each other file found is in `ignored`. The `defaults` a tool gives are kept beside it, for\n * `sectionOf` of ./section to merge the project's sections over, and so are the variables of the\n * environment of the platform, its `env`, of the prefix of the names, `WTF_` by default, with the\n * whole environment, which placeholders are taken from. No placeholder is expanded here. A file of code is imported by `importModule`. A file that\n * holds no object, or a module that fails to load, is an {@link InvalidConfigFileError}.\n */\nexport async function loadConfig({\n importModule,\n platform,\n ...options\n}: LoadOptions): Promise<ResolvedConfig> {\n const { namespace } = configNamesOf(options)\n const { root, key, sources } = await locateConfig(options.folder ?? platform.dirs.cwd, {\n platform,\n ...locateNamesOf(options)\n })\n const [source, ...ignored] = sources\n const layers = layersOf(options, platform.env)\n if (source === undefined)\n return { namespace, root, key, config: {}, source: undefined, ignored: [], ...layers }\n const config =\n kindOf(source.file) === 'code'\n ? await configOfModule(source, importModule ?? importFileModule(platform.path))\n : await readAsync(configOfJson(source, key), filesOf(platform))\n return { namespace, root, key, config, source, ignored, ...layers }\n}\n\n/**\n * The configuration of the project in `folder`, the working folder of the platform by default, with\n * the environment of the platform over it, as {@link loadConfig} reads it, read synchronously:\n * of a JSON file of the names, `wtf.config.json` by default, or the key of package.json, `wtf` by\n * default, for a tool that loads its own config synchronously. A configuration of code in use, as\n * `wtf.config.ts`, is a {@link SyncConfigInCodeError}, as importing it is asynchronous.\n */\nexport function loadConfigSync({ platform, ...options }: LoadSyncOptions): ResolvedConfig {\n const { namespace } = configNamesOf(options)\n const { root, key, sources } = locateConfigSync(options.folder ?? platform.dirs.cwd, {\n platform,\n ...locateNamesOf(options)\n })\n const [source, ...ignored] = sources\n const layers = layersOf(options, platform.env)\n if (source === undefined)\n return { namespace, root, key, config: {}, source: undefined, ignored: [], ...layers }\n if (kindOf(source.file) === 'code')\n throw new SyncConfigInCodeError(source.path, { files: jsonFilesOf(options), key })\n const config = readSync(configOfJson(source, key), platform.files)\n return { namespace, root, key, config, source, ignored, ...layers }\n}\n\n/**\n * What to say of the files of the configuration that are ignored, as a tool warns: `undefined`\n * when none is.\n */\nexport function ignoredWarning({\n namespace,\n key,\n source,\n ignored\n}: Pick<ResolvedConfig, 'namespace' | 'key' | 'source' | 'ignored'>): string | undefined {\n if (source === undefined || ignored.length === 0) return undefined\n const names = ignored.map(({ file }) =>\n kindOf(file) === 'package' ? `the \"${key}\" key of ${file}` : file\n )\n return `The ${namespace} configuration is read from ${source.file}; ${names.join(' and ')} ${names.length === 1 ? 'is' : 'are'} ignored. Keep it in one file.`\n}\n"]}
package/dist/locate.d.ts CHANGED
@@ -38,13 +38,14 @@ export type LocateNames = NamespaceNames & {
38
38
  export type LocateOptions = LocateNames & {
39
39
  /**
40
40
  * The platform it is read by: its storage, whose `getDirectory()` is the root of its file
41
- * system, as a browser's or `nodeConfigPlatform()` of ./node gives it, and its paths.
41
+ * system, as a browser's or `nodePlatform()` of `@wtf/platform-node/platform` gives it, its
42
+ * paths, and its working folder, which a relative folder is resolved against.
42
43
  */
43
44
  readonly platform: ConfigPlatform;
44
45
  };
45
46
  /** Where the configuration is looked for, synchronously, by the platform's files. */
46
47
  export type LocateSyncOptions = LocateNames & {
47
- /** The platform it is read by synchronously, as `nodeSyncPlatform()` of ./node gives it. */
48
+ /** The platform it is read by synchronously, as `nodeSyncPlatform()` of ./node makes it. */
48
49
  readonly platform: ConfigSyncPlatform;
49
50
  };
50
51
  /**
package/dist/locate.js CHANGED
@@ -9,10 +9,13 @@
9
9
  * the files of a synchronous one.
10
10
  *
11
11
  * ```ts
12
+ * import { nodeStorage } from '@wtf/platform-fs-node/storage'
13
+ * import { nodePlatform } from '@wtf/platform-node/platform'
14
+ *
12
15
  * import { locateConfig } from '@wtf/project-config/locate'
13
- * import { nodeConfigPlatform } from '@wtf/project-config/node'
14
16
  *
15
- * const { root, sources } = await locateConfig(process.cwd(), { platform: nodeConfigPlatform() })
17
+ * const platform = nodePlatform({ fetch, storage: nodeStorage() })
18
+ * const { root, sources } = await locateConfig(platform.dirs.cwd, { platform })
16
19
  * ```
17
20
  *
18
21
  * @packageDocumentation
@@ -1 +1 @@
1
- {"version":3,"file":"locate.js","sourceRoot":"","sources":["../src/locate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,UAAU,EACV,OAAO,EACP,YAAY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AC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEjF;yDACyD;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,EAAE,QAAQ,EAAuC,EACzC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;AAEpE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,MAAc,EACd,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAiB,EACb,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;AAE/F;yBACyB;AACzB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,MAAc,EACd,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAqB,EAC1B,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA","sourcesContent":["/**\n * Where a project's configuration is: {@link projectRootOf}, the folder it is looked for in, the\n * root of the workspace the project is in, or the project's own folder; {@link locateConfig}, each\n * file of it there, in the order of the files of its names, of which the first is used; and\n * {@link configNamesOf}, those names: the files ({@link configFilesOf} of the namespace by\n * default), the key of package.json (the namespace) and the prefix of the environment's variables\n * (the key). The namespace is `wtf` by default ({@link DEFAULT_NAMESPACE}). Each reads by the\n * platform it is given, asynchronously; {@link projectRootOfSync} and {@link locateConfigSync} by\n * the files of a synchronous one.\n *\n * ```ts\n * import { locateConfig } from '@wtf/project-config/locate'\n * import { nodeConfigPlatform } from '@wtf/project-config/node'\n *\n * const { root, sources } = await locateConfig(process.cwd(), { platform: nodeConfigPlatform() })\n * ```\n *\n * @packageDocumentation\n */\nimport { envNameOf } from './env.ts'\nimport {\n filesOf,\n isObject,\n kindOf,\n manifestAt,\n namesOf,\n PACKAGE_JSON,\n readAsync,\n type Reads,\n readSync,\n textOf\n} from './files.ts'\nimport type {\n ConfigNames,\n ConfigPlatform,\n ConfigSource,\n ConfigSyncPlatform,\n LocatedConfig\n} from './index.ts'\n\n/** The namespace a configuration is of when none is given: `wtf`, as `wtf.config.json`. */\nexport const DEFAULT_NAMESPACE = 'wtf'\n\n/**\n * The files the configuration of `namespace` can be in by default, in the order the first found is\n * used: code first, as a person who writes code means it to be read, then JSON. After them comes\n * the `namespace` key of package.json, where a write makes it when there is none.\n */\nexport const configFilesOf = (namespace: string = DEFAULT_NAMESPACE): readonly string[] => [\n `${namespace}.config.mjs`,\n `${namespace}.config.js`,\n `${namespace}.config.ts`,\n `${namespace}.config.json`\n]\n\n/** The names of a namespace's configuration: the namespace, `wtf` by default, and the names a\n * tool gives. */\nexport type NamespaceNames = ConfigNames & {\n /** The namespace of the tools: the name of its files and its key by default. `wtf` by default. */\n readonly namespace?: string\n}\n\n/**\n * The names of the configuration of the namespace, each as `names` gives it, else its default: the\n * files, {@link configFilesOf} the namespace; the key of package.json, the namespace; and the\n * prefix of the environment's variables, the key. A file that is neither code nor JSON,\n * package.json among the files, an empty key, or a prefix of no letter or digit, is a `TypeError`.\n */\nexport function configNamesOf({\n namespace = DEFAULT_NAMESPACE,\n files,\n key,\n env\n}: NamespaceNames = {}): Required<ConfigNames> & { readonly namespace: string } {\n const resolvedKey = key ?? namespace\n const names = {\n namespace,\n files: files ?? configFilesOf(namespace),\n key: resolvedKey,\n env: env ?? resolvedKey\n }\n for (const file of names.files)\n if (kindOf(file) === 'package')\n throw new TypeError(\n `${PACKAGE_JSON} is no file of the configuration: it holds it by its key, which \\`key\\` names.`\n )\n if (names.key === '')\n throw new TypeError(`The key of package.json is empty: name one, as ${namespace}.`)\n if (envNameOf(names.env) === '')\n throw new TypeError(\n `The name of the variables of the environment is empty: name one, as ${names.key}.`\n )\n return names\n}\n\n/** The JSON files of the names of a namespace, which a write makes or changes, and a synchronous\n * load reads: those of its files that are no code, in their order. */\nexport const jsonFilesOf = (names: NamespaceNames = {}): readonly string[] =>\n configNamesOf(names).files.filter((file) => kindOf(file) === 'json')\n\n/** Where the configuration is looked for, apart from the platform: the namespace and its names,\n * each its default when not given, and whether the root is looked for from the folder up. */\nexport type LocateNames = NamespaceNames & {\n /**\n * Whether the root is looked for from the folder up, as {@link projectRootOf} finds it: by\n * default. With `false`, the folder given is the root.\n */\n readonly up?: boolean\n}\n\n/** Where the configuration is looked for, asynchronously, by the platform's files. */\nexport type LocateOptions = LocateNames & {\n /**\n * The platform it is read by: its storage, whose `getDirectory()` is the root of its file\n * system, as a browser's or `nodeConfigPlatform()` of ./node gives it, and its paths.\n */\n readonly platform: ConfigPlatform\n}\n\n/** Where the configuration is looked for, synchronously, by the platform's files. */\nexport type LocateSyncOptions = LocateNames & {\n /** The platform it is read by synchronously, as `nodeSyncPlatform()` of ./node gives it. */\n readonly platform: ConfigSyncPlatform\n}\n\n/** The paths the root is looked for by. */\ntype Paths = Pick<ConfigPlatform['path'], 'resolve' | 'join' | 'dirname'>\n\n/** Whether the folder is the root of a workspace: a pnpm-workspace.yaml, or npm's `workspaces`. */\nfunction* isWorkspaceRoot(folder: string, { join }: Paths): Reads<boolean> {\n if ((yield* textOf(join(folder, 'pnpm-workspace.yaml'))) !== undefined) return true\n let manifest: Record<string, unknown> | undefined\n try {\n manifest = yield* manifestAt(join(folder, PACKAGE_JSON))\n } catch {\n return false\n }\n return isObject(manifest) && manifest['workspaces'] !== undefined\n}\n\n/** The root of the project in `folder`, of the reads it asks for. */\nfunction* rootOf(folder: string, path: Paths): Reads<string> {\n const { dirname, join, resolve } = path\n let project: string | undefined\n for (let at = resolve(folder); ; at = dirname(at)) {\n if (yield* isWorkspaceRoot(at, path)) return at\n if (project === undefined && (yield* textOf(join(at, PACKAGE_JSON))) !== undefined) project = at\n if (dirname(at) === at) return project ?? resolve(folder)\n }\n}\n\n/** The configuration of the project in `folder`, located, of the reads it asks for. */\nfunction* locate(\n folder: string,\n { up = true, ...names }: LocateNames,\n path: Paths\n): Reads<LocatedConfig> {\n const { files, key } = configNamesOf(names)\n const root = up ? yield* rootOf(folder, path) : path.resolve(folder)\n const found = yield* namesOf(root)\n const manifest = yield* manifestAt(path.join(root, PACKAGE_JSON))\n const sources: ConfigSource[] = [\n ...files.filter((file) => found.has(file)),\n ...(manifest !== undefined && Object.hasOwn(manifest, key) ? [PACKAGE_JSON] : [])\n ].map((file) => ({ file, path: path.join(root, file) }))\n return { root, key, sources }\n}\n\n/**\n * The folder the configuration of the project in `folder` is looked for in: the root of the\n * workspace it is in, the nearest from `folder` up with a pnpm-workspace.yaml or a package.json of\n * `workspaces`; else the project's own folder, the nearest from `folder` up with a package.json;\n * else `folder`. One configuration then serves each package of a workspace.\n */\nexport const projectRootOf = (\n folder: string,\n { platform }: Pick<LocateOptions, 'platform'>\n): Promise<string> => readAsync(rootOf(folder, platform.path), filesOf(platform))\n\n/** The folder the configuration of the project in `folder` is looked for in, as\n * {@link projectRootOf} finds it, read synchronously. */\nexport const projectRootOfSync = (\n folder: string,\n { platform }: Pick<LocateSyncOptions, 'platform'>\n): string => readSync(rootOf(folder, platform.path), platform.files)\n\n/**\n * Each file of the configuration of the project in `folder`, at its root, in the order of the\n * files of its names (`wtf.config.mjs`, `.js`, `.ts` and `.json` by default), and package.json\n * when it has the key (`wtf` by default). The first is the one in use. The root is\n * {@link projectRootOf} `folder`, or `folder` itself with `up: false`. A package.json that is no\n * JSON object is an `InvalidConfigFileError` of ./errors; names that are not of the configuration,\n * a `TypeError`, as {@link configNamesOf} says.\n */\nexport const locateConfig = (\n folder: string,\n { platform, ...names }: LocateOptions\n): Promise<LocatedConfig> => readAsync(locate(folder, names, platform.path), filesOf(platform))\n\n/** Each file of the configuration of the project in `folder`, as {@link locateConfig} finds them,\n * read synchronously. */\nexport const locateConfigSync = (\n folder: string,\n { platform, ...names }: LocateSyncOptions\n): LocatedConfig => readSync(locate(folder, names, platform.path), platform.files)\n"]}
1
+ {"version":3,"file":"locate.js","sourceRoot":"","sources":["../src/locate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,UAAU,EACV,OAAO,EACP,YAAY,EACZ,SAAS,EAET,QAAQ,EACR,MAAM,EACP,MAAM,YAAY,CAAA;AASnB,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAA;AAEtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,YAAoB,iBAAiB,EAAqB,EAAE,CAAC;IACzF,GAAG,SAAS,aAAa;IACzB,GAAG,SAAS,YAAY;IACxB,GAAG,SAAS,YAAY;IACxB,GAAG,SAAS,cAAc;CAC3B,CAAA;AASD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,SAAS,GAAG,iBAAiB,EAC7B,KAAK,EACL,GAAG,EACH,GAAG,KACe,EAAE;IACpB,MAAM,WAAW,GAAG,GAAG,IAAI,SAAS,CAAA;IACpC,MAAM,KAAK,GAAG;QACZ,SAAS;QACT,KAAK,EAAE,KAAK,IAAI,aAAa,CAAC,SAAS,CAAC;QACxC,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,GAAG,IAAI,WAAW;KACxB,CAAA;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK;QAC5B,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS;YAC5B,MAAM,IAAI,SAAS,CACjB,GAAG,YAAY,gFAAgF,CAChG,CAAA;IACL,IAAI,KAAK,CAAC,GAAG,KAAK,EAAE;QAClB,MAAM,IAAI,SAAS,CAAC,kDAAkD,SAAS,GAAG,CAAC,CAAA;I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C,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;IACxD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAAc,EACd,EAAE,QAAQ,EAAmC,EAC5B,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEjF;yDACyD;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,EAAE,QAAQ,EAAuC,EACzC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;AAEpE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,MAAc,EACd,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAiB,EACb,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;AAE/F;yBACyB;AACzB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,MAAc,EACd,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAqB,EAC1B,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA","sourcesContent":["/**\n * Where a project's configuration is: {@link projectRootOf}, the folder it is looked for in, the\n * root of the workspace the project is in, or the project's own folder; {@link locateConfig}, each\n * file of it there, in the order of the files of its names, of which the first is used; and\n * {@link configNamesOf}, those names: the files ({@link configFilesOf} of the namespace by\n * default), the key of package.json (the namespace) and the prefix of the environment's variables\n * (the key). The namespace is `wtf` by default ({@link DEFAULT_NAMESPACE}). Each reads by the\n * platform it is given, asynchronously; {@link projectRootOfSync} and {@link locateConfigSync} by\n * the files of a synchronous one.\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { locateConfig } from '@wtf/project-config/locate'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const { root, sources } = await locateConfig(platform.dirs.cwd, { platform })\n * ```\n *\n * @packageDocumentation\n */\nimport { envNameOf } from './env.ts'\nimport {\n filesOf,\n isObject,\n kindOf,\n manifestAt,\n namesOf,\n PACKAGE_JSON,\n readAsync,\n type Reads,\n readSync,\n textOf\n} from './files.ts'\nimport type {\n ConfigNames,\n ConfigPlatform,\n ConfigSource,\n ConfigSyncPlatform,\n LocatedConfig\n} from './index.ts'\n\n/** The namespace a configuration is of when none is given: `wtf`, as `wtf.config.json`. */\nexport const DEFAULT_NAMESPACE = 'wtf'\n\n/**\n * The files the configuration of `namespace` can be in by default, in the order the first found is\n * used: code first, as a person who writes code means it to be read, then JSON. After them comes\n * the `namespace` key of package.json, where a write makes it when there is none.\n */\nexport const configFilesOf = (namespace: string = DEFAULT_NAMESPACE): readonly string[] => [\n `${namespace}.config.mjs`,\n `${namespace}.config.js`,\n `${namespace}.config.ts`,\n `${namespace}.config.json`\n]\n\n/** The names of a namespace's configuration: the namespace, `wtf` by default, and the names a\n * tool gives. */\nexport type NamespaceNames = ConfigNames & {\n /** The namespace of the tools: the name of its files and its key by default. `wtf` by default. */\n readonly namespace?: string\n}\n\n/**\n * The names of the configuration of the namespace, each as `names` gives it, else its default: the\n * files, {@link configFilesOf} the namespace; the key of package.json, the namespace; and the\n * prefix of the environment's variables, the key. A file that is neither code nor JSON,\n * package.json among the files, an empty key, or a prefix of no letter or digit, is a `TypeError`.\n */\nexport function configNamesOf({\n namespace = DEFAULT_NAMESPACE,\n files,\n key,\n env\n}: NamespaceNames = {}): Required<ConfigNames> & { readonly namespace: string } {\n const resolvedKey = key ?? namespace\n const names = {\n namespace,\n files: files ?? configFilesOf(namespace),\n key: resolvedKey,\n env: env ?? resolvedKey\n }\n for (const file of names.files)\n if (kindOf(file) === 'package')\n throw new TypeError(\n `${PACKAGE_JSON} is no file of the configuration: it holds it by its key, which \\`key\\` names.`\n )\n if (names.key === '')\n throw new TypeError(`The key of package.json is empty: name one, as ${namespace}.`)\n if (envNameOf(names.env) === '')\n throw new TypeError(\n `The name of the variables of the environment is empty: name one, as ${names.key}.`\n )\n return names\n}\n\n/** The JSON files of the names of a namespace, which a write makes or changes, and a synchronous\n * load reads: those of its files that are no code, in their order. */\nexport const jsonFilesOf = (names: NamespaceNames = {}): readonly string[] =>\n configNamesOf(names).files.filter((file) => kindOf(file) === 'json')\n\n/** Where the configuration is looked for, apart from the platform: the namespace and its names,\n * each its default when not given, and whether the root is looked for from the folder up. */\nexport type LocateNames = NamespaceNames & {\n /**\n * Whether the root is looked for from the folder up, as {@link projectRootOf} finds it: by\n * default. With `false`, the folder given is the root.\n */\n readonly up?: boolean\n}\n\n/** Where the configuration is looked for, asynchronously, by the platform's files. */\nexport type LocateOptions = LocateNames & {\n /**\n * The platform it is read by: its storage, whose `getDirectory()` is the root of its file\n * system, as a browser's or `nodePlatform()` of `@wtf/platform-node/platform` gives it, its\n * paths, and its working folder, which a relative folder is resolved against.\n */\n readonly platform: ConfigPlatform\n}\n\n/** Where the configuration is looked for, synchronously, by the platform's files. */\nexport type LocateSyncOptions = LocateNames & {\n /** The platform it is read by synchronously, as `nodeSyncPlatform()` of ./node makes it. */\n readonly platform: ConfigSyncPlatform\n}\n\n/** The paths the root is looked for by. */\ntype Paths = Pick<ConfigPlatform['path'], 'resolve' | 'join' | 'dirname'>\n\n/** Whether the folder is the root of a workspace: a pnpm-workspace.yaml, or npm's `workspaces`. */\nfunction* isWorkspaceRoot(folder: string, { join }: Paths): Reads<boolean> {\n if ((yield* textOf(join(folder, 'pnpm-workspace.yaml'))) !== undefined) return true\n let manifest: Record<string, unknown> | undefined\n try {\n manifest = yield* manifestAt(join(folder, PACKAGE_JSON))\n } catch {\n return false\n }\n return isObject(manifest) && manifest['workspaces'] !== undefined\n}\n\n/** The root of the project in `folder`, of the reads it asks for. */\nfunction* rootOf(folder: string, path: Paths): Reads<string> {\n const { dirname, join, resolve } = path\n let project: string | undefined\n for (let at = resolve(folder); ; at = dirname(at)) {\n if (yield* isWorkspaceRoot(at, path)) return at\n if (project === undefined && (yield* textOf(join(at, PACKAGE_JSON))) !== undefined) project = at\n if (dirname(at) === at) return project ?? resolve(folder)\n }\n}\n\n/** The configuration of the project in `folder`, located, of the reads it asks for. */\nfunction* locate(\n folder: string,\n { up = true, ...names }: LocateNames,\n path: Paths\n): Reads<LocatedConfig> {\n const { files, key } = configNamesOf(names)\n const root = up ? yield* rootOf(folder, path) : path.resolve(folder)\n const found = yield* namesOf(root)\n const manifest = yield* manifestAt(path.join(root, PACKAGE_JSON))\n const sources: ConfigSource[] = [\n ...files.filter((file) => found.has(file)),\n ...(manifest !== undefined && Object.hasOwn(manifest, key) ? [PACKAGE_JSON] : [])\n ].map((file) => ({ file, path: path.join(root, file) }))\n return { root, key, sources }\n}\n\n/**\n * The folder the configuration of the project in `folder` is looked for in: the root of the\n * workspace it is in, the nearest from `folder` up with a pnpm-workspace.yaml or a package.json of\n * `workspaces`; else the project's own folder, the nearest from `folder` up with a package.json;\n * else `folder`. One configuration then serves each package of a workspace.\n */\nexport const projectRootOf = (\n folder: string,\n { platform }: Pick<LocateOptions, 'platform'>\n): Promise<string> => readAsync(rootOf(folder, platform.path), filesOf(platform))\n\n/** The folder the configuration of the project in `folder` is looked for in, as\n * {@link projectRootOf} finds it, read synchronously. */\nexport const projectRootOfSync = (\n folder: string,\n { platform }: Pick<LocateSyncOptions, 'platform'>\n): string => readSync(rootOf(folder, platform.path), platform.files)\n\n/**\n * Each file of the configuration of the project in `folder`, at its root, in the order of the\n * files of its names (`wtf.config.mjs`, `.js`, `.ts` and `.json` by default), and package.json\n * when it has the key (`wtf` by default). The first is the one in use. The root is\n * {@link projectRootOf} `folder`, or `folder` itself with `up: false`. A package.json that is no\n * JSON object is an `InvalidConfigFileError` of ./errors; names that are not of the configuration,\n * a `TypeError`, as {@link configNamesOf} says.\n */\nexport const locateConfig = (\n folder: string,\n { platform, ...names }: LocateOptions\n): Promise<LocatedConfig> => readAsync(locate(folder, names, platform.path), filesOf(platform))\n\n/** Each file of the configuration of the project in `folder`, as {@link locateConfig} finds them,\n * read synchronously. */\nexport const locateConfigSync = (\n folder: string,\n { platform, ...names }: LocateSyncOptions\n): LocatedConfig => readSync(locate(folder, names, platform.path), platform.files)\n"]}
package/dist/node.d.ts CHANGED
@@ -1,35 +1,22 @@
1
- import type { ConfigPlatform, ConfigSyncPlatform, ResolvedConfig } from './index.ts';
2
- import { type LoadOptions, type LoadSyncOptions } from './load.ts';
1
+ import type { LoadSyncPlatform } from './load.ts';
3
2
  import type { LoadModule } from './named.ts';
4
- /** Node's platform the configuration is read and written by: the disk from its root, its paths,
5
- * and the process's working folder. */
6
- export declare const nodeConfigPlatform: () => ConfigPlatform;
7
- /** Node's platform the configuration is read by synchronously: the disk by `node:fs`, and its
8
- * paths. */
9
- export declare const nodeSyncPlatform: () => ConfigSyncPlatform;
10
3
  /**
11
- * The configuration of the project in `folder`, the process's working folder by default, as
12
- * `loadConfig` of ./load reads it: the namespace `wtf` by default, of Node's platform and the
13
- * process's environment, unless `options` gives others.
4
+ * The platform the configuration is read by synchronously, of `platform`: its paths, its working
5
+ * folder and its environment, as they are, and the disk, read synchronously by `node:fs`, as its
6
+ * files. `loadConfigSync` of ./load reads by it.
14
7
  */
15
- export declare const loadConfig: (folder?: string, options?: Partial<LoadOptions>) => Promise<ResolvedConfig>;
16
- /**
17
- * The configuration of the project in `folder`, the process's working folder by default, as
18
- * `loadConfigSync` of ./load reads it, of a JSON file or package.json alone: of Node's platform
19
- * and the process's environment, unless `options` gives others.
20
- */
21
- export declare const loadConfigSync: (folder?: string, options?: Partial<LoadSyncOptions>) => ResolvedConfig;
8
+ export declare const nodeSyncPlatform: ({ path, dirs, env }: Omit<LoadSyncPlatform, "files">) => LoadSyncPlatform;
22
9
  /**
23
10
  * 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.
11
+ * `root`, the root of the project, as the entry point gives it; a package, the one `root`
12
+ * installs, else the one installed beside `beside`, as a tool gives its own `import.meta.url`, so a
13
+ * package a global install puts beside the tool is found too. What fails to resolve or load fails
14
+ * of the error of `root`'s resolve, or of the import.
28
15
  *
29
16
  * ```ts
30
17
  * import { nodeLoadModule } from '@wtf/project-config/node'
31
18
  *
32
- * const load = nodeLoadModule(process.cwd(), import.meta.url)
19
+ * const load = nodeLoadModule(resolved.root, import.meta.url)
33
20
  * ```
34
21
  */
35
- export declare const nodeLoadModule: (root?: string, beside?: string | URL) => LoadModule;
22
+ export declare const nodeLoadModule: (root: string, beside?: string | URL) => LoadModule;
package/dist/node.js CHANGED
@@ -7,22 +7,22 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
7
7
  return path;
8
8
  };
9
9
  /**
10
- * Node's platform and loads of the configuration: {@link nodeConfigPlatform}, the disk as handles
11
- * of the File System Standard, by `nodeStorage()` of `@wtf/platform-fs-node/storage`, and the paths
12
- * of `nodePath()` of `@wtf/platform-node/path`; {@link nodeSyncPlatform}, the disk read
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:
10
+ * What of the configuration is Node's by nature: {@link nodeSyncPlatform}, a platform's files read
11
+ * synchronously, by `node:fs`, as no handle of the File System Standard reads them, for
12
+ * `loadConfigSync` of ./load; and {@link nodeLoadModule}, what loads a module a reference of
13
+ * ./named names, by Node's resolution and `import()`. Neither reads anything of the process: the
14
+ * entry point gives the platform, and the root of the project:
17
15
  *
18
16
  * ```ts
19
- * import { loadConfig } from '@wtf/project-config/node'
20
- * import { sectionOf } from '@wtf/project-config/section'
21
- * import { rootConfig } from '@wtf/project-vitest/config'
22
- * import { vitestSchema } from '@wtf/project-vitest/schema'
17
+ * import { nodeStorage } from '@wtf/platform-fs-node/storage'
18
+ * import { nodePlatform } from '@wtf/platform-node/platform'
23
19
  *
24
- * const config = await loadConfig()
25
- * export default rootConfig({ ...(await sectionOf(config, 'vitest', vitestSchema)) })
20
+ * import { loadConfigSync } from '@wtf/project-config/load'
21
+ * import { nodeLoadModule, nodeSyncPlatform } from '@wtf/project-config/node'
22
+ *
23
+ * const platform = nodePlatform({ fetch, storage: nodeStorage() })
24
+ * const resolved = loadConfigSync({ platform: nodeSyncPlatform(platform) })
25
+ * const load = nodeLoadModule(resolved.root, import.meta.url)
26
26
  * ```
27
27
  *
28
28
  * @packageDocumentation
@@ -31,72 +31,49 @@ import { readdirSync, readFileSync, statSync } from 'node:fs';
31
31
  import { createRequire } from 'node:module';
32
32
  import { isAbsolute, join } from 'node:path';
33
33
  import { pathToFileURL } from 'node:url';
34
- import { nodeStorage } from '@wtf/platform-fs-node/storage';
35
- import { nodePath } from '@wtf/platform-node/path';
36
- import { loadConfig as loadWith, loadConfigSync as loadSyncWith } from "./load.js";
37
- /** Node's platform the configuration is read and written by: the disk from its root, its paths,
38
- * and the process's working folder. */
39
- export const nodeConfigPlatform = () => ({
40
- navigator: { storage: nodeStorage() },
41
- path: nodePath(),
42
- dirs: { cwd: process.cwd() }
43
- });
44
34
  /** Whether `error` is Node's of a file or a folder not there, or of the other kind. */
45
35
  const isMissing = (error) => ['ENOENT', 'ENOTDIR', 'EISDIR'].includes(error?.code ?? '');
46
- /** Node's platform the configuration is read by synchronously: the disk by `node:fs`, and its
47
- * paths. */
48
- export const nodeSyncPlatform = () => ({
49
- path: nodePath(),
50
- files: {
51
- text: (path) => {
52
- try {
53
- return readFileSync(path, 'utf8');
54
- }
55
- catch (error) {
56
- if (isMissing(error))
57
- return undefined;
58
- throw error;
59
- }
60
- },
61
- files: (folder) => {
62
- try {
63
- // A link is what it links to, as a handle of the disk reads it.
64
- return new Set(readdirSync(folder).filter((name) => {
65
- try {
66
- return statSync(join(folder, name)).isFile();
67
- }
68
- catch {
69
- return false;
70
- }
71
- }));
72
- }
73
- catch (error) {
74
- if (isMissing(error))
75
- return new Set();
76
- throw error;
77
- }
36
+ /** Node's files, read synchronously by `node:fs`, by their absolute paths. */
37
+ const nodeSyncFiles = {
38
+ text: (path) => {
39
+ try {
40
+ return readFileSync(path, 'utf8');
41
+ }
42
+ catch (error) {
43
+ if (isMissing(error))
44
+ return undefined;
45
+ throw error;
46
+ }
47
+ },
48
+ files: (folder) => {
49
+ try {
50
+ // A link is what it links to, as a handle of the disk reads it.
51
+ return new Set(readdirSync(folder).filter((name) => {
52
+ try {
53
+ return statSync(join(folder, name)).isFile();
54
+ }
55
+ catch {
56
+ return false;
57
+ }
58
+ }));
59
+ }
60
+ catch (error) {
61
+ if (isMissing(error))
62
+ return new Set();
63
+ throw error;
78
64
  }
79
65
  }
80
- });
81
- /**
82
- * The configuration of the project in `folder`, the process's working folder by default, as
83
- * `loadConfig` of ./load reads it: the namespace `wtf` by default, of Node's platform and the
84
- * process's environment, unless `options` gives others.
85
- */
86
- export const loadConfig = (folder = process.cwd(), options = {}) => loadWith(folder, {
87
- environment: process.env,
88
- ...options,
89
- platform: options.platform ?? nodeConfigPlatform()
90
- });
66
+ };
91
67
  /**
92
- * The configuration of the project in `folder`, the process's working folder by default, as
93
- * `loadConfigSync` of ./load reads it, of a JSON file or package.json alone: of Node's platform
94
- * and the process's environment, unless `options` gives others.
68
+ * The platform the configuration is read by synchronously, of `platform`: its paths, its working
69
+ * folder and its environment, as they are, and the disk, read synchronously by `node:fs`, as its
70
+ * files. `loadConfigSync` of ./load reads by it.
95
71
  */
96
- export const loadConfigSync = (folder = process.cwd(), options = {}) => loadSyncWith(folder, {
97
- environment: process.env,
98
- ...options,
99
- platform: options.platform ?? nodeSyncPlatform()
72
+ export const nodeSyncPlatform = ({ path, dirs, env }) => ({
73
+ path,
74
+ dirs,
75
+ env,
76
+ files: nodeSyncFiles
100
77
  });
101
78
  /**
102
79
  * The file of the module `module`: of an absolute path, itself; of a path from the root, `./` or
@@ -124,16 +101,16 @@ function fileOf(module, root, beside) {
124
101
  }
125
102
  /**
126
103
  * 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.
104
+ * `root`, the root of the project, as the entry point gives it; a package, the one `root`
105
+ * installs, else the one installed beside `beside`, as a tool gives its own `import.meta.url`, so a
106
+ * package a global install puts beside the tool is found too. What fails to resolve or load fails
107
+ * of the error of `root`'s resolve, or of the import.
131
108
  *
132
109
  * ```ts
133
110
  * import { nodeLoadModule } from '@wtf/project-config/node'
134
111
  *
135
- * const load = nodeLoadModule(process.cwd(), import.meta.url)
112
+ * const load = nodeLoadModule(resolved.root, import.meta.url)
136
113
  * ```
137
114
  */
138
- export const nodeLoadModule = (root = process.cwd(), beside) => async (module) => import(__rewriteRelativeImportExtension(pathToFileURL(fileOf(module, root, beside)).href));
115
+ export const nodeLoadModule = (root, beside) => async (module) => import(__rewriteRelativeImportExtension(pathToFileURL(fileOf(module, root, beside)).href));
139
116
  //# sourceMappingURL=node.js.map
package/dist/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["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,CAAC,MAAc,EAAE,IAAY,EAAE,MAAgC;IAC5E,IAAI,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IACrC,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACxD,IAAI,CAAC;QACH,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAClE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM,KAAK,CAAA;QACrC,IAAI,CAAC;YACH,OAAO,aAAa,CAAC,MAAM,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"]}
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;G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;QACb,CAAC;IACH,CAAC;CACF,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,IAAI,EACJ,IAAI,EACJ,GAAG,EAC6B,EAAoB,EAAE,CAAC,CAAC;IACxD,IAAI;IACJ,IAAI;IACJ,GAAG;IACH,KAAK,EAAE,aAAa;CACrB,CAAC,CAAA;AAEF;;;;GAIG;AACH,SAAS,MAAM,CAAC,MAAc,EAAE,IAAY,EAAE,MAAgC;IAC5E,IAAI,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IACrC,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACxD,IAAI,CAAC;QACH,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAClE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM,KAAK,CAAA;QACrC,IAAI,CAAC;YACH,OAAO,aAAa,CAAC,MAAM,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,IAAY,EAAE,MAAqB,EAAc,EAAE,CACpD,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 * What of the configuration is Node's by nature: {@link nodeSyncPlatform}, a platform's files read\n * synchronously, by `node:fs`, as no handle of the File System Standard reads them, for\n * `loadConfigSync` of ./load; and {@link nodeLoadModule}, what loads a module a reference of\n * ./named names, by Node's resolution and `import()`. Neither reads anything of the process: the\n * entry point gives the platform, and the root of the project:\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { loadConfigSync } from '@wtf/project-config/load'\n * import { nodeLoadModule, nodeSyncPlatform } from '@wtf/project-config/node'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const resolved = loadConfigSync({ platform: nodeSyncPlatform(platform) })\n * const load = nodeLoadModule(resolved.root, import.meta.url)\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 type { SyncFiles } from './index.ts'\nimport type { LoadSyncPlatform } from './load.ts'\nimport type { LoadModule } from './named.ts'\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 files, read synchronously by `node:fs`, by their absolute paths. */\nconst nodeSyncFiles: SyncFiles = {\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 * The platform the configuration is read by synchronously, of `platform`: its paths, its working\n * folder and its environment, as they are, and the disk, read synchronously by `node:fs`, as its\n * files. `loadConfigSync` of ./load reads by it.\n */\nexport const nodeSyncPlatform = ({\n path,\n dirs,\n env\n}: Omit<LoadSyncPlatform, 'files'>): LoadSyncPlatform => ({\n path,\n dirs,\n env,\n files: nodeSyncFiles\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, as the entry point gives it; a package, the one `root`\n * installs, else the one installed beside `beside`, as a tool gives its own `import.meta.url`, so a\n * package a global install puts beside the tool is found too. What fails to resolve or load fails\n * 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(resolved.root, import.meta.url)\n * ```\n */\nexport const nodeLoadModule =\n (root: string, beside?: string | URL): LoadModule =>\n async (module) =>\n import(pathToFileURL(fileOf(module, root, beside)).href)\n"]}
package/dist/section.d.ts CHANGED
@@ -20,11 +20,11 @@ export declare function issuesOfSync<T>(value: unknown, schema: SectionSchema<T>
20
20
  /**
21
21
  * The section `name` of the configuration, as its tool reads it: the project's, merged over the
22
22
  * section of the `defaults` of the tool's package when it gives some ({@link mergeSection}), with
23
- * the environment's variables the tool gave `loadConfig` over both, each that names a key of the
24
- * section or of its schema, as `WTF_VITE_COMPRESS` (`withEnvironment` of ./env); `undefined` when
25
- * none has one, which the tool takes as its own defaults. Each string in it is then read for
26
- * placeholders `${env:NAME}`, taken from the whole environment the tool gave (`expandPlaceholders`
27
- * of ./placeholder); a variable not set, or of no environment given, is an
23
+ * the variables of the environment of the platform the tool gave `loadConfig` over both, each that
24
+ * names a key of the section or of its schema, as `WTF_VITE_COMPRESS` (`withEnvironment` of
25
+ * ./env); `undefined` when none has one, which the tool takes as its own defaults. Each string in it is then read for
26
+ * placeholders `${env:NAME}`, taken from that whole environment (`expandPlaceholders` of
27
+ * ./placeholder); a variable not set, or of a configuration read of no environment, is an
28
28
  * `EnvPlaceholderUnsetError`. Only this, and {@link sectionOfSync}, expand them, so what shows or
29
29
  * writes the configuration never holds a secret it points at. With a `schema` it is checked, and
30
30
  * what is wrong is an {@link InvalidSectionError}, which names where the value came from and the
package/dist/section.js CHANGED
@@ -129,11 +129,11 @@ function invalidOf(resolved, name, { own, environment }, issues) {
129
129
  /**
130
130
  * The section `name` of the configuration, as its tool reads it: the project's, merged over the
131
131
  * section of the `defaults` of the tool's package when it gives some ({@link mergeSection}), with
132
- * the environment's variables the tool gave `loadConfig` over both, each that names a key of the
133
- * section or of its schema, as `WTF_VITE_COMPRESS` (`withEnvironment` of ./env); `undefined` when
134
- * none has one, which the tool takes as its own defaults. Each string in it is then read for
135
- * placeholders `${env:NAME}`, taken from the whole environment the tool gave (`expandPlaceholders`
136
- * of ./placeholder); a variable not set, or of no environment given, is an
132
+ * the variables of the environment of the platform the tool gave `loadConfig` over both, each that
133
+ * names a key of the section or of its schema, as `WTF_VITE_COMPRESS` (`withEnvironment` of
134
+ * ./env); `undefined` when none has one, which the tool takes as its own defaults. Each string in it is then read for
135
+ * placeholders `${env:NAME}`, taken from that whole environment (`expandPlaceholders` of
136
+ * ./placeholder); a variable not set, or of a configuration read of no environment, is an
137
137
  * `EnvPlaceholderUnsetError`. Only this, and {@link sectionOfSync}, expand them, so what shows or
138
138
  * writes the configuration never holds a secret it points at. With a `schema` it is checked, and
139
139
  * what is wrong is an {@link InvalidSectionError}, which names where the value came from and the
@@ -1 +1 @@
1
- {"version":3,"file":"section.js","sourceRoot":"","sources":["../src/section.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,OAAO,EAA2C,MAAM,kBAAkB,CAAA;AAEnF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAwB,MAAM,U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MAAM,CAAC,CAAA;IACjD,IAAI,CAAC,OAAO,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IACpC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,OAAY,CAAA;IACrD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACjE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrC,MAAM,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAwB,EACxB,IAAY,EACZ,MAAyB;IAEzB,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IACjD,IAAI,CAAC,OAAO,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IACpC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,OAAY,CAAA;IACrD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IACrE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrC,MAAM,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAClD,CAAC","sourcesContent":["/**\n * A tool's section of the configuration: {@link sectionOf}, the section of a name, the project's\n * merged over the defaults of the tool's package ({@link mergeSection}), with the environment's\n * variables the tool gives over both, each placeholder `${env:NAME}` in it replaced by the variable\n * it names, and checked by the schema the tool gives; {@link sectionOfSync}, the same, checked\n * synchronously; and {@link issuesOf} and {@link issuesOfSync}, what a schema finds wrong with a\n * value. A schema is a Standard Schema, as each preset's `./schema` exports one, a JSON Schema or a\n * Standard JSON Schema, which ajv checks, or a function. What is wrong is an\n * `InvalidSectionError` of ./errors, which names the file and the path of each value.\n *\n * ```ts\n * import { loadConfig } from '@wtf/project-config/node'\n * import { sectionOf } from '@wtf/project-config/section'\n * import { baseConfig } from '@wtf/project-vite/config'\n * import { viteSchema } from '@wtf/project-vite/schema'\n *\n * const config = await loadConfig(process.cwd())\n * export default baseConfig({ ...(await sectionOf(config, 'vite', viteSchema)) })\n * ```\n *\n * @packageDocumentation\n */\nimport type { StandardSchemaV1 } from '@standard-schema/spec'\nimport { Ajv2020, type ErrorObject, type ValidateFunction } from 'ajv/dist/2020.js'\n\nimport { envNameOf, jsonSchemaOf, withEnvironment, type WithEnvironment } from './env.ts'\nimport { InvalidSectionError, SyncSchemaError } from './errors.ts'\nimport type {\n ConfigIssue,\n ConfigPath,\n JsonSchema,\n ResolvedConfig,\n SectionSchema,\n ValidateSection\n} from './index.ts'\nimport { mergeSection } from './merge.ts'\nimport { expandPlaceholders } from './placeholder.ts'\n\nexport { mergeSection } from './merge.ts'\n\n/** What a schema found of a value: what is wrong with it, none when it is valid, and the value as\n * the schema reads it. */\nexport type Checked<T> = { readonly issues: readonly ConfigIssue[]; readonly value: T }\n\nconst isNode = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null\n\n/** Whether `schema` is a Standard Schema that validates: its `~standard` has `validate`. */\nconst validatorOf = (schema: unknown): StandardSchemaV1['~standard'] | undefined => {\n if (!isNode(schema) || !('~standard' in schema)) return undefined\n const standard = schema['~standard']\n return isNode(standard) && typeof standard['validate'] === 'function'\n ? (standard as unknown as StandardSchemaV1['~standard'])\n : undefined\n}\n\n/**\n * The JSON Schemas compiled, by ajv, for draft 2020-12: every fault and not the first, no check\n * of a `format`, and the keywords of an editor's own, as `markdownDescription`, taken.\n */\nlet ajv: Ajv2020 | undefined\nconst compiled = new WeakMap<object, ValidateFunction>()\n\nconst compile = (schema: JsonSchema): ValidateFunction => {\n ajv ??= new Ajv2020({ allErrors: true, strict: false, validateFormats: false, logger: false })\n if (typeof schema === 'boolean') return ajv.compile(schema)\n let validate = compiled.get(schema)\n if (validate === undefined) {\n validate = ajv.compile(schema)\n compiled.set(schema, validate)\n }\n return validate\n}\n\n/** The keys of a JSON Pointer, as ajv gives the place of a value: `/compress/threshold`. */\nconst keysOfPointer = (pointer: string): string[] =>\n pointer === ''\n ? []\n : pointer\n .slice(1)\n .split('/')\n .map((key) => key.replaceAll('~1', '/').replaceAll('~0', '~'))\n\n/** What ajv found wrong, as an issue: a key the schema does not take at its own path. */\nconst issueOfAjv = ({ instancePath, keyword, params, message }: ErrorObject): ConfigIssue => {\n const path = keysOfPointer(instancePath)\n const extra: unknown =\n keyword === 'additionalProperties' ? params['additionalProperty'] : undefined\n return typeof extra === 'string'\n ? { path: [...path, extra], message: 'is no key that the section takes' }\n : { path, message: message ?? keyword }\n}\n\n/** The keys of a Standard Schema's path, each as text. */\nconst pathOfStandard = (path: StandardSchemaV1.Issue['path']): ConfigPath =>\n (path ?? []).map((segment) =>\n String(typeof segment === 'object' && segment !== null ? segment.key : segment)\n )\n\n/** What a Standard Schema's result says, as issues. */\nconst checkedOfResult = <T>(result: StandardSchemaV1.Result<T>, value: unknown): Checked<T> =>\n result.issues === undefined\n ? { issues: [], value: result.value }\n : {\n issues: result.issues.map(({ path, message }) => ({ path: pathOfStandard(path), message })),\n value: value as T\n }\n\n/** What ajv finds wrong with `value` by the JSON Schema of `schema`; nothing of a schema that gives\n * none. */\nconst checkedOfJson = <T>(value: unknown, schema: unknown): Checked<T> => {\n const json = jsonSchemaOf(schema)\n if (json === undefined) return { issues: [], value: value as T }\n const validate = compile(json)\n validate(value)\n return { issues: (validate.errors ?? []).map(issueOfAjv), value: value as T }\n}\n\n/**\n * What `schema` finds wrong with `value`, none when it is valid, and the value as it reads it: a\n * Standard Schema's output, or `value` itself. A Standard Schema that validates is asked; a JSON\n * Schema, or a Standard JSON Schema of none, is checked by ajv; a function is called.\n */\nexport async function issuesOf<T>(value: unknown, schema: SectionSchema<T>): Promise<Checked<T>> {\n if (typeof schema === 'function')\n return { issues: await (schema as ValidateSection)(value), value: value as T }\n const standard = validatorOf(schema)\n if (standard !== undefined)\n return checkedOfResult((await standard.validate(value)) as StandardSchemaV1.Result<T>, value)\n return checkedOfJson(value, schema)\n}\n\n/**\n * What `schema` finds wrong with `value`, as {@link issuesOf} checks it, checked synchronously: a\n * schema that answers with a promise is a {@link SyncSchemaError} of the section `section`.\n */\nexport function issuesOfSync<T>(\n value: unknown,\n schema: SectionSchema<T>,\n section: string = 'configuration'\n): Checked<T> {\n if (typeof schema === 'function') {\n const issues = (schema as ValidateSection)(value)\n if (issues instanceof Promise) throw new SyncSchemaError(section)\n return { issues, value: value as T }\n }\n const standard = validatorOf(schema)\n if (standard !== undefined) {\n const result = standard.validate(value)\n if (result instanceof Promise) throw new SyncSchemaError(section)\n return checkedOfResult(result as StandardSchemaV1.Result<T>, value)\n }\n return checkedOfJson(value, schema)\n}\n\n/** Whether `path` is `under` or a path under it. */\nconst isUnder = (path: ConfigPath, under: ConfigPath): boolean =>\n under.every((key, index) => path[index] === key)\n\n/** The section of `name` as the layers give it, before it is checked, and whether any gave one. */\ntype Layered = {\n readonly section: unknown\n readonly given: boolean\n readonly own: boolean\n readonly environment: WithEnvironment\n}\n\n/** The section `name` of the layers of `resolved`, read for placeholders, before it is checked. */\nfunction layeredOf(resolved: ResolvedConfig, name: string, schema: unknown): Layered {\n const own = Object.hasOwn(resolved.config, name)\n const defaults = resolved.defaults?.config\n const layered = defaults !== undefined && Object.hasOwn(defaults, name)\n const filed = mergeSection(layered ? defaults[name] : undefined, resolved.config[name])\n const environment =\n resolved.environment === undefined\n ? { value: filed, set: [] }\n : withEnvironment(\n filed,\n resolved.environment.variables,\n `${resolved.environment.prefix}${envNameOf(name)}_`,\n jsonSchemaOf(schema)\n )\n const given = own || layered || environment.set.length > 0\n // No environment given is one of no variable: each placeholder is refused, never left as text.\n const section = given\n ? expandPlaceholders(\n environment.value,\n [resolved.key, name],\n resolved.environment?.values ?? {}\n )\n : undefined\n return { section, given, own, environment }\n}\n\n/** The error of what a schema found wrong with a section: of the variables that set a value it\n * refuses, else of the project's file, or the defaults', of a section the project gives none of. */\nfunction invalidOf(\n resolved: ResolvedConfig,\n name: string,\n { own, environment }: Layered,\n issues: readonly ConfigIssue[]\n): InvalidSectionError {\n const variables = environment.set.filter(({ path }) =>\n issues.some((issue) => isUnder(issue.path, path))\n )\n if (variables.length > 0)\n return new InvalidSectionError(\n variables.map(({ variable }) => variable).join(', '),\n resolved.namespace,\n name,\n issues.filter((issue) => variables.some(({ path }) => isUnder(issue.path, path))),\n resolved.key\n )\n return own || resolved.defaults === undefined\n ? new InvalidSectionError(\n resolved.source?.path ?? resolved.root,\n resolved.namespace,\n name,\n issues,\n resolved.key\n )\n : new InvalidSectionError(resolved.defaults.path, resolved.namespace, name, issues)\n}\n\n/**\n * The section `name` of the configuration, as its tool reads it: the project's, merged over the\n * section of the `defaults` of the tool's package when it gives some ({@link mergeSection}), with\n * the environment's variables the tool gave `loadConfig` over both, each that names a key of the\n * section or of its schema, as `WTF_VITE_COMPRESS` (`withEnvironment` of ./env); `undefined` when\n * none has one, which the tool takes as its own defaults. Each string in it is then read for\n * placeholders `${env:NAME}`, taken from the whole environment the tool gave (`expandPlaceholders`\n * of ./placeholder); a variable not set, or of no environment given, is an\n * `EnvPlaceholderUnsetError`. Only this, and {@link sectionOfSync}, expand them, so what shows or\n * writes the configuration never holds a secret it points at. With a `schema` it is checked, and\n * what is wrong is an {@link InvalidSectionError}, which names where the value came from and the\n * path of each value, as `wtf.vite.compress`.\n */\nexport async function sectionOf<T = unknown>(\n resolved: ResolvedConfig,\n name: string,\n schema?: SectionSchema<T>\n): Promise<T | undefined> {\n const layered = layeredOf(resolved, name, schema)\n if (!layered.given) return undefined\n if (schema === undefined) return layered.section as T\n const { issues, value } = await issuesOf(layered.section, schema)\n if (issues.length === 0) return value\n throw invalidOf(resolved, name, layered, issues)\n}\n\n/**\n * The section `name` of the configuration, as {@link sectionOf} reads it, checked synchronously,\n * as a tool that reads its config synchronously reads it with `loadConfigSync` of ./load. A schema\n * that checks asynchronously is a {@link SyncSchemaError}.\n */\nexport function sectionOfSync<T = unknown>(\n resolved: ResolvedConfig,\n name: string,\n schema?: SectionSchema<T>\n): T | undefined {\n const layered = layeredOf(resolved, name, schema)\n if (!layered.given) return undefined\n if (schema === undefined) return layered.section as T\n const { issues, value } = issuesOfSync(layered.section, schema, name)\n if (issues.length === 0) return value\n throw invalidOf(resolved, name, layered, issues)\n}\n"]}
1
+ {"version":3,"file":"section.js","sourceRoot":"","sources":["../src/section.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,OAAO,EAA2C,MAAM,kBAAkB,CAAA;AAEnF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAwB,MAAM,UAAU,CAAA;AACzF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AASlE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAMzC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAoC,EAAE,CAClE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAA;AAE7C,4FAA4F;AAC5F,MAAM,WAAW,GAAG,CAAC,MAAe,EAA6C,EAAE;IACjF,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,IAAI,MAAM,CAAC;QAAE,OAAO,SAAS,CAAA;IACjE,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;IACpC,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,OAAO,QAAQ,CAAC,UAAU,CAAC,KAAK,UAAU;QACnE,CAAC,CAAE,QAAqD;QACxD,CAAC,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,CAAA;IACrD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IACrE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrC,MAAM,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAClD,CAAC","sourcesContent":["/**\n * A tool's section of the configuration: {@link sectionOf}, the section of a name, the project's\n * merged over the defaults of the tool's package ({@link mergeSection}), with the environment's\n * variables the tool gives over both, each placeholder `${env:NAME}` in it replaced by the variable\n * it names, and checked by the schema the tool gives; {@link sectionOfSync}, the same, checked\n * synchronously; and {@link issuesOf} and {@link issuesOfSync}, what a schema finds wrong with a\n * value. A schema is a Standard Schema, as each preset's `./schema` exports one, a JSON Schema or a\n * Standard JSON Schema, which ajv checks, or a function. What is wrong is an\n * `InvalidSectionError` of ./errors, which names the file and the path of each value.\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { loadConfig } from '@wtf/project-config/load'\n * import { sectionOf } from '@wtf/project-config/section'\n * import { baseConfig } from '@wtf/project-vite/config'\n * import { viteSchema } from '@wtf/project-vite/schema'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const config = await loadConfig({ platform })\n * export default baseConfig({ platform, ...(await sectionOf(config, 'vite', viteSchema)) })\n * ```\n *\n * @packageDocumentation\n */\nimport type { StandardSchemaV1 } from '@standard-schema/spec'\nimport { Ajv2020, type ErrorObject, type ValidateFunction } from 'ajv/dist/2020.js'\n\nimport { envNameOf, jsonSchemaOf, withEnvironment, type WithEnvironment } from './env.ts'\nimport { InvalidSectionError, SyncSchemaError } from './errors.ts'\nimport type {\n ConfigIssue,\n ConfigPath,\n JsonSchema,\n ResolvedConfig,\n SectionSchema,\n ValidateSection\n} from './index.ts'\nimport { mergeSection } from './merge.ts'\nimport { expandPlaceholders } from './placeholder.ts'\n\nexport { mergeSection } from './merge.ts'\n\n/** What a schema found of a value: what is wrong with it, none when it is valid, and the value as\n * the schema reads it. */\nexport type Checked<T> = { readonly issues: readonly ConfigIssue[]; readonly value: T }\n\nconst isNode = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null\n\n/** Whether `schema` is a Standard Schema that validates: its `~standard` has `validate`. */\nconst validatorOf = (schema: unknown): StandardSchemaV1['~standard'] | undefined => {\n if (!isNode(schema) || !('~standard' in schema)) return undefined\n const standard = schema['~standard']\n return isNode(standard) && typeof standard['validate'] === 'function'\n ? (standard as unknown as StandardSchemaV1['~standard'])\n : undefined\n}\n\n/**\n * The JSON Schemas compiled, by ajv, for draft 2020-12: every fault and not the first, no check\n * of a `format`, and the keywords of an editor's own, as `markdownDescription`, taken.\n */\nlet ajv: Ajv2020 | undefined\nconst compiled = new WeakMap<object, ValidateFunction>()\n\nconst compile = (schema: JsonSchema): ValidateFunction => {\n ajv ??= new Ajv2020({ allErrors: true, strict: false, validateFormats: false, logger: false })\n if (typeof schema === 'boolean') return ajv.compile(schema)\n let validate = compiled.get(schema)\n if (validate === undefined) {\n validate = ajv.compile(schema)\n compiled.set(schema, validate)\n }\n return validate\n}\n\n/** The keys of a JSON Pointer, as ajv gives the place of a value: `/compress/threshold`. */\nconst keysOfPointer = (pointer: string): string[] =>\n pointer === ''\n ? []\n : pointer\n .slice(1)\n .split('/')\n .map((key) => key.replaceAll('~1', '/').replaceAll('~0', '~'))\n\n/** What ajv found wrong, as an issue: a key the schema does not take at its own path. */\nconst issueOfAjv = ({ instancePath, keyword, params, message }: ErrorObject): ConfigIssue => {\n const path = keysOfPointer(instancePath)\n const extra: unknown =\n keyword === 'additionalProperties' ? params['additionalProperty'] : undefined\n return typeof extra === 'string'\n ? { path: [...path, extra], message: 'is no key that the section takes' }\n : { path, message: message ?? keyword }\n}\n\n/** The keys of a Standard Schema's path, each as text. */\nconst pathOfStandard = (path: StandardSchemaV1.Issue['path']): ConfigPath =>\n (path ?? []).map((segment) =>\n String(typeof segment === 'object' && segment !== null ? segment.key : segment)\n )\n\n/** What a Standard Schema's result says, as issues. */\nconst checkedOfResult = <T>(result: StandardSchemaV1.Result<T>, value: unknown): Checked<T> =>\n result.issues === undefined\n ? { issues: [], value: result.value }\n : {\n issues: result.issues.map(({ path, message }) => ({ path: pathOfStandard(path), message })),\n value: value as T\n }\n\n/** What ajv finds wrong with `value` by the JSON Schema of `schema`; nothing of a schema that gives\n * none. */\nconst checkedOfJson = <T>(value: unknown, schema: unknown): Checked<T> => {\n const json = jsonSchemaOf(schema)\n if (json === undefined) return { issues: [], value: value as T }\n const validate = compile(json)\n validate(value)\n return { issues: (validate.errors ?? []).map(issueOfAjv), value: value as T }\n}\n\n/**\n * What `schema` finds wrong with `value`, none when it is valid, and the value as it reads it: a\n * Standard Schema's output, or `value` itself. A Standard Schema that validates is asked; a JSON\n * Schema, or a Standard JSON Schema of none, is checked by ajv; a function is called.\n */\nexport async function issuesOf<T>(value: unknown, schema: SectionSchema<T>): Promise<Checked<T>> {\n if (typeof schema === 'function')\n return { issues: await (schema as ValidateSection)(value), value: value as T }\n const standard = validatorOf(schema)\n if (standard !== undefined)\n return checkedOfResult((await standard.validate(value)) as StandardSchemaV1.Result<T>, value)\n return checkedOfJson(value, schema)\n}\n\n/**\n * What `schema` finds wrong with `value`, as {@link issuesOf} checks it, checked synchronously: a\n * schema that answers with a promise is a {@link SyncSchemaError} of the section `section`.\n */\nexport function issuesOfSync<T>(\n value: unknown,\n schema: SectionSchema<T>,\n section: string = 'configuration'\n): Checked<T> {\n if (typeof schema === 'function') {\n const issues = (schema as ValidateSection)(value)\n if (issues instanceof Promise) throw new SyncSchemaError(section)\n return { issues, value: value as T }\n }\n const standard = validatorOf(schema)\n if (standard !== undefined) {\n const result = standard.validate(value)\n if (result instanceof Promise) throw new SyncSchemaError(section)\n return checkedOfResult(result as StandardSchemaV1.Result<T>, value)\n }\n return checkedOfJson(value, schema)\n}\n\n/** Whether `path` is `under` or a path under it. */\nconst isUnder = (path: ConfigPath, under: ConfigPath): boolean =>\n under.every((key, index) => path[index] === key)\n\n/** The section of `name` as the layers give it, before it is checked, and whether any gave one. */\ntype Layered = {\n readonly section: unknown\n readonly given: boolean\n readonly own: boolean\n readonly environment: WithEnvironment\n}\n\n/** The section `name` of the layers of `resolved`, read for placeholders, before it is checked. */\nfunction layeredOf(resolved: ResolvedConfig, name: string, schema: unknown): Layered {\n const own = Object.hasOwn(resolved.config, name)\n const defaults = resolved.defaults?.config\n const layered = defaults !== undefined && Object.hasOwn(defaults, name)\n const filed = mergeSection(layered ? defaults[name] : undefined, resolved.config[name])\n const environment =\n resolved.environment === undefined\n ? { value: filed, set: [] }\n : withEnvironment(\n filed,\n resolved.environment.variables,\n `${resolved.environment.prefix}${envNameOf(name)}_`,\n jsonSchemaOf(schema)\n )\n const given = own || layered || environment.set.length > 0\n // No environment given is one of no variable: each placeholder is refused, never left as text.\n const section = given\n ? expandPlaceholders(\n environment.value,\n [resolved.key, name],\n resolved.environment?.values ?? {}\n )\n : undefined\n return { section, given, own, environment }\n}\n\n/** The error of what a schema found wrong with a section: of the variables that set a value it\n * refuses, else of the project's file, or the defaults', of a section the project gives none of. */\nfunction invalidOf(\n resolved: ResolvedConfig,\n name: string,\n { own, environment }: Layered,\n issues: readonly ConfigIssue[]\n): InvalidSectionError {\n const variables = environment.set.filter(({ path }) =>\n issues.some((issue) => isUnder(issue.path, path))\n )\n if (variables.length > 0)\n return new InvalidSectionError(\n variables.map(({ variable }) => variable).join(', '),\n resolved.namespace,\n name,\n issues.filter((issue) => variables.some(({ path }) => isUnder(issue.path, path))),\n resolved.key\n )\n return own || resolved.defaults === undefined\n ? new InvalidSectionError(\n resolved.source?.path ?? resolved.root,\n resolved.namespace,\n name,\n issues,\n resolved.key\n )\n : new InvalidSectionError(resolved.defaults.path, resolved.namespace, name, issues)\n}\n\n/**\n * The section `name` of the configuration, as its tool reads it: the project's, merged over the\n * section of the `defaults` of the tool's package when it gives some ({@link mergeSection}), with\n * the variables of the environment of the platform the tool gave `loadConfig` over both, each that\n * names a key of the section or of its schema, as `WTF_VITE_COMPRESS` (`withEnvironment` of\n * ./env); `undefined` when none has one, which the tool takes as its own defaults. Each string in it is then read for\n * placeholders `${env:NAME}`, taken from that whole environment (`expandPlaceholders` of\n * ./placeholder); a variable not set, or of a configuration read of no environment, is an\n * `EnvPlaceholderUnsetError`. Only this, and {@link sectionOfSync}, expand them, so what shows or\n * writes the configuration never holds a secret it points at. With a `schema` it is checked, and\n * what is wrong is an {@link InvalidSectionError}, which names where the value came from and the\n * path of each value, as `wtf.vite.compress`.\n */\nexport async function sectionOf<T = unknown>(\n resolved: ResolvedConfig,\n name: string,\n schema?: SectionSchema<T>\n): Promise<T | undefined> {\n const layered = layeredOf(resolved, name, schema)\n if (!layered.given) return undefined\n if (schema === undefined) return layered.section as T\n const { issues, value } = await issuesOf(layered.section, schema)\n if (issues.length === 0) return value\n throw invalidOf(resolved, name, layered, issues)\n}\n\n/**\n * The section `name` of the configuration, as {@link sectionOf} reads it, checked synchronously,\n * as a tool that reads its config synchronously reads it with `loadConfigSync` of ./load. A schema\n * that checks asynchronously is a {@link SyncSchemaError}.\n */\nexport function sectionOfSync<T = unknown>(\n resolved: ResolvedConfig,\n name: string,\n schema?: SectionSchema<T>\n): T | undefined {\n const layered = layeredOf(resolved, name, schema)\n if (!layered.given) return undefined\n if (schema === undefined) return layered.section as T\n const { issues, value } = issuesOfSync(layered.section, schema, name)\n if (issues.length === 0) return value\n throw invalidOf(resolved, name, layered, issues)\n}\n"]}
package/dist/write.js CHANGED
@@ -9,12 +9,13 @@
9
9
  * platform it is given.
10
10
  *
11
11
  * ```ts
12
- * import { nodeConfigPlatform } from '@wtf/project-config/node'
12
+ * import { nodeStorage } from '@wtf/platform-fs-node/storage'
13
+ * import { nodePlatform } from '@wtf/platform-node/platform'
14
+ *
13
15
  * import { setConfigValue } from '@wtf/project-config/write'
14
16
  *
15
- * await setConfigValue(process.cwd(), ['vite', 'compress'], false, {
16
- * platform: nodeConfigPlatform()
17
- * })
17
+ * const platform = nodePlatform({ fetch, storage: nodeStorage() })
18
+ * await setConfigValue(platform.dirs.cwd, ['vite', 'compress'], false, { platform })
18
19
  * ```
19
20
  *
20
21
  * @packageDocumentation