@commitlint/load
Advanced tools
Comparing version 14.1.0 to 15.0.0
@@ -6,2 +6,18 @@ # Change Log | ||
# [15.0.0](https://github.com/conventional-changelog/commitlint/compare/v14.2.0...v15.0.0) (2021-11-17) | ||
### Bug Fixes | ||
* **types:** fix signature of QualifiedRuleConfig for async configurations ([#2868](https://github.com/conventional-changelog/commitlint/issues/2868)) ([#2869](https://github.com/conventional-changelog/commitlint/issues/2869)) ([c7f355b](https://github.com/conventional-changelog/commitlint/commit/c7f355b25e5baddab0b9559892f5ce4112e4f93a)) | ||
### Features | ||
* simplify config resolution ([#2398](https://github.com/conventional-changelog/commitlint/issues/2398)) ([8a8384f](https://github.com/conventional-changelog/commitlint/commit/8a8384f3c18954447cb633e76a573e1db71a1440)), closes [#327](https://github.com/conventional-changelog/commitlint/issues/327) | ||
# [14.1.0](https://github.com/conventional-changelog/commitlint/compare/v14.0.0...v14.1.0) (2021-11-01) | ||
@@ -8,0 +24,0 @@ |
@@ -10,5 +10,3 @@ "use strict"; | ||
const merge_1 = __importDefault(require("lodash/merge")); | ||
const mergeWith_1 = __importDefault(require("lodash/mergeWith")); | ||
const pick_1 = __importDefault(require("lodash/pick")); | ||
const union_1 = __importDefault(require("lodash/union")); | ||
const uniq_1 = __importDefault(require("lodash/uniq")); | ||
const path_1 = __importDefault(require("path")); | ||
@@ -20,3 +18,2 @@ const resolve_from_1 = __importDefault(require("resolve-from")); | ||
const pick_config_1 = require("./utils/pick-config"); | ||
const w = (_, b) => Array.isArray(b) ? b : undefined; | ||
async function load(seed = {}, options = {}) { | ||
@@ -29,4 +26,7 @@ const cwd = typeof options.cwd === 'undefined' ? process.cwd() : options.cwd; | ||
// Merge passed config with file based options | ||
const config = (0, pick_config_1.pickConfig)((0, merge_1.default)({}, loaded ? loaded.config : null, seed)); | ||
const opts = (0, merge_1.default)({ extends: [], rules: {}, formatter: '@commitlint/format' }, (0, pick_1.default)(config, 'extends', 'plugins', 'ignores', 'defaultIgnores')); | ||
const config = (0, pick_config_1.pickConfig)((0, merge_1.default)({ | ||
extends: [], | ||
plugins: [], | ||
rules: {}, | ||
}, loaded ? loaded.config : null, seed)); | ||
// Resolve parserPreset key | ||
@@ -42,3 +42,3 @@ if (typeof config.parserPreset === 'string') { | ||
// Resolve extends key | ||
const extended = (0, resolve_extends_1.default)(opts, { | ||
const extended = (0, resolve_extends_1.default)(config, { | ||
prefix: 'commitlint-config', | ||
@@ -48,34 +48,18 @@ cwd: base, | ||
}); | ||
const preset = (0, pick_config_1.pickConfig)((0, mergeWith_1.default)(extended, config, w)); | ||
preset.plugins = {}; | ||
// TODO: check if this is still necessary with the new factory based conventional changelog parsers | ||
// config.extends = Array.isArray(config.extends) ? config.extends : []; | ||
// Resolve parser-opts from preset | ||
if (typeof preset.parserPreset === 'object') { | ||
preset.parserPreset.parserOpts = await (0, load_parser_opts_1.loadParserOpts)(preset.parserPreset.name, | ||
// TODO: fix the types for factory based conventional changelog parsers | ||
preset.parserPreset); | ||
if (!extended.formatter || typeof extended.formatter !== 'string') { | ||
extended.formatter = '@commitlint/format'; | ||
} | ||
// Resolve config-relative formatter module | ||
if (typeof config.formatter === 'string') { | ||
preset.formatter = | ||
resolve_from_1.default.silent(base, config.formatter) || config.formatter; | ||
} | ||
// Read plugins from extends | ||
let plugins = {}; | ||
if (Array.isArray(extended.plugins)) { | ||
config.plugins = (0, union_1.default)(config.plugins, extended.plugins || []); | ||
} | ||
// resolve plugins | ||
if (Array.isArray(config.plugins)) { | ||
config.plugins.forEach((plugin) => { | ||
(0, uniq_1.default)(extended.plugins || []).forEach((plugin) => { | ||
if (typeof plugin === 'string') { | ||
(0, load_plugin_1.default)(preset.plugins, plugin, process.env.DEBUG === 'true'); | ||
plugins = (0, load_plugin_1.default)(plugins, plugin, process.env.DEBUG === 'true'); | ||
} | ||
else { | ||
preset.plugins.local = plugin; | ||
plugins.local = plugin; | ||
} | ||
}); | ||
} | ||
const rules = preset.rules ? preset.rules : {}; | ||
const qualifiedRules = (await Promise.all(Object.entries(rules || {}).map((entry) => (0, execute_rule_1.default)(entry)))).reduce((registry, item) => { | ||
const rules = (await Promise.all(Object.entries(extended.rules || {}).map((entry) => (0, execute_rule_1.default)(entry)))).reduce((registry, item) => { | ||
// type of `item` can be null, but Object.entries always returns key pair | ||
const [key, value] = item; | ||
@@ -90,12 +74,18 @@ registry[key] = value; | ||
: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'; | ||
const prompt = preset.prompt && (0, isPlainObject_1.default)(preset.prompt) ? preset.prompt : {}; | ||
const prompt = extended.prompt && (0, isPlainObject_1.default)(extended.prompt) ? extended.prompt : {}; | ||
return { | ||
extends: preset.extends, | ||
formatter: preset.formatter, | ||
parserPreset: preset.parserPreset, | ||
ignores: preset.ignores, | ||
defaultIgnores: preset.defaultIgnores, | ||
plugins: preset.plugins, | ||
rules: qualifiedRules, | ||
helpUrl, | ||
extends: Array.isArray(extended.extends) | ||
? extended.extends | ||
: typeof extended.extends === 'string' | ||
? [extended.extends] | ||
: [], | ||
// Resolve config-relative formatter module | ||
formatter: resolve_from_1.default.silent(base, extended.formatter) || extended.formatter, | ||
// Resolve parser-opts from preset | ||
parserPreset: await (0, load_parser_opts_1.loadParserOpts)(extended.parserPreset), | ||
ignores: extended.ignores, | ||
defaultIgnores: extended.defaultIgnores, | ||
plugins: plugins, | ||
rules: rules, | ||
helpUrl: helpUrl, | ||
prompt, | ||
@@ -102,0 +92,0 @@ }; |
@@ -1,2 +0,3 @@ | ||
export declare function loadParserOpts(parserName: string, pendingParser: Promise<any>): Promise<any>; | ||
import { ParserPreset } from '@commitlint/types'; | ||
export declare function loadParserOpts(pendingParser: string | ParserPreset | Promise<ParserPreset> | undefined): Promise<ParserPreset | undefined>; | ||
//# sourceMappingURL=load-parser-opts.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loadParserOpts = void 0; | ||
async function loadParserOpts(parserName, pendingParser) { | ||
function isObjectLike(obj) { | ||
return Boolean(obj) && typeof obj === 'object'; // typeof null === 'object' | ||
} | ||
function isParserOptsFunction(obj) { | ||
return typeof obj.parserOpts === 'function'; | ||
} | ||
async function loadParserOpts(pendingParser) { | ||
if (!pendingParser || typeof pendingParser !== 'object') { | ||
return undefined; | ||
} | ||
// Await for the module, loaded with require | ||
const parser = await pendingParser; | ||
// Await parser opts if applicable | ||
if (typeof parser === 'object' && | ||
typeof parser.parserOpts === 'object' && | ||
typeof parser.parserOpts.then === 'function') { | ||
return (await parser.parserOpts).parserOpts; | ||
// exit early, no opts to resolve | ||
if (!parser.parserOpts) { | ||
return parser; | ||
} | ||
// Pull nested parserOpts, might happen if overwritten with a module in main config | ||
if (typeof parser.parserOpts === 'object') { | ||
// Await parser opts if applicable | ||
parser.parserOpts = await parser.parserOpts; | ||
if (isObjectLike(parser.parserOpts) && | ||
isObjectLike(parser.parserOpts.parserOpts)) { | ||
parser.parserOpts = parser.parserOpts.parserOpts; | ||
} | ||
return parser; | ||
} | ||
// Create parser opts from factory | ||
if (typeof parser === 'object' && | ||
typeof parser.parserOpts === 'function' && | ||
parserName.startsWith('conventional-changelog-')) { | ||
return await new Promise((resolve) => { | ||
if (isParserOptsFunction(parser) && | ||
typeof parser.name === 'string' && | ||
parser.name.startsWith('conventional-changelog-')) { | ||
return new Promise((resolve) => { | ||
const result = parser.parserOpts((_, opts) => { | ||
resolve(opts.parserOpts); | ||
resolve(Object.assign(Object.assign({}, parser), { parserOpts: opts === null || opts === void 0 ? void 0 : opts.parserOpts })); | ||
}); | ||
@@ -25,16 +42,11 @@ // If result has data or a promise, the parser doesn't support factory-init | ||
Promise.resolve(result).then((opts) => { | ||
resolve(opts.parserOpts); | ||
resolve(Object.assign(Object.assign({}, parser), { parserOpts: opts === null || opts === void 0 ? void 0 : opts.parserOpts })); | ||
}); | ||
} | ||
return; | ||
}); | ||
} | ||
// Pull nested paserOpts, might happen if overwritten with a module in main config | ||
if (typeof parser === 'object' && | ||
typeof parser.parserOpts === 'object' && | ||
typeof parser.parserOpts.parserOpts === 'object') { | ||
return parser.parserOpts.parserOpts; | ||
} | ||
return parser.parserOpts; | ||
return parser; | ||
} | ||
exports.loadParserOpts = loadParserOpts; | ||
//# sourceMappingURL=load-parser-opts.js.map |
@@ -1,3 +0,2 @@ | ||
import { UserConfig } from '@commitlint/types'; | ||
export declare const pickConfig: (input: unknown) => UserConfig; | ||
export declare const pickConfig: (input: unknown) => Record<string, unknown>; | ||
//# sourceMappingURL=pick-config.d.ts.map |
{ | ||
"name": "@commitlint/load", | ||
"version": "14.1.0", | ||
"version": "15.0.0", | ||
"description": "Load shared commitlint configuration", | ||
@@ -38,5 +38,5 @@ "main": "lib/load.js", | ||
"devDependencies": { | ||
"@commitlint/test": "^14.0.0", | ||
"@commitlint/utils": "^14.0.0", | ||
"@types/lodash": "4.14.176", | ||
"@commitlint/test": "^15.0.0", | ||
"@commitlint/utils": "^15.0.0", | ||
"@types/lodash": "4.14.177", | ||
"conventional-changelog-atom": "^2.0.8", | ||
@@ -46,5 +46,5 @@ "execa": "^5.0.0" | ||
"dependencies": { | ||
"@commitlint/execute-rule": "^14.0.0", | ||
"@commitlint/resolve-extends": "^14.1.0", | ||
"@commitlint/types": "^14.0.0", | ||
"@commitlint/execute-rule": "^15.0.0", | ||
"@commitlint/resolve-extends": "^15.0.0", | ||
"@commitlint/types": "^15.0.0", | ||
"@endemolshinegroup/cosmiconfig-typescript-loader": "^3.0.2", | ||
@@ -57,3 +57,3 @@ "chalk": "^4.0.0", | ||
}, | ||
"gitHead": "3882bd1680197f0ec4c40e4c9955911e20647488" | ||
"gitHead": "399a0289356c670a87524387cc96d8fb0a33fdca" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47028
405
+ Added@commitlint/execute-rule@15.0.0(transitive)
+ Added@commitlint/resolve-extends@15.0.0(transitive)
+ Added@commitlint/types@15.0.0(transitive)
- Removed@commitlint/execute-rule@14.0.0(transitive)
- Removed@commitlint/resolve-extends@14.1.0(transitive)
- Removed@commitlint/types@14.0.0(transitive)
Updated@commitlint/types@^15.0.0