Socket
Socket
Sign inDemoInstall

@commitlint/load

Package Overview
Dependencies
Maintainers
4
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commitlint/load - npm Package Compare versions

Comparing version 18.6.1 to 19.0.0

75

lib/load.js

@@ -1,28 +0,34 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
import path from 'path';
import { validateConfig } from '@commitlint/config-validator';
import executeRule from '@commitlint/execute-rule';
import resolveExtends, { resolveFrom, loadParserPreset, } from '@commitlint/resolve-extends';
import isPlainObject from 'lodash.isplainobject';
import merge from 'lodash.merge';
import uniq from 'lodash.uniq';
import { loadConfig } from './utils/load-config.js';
import { loadParserOpts } from './utils/load-parser-opts.js';
import loadPlugin from './utils/load-plugin.js';
/**
* formatter should be kept as is when unable to resolve it from config directory
*/
const resolveFormatter = (formatter, parent) => {
try {
return resolveFrom(formatter, parent);
}
catch (error) {
return formatter;
}
};
Object.defineProperty(exports, "__esModule", { value: true });
const execute_rule_1 = __importDefault(require("@commitlint/execute-rule"));
const resolve_extends_1 = __importDefault(require("@commitlint/resolve-extends"));
const config_validator_1 = require("@commitlint/config-validator");
const lodash_isplainobject_1 = __importDefault(require("lodash.isplainobject"));
const lodash_merge_1 = __importDefault(require("lodash.merge"));
const lodash_uniq_1 = __importDefault(require("lodash.uniq"));
const path_1 = __importDefault(require("path"));
const resolve_from_1 = __importDefault(require("resolve-from"));
const load_config_1 = require("./utils/load-config");
const load_parser_opts_1 = require("./utils/load-parser-opts");
const load_plugin_1 = __importDefault(require("./utils/load-plugin"));
async function load(seed = {}, options = {}) {
export default async function load(seed = {}, options = {}) {
const cwd = typeof options.cwd === 'undefined' ? process.cwd() : options.cwd;
const loaded = await (0, load_config_1.loadConfig)(cwd, options.file);
const base = loaded && loaded.filepath ? path_1.default.dirname(loaded.filepath) : cwd;
const loaded = await loadConfig(cwd, options.file);
const baseDirectory = (loaded === null || loaded === void 0 ? void 0 : loaded.filepath) ? path.dirname(loaded.filepath) : cwd;
const configFilePath = loaded === null || loaded === void 0 ? void 0 : loaded.filepath;
let config = {};
if (loaded) {
(0, config_validator_1.validateConfig)(loaded.filepath || '', loaded.config);
validateConfig(loaded.filepath || '', loaded.config);
config = loaded.config;
}
// Merge passed config with file based options
config = (0, lodash_merge_1.default)({
config = merge({
extends: [],

@@ -34,14 +40,10 @@ plugins: [],

if (typeof config.parserPreset === 'string') {
const resolvedParserPreset = (0, resolve_from_1.default)(base, config.parserPreset);
config.parserPreset = {
name: config.parserPreset,
path: resolvedParserPreset,
parserOpts: require(resolvedParserPreset),
};
const resolvedParserPreset = resolveFrom(config.parserPreset, configFilePath);
config.parserPreset = Object.assign({ name: config.parserPreset }, (await loadParserPreset(resolvedParserPreset)));
}
// Resolve extends key
const extended = (0, resolve_extends_1.default)(config, {
const extended = await resolveExtends(config, {
prefix: 'commitlint-config',
cwd: base,
parserPreset: config.parserPreset,
cwd: baseDirectory,
parserPreset: await config.parserPreset,
});

@@ -53,5 +55,5 @@ if (!extended.formatter || typeof extended.formatter !== 'string') {

if (Array.isArray(extended.plugins)) {
(0, lodash_uniq_1.default)(extended.plugins || []).forEach((plugin) => {
for (const plugin of uniq(extended.plugins)) {
if (typeof plugin === 'string') {
plugins = (0, load_plugin_1.default)(plugins, plugin, process.env.DEBUG === 'true');
plugins = await loadPlugin(plugins, plugin, process.env.DEBUG === 'true');
}

@@ -61,5 +63,5 @@ else {

}
});
}
}
const rules = (await Promise.all(Object.entries(extended.rules || {}).map((entry) => (0, execute_rule_1.default)(entry)))).reduce((registry, item) => {
const rules = (await Promise.all(Object.entries(extended.rules || {}).map((entry) => executeRule(entry)))).reduce((registry, item) => {
// type of `item` can be null, but Object.entries always returns key pair

@@ -75,3 +77,3 @@ const [key, value] = item;

: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint';
const prompt = extended.prompt && (0, lodash_isplainobject_1.default)(extended.prompt) ? extended.prompt : {};
const prompt = extended.prompt && isPlainObject(extended.prompt) ? extended.prompt : {};
return {

@@ -84,5 +86,5 @@ extends: Array.isArray(extended.extends)

// Resolve config-relative formatter module
formatter: resolve_from_1.default.silent(base, extended.formatter) || extended.formatter,
formatter: resolveFormatter(extended.formatter, configFilePath),
// Resolve parser-opts from preset
parserPreset: await (0, load_parser_opts_1.loadParserOpts)(extended.parserPreset),
parserPreset: await loadParserOpts(extended.parserPreset),
ignores: extended.ignores,

@@ -96,3 +98,2 @@ defaultIgnores: extended.defaultIgnores,

}
exports.default = load;
//# sourceMappingURL=load.js.map

@@ -1,17 +0,11 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEsmModule = exports.isDynamicAwaitSupported = exports.loadConfig = void 0;
const cosmiconfig_1 = require("cosmiconfig");
const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import { cosmiconfig, defaultLoadersSync, defaultLoaders, } from 'cosmiconfig';
import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
const moduleName = 'commitlint';
async function loadConfig(cwd, configPath) {
export async function loadConfig(cwd, configPath) {
let tsLoaderInstance;
const tsLoader = (...args) => {
if (!tsLoaderInstance) {
tsLoaderInstance = (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)();
tsLoaderInstance = TypeScriptLoader();
}

@@ -22,6 +16,6 @@ return tsLoaderInstance(...args);

// async js/cjs loaders (dynamic import). Otherwise, use synchronous js/cjs loaders.
const loaders = (0, exports.isDynamicAwaitSupported)() || (0, exports.isEsmModule)(cwd)
? cosmiconfig_1.defaultLoaders
: cosmiconfig_1.defaultLoadersSync;
const explorer = (0, cosmiconfig_1.cosmiconfig)(moduleName, {
const loaders = isDynamicAwaitSupported() || isEsmModule(cwd)
? defaultLoaders
: defaultLoadersSync;
const explorer = cosmiconfig(moduleName, {
searchPlaces: [

@@ -54,3 +48,3 @@ // cosmiconfig overrides default searchPlaces if any new search place is added (For e.g. `*.ts` files),

});
const explicitPath = configPath ? path_1.default.resolve(cwd, configPath) : undefined;
const explicitPath = configPath ? path.resolve(cwd, configPath) : undefined;
const explore = explicitPath ? explorer.load : explorer.search;

@@ -64,7 +58,6 @@ const searchPath = explicitPath ? explicitPath : cwd;

}
exports.loadConfig = loadConfig;
// See the following issues for more context, contributing to failing Jest tests:
// - Issue: https://github.com/nodejs/node/issues/40058
// - Resolution: https://github.com/nodejs/node/pull/48510 (Node v20.8.0)
const isDynamicAwaitSupported = () => {
export const isDynamicAwaitSupported = () => {
const [major, minor] = process.version

@@ -76,14 +69,12 @@ .replace('v', '')

};
exports.isDynamicAwaitSupported = isDynamicAwaitSupported;
// Is the given directory set up to use ESM (ECMAScript Modules)?
const isEsmModule = (cwd) => {
export const isEsmModule = (cwd) => {
var _a;
const packagePath = path_1.default.join(cwd, 'package.json');
if (!(0, fs_1.existsSync)(packagePath)) {
const packagePath = path.join(cwd, 'package.json');
if (!existsSync(packagePath)) {
return false;
}
const packageJSON = (0, fs_1.readFileSync)(packagePath, { encoding: 'utf-8' });
const packageJSON = readFileSync(packagePath, { encoding: 'utf-8' });
return ((_a = JSON.parse(packageJSON)) === null || _a === void 0 ? void 0 : _a.type) === 'module';
};
exports.isEsmModule = isEsmModule;
//# sourceMappingURL=load-config.js.map

@@ -1,4 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadParserOpts = void 0;
function isObjectLike(obj) {

@@ -10,3 +7,3 @@ return Boolean(obj) && typeof obj === 'object'; // typeof null === 'object'

}
async function loadParserOpts(pendingParser) {
export async function loadParserOpts(pendingParser) {
if (typeof pendingParser === 'function') {

@@ -54,3 +51,2 @@ return loadParserOpts(pendingParser());

}
exports.loadParserOpts = loadParserOpts;
//# sourceMappingURL=load-parser-opts.js.map
import { PluginRecords } from '@commitlint/types';
export default function loadPlugin(plugins: PluginRecords, pluginName: string, debug?: boolean): PluginRecords;
export default function loadPlugin(plugins: PluginRecords, pluginName: string, debug?: boolean): Promise<PluginRecords>;
//# sourceMappingURL=load-plugin.d.ts.map

@@ -1,16 +0,19 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
import { createRequire } from 'module';
import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
import chalk from 'chalk';
import { normalizePackageName, getShorthandName } from './plugin-naming.js';
import { WhitespacePluginError, MissingPluginError } from './plugin-errors.js';
const require = createRequire(import.meta.url);
const __dirname = path.resolve(fileURLToPath(import.meta.url), '..');
const dynamicImport = async (id) => {
const imported = await import(path.isAbsolute(id) ? pathToFileURL(id).toString() : id);
return ('default' in imported && imported.default) || imported;
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
const plugin_naming_1 = require("./plugin-naming");
const plugin_errors_1 = require("./plugin-errors");
function loadPlugin(plugins, pluginName, debug = false) {
const longName = (0, plugin_naming_1.normalizePackageName)(pluginName);
const shortName = (0, plugin_naming_1.getShorthandName)(longName);
let plugin = null;
export default async function loadPlugin(plugins, pluginName, debug = false) {
const longName = normalizePackageName(pluginName);
const shortName = getShorthandName(longName);
let plugin;
if (pluginName.match(/\s+/u)) {
throw new plugin_errors_1.WhitespacePluginError(pluginName, {
throw new WhitespacePluginError(pluginName, {
pluginName: longName,

@@ -22,3 +25,3 @@ });

try {
plugin = require(longName);
plugin = await dynamicImport(longName);
}

@@ -32,7 +35,7 @@ catch (pluginLoadErr) {

// If the plugin can't be resolved, display the missing plugin error (usually a config or install error)
console.error(chalk_1.default.red(`Failed to load plugin ${longName}.`));
console.error(chalk.red(`Failed to load plugin ${longName}.`));
const message = (error === null || error === void 0 ? void 0 : error.message) || 'Unknown error occurred';
throw new plugin_errors_1.MissingPluginError(pluginName, message, {
throw new MissingPluginError(pluginName, message, {
pluginName: longName,
commitlintPath: path_1.default.resolve(__dirname, '../..'),
commitlintPath: path.resolve(__dirname, '../..'),
});

@@ -56,3 +59,3 @@ }

: `${longName}, version unknown`;
console.log(chalk_1.default.blue(`Loaded plugin ${pluginName} (${loadedPluginAndVersion}) (from ${resolvedPath})`));
console.log(chalk.blue(`Loaded plugin ${pluginName} (${loadedPluginAndVersion}) (from ${resolvedPath})`));
}

@@ -63,3 +66,2 @@ plugins[pluginKey] = plugin;

}
exports.default = loadPlugin;
//# sourceMappingURL=load-plugin.js.map

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MissingPluginError = exports.WhitespacePluginError = void 0;
class WhitespacePluginError extends Error {
export class WhitespacePluginError extends Error {
constructor(pluginName, data = {}) {

@@ -14,4 +11,3 @@ super(`Whitespace found in plugin name '${pluginName}'`);

}
exports.WhitespacePluginError = WhitespacePluginError;
class MissingPluginError extends Error {
export class MissingPluginError extends Error {
constructor(pluginName, errorMessage = '', data = {}) {

@@ -25,3 +21,2 @@ super(`Failed to load plugin ${pluginName}: ${errorMessage}`);

}
exports.MissingPluginError = MissingPluginError;
//# sourceMappingURL=plugin-errors.js.map

@@ -1,8 +0,2 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNamespaceFromTerm = exports.getShorthandName = exports.normalizePackageName = void 0;
const path_1 = __importDefault(require("path"));
import path from 'path';
// largely adapted from eslint's plugin system

@@ -14,3 +8,3 @@ const NAMESPACE_REGEX = /^@.*\//iu;

function convertPathToPosix(filepath) {
const normalizedFilepath = path_1.default.normalize(filepath);
const normalizedFilepath = path.normalize(filepath);
const posixFilepath = normalizedFilepath.replace(/\\/gu, '/');

@@ -25,3 +19,3 @@ return posixFilepath;

*/
function normalizePackageName(name) {
export function normalizePackageName(name) {
let normalizedName = name;

@@ -58,3 +52,2 @@ /**

}
exports.normalizePackageName = normalizePackageName;
/**

@@ -65,3 +58,3 @@ * Removes the prefix from a fullname.

*/
function getShorthandName(fullname) {
export function getShorthandName(fullname) {
if (fullname[0] === '@') {

@@ -82,3 +75,2 @@ let matchResult = new RegExp(`^(@[^/]+)/${prefix}$`, 'u').exec(fullname);

}
exports.getShorthandName = getShorthandName;
/**

@@ -89,7 +81,6 @@ * Gets the scope (namespace) of a term.

*/
function getNamespaceFromTerm(term) {
export function getNamespaceFromTerm(term) {
const match = term.match(NAMESPACE_REGEX);
return match ? match[0] : '';
}
exports.getNamespaceFromTerm = getNamespaceFromTerm;
//# sourceMappingURL=plugin-naming.js.map
{
"name": "@commitlint/load",
"version": "18.6.1",
"type": "module",
"version": "19.0.0",
"description": "Load shared commitlint configuration",

@@ -38,7 +39,7 @@ "main": "lib/load.js",

"devDependencies": {
"@commitlint/test": "^18.0.0",
"@commitlint/test": "^19.0.0",
"@types/lodash.isplainobject": "^4.0.8",
"@types/lodash.merge": "^4.6.8",
"@types/lodash.uniq": "^4.5.8",
"@types/node": "^18.11.9",
"@types/node": "^18.19.17",
"conventional-changelog-atom": "^4.0.0",

@@ -48,7 +49,7 @@ "typescript": "^5.2.2"

"dependencies": {
"@commitlint/config-validator": "^18.6.1",
"@commitlint/execute-rule": "^18.6.1",
"@commitlint/resolve-extends": "^18.6.1",
"@commitlint/types": "^18.6.1",
"chalk": "^4.1.0",
"@commitlint/config-validator": "^19.0.0",
"@commitlint/execute-rule": "^19.0.0",
"@commitlint/resolve-extends": "^19.0.0",
"@commitlint/types": "^19.0.0",
"chalk": "^5.3.0",
"cosmiconfig": "^8.3.6",

@@ -58,6 +59,5 @@ "cosmiconfig-typescript-loader": "^5.0.0",

"lodash.merge": "^4.6.2",
"lodash.uniq": "^4.5.0",
"resolve-from": "^5.0.0"
"lodash.uniq": "^4.5.0"
},
"gitHead": "89f5bf91d1c11b1f457a6f0d99b8ea34583a9311"
"gitHead": "f1ff12159d627ee63bf8982ab02e6cca8f10b09f"
}

@@ -1,5 +0,5 @@

> Load shared commitlint configuration
# @commitlint/load
Load shared commitlint configuration
## Getting started

@@ -11,11 +11,6 @@

## Example
## Documentation
```js
const load = require('@commitlint/load').default;
Consult [API docs](https://commitlint.js.org/api/load) for comprehensive documentation.
load({extends: ['./package']}).then((config) => console.log(config));
// => { extends: ['./package', './package-b'], rules: {} }
```
Consult [docs/api](https://conventional-changelog.github.io/commitlint/#/reference-api) for comprehensive documentation.
Documentation generated from [`docs` folder](../../docs/api/format.md).

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc