@reelout/config 0.7.2 → 0.8.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/index.js +67 -4
- package/dist/index.js.map +1 -1
- package/package.json +18 -8
- package/src/index.ts +1 -0
- package/src/resolveConfig.ts +10 -2
- package/src/validateUserConfig.ts +117 -0
package/dist/index.js
CHANGED
|
@@ -106,20 +106,83 @@ async function normalizeConfig(cwd, config) {
|
|
|
106
106
|
plugins
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
+
// src/validateUserConfig.ts
|
|
110
|
+
/**
|
|
111
|
+
* Describe the runtime type of a configuration value for error messages.
|
|
112
|
+
*
|
|
113
|
+
* @param value Configuration value to describe
|
|
114
|
+
* @returns The human-readable type name
|
|
115
|
+
*/
|
|
116
|
+
var describeValueType = (value) => {
|
|
117
|
+
if (value === null) return "null";
|
|
118
|
+
if (Array.isArray(value)) return "array";
|
|
119
|
+
return typeof value;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Throw a subject-first error for an invalid configuration value.
|
|
123
|
+
*
|
|
124
|
+
* @param filepath Path of the configuration file being validated
|
|
125
|
+
* @param key Dotted path of the invalid value
|
|
126
|
+
* @param expected Description of the expected shape
|
|
127
|
+
* @param received The invalid value
|
|
128
|
+
*/
|
|
129
|
+
function fail(filepath, key, expected, received) {
|
|
130
|
+
throw new Error(`Configuration file "${filepath}" contains an invalid "${key}" value: expected ${expected}, received ${describeValueType(received)}.`);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Validate the raw shape of a user-provided release configuration.
|
|
134
|
+
*
|
|
135
|
+
* Rejects values whose shape ReelOut cannot consume meaningfully — such as a
|
|
136
|
+
* non-array `rules`, a `classifier` that is neither an object nor a
|
|
137
|
+
* function, or a non-object `author` — with a subject-first error naming
|
|
138
|
+
* the configuration file and the offending key. Absent values fall back to
|
|
139
|
+
* defaults and stay valid; `author` fields that are `null` keep their
|
|
140
|
+
* documented fallback to the default author.
|
|
141
|
+
*
|
|
142
|
+
* @param config User-provided configuration value read by cosmiconfig
|
|
143
|
+
* @param filepath Path of the configuration file the value came from
|
|
144
|
+
* @throws If a present configuration value has an invalid shape
|
|
145
|
+
*/
|
|
146
|
+
function validateUserConfig(config, filepath) {
|
|
147
|
+
if (config === null || config === void 0) return;
|
|
148
|
+
if (typeof config !== "object" || Array.isArray(config)) fail(filepath, "configuration", "an object", config);
|
|
149
|
+
const record = config;
|
|
150
|
+
const author = record.author;
|
|
151
|
+
if (author !== void 0) {
|
|
152
|
+
if (typeof author !== "object" || author === null || Array.isArray(author)) fail(filepath, "author", "an object", author);
|
|
153
|
+
const { name, email } = author;
|
|
154
|
+
if (name !== void 0 && name !== null && typeof name !== "string") fail(filepath, "author.name", "a string", name);
|
|
155
|
+
if (email !== void 0 && email !== null && typeof email !== "string") fail(filepath, "author.email", "a string", email);
|
|
156
|
+
}
|
|
157
|
+
const classifier = record.classifier;
|
|
158
|
+
if (classifier !== void 0 && typeof classifier !== "function") {
|
|
159
|
+
if (typeof classifier !== "object" || classifier === null || Array.isArray(classifier)) fail(filepath, "classifier", "an object or function", classifier);
|
|
160
|
+
for (const [key, value] of Object.entries(classifier)) if (!Array.isArray(value)) fail(filepath, `classifier.${key}`, "an array", value);
|
|
161
|
+
}
|
|
162
|
+
const rules = record.rules;
|
|
163
|
+
if (rules !== void 0 && !Array.isArray(rules)) fail(filepath, "rules", "an array", rules);
|
|
164
|
+
const plugins = record.plugins;
|
|
165
|
+
if (plugins !== void 0 && !Array.isArray(plugins)) fail(filepath, "plugins", "an array", plugins);
|
|
166
|
+
}
|
|
109
167
|
// src/resolveConfig.ts
|
|
110
168
|
/**
|
|
111
169
|
* Resolve and normalize a release configuration for a target directory.
|
|
112
170
|
*
|
|
113
|
-
* Searches for configuration files using `cosmiconfig`,
|
|
114
|
-
*
|
|
171
|
+
* Searches for configuration files using `cosmiconfig`, validates the raw
|
|
172
|
+
* shape of the discovered settings, merges them with default configurations,
|
|
173
|
+
* and normalizes the resulting structure.
|
|
115
174
|
*
|
|
116
175
|
* @param cwd Working directory path to search from
|
|
117
176
|
* @param name Module name used for configuration file discovery
|
|
118
177
|
* @returns Resolved and normalized release configuration
|
|
178
|
+
* @throws If a discovered configuration value has an invalid shape, or a
|
|
179
|
+
* configured plugin cannot be resolved
|
|
119
180
|
*/
|
|
120
181
|
async function resolveConfig(cwd, name = "reelout") {
|
|
121
|
-
|
|
182
|
+
const result = await cosmiconfig(name).search(cwd);
|
|
183
|
+
if (result?.config !== void 0) validateUserConfig(result.config, result.filepath);
|
|
184
|
+
return normalizeConfig(cwd, mergeConfig(defaultConfig, result?.config));
|
|
122
185
|
}
|
|
123
|
-
export { defaultConfig, mergeConfig, normalizeConfig, resolveConfig };
|
|
186
|
+
export { defaultConfig, mergeConfig, normalizeConfig, resolveConfig, validateUserConfig };
|
|
124
187
|
|
|
125
188
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/defaultConfig.ts","../src/mergeConfig.ts","../src/normalizeConfig.ts","../src/resolveConfig.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleaseConfig } from '@reelout/core'\n\n/**\n * Default release configuration used when no user config is provided.\n *\n * Includes defaults for user identity, workspace layout, release rules,\n * commit-to-release mappings, and built-in plugins.\n */\nexport const defaultConfig = Object.freeze({\n author: {\n name: 'github-actions[bot]',\n email: '41898282+github-actions[bot]@users.noreply.github.com',\n },\n classifier: {\n major: [],\n minor: ['feat'],\n patch: ['fix', 'perf', 'revert'],\n },\n rules: [\n { type: 'branch', pattern: 'alpha', qualifier: 'alpha', channel: 'alpha' },\n { type: 'branch', pattern: 'beta', qualifier: 'beta', channel: 'beta' },\n { type: 'branch', pattern: 'next', qualifier: 'next', channel: 'next' },\n ],\n plugins: [\n '@reelout/core/analyzer', // Analyze the commits and determine the release type.\n '@reelout/core/builder', // Build the release artifacts.\n '@reelout/core/changelog', // Generate and write changelog entries for each release.\n '@reelout/npm', // Update package manifests and publish packages to npm.\n '@reelout/cargo', // Update crate manifests and publish crates to crates.io.\n '@reelout/git', // Create release commits and tags, then push them.\n '@reelout/github', // Create GitHub releases from finalized plans.\n '@reelout/gitlab', // Create GitLab releases from finalized plans.\n ],\n} satisfies Required<ReleaseConfig>)\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { assignWith } from 'lodash-es'\n\n/**\n * Merge a user configuration into the defaults, preserving unspecified keys.\n *\n * Uses `lodash.assignWith` to avoid overwriting default values with\n * `undefined` from the user configuration.\n *\n * @param defaultConfig Default configuration object\n * @param userConfig Partial user-provided configuration\n * @returns Merged configuration object\n */\nexport function mergeConfig<T>(\n defaultConfig: T,\n userConfig: Partial<T> | null | undefined\n): T {\n return assignWith({}, defaultConfig, userConfig, (objValue, srcValue) => {\n if (srcValue === undefined) {\n return objValue\n }\n })\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport {\n compact,\n normalizeCommitFilter,\n normalizeReleaseRule,\n resolvePlugin,\n type GitAuthor,\n type ReleaseConfig,\n type ResolvedReleaseConfig,\n} from '@reelout/core'\nimport { defaultConfig } from './defaultConfig'\n\n/**\n * Normalize and resolve a release configuration.\n *\n * Applies default author settings when incomplete, normalizes commit filters\n * and release rules, and loads specified plugins.\n *\n * @param cwd Working directory path used for plugin resolution\n * @param config User-supplied release configuration\n * @returns Resolved and normalized release configuration\n * @throws If a configured plugin cannot be resolved\n */\nexport async function normalizeConfig(\n cwd: string,\n config: Required<ReleaseConfig>\n): Promise<ResolvedReleaseConfig> {\n const author: GitAuthor =\n config.author.name && config.author.email\n ? { name: config.author.name, email: config.author.email }\n : { ...defaultConfig.author }\n\n const classifier = normalizeCommitFilter(config.classifier)\n\n const rules = compact(config.rules.map((rule) => normalizeReleaseRule(rule)))\n\n const plugins = compact(\n await Promise.all(\n config.plugins.map(async (plugin) => {\n try {\n return await resolvePlugin(cwd, plugin)\n } catch (err) {\n try {\n return await resolvePlugin(import.meta.filename, plugin)\n } catch {}\n\n throw err\n }\n })\n )\n )\n\n return {\n ...config,\n author,\n classifier,\n rules,\n plugins,\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleaseConfig, ResolvedReleaseConfig } from '@reelout/core'\nimport { cosmiconfig } from 'cosmiconfig'\nimport { defaultConfig } from './defaultConfig'\nimport { mergeConfig } from './mergeConfig'\nimport { normalizeConfig } from './normalizeConfig'\n\n/**\n * Resolve and normalize a release configuration for a target directory.\n *\n * Searches for configuration files using `cosmiconfig`, merges discovered user\n * settings with default configurations, and normalizes the resulting structure.\n *\n * @param cwd Working directory path to search from\n * @param name Module name used for configuration file discovery\n * @returns Resolved and normalized release configuration\n */\nexport async function resolveConfig(\n cwd: string,\n name = 'reelout'\n): Promise<ResolvedReleaseConfig> {\n const explorer = cosmiconfig(name)\n\n const result = await explorer.search(cwd)\n\n const config = mergeConfig<Required<ReleaseConfig>>(\n defaultConfig,\n result?.config\n )\n\n return normalizeConfig(cwd, config)\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAa,gBAAgB,OAAO,OAAO;CACzC,QAAQ;EACN,MAAM;EACN,OAAO;CACT;CACA,YAAY;EACV,OAAO,CAAC;EACR,OAAO,CAAC,MAAM;EACd,OAAO;GAAC;GAAO;GAAQ;EAAQ;CACjC;CACA,OAAO;EACL;GAAE,MAAM;GAAU,SAAS;GAAS,WAAW;GAAS,SAAS;EAAQ;EACzE;GAAE,MAAM;GAAU,SAAS;GAAQ,WAAW;GAAQ,SAAS;EAAO;EACtE;GAAE,MAAM;GAAU,SAAS;GAAQ,WAAW;GAAQ,SAAS;EAAO;CACxE;CACA,SAAS;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF,CAAmC;;;;;;;;;;;;ACrBnC,SAAgB,YACd,eACA,YACG;CACH,OAAO,WAAW,CAAC,GAAG,eAAe,aAAa,UAAU,aAAa;EACvE,IAAI,aAAa,KAAA,GACf,OAAO;CAEX,CAAC;AACH;;;;;;;;;;;;;ACCA,eAAsB,gBACpB,KACA,QACgC;CAChC,MAAM,SACJ,OAAO,OAAO,QAAQ,OAAO,OAAO,QAChC;EAAE,MAAM,OAAO,OAAO;EAAM,OAAO,OAAO,OAAO;CAAM,IACvD,EAAE,GAAG,cAAc,OAAO;CAEhC,MAAM,aAAa,sBAAsB,OAAO,UAAU;CAE1D,MAAM,QAAQ,QAAQ,OAAO,MAAM,KAAK,SAAS,qBAAqB,IAAI,CAAC,CAAC;CAE5E,MAAM,UAAU,QACd,MAAM,QAAQ,IACZ,OAAO,QAAQ,IAAI,OAAO,WAAW;EACnC,IAAI;GACF,OAAO,MAAM,cAAc,KAAK,MAAM;EACxC,SAAS,KAAK;GACZ,IAAI;IACF,OAAO,MAAM,cAAc,YAAY,UAAU,MAAM;GACzD,QAAQ,CAAC;GAET,MAAM;EACR;CACF,CAAC,CACH,CACF;CAEA,OAAO;EACL,GAAG;EACH;EACA;EACA;EACA;CACF;AACF;;;;;;;;;;;;AC1CA,eAAsB,cACpB,KACA,OAAO,WACyB;CAUhC,OAAO,gBAAgB,KALR,YACb,gBACA,MANe,YAAY,IAER,CAAA,CAAS,OAAO,GAAG,EAItC,EAAQ,MAGkB,CAAM;AACpC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/defaultConfig.ts","../src/mergeConfig.ts","../src/normalizeConfig.ts","../src/validateUserConfig.ts","../src/resolveConfig.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleaseConfig } from '@reelout/core'\n\n/**\n * Default release configuration used when no user config is provided.\n *\n * Includes defaults for user identity, workspace layout, release rules,\n * commit-to-release mappings, and built-in plugins.\n */\nexport const defaultConfig = Object.freeze({\n author: {\n name: 'github-actions[bot]',\n email: '41898282+github-actions[bot]@users.noreply.github.com',\n },\n classifier: {\n major: [],\n minor: ['feat'],\n patch: ['fix', 'perf', 'revert'],\n },\n rules: [\n { type: 'branch', pattern: 'alpha', qualifier: 'alpha', channel: 'alpha' },\n { type: 'branch', pattern: 'beta', qualifier: 'beta', channel: 'beta' },\n { type: 'branch', pattern: 'next', qualifier: 'next', channel: 'next' },\n ],\n plugins: [\n '@reelout/core/analyzer', // Analyze the commits and determine the release type.\n '@reelout/core/builder', // Build the release artifacts.\n '@reelout/core/changelog', // Generate and write changelog entries for each release.\n '@reelout/npm', // Update package manifests and publish packages to npm.\n '@reelout/cargo', // Update crate manifests and publish crates to crates.io.\n '@reelout/git', // Create release commits and tags, then push them.\n '@reelout/github', // Create GitHub releases from finalized plans.\n '@reelout/gitlab', // Create GitLab releases from finalized plans.\n ],\n} satisfies Required<ReleaseConfig>)\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { assignWith } from 'lodash-es'\n\n/**\n * Merge a user configuration into the defaults, preserving unspecified keys.\n *\n * Uses `lodash.assignWith` to avoid overwriting default values with\n * `undefined` from the user configuration.\n *\n * @param defaultConfig Default configuration object\n * @param userConfig Partial user-provided configuration\n * @returns Merged configuration object\n */\nexport function mergeConfig<T>(\n defaultConfig: T,\n userConfig: Partial<T> | null | undefined\n): T {\n return assignWith({}, defaultConfig, userConfig, (objValue, srcValue) => {\n if (srcValue === undefined) {\n return objValue\n }\n })\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport {\n compact,\n normalizeCommitFilter,\n normalizeReleaseRule,\n resolvePlugin,\n type GitAuthor,\n type ReleaseConfig,\n type ResolvedReleaseConfig,\n} from '@reelout/core'\nimport { defaultConfig } from './defaultConfig'\n\n/**\n * Normalize and resolve a release configuration.\n *\n * Applies default author settings when incomplete, normalizes commit filters\n * and release rules, and loads specified plugins.\n *\n * @param cwd Working directory path used for plugin resolution\n * @param config User-supplied release configuration\n * @returns Resolved and normalized release configuration\n * @throws If a configured plugin cannot be resolved\n */\nexport async function normalizeConfig(\n cwd: string,\n config: Required<ReleaseConfig>\n): Promise<ResolvedReleaseConfig> {\n const author: GitAuthor =\n config.author.name && config.author.email\n ? { name: config.author.name, email: config.author.email }\n : { ...defaultConfig.author }\n\n const classifier = normalizeCommitFilter(config.classifier)\n\n const rules = compact(config.rules.map((rule) => normalizeReleaseRule(rule)))\n\n const plugins = compact(\n await Promise.all(\n config.plugins.map(async (plugin) => {\n try {\n return await resolvePlugin(cwd, plugin)\n } catch (err) {\n try {\n return await resolvePlugin(import.meta.filename, plugin)\n } catch {}\n\n throw err\n }\n })\n )\n )\n\n return {\n ...config,\n author,\n classifier,\n rules,\n plugins,\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\n/**\n * Describe the runtime type of a configuration value for error messages.\n *\n * @param value Configuration value to describe\n * @returns The human-readable type name\n */\nconst describeValueType = (value: unknown): string => {\n if (value === null) {\n return 'null'\n }\n\n if (Array.isArray(value)) {\n return 'array'\n }\n\n return typeof value\n}\n\n/**\n * Throw a subject-first error for an invalid configuration value.\n *\n * @param filepath Path of the configuration file being validated\n * @param key Dotted path of the invalid value\n * @param expected Description of the expected shape\n * @param received The invalid value\n */\nfunction fail(\n filepath: string,\n key: string,\n expected: string,\n received: unknown\n): never {\n throw new Error(\n `Configuration file \"${filepath}\" contains an invalid \"${key}\" value: expected ${expected}, received ${describeValueType(received)}.`\n )\n}\n\n/**\n * Validate the raw shape of a user-provided release configuration.\n *\n * Rejects values whose shape ReelOut cannot consume meaningfully — such as a\n * non-array `rules`, a `classifier` that is neither an object nor a\n * function, or a non-object `author` — with a subject-first error naming\n * the configuration file and the offending key. Absent values fall back to\n * defaults and stay valid; `author` fields that are `null` keep their\n * documented fallback to the default author.\n *\n * @param config User-provided configuration value read by cosmiconfig\n * @param filepath Path of the configuration file the value came from\n * @throws If a present configuration value has an invalid shape\n */\nexport function validateUserConfig(config: unknown, filepath: string): void {\n if (config === null || config === undefined) {\n return\n }\n\n if (typeof config !== 'object' || Array.isArray(config)) {\n fail(filepath, 'configuration', 'an object', config)\n }\n\n const record = config as Record<string, unknown>\n\n const author = record.author\n\n if (author !== undefined) {\n if (\n typeof author !== 'object' ||\n author === null ||\n Array.isArray(author)\n ) {\n fail(filepath, 'author', 'an object', author)\n }\n\n const { name, email } = author as Record<string, unknown>\n\n if (name !== undefined && name !== null && typeof name !== 'string') {\n fail(filepath, 'author.name', 'a string', name)\n }\n\n if (email !== undefined && email !== null && typeof email !== 'string') {\n fail(filepath, 'author.email', 'a string', email)\n }\n }\n\n const classifier = record.classifier\n\n if (classifier !== undefined && typeof classifier !== 'function') {\n if (\n typeof classifier !== 'object' ||\n classifier === null ||\n Array.isArray(classifier)\n ) {\n fail(filepath, 'classifier', 'an object or function', classifier)\n }\n\n for (const [key, value] of Object.entries(classifier)) {\n if (!Array.isArray(value)) {\n fail(filepath, `classifier.${key}`, 'an array', value)\n }\n }\n }\n\n const rules = record.rules\n\n if (rules !== undefined && !Array.isArray(rules)) {\n fail(filepath, 'rules', 'an array', rules)\n }\n\n const plugins = record.plugins\n\n if (plugins !== undefined && !Array.isArray(plugins)) {\n fail(filepath, 'plugins', 'an array', plugins)\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleaseConfig, ResolvedReleaseConfig } from '@reelout/core'\nimport { cosmiconfig } from 'cosmiconfig'\nimport { defaultConfig } from './defaultConfig'\nimport { mergeConfig } from './mergeConfig'\nimport { normalizeConfig } from './normalizeConfig'\nimport { validateUserConfig } from './validateUserConfig'\n\n/**\n * Resolve and normalize a release configuration for a target directory.\n *\n * Searches for configuration files using `cosmiconfig`, validates the raw\n * shape of the discovered settings, merges them with default configurations,\n * and normalizes the resulting structure.\n *\n * @param cwd Working directory path to search from\n * @param name Module name used for configuration file discovery\n * @returns Resolved and normalized release configuration\n * @throws If a discovered configuration value has an invalid shape, or a\n * configured plugin cannot be resolved\n */\nexport async function resolveConfig(\n cwd: string,\n name = 'reelout'\n): Promise<ResolvedReleaseConfig> {\n const explorer = cosmiconfig(name)\n\n const result = await explorer.search(cwd)\n\n if (result?.config !== undefined) {\n validateUserConfig(result.config, result.filepath)\n }\n\n const config = mergeConfig<Required<ReleaseConfig>>(\n defaultConfig,\n result?.config\n )\n\n return normalizeConfig(cwd, config)\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reelout/config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Discovers, merges, and normalizes ReelOut configuration, including plugin registrations.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"release",
|
|
7
|
+
"versioning",
|
|
8
|
+
"monorepo",
|
|
9
|
+
"configuration",
|
|
10
|
+
"plugin"
|
|
11
|
+
],
|
|
5
12
|
"repository": {
|
|
6
13
|
"type": "git",
|
|
7
14
|
"url": "git+https://github.com/reelout/reelout.git",
|
|
8
15
|
"directory": "packages/config"
|
|
9
16
|
},
|
|
10
17
|
"license": "MIT",
|
|
18
|
+
"sideEffects": false,
|
|
11
19
|
"type": "module",
|
|
12
|
-
"imports": {},
|
|
13
20
|
"exports": {
|
|
14
21
|
"./package.json": {
|
|
15
22
|
"default": "./package.json"
|
|
@@ -32,12 +39,12 @@
|
|
|
32
39
|
"./src"
|
|
33
40
|
],
|
|
34
41
|
"dependencies": {
|
|
35
|
-
"@reelout/cargo": "^0.
|
|
36
|
-
"@reelout/core": "^0.
|
|
37
|
-
"@reelout/git": "^0.
|
|
38
|
-
"@reelout/github": "^0.
|
|
39
|
-
"@reelout/gitlab": "^0.
|
|
40
|
-
"@reelout/npm": "^0.
|
|
42
|
+
"@reelout/cargo": "^0.4.0",
|
|
43
|
+
"@reelout/core": "^0.14.0",
|
|
44
|
+
"@reelout/git": "^0.10.0",
|
|
45
|
+
"@reelout/github": "^0.9.0",
|
|
46
|
+
"@reelout/gitlab": "^0.9.0",
|
|
47
|
+
"@reelout/npm": "^0.15.0",
|
|
41
48
|
"cosmiconfig": "^10.0.1",
|
|
42
49
|
"lodash-es": "^4.18.1"
|
|
43
50
|
},
|
|
@@ -47,6 +54,9 @@
|
|
|
47
54
|
"engines": {
|
|
48
55
|
"node": ">=24.15"
|
|
49
56
|
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
50
60
|
"scripts": {
|
|
51
61
|
"build": "vite build --ssr --sourcemap",
|
|
52
62
|
"dev": "vite build --ssr --watch"
|
package/src/index.ts
CHANGED
package/src/resolveConfig.ts
CHANGED
|
@@ -6,16 +6,20 @@ import { cosmiconfig } from 'cosmiconfig'
|
|
|
6
6
|
import { defaultConfig } from './defaultConfig'
|
|
7
7
|
import { mergeConfig } from './mergeConfig'
|
|
8
8
|
import { normalizeConfig } from './normalizeConfig'
|
|
9
|
+
import { validateUserConfig } from './validateUserConfig'
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Resolve and normalize a release configuration for a target directory.
|
|
12
13
|
*
|
|
13
|
-
* Searches for configuration files using `cosmiconfig`,
|
|
14
|
-
*
|
|
14
|
+
* Searches for configuration files using `cosmiconfig`, validates the raw
|
|
15
|
+
* shape of the discovered settings, merges them with default configurations,
|
|
16
|
+
* and normalizes the resulting structure.
|
|
15
17
|
*
|
|
16
18
|
* @param cwd Working directory path to search from
|
|
17
19
|
* @param name Module name used for configuration file discovery
|
|
18
20
|
* @returns Resolved and normalized release configuration
|
|
21
|
+
* @throws If a discovered configuration value has an invalid shape, or a
|
|
22
|
+
* configured plugin cannot be resolved
|
|
19
23
|
*/
|
|
20
24
|
export async function resolveConfig(
|
|
21
25
|
cwd: string,
|
|
@@ -25,6 +29,10 @@ export async function resolveConfig(
|
|
|
25
29
|
|
|
26
30
|
const result = await explorer.search(cwd)
|
|
27
31
|
|
|
32
|
+
if (result?.config !== undefined) {
|
|
33
|
+
validateUserConfig(result.config, result.filepath)
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
const config = mergeConfig<Required<ReleaseConfig>>(
|
|
29
37
|
defaultConfig,
|
|
30
38
|
result?.config
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 Fai
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Describe the runtime type of a configuration value for error messages.
|
|
6
|
+
*
|
|
7
|
+
* @param value Configuration value to describe
|
|
8
|
+
* @returns The human-readable type name
|
|
9
|
+
*/
|
|
10
|
+
const describeValueType = (value: unknown): string => {
|
|
11
|
+
if (value === null) {
|
|
12
|
+
return 'null'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
return 'array'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return typeof value
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Throw a subject-first error for an invalid configuration value.
|
|
24
|
+
*
|
|
25
|
+
* @param filepath Path of the configuration file being validated
|
|
26
|
+
* @param key Dotted path of the invalid value
|
|
27
|
+
* @param expected Description of the expected shape
|
|
28
|
+
* @param received The invalid value
|
|
29
|
+
*/
|
|
30
|
+
function fail(
|
|
31
|
+
filepath: string,
|
|
32
|
+
key: string,
|
|
33
|
+
expected: string,
|
|
34
|
+
received: unknown
|
|
35
|
+
): never {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Configuration file "${filepath}" contains an invalid "${key}" value: expected ${expected}, received ${describeValueType(received)}.`
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Validate the raw shape of a user-provided release configuration.
|
|
43
|
+
*
|
|
44
|
+
* Rejects values whose shape ReelOut cannot consume meaningfully — such as a
|
|
45
|
+
* non-array `rules`, a `classifier` that is neither an object nor a
|
|
46
|
+
* function, or a non-object `author` — with a subject-first error naming
|
|
47
|
+
* the configuration file and the offending key. Absent values fall back to
|
|
48
|
+
* defaults and stay valid; `author` fields that are `null` keep their
|
|
49
|
+
* documented fallback to the default author.
|
|
50
|
+
*
|
|
51
|
+
* @param config User-provided configuration value read by cosmiconfig
|
|
52
|
+
* @param filepath Path of the configuration file the value came from
|
|
53
|
+
* @throws If a present configuration value has an invalid shape
|
|
54
|
+
*/
|
|
55
|
+
export function validateUserConfig(config: unknown, filepath: string): void {
|
|
56
|
+
if (config === null || config === undefined) {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (typeof config !== 'object' || Array.isArray(config)) {
|
|
61
|
+
fail(filepath, 'configuration', 'an object', config)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const record = config as Record<string, unknown>
|
|
65
|
+
|
|
66
|
+
const author = record.author
|
|
67
|
+
|
|
68
|
+
if (author !== undefined) {
|
|
69
|
+
if (
|
|
70
|
+
typeof author !== 'object' ||
|
|
71
|
+
author === null ||
|
|
72
|
+
Array.isArray(author)
|
|
73
|
+
) {
|
|
74
|
+
fail(filepath, 'author', 'an object', author)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const { name, email } = author as Record<string, unknown>
|
|
78
|
+
|
|
79
|
+
if (name !== undefined && name !== null && typeof name !== 'string') {
|
|
80
|
+
fail(filepath, 'author.name', 'a string', name)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (email !== undefined && email !== null && typeof email !== 'string') {
|
|
84
|
+
fail(filepath, 'author.email', 'a string', email)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const classifier = record.classifier
|
|
89
|
+
|
|
90
|
+
if (classifier !== undefined && typeof classifier !== 'function') {
|
|
91
|
+
if (
|
|
92
|
+
typeof classifier !== 'object' ||
|
|
93
|
+
classifier === null ||
|
|
94
|
+
Array.isArray(classifier)
|
|
95
|
+
) {
|
|
96
|
+
fail(filepath, 'classifier', 'an object or function', classifier)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (const [key, value] of Object.entries(classifier)) {
|
|
100
|
+
if (!Array.isArray(value)) {
|
|
101
|
+
fail(filepath, `classifier.${key}`, 'an array', value)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const rules = record.rules
|
|
107
|
+
|
|
108
|
+
if (rules !== undefined && !Array.isArray(rules)) {
|
|
109
|
+
fail(filepath, 'rules', 'an array', rules)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const plugins = record.plugins
|
|
113
|
+
|
|
114
|
+
if (plugins !== undefined && !Array.isArray(plugins)) {
|
|
115
|
+
fail(filepath, 'plugins', 'an array', plugins)
|
|
116
|
+
}
|
|
117
|
+
}
|